MCUX CLNS
MCUX Crypto Library Normal Secure
 
Loading...
Searching...
No Matches
mcuxClExample_Session_Helper.h
1/*--------------------------------------------------------------------------*/
2/* Copyright 2022-2024 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_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/* TODO: CLNS-5886 [DEV][Session][Example] enable size checking when allocating buffers and update example macros */
32#if 0
33/* Macros to make sure some memory is always allocated to avoid issues */
34#define MCUXCLEXAMPLE_ALLOCATE_CPUWA(cpuWaLength) \
35 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
36 (((cpuWaLength > 0u)?(cpuWaLength):(sizeof(uint32_t))) / (sizeof(uint32_t))) \
37 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
38#define MCUXCLEXAMPLE_ALLOCATE_PKCWA(pkcWaLength) \
39 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
40 (((pkcWaLength > 0u)?(pkcWaLength):(sizeof(uint32_t))) / (sizeof(uint32_t))) \
41 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
42#else
43/* Macros to make sure some memory is always allocated to avoid issues */
44#define MCUXCLEXAMPLE_ALLOCATE_CPUWA(cpuWaLength) \
45 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
46 ((cpuWaLength > 0u)?(cpuWaLength):1u) \
47 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
48#define MCUXCLEXAMPLE_ALLOCATE_PKCWA(pkcWaLength) \
49 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
50 ((pkcWaLength > 0u )?(pkcWaLength):1u) \
51 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
52#endif
53
54#define MCUXCLEXAMPLE_MAX_WA(a, b) \
55 MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Constant values are allowed as an argument to macro function") \
56 (((a) > (b)) ? (a) : (b)) \
57 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
58
59#define MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(pSession, cpuWaLength, pkcWaLength) \
60 uint32_t cpuWaBuffer[MCUXCLEXAMPLE_ALLOCATE_CPUWA(cpuWaLength)]; \
61 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(si_status, token, mcuxClSession_init( \
62 /* mcuxClSession_Handle_t session: */ pSession, \
63 /* uint32_t * const cpuWaBuffer: */ cpuWaBuffer, \
64 /* uint32_t cpuWaSize: */ cpuWaLength, \
65 /* uint32_t * const pkcWaBuffer: */ (uint32_t *) PKC_RAM_ADDR, \
66 /* uint32_t pkcWaSize: */ pkcWaLength \
67 )); \
68 /* mcuxClSession_init is a flow-protected function: Check the protection token and the return value */ \
69 if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClSession_init) != token) || (MCUXCLSESSION_STATUS_OK != si_status)) \
70 { \
71 return false; \
72 } \
73 MCUX_CSSL_FP_FUNCTION_CALL_END();
74
79MCUX_CSSL_FP_FUNCTION_DEF(mcuxClExample_Session_Clean)
80static inline bool mcuxClExample_Session_Clean(mcuxClSession_Handle_t pSession)
81{
82 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(cleanup_result, cleanup_token, mcuxClSession_cleanup(pSession));
83
84 if(MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClSession_cleanup) != cleanup_token || MCUXCLSESSION_STATUS_OK != cleanup_result)
85 {
86 return false;
87 }
88
90
91 MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(destroy_result, destroy_token, mcuxClSession_destroy(pSession));
92
93 if(MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClSession_destroy) != destroy_token || MCUXCLSESSION_STATUS_OK != destroy_result)
94 {
95 return false;
96 }
97
99 return true;
100}
101
102#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