MCUX CLNS
MCUX Crypto Library Normal Secure
mcuxClExample_RNG_Helper.h
1 /*--------------------------------------------------------------------------*/
2 /* Copyright 2022-2023 NXP */
3 /* */
4 /* NXP Confidential. This software is owned or controlled by NXP and may */
5 /* only be used strictly in accordance with the applicable license terms. */
6 /* By expressly accepting such terms or by downloading, installing, */
7 /* activating and/or otherwise using the software, you are agreeing that */
8 /* you have read, and that you agree to comply with and are bound by, such */
9 /* license terms. If you do not agree to be bound by the applicable license */
10 /* terms, then you may not retain, install, activate or otherwise use the */
11 /* software. */
12 /*--------------------------------------------------------------------------*/
13 
14 #ifndef MCUXCLEXAMPLE_RNG_HELPER_H_
15 #define MCUXCLEXAMPLE_RNG_HELPER_H_
16 
17 #include <mcuxClConfig.h> // Exported features flags header
18 #include <mcuxClCore_Platform.h>
19 #include <mcuxClRandom.h>
20 #include <mcuxCsslFlowProtection.h>
22 
23 // always allocate a minimum size buffer to avoid issues
24 // The size is given in bytes and allocated in words
25 #define MCUXCLEXAMPLE_ALLOCATE_RNG_CTXT(rngCtxLength) (rngCtxLength?((rngCtxLength + sizeof(uint32_t) - 1u) / sizeof(uint32_t)):1u)
26 
27 
35 #define MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_RNG(pSession, rngCtxLength, mode) \
36  uint32_t context[MCUXCLEXAMPLE_ALLOCATE_RNG_CTXT(rngCtxLength)] = {0}; \
37  mcuxClRandom_Context_t pRng_ctx = (mcuxClRandom_Context_t)context; \
38  \
39  /* Initialize the RNG context */ \
40  MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(randomInit_result, randomInit_token, mcuxClRandom_init(pSession, \
41  pRng_ctx, \
42  mode)); \
43  if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_init) != randomInit_token) || (MCUXCLRANDOM_STATUS_OK != randomInit_result)) \
44  { \
45  return MCUXCLEXAMPLE_ERROR; \
46  } \
47  MCUX_CSSL_FP_FUNCTION_CALL_END(); \
48  /* Initialize the PRNG */ \
49  MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(prngInit_result, prngInit_token, mcuxClRandom_ncInit(pSession)); \
50  if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_ncInit) != prngInit_token) || (MCUXCLRANDOM_STATUS_OK != prngInit_result)) \
51  { \
52  return MCUXCLEXAMPLE_ERROR; \
53  } \
54  MCUX_CSSL_FP_FUNCTION_CALL_END();
55 
56 #endif /* MCUXCLEXAMPLE_RNG_HELPER_H_ */
Top level header of mcuxClRandom component.
Definition of function identifiers for the flow protection mechanism.
Provides the API for the CSSL flow protection mechanism.