MCUX CLNS
MCUX Crypto Library Normal Secure
mcuxClExample_Key_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_KEY_HELPER_H_
15 #define MCUXCLEXAMPLE_KEY_HELPER_H_
16 
17 #include <mcuxClConfig.h> // Exported features flags header
18 #include <mcuxClCore_Platform.h>
19 #include <mcuxClCore_Buffer.h>
20 #include <mcuxClKey.h>
21 #include <mcuxClSession.h>
22 #include <mcuxCsslFlowProtection.h>
24 
36 #define MCUXCLEXAMPLE_CONST_EXTERNAL_KEY 0U
37 #define MCUXCLEXAMPLE_CONST_INTERNAL_KEY 1U
38 MCUX_CSSL_FP_FUNCTION_DEF(mcuxClExample_Key_Init_And_Load)
39 static inline bool mcuxClExample_Key_Init_And_Load(mcuxClSession_Handle_t pSession,
40  mcuxClKey_Handle_t pKey,
41  mcuxClKey_Type_t type,
42  mcuxCl_Buffer_t pData,
43  uint32_t keyDataLength,
44  mcuxClEls_KeyProp_t * key_properties,
45  uint32_t * dst,
46  uint8_t key_loading_option)
47 {
48  /* Init the key. */
49  MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(result, token, mcuxClKey_init(pSession,
50  pKey,
51  type,
52  pData,
53  keyDataLength));
54 
56  {
57  return false;
58  }
60 
61  /* Set the key properties. */
63  key_properties));
64 
66  {
67  return false;
68  }
70 
71  if(MCUXCLEXAMPLE_CONST_EXTERNAL_KEY == key_loading_option)
72  {
73  /* load key into destination memory buffer */
75  /* mcuxClSession_Handle_t pSession: */ pSession,
76  /* mcuxClKey_Handle_t key: */ pKey,
77  /* uint32_t * dstData: */ dst));
78 
80  {
81  return false;
82  }
84  }
85  else
86  {
87  /* load key into destination key slot of coprocessor (key_slot = '*dst') */
89  /* mcuxClSession_Handle_t pSession: */ pSession,
90  /* mcuxClKey_Handle_t key: */ pKey,
91  /* uint32_t dstSlot: */ *dst));
92 
94  {
95  return false;
96  }
98  }
99  return true;
100 }
101 
102 #endif /* MCUXCLEXAMPLE_KEY_HELPER_H_ */
const mcuxClKey_TypeDescriptor_t * mcuxClKey_Type_t
Key type handle type.
Definition: mcuxClKey_Types.h:111
#define MCUXCLKEY_STATUS_OK
Key operation successful.
Definition: mcuxClKey_Constants.h:39
Top-level include file for the mcuxClKey component.
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition: mcuxCsslFlowProtection.h:730
mcuxClKey_Descriptor_t *const mcuxClKey_Handle_t
Key handle type.
Definition: mcuxClKey_Types.h:88
Provides the API for the CSSL flow protection mechanism.
mcuxClKey_Status_t mcuxClKey_setKeyproperties(mcuxClKey_Handle_t key, mcuxClEls_KeyProp_t *key_properties)
Set the requested key properties of the destination key.
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition: mcuxCsslFlowProtection.h:576
#define MCUX_CSSL_FP_FUNCTION_DEF(...)
Definition of a flow protected function.
Definition: mcuxCsslFlowProtection.h:159
Top-level include file for the mcuxClSession component.
Type for ELS key store key properties.
Definition: mcuxClEls_Types.h:224
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition: mcuxClSession_Types.h:133
mcuxClKey_Status_t mcuxClKey_loadMemory(mcuxClSession_Handle_t pSession, mcuxClKey_Handle_t key, uint32_t *dstData)
Load key into destination memory buffer.
Definition of function identifiers for the flow protection mechanism.
mcuxClKey_Status_t mcuxClKey_loadCopro(mcuxClSession_Handle_t pSession, mcuxClKey_Handle_t key, uint32_t dstSlot)
Load key into destination key slot of a coprocessor.
mcuxClKey_Status_t mcuxClKey_init(mcuxClSession_Handle_t pSession, mcuxClKey_Handle_t key, mcuxClKey_Type_t type, mcuxCl_InputBuffer_t pKeyData, uint32_t keyDataLength)
Initializes a key handle.
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition: mcuxCsslFlowProtection.h:611
uint8_t *const mcuxCl_Buffer_t
Generic buffer typeThis type provides a pointer to the memory location that can be used for both read...
Definition: mcuxClCore_Buffer.h:51