58. True random number generator (RNG)

58.1 Introduction

The RNG is a true random number generator that provides full entropy outputs to the application as 32-bit samples. It is composed of a live entropy source (analog) and an internal conditioning component.

The RNG is a NIST SP 800-90B compliant entropy source that can be used to construct a nondeterministic random bit generator (NDRBG).

The RNG true random number generator can be certified NIST SP800-90B. It can also be tested using the German BSI statistical tests of AIS-31 (T0 to T8).

58.2 RNG main features

58.3 RNG functional description

58.3.1 RNG block diagram

Figure 519 shows the RNG block diagram.

Block diagram of the True RNG showing internal components and external interfaces.

Figure 519. RNG block diagram

The diagram illustrates the True RNG architecture, divided into two main clock domains: the AHB clock domain and the RNG clock domain.

External signals include rng_it (digital output), rng_hclk (digital input), rng_clk (digital input), and rng_itamp_out (digital output).

MSv42098V3

Block diagram of the True RNG showing internal components and external interfaces.

58.3.2 RNG internal signals

Table 521 describes a list of useful-to-know internal signals available at the RNG level, not at the STM32 product level (on pads).

Table 521. RNG internal input/output signals

Signal nameSignal typeDescription
rng_itDigital outputRNG global interrupt request
rng_hclkDigital inputAHB clock
rng_clkDigital inputRNG dedicated clock, asynchronous to rng_hclk
rng_itamp_outdigital outputRNG internal tamper event signal to TAMP (XORed), triggered when an unexpected hardware fault occurs. When this signal is triggered, RNG stops delivering random samples, requiring a reset and a new initialization to be usable again.

58.3.3 Random number generation

The true random number generator (RNG) delivers truly random data through its AHB interface at deterministic intervals.

Within its boundary RNG integrates all the required NIST components depicted on Figure 520. Those components are an analog noise source, a digitization stage, a conditioning algorithm, a health monitoring block and two interfaces that are used to interact with the entropy source: GetEntropy and HealthTest.

Figure 520. NIST SP800-90B entropy source model

Block diagram of the NIST SP800-90B entropy source model. The diagram shows a large box labeled 'Entropy source'. Inside this box, from bottom to top, are: 'Noise Source' (with a small icon), 'Digitization', 'Post-processing (optional)', and 'Conditioning (optional)'. A dashed box encloses the 'Noise Source', 'Digitization', and 'Post-processing (optional)' blocks. An arrow labeled 'Raw data' points from the dashed box to the 'Conditioning (optional)' block. To the left of the 'Conditioning (optional)' block is a 'Heath tests' block. A dashed arrow points from 'Conditioning (optional)' to 'Heath tests'. A dashed arrow points from 'Heath tests' to an external 'Error message (HealthTest)' output. A solid arrow points from 'Conditioning (optional)' to an external 'Output (GetEntropy)' output. The label 'MSv44200V3' is in the bottom right corner of the diagram area.
Block diagram of the NIST SP800-90B entropy source model. The diagram shows a large box labeled 'Entropy source'. Inside this box, from bottom to top, are: 'Noise Source' (with a small icon), 'Digitization', 'Post-processing (optional)', and 'Conditioning (optional)'. A dashed box encloses the 'Noise Source', 'Digitization', and 'Post-processing (optional)' blocks. An arrow labeled 'Raw data' points from the dashed box to the 'Conditioning (optional)' block. To the left of the 'Conditioning (optional)' block is a 'Heath tests' block. A dashed arrow points from 'Conditioning (optional)' to 'Heath tests'. A dashed arrow points from 'Heath tests' to an external 'Error message (HealthTest)' output. A solid arrow points from 'Conditioning (optional)' to an external 'Output (GetEntropy)' output. The label 'MSv44200V3' is in the bottom right corner of the diagram area.

The components pictured above are detailed hereafter.

Noise source

The noise source is the component that contains the non-deterministic, entropy-providing activity that is ultimately responsible for the uncertainty associated with the bitstring output by the entropy source. This noise source provides 1-bit samples. It is composed of:

This noise source sampling is independent to the AHB interface clock frequency (rng_hclk), with a possibility for the software to decrease the sampling frequency by using the integrated divider.

Note: In Section 58.6 the recommended RNG clock frequencies and associated divider value are given.

Post processing

In the NIST configuration no post-processing is applied to the sampled noise source. In non-NIST configuration B (as defined in Section 58.6.2) a normalization debiasing is applied,

that is half of the bits are taken from the sampled noise source, half of the bits are taken from the inverted sampled noise source.

Conditioning

The conditioning component in the RNG is a deterministic function that increases the entropy rate of the resulting fixed-length bitstrings output (128-bit). The NIST SP800-90B target is full entropy on the output (128-bit).

The times required between two random number generations, and between the RNG initialization and availability of first sample are described in Section 58.5.

Output buffer

A data output buffer can store up to four 32-bit words that have been output from the conditioning component. When four words have been read from the output FIFO through the RNG_DR register, the content of the 128-bit conditioning output register is pushed into the output FIFO, and a new conditioning round is automatically started. Four new words are added to the conditioning output register after a number of clock cycles specified in Section 58.5.

Whenever a random number is available through the RNG_DR register, the DRDY flag changes from 0 to 1. This flag remains high until the output buffer becomes empty after reading four words from the RNG_DR register.

Note: When interrupts are enabled an interrupt is generated when this data ready flag transitions from 0 to 1. Interrupt is then cleared automatically by the RNG as explained above.

Health checks

This component ensures that the entire entropy source (with its noise source) starts then operates as expected, obtaining assurance that failures are caught quickly and with a high probability and reliability.

The RNG implements the following health check features in accordance with NIST SP800-90B. The described thresholds correspond to the value recommended for register RNG_HTCR (configuration A in Section 58.6.2).

  1. 1. Startup health tests, performed after reset and before the first use of the RNG as entropy source:
    • – Repetition count test, flagging an error when the noise source has provided more than 42 consecutive bits at a constant value (0 or 1).
    • – Adaptive proportion test running on a window of 1024 consecutive bits: the RNG verifies that the first bit on the outputs of the noise source is not repeated more than 711 times.
    • – Known-answer tests, to verify the conditioning stage.
  2. 2. Continuous health tests, running indefinitely on the outputs of the noise source:
    • – Repetition count test, similar to the one running in startup tests.
    • – Adaptive proportion test, similar to the one running in startup tests.
  3. 3. Vendor specific continuous tests
    • – Transition count test, flagging an error when the noise source has delivered more than 32 consecutive occurrences of 2-bit patterns (01 or 10).
    • – Real-time “too slow” sampling clock detector, flagging an error when one RNG clock cycle (before divider) is smaller than AHB clock cycle divided by 32.
  4. 4. On-demand test of digitized noise source (raw data)
    • – Supported by restarting the entropy source and rerunning the startup tests (see software reset sequence in Section 58.3.4: RNG initialization). Other kinds of on-demand testing (software based) are not supported.

The CECS and SECS status bits in the RNG_SR register indicate when an error condition is detected, as detailed in Section 58.3.7: Error management.

Note: An interrupt can be generated when an error is detected.

Above the health test thresholds are modified by changing the value in the RNG_HTCR register. See Section 58.6: RNG entropy source validation for details.

58.3.4 RNG initialization

The RNG simplified state machine is pictured on Figure 521.

After enabling the RNG (RNGEN = 1 in RNG_CR), the following chain of events occurs:

  1. 1. The analog noise source is enabled, and by default the RNG waits 16 cycles of RNG clock cycles (before divider) before starting to sample the analog output and filling the 128-bit conditioning shift register.
  2. 2. The conditioning hardware initializes, automatically triggering startup behavior test on the raw data samples and known-answer tests.
  3. 3. When startup health tests are completed. During this time, three 128-bit noise source samples are used.
  4. 4. The conditioning stage internal input data buffer is filled again with 128-bit and a number of conditioning rounds defined by the RNG configuration (NIST or non-NIST) is performed. The output buffer is then filled with the post processing result.
  5. 5. The output buffer is refilled automatically according to the RNG usage.

The associated initialization time can be found in Section 58.5: RNG processing time.

Figure 521. RNG initialization overview

Flowchart showing RNG initialization steps: 1. Wait for noise source, 2. Start-up health tests, 3. Conditioning keys init, 4. Generate samples, 5. Loop back to Generate samples. Includes transitions to an Error state based on test results and software reset paths.
graph TD
    Start(( )) --> 1[1]
    1 --> Wait[Wait for noise source]
    Wait --> 2[2]
    2 --> Health[Start-up health tests]
    Health --> 3[3]
    3 --> Keys[Conditioning keys init]
    Keys --> 4[4]
    4 --> Samples[Generate samples]
    Samples --> 5[5]
    5 --> Samples
    Health -- "start-up test(s) not OK" --> Error[Error state]
    Samples -- "continuous test(s) not OK" --> Error
    Error -- "Software reset" --> Wait
    Wait -- "Software reset" --> Wait
  

MSv44204V2

Flowchart showing RNG initialization steps: 1. Wait for noise source, 2. Start-up health tests, 3. Conditioning keys init, 4. Generate samples, 5. Loop back to Generate samples. Includes transitions to an Error state based on test results and software reset paths.

Figure 521 also highlights a possible software reset sequence, implemented by:

  1. 1. Writing bits RNGEN = 0 and CONDRST = 1 in the RNG_CR register with the same RNG configuration and a new CLKDIV if needed.
  2. 2. Then writing RNGEN = 1 and CONDRST = 0 in the RNG_CR register.
  3. 3. Wait for random number to be ready, after initialization completes.

Note: When the RNG peripheral is reset through RCC (hardware reset), the RNG configuration for optimal randomness is lost in the RNG registers. Software reset with CONFIGLOCK set preserves the RNG configuration.

58.3.5 RNG operation

Normal operations

To run the RNG using interrupts, the following steps are recommended:

  1. 1. Consult Section 58.6: RNG entropy source validation and verify if a specific RNG configuration is required for the application.
    • – If it is the case, write in the RNG_CR register the bit CONDRST = 1 together with the correct RNG configuration. Then perform a second write to the RNG_CR

register with the bit CONDRST = 0, the interrupt enable bit IE = 1 and the RNG enable bit RNGEN = 1.

    • – If it is not the case perform a write to the RNG_CR register with the interrupt enable bit IE = 1 and the RNG enable bit RNGEN = 1.
  1. 2. An interrupt is now generated when a random number is ready or when an error occurs. Therefore, at each interrupt, check that:
    • – No error occurred. The SEIS and CEIS bits must be set to 0 in the RNG_SR register.
    • – A random number is ready. The DRDY bit must be set to 1 in the RNG_SR register.
    • – If the above two conditions are true the content of the RNG_DR register can be read up to four consecutive times. If valid data is available in the conditioning output buffer, four additional words can be read by the application (in this case the DRDY bit is still high). If one or both of the above conditions are false, the RNG_DR register must not be read. If an error occurred, the error recovery sequence described in Section 58.3.7 must be used.

To run the RNG in polling mode following steps are recommended:

  1. 1. Consult Section 58.6: RNG entropy source validation and verify if a specific RNG configuration is required for the application.
    • – If it is the case write in the RNG_CR register the bit CONDRST = 1 together with the correction RNG configuration. Then perform a second write to the RNG_CR register with the bit CONDRST = 0 and the RNG enable bit RNGEN = 1.
    • – If it is not the case only enable the RNG by setting the RNGEN bit to 1 in the RNG_CR register.
  2. 2. Read the RNG_SR register and check that:
    • – No error occurred (the SEIS and CEIS bits must be set to 0)
    • – A random number is ready (the DRDY bit must be set to 1)
  3. 3. If above conditions are true read the content of the RNG_DR register up to four consecutive times. If valid data is available in the conditioning output buffer four additional words can be read by the application (in this case the DRDY bit is still high). If one or both of the above conditions are false, the RNG_DR register must not be read. If an error occurred, the error recovery sequence described in Section 58.3.7 must be used.

Note: When data is not ready (DRDY = 0) RNG_DR returns zero.

It is recommended to always verify that RNG_DR is different from zero. Because when it is the case a seed error occurred between RNG_SR polling and RND_DR output reading (rare event).

If the random number generation period is a concern to the application and if NIST compliance is not required it is possible to select a faster RNG configuration by using the RNG configuration “B”, described in Section 58.6: RNG entropy source validation. The gain in random number generation speed is summarized in Section 58.5: RNG processing time.

Low-power operations

If the power consumption is a concern to the application, low-power strategies can be used, as described in Section 58.3.8: RNG low-power use.

Software post-processing

No specific software post-processing/conditioning is expected to meet the AIS-31 or NIST SP800-90B approvals.

Built-in health check functions are described in Section 58.3.3: Random number generation.

58.3.6 RNG clocking

The RNG runs on two different clocks: the AHB bus clock and a dedicated RNG clock.

The AHB clock is used to clock the AHB banked registers and conditioning component. The RNG clock, coupled with a programmable divider (see CLKDIV bitfield in the RNG_CR register) is used for noise source sampling. Recommended clock configurations are detailed in Section 58.6: RNG entropy source validation.

Note: When the CED bit in the RNG_CR register is set to 0, the RNG clock frequency before the internal divider must be higher than the AHB clock frequency divided by 32, otherwise the clock checker always flags a clock error (CECS = 1 in the RNG_SR register).

See Section 58.3.1: RNG block diagram for details (AHB and RNG clock domains).

58.3.7 Error management

In parallel to random number generation a health check block verifies the correct noise source behavior and the frequency of the RNG source clock as detailed in this section. Associated error state is also described.

Clock error detection

When the clock error detection is enabled (CED = 0) and if the RNG clock frequency is too low, the RNG sets to 1 both the CEIS and CECS bits to indicate that a clock error occurred. In this case, the application must check that the RNG clock is configured correctly (see Section 58.3.6: RNG clocking) and then it must clear the CEIS bit interrupt flag. The CECS bit is automatically cleared when the clocking condition is normal.

Note: The clock error has no impact on generated random numbers that is the application can still read the RNG_DR register.

CEIS is set only when CECS is set to 1 by RNG.

Noise source error detection

When a noise source (or seed) error occurs, the RNG stops generating random numbers and sets to 1 both SEIS and SECS bits to indicate that a seed error occurred. If a value is available in the RNG_DR register, it must not be used as it may not have enough entropy.

The following sequence must be used to fully recover from a seed error:

  1. 1. Software reset by writing CONDRST at 1 and at 0 (see bitfield description for details). This step is needed only if SECS is set. Indeed, when SEIS is set and SECS is cleared

it means RNG performed the reset automatically (auto-reset). In this case application must clear the SEIS bit interrupt flag.

  1. 2. If SECS was set in step 1 (no auto-reset) wait for CONDRST to be cleared in the RNG_CR register, then confirm that SEIS is cleared in the RNG_SR register. Otherwise, just clear the SEIS bit in the RNG_SR register.
  2. 3. If SECS was set in step 1 (no auto-reset), wait for SECS to be cleared by RNG. The random number generation is now back to normal.

Note: After a seed error RNG restarts generating random numbers when SECS is cleared. When the application sets the ARDIS bit in the RNG_CR register, the auto-reset is disabled. CONDRST must be used in step 1.

RNG tamper errors

When an unexpected error is found by the RNG an internal tamper event is triggered in the TAMP peripheral, and the RNG stops delivering random data.

When this event occurs, the secure application needs to reset the RNG peripheral either using the central reset management or the global SoC reset. Then a proper initialization of the RNG is required, again.

58.3.8 RNG low-power use

If power consumption is a concern, the RNG can be disabled as soon as the DRDY bit is set to 1 by setting the RNGEN bit to 0 in the RNG_CR register. As the post-processing logic and the output buffer remain operational while RNGEN = 0 following features are available to the software:

When disabling the RNG the user deactivates all the analog seed generators, whose power consumption is given in the datasheet electrical characteristics section. The user also gates all the logic clocked by the RNG clock. Note that this strategy is adding latency before a random sample is available on the RNG_DR register, because of the RNG initialization time.

If the RNG block is disabled during initialization (that is well before the DRDY bit rises for the first time), the initialization sequence resumes from where it was stopped when RNGEN bit is set to 1, unless the application resets the conditioning logic using CONDRST bit in the RNG_CR register.

When the application wants to disable the RNG clock it is recommended to wait two RNG kernel clock cycles between clearing the RNGEN bit and disabling the RNG kernel clock using the RCC.

Also, when application needs to enter a power mode where RNG is de-activated, it is recommended to wait two RNG kernel clock cycles between clearing the RNGEN bit and entering the low power mode using the PWR.

In the two cases above, to avoid unexpected consumption when RNG analog oscillators stay active, application can set the bit 13 in RNG_CR register. Setting this bit adds some marginal power consumption while RNGEN bit is set (RNG activated).

Note: The power modes where RNG is deactivated (that is retained or not available) can be found in the PWR section.

58.4 RNG interrupts

In the RNG an interrupt can be produced on the following events:

Dedicated interrupt enable control bits are available as shown in Table 522.

Table 522. RNG interrupt requests

Interrupt acronymInterrupt eventEvent flagEnable control bitInterrupt clear method
RNGData ready flagDRDYIENone (automatic)
Seed error flagSEISIEWrite CONDRST to 1 then to 0 unless ARDIS is cleared (see Section 58.3.7: Error management)
Clock error flagCEISIEWrite 0 to CEIS

The user can enable or disable the above interrupt sources individually by changing the mask bits or the general interrupt control bit IE in the RNG_CR register. The status of the individual interrupt sources can be read from the RNG_SR register.

Note: Interrupts are generated only when RNG is enabled.

58.5 RNG processing time

In recommended configuration A or C described in Table 524, the time between two sets of four 32-bit data is either:

With \(f_{threshold} = 1.6 \times f_{RNG}\), for instance 77 MHz if \(f_{RNG} = 48\) MHz. Value N is defined in Section 58.6: RNG entropy source validation.

Note: When CLKDIV is different from zero, \(f_{RNG}\) must take into account the internal divider ratio.

If configuration B is selected the performance figures become:

with \(f_{threshold} = 6.5 \times f_{RNG}\).

Initialization time

More time is needed for the first set of random numbers after the device exits reset (see Section 1.3.4: RNG initialization). Table below gives details on how to compute the time spent in each initialization step.

Table 523. RNG initialization times

Initialization stepConfiguration A or C, reset valueConfiguratton B
Wait for noise source, then startup health tests\(\text{Max}(\text{wait\_noise}^{(1)} + 11 + 1024 \times \text{CLKDIV})\)
RNG_cycles, 13 × 203 AHB_cycles)
\(\text{Max}(16 + 1035 \text{ RNG\_cycles},\)
13 × 203 AHB\_cycles)
Conditioning keys initialization\(\text{Max}((1+2xN) \times 128 \times \text{CLKDIV})\) RNG_cycles
+ 203 AHB_cycles, (128 × CLKDIV)
RNG_cycles + (2xN+2) × 203 AHB_cycles)
\(\text{Max}(3 \times 32 \text{ RNG\_cycles} + 203 \text{ AHB\_cycles},\)
\(32 \text{ RNG\_cycles} + 4 \times 203 \text{ AHB\_cycles})\)
  1. 1. 192 RNG_cycles (configuration A or C), 16 RNG_cycles (reset value)

As an example, if AHB clock= 200 MHz and RNG clock= 48 MHz then the initialization time is around 56 μs in the configuration C (CLKDIV=2, N=2) and 37 μs in the configuration B.

58.6 RNG entropy source validation

58.6.1 Introduction

In order to assess the amount of entropy available from the RNG, STMicroelectronics has tested the peripheral using the German BSI AIS-31 statistical tests (T0 to T8), and NIST SP800-90B test suite.

58.6.2 Validation conditions

STMicroelectronics has tested the RNG true random number generator in the following conditions:

Table 524. RNG configurations

ConfigurationRNG_CR bitsLoop number (N)RNG_HTCR registerRNG_NCSR register
NISTC bitRNG_CONFIG1 [5:0]CLKDIV [3:0]RNG_CONFIG2 [2:0](1)RNG_CONFIG3 [3:0](2)CED bit
ARefer to NIST compliant RNG configuration table in AN4230 available from www.st.com. This application note also indicates if this configuration is part of an existing NIST SP800-90B Entropy Certificate listed on https://csrc.nist.gov/projects/cryptographic-module-validation-program.

Table 524. RNG configurations (continued)

ConfigurationRNG_CR bitsLoop number (N)RNG_HTCR registerRNG_NCSR register
NISTC bitRNG_CONFIG1 [5:0]CLKDIV [3:0]RNG_CONFIG2 [2:0](1)RNG_CONFIG3 [3:0](2)CED bit
B10x180x0(3)0x00x0010x0000 AAC7(4)default
C00x0F0x00xD02default
  1. 0x1 value is recommended instead of 0x0 for RNG_CONFIG2[2:0], when RNG power consumption is critical. See the end of Section 58.3.8: RNG low-power use for details.
  2. RNG_CONFIG3[1:0] defines the loop number N: 0x0 corresponds to N=1, 0x1 to N=2, 0x2 to N=3, 0x3 to N=4
  3. The noise source sampling must be 32 MHz or less. Hence, if the RNG clock is different from 64 MHz, this value of CLKDIV must be adapted. See the CLKDIV bitfield description in Section 58.7.1 for details.
  4. This value can be fixed in the RNG driver (it doesn't depend on the STM32 family).

Table 525. Configuration selection

Section criteriaConfig AConfig BConfig C
Suitable to generate NIST compliant cryptographic keysYesNo
Entropy(1)CertifiedGoodVery good
Speed(2)BaselineFasterBaseline
  1. For configurations B and C entropy is verified using AIS-31 test suite (T0 to T8).
  2. When speed is not enough for application a NIST compliant DRBG can be used to increase throughput.

For details on data collection and the running of statistical test suites refer to “STM32 microcontrollers random number generation validation using NIST statistical test suite” application note (AN4230) available from www.st.com.

58.7 RNG registers

The RNG is associated with a control register, a data register and a status register.

58.7.1 RNG control register (RNG_CR)

Address offset: 0x000

Reset value: 0x0080 0D00

31302928272625242322212019181716
CONFI GLOCKCOND RSTRes.Res.Res.Res.RNG_CONFIG1[5:0]CLKDIV[3:0]
rsrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
RNG_CONFIG2[2:0]NISTCRNG_CONFIG3[3:0]ARDISRes.CEDRes.IERNGENRes.Res.
rwrwrwrwrwrwrwrwrwrwrw

Bit 7 ARDIS: Auto reset disable

Set this bit to deactivate the auto-reset feature.

0: Auto-reset enabled

1: Auto-reset disabled

Keeping the auto-reset enabled (automatic clearance of the SECS bit) simplifies the management of noise source errors, as described in Section 58.3.7: Error management.

Writing this bit is taken into account only if CONDRST bit is set to 1 in the same access, while CONFIGLOCK remains at 0. Writing to this bit is ignored if CONFIGLOCK = 1.

Bit 6 Reserved, must be kept at reset value.

Bit 5 CED: Clock error detection

0: Clock error detection enabled

1: Clock error detection is disabled

The clock error detection cannot be enabled nor disabled on-the-fly when the RNG is enabled, that is to enable or disable CED, the RNG must be disabled.

Writing this bit is taken into account only if the CONDRST bit is set to 1 in the same access, while CONFIGLOCK remains at 0. Writing to this bit is ignored if CONFIGLOCK = 1.

Bit 4 Reserved, must be kept at reset value.

Bit 3 IE: Interrupt enable

0: RNG interrupt is disabled

1: RNG interrupt is enabled. An interrupt is pending as soon as the DRDY, SEIS, or CEIS is set in the RNG_SR register.

Bit 2 RNGEN: True random number generator enable

0: True random number generator is disabled. Analog noise sources are powered off and logic clocked by the RNG clock is gated.

1: True random number generator is enabled.

Bits 1:0 Reserved, must be kept at reset value.

58.7.2 RNG status register (RNG_SR)

Address offset: 0x004

Reset value: 0x0000 0000

58.7.2column_2Bit 7 Bit 5 Bit 3 Bit 2ARDIS CED: IE: RNGEN:Interrupt enablecolumn_6column_7column_8column_9column_10column_11column_12column_13column_14column_15RM0457 .
31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.SEISCEISRes.Res.SECS CECS DRDY
rc_w0rc_w0rrr
Bit 6SEIS:Seed error interrupt status

Bits 31:7 Reserved, must be kept at reset value.

Bit 6 SEIS: Seed error interrupt status

This bit is set at the same time as SECS. It is cleared by writing 0 (unless CONDRST is used). Writing 1 has no effect.

0: No faulty sequence detected

1: At least one faulty sequence is detected. See SECS bit description for details.

An interrupt is pending if IE = 1 in the RNG_CR register.

Bit 5 CEIS: Clock error interrupt status

This bit is set at the same time as CECS. It is cleared by writing 0. Writing 1 has no effect.

0: The RNG clock is correct (\(f_{\text{RNGCLK}} > f_{\text{HCLK}}/32\))

1: The RNG clock before the internal divider is detected too slow (\(f_{\text{RNGCLK}} < f_{\text{HCLK}}/32\))

An interrupt is pending if IE = 1 in the RNG_CR register.

Bits 4:3 Reserved, must be kept at reset value.

Bit 2 SECS: Seed error current status

0: No faulty sequence has currently been detected. If the SEIS bit is set, this means that a faulty sequence was detected and the situation has been recovered.

1: At least one of the following faulty sequences has been detected:

Bit 1 CECS: Clock error current status

0: The RNG clock is correct (\(f_{\text{RNGCLK}} > f_{\text{HCLK}}/32\)). If the CEIS bit is set, this means that a slow clock was detected and the situation has been recovered.

1: The RNG clock is too slow (\(f_{\text{RNGCLK}} < f_{\text{HCLK}}/32\)).

Note: CECS bit is valid only if the CED bit in the RNG_CR register is set to 0.

Bit 0 DRDY: Data ready

0: The RNG_DR register is not yet valid, no random data is available.

1: The RNG_DR register contains valid random data.

Once the output buffer becomes empty (after reading the RNG_DR register), this bit returns to 0 until a new random value is generated.

Note: The DRDY bit can rise when the peripheral is disabled (RNGEN = 0 in the RNG_CR register).

If IE=1 in the RNG_CR register, an interrupt is generated when DRDY = 1.

58.7.3 RNG data register (RNG_DR)

Address offset: 0x008

Reset value: 0x0000 0000

The RNG_DR register is a read-only register that delivers a 32-bit random value when read. The content of this register is valid when the DRDY = 1 and the value is not 0x0, even if RNGEN = 0.

31302928272625242322212019181716
RNDATA[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
RNDATA[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 RNDATA[31:0]: Random data

32-bit random data, which are valid when DRDY = 1. When DRDY = 0, the RNDATA value is zero.

When DRDY is set, it is recommended to always verify that RNG_DR is different from zero. The zero value means that a seed error occurred between RNG_SR polling and RND_DR output reading (a rare event).

58.7.4 RNG noise source control register (RNG_NSCR)

Address offset: 0x00C

Reset value: 0x0003 FFFF

Writing in RNG_NSCR is taken into account only if the CONDRST bit is set, and the CONFIGLOCK bit is cleared in RNG_CR. Writing to this register is ignored if CONFIGLOCK= 1.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.EN_OSC6[2:1]
rwrw
1514131211109876543210
EN_OSC6[0]EN_OSC5[2:0]EN_OSC4[2:0]EN_OSC3[2:0]EN_OSC2[2:0]EN_OSC1[2:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:18 Reserved, must be kept at reset value.

Bits 17:15 EN_OSC6[2:0]:

When the RNG is enabled (RNGEN bit set), each bit of this bitfield enables one of the three inputs from the oscillator instance number 6. The bitfield has no effect otherwise.

Bits 14:12 EN_OSC5[2:0]:

When the RNG is enabled (RNGEN bit set), each bit of this bitfield enables one of the three inputs from the oscillator instance number 5. The bitfield has no effect otherwise.

Bits 11:9 EN_OSC4[2:0]:

When the RNG is enabled (RNGEN bit set), each bit of this bitfield enables one of the three inputs from the oscillator instance number 4. The bitfield has no effect otherwise.

Bits 8:6 EN_OSC3[2:0]:

When the RNG is enabled (RNGEN bit set), each bit of this bitfield enables one of the three inputs from the oscillator instance number 3. The bitfield has no effect otherwise.

Bits 5:3 EN_OSC2[2:0]:

When the RNG is enabled (RNGEN bit set), each bit of this bitfield enables one of the three inputs from the oscillator instance number 2. The bitfield has no effect otherwise.

Bits 2:0 EN_OSC1[2:0]:

When the RNG is enabled (RNGEN bit set), each bit of this bitfield enables one of the three inputs from the oscillator instance number 1. The bitfield has no effect otherwise.

58.7.5 RNG health test control register (RNG_HTCR)

Address offset: 0x010

Reset value: 0x0000 72AC

Writing in RNG_HTCR is taken into account only if the CONDRST bit is set, and the CONFIGLOCK bit is cleared in the RNG_CR. Writing to this register is ignored if CONFIGLOCK=1.

31302928272625242322212019181716
HTCFG[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
HTCFG[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 HTCFG[31:0]: health test configuration

This configuration is used by RNG to configure the health tests. See Section 58.6: RNG entropy source validation for the recommended value.

Note: The RNG behavior, including the read to this register, is not guaranteed if a different value from the recommended value is written.

58.7.6 RNG hardware configuration register (RNG_HWCFGR)

Address offset: 0x3F0

Reset value: 0x0000 0306

31302928272625242322212019181716
ResResResResResResResResResResResResResResResRes
1514131211109876543210
CFG2[7:0]CFG1[7:0]
rrrrrrrrrrrrrrrr

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:8 CFG2[7:0]: Hardware generic 2

This bitfield returns the number of RNG buses (rngbus_nb).

Bits 7:0 CFG1[7:0]: Hardware generic 1

This field returns the triple_oscillator_nb generic value (0x6).

58.7.7 RNG version register (RNG_VERR)

Address offset: 0x3F4

Reset value: 0x0000 0043

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:4 MAJREV[3:0]: RNG major revision

Bits 3:0 MINREV[3:0]: RNG minor revision

58.7.8 RNG identification register (RNG_IPIDR)

Address offset: 0x3F8

Reset value: 0x0017 0041

31302928272625242322212019181716
ID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
ID[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 ID[31:0]: RNG identification code

58.7.9 RNG size identification register (RNG_SIDR)

Address offset: 0x3FC

Reset value: 0xA3C5 DD01

31302928272625242322212019181716
SID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
SID[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 SID[31:0]: RNG size identification code

Bits[31:8] = 0xA3C5DD (fixed code)

Bits[7:0] = 0x01 (1 Kbyte address decoding)

58.7.10 RNG register map

Table 526. RNG register map and reset map

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x000RNG_CRCONFIGLOCKCONDRSTRes.Res.Res.Res.RNG_CONFIG1[5:0]CLKDIV[3:0]RNG_CONFIG2[2:0]NISTCRNG_CONFIG3[3:0]ARDISRes.CEDRes.IERNGENRes.Res.
Reset value000010000000000011010000
0x004RNG_SRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SEISCEISRes.Res.SECSCECSDRDY
Reset value00000
0x008RNG_DRRNDATA[31:0]
Reset value00000000000000000000000000000000
0x00CRNG_NSCRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.EN_OSC6[2:0]EN_OSC5[2:0]EN_OSC4[2:0]EN_OSC3[2:0]EN_OSC2[2:0]EN_OSC1[2:0]
Reset value11111111111111111
0x010RNG_HTCRHTCFG[31:0]
Reset value00000000000000000111001010101100
0x3EC
0x20C
ReservedReserved
0x3F0RNG_HWCFGRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CFG2[7:0]CFG1[7:0]
Reset value00000000000000000
0x3F4RNG_VERRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
Reset value01000011
0x3F8RNG_IPIDRID[31:0]
Reset value00000000000101110000000001000001
0x3FCRNG_SIDRSID[31:0]
Reset value10100011110001011101110100000001
Refer to Section 2.4: Memory organization for the register boundary addresses.