This repository provides two separate programs for assessing the randomness of a bit sequence based on the NIST SP 800-90B standard: ea_iid for independent and identically distributed (IID) data and ea_non_iid for non-IID data. Most real-world entropy sources are not IID, so ea_non_iid is likely the tool you need. It's crucial to understand this distinction, as applying the wrong assessment could lead to incorrect entropy estimations. See section 7.18 of SP 800-90B for more details on the justification needed for IID claims.
Here's a breakdown of how to use the appropriate tool:
1. Compilation:
First, compile the necessary program using the provided Makefile:
For IID data:make iid
For non-IID data:make non_iid
This will create the executables ea_iid or ea_non_iid respectively.
2. Running the Assessment:
The general usage pattern for both programs is similar:
<file_name>: Path to the binary file containing your bit sequence. Each byte in the file represents a sample.
[bits_per_symbol]: (Optional) Number of bits per sample (1-8). If omitted, the tool attempts to infer this from the data. For a raw bit sequence, this should be 1.
-i: Perform an initial entropy estimate (default).
-c: Perform a conditioned sequential dataset entropy estimate. This is used after applying a conditioning function to the data. For raw bit sequences, use -i.
-a: Use all data for the H_bitstring assessment (relevant when bits_per_symbol > 1).
-t: Truncate data to the first 1,000,000 bits for H_bitstring assessment.
-v: Increase verbosity of output (can be used multiple times).
-q: Quiet mode (minimal output). Overrides -v.
-l <index>,<samples>: Reads a specific substring of the data starting from byte offset <index>*<samples> and reading <samples> bytes.
Example for a raw bit sequence (non-IID):
bash
./ea_non_iid -i -v my_bit_sequence.bin 1
3. Interpreting the Results:
The output will show the results of various statistical tests and entropy estimations. The most important value is the final "Assessed min entropy" (or h' for conditioned data). This represents the estimated min-entropy per bit. For a truly random source, this value should be close to 1.
Sufficient Randomness:
There's no single hard threshold for "sufficient randomness." The required entropy depends on the cryptographic application. However, the following guidelines can be helpful:
Values close to 1: Indicate good randomness.
Values significantly below 1: Suggest potential weaknesses in the randomness. You might need to consider a stronger entropy source or apply a conditioning function.
Failed statistical tests: Indicate non-random patterns in the data. Examine the verbose output to understand which tests failed and investigate the source of the non-randomness.
If the assessed entropy is substantially lower than expected or if multiple statistical tests fail, your bit sequence likely isn't sufficiently random for cryptographic purposes. You should carefully review the results of each test and consider improving your entropy source or applying a conditioning function as described in SP 800-90B.