PSOC E8XXGP Device Support Library

| PSOC E8XXGP Device Support Library

API Reference | Functions
TRNG (True Random Number Generator)
HAL API Reference » HAL Drivers

## General Description

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 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;
mtb_hal_trng_configurator_t config;
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);
Cy_Crypto_Core_Enable
cy_en_crypto_status_t Cy_Crypto_Core_Enable(CRYPTO_Type *base)
The function to enable the Crypto hardware.
Definition: cy_crypto_core_hw.c:459
mtb_hal_trng_t::base
CRYPTO_Type * base
Base address of CRYPTO IP instance.
Definition: mtb_hal_hw_types_trng_crypto.h:53
mtb_hal_trng_t
RNG object.
Definition: mtb_hal_hw_types_trng_crypto.h:52
mtb_hal_trng_configurator_t
void * mtb_hal_trng_configurator_t
TRNG configurator struct.
Definition: mtb_hal_hw_types_trng.h:54
mtb_hal_trng_setup
__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
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.
cy_rslt_t
uint32_t cy_rslt_t
Provides the result of an operation as a structured bitfield.
Definition: cy_result.h:459

## 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] | obj | The TRNG object
  [out] | value | Location to store the random number

Returns
  Status of number generation request

See Simple TRNG number generation example