Step 1: random number generator
Connect the STM32 board to the workstation, via USB Type-A to Micro-B cable.
The STM32 RNG is run via the UART firmware in order to generate a random number as described in STM32 MCU side. Data are stored on the workstation using a terminal emulation application such as PuTTY (free and open-source terminal emulator, serial console, and network file transfer application).
Step 2: NIST statistical tests
The Makefile is used to compile the program as described in the readme file mentioned in NIST SP800-90b test suite side.
For non-IID tests, the user must follow the steps detailed below:
- Use the Makefile to compile the program: make non_iid
- Run the program with
./ea_non_iid [-i|-c] [-a|-t] [-v] [-l <index>,<samples> ] <file_name> [bits_per_symbol]
where
-i indicates that data is unconditioned and returns an initial entropy estimate (default).
-c indicates that data is conditioned.
-a estimates the entropy for all data in the binary file (default).
-t truncates the created bit-string representation of data to the first 1 Mbit.
-l reads (at most) data samples after indexing into the file by * bytes.
-v verbosity flag for more output (optional, can be used multiple times)bits_per_symbol: number of bits per symbol. Each symbol is expected to fit within a single byte.
Example:
/ea_non_iid ../bin/l5.bin 1 -i -t -vFor restart tests, the user must follow the steps detailed below:
- Use the Makefile to compile the program: make restart.
- Run the program with.
./ ea_restart [-i|-n] [-v] <file_name> [bits_per_symbol] <H_I>Where
[bits_per_symbol]: Must be between 1-8, inclusive.
<H_I>: Initial entropy estimate.
[-i|-n]: '-i' for IID data, '-n' for non-IID data. Non-IID is the default.
-v Optional verbosity flag for more output.<file_name>: Must be relative path to a binary file contains the data that consists of 1000 restarts, each with 1000 samples. The data is converted to rows and columns. Example:
./ea_restart It_res_1000x1000.bin 1 0.7695 -n -v
Step 3: test report
The NIST statistical tests provide an analytical routine to facilitate the interpretation of the results:
- For the non IID tests, the result for each IID test is provided and, at the end, the final min entropy.
- For the restart tests, we determine the Hr and Hc , the entropy estimates of the row and the column datasets, respectively. the final result of the restart tests is min (H_r, H_c, H_I).
Conclusion
This application note describes the main guidelines and steps to verify the randomness of numbers generated by the STM32 microcontrollers RNG peripheral, using either NIST statistical test suite SP800-22rev1a, April 2010 or SP800-90B, January 2018.
NIST SP800-22rev1a statistical test suite
The results are represented as a table with p rows and q columns, where:
- p, the number of rows, corresponds to the number of statistical tests applied
- q, the number of columns (q = 13) is distributed as follows:
- columns 1-10 correspond to the frequency of 10 Pvalues
- column 11 is the Pvalue that arises via the application of a chi-square test11
- column 12 is the proportion of binary sequences that passed
- column 13 is the corresponding statistical test
The example below shows the first and last part of the test results. For more details, refer to the finalAnalysisReport file under sts-2.1.1\experiments\AlgorithmTesting.
Part 1
Part 2
The minimum pass rate for each statistical test, except the random excursion (variant) test, is approximately 8 for a sample size of 10 binary sequences.
The minimum pass rate for the random excursion (variant) test is approximately 4 for a sample size of 5 binary sequences.
For further guidelines, construct a probability table using the MAPLE program provided in the addendum section of the documentation.
NIST SP800-90b statistical test suite
This is an example of the execution of the non-IID tests.
$ ./ea_non_iid ../bin/l5.bin 1 -i -t -v Opening file: '../bin/l5.bin'
Number of Binary Symbols: 1024000
Symbol alphabet consists of 2 unique symbols
Running non-IID tests...
Running Most Common Value Estimate...
MCV Estimate: mode = 530185, p-hat = 0.51775878906249995, p_u = 0.51903071907139675
Most Common Value Estimate (bit string) = 0.946108 / 1 bit(s)
Running Entropic Statistic Estimates (bit strings only)...
Collision Estimate: X-bar = 2.4954732991667945, sigma-hat = 0.49998011778222412, p = 0.55717151750062044
Collision Test Estimate (bit string) = 0.843807 / 1 bit(s)
Markov Estimate: P_0 = 0.4822412109375, P_1 = 0.51775878906249995, P_0,0 = 0.48618305677846313, P_0,1 = 0.51381694322153693, P_1,0 = 0.47857068759018079, P_1,1 = 0.52142931240981927, p_max = 6.2798397734367098e-37
Markov Test Estimate (bit string) = 0.939536 / 1 bit(s)
Compression Estimate: X-bar = 5.2113069751685934, sigma-hat = 1.0187463366852749, p = 0.035431813237513987
Compression Test Estimate (bit string) = 0.803135 / 1 bit(s)
Running Tuple Estimates... t-Tuple Estimate: t = 16, p-hat_max = 0.53187518804173173, p_u = 0.53314533218239224
LRS Estimate: u = 17, v = 38, P_{max,W} = 0.50423097749594759, p_u = 0.50550366496585808
T-Tuple Test Estimate (bit string) = 0.907399 / 1 bit(s)
LRS Test Estimate (bit string) = 0.984207 / 1 bit(s)
Running Predictor Estimates...
MultiMCW Prediction Estimate: N = 1023937, Pglobal' = 0.51634782805743162 (C = 527405) Plocal = 0.42674646958653317 (r = 21)
Multi Most Common in Window (MultiMCW) Prediction Test Estimate (bit string) = 0.953585 / 1 bit(s)
Lag Prediction Estimate: N = 1023999, Pglobal' = 0.50526439621655594 (C = 516087) Plocal = 0.40830971576974662 (r = 20)
Lag Prediction Test Estimate (bit string) = 0.984890 / 1 bit(s)
MultiMMC Prediction Estimate: N = 1023998, Pglobal' = 0.51899462537798435 (C = 530147) Plocal = 0.42674521449187308 (r = 21)
Multi Markov Model with Counting (MultiMMC) Prediction Test Estimate (bit string) = 0.946208 / 1 bit(s)
LZ78Y Prediction Estimate: N = 1023983, Pglobal' = 0.51899440603936897 (C = 530139) Plocal = 0.42674552311446512 (r = 21)
LZ78Y Prediction Test Estimate (bit string) = 0.946209 / 1 bit(s)
H_original: 1.000000
H_bitstring: 0.803135
min(H_original, 1 X H_bitstring): 0.803135This is an example of the execution of the restart tests.
$ ./ea_restart It_res_1000x1000.bin 1 0.7695 -n -v
Opening file: '/home/Desktop/It_restart_1000x1000_bins/It_res_1000x1000.bin'
Loaded 1000000 samples made up of 2 distinct 1-bit-wide symbols.
H_I: 0.769500
ALPHA: 5.0251553006530614e-06, X_cutoff: 654
X_max: 592
Restart Sanity Check Passed...
Running non-IID tests...
Running Most Common Value Estimate...
Literal MCV Estimate: mode = 524815, p-hat = 0.52481500000000003, p_u = 0.52610132816195332
Most Common Value Estimate (Rows) = 0.926587 / 1 bit(s)
Literal MCV Estimate: mode = 524815, p-hat = 0.52481500000000003, p_u = 0.52610132816195332
Most Common Value Estimate (Cols) = 0.926587 / 1 bit(s)
Running Entropic Statistic Estimates (bit strings only)...
Literal Collision Estimate: X-bar = 2.4939272870560187, sigma-hat = 0.49996374423442524, p = 0.56366499259647185
Collision Test Estimate (Rows) = 0.827090 / 1 bit(s)
Literal Collision Estimate: X-bar = 2.4988330426351748, sigma-hat = 0.49999926291763369, p = 0.54001782688956723
Collision Test Estimate (Cols) = 0.888921 / 1 bit(s)
Literal Markov Estimate: P_0 = 0.52481500000000003, P_1 = 0.47518499999999997, P_0,0 = 0.5286091289311472, P_0,1 = 0.4713908710688528, P_1,0 = 0.52062569446782725, P_1,1 = 0.47937430553217275, p_max = 3.6149969304059282e-36
Markov Test Estimate (Rows) = 0.919808 / 1 bit(s)
Literal Markov Estimate: P_0 = 0.52481500000000003, P_1 = 0.47518499999999997, P_0,0 = 0.52490687194535213, P_0,1 = 0.47509312805464787, P_1,0 = 0.5247146368564598, P_1,1 = 0.4752853631435402, p_max = 1.4806522327909964e-36
Markov Test Estimate (Cols) = 0.929869 / 1 bit(s)
Literal Compression Estimate: X-bar = 5.2053159685055412, sigma-hat = 1.0214276541597365, p = 0.040397638399976898
Compression Test Estimate (Rows) = 0.771598 / 1 bit(s)
Literal Compression Estimate: X-bar = 5.2093623833151179, sigma-hat = 1.0198576801023285, p = 0.037170466884093645
Compression Test Estimate (Cols) = 0.791617 / 1 bit(s)
Running Tuple Estimates...
Literal t-Tuple Estimate: t = 16, p-hat_max = 0.54171776156680396, p_u = 0.54300118613085924
Literal LRS Estimate: u = 17, v = 38, p-hat = 0.50185202103932736, p_u = 0.50313992749997694
Literal t-Tuple Estimate: t = 16, p-hat_max = 0.53421514909068124, p_u = 0.535500045383837
Literal LRS Estimate: u = 17, v = 36, p-hat = 0.50196715258596614, p_u = 0.50325505791399572
T-Tuple Test Estimate (Rows) = 0.880973 / 1 bit(s)
T-Tuple Test Estimate (Cols) = 0.901041 / 1 bit(s)
LRS Test Estimate (Rows) = 0.990968 / 1 bit(s)
LRS Test Estimate (Cols) = 0.990638 / 1 bit(s)
Running Predictor Estimates...
Literal MultiMCW Prediction Estimate: N = 999937, Pglobal' = 0.52385156519694509 (C = 522532) Plocal can't affect result (r = 21)
Multi Most Common in Window (MultiMCW) Prediction Test Estimate (Rows) = 0.932770 / 1 bit(s)
Literal MultiMCW Prediction Estimate: N = 999937, Pglobal' = 0.52391856160939276 (C = 522599) Plocal can't affect result (r = 22)
Multi Most Common in Window (MultiMCW) Prediction Test Estimate (Cols) = 0.932586 / 1 bit(s)
Literal Lag Prediction Estimate: N = 999999, Pglobal' = 0.50560437226186183 (C = 504316) Plocal can't affect result (r = 20)
Lag Prediction Test Estimate (Rows) = 0.983919 / 1 bit(s)
Literal Lag Prediction Estimate: N = 999999, Pglobal' = 0.50229941431576741 (C = 501011) Plocal can't affect result (r = 19)
Lag Prediction Test Estimate (Cols) = 0.993381 / 1 bit(s)
Literal MultiMMC Prediction Estimate: N = 999998, Pglobal' = 0.52608038171682492 (C = 524793) Plocal can't affect result (r = 21)
Multi Markov Model with Counting (MultiMMC) Prediction Test Estimate (Rows) = 0.926645 / 1 bit(s)
Literal MultiMMC Prediction Estimate: N = 999998, Pglobal' = 0.5260743824720614 (C = 524787) Plocal can't affect result (r = 22)
Multi Markov Model with Counting (MultiMMC) Prediction Test Estimate (Cols) = 0.926661 / 1 bit(s)
Literal LZ78Y Prediction Estimate: N = 999983, Pglobal' = 0.52609326184739169 (C = 524798) Plocal can't affect result (r = 21)
LZ78Y Prediction Test Estimate (Rows) = 0.926610 / 1 bit(s)
Literal LZ78Y Prediction Estimate: N = 999983, Pglobal' = 0.52608626262396685 (C = 524791) Plocal can't affect result (r = 22)
LZ78Y Prediction Test Estimate (Cols) = 0.926629 / 1 bit(s)
H_r: 0.771598
H_c: 0.791617
H_I: 0.769500
Validation Test Passed...
min(H_r, H_c, H_I): 0.769500Revision history
| Date | Version | Changes |
|---|---|---|
| 13-May-2013 | 1 | Initial release. |
|
22-Jun-2016 | 2 | Updated:
|
|
1-Oct-2019 | 3 | Updated:
Added: Section 4: NIST SP800-90b test suite Section 5: NIST SP800-90b test suite running and analyzing Appendix B: NIST SP800-90b statistical test suite |
|
10-Oct-2019 |
4 | Updated Table 2: STM32 lines embedding the RNG hardware peripheral. |
|
8-Jan-2020 |
5 | Updated:
|
|
18-Aug-2020 |
6 |
Updated with new products STM32H72x/73x:
|
| 25-Aug-2021 | 6 | Migration to DITA |
| 1-Jul-2022 | 7 | Updated:
|
| 09-Mar-2023 | 8 | Updated the following elements to add STM32H5 and STM32WBA series:
Updated the document title. Applied minor changes to the whole document. |
| 10-Jan-2024 | 9 | Updated:
|
| 14-Mar-2024 | 10 | Added STM32U0 series and STM32H7R3/7S3 and STM32H7R7/7S7 lines in Table 1. Applicable products Updated:
|
| 21-Oct-2024 | 11 | Added STM32MP2 series in Table 1. Applicable products Updated:
|
| 07-Feb-2025 | 12 | Added STM32N6 series and STM32U3 series in Table 1. Applicable products Updated:
|
| 16-Feb-2026 | 13 |
Updated:
|
| 28-Jul-2026 | 14 | Updated Table 3 RNG register values. |
1 A special device must be used to execute the NIST test suite, except for the STM32L4P/Q, STM32H7A3/7B3, and STM32H72x/73x.
2 The bit 6 of RNG_CR enables or disables the bypass of post‑processing/conditioning logic. This bit must be enabled to run the NIST SP800‑90B test suite.
3 "Yes" indicates when the configuration values are part of an official NIST SP800-90B certificate. Links to these certificates can be found in ***.
4 The HTCR value programmed in the product OTP fuse configuration (rng_htcr_value) applies only to the boot ROM. Because the OTP selection supports only a restricted set of HTCR values, set rng_htcr_value to 0x6, which corresponds to HTCR = 0xAAC7. The user application can then use the HTCR value provided in ***.