Skip to content

Commit

Permalink
Merge pull request #6539 from JacobBarthelmeh/caam
Browse files Browse the repository at this point in the history
fix for keymod with rt1170 blobs
  • Loading branch information
dgarske committed Jun 23, 2023
2 parents 06c1dd1 + 2d87037 commit ea68920
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
34 changes: 24 additions & 10 deletions IDE/MCUEXPRESSO/RT1170/fsl_caam_c.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- fsl_caam-orig.c 2022-10-21 15:50:35.709951000 -0700
+++ fsl_caam.c 2022-12-28 06:30:34.788316189 -0800
@@ -7872,3 +7872,462 @@
--- fsl_caam.c 2023-01-12 23:39:04.000000000 -0800
+++ fsl_caam-expanded.c 2023-06-23 00:18:14.395128903 -0700
@@ -7872,3 +7872,476 @@
}
return status;
}
Expand Down Expand Up @@ -128,7 +128,9 @@
+ descriptor[4] |= enc;
+
+ /* schedule the job */
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ do {
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ } while (status == kStatus_CAAM_Again);
+ if (status == kStatus_Success) {
+ status = CAAM_Wait(base, handle, descriptor, kCAAM_Blocking);
+ }
Expand Down Expand Up @@ -212,7 +214,9 @@
+ descriptor[7] |= enc;
+
+ /* schedule the job */
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ do {
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ } while (status == kStatus_CAAM_Again);
+ if (status == kStatus_Success) {
+ status = CAAM_Wait(base, handle, descriptor, kCAAM_Blocking);
+ }
Expand Down Expand Up @@ -283,7 +287,9 @@
+ DESC_ADD_LEN(descriptor[7], sizeHash);
+
+ /* schedule the job */
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ do {
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ } while (status == kStatus_CAAM_Again);
+ if (status == kStatus_Success) {
+ status = CAAM_Wait(base, handle, descriptor, kCAAM_Blocking);
+ }
Expand Down Expand Up @@ -350,7 +356,9 @@
+ descriptor[5] |= enc;
+
+ /* schedule the job */
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ do {
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ } while (status == kStatus_CAAM_Again);
+ if (status == kStatus_Success) {
+ status = CAAM_Wait(base, handle, descriptor, kCAAM_Blocking);
+ }
Expand All @@ -367,7 +375,7 @@
+/* Handle BLOB create and open */
+static const uint32_t templateBlob[] = {
+ /* 00 */ 0xB0800000u, /* HEADER */
+ /* 01 */ 0x14400000u, /* class */
+ /* 01 */ 0x04000000u, /* class */
+ /* 02 */ 0x00000000u, /* key mod */
+ /* 03 */ 0xF0000000u, /* SEQ input size */
+ /* 04 */ 0x00000000u, /* input */
Expand Down Expand Up @@ -425,6 +433,10 @@
+ return status;
+ }
+
+ if (keyModSz != CAAM_SM_KEYMODSZ && keyModSz != CAAM_KEYMODSZ) {
+ return status;
+ }
+
+ if (dir == CAAM_DECAP_BLOB &&
+ (sizeOut > sizeIn - CAAM_PADDING_SIZE_BLOB)) {
+ return status;
Expand All @@ -435,7 +447,7 @@
+
+ /* add descriptor lenght in bytes to HEADER descriptor command */
+ DESC_HEADER_ADD_DESCLEN(descriptor[0], descriptorSize);
+ descriptor[1] |= color; /* add color of blob */
+ descriptor[1] |= keyModSz;
+ DESC_SET_ADDR(descriptor[2], keyMod);
+ DESC_ADD_LEN(descriptor[3], sizeIn);
+ DESC_SET_ADDR(descriptor[4], in);
Expand All @@ -450,7 +462,9 @@
+ }
+
+ /* schedule the job */
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ do {
+ status = caam_in_job_ring_add(base, handle->jobRing, &descriptor[0]);
+ } while (status == kStatus_CAAM_Again);
+ if (status == kStatus_Success) {
+ status = CAAM_Wait(base, handle, descriptor, kCAAM_Blocking);
+ }
Expand Down
12 changes: 7 additions & 5 deletions IDE/MCUEXPRESSO/RT1170/fsl_caam_h.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- fsl_caam-orig.h 2022-10-21 15:50:35.745560000 -0700
+++ fsl_caam.h 2022-12-28 08:10:29.413415216 -0800
@@ -3038,6 +3038,162 @@
--- fsl_caam.h 2023-06-23 00:08:46.491699533 -0700
+++ fsl_caam-expanded.h 2023-06-23 00:10:22.702730462 -0700
@@ -3038,6 +3038,164 @@
*@}
*/ /* end of caam_driver_pkha */

Expand Down Expand Up @@ -127,10 +127,12 @@
+
+/* define for application to check for ECC CAAM additions */
+#define CAAM_BLOB_EXPANSION
+#define CAAM_RED_BLOB 0x00000C08
+#define CAAM_BLACK_BLOB 0x00000010
+#define CAAM_RED_BLOB 1
+#define CAAM_BLACK_BLOB 2
+#define CAAM_ENCAP_BLOB 0x07000000
+#define CAAM_DECAP_BLOB 0x06000000
+#define CAAM_SM_KEYMODSZ 8
+#define CAAM_KEYMODSZ 16
+#define CAAM_PADDING_SIZE_BLOB 48
+
+/*!
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/port/caam/wolfcaam_fsl_nxp.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ int SynchronousSendRequest(int type, unsigned int args[4], CAAM_BUFFER *buf,
buf[1].Length, (byte*)buf[2].TheAddress,
buf[2].Length, (byte*)buf[0].TheAddress,
buf[0].Length, CAAM_ENCAP_BLOB,
(args[0] = 0)? CAAM_RED_BLOB : CAAM_BLACK_BLOB)
(args[0] == 0)? CAAM_RED_BLOB : CAAM_BLACK_BLOB)
!= kStatus_Success) {
ret = WC_HW_E;
}
Expand All @@ -849,7 +849,7 @@ int SynchronousSendRequest(int type, unsigned int args[4], CAAM_BUFFER *buf,
(byte*)buf[2].TheAddress, buf[2].Length,
(byte*)buf[0].TheAddress, buf[0].Length,
CAAM_DECAP_BLOB,
(args[0] = 0)? CAAM_RED_BLOB : CAAM_BLACK_BLOB)
(args[0] == 0)? CAAM_RED_BLOB : CAAM_BLACK_BLOB)
!= kStatus_Success) {
ret = WC_HW_E;
}
Expand Down
3 changes: 2 additions & 1 deletion wolfssl/wolfcrypt/port/caam/caam_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,6 @@ struct DESCSTRUCT {
#define MAX_ECDSA_SIGN_ADDR 8
#define BLACK_KEY_MAC_SZ 16
#define BLACK_BLOB_KEYMOD_SZ 16
#define RED_BLOB_KEYMOD_SZ 8
#define RED_BLOB_KEYMOD_SZ 16
#define SM_BLOB_KEYMOD_SZ 8
#endif /* CAAM_DRIVER_H */
3 changes: 2 additions & 1 deletion wolfssl/wolfcrypt/port/caam/wolfcaam.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ WOLFSSL_API int wc_caamCoverKey(byte* in, word32 inSz, byte* out, word32* outSz,
#define WC_CAAM_MAC_SZ 16
#define WC_CAAM_BLOB_RED 1
#define WC_CAAM_BLOB_BLACK 2
#define WC_CAAM_RED_KEYMOD_SZ 8
#define WC_CAAM_RED_KEYMOD_SZ 16
#define WC_CAAM_BLACK_KEYMOD_SZ 16
#define WC_SM_BLOB_KEYMOD_SZ 8
#define WC_CAAM_MAX_ENTROPY 44

#if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SECO_CAAM) && \
Expand Down

0 comments on commit ea68920

Please sign in to comment.