MCUX CLNS
MCUX Crypto Library Normal Secure
Loading...
Searching...
No Matches
mcuxClExample_RNG_Helper.h
1/*--------------------------------------------------------------------------*/
2/* Copyright 2022-2023, 2025 NXP */
3/* */
4/* NXP Confidential and Proprietary. This software is owned or controlled */
5/* by NXP and may only be used strictly in accordance with the applicable */
6/* license terms. By expressly accepting such terms or by downloading, */
7/* installing, activating and/or otherwise using the software, you are */
8/* agreeing that you have read, and that you agree to comply with and are */
9/* bound by, such license terms. If you do not agree to be bound by the */
10/* applicable license terms, then you may not retain, install, activate or */
11/* otherwise 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?((rngCtxLength + sizeof(uint32_t) - 1u) / sizeof(uint32_t)):1u)
27
34
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_STATUS_ERROR; \
46 } \
47 MCUX_CSSL_FP_FUNCTION_CALL_END(); \
48 \
49 MCUXCLEXAMPLE_INITIALIZE_PRNG(pSession);
50
51
52#define MCUXCLEXAMPLE_INITIALIZE_PRNG(session) \
53 /* Initialize the PRNG */ \
54 MCUX_CSSL_ANALYSIS_START_SUPPRESS_DEREFERENCE_NULL_POINTER("session->apiCall is not NULL") \
55 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(prngInit_result, prngInit_token, mcuxClRandom_ncInit(session)); \
56 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DEREFERENCE_NULL_POINTER() \
57 if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClRandom_ncInit) != prngInit_token) || (MCUXCLRANDOM_STATUS_OK != prngInit_result)) \
58 { \
59 return MCUXCLEXAMPLE_STATUS_ERROR; \
60 } \
61 MCUX_CSSL_FP_FUNCTION_CALL_END()
62
63#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.