32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
35 #include "fsl_device_registers.h"
46 #if (MIMXRT1160_CRYPTO_CIPHER_SUPPORT == ENABLED)
49 #if defined(__ICCARM__)
52 #pragma data_alignment = 16
56 #pragma data_alignment = 16
60 #pragma data_alignment = 16
61 uint8_t caamInitVector[16];
75 uint8_t caamInitVector[16]
80 #if (DES_SUPPORT == ENABLED)
93 if(context == NULL || key == NULL)
118 caam_handle_t caamHandle;
121 caamHandle.jobRing = kCAAM_JobRing0;
129 CAAM_DES_EncryptEcb(CAAM, &caamHandle, caamBufferIn, caamBufferOut,
149 caam_handle_t caamHandle;
152 caamHandle.jobRing = kCAAM_JobRing0;
160 CAAM_DES_DecryptEcb(CAAM, &caamHandle, caamBufferIn, caamBufferOut,
171 #if (DES3_SUPPORT == ENABLED)
182 caam_handle_t caamHandle;
185 caamHandle.jobRing = kCAAM_JobRing0;
193 CAAM_DES3_EncryptEcb(CAAM, &caamHandle, caamBufferIn, caamBufferOut,
195 (
const uint8_t *) context->
k2.
ks,
196 (
const uint8_t *) context->
k3.
ks);
215 caam_handle_t caamHandle;
218 caamHandle.jobRing = kCAAM_JobRing0;
226 CAAM_DES3_DecryptEcb(CAAM, &caamHandle, caamBufferIn, caamBufferOut,
228 (
const uint8_t *) context->
k2.
ks,
229 (
const uint8_t *) context->
k3.
ks);
239 #if (ECB_SUPPORT == ENABLED)
252 const uint8_t *
p, uint8_t *
c,
size_t length)
257 status = kStatus_Success;
259 #if (DES_SUPPORT == ENABLED)
273 caam_handle_t caamHandle;
279 caamHandle.jobRing = kCAAM_JobRing0;
285 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
293 status = CAAM_DES_EncryptEcb(CAAM, &caamHandle, caamBufferIn,
294 caamBufferOut,
n, (
const uint8_t *) desContext->
ks);
297 if(status == kStatus_Success)
310 status = kStatus_InvalidArgument;
315 #if (DES3_SUPPORT == ENABLED)
329 caam_handle_t caamHandle;
335 caamHandle.jobRing = kCAAM_JobRing0;
341 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
349 status = CAAM_DES3_EncryptEcb(CAAM, &caamHandle, caamBufferIn,
350 caamBufferOut,
n, (
const uint8_t *) des3Context->
k1.
ks,
351 (
const uint8_t *) des3Context->
k2.
ks,
352 (
const uint8_t *) des3Context->
k3.
ks);
355 if(status == kStatus_Success)
368 status = kStatus_InvalidArgument;
373 #if (AES_SUPPORT == ENABLED)
388 caam_handle_t caamHandle;
394 if(aesContext->
nr == 10)
399 else if(aesContext->
nr == 12)
404 else if(aesContext->
nr == 14)
412 status = kStatus_Fail;
416 if(status == kStatus_Success)
419 caamHandle.jobRing = kCAAM_JobRing0;
425 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
433 status = CAAM_AES_EncryptEcb(CAAM, &caamHandle, caamBufferIn,
434 caamBufferOut,
n, (
const uint8_t *) aesContext->
ek, keySize);
437 if(status == kStatus_Success)
451 status = kStatus_InvalidArgument;
473 status = kStatus_InvalidArgument;
493 const uint8_t *
c, uint8_t *
p,
size_t length)
498 status = kStatus_Success;
500 #if (DES_SUPPORT == ENABLED)
514 caam_handle_t caamHandle;
520 caamHandle.jobRing = kCAAM_JobRing0;
526 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
534 status = CAAM_DES_DecryptEcb(CAAM, &caamHandle, caamBufferIn,
535 caamBufferOut,
n, (
const uint8_t *) desContext->
ks);
538 if(status == kStatus_Success)
551 status = kStatus_InvalidArgument;
556 #if (DES3_SUPPORT == ENABLED)
570 caam_handle_t caamHandle;
576 caamHandle.jobRing = kCAAM_JobRing0;
582 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
590 status = CAAM_DES3_DecryptEcb(CAAM, &caamHandle, caamBufferIn,
591 caamBufferOut,
n, (
const uint8_t *) des3Context->
k1.
ks,
592 (
const uint8_t *) des3Context->
k2.
ks,
593 (
const uint8_t *) des3Context->
k3.
ks);
596 if(status == kStatus_Success)
609 status = kStatus_InvalidArgument;
614 #if (AES_SUPPORT == ENABLED)
629 caam_handle_t caamHandle;
635 if(aesContext->
nr == 10)
640 else if(aesContext->
nr == 12)
645 else if(aesContext->
nr == 14)
653 status = kStatus_Fail;
657 if(status == kStatus_Success)
660 caamHandle.jobRing = kCAAM_JobRing0;
666 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
674 status = CAAM_AES_DecryptEcb(CAAM, &caamHandle, caamBufferIn,
675 caamBufferOut,
n, (
const uint8_t *) aesContext->
ek, keySize);
678 if(status == kStatus_Success)
692 status = kStatus_InvalidArgument;
714 status = kStatus_InvalidArgument;
723 #if (CBC_SUPPORT == ENABLED)
737 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
742 status = kStatus_Success;
744 #if (DES_SUPPORT == ENABLED)
758 caam_handle_t caamHandle;
764 caamHandle.jobRing = kCAAM_JobRing0;
770 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
778 status = CAAM_DES_EncryptCbc(CAAM, &caamHandle, caamBufferIn,
779 caamBufferOut,
n,
iv, (
const uint8_t *) desContext->
ks);
782 if(status == kStatus_Success)
797 status = kStatus_InvalidArgument;
802 #if (DES3_SUPPORT == ENABLED)
816 caam_handle_t caamHandle;
822 caamHandle.jobRing = kCAAM_JobRing0;
828 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
836 status = CAAM_DES3_EncryptCbc(CAAM, &caamHandle, caamBufferIn,
837 caamBufferOut,
n,
iv, (
const uint8_t *) des3Context->
k1.
ks,
838 (
const uint8_t *) des3Context->
k2.
ks,
839 (
const uint8_t *) des3Context->
k3.
ks);
842 if(status == kStatus_Success)
857 status = kStatus_InvalidArgument;
862 #if (AES_SUPPORT == ENABLED)
877 caam_handle_t caamHandle;
883 if(aesContext->
nr == 10)
888 else if(aesContext->
nr == 12)
893 else if(aesContext->
nr == 14)
901 status = kStatus_Fail;
905 if(status == kStatus_Success)
908 caamHandle.jobRing = kCAAM_JobRing0;
914 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
922 status = CAAM_AES_EncryptCbc(CAAM, &caamHandle, caamBufferIn,
923 caamBufferOut,
n,
iv, (
const uint8_t *) aesContext->
ek, keySize);
926 if(status == kStatus_Success)
942 status = kStatus_InvalidArgument;
976 status = kStatus_InvalidArgument;
997 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
1002 status = kStatus_Success;
1004 #if (DES_SUPPORT == ENABLED)
1018 caam_handle_t caamHandle;
1025 caamHandle.jobRing = kCAAM_JobRing0;
1031 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
1041 status = CAAM_DES_DecryptCbc(CAAM, &caamHandle, caamBufferIn,
1042 caamBufferOut,
n,
iv, (
const uint8_t *) desContext->
ks);
1045 if(status == kStatus_Success)
1060 status = kStatus_InvalidArgument;
1065 #if (DES3_SUPPORT == ENABLED)
1079 caam_handle_t caamHandle;
1086 caamHandle.jobRing = kCAAM_JobRing0;
1092 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
1102 status = CAAM_DES3_DecryptCbc(CAAM, &caamHandle, caamBufferIn,
1103 caamBufferOut,
n,
iv, (
const uint8_t *) des3Context->
k1.
ks,
1104 (
const uint8_t *) des3Context->
k2.
ks,
1105 (
const uint8_t *) des3Context->
k3.
ks);
1108 if(status == kStatus_Success)
1123 status = kStatus_InvalidArgument;
1128 #if (AES_SUPPORT == ENABLED)
1143 caam_handle_t caamHandle;
1150 if(aesContext->
nr == 10)
1155 else if(aesContext->
nr == 12)
1160 else if(aesContext->
nr == 14)
1168 status = kStatus_Fail;
1172 if(status == kStatus_Success)
1175 caamHandle.jobRing = kCAAM_JobRing0;
1181 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
1191 status = CAAM_AES_DecryptCbc(CAAM, &caamHandle, caamBufferIn,
1192 caamBufferOut,
n,
iv, (
const uint8_t *) aesContext->
ek, keySize);
1195 if(status == kStatus_Success)
1211 status = kStatus_InvalidArgument;
1248 status = kStatus_InvalidArgument;
1257 #if (CTR_SUPPORT == ENABLED)
1272 uint8_t *
t,
const uint8_t *
p, uint8_t *
c,
size_t length)
1277 status = kStatus_Success;
1286 #if (AES_SUPPORT == ENABLED)
1295 caam_handle_t caamHandle;
1301 if(aesContext->
nr == 10)
1306 else if(aesContext->
nr == 12)
1311 else if(aesContext->
nr == 14)
1319 status = kStatus_Fail;
1323 if(status == kStatus_Success)
1326 caamHandle.jobRing = kCAAM_JobRing0;
1332 for(i = 0; i <
length && status == kStatus_Success; i +=
n)
1347 status = CAAM_AES_CryptCtr(CAAM, &caamHandle,
1349 caamInitVector, (
const uint8_t *) aesContext->
ek, keySize,
1353 if(status == kStatus_Success)
1384 for(i = 0; i <
n; i++)
1402 status = kStatus_InvalidArgument;
1410 #if (GCM_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
1421 void *cipherContext)
1424 if(context == NULL || cipherContext == NULL)
1456 size_t ivLen,
const uint8_t *
a,
size_t aLen,
const uint8_t *
p,
1457 uint8_t *
c,
size_t length, uint8_t *
t,
size_t tLen)
1461 caam_handle_t caamHandle;
1469 if(tLen < 4 || tLen > 16)
1473 status = kStatus_Success;
1479 if(aesContext->
nr == 10)
1484 else if(aesContext->
nr == 12)
1489 else if(aesContext->
nr == 14)
1497 status = kStatus_Fail;
1501 if(status == kStatus_Success)
1504 caamHandle.jobRing = kCAAM_JobRing0;
1510 status = CAAM_AES_EncryptTagGcm(CAAM, &caamHandle,
p,
c,
length,
iv,
1511 ivLen,
a, aLen, (
const uint8_t *) aesContext->
ek, keySize,
t, tLen);
1538 size_t ivLen,
const uint8_t *
a,
size_t aLen,
const uint8_t *
c,
1539 uint8_t *
p,
size_t length,
const uint8_t *
t,
size_t tLen)
1543 caam_handle_t caamHandle;
1551 if(tLen < 4 || tLen > 16)
1555 status = kStatus_Success;
1561 if(aesContext->
nr == 10)
1566 else if(aesContext->
nr == 12)
1571 else if(aesContext->
nr == 14)
1579 status = kStatus_Fail;
1583 if(status == kStatus_Success)
1586 caamHandle.jobRing = kCAAM_JobRing0;
1592 status = CAAM_AES_DecryptTagGcm(CAAM, &caamHandle,
c,
p,
length,
iv,
1593 ivLen,
a, aLen, (
const uint8_t *) aesContext->
ek, keySize,
t, tLen);