TRNG (True Random Number Generator)

group group_hal_trng

High level interface to the True Random Number Generator (TRNG).

This block uses dedicated hardware to efficiently generate true random numbers.

Features

  • Number generated is statistically random

  • Based on physical processes exhibiting random variation

  • Generated sequences of numbers cannot be duplicated by running the process again

  • Uses polynomial generators with fixed and programmable polynomials

note

This driver is not intended to be used as a security library. If a full security library is needed something like Mbed TLS should be used instead.

Quick Start

cyhal_trng_init initializes the TRNG and passes a pointer to the TRNG block through the obj object of type cyhal_trng_t.

See Simple TRNG number generation example.

Simple TRNG number generation example

The following snippet initializes a TRNG and generates a true random number.


    cy_rslt_t    rslt;
    cyhal_trng_t trng_obj;
    uint32_t     rnd_num;

    // Initialize the true random number generator block
    rslt = cyhal_trng_init(&trng_obj);

    // Generate a true random number
    rnd_num = cyhal_trng_generate(&trng_obj);

    // Release the true random number generator block
    // Note: Free only if not required anymore
    cyhal_trng_free(&trng_obj);

Functions

cy_rslt_t cyhal_trng_init(cyhal_trng_t *obj)

Initialize the random number generator.

Returns CY_RSLT_SUCCESS if the operation was successful

Parameters

obj[out] Pointer to a random number generator object. The caller must allocate the memory for this object but the init function will initialize its contents.

Returns

The status of the init request

void cyhal_trng_free(cyhal_trng_t *obj)

Release the random number generator.

Parameters

obj[inout] The random number generator object

uint32_t cyhal_trng_generate(const cyhal_trng_t *obj)

Generate a random number.

See Simple TRNG number generation example

Parameters

obj[in] The random number generator object

Returns

The random number generated