MCUXpresso SDK API Reference Manual  Rev 2.15.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
RNG: Random Number Generator

Overview

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

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

Get random data from RNG

  1. RNG_GetRandomData() function gets random data from the RNG module.

This example code shows how to get 128-bit random data from the RNG driver.

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/rng

Functions

void RNG_Init (RNG_Type *base)
 Initializes the RNG. More...
 
void RNG_Deinit (RNG_Type *base)
 Shuts down the RNG. More...
 
status_t RNG_GetRandomData (RNG_Type *base, void *data, size_t dataSize)
 Gets random data. More...
 
static uint32_t RNG_GetRandomWord (RNG_Type *base)
 Returns random 32-bit number. More...
 

Driver version

#define FSL_RNG_DRIVER_VERSION   (MAKE_VERSION(2, 0, 3))
 RNG driver version. More...
 

Macro Definition Documentation

#define FSL_RNG_DRIVER_VERSION   (MAKE_VERSION(2, 0, 3))

Version 2.0.3.

Current version: 2.0.3

Change log:

  • Version 2.0.0
    • Initial version
  • Version 2.0.1
    • Fix MISRA C-2012 issue.
  • Version 2.0.2
    • Add RESET_PeripheralReset function inside RNG_Init and RNG_Deinit functions.
  • Version 2.0.3
    • Modified RNG_Init and RNG_GetRandomData functions, added rng_accumulateEntropy and rng_readEntropy functions.
    • These changes are reflecting recommended usage of RNG according to device UM.

Function Documentation

void RNG_Init ( RNG_Type *  base)

This function initializes the RNG. When called, the RNG module and ring oscillator is enabled.

Parameters
baseRNG base address
Returns
If successful, returns the kStatus_RNG_Success. Otherwise, it returns an error.
void RNG_Deinit ( RNG_Type *  base)

This function shuts down the RNG.

Parameters
baseRNG base address.
status_t RNG_GetRandomData ( RNG_Type *  base,
void *  data,
size_t  dataSize 
)

This function gets random data from the RNG.

Parameters
baseRNG base address.
dataPointer address used to store random data.
dataSizeSize of the buffer pointed by the data parameter.
Returns
random data
static uint32_t RNG_GetRandomWord ( RNG_Type *  base)
inlinestatic

This function gets random number from the RNG.

Parameters
baseRNG base address.
Returns
random number