Module imxrt_hal::trng[][src]

True Random Number Generator (TRNG)

Provides basic support for the True Random Number Generator. The TRNG generates truly random data and is intended for use as a generator of entropy.

The TRNG is fairly slow - 15 minutes to an hour to generate 1 megabyte - so it probably should only be used to generate a relatively small amount of entropy for a cryptographic algorithm. Occasionally retrieving entropy from it won’t necessarily need to block, as this driver retrieves 512 bits at a time.

RngCore Support

When the crate feature rand_core is enabled, the TRNG can be wrapped in a struct that implements rand_core’s RngCore trait (via into_rng()). The rand crate’s Rng trait automatically implements high-level functions on top of RngCore.

This feature is opt-in because Cargo’s current feature resolution may trigger a build failure (or require the use of an unstable Cargo feature) if any dev-dependency has enabled the std feature of rand_core.

Note that only the try_fill_bytes function of RngCore allows reporting an error. The others will panic if the TRNG reports an error. Errors appear to be extremely rare in the default configuration (none were seen over 3GB of data), but it’s possible they will be more common in certain situations, such as extreme temperatures or an inconsistent power supply. The non-public Security Reference Manual may have more information.

If you intend to use the RngCore wrapper, you should increase the retry count before clocking the TRNG.

Structs

Error

A TRNG error occurred, such as a statistical test failing.

ErrorFlags

Specific errors that may occur during entropy generation

InvalidRetryCountError

The specified retry count was outside of the valid range of 1..=15.

TRNG

The True Random Number Generator.

Unclocked

The TRNG, not yet enabled.

Enums

SampleMode

TRNG sampling mode