32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
35 #include "fsl_device_registers.h"
45 #if (MIMXRT1050_CRYPTO_CIPHER_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
48 #if defined(__ICCARM__)
51 #pragma data_alignment = 16
52 #pragma location = MIMXRT1050_DCP_RAM_SECTION
56 #pragma data_alignment = 16
57 #pragma location = MIMXRT1050_DCP_RAM_SECTION
73 #if (ECB_SUPPORT == ENABLED)
86 const uint8_t *
p, uint8_t *
c,
size_t length)
91 status = kStatus_Success;
106 dcp_handle_t dcpHandle;
112 if(aesContext->
nr == 10)
115 dcpHandle.channel = kDCP_Channel0;
116 dcpHandle.keySlot = kDCP_KeySlot0;
117 dcpHandle.swapConfig = kDCP_NoSwap;
123 status = DCP_AES_SetKey(DCP, &dcpHandle,
124 (
const uint8_t *) aesContext->
ek, 16);
127 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
135 status = DCP_AES_EncryptEcb(DCP, &dcpHandle, dcpBufferIn,
139 if(status == kStatus_Success)
152 status = kStatus_Fail;
158 status = kStatus_InvalidArgument;
178 status = kStatus_InvalidArgument;
198 const uint8_t *
c, uint8_t *
p,
size_t length)
203 status = kStatus_Success;
218 dcp_handle_t dcpHandle;
224 if(aesContext->
nr == 10)
227 dcpHandle.channel = kDCP_Channel0;
228 dcpHandle.keySlot = kDCP_KeySlot0;
229 dcpHandle.swapConfig = kDCP_NoSwap;
235 status = DCP_AES_SetKey(DCP, &dcpHandle,
236 (
const uint8_t *) aesContext->
ek, 16);
239 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
247 status = DCP_AES_DecryptEcb(DCP, &dcpHandle, dcpBufferIn,
251 if(status == kStatus_Success)
261 status = kStatus_Fail;
270 status = kStatus_InvalidArgument;
290 status = kStatus_InvalidArgument;
299 #if (CBC_SUPPORT == ENABLED)
313 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
318 status = kStatus_Success;
333 dcp_handle_t dcpHandle;
339 if(aesContext->
nr == 10)
342 dcpHandle.channel = kDCP_Channel0;
343 dcpHandle.keySlot = kDCP_KeySlot0;
344 dcpHandle.swapConfig = kDCP_NoSwap;
350 status = DCP_AES_SetKey(DCP, &dcpHandle,
351 (
const uint8_t *) aesContext->
ek, 16);
354 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
362 status = DCP_AES_EncryptCbc(DCP, &dcpHandle, dcpBufferIn,
363 dcpBufferOut,
n,
iv);
366 if(status == kStatus_Success)
378 status = kStatus_Fail;
387 status = kStatus_InvalidArgument;
419 status = kStatus_InvalidArgument;
440 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
445 status = kStatus_Success;
460 dcp_handle_t dcpHandle;
467 if(aesContext->
nr == 10)
470 dcpHandle.channel = kDCP_Channel0;
471 dcpHandle.keySlot = kDCP_KeySlot0;
472 dcpHandle.swapConfig = kDCP_NoSwap;
478 status = DCP_AES_SetKey(DCP, &dcpHandle,
479 (
const uint8_t *) aesContext->
ek, 16);
482 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
492 status = DCP_AES_DecryptCbc(DCP, &dcpHandle, dcpBufferIn,
493 dcpBufferOut,
n,
iv);
496 if(status == kStatus_Success)
508 status = kStatus_Fail;
517 status = kStatus_InvalidArgument;
552 status = kStatus_InvalidArgument;