MCUX CLNS
MCUX Crypto Library Normal Secure
rng_prng_get_random.c

Example of getting a random number from PRNG of CSSv2 (CLNS component mcuxClCss)

/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
#include <mcuxClCss.h> // Interface to the entire mcuxClCss component
#include <mcuxCsslFlowProtection.h> // Code flow protection
#include <stdbool.h> // bool type for the example's return code
void)
{
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(result, token, mcuxClCss_Enable_Async()); // Enable the CSSv2.
// mcuxClCss_Enable_Async is a flow-protected function: Check the protection token and the return value
return false;
// PRNG needs to be initialized; this can be done by calling mcuxClCss_KeyDelete_Async (delete any key slot, can be empty)
// mcuxClCss_KeyDelete_Async is a flow-protected function: Check the protection token and the return value
return false; // Expect that no error occurred, meaning that the mcuxClCss_KeyDelete_Async operation was started.
// Wait for operation to finish
// mcuxClCss_WaitForOperation is a flow-protected function: Check the protection token and the return value
return false; // Expect that no error occurred, meaning that the mcuxClCss_WaitForOperation operation was started.
uint32_t dummy;
// mcuxClCss_Prng_GetRandomWord is a flow-protected function: Check the protection token and the return value
return false; // Expect that no error occurred, meaning that the mcuxClCss_Prng_GetRandomWord operation was started.
uint32_t random[16]; // buffers of 16 CPU words to be filled with random numbers from PRNG.
// fill the buffer with random numbers from PRNG.
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(result, token, mcuxClCss_Prng_GetRandom((uint8_t*) random, sizeof(random)));
// mcuxClCss_Prng_GetRandom is a flow-protected function: Check the protection token and the return value
return false; // Expect that no error occurred, meaning that the mcuxClCss_Prng_GetRandom operation was started.
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(result, token, mcuxClCss_Disable()); // Disable the CSSv2.
// mcuxClCss_Disable is a flow-protected function: Check the protection token and the return value
return false;
return true;
}