MCUX CLNS
MCUX Crypto Library Normal Secure
 
Loading...
Searching...
No Matches
mcuxClExample_RNG_Helper.h
1/*--------------------------------------------------------------------------*/
2/* Copyright 2022-2024 NXP */
3/* */
4/* NXP Proprietary. 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 */
10/* license terms, then you may not retain, install, activate or otherwise */
11/* use the 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>
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) > 0u)?(((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 MCUX_CSSL_ANALYSIS_START_PATTERN_CAST_TO_MORE_SPECIFIC_TYPE() \
39 mcuxClRandom_Context_t pRng_ctx = (mcuxClRandom_Context_t)context; \
40 MCUX_CSSL_ANALYSIS_STOP_PATTERN_CAST_TO_MORE_SPECIFIC_TYPE() \
41 \
42 /* Initialize the RNG context */ \
43 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(randomInit_result, randomInit_token, mcuxClRandom_init( \
44 pSession, \
45 MCUX_CSSL_ANALYSIS_START_SUPPRESS_POINTER_INCOMPATIBLE("pRng_ctx has the correct type and the cast was safe and valid.") \
46 pRng_ctx, \
47 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_POINTER_INCOMPATIBLE() \
48 mode)); \
49 if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_init) != randomInit_token) || (MCUXCLRANDOM_STATUS_OK != randomInit_result)) \
50 { \
51 return MCUXCLEXAMPLE_STATUS_ERROR; \
52 } \
53 MCUX_CSSL_FP_FUNCTION_CALL_END(); \
54 /* Initialize the PRNG */ \
55 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(prngInit_result, prngInit_token, mcuxClRandom_ncInit(pSession)); \
56 if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_ncInit) != prngInit_token) || (MCUXCLRANDOM_STATUS_OK != prngInit_result)) \
57 { \
58 return MCUXCLEXAMPLE_STATUS_ERROR; \
59 } \
60 MCUX_CSSL_FP_FUNCTION_CALL_END();
61
62#define MCUXCLEXAMPLE_INITIALIZE_PRNG(session) \
63 /* Initialize the PRNG */ \
64 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(prngInit_result, prngInit_token, mcuxClRandom_ncInit(session)); \
65 if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_ncInit) != prngInit_token) || (MCUXCLRANDOM_STATUS_OK != prngInit_result)) \
66 { \
67 return MCUXCLEXAMPLE_STATUS_ERROR; \
68 } \
69 MCUX_CSSL_FP_FUNCTION_CALL_END();
70
71#endif /* MCUXCLEXAMPLE_RNG_HELPER_H_ */
Definition of function identifiers for the flow protection mechanism.
Top level header of mcuxClRandom component.
Top level header of mcuxClRandomModes component.
Provides the API for the CSSL flow protection mechanism.