@1fun-oss/rng
v1.0.1
Published
This repository implements a cryptographically secure Random Number Generator (RNG) built on **HMAC-DRBG** (Deterministic Random Bit Generator).
Maintainers
Readme
GLI-19 Compliant Cryptographically Secure Pseudo Random Number Generator (RNG)
This repository implements a cryptographically secure Random Number Generator (RNG) built on HMAC-DRBG (Deterministic Random Bit Generator).
The project follows the technical requirements from GLI-19 Chapter 3: Random Number Generator (RNG) Requirements.
This implementation is designed as production-ready RNG code and can be submitted for GLI / iTech Labs certification.
Structure
cli- CLI tools for generating test dataexamples- Example usage of the RNGsrc/hmac-drbg- HMAC-DRBG implementationsrc/rng- Shuffling, scaling and draw utilitiessrc/utils- Some helpful utilities
Dieharder Docker
This project includes a Dockerfile with dieharder.
docker build -t 1fun-rng .
docker run -it --rm 1fun-rng⚠️ Note on Dieharder Testing
Some statistical tests in the Dieharder suite are very data-hungry.
To achieve a full "PASSED" status across all tests, a large amount of RNG output data may be required.
This is expected behavior since certain tests need millions or even billions of samples to converge reliably.
Generate ASCII output to txt file for usage with dieharder
npx ts-node ./cli/generate-dieharder-ascii.ts \
--server-seed abcdefghijklmnopqrstuvwxyz \
--client-seed abcdefghijklmnopqrstuvwxyz \
--count 2684354560 \
--destination data/hmac-dbrng.txtThis creates a file hmac-dbrng.txt with 2 684 354 560 uint32 values generated with the HMAC-DRBG algorithm.
It can be used with the dieharder test suite:
dieharder -g 202 -f data/hmac-dbrng.txt -aGenerate raw output to bin file for usage with dieharder
npx ts-node ./cli/generate-dieharder-bin.ts \
--server-seed abcdefghijklmnopqrstuvwxyz \
--client-seed abcdefghijklmnopqrstuvwxyz \
--count 2684354560 \
--destination data/hmac-dbrng.binThis creates a file hmac-dbrng.bin with 2 684 354 560 uint32 values (10GiB of data) generated with the HMAC-DRBG algorithm.
It can be used with the dieharder test suite:
dieharder -g 201 -f data/hmac-dbrng.bin -aGenerate output to txt file for GLI
npx ts-node ./cli/generate-gli-output.ts \
--server-seed abcdefghijklmnopqrstuvwxyz \
--client-seed abcdefghijklmnopqrstuvwxyz \
--range-start 1 \
--range-end 52 \
--selections 52 \
--draws 100000 \
--destination data/gli.txtThe additional parameter --with-replacements allows for numbers to be repeated within selections.
range-start and range-end are inclusive
Acknowledgements
This project draws ideas and inspiration (and in some cases code concepts) from the following open-source projects:
