minor change of variable name and add settings check

This commit is contained in:
Jacob Barthelmeh
2017-12-20 13:59:20 -07:00
parent 351a673ec0
commit 20e69460b0
2 changed files with 43 additions and 32 deletions

View File

@@ -61,12 +61,13 @@ struct DescStruct {
struct buffer buf[MAX_BUF]; /* buffers holding data input address */ struct buffer buf[MAX_BUF]; /* buffers holding data input address */
UINT4 desc[MAX_DESC_SZ]; /* max size of 64 word32 */ UINT4 desc[MAX_DESC_SZ]; /* max size of 64 word32 */
UINT4 aadSzBuf[4]; /* Formated AAD size for CCM */ UINT4 aadSzBuf[4]; /* Formated AAD size for CCM */
UINT4 shaBuf[ALIGN_BUF]; /* 64 byte buffer for non page align */ UINT4 alignBuf[ALIGN_BUF]; /* 64 byte buffer for non page
align */
UINT4 iv[MAX_CTX]; /* AES IV and also hash state */ UINT4 iv[MAX_CTX]; /* AES IV and also hash state */
UINT4 ctxBuf[MAX_CTX]; /* key */ UINT4 ctxBuf[MAX_CTX]; /* key */
Address output; /* address to output buffer */ Address output; /* address to output buffer */
Address ctxOut; /* address to update buffer holding state */ Address ctxOut; /* address to update buffer holding state */
Value shaIdx; /* index for descriptor buffer */ Value alignIdx;/* index for align buffer */
Value idx; /* index for descriptor buffer */ Value idx; /* index for descriptor buffer */
Value headIdx; /* for first portion of descriptor buffer */ Value headIdx; /* for first portion of descriptor buffer */
Value lastIdx; /* for last portion of descriptor buffer */ Value lastIdx; /* for last portion of descriptor buffer */
@@ -78,7 +79,8 @@ struct DescStruct {
Value type; Value type;
Value state; Value state;
Value DescriptorCount; Value DescriptorCount;
Boolean running; /* True if building/running descriptor is in process */ Boolean running; /* True if building/running descriptor is
in process */
}; };
struct CAAM_DEVICE { struct CAAM_DEVICE {
@@ -399,33 +401,33 @@ static int caamAddIO(struct DescStruct* desc, UINT4 options, UINT4 sz,
if (dataSz % align > 0) { if (dataSz % align > 0) {
/* store potental overlap */ /* store potental overlap */
int tmpSz = dataSz % align; int tmpSz = dataSz % align;
int add = (tmpSz < (align - desc->shaIdx)) ? tmpSz : int add = (tmpSz < (align - desc->alignIdx)) ? tmpSz :
align - desc->shaIdx; align - desc->alignIdx;
unsigned char* local = (unsigned char*)desc->shaBuf; unsigned char* local = (unsigned char*)desc->alignBuf;
/* if already something in the buffer then add from front */ /* if already something in the buffer then add from front */
if (desc->shaIdx > 0) { if (desc->alignIdx > 0) {
memcpy((unsigned char*)&local[desc->shaIdx], memcpy((unsigned char*)&local[desc->alignIdx],
(unsigned char*)data, add); (unsigned char*)data, add);
data += add; data += add;
} }
else { else {
memcpy((unsigned char*)&local[desc->shaIdx], memcpy((unsigned char*)&local[desc->alignIdx],
(unsigned char*)data + (blocks * align), add); (unsigned char*)data + (blocks * align), add);
} }
dataSz -= add; dataSz -= add;
desc->shaIdx += add; desc->alignIdx += add;
} }
if (desc->shaIdx == align) { if (desc->alignIdx == align) {
desc->lastFifo = desc->idx; desc->lastFifo = desc->idx;
if (desc->idx + 2 > MAX_DESC_SZ) { if (desc->idx + 2 > MAX_DESC_SZ) {
return -1; return -1;
} }
desc->desc[desc->idx++] = options + desc->shaIdx; desc->desc[desc->idx++] = options + desc->alignIdx;
desc->desc[desc->idx++] = BSP_VirtualToPhysical(desc->shaBuf); desc->desc[desc->idx++] = BSP_VirtualToPhysical(desc->alignBuf);
ASP_FlushCaches((Address)desc->shaBuf, desc->shaIdx); ASP_FlushCaches((Address)desc->alignBuf, desc->alignIdx);
outSz += desc->shaIdx; outSz += desc->alignIdx;
} }
if (blocks > 0) { if (blocks > 0) {
@@ -439,8 +441,8 @@ static int caamAddIO(struct DescStruct* desc, UINT4 options, UINT4 sz,
/* only one buffer available for align cases so exit here and make /* only one buffer available for align cases so exit here and make
a new descriptor after running current one */ a new descriptor after running current one */
if (desc->shaIdx == align) { if (desc->alignIdx == align) {
desc->shaIdx = 0; desc->alignIdx = 0;
i++; /* start at next buffer */ i++; /* start at next buffer */
break; break;
} }
@@ -992,29 +994,29 @@ static Error caamAead(struct DescStruct* desc)
} }
/* handle alignment constraints on input */ /* handle alignment constraints on input */
if (desc->shaIdx > 0) { if (desc->alignIdx > 0) {
sz = desc->shaIdx; sz = desc->alignIdx;
/* if there is more input buffers then add part of it */ /* if there is more input buffers then add part of it */
if (i < desc->outputIdx && i < desc->DescriptorCount) { if (i < desc->outputIdx && i < desc->DescriptorCount) {
sz = align - desc->shaIdx; sz = align - desc->alignIdx;
sz = (sz <= desc->buf[i].dataSz) ? sz : desc->buf[i].dataSz; sz = (sz <= desc->buf[i].dataSz) ? sz : desc->buf[i].dataSz;
memcpy((unsigned char*)(desc->shaBuf) + desc->shaIdx, memcpy((unsigned char*)(desc->alignBuf) + desc->alignIdx,
(unsigned char*)(desc->buf[i].data), sz); (unsigned char*)(desc->buf[i].data), sz);
desc->buf[i].dataSz -= sz; desc->buf[i].dataSz -= sz;
desc->buf[i].data += sz; desc->buf[i].data += sz;
sz += desc->shaIdx; sz += desc->alignIdx;
} }
if (desc->idx + 2 > MAX_DESC_SZ) { if (desc->idx + 2 > MAX_DESC_SZ) {
return TransferFailed; return TransferFailed;
} }
ASP_FlushCaches((Address)desc->shaBuf, sz); ASP_FlushCaches((Address)desc->alignBuf, sz);
desc->desc[desc->idx++] = (CAAM_FIFO_L | FIFOL_TYPE_LC1 | desc->desc[desc->idx++] = (CAAM_FIFO_L | FIFOL_TYPE_LC1 |
CAAM_CLASS1 | FIFOL_TYPE_MSG) + sz; CAAM_CLASS1 | FIFOL_TYPE_MSG) + sz;
desc->desc[desc->idx++] = BSP_VirtualToPhysical(desc->shaBuf); desc->desc[desc->idx++] = BSP_VirtualToPhysical(desc->alignBuf);
desc->shaIdx = 0; desc->alignIdx = 0;
} }
else { else {
sz = desc->buf[i].dataSz; sz = desc->buf[i].dataSz;
@@ -1023,12 +1025,12 @@ static Error caamAead(struct DescStruct* desc)
align = 1; align = 1;
} }
desc->shaIdx = sz % align; desc->alignIdx = sz % align;
if (desc->shaIdx != 0) { if (desc->alignIdx != 0) {
sz -= desc->shaIdx; sz -= desc->alignIdx;
memcpy((unsigned char*)desc->shaBuf, memcpy((unsigned char*)desc->alignBuf,
(unsigned char*)(desc->buf[i].data) + sz, (unsigned char*)(desc->buf[i].data) + sz,
desc->shaIdx); desc->alignIdx);
} }
if (desc->idx + 2 > MAX_DESC_SZ) { if (desc->idx + 2 > MAX_DESC_SZ) {
@@ -1457,7 +1459,7 @@ static Error caamTransferStart(IODeviceVector ioCaam,
desc->output = 0; desc->output = 0;
desc->ctxOut = 0; desc->ctxOut = 0;
desc->outputIdx = 0; desc->outputIdx = 0;
desc->shaIdx = 0; desc->alignIdx = 0;
desc->lastFifo = 0; desc->lastFifo = 0;
desc->state = args[0]; desc->state = args[0];
desc->ctxSz = args[1]; desc->ctxSz = args[1];

View File

@@ -1189,6 +1189,15 @@ extern void uITRON4_free(void *p) ;
#endif #endif
#endif #endif
/* if defined turn on all CAAM support */
#ifdef WOLFSSL_IMX6_CAAM
#undef WOLFSSL_IMX6_CAAM_RNG
#define WOLFSSL_IMX6_CAAM_RNG
#undef WOLFSSL_IMX6_CAAM_BLOB
#define WOLFSSL_IMX6_CAAM_BLOB
#endif
#if !defined(XMALLOC_USER) && !defined(MICRIUM_MALLOC) && \ #if !defined(XMALLOC_USER) && !defined(MICRIUM_MALLOC) && \
!defined(WOLFSSL_LEANPSK) && !defined(NO_WOLFSSL_MEMORY) && \ !defined(WOLFSSL_LEANPSK) && !defined(NO_WOLFSSL_MEMORY) && \
!defined(XMALLOC_OVERRIDE) !defined(XMALLOC_OVERRIDE)