MCUX CLNS
MCUX Crypto Library Normal Secure
Loading...
Searching...
No Matches
mcuxClRandom_PRNG_Seed_example.c

Example for the mcuxClRandom component with seeding for Prng.

Example for the mcuxClRandom component with seeding for Prng

/*--------------------------------------------------------------------------*/
/* Copyright 2025 NXP */
/* */
/* NXP Confidential and Proprietary. 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 <mcuxClCore_Examples.h> // Defines and assertions for examples
#include <mcuxClCore_FunctionIdentifiers.h> // Code flow protection
#include <mcuxClToolchain.h>
#include <mcuxClBuffer.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClRandom.h>
#include <mcuxClSession.h>
#define randomDataSize (16u)
#define randomDataWordSize ((randomDataSize) / sizeof(uint32_t))
MCUXCLEXAMPLE_FUNCTION(mcuxClRandom_PRNG_Seed_example)
{
/**************************************************************************/
/* Preparation */
/**************************************************************************/
/**************************************************************************/
/* In mcuxClSession_init(), the PRNG seed will be reseeded. */
/* A reseed is neccessary after an SGI restart/flush because the seed is */
/* initialized at 0x00. */
/**************************************************************************/
mcuxClSession_Descriptor_t sessionDesc;
mcuxClSession_Handle_t session = &sessionDesc;
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session, MCUXCLRANDOM_NCINIT_WACPU_SIZE, 0u);
/* Initialize PRNG. This initializes PRNG in normal / unpatched mode */
MCUX_CSSL_ANALYSIS_START_SUPPRESS_DEREFERENCE_NULL_POINTER("session->apiCall is not NULL when accessed")
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(nci_status, nci_token, mcuxClRandom_ncInit(session));
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DEREFERENCE_NULL_POINTER()
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Generate data for the first time */
/**************************************************************************/
uint32_t pPrngData1[randomDataWordSize];
MCUXCLBUFFER_INIT(pPrngBuffer1, session, pPrngData1, randomDataSize);
/* Generate non cryptographic random values. */
ncg_status1,
ncg_token1,
mcuxClRandom_ncGenerate(session, pPrngBuffer1, randomDataSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Reseed the PRNG */
/**************************************************************************/
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(ncr_status, ncr_token, mcuxClRandom_ncReseed(session));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Generate data for the second time */
/**************************************************************************/
uint8_t pPrngData2[randomDataSize];
MCUXCLBUFFER_INIT(pPrngBuffer2, session, pPrngData2, randomDataSize);
/* Generate non cryptographic random values. */
ncg_status2,
ncg_token2,
mcuxClRandom_ncGenerate(session, pPrngBuffer2, randomDataSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Cleanup */
/**************************************************************************/
if(!mcuxClExample_Session_Clean(session))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
Top-level include file for the mcuxClBuffer component.
Definition of function identifiers for the flow protection mechanism.
Top level header of mcuxClRandom component.
Top-level include file for the mcuxClSession component.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLBUFFER_INIT(name, info, ptr, size)
Initialize an input/output buffer (mcuxCl_Buffer_t).
Definition mcuxClBuffer.h:67
mcuxClRandom_Status_t mcuxClRandom_ncReseed(mcuxClSession_Handle_t pSession)
Non-cryptographic PRNG reseed function.
mcuxClRandom_Status_t mcuxClRandom_ncInit(mcuxClSession_Handle_t pSession)
Non-cryptographic PRNG initialization function.
mcuxClRandom_Status_t mcuxClRandom_ncGenerate(mcuxClSession_Handle_t pSession, mcuxCl_Buffer_t pOut, uint32_t outLength)
Non-cryptographic PRNG data generation function.
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:98
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:623
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:777
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:658
#define MCUXCLRANDOM_STATUS_OK
Random function returned successfully.
Definition mcuxClRandom_Constants.h:46