32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
35 #include "hw_sce_private.h"
36 #include "hw_sce_tdes_private.h"
37 #include "hw_sce_aes_private.h"
47 #if (S5D9_CRYPTO_CIPHER_SUPPORT == ENABLED)
48 #if (DES3_SUPPORT == ENABLED)
62 if(context == NULL || key == NULL)
127 (
const uint32_t *) input, (uint32_t *) output);
130 if(status != SSP_SUCCESS)
156 (
const uint32_t *) input, (uint32_t *) output);
159 if(status != SSP_SUCCESS)
169 #if (AES_SUPPORT == ENABLED)
184 if(context == NULL || key == NULL)
188 status = SSP_SUCCESS;
198 else if(keyLen == 24)
205 else if(keyLen == 32)
215 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
238 if(context->
nr == 10)
242 (
const uint32_t *) input, (uint32_t *) output);
244 else if(context->
nr == 12)
248 (
const uint32_t *) input, (uint32_t *) output);
250 else if(context->
nr == 14)
254 (
const uint32_t *) input, (uint32_t *) output);
259 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
263 if(status != SSP_SUCCESS)
288 if(context->
nr == 10)
292 (
const uint32_t *) input, (uint32_t *) output);
294 else if(context->
nr == 12)
298 (
const uint32_t *) input, (uint32_t *) output);
300 else if(context->
nr == 14)
304 (
const uint32_t *) input, (uint32_t *) output);
309 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
313 if(status != SSP_SUCCESS)
323 #if (ECB_SUPPORT == ENABLED)
336 const uint8_t *
p, uint8_t *
c,
size_t length)
341 status = SSP_SUCCESS;
343 #if (DES3_SUPPORT == ENABLED)
363 status = HW_SCE_TDES_192EcbEncrypt(des3Context->
k1.
ks,
length / 4,
364 (
const uint32_t *)
p, (uint32_t *)
c);
372 status = SSP_ERR_CRYPTO_INVALID_SIZE;
377 #if (AES_SUPPORT == ENABLED)
397 if(aesContext->
nr == 10)
400 status = HW_SCE_AES_128EcbEncrypt(aesContext->
ek,
length / 4,
401 (
const uint32_t *)
p, (uint32_t *)
c);
403 else if(aesContext->
nr == 12)
406 status = HW_SCE_AES_192EcbEncrypt(aesContext->
ek,
length / 4,
407 (
const uint32_t *)
p, (uint32_t *)
c);
409 else if(aesContext->
nr == 14)
412 status = HW_SCE_AES_256EcbEncrypt(aesContext->
ek,
length / 4,
413 (
const uint32_t *)
p, (uint32_t *)
c);
418 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
427 status = SSP_ERR_CRYPTO_INVALID_SIZE;
449 status = SSP_ERR_CRYPTO_INVALID_SIZE;
469 const uint8_t *
c, uint8_t *
p,
size_t length)
474 status = SSP_SUCCESS;
476 #if (DES3_SUPPORT == ENABLED)
496 status = HW_SCE_TDES_192EcbDecrypt(des3Context->
k1.
ks,
length / 4,
497 (
const uint32_t *)
p, (uint32_t *)
c);
505 status = SSP_ERR_CRYPTO_INVALID_SIZE;
510 #if (AES_SUPPORT == ENABLED)
530 if(aesContext->
nr == 10)
533 status = HW_SCE_AES_128EcbDecrypt(aesContext->
ek,
length / 4,
534 (
const uint32_t *)
c, (uint32_t *)
p);
536 else if(aesContext->
nr == 12)
539 status = HW_SCE_AES_192EcbDecrypt(aesContext->
ek,
length / 4,
540 (
const uint32_t *)
c, (uint32_t *)
p);
542 else if(aesContext->
nr == 14)
545 status = HW_SCE_AES_256EcbDecrypt(aesContext->
ek,
length / 4,
546 (
const uint32_t *)
c, (uint32_t *)
p);
551 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
560 status = SSP_ERR_CRYPTO_INVALID_SIZE;
582 status = SSP_ERR_CRYPTO_INVALID_SIZE;
591 #if (CBC_SUPPORT == ENABLED)
605 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
610 status = SSP_SUCCESS;
612 #if (DES3_SUPPORT == ENABLED)
632 status = HW_SCE_TDES_192CbcEncrypt(des3Context->
k1.
ks,
633 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
p,
634 (uint32_t *)
c, (uint32_t *)
iv);
642 status = SSP_ERR_CRYPTO_INVALID_SIZE;
647 #if (AES_SUPPORT == ENABLED)
667 if(aesContext->
nr == 10)
670 status = HW_SCE_AES_128CbcEncrypt(aesContext->
ek,
671 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
p,
672 (uint32_t *)
c, (uint32_t *)
iv);
674 else if(aesContext->
nr == 12)
677 status = HW_SCE_AES_192CbcEncrypt(aesContext->
ek,
678 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
p,
679 (uint32_t *)
c, (uint32_t *)
iv);
681 else if(aesContext->
nr == 14)
684 status = HW_SCE_AES_256CbcEncrypt(aesContext->
ek,
685 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
p,
686 (uint32_t *)
c, (uint32_t *)
iv);
691 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
700 status = SSP_ERR_CRYPTO_INVALID_SIZE;
734 status = SSP_ERR_CRYPTO_INVALID_SIZE;
755 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
760 status = SSP_SUCCESS;
762 #if (DES3_SUPPORT == ENABLED)
782 status = HW_SCE_TDES_192CbcDecrypt(des3Context->
k1.
ks,
783 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
c,
784 (uint32_t *)
p, (uint32_t *)
iv);
792 status = SSP_ERR_CRYPTO_INVALID_SIZE;
797 #if (AES_SUPPORT == ENABLED)
817 if(aesContext->
nr == 10)
820 status = HW_SCE_AES_128CbcDecrypt(aesContext->
ek,
821 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
c,
822 (uint32_t *)
p, (uint32_t *)
iv);
824 else if(aesContext->
nr == 12)
827 status = HW_SCE_AES_192CbcDecrypt(aesContext->
ek,
828 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
c,
829 (uint32_t *)
p, (uint32_t *)
iv);
831 else if(aesContext->
nr == 14)
834 status = HW_SCE_AES_256CbcDecrypt(aesContext->
ek,
835 (
const uint32_t *)
iv,
length / 4, (
const uint32_t *)
c,
836 (uint32_t *)
p, (uint32_t *)
iv);
841 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
850 status = SSP_ERR_CRYPTO_INVALID_SIZE;
887 status = SSP_ERR_CRYPTO_INVALID_SIZE;
896 #if (CTR_SUPPORT == ENABLED)
911 uint8_t *
t,
const uint8_t *
p, uint8_t *
c,
size_t length)
916 status = SSP_SUCCESS;
918 #if (DES3_SUPPORT == ENABLED)
941 status = HW_SCE_TDES_192CtrEncrypt(des3Context->
k1.
ks,
942 (
const uint32_t *)
t,
length / 4, (
const uint32_t *)
p,
943 (uint32_t *)
c, (uint32_t *)
t);
951 status = SSP_ERR_CRYPTO_INVALID_SIZE;
957 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
962 #if (AES_SUPPORT == ENABLED)
985 if(aesContext->
nr == 10)
988 status = HW_SCE_AES_128CtrEncrypt(aesContext->
ek,
989 (
const uint32_t *)
t,
length / 4, (
const uint32_t *)
p,
990 (uint32_t *)
c, (uint32_t *)
t);
992 else if(aesContext->
nr == 12)
995 status = HW_SCE_AES_192CtrEncrypt(aesContext->
ek,
996 (
const uint32_t *)
t,
length / 4, (
const uint32_t *)
p,
997 (uint32_t *)
c, (uint32_t *)
t);
999 else if(aesContext->
nr == 14)
1002 status = HW_SCE_AES_256CtrEncrypt(aesContext->
ek,
1003 (
const uint32_t *)
t,
length / 4, (
const uint32_t *)
p,
1004 (uint32_t *)
c, (uint32_t *)
t);
1009 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
1018 status = SSP_ERR_CRYPTO_INVALID_SIZE;
1024 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
1052 for(i = 0; i <
n; i++)
1069 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
1078 #if (GCM_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
1089 void *cipherContext)
1111 context->
m[0][0] =
h[0];
1112 context->
m[0][1] =
h[1];
1113 context->
m[0][2] =
h[2];
1114 context->
m[0][3] =
h[3];
1137 size_t ivLen,
const uint8_t *
a,
size_t aLen,
const uint8_t *
p,
1138 uint8_t *
c,
size_t length, uint8_t *
t,
size_t tLen)
1157 if(tLen < 4 || tLen > 16)
1164 if(aesContext->
nr != 10 && aesContext->
nr != 12 && aesContext->
nr != 14)
1199 HW_SCE_AES_Ghash(context->
m[0], j, k / 4, (
const uint32_t *)
iv, j);
1214 HW_SCE_AES_Ghash(context->
m[0], j, 4,
b, j);
1227 HW_SCE_AES_Ghash(context->
m[0], j, 4,
b, j);
1231 if(aesContext->
nr == 10)
1233 HW_SCE_AES_128EcbEncrypt(aesContext->
ek, 4, j,
b);
1235 else if(aesContext->
nr == 12)
1237 HW_SCE_AES_192EcbEncrypt(aesContext->
ek, 4, j,
b);
1241 HW_SCE_AES_256EcbEncrypt(aesContext->
ek, 4, j,
b);
1268 HW_SCE_AES_Ghash(context->
m[0],
s, k / 4, (
const uint32_t *)
a,
s);
1283 HW_SCE_AES_Ghash(context->
m[0],
s, 4,
b,
s);
1297 if(aesContext->
nr == 10)
1299 HW_SCE_AES_128GctrEncrypt(aesContext->
ek, j, k / 4,
1300 (
const uint32_t *)
p, (uint32_t *)
c, j);
1302 else if(aesContext->
nr == 12)
1304 HW_SCE_AES_192GctrEncrypt(aesContext->
ek, j, k / 4,
1305 (
const uint32_t *)
p, (uint32_t *)
c, j);
1309 HW_SCE_AES_256GctrEncrypt(aesContext->
ek, j, k / 4,
1310 (
const uint32_t *)
p, (uint32_t *)
c, j);
1314 HW_SCE_AES_Ghash(context->
m[0],
s, k / 4, (
const uint32_t *)
c,
s);
1330 if(aesContext->
nr == 10)
1332 HW_SCE_AES_128GctrEncrypt(aesContext->
ek, j, 4,
b,
b, j);
1334 else if(aesContext->
nr == 12)
1336 HW_SCE_AES_192GctrEncrypt(aesContext->
ek, j, 4,
b,
b, j);
1340 HW_SCE_AES_256GctrEncrypt(aesContext->
ek, j, 4,
b,
b, j);
1347 HW_SCE_AES_Ghash(context->
m[0],
s, 4,
b,
s);
1364 HW_SCE_AES_Ghash(context->
m[0],
s, 4,
b,
s);
1393 size_t ivLen,
const uint8_t *
a,
size_t aLen,
const uint8_t *
c,
1394 uint8_t *
p,
size_t length,
const uint8_t *
t,
size_t tLen)
1415 if(tLen < 4 || tLen > 16)
1422 if(aesContext->
nr != 10 && aesContext->
nr != 12 && aesContext->
nr != 14)
1457 HW_SCE_AES_Ghash(context->
m[0], j, k / 4, (
const uint32_t *)
iv, j);
1472 HW_SCE_AES_Ghash(context->
m[0], j, 4,
b, j);
1485 HW_SCE_AES_Ghash(context->
m[0], j, 4,
b, j);
1489 if(aesContext->
nr == 10)
1491 HW_SCE_AES_128EcbEncrypt(aesContext->
ek, 4, j,
b);
1493 else if(aesContext->
nr == 12)
1495 HW_SCE_AES_192EcbEncrypt(aesContext->
ek, 4, j,
b);
1499 HW_SCE_AES_256EcbEncrypt(aesContext->
ek, 4, j,
b);
1526 HW_SCE_AES_Ghash(context->
m[0],
s, k / 4, (
const uint32_t *)
a,
s);
1541 HW_SCE_AES_Ghash(context->
m[0],
s, 4,
b,
s);
1555 HW_SCE_AES_Ghash(context->
m[0],
s, k / 4, (
const uint32_t *)
c,
s);
1558 if(aesContext->
nr == 10)
1560 HW_SCE_AES_128GctrEncrypt(aesContext->
ek, j, k / 4,
1561 (
const uint32_t *)
c, (uint32_t *)
p, j);
1563 else if(aesContext->
nr == 12)
1565 HW_SCE_AES_192GctrEncrypt(aesContext->
ek, j, k / 4,
1566 (
const uint32_t *)
c, (uint32_t *)
p, j);
1570 HW_SCE_AES_256GctrEncrypt(aesContext->
ek, j, k / 4,
1571 (
const uint32_t *)
c, (uint32_t *)
p, j);
1588 HW_SCE_AES_Ghash(context->
m[0],
s, 4,
b,
s);
1591 if(aesContext->
nr == 10)
1593 HW_SCE_AES_128GctrEncrypt(aesContext->
ek, j, 4,
b,
b, j);
1595 else if(aesContext->
nr == 12)
1597 HW_SCE_AES_192GctrEncrypt(aesContext->
ek, j, 4,
b,
b, j);
1601 HW_SCE_AES_256GctrEncrypt(aesContext->
ek, j, 4,
b,
b, j);
1619 HW_SCE_AES_Ghash(context->
m[0],
s, 4,
b,
s);
1626 for(
mask = 0,
n = 0;
n < tLen;
n++)