MCUX CLNS
MCUX Crypto Library Normal Secure
 
Loading...
Searching...
No Matches
mcuxClExample_Session_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_SESSION_HELPER_H_
15#define MCUXCLEXAMPLE_SESSION_HELPER_H_
16
17#include <mcuxClConfig.h> // Exported features flags header
18#include <mcuxClCore_Platform.h>
19#include <mcuxClSession.h>
22#include <platform_specific_headers.h>
23
31/* Macros to make sure some memory is always allocated to avoid issues */
32#define MCUXCLEXAMPLE_ALLOCATE_CPUWA(cpuWaLength) \
33 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
34 ((((sizeof(uint32_t)) <= (cpuWaLength))?(cpuWaLength):sizeof(uint32_t)) / (sizeof(uint32_t))) \
35 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
36#define MCUXCLEXAMPLE_ALLOCATE_PKCWA(pkcWaLength) \
37 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
38 ((((sizeof(uint32_t)) <= (pkcWaLength))?(pkcWaLength):sizeof(uint32_t)) / (sizeof(uint32_t))) \
39 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
40
41#define MCUXCLEXAMPLE_MAX_WA(a, b) \
42 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
43 (((a) > (b)) ? (a) : (b)) \
44 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
45
46#define MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(pSession, cpuWaLength, pkcWaLength) \
47 uint32_t cpuWaBuffer[MCUXCLEXAMPLE_ALLOCATE_CPUWA(cpuWaLength)]; \
48 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(si_status, token, mcuxClSession_init( \
49 /* mcuxClSession_Handle_t session: */ pSession, \
50 /* uint32_t * const cpuWaBuffer: */ cpuWaBuffer, \
51 /* uint32_t cpuWaSize: */ cpuWaLength, \
52 MCUX_CSSL_ANALYSIS_START_SUPPRESS_TYPECAST_INTEGER_TO_POINTER("The start address of the PKC RAM is 32-bit aligned, this conversion is safe.") \
53 MCUX_CSSL_ANALYSIS_START_SUPPRESS_DISCARD_CONST_QUALIFIER("Convert address to pointer") \
54 /* uint32_t * const pkcWaBuffer: */ (uint32_t *) PKC_RAM_ADDR, \
55 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DISCARD_CONST_QUALIFIER() \
56 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_TYPECAST_INTEGER_TO_POINTER() \
57 /* uint32_t pkcWaSize: */ pkcWaLength \
58 )); \
59 /* mcuxClSession_init is a flow-protected function: Check the protection token and the return value */ \
60 if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClSession_init) != token) || (MCUXCLSESSION_STATUS_OK != si_status)) \
61 { \
62 return false; \
63 } \
64 MCUX_CSSL_FP_FUNCTION_CALL_END();
65
70MCUX_CSSL_FP_FUNCTION_DEF(mcuxClExample_Session_Clean)
71static inline bool mcuxClExample_Session_Clean(mcuxClSession_Handle_t pSession)
72{
73 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(cleanup_result, cleanup_token, mcuxClSession_cleanup(pSession));
74
75 if(MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClSession_cleanup) != cleanup_token || MCUXCLSESSION_STATUS_OK != cleanup_result)
76 {
77 return false;
78 }
79
81
82 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(destroy_result, destroy_token, mcuxClSession_destroy(pSession));
83
84 if(MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClSession_destroy) != destroy_token || MCUXCLSESSION_STATUS_OK != destroy_result)
85 {
86 return false;
87 }
88
90 return true;
91}
92
93#endif /* MCUXCLEXAMPLE_SESSION_HELPER_H_ */
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the mcuxClSession component.
Provides the API for the CSSL flow protection mechanism.
mcuxClSession_Status_t mcuxClSession_cleanup(mcuxClSession_Handle_t pSession)
Clean up a Crypto Library session.
mcuxClSession_Status_t mcuxClSession_destroy(mcuxClSession_Handle_t pSession)
Destroy a Crypto Library session.
#define MCUXCLSESSION_STATUS_OK
Session operation successful.
Definition mcuxClSession_Types.h:42
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:113
#define MCUX_CSSL_FP_FUNCTION_DEF(...)
Definition of a flow protected function.
Definition mcuxCsslFlowProtection.h:159
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:581
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:735
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:616