8.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.

Parameters

No.Argument TypeArgument NameTypeDescription
1crypto_HandlerType_ErngHandlerType_enInputEnum for crypto operation handler i.e., SW, HW.
2uint8_t*ptr_rngDataOutputPointer which holds generated random numbers in bytes.
3uint32_trngLenInputLength of the random numbers in bytes.
4uint8_t*ptr_nonceInputPointer Holds of nonce in bytes; It is optional. Pass it NULL when not required.
5uint32_tnonceLenInputLength of nonce length in bytes . It is optional pass it 0 when not required.
6uint32_tsessionIDInputIt defines the session ID, must be more than zero.

Returns

Return TypeDescription
crypto_Rng_Status_EFunction returns the status of the API.

Example

#define sessionID 1
crypto_Kas_Status_E status;
crypto_HandlerType_E handlerType_en = CRYPTO_HANDLER_HW_INTERNAL;

uint8_t rngData[32]; 
uint32_t dataLen = sizeof(inputData);
uint8_t nonce[32] = {/*data*/};
uint32_t nonceLen = sizeof(nonce);


status = Crypto_Rng_Generate(
    handlerType_en,
    rngData, 
    dataLen, 
    nonce, 
    nonceLen, 
    sessionID
    );