Features:
- Emulates
$ cat /dev/randomshell 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 abstractionmain.go- application entry pointmain_test.go- application entry point testsgo.mod- go modules configurationMakefile- make utility configurationREADME.md- this file
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.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.
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-lintFor 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 lintConsidering that linting tool could not be installed on target computer this option is not part of building process.
Run following command to run application unit tests:
make testRun following command to build application binary file:
make buildOr full build process including clean up and unit tests:
makeCompiled binary could be installed in to $GOBIN folder with the following command:
make installAfter installation library classes could be references from any ruby code with command:
make runI 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.