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 <mcuxClRandomModes.h>
21 #include <mcuxCsslFlowProtection.h>
23 
24 // always allocate a minimum size buffer to avoid issues
25 // The size is given in bytes and allocated in words
26 #define MCUXCLEXAMPLE_ALLOCATE_RNG_CTXT(rngCtxLength) (rngCtxLength?((rngCtxLength + sizeof(uint32_t) - 1u) / sizeof(uint32_t)):1u)
27 
28 
36 #define MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_RNG(pSession, rngCtxLength, mode) \
37  uint32_t context[MCUXCLEXAMPLE_ALLOCATE_RNG_CTXT(rngCtxLength)] = {0}; \
38  mcuxClRandom_Context_t pRng_ctx = (mcuxClRandom_Context_t)context; \
39  \
40  /* Initialize the RNG context */ \
41  MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(randomInit_result, randomInit_token, mcuxClRandom_init(pSession, \
42  pRng_ctx, \
43  mode)); \
44  if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_init) != randomInit_token) || (MCUXCLRANDOM_STATUS_OK != randomInit_result)) \
45  { \
46  return MCUXCLEXAMPLE_STATUS_ERROR; \
47  } \
48  MCUX_CSSL_FP_FUNCTION_CALL_END(); \
49  /* Initialize the PRNG */ \
50  MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(prngInit_result, prngInit_token, mcuxClRandom_ncInit(pSession)); \
51  if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_ncInit) != prngInit_token) || (MCUXCLRANDOM_STATUS_OK != prngInit_result)) \
52  { \
53  return MCUXCLEXAMPLE_STATUS_ERROR; \
54  } \
55  MCUX_CSSL_FP_FUNCTION_CALL_END();
56 
57 #define MCUXCLEXAMPLE_INITIALIZE_PRNG(session) \
58  /* Initialize the PRNG */ \
59  MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(prngInit_result, prngInit_token, mcuxClRandom_ncInit(session)); \
60  if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_ncInit) != prngInit_token) || (MCUXCLRANDOM_STATUS_OK != prngInit_result)) \
61  { \
62  return MCUXCLEXAMPLE_STATUS_ERROR; \
63  } \
64  MCUX_CSSL_FP_FUNCTION_CALL_END();
65 
66 #endif /* MCUXCLEXAMPLE_RNG_HELPER_H_ */
Top level header of mcuxClRandomModes component.
Top level header of mcuxClRandom component.
Definition of function identifiers for the flow protection mechanism.
Provides the API for the CSSL flow protection mechanism.