14#ifndef MCUXCLEXAMPLE_RFC3394_HELPER_H_
15#define MCUXCLEXAMPLE_RFC3394_HELPER_H_
17#include <mcuxClConfig.h>
18#include <mcuxClCore_Platform.h>
28static inline bool mcuxClExample_rfc3394_wrap(
29 const uint32_t * pInput,
31 const uint8_t * pKek_in,
62 concat[0] = 0xA6A6A6A6u;
63 concat[1] = 0xA6A6A6A6u;
65 concat[3] = 0x00000000u;
66 concat[2] = (concat[2] << 24u) | (concat[2] >> 24u) | ((concat[2] & 0x0000ff00u) << 8u) | ((concat[2] >> 8u) & 0x0000ff00u);
76 if (inputLength %
sizeof(uint64_t) != 0u)
81 const uint32_t *pSource = pInput;
82 uint32_t *pDest = pOutput;
83 uint32_t std_n = inputLength/
sizeof(uint64_t) + 1u;
84 for(
size_t jdx = 0u; jdx < 6u; jdx++)
86 for(
size_t idx = 0u; idx < std_n; idx++)
94 MCUX_CSSL_ANALYSIS_START_PATTERN_NULL_POINTER_CONSTANT()
95 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.")
105 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ESCAPING_LOCAL_ADDRESS()
106 MCUX_CSSL_ANALYSIS_STOP_PATTERN_NULL_POINTER_CONSTANT()
121 pDest[2u*idx + 2u] = concat[2u];
122 pDest[2u*idx + 3u] = concat[3u];
124 if( idx == std_n - 1u)
127 concat[2u] = pDest[2u];
128 concat[3u] = pDest[3u];
134 concat[2u] = pSource[2u*idx + 0u];
135 concat[3u] = pSource[2u*idx + 1u];
139 uint32_t gdx = std_n * jdx + (idx + 1u);
140 gdx = (gdx << 24u) | (gdx >> 24u) | ((gdx & 0x0000ff00u) << 8u) | ((gdx >> 8u) & 0x0000ff00u);
145 pDest[0u] = concat[0u];
146 pDest[1u] = concat[1u];
155static inline bool mcuxClExample_rfc3394_unwrap(
156 const uint32_t * pInput,
158 const uint8_t * pKek_in,
186 concat[0] = pInput[0];
187 concat[1] = pInput[1];
197 if ((inputLength %
sizeof(uint64_t) != 0u)
198#ifdef MCUXCL_FEATURE_ELS_PUK_INTERNAL
199 || (inputLength > MCUXCLELS_RFC3394_CONTAINER_SIZE_P256))
207 uint32_t std_n = inputLength/
sizeof(uint64_t) - 1u;
208 const uint32_t *pSource = pInput + 2u;
209 uint32_t *pDest = pOutput;
210 for(
size_t jdx = 6u; jdx > 0u; jdx--)
212 for(
size_t idx = std_n; idx > 0u; idx--)
215 MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW(
"Index calculation cannot wrap.")
216 concat[2u] = pSource[2u * (idx-1u) + 0u];
217 concat[3u] = pSource[2u * (idx-1u) + 1u];
218 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
221 MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_WRAP("The result will fit into 32 bit, as inputLength has an upper bound as checked above.")
222 uint32_t gdx = std_n * (jdx-1u) + idx;
223 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_WRAP()
224 gdx = (gdx << 24u) | (gdx >> 24u) | ((gdx & 0x0000ff00u) << 8u) | ((gdx >> 8u) & 0x0000ff00u);
233 MCUX_CSSL_ANALYSIS_START_PATTERN_NULL_POINTER_CONSTANT()
234 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.")
244 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ESCAPING_LOCAL_ADDRESS()
245 MCUX_CSSL_ANALYSIS_STOP_PATTERN_NULL_POINTER_CONSTANT()
260 MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW(
"Index calculation cannot wrap.")
261 pDest[2u * (idx-1u) + 0u] = concat[2u];
262 pDest[2u * (idx-1u) + 1u] = concat[3u];
263 MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
267 pDest[0] = (pDest[0] << 24u) | (pDest[0] >> 24u) | ((pDest[0] & 0x0000ff00u) << 8u) | ((pDest[0] >> 8u) & 0x0000ff00u);
269 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
Definition mcuxClEls_Cipher.h:87
#define MCUXCLELS_CIPHER_DECRYPT
Set this option at mcuxClEls_CipherOption_t.dcrpt to perform a decryption.
Definition mcuxClEls_Cipher.h:63
#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:76
#define MCUXCLELS_CIPHER_ENCRYPT
Set this option at mcuxClEls_CipherOption_t.dcrpt to perform an encryption.
Definition mcuxClEls_Cipher.h:62
#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:73
#define MCUXCLELS_CIPHER_KEY_SIZE_AES_256
Size of an AES192 key: 256 bit (32 bytes)
Definition mcuxClEls_Cipher.h:98
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:110
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:107
#define MCUXCLELS_STATUS_OK
No error occurred.
Definition mcuxClEls_Types.h:171
#define MCUXCLELS_STATUS_OK_WAIT
An _Async function successfully started an ELS command. Call mcuxClEls_WaitForOperation to complete i...
Definition mcuxClEls_Types.h:172
uint32_t mcuxClEls_KeyIndex_t
Type for ELS keystore indices.
Definition mcuxClEls_Types.h:222
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:652
#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:683
#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
Command option bit field for mcuxClEls_Cipher_Async.
Definition mcuxClEls_Cipher.h:121
uint32_t value
Accesses the bit field as a full word.
Definition mcuxClEls_Cipher.h:124
struct mcuxClEls_CipherOption_t::@3 bits
Access mcuxClEls_CipherOption_t bit-wise.
uint32_t cphmde
Define cipher mode.
Definition mcuxClEls_Cipher.h:130
uint32_t extkey
Define whether an external key from memory or ELS internal key should be used.
Definition mcuxClEls_Cipher.h:138
struct mcuxClEls_CipherOption_t::@2 word
Access mcuxClEls_CipherOption_t word-wise.
uint32_t dcrpt
Define operation mode.
Definition mcuxClEls_Cipher.h:129
Type for ELS key store key properties.
Definition mcuxClEls_Types.h:226
struct mcuxClEls_KeyProp_t::@40 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:229