7.3.1 Crypto_Rng_Generate
crypto_Rng_Status_E Crypto_Rng_Generate(
crypto_HandlerType_E rngHandlerType_en,
uint8_t *ptr_rngData,
uint32_t rngLen,
uint8_t *ptr_nonce,
uint32_t nonceLen,
uint32_t sessionID
);
Description
This API is used to generate random numbers in blocks of bytes.
The provided PRNG entropy source is declared by the following function:
__attribute__((weak)) int Crypto_Rng_Wc_Prng_EntropySource(void);
This function is generic to all boards. As a result, the entropy can be significantly
improved by overriding the __attribute__((weak))
definition with a
custom function that better suits the board being developed for.
Max PRNG size : 0x1000 (~65kB) per buffer.
Parameters
No. | Argument Type | Argument Name | Type | Description |
---|---|---|---|---|
1 | crypto_HandlerType_E | rngHandlerType_en | Input | Enum for crypto operation handler i.e., SW, HW. |
2 | uint8_t* | ptr_rngData | Output | Pointer which holds generated random numbers in bytes. |
3 | uint32_t | rngLen | Input | Length of the random numbers in bytes. |
4 | uint8_t* | ptr_nonce | Input | Pointer Holds of nonce in bytes; It is optional. Pass it NULL when not required. |
5 | uint32_t | nonceLen | Input | Length of nonce length in bytes. It is optional pass it 0 when not required. |
6 | uint32_t | sessionID | Input | It defines the session ID, must be more than zero. |
Returns
Return Type | Description |
---|---|
crypto_Rng_Status_E | Function returns the status of the API. |
Prerequisites
- To use the HW handler, the algorithm must be enabled in Crypto v4 in MPLAB® Code Configurator.
- To use the SW handler, the algorithm must be enabled in wolfCrypt, and linked to Crypto V4 in MPLAB® Code Configurator.
- TRNG Peripheral must be enabled in MPLAB® Code Configurator when using the HW handler.
Example
#define sessionID 1
#define DATA_SIZE 32
crypto_Rng_Status_E status;
crypto_HandlerType_E handlerType_en = CRYPTO_HANDLER_HW_INTERNAL;
uint8_t rngData[32];
status = Crypto_Rng_Generate(
handlerType_en,
rngData,
DATA_SIZE,
NULL, // ptr_nonce
0, // sizeof(nonce)
sessionID
);