This repository provides tools based on NIST Special Publication 800-90B for assessing the entropy of a sequence of bits (or bytes represented as bits). Since randomness implies unpredictability, which is measured by entropy, these tools can help determine if a sequence is sufficiently random. There isn't a single definitive answer for "sufficient randomness" as it depends on the intended application. However, the tools provide an entropy estimate, allowing you to judge if the randomness meets your specific needs.
Here's how to use the repository and interpret the results:
1. Compilation:
First, compile the tools. The repository has two main programs for entropy assessment: ea_iid (for independent and identically distributed data) and ea_non_iid (for non-IID data, which is more common). You'll likely want ea_non_iid for assessing randomness. Compile them using the provided Makefile:
bash
make iid
make non_iid
2. Running the Assessment:
The basic command structure for assessing a file named data.bin is:
bash
./ea_non_iid data.bin [bits_per_symbol]
data.bin: The path to your binary file containing the bit sequence. The file should contain at least 1,000,000 bits (or 125,000 bytes if each byte represents 8 bits).
[bits_per_symbol]: Optional. Specifies how many bits are used per symbol. If omitted, it's inferred from the data (each byte is treated as a symbol of 8 bits by default). For a raw bit sequence where each byte represents 8 bits, you'd typically omit this or specify 8.
Example: If your data is in random_bits.bin and you want to treat each byte as representing 8 bits:
bash
./ea_non_iid random_bits.bin 8
3. Interpreting the Output:
The output will show the results of various statistical tests and entropy estimations. The most important value is the final "Assessed min entropy" (or "min(H_original, <bits_per_symbol> X H_bitstring)" if run with -i flag). This value, representing entropy per symbol, indicates the level of unpredictability. A higher value means more entropy and thus better randomness.
For IID Data (less common): If you used ea_iid, also pay attention to the results of the Chi-square and IID permutation tests. The sequence is deemed IID only if all tests pass. An IID sequence has the property that each bit is independent of the others and has the same probability distribution. The assessment will still produce entropy estimates even if the IID tests fail, but the IID assumption won't be valid.
For non-IID Data (more common): The output includes results from various tests (Most Common Value, Collision, Markov, Compression, t-Tuple, LRS, MultiMCW, Lag Prediction, MultiMMC, LZ78Y). Each test estimates entropy. The lowest entropy estimate among all tests is selected as the overall minimum entropy.
4. Determining Sufficient Randomness:
There's no universal threshold for "sufficient" randomness. It depends on your application's security requirements. However, here are some general guidelines:
Ideally: For true random bits, the entropy should be close to the bits_per_symbol value. For example, if bits_per_symbol is 8, an entropy of nearly 8 bits per symbol is excellent.
Cryptographic Applications: For cryptographic keys or seeds, you'll want very high entropy, ideally very close to the bits_per_symbol. Any significant deviation could indicate a weakness.
Non-Cryptographic Applications: For less sensitive applications, lower entropy might be acceptable, but you still need to consider the potential impact of predictability.
5. Verbose Output and JSON:
For more detailed information about each test, use the -v flag (multiple -v flags increase verbosity). To get output in JSON format for easier parsing, use the -o <filename> flag. For example:
bash
./ea_non_iid -v -v -o results.json data.bin 8
6. Restart Testing:
If your data comes from a physical RNG and you want to perform restart testing as described in SP 800-90B Section 3.1.4, you should use the ea_restart tool. See the documentation or use ./ea_restart --help for how to use it. This involves specific data formatting requirements (1000 restarts, each with 1000 samples) and requires providing an initial entropy estimate.
By carefully examining the entropy estimates and test results, and considering your specific application's security requirements, you can use this repository to assess the randomness of a bit sequence. Remember to consult the SP 800-90B document for a full understanding of the tests and their implications.