Hardware Abstraction Layer (HAL)
All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
TRNG (True Random Number Generator)

General Description

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

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

Features

Note
This driver is not intended to be used directly as a security library, but can be used in a security context. If a full security library is needed something like Mbed TLS should be used instead.

Quick Start

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;
mtb_hal_trng_t trng_obj;
uint32_t rnd_num;
// Initialize the true random number generator block
rslt = mtb_hal_trng_setup(&trng_obj, &config);
#if defined(CY_IP_MXCRYPTO)
// Perform PDL initialization. This varies by IP, e.g. for the MXCRYPTO IP:
Cy_Crypto_Core_Enable(trng_obj.base);
#endif /* defined(CY_IP_MXCRYPTO) */
// Generate a true random number
rslt = mtb_hal_trng_get_uint32(&trng_obj, &rnd_num);
void * mtb_hal_trng_configurator_t
TRNG configurator struct.
Definition: mtb_hal_hw_types_trng.h:54
__STATIC_INLINE cy_rslt_t mtb_hal_trng_setup(mtb_hal_trng_t *obj, const mtb_hal_trng_configurator_t *config)
Sets up a HAL instance to use the specified hardware resource.
Definition: mtb_hal_trng_impl.h:63
cy_rslt_t mtb_hal_trng_get_uint32(const mtb_hal_trng_t *obj, uint32_t *value)
Get a random uint32_t number.
uint32_t cy_rslt_t
Provides the result of an operation as a structured bitfield.
Definition: cy_result.h:457

API Reference

 TRNG HAL Results
 TRNG specific return codes.
 

Functions

cy_rslt_t mtb_hal_trng_get_uint32 (const mtb_hal_trng_t *obj, uint32_t *value)
 Get a random uint32_t number. More...
 

Function Documentation

◆ mtb_hal_trng_get_uint32()

cy_rslt_t mtb_hal_trng_get_uint32 ( const mtb_hal_trng_t *  obj,
uint32_t *  value 
)

Get a random uint32_t number.

Parameters
[in]objThe TRNG object
[out]valueLocation to store the random number
Returns
Status of number generation request

See Simple TRNG number generation example