34#ifndef MCUXCLEXAMPLE_RFC3394_HELPER_H_
35#define MCUXCLEXAMPLE_RFC3394_HELPER_H_
37#include <mcuxClConfig.h>
38#include <mcuxClCore_Platform.h>
48static inline bool mcuxClExample_rfc3394_wrap(
49 const uint32_t * pInput,
51 const uint8_t * pKek_in,
82 concat[0] = 0xA6A6A6A6u;
83 concat[1] = 0xA6A6A6A6u;
85 concat[3] = 0x00000000u;
86 concat[2] = (concat[2] << 24u) | (concat[2] >> 24u) | ((concat[2] & 0x0000ff00u) << 8u) | ((concat[2] >> 8u) & 0x0000ff00u);
96 if (inputLength %
sizeof(uint64_t) != 0u)
101 const uint32_t *pSource = pInput;
102 uint32_t *pDest = pOutput;
103 uint32_t std_n = inputLength/
sizeof(uint64_t) + 1u;
104 for(
size_t jdx = 0u; jdx < 6u; jdx++)
106 for(
size_t idx = 0u; idx < std_n; idx++)
114 MCUX_CSSL_ANALYSIS_START_PATTERN_NULL_POINTER_CONSTANT()
115 MCUX_CSSL_ANALYSIS_START_SUPPRESS_ESCAPING_LOCAL_ADDRESS(
"Address of concat is for local use only. The call to mcuxClEls_WaitForOperation ensures it cannot escape.")
125 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ESCAPING_LOCAL_ADDRESS()
126 MCUX_CSSL_ANALYSIS_STOP_PATTERN_NULL_POINTER_CONSTANT()
141 pDest[2u*idx + 2u] = concat[2u];
142 pDest[2u*idx + 3u] = concat[3u];
144 if( idx == std_n - 1u)
147 concat[2u] = pDest[2u];
148 concat[3u] = pDest[3u];
154 concat[2u] = pSource[2u*idx + 0u];
155 concat[3u] = pSource[2u*idx + 1u];
159 uint32_t gdx = std_n * jdx + (idx + 1u);
160 gdx = (gdx << 24u) | (gdx >> 24u) | ((gdx & 0x0000ff00u) << 8u) | ((gdx >> 8u) & 0x0000ff00u);
165 pDest[0u] = concat[0u];
166 pDest[1u] = concat[1u];
175static inline bool mcuxClExample_rfc3394_unwrap(
176 const uint32_t * pInput,
178 const uint8_t * pKek_in,
206 concat[0] = pInput[0];
207 concat[1] = pInput[1];
217 if ((inputLength %
sizeof(uint64_t) != 0u)
218#ifdef MCUXCL_FEATURE_ELS_PUK_INTERNAL
219 || (inputLength > MCUXCLELS_RFC3394_CONTAINER_SIZE_P256))
227 uint32_t std_n = inputLength/
sizeof(uint64_t) - 1u;
228 const uint32_t *pSource = pInput + 2u;
229 uint32_t *pDest = pOutput;
230 for(
size_t jdx = 6u; jdx > 0u; jdx--)
232 for(
size_t idx = std_n; idx > 0u; idx--)
235 MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW(
"Index calculation cannot wrap.")
236 concat[2u] = pSource[2u * (idx-1u) + 0u];
237 concat[3u] = pSource[2u * (idx-1u) + 1u];
238 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
241 MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_WRAP(
"The result will fit into 32 bit, as inputLength has an upper bound as checked above.")
242 uint32_t gdx = std_n * (jdx-1u) + idx;
243 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_WRAP()
244 gdx = (gdx << 24u) | (gdx >> 24u) | ((gdx & 0x0000ff00u) << 8u) | ((gdx >> 8u) & 0x0000ff00u);
253 MCUX_CSSL_ANALYSIS_START_PATTERN_NULL_POINTER_CONSTANT()
254 MCUX_CSSL_ANALYSIS_START_SUPPRESS_ESCAPING_LOCAL_ADDRESS(
"Address of concat is for local use only. The call to mcuxClEls_WaitForOperation ensures it cannot escape.")
264 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ESCAPING_LOCAL_ADDRESS()
265 MCUX_CSSL_ANALYSIS_STOP_PATTERN_NULL_POINTER_CONSTANT()
280 MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW(
"Index calculation cannot wrap.")
281 pDest[2u * (idx-1u) + 0u] = concat[2u];
282 pDest[2u * (idx-1u) + 1u] = concat[3u];
283 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
287 pDest[0] = (pDest[0] << 24u) | (pDest[0] >> 24u) | ((pDest[0] & 0x0000ff00u) << 8u) | ((pDest[0] >> 8u) & 0x0000ff00u);
289 if((concat[0u] != 0xA6A6A6A6u) || (concat[1u] != 0xA6A6A6A6u))
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the ELS driver.
Memory header for copy functions.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLELS_CIPHER_BLOCK_SIZE_AES
Size of an AES input block: 128 bit (16 bytes).
Definition mcuxClEls_Cipher.h:107
#define MCUXCLELS_CIPHER_DECRYPT
Set this option at mcuxClEls_CipherOption_t.dcrpt to perform a decryption.
Definition mcuxClEls_Cipher.h:83
#define MCUXCLELS_CIPHERPARAM_ALGORITHM_AES_ECB
Set this option at mcuxClEls_CipherOption_t.cphmde to use AES engine in Electornic Code Book (ECB) mo...
Definition mcuxClEls_Cipher.h:96
#define MCUXCLELS_CIPHER_ENCRYPT
Set this option at mcuxClEls_CipherOption_t.dcrpt to perform an encryption.
Definition mcuxClEls_Cipher.h:82
#define MCUXCLELS_CIPHER_EXTERNAL_KEY
Set this option at mcuxClEls_CipherOption_t.extkey to use a key located in CPU memory provided by pKe...
Definition mcuxClEls_Cipher.h:93
#define MCUXCLELS_CIPHER_KEY_SIZE_AES_256
Size of an AES192 key: 256 bit (32 bytes).
Definition mcuxClEls_Cipher.h:118
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_Cipher_Async(mcuxClEls_CipherOption_t options, mcuxClEls_KeyIndex_t keyIdx, uint8_t const *pKey, size_t keyLength, uint8_t const *pInput, size_t inputLength, uint8_t *pIV, uint8_t *pOutput)
Performs AES encryption/decryption.
#define MCUXCLELS_ERROR_FLAGS_CLEAR
Set this option at mcuxClEls_ErrorHandling_t to clear all ELS error flags.
Definition mcuxClEls_Common.h:130
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_WaitForOperation(mcuxClEls_ErrorHandling_t errorHandling)
Wait for an ELS operation and optionally clear the error status.
#define MCUXCLELS_RFC3394_CONTAINER_SIZE_256
Size of RFC3394 container for 256 bit key.
Definition mcuxClEls_KeyManagement.h:127
#define MCUXCLELS_STATUS_OK
No error occurred.
Definition mcuxClEls_Types.h:191
#define MCUXCLELS_STATUS_OK_WAIT
An _Async function successfully started an ELS command. Call mcuxClEls_WaitForOperation to complete i...
Definition mcuxClEls_Types.h:192
uint32_t mcuxClEls_KeyIndex_t
Type for ELS keystore indices.
Definition mcuxClEls_Types.h:242
void mcuxClMemory_copy(uint8_t *pDst, uint8_t const *pSrc, size_t length, size_t bufLength)
Copies a memory buffer to another location.
#define MCUX_CSSL_FP_FUNCTION_CALL_VOID_BEGIN(...)
Call a flow protected void function and check the protection token.
Definition mcuxCsslFlowProtection.h:672
#define MCUX_CSSL_FP_FUNCTION_CALL_VOID_END(...)
End a void function call section started by MCUX_CSSL_FP_FUNCTION_CALL_VOID_BEGIN.
Definition mcuxCsslFlowProtection.h:703
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:601
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:755
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:636
Command option bit field for mcuxClEls_Cipher_Async.
Definition mcuxClEls_Cipher.h:141
uint32_t value
Accesses the bit field as a full word.
Definition mcuxClEls_Cipher.h:144
uint32_t cphmde
Define cipher mode.
Definition mcuxClEls_Cipher.h:150
uint32_t extkey
Define whether an external key from memory or ELS internal key should be used.
Definition mcuxClEls_Cipher.h:158
struct mcuxClEls_CipherOption_t::@040146127063252077303251341061227266321102231343 word
Access mcuxClEls_CipherOption_t word-wise.
struct mcuxClEls_CipherOption_t::@211376152271043115107205214261204042163004233364 bits
Access mcuxClEls_CipherOption_t bit-wise.
uint32_t dcrpt
Define operation mode.
Definition mcuxClEls_Cipher.h:149
Type for ELS key store key properties.
Definition mcuxClEls_Types.h:246
struct mcuxClEls_KeyProp_t::@275171221237375205140351133234315312172366173335 word
Access mcuxClEls_KeyProp_t word-wise.
uint32_t value
Accesses the bit field as a full word; initialize with a combination of constants from MCUXCLELS_KEYP...
Definition mcuxClEls_Types.h:249