Skip to content

1fun-oss/rng

Repository files navigation

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 data
  • examples - Example usage of the RNG
  • src/hmac-drbg - HMAC-DRBG implementation
  • src/rng - Shuffling, scaling and draw utilities
  • src/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.txt

This 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 -a

Generate 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.bin

This 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 -a

Generate 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.txt

The 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:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published