NISTSP800-22rev1a test suite steps


Connect the STM32 board to the workstation. Depending on the type of board, the connection is made as follows:
The STM32 RNG is run via the UART firmware in order to generate a random number as described in STM32MCU side. Data are stored on the workstation using a terminal emulation application such as a PuTTY (free and open-source terminal emulator, serial console and network file transfer application).
The sts-2.1.1 package is compiled as described in the NIST statistical test suite documentation in order to create an executable program using visual C++ compiler.
After running the NIST statistical test suite program, a series of menu prompts are displayed in order to select the data to be analyzed and the statistical tests to be applied.
In this application note, the NIST statistical test suite is compiled under the name assess.exe and saved under the NIST_Test_Suite_OutputExample folder. As described previously, the random number is defined as 512,000 bits per block.
The various steps are detailed as follows:

When value 0 is entered, the program requires to enter the file name and path of the random number to be tested.

This application note details an example with two files per series, generated with the STM32 RNG, with the following file formats as recommended by NIST:
ascii.bin: sequence of ASCII 0's and 1'sbinary.bin: each byte in the data file contains 8 bits of data
In this case, 1 has been selected to apply all of the statistical tests.

In this example, the default settings are kept and value 0 is selected to go to the next step.

The NIST statistical test suite requires to put the number of bitstreams: 10 is entered for this example, meaning 10 blocks of 512 Kbits are selected (5,12 Mbits).

Value 0 is selected because the file is in ASCII format.


The statistical test results can be found in sts-2.1.1\experiments\AlgorithmTesting.
The NIST statistical tests provide an analytical routine to facilitate the interpretation of the results. A file named
finalAnalysisReport is generated when the statistical testing is complete and saved under sts2.1.1\experiments\AlgorithmTesting.
The report contains a summary of experimental results of 15 tests (see NIST SP800-22rev1a statistical test suite).
The NIST statistical tests also provide a detailed report for each test, saved under
sts-2.1.1\experiments\AlgorithmTesting\<Test suite name>.
The two following examples of complete NIST statistical test suite output reports are available under
The cryptographic random bit generators (RBGs), also known as random number generators (RNGs), require a noise source that produces outputs with some level of unpredictability, expressed as min-entropy.
The specificity of the NIST SP800-90b statistical test suite is to probe the quality of random generators for cryptographic applications by its standardized means of estimating the quality of a source of entropy.
A comprehensive description of the suite is presented in the NIST document entitled Recommendation for the Entropy Sources Used for Random Bit Generation.
The NIST SP800-90b statistical test suite can be downloaded from the GitHub web site (https://github.com/usnistgov/SP800-90B_EntropyAssessment).
The SP800-90B_EntropyAssessment C++ package implements the min-entropy assessment methods included in Special publication 800-90B.
To ensure that all the requirements for the NIST Special Publication (SP) 800-90 series recommendations are met it is necessary to validate the entropy source.
HI = min (Horiginal, Hsubmitter) for binary sources where Hsubmitter is the entropy estimate provided based on the submitter’s analysis of the noise source.
Random datasets are extracted from STM32-RNG peripheral entropy sources using the interrupt method (see AN4230_STM32-Firmware-description.html#id_36750__fig_ucv_5yg_wqb). The USART is used to send the generated raw data to the workstation to be tested with the NIST statistical test suite.
This random dataset can be extracted either with collecting continuous bits without disabling the RNG module or with restarting the RNG at every 1000 bits. The output file format is a sequence of hexadecimal digits in ASCII format, which is converted to binary format without alteration of data using a small Python script. This way, random bits are ready to be processed by NIST tests suite in *.bin dataset format.
An STM32 USART peripheral is configured to establish USB communication between the STM32 board and a workstation.
To extract raw data sets for NIST evaluation, the RNG peripheral can be configured to operate either in polling mode or in interrupt mode.
/* number of random bits*/
#define NUMBER_OF_RANDOM_BITS 1024
/* number of 32bits words*/
#define NUMBER_OF_RANDOM_32_BITS NUMBER_OF_RANDOM_BITS /32
/* number of restarts */
#define BLOCK_NUMBER 1000
/* number of random bits*/
#define NUMBER_OF_RANDOM_BITS 1024*1000
/* number of 32bits words*/
#define NUMBER_OF_RANDOM_32_BITS NUMBER_OF_RANDOM_BITS /32
/* number of restarts */
#define BLOCK_NUMBER 1
In continuous extraction mode, the size of a block is set to 1,024,000 and the number of blocks is set to 1, so that the RNG is disabled only after the generation of the entire dataset.
HAL_RNG_ReadyDataCallback) which extracts four 32-bit raw data words.NewBlockFlag and EndOfCollect. The main function monitors these flags to control data transmission to the workstation.HAL_RNG_ErrorCallback) is triggered if the RNG detects a seed or clock error. An error counter is then incremented, the RNG is restarted, and the extraction of the current data set is aborted (see Figure 14 ISR callback function when Error-flag).




The STM32Cube HAL RNG driver is used to configure the RNG with a NIST‑compliant setup. This driver provides the RNG_ConfigTypeDef structure and the HAL_RNGEx_SetConfig() API to customize the RNG configuration.
In the following code example, the RNG peripheral of the STM32U54x is configured according to the NIST‑compliant settings published by NIST for the STM32U545 public use entry (#E158).
First, the NIST‑compliant configuration is stored in a firmware structure named
sRngNistConfigU545, initialized as shown below. The first five fields map to the RNG_CR register bits (bit ranges indicated in the comments). The sixth and seventh fields hold the values for the RNG_HTCR and RNG_NSCR registers.RNG_ConfigTypeDef sRngNistConfigU545 =
{
.Config1 = 0x0F, /* RNG_CR[27:20] */
.Config2 = 0, /* RNG_CR[15:13] */
.Config3 = 0xF, /* RNG_CR[11:8] */
.ClockDivider = 0x1, /* RNG_CR[19:16] */
.NistCompliance= RNG_CR_NISTC, /* RNG_CR[12] bit NISTC = 1 */
.HealthTest = 0x76B3, /* RNG_HTCR register */
.NoiseSource = 0x24C2, /* RNG_NSCR register */
.AutoReset = RNG_ARDIS_ENABLE,
};HAL_RNGEx_SetConfig() API is called to apply this NIST‑compliant configuration to the RNG peripheral.if (HAL_RNGEx_SetConfig(&hrng, &sRngNistConfigU545) != HAL_OK)
{
/* ERROR: RNG SET CONFIG FAILED */
}| Product(1) | RNG_CR value(2) | HTCR value | NSCR value | Certificate(3) |
|---|---|---|---|---|
| STM32L4P/Q | 0x00F00D00 | 0xAA74 | default | - |
| STM32L5 | 0x00F00D00 | 0xA2B3 | default | - |
| STM32U073x/83x | 0x08F01E00 | 0x6683 | 0x003F | Yes |
| STM32U575/585 | 0x00F00D00 | 0xA2B0 | 0x17CBB | Yes |
| STM32U59x/5Ax | 0x00F11F00 | 0x92F3 | 0x1609 | Yes |
| STM32U535/545 | 0x00F11F00 | 0x76B3 | 0x24C2 | Yes |
| STM32U5Fx/5Gx | 0x00F11F00 | 0xA715 | 0x9049 | Yes |
| STM32H7Rx/7Sx | 0x08F01E00 | 0x6a92 | 0x2F83F | Yes |
| STM32H7A3/7B3 | 0x00F00D00 | 0x72AC | default | - |
| STM32H72x/73x | 0x00F00D00 | 0xAA74 | default | - |
| STM32WLx | 0x00F00D00 | 0xAA74 | default | - |
| STM32H503 | 0x00F00D00 | 0xAAC7 | default | - |
| STM32H523/533 | 0x08F01E00 | 0x06689 | 0x2357F | Yes |
| STM32H543/553 | 0x0845 1F00 | 0xAAC7 | default | - |
| STM32H563/573/562 | 0x00F01E00 | 0x6A91 | 0x3AF66 | Yes |
| STM32H5Ex/5Fx | 0x08451F00 | 0xAAC7 | default | - |
| STM32WBA5x | 0x08F01F00 | 0x6688 | 0x0FFF | Yes |
| STM32MP13x | 0x00F00D00 | 0x668A | 0x2B5BB | Yes |
| STM32MP25x | 0x08F01E00 | 0x6688 | 0x2E649 | Yes |
| STM32U375/385 | 0x08351F00 | 0x6A8B | 0x01FF | - |
| STM32N6 | 0x08F00D00 | 0x6A93(4) | default | - |
| STM32WBA6x | 0x08401F00 | 0x6EA0 | 0x01FF | Yes |
| STM32MP21x | 0x08451F00 | 0x6A8C(4) | 0x1DF | - |
| STM32C5x | 0x08451F00 | 0x6684 | 0x01BF | - |
| Product | SP800-90B entropy source certificate | NIST public use document |
|---|---|---|
| STM32U575/585 | #E11(5) | E11 public use(5) |
| STM32U5Fx/5Gx | #E116(5) | E116 public(5) |
| STM32U59x/5Ax | #E135(5) | E135 public(5) |
| STM32U535x/545x | #E158 | E158 public(5) |
| STM32H56x/573 | #E163(5) | E163 public(5) |
| STM32MP13x | #E53(5) | E53 public use(5) |
| STM32WBA5x | #E186(5) | E186 public(5) |
| STM32U073x/83x | #E262(5) | E262 public(5) |
| STM32H7Rx/7Sx | #E255(5) | E255 public(5) |
| STM32H523/533 | #E283(5) | E283 prblic(5) |
| STM32MP25x | #228(5) | E228 public(5) |
| STM32WBA6x | #299(5) | E299 public(5) |
Entropy results can be shared with customers when required.