MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
TRNG: True Random Number Generator

The MCUXpresso SDK provides a peripheral driver for the True Random Number Generator (TRNG) module of MCUXpresso SDK devices.

The True Random Number Generator is a hardware accelerator module that generates a 512-bit entropy as needed by an entropy consuming module or by other post processing functions. A typical entropy consumer is a pseudo random number generator (PRNG) which can be implemented to achieve both true randomness and cryptographic strength random numbers using the TRNG output as its entropy seed. The entropy generated by a TRNG is intended for direct use by functions that generate secret keys, per-message secrets, random challenges, and other similar quantities used in cryptographic algorithms.

TRNG Initialization

  1. Define the TRNG user configuration structure. Use TRNG_InitUserConfigDefault() function to set it to default TRNG configuration values.
  2. Initialize the TRNG module, call the TRNG_Init() function, and pass the user configuration structure. This function automatically enables the TRNG module and its clock. After that, the TRNG is enabled and the entropy generation starts working.
  3. To disable the TRNG module, call the TRNG_Deinit() function.

Get random data from TRNG

  1. TRNG_GetRandomData() function gets random data from the TRNG module.

This example code shows how to initialize and get random data from the TRNG driver.

{
trng_user_config_t trngConfig;
status_t status;
uint32_t data;
/* Initialize TRNG configuration structure to default.*/
TRNG_InitUserConfigDefault(&trngConfig);
/* Initialize TRNG */
status = TRNG_Init(TRNG0, &trngConfig);
if (status == kStatus_Success)
{
/* Read Random data*/
if((status = TRNG_GetRandomData(TRNG0, data, sizeof(data))) == kStatus_TRNG_Success)
{
/* Print data*/
PRINTF("Random = 0x%X\r\n", i, data );
PRINTF("Succeed.\r\n");
}
else
{
PRINTF("TRNG failed! (0x%x)\r\n", status);
}
/* Deinitialize TRNG*/
TRNG_Deinit(TRNG0);
}
else
{
PRINTF("TRNG initialization failed!\r\n");
}
}