Skip to content

Emulates '$ cat /dev/random' shell command by eternally producing random bites sequence

License

Notifications You must be signed in to change notification settings

vokinneberg/devrandom-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

/dev/random clone

Features:

  • Emulates $ cat /dev/random shell command by eternally producing random bites sequence using ANU Quantum Random Numbers Server as the source of entropy. The random numbers are generated in real-time in their lab by measuring the quantum fluctuations of the vacuum.

Package structure:

  • entropy_source - contains implementation and test of entropy source abstraction
  • main.go - application entry point
  • main_test.go - application entry point tests
  • go.mod - go modules configuration
  • Makefile - make utility configuration
  • README.md - this file

Configuration

Application configured with constant hardcoded values. It is easy to extend to environment variables though.

List of QRNG settings:

	EntropySourceUrl   = "https://qrng.anu.edu.au/API/jsonI.php" // QRNG server URL
	EntropyDataType    = "hex16" // Data format. unit8, unit16 also available.
	EntropyArrayLength = "1024" // Array length up to 1024.
	EntropyBlockSize   = "1024" // Blocks count up to 1024.

Getting Up and Running

Package manager

Go modules go mod used to set up dependencies for the project. Sources provided with vendor folder, so no need to download packages. Sources might be compiled right after download.

Linters

I use golanci-lint to statically check source code. If you're on Mac golangci-lint utility might be easily installed with with brew:

brew install golangci/tap/golangci-lint

For another platforms instructions could be found on the linter official page.

Linter could be run against all sources in the folder recursively with the following command:

make lint

Considering that linting tool could not be installed on target computer this option is not part of building process.

Test

Run following command to run application unit tests:

make test

Build

Run following command to build application binary file:

make build

Or full build process including clean up and unit tests:

make

Install

Compiled binary could be installed in to $GOBIN folder with the following command:

make install

Run

After installation library classes could be references from any ruby code with command:

make run

Technical details

I decided to implement /dev/random using ANU Quantum Random Numbers Server as the source of entropy as it looks elegant to get entropy by measuring the quantum fluctuations of the vacuum. Though it would not work in absence of internet connection and not very reliable because ANU Quantum Random Numbers Server seems to be a reliable source of entropy as it's continuously tested with various randomness test algorithms including Diehard.

I implemented the entropy source as an abstraction: interface EntropySource that potentially could be implemented using any entropy source. EntropySource interface provides only one method Entropy(entropy chan []byte, err chan error) which suppose to produce random numbers eternally using entropy channel, or produce error using err channel in case of any kind of internal error or lack of entropy. Thus you can use devrandom-clone package in your solution either using QRNG entropy source implementation or implementing your own entropy source.

About

Emulates '$ cat /dev/random' shell command by eternally producing random bites sequence

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published