Adding SHA-384/512 support, Null Checks, RNG Health Test for HW, and MAA call update for MAX3266X Port.

pull/7777/head
night1rider 2024-08-05 12:32:42 -06:00 committed by ZackLabPC
parent d714e55a2b
commit fe7987f241
7 changed files with 272 additions and 78 deletions

View File

@ -5412,16 +5412,23 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
int status; int status;
byte *iv; byte *iv;
#ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS if ((in == NULL) || (out == NULL) || (aes == NULL)) {
if (sz % AES_BLOCK_SIZE) { return BAD_FUNC_ARG;
return BAD_LENGTH_E;
} }
#endif
if (sz == 0) /* Always enforce a length check */
if (sz % AES_BLOCK_SIZE) {
#ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
return BAD_LENGTH_E;
#else
return BAD_FUNC_ARG;
}
#endif
if (sz == 0) {
return 0; return 0;
}
iv = (byte*)aes->reg; iv = (byte*)aes->reg;
status = wc_AesGetKeySize(aes, &keySize); status = wc_AesGetKeySize(aes, &keySize);
if (status != 0) { if (status != 0) {
return status; return status;
@ -5430,12 +5437,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
status = wc_MXC_TPU_AesEncrypt(in, iv, (byte*)aes->key, status = wc_MXC_TPU_AesEncrypt(in, iv, (byte*)aes->key,
MXC_TPU_MODE_CBC, sz, out, MXC_TPU_MODE_CBC, sz, out,
(unsigned int)keySize); (unsigned int)keySize);
/* store iv for next call */ /* store iv for next call */
if (status == 0) { if (status == 0) {
XMEMCPY(iv, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); XMEMCPY(iv, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
} }
return (status == 0) ? 0 : -1; return (status == 0) ? 0 : -1;
} }
@ -5447,16 +5452,23 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
byte *iv; byte *iv;
byte temp_block[AES_BLOCK_SIZE]; byte temp_block[AES_BLOCK_SIZE];
#ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS if ((in == NULL) || (out == NULL) || (aes == NULL)) {
if (sz % AES_BLOCK_SIZE) { return BAD_FUNC_ARG;
return BAD_LENGTH_E;
} }
#endif
if (sz == 0) /* Always enforce a length check */
if (sz % AES_BLOCK_SIZE) {
#ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
return BAD_LENGTH_E;
#else
return BAD_FUNC_ARG;
}
#endif
if (sz == 0) {
return 0; return 0;
}
iv = (byte*)aes->reg; iv = (byte*)aes->reg;
status = wc_AesGetKeySize(aes, &keySize); status = wc_AesGetKeySize(aes, &keySize);
if (status != 0) { if (status != 0) {
return status; return status;
@ -5464,17 +5476,14 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
/* get IV for next call */ /* get IV for next call */
XMEMCPY(temp_block, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); XMEMCPY(temp_block, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
status = wc_MXC_TPU_AesDecrypt(in, iv, (byte*)aes->key, status = wc_MXC_TPU_AesDecrypt(in, iv, (byte*)aes->key,
MXC_TPU_MODE_CBC, sz, out, MXC_TPU_MODE_CBC, sz, out,
keySize); keySize);
/* store iv for next call */ /* store iv for next call */
if (status == 0) { if (status == 0) {
XMEMCPY(iv, temp_block, AES_BLOCK_SIZE); XMEMCPY(iv, temp_block, AES_BLOCK_SIZE);
} }
return (status == 0) ? 0 : -1; return (status == 0) ? 0 : -1;
} }
#endif /* HAVE_AES_DECRYPT */ #endif /* HAVE_AES_DECRYPT */

View File

@ -41,30 +41,26 @@ all other operations will use the default software implementations.
The other prerequisite is that a change needs to be made to the Maxim SDK. This The other prerequisite is that a change needs to be made to the Maxim SDK. This
is to use the MAA Math Accelerator, this change only needs to be made if you are is to use the MAA Math Accelerator, this change only needs to be made if you are
using `#define WOLFSSL_MAX3266X` or `define WOLFSSL_MAX3266X_OLD` by themselves using `#define WOLFSSL_MAX3266X` or `define WOLFSSL_MAX3266X_OLD` by themselves
or you are specifying `#define MAX3266X_MATH`. or you are specifying `#define MAX3266X_MATH`. This is only needed if you are
not using the latest Maxim SDK.
In the SDK you will need to find the underlying function that In the SDK you will need to find the underlying function that
`MXC_TPU_MAA_Compute()` from `tpu.h` compute calls in the newer SDK. In the `MXC_TPU_MAA_Compute()` from `tpu.h` compute calls in the newer SDK. In the
older SDK this function is called `MAA_Compute()` in `maa.h`. In the underlying older SDK this function is called `MAA_Compute()` in `maa.h`. In the underlying
function you will need to change this error check: function you will need to this:
``` ```
// Check that we're performing a valid operation MXC_SETFIELD(tpu->maa_ctrl, MXC_F_TPU_REVA_MAA_CTRL_CLC, clc);
if (clc >= 0x6) {
return E_INVALID;
}
``` ```
to to
``` ```
// Check that we're performing a valid operation MXC_SETFIELD(tpu->maa_ctrl, MXC_F_TPU_REVA_MAA_CTRL_CLC,
if (clc >= 0b1111) { clc << MXC_F_TPU_REVA_MAA_CTRL_CLC_POS);
return E_INVALID;
}
``` ```
This bug has been reported to Analog Devices This bug has been reported to Analog Devices and a PR has been made
[here](https://github.com/analogdevicesinc/msdk/issues/1089) [here](https://github.com/analogdevicesinc/msdk/pull/1104)
if you want to know more details on the issue. if you want to know more details on the issue, or use a patch.
## Supported Algos ## Supported Algos
@ -81,17 +77,21 @@ hardware.
`#define MAX3266X_SHA`: `#define MAX3266X_SHA`:
- SHA-1
- SHA-224
- SHA-256 - SHA-256
- SHA-384
- SHA-512
`#define MAX3266X_MATH` (Replaces math operation calls for algos `#define MAX3266X_MATH` (Replaces math operation calls for algos
like RSA and ECC key generation): like RSA and ECC key generation):
- mod - `a mod m = r` - mod: `a mod m = r`
- addmod - `(a+b)mod m = r` - addmod: `(a+b)mod m = r`
- submod - `(a-b)mod m = r` - submod: `(a-b)mod m = r`
- mulmod - `(a*b)mod m = r` - mulmod: `(a*b)mod m = r`
- sqrmod - `(b^2)mod m = r` - sqrmod: `(b^2)mod m = r`
- exptmod - `(b^e)mod m = r` - exptmod: `(b^e)mod m = r`
## Extra Information ## Extra Information
For more Verbose info you can use `#define DEBUG_WOLFSSL` in combination with For more Verbose info you can use `#define DEBUG_WOLFSSL` in combination with

View File

@ -360,16 +360,26 @@ int wc_MXC_TPU_SHA_GetDigest(wc_MXC_Sha *hash, unsigned char* digest,
XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA1, WC_SHA_DIGEST_SIZE); XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA1, WC_SHA_DIGEST_SIZE);
break; break;
#endif /* NO_SHA */ #endif /* NO_SHA */
#ifndef NO_SHA256
case MXC_TPU_HASH_SHA256:
XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA256, WC_SHA256_DIGEST_SIZE);
break;
#endif /* NO_SHA256 */
#ifdef WOLFSSL_SHA224 #ifdef WOLFSSL_SHA224
case MXC_TPU_HASH_SHA224: case MXC_TPU_HASH_SHA224:
XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA224, WC_SHA224_DIGEST_SIZE); XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA224, WC_SHA224_DIGEST_SIZE);
break; break;
#endif /* WOLFSSL_SHA224 */ #endif /* WOLFSSL_SHA224 */
#ifndef NO_SHA256
case MXC_TPU_HASH_SHA256:
XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA256, WC_SHA256_DIGEST_SIZE);
break;
#endif /* NO_SHA256 */
#ifdef WOLFSSL_SHA384
case MXC_TPU_HASH_SHA384:
XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA384, WC_SHA384_DIGEST_SIZE);
break;
#endif /* WOLFSSL_SHA384 */
#ifdef WOLFSSL_SHA512
case MXC_TPU_HASH_SHA512:
XMEMCPY(digest, MXC_EMPTY_DIGEST_SHA512, WC_SHA512_DIGEST_SIZE);
break;
#endif /* WOLFSSL_SHA512 */
default: default:
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
@ -517,6 +527,102 @@ WOLFSSL_API void wc_Sha256Free(wc_Sha256* sha256)
#endif /* NO_SHA256 */ #endif /* NO_SHA256 */
#if defined(WOLFSSL_SHA384)
WOLFSSL_API int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
{
if (sha384 == NULL) {
return BAD_FUNC_ARG;
}
(void)heap;
(void)devId;
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha384);
}
WOLFSSL_API int wc_InitSha384(wc_Sha384* sha384)
{
return wc_InitSha384_ex(sha384, NULL, INVALID_DEVID);
}
WOLFSSL_API int wc_Sha384Update(wc_Sha384* sha384, const unsigned char* data,
unsigned int len)
{
return wc_MXC_TPU_SHA_Update(sha384, data, len);
}
WOLFSSL_API int wc_Sha384Final(wc_Sha384* sha384, unsigned char* hash)
{
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha384, hash,
MXC_TPU_HASH_SHA384);
}
WOLFSSL_API int wc_Sha384GetHash(wc_Sha384* sha384, unsigned char* hash)
{
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha384, hash,
MXC_TPU_HASH_SHA384);
}
WOLFSSL_API int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
{
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
}
WOLFSSL_API void wc_Sha384Free(wc_Sha384* sha384)
{
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha384);
return;
}
#endif /* WOLFSSL_SHA384 */
#if defined(WOLFSSL_SHA512)
WOLFSSL_API int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
{
if (sha512 == NULL) {
return BAD_FUNC_ARG;
}
(void)heap;
(void)devId;
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha512);
}
WOLFSSL_API int wc_InitSha512(wc_Sha512* sha512)
{
return wc_InitSha512_ex(sha512, NULL, INVALID_DEVID);
}
WOLFSSL_API int wc_Sha512Update(wc_Sha512* sha512, const unsigned char* data,
unsigned int len)
{
return wc_MXC_TPU_SHA_Update(sha512, data, len);
}
WOLFSSL_API int wc_Sha512Final(wc_Sha512* sha512, unsigned char* hash)
{
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha512, hash,
MXC_TPU_HASH_SHA512);
}
WOLFSSL_API int wc_Sha512GetHash(wc_Sha512* sha512, unsigned char* hash)
{
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha512, hash,
MXC_TPU_HASH_SHA512);
}
WOLFSSL_API int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
{
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
}
WOLFSSL_API void wc_Sha512Free(wc_Sha512* sha512)
{
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha512);
return;
}
#endif /* WOLFSSL_SHA512 */
#endif /* MAX3266X_SHA */ #endif /* MAX3266X_SHA */
#if defined(MAX3266X_MATH) #if defined(MAX3266X_MATH)
@ -615,7 +721,7 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
if ((result == NULL) || (multiplier == NULL) || (multiplicand == NULL) || if ((result == NULL) || (multiplier == NULL) || (multiplicand == NULL) ||
((exp == NULL) && (clc == WC_MXC_TPU_MAA_EXP)) || (mod == NULL)) { ((exp == NULL) && (clc == MXC_TPU_MAA_EXP)) || (mod == NULL)) {
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
@ -630,7 +736,7 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
/* Check for invalid arguments befor padding */ /* Check for invalid arguments befor padding */
switch ((char)clc) { switch ((char)clc) {
case WC_MXC_TPU_MAA_EXP: case MXC_TPU_MAA_EXP:
/* Cannot be 0 for a^e mod m operation */ /* Cannot be 0 for a^e mod m operation */
if (XMEMCMP(zero_tmp, exp, (exp->used*sizeof(mp_digit))) == 0) { if (XMEMCMP(zero_tmp, exp, (exp->used*sizeof(mp_digit))) == 0) {
XFREE(zero_tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(zero_tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@ -638,9 +744,9 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
/* Padd out rest of data if used != length to ensure no */ /* Pad out rest of data if used != length to ensure no */
/* garbage is used in calculation */ /* garbage is used in calculation */
if ((exp != NULL) && (clc == WC_MXC_TPU_MAA_EXP)) { if ((exp != NULL) && (clc == MXC_TPU_MAA_EXP)) {
if ((exp->dp != NULL) && (exp->used < length)) { if ((exp->dp != NULL) && (exp->used < length)) {
MAX3266X_MSG("Zero Padding Exp Buffer"); MAX3266X_MSG("Zero Padding Exp Buffer");
XMEMSET(exp->dp + exp->used, 0x00, XMEMSET(exp->dp + exp->used, 0x00,
@ -649,11 +755,11 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
} }
/* Fall through to check mod is not 0 */ /* Fall through to check mod is not 0 */
case WC_MXC_TPU_MAA_SQ: case MXC_TPU_MAA_SQ:
case WC_MXC_TPU_MAA_MUL: case MXC_TPU_MAA_MUL:
case WC_MXC_TPU_MAA_SQMUL: case MXC_TPU_MAA_SQMUL:
case WC_MXC_TPU_MAA_ADD: case MXC_TPU_MAA_ADD:
case WC_MXC_TPU_MAA_SUB: case MXC_TPU_MAA_SUB:
/* Cannot be 0 for mod m value */ /* Cannot be 0 for mod m value */
if (XMEMCMP(zero_tmp, mod, (exp->used*sizeof(mp_digit))) == 0) { if (XMEMCMP(zero_tmp, mod, (exp->used*sizeof(mp_digit))) == 0) {
XFREE(zero_tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(zero_tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@ -723,7 +829,7 @@ int wc_MXC_MAA_math(mp_int* multiplier, mp_int* multiplicand, mp_int* exp,
return MP_VAL; return MP_VAL;
} }
if (clc == WC_MXC_TPU_MAA_EXP) { if (clc == MXC_TPU_MAA_EXP) {
length = wc_MXC_MAA_Largest(5, multiplier->used, multiplicand->used, length = wc_MXC_MAA_Largest(5, multiplier->used, multiplicand->used,
exp->used, mod->used, result->used); exp->used, mod->used, result->used);
} }
@ -791,7 +897,7 @@ int wc_MXC_MAA_expmod(mp_int* base, mp_int* exp, mp_int* mod,
multiplicand.used = mod->used; multiplicand.used = mod->used;
MAX3266X_MSG("Preparing exptmod MAA HW Call"); MAX3266X_MSG("Preparing exptmod MAA HW Call");
return wc_MXC_MAA_math(base, &multiplicand, exp, mod, result, return wc_MXC_MAA_math(base, &multiplicand, exp, mod, result,
WC_MXC_TPU_MAA_EXP); MXC_TPU_MAA_EXP);
} }
int wc_MXC_MAA_sqrmod(mp_int* multiplier, mp_int* mod, mp_int* result) int wc_MXC_MAA_sqrmod(mp_int* multiplier, mp_int* mod, mp_int* result)
@ -802,7 +908,7 @@ int wc_MXC_MAA_sqrmod(mp_int* multiplier, mp_int* mod, mp_int* result)
multiplicand.used = mod->used; multiplicand.used = mod->used;
MAX3266X_MSG("Preparing sqrmod MAA HW Call"); MAX3266X_MSG("Preparing sqrmod MAA HW Call");
return wc_MXC_MAA_math(multiplier, &multiplicand, NULL, mod, result, return wc_MXC_MAA_math(multiplier, &multiplicand, NULL, mod, result,
WC_MXC_TPU_MAA_SQ); MXC_TPU_MAA_SQ);
} }
int wc_MXC_MAA_mulmod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod, int wc_MXC_MAA_mulmod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod,
@ -810,7 +916,7 @@ int wc_MXC_MAA_mulmod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod,
{ {
MAX3266X_MSG("Preparing mulmod MAA HW Call"); MAX3266X_MSG("Preparing mulmod MAA HW Call");
return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result, return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result,
WC_MXC_TPU_MAA_MUL); MXC_TPU_MAA_MUL);
} }
int wc_MXC_MAA_sqrmulmod(mp_int* multiplier, mp_int* multiplicand, int wc_MXC_MAA_sqrmulmod(mp_int* multiplier, mp_int* multiplicand,
@ -818,7 +924,7 @@ int wc_MXC_MAA_sqrmulmod(mp_int* multiplier, mp_int* multiplicand,
{ {
MAX3266X_MSG("Preparing sqrmulmod MAA HW Call"); MAX3266X_MSG("Preparing sqrmulmod MAA HW Call");
return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result, return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result,
WC_MXC_TPU_MAA_SQMUL); MXC_TPU_MAA_SQMUL);
} }
int wc_MXC_MAA_addmod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod, int wc_MXC_MAA_addmod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod,
@ -826,7 +932,7 @@ int wc_MXC_MAA_addmod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod,
{ {
MAX3266X_MSG("Preparing addmod MAA HW Call"); MAX3266X_MSG("Preparing addmod MAA HW Call");
return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result, return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result,
WC_MXC_TPU_MAA_ADD); MXC_TPU_MAA_ADD);
} }
int wc_MXC_MAA_submod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod, int wc_MXC_MAA_submod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod,
@ -839,7 +945,7 @@ int wc_MXC_MAA_submod(mp_int* multiplier, mp_int* multiplicand, mp_int* mod,
} }
else { else {
return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result, return wc_MXC_MAA_math(multiplier, multiplicand, NULL, mod, result,
WC_MXC_TPU_MAA_SUB); MXC_TPU_MAA_SUB);
} }
} }

View File

@ -3839,7 +3839,17 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
#elif defined(MAX3266X_RNG) #elif defined(MAX3266X_RNG)
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{ {
static int initDone = 0;
(void)os; (void)os;
if (initDone == 0) {
if(MXC_TRNG_HealthTest() != 0) {
#if defined(DEBUG_WOLFSSL)
WOLFSSL_MSG("TRNG HW Health Test Failed");
#endif
return WC_HW_E;
}
initDone = 1;
}
return wc_MXC_TRNG_Random(output, sz); return wc_MXC_TRNG_Random(output, sz);
} }

View File

@ -96,6 +96,11 @@
#include <wolfssl/wolfcrypt/port/nxp/se050_port.h> #include <wolfssl/wolfcrypt/port/nxp/se050_port.h>
#endif #endif
#if defined(MAX3266X_SHA)
/* Already brought in by sha512.h */
/* #include <wolfssl/wolfcrypt/port/maxim/max3266x.h> */
#endif
#if defined(WOLFSSL_X86_64_BUILD) && defined(USE_INTEL_SPEEDUP) #if defined(WOLFSSL_X86_64_BUILD) && defined(USE_INTEL_SPEEDUP)
#if defined(__GNUC__) && ((__GNUC__ < 4) || \ #if defined(__GNUC__) && ((__GNUC__ < 4) || \
(__GNUC__ == 4 && __GNUC_MINOR__ <= 8)) (__GNUC__ == 4 && __GNUC_MINOR__ <= 8))
@ -149,6 +154,9 @@
!defined(NO_WOLFSSL_RENESAS_FSPSM_HASH) !defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)
/* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */ /* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */
#elif defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH)
int wc_InitSha512(wc_Sha512* sha512) int wc_InitSha512(wc_Sha512* sha512)
{ {
@ -1158,6 +1166,9 @@ int wc_Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
/* functions defined in wolfcrypt/src/port/renesas/renesas_fspsm_sha.c */ /* functions defined in wolfcrypt/src/port/renesas/renesas_fspsm_sha.c */
#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH)
#elif defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#else #else
static WC_INLINE int Sha512Final(wc_Sha512* sha512) static WC_INLINE int Sha512Final(wc_Sha512* sha512)
@ -1318,6 +1329,9 @@ static WC_INLINE int Sha512Final(wc_Sha512* sha512)
!defined(NO_WOLFSSL_RENESAS_FSPSM_HASH) !defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)
/* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */ /* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */
#elif defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#else #else
static int Sha512FinalRaw(wc_Sha512* sha512, byte* hash, size_t digestSz) static int Sha512FinalRaw(wc_Sha512* sha512, byte* hash, size_t digestSz)
@ -1394,6 +1408,10 @@ int wc_Sha512Final(wc_Sha512* sha512, byte* hash)
#endif /* WOLFSSL_KCAPI_HASH */ #endif /* WOLFSSL_KCAPI_HASH */
#if defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#else
#if !defined(WOLFSSL_SE050) || !defined(WOLFSSL_SE050_HASH) #if !defined(WOLFSSL_SE050) || !defined(WOLFSSL_SE050_HASH)
int wc_InitSha512(wc_Sha512* sha512) int wc_InitSha512(wc_Sha512* sha512)
{ {
@ -1442,6 +1460,8 @@ void wc_Sha512Free(wc_Sha512* sha512)
ForceZero(sha512, sizeof(*sha512)); ForceZero(sha512, sizeof(*sha512));
} }
#endif
#if (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) \ #if (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) \
&& !defined(WOLFSSL_KCAPI_HASH) && !defined(WOLFSSL_KCAPI_HASH)
/* Apply SHA512 transformation to the data */ /* Apply SHA512 transformation to the data */
@ -1560,6 +1580,9 @@ int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data)
!defined(NO_WOLFSSL_RENESAS_FSPSM_HASH) !defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)
/* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */ /* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */
#elif defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#else #else
static int InitSha384(wc_Sha384* sha384) static int InitSha384(wc_Sha384* sha384)
@ -1755,6 +1778,10 @@ int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
#endif /* WOLFSSL_IMX6_CAAM || WOLFSSL_SILABS_SHA512 || WOLFSSL_KCAPI_HASH */ #endif /* WOLFSSL_IMX6_CAAM || WOLFSSL_SILABS_SHA512 || WOLFSSL_KCAPI_HASH */
#if defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#else
int wc_InitSha384(wc_Sha384* sha384) int wc_InitSha384(wc_Sha384* sha384)
{ {
int devId = INVALID_DEVID; int devId = INVALID_DEVID;
@ -1813,6 +1840,7 @@ void wc_Sha384Free(wc_Sha384* sha384)
ForceZero(sha384, sizeof(*sha384)); ForceZero(sha384, sizeof(*sha384));
} }
#endif
#endif /* WOLFSSL_SHA384 */ #endif /* WOLFSSL_SHA384 */
#ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SHA512
@ -1824,6 +1852,9 @@ void wc_Sha384Free(wc_Sha384* sha384)
!defined(NO_WOLFSSL_RENESAS_FSPSM_HASH) !defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)
/* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */ /* functions defined in wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c */
#elif defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#else #else
static int Sha512_Family_GetHash(wc_Sha512* sha512, byte* hash, static int Sha512_Family_GetHash(wc_Sha512* sha512, byte* hash,
@ -2115,6 +2146,8 @@ int wc_Sha512_256Transform(wc_Sha512* sha, const unsigned char* data)
#elif defined(WOLFSSL_RENESAS_RSIP) && \ #elif defined(WOLFSSL_RENESAS_RSIP) && \
!defined(NO_WOLFSSL_RENESAS_FSPSM_HASH) !defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)
/* functions defined in wolfcrypt/src/port/renesas/renesas_fspsm_sha.c */ /* functions defined in wolfcrypt/src/port/renesas/renesas_fspsm_sha.c */
#elif defined(MAX3266X_SHA)
/* Functions defined in wolfcrypt/src/port/maxim/max3266x.c */
#else #else
int wc_Sha384GetHash(wc_Sha384* sha384, byte* hash) int wc_Sha384GetHash(wc_Sha384* sha384, byte* hash)

View File

@ -53,7 +53,9 @@
#if defined(MAX3266X_RNG) #if defined(MAX3266X_RNG)
#include "trng.h" /* Provides TRNG Drivers */ #include "trng.h" /* Provides TRNG Drivers */
#define MXC_TPU_TRNG_Read TRNG_Read #define MXC_TPU_TRNG_Read TRNG_Read
#warning "TRNG Health Test not available in older Maxim SDK"
#define MXC_TRNG_HealthTest(...) 0
#endif #endif
#if defined(MAX3266X_AES) #if defined(MAX3266X_AES)
#include "cipher.h" /* Provides Drivers for AES */ #include "cipher.h" /* Provides Drivers for AES */
@ -95,12 +97,12 @@
/* ECDSA and RSA Acceleration */ /* ECDSA and RSA Acceleration */
/* MAA Defines */ /* MAA Defines */
#define MXC_TPU_MAA_TYPE tpu_maa_clcsel_t #define MXC_TPU_MAA_TYPE tpu_maa_clcsel_t
#define WC_MXC_TPU_MAA_EXP 0b0000 #define MXC_TPU_MAA_EXP TPU_MAA_EXP
#define WC_MXC_TPU_MAA_SQ 0b0010 #define MXC_TPU_MAA_SQ TPU_MAA_SQ
#define WC_MXC_TPU_MAA_MUL 0b0100 #define MXC_TPU_MAA_MUL TPU_MAA_MUL
#define WC_MXC_TPU_MAA_SQMUL 0b0110 #define MXC_TPU_MAA_SQMUL TPU_MAA_SQMUL
#define WC_MXC_TPU_MAA_ADD 0b1000 #define MXC_TPU_MAA_ADD TPU_MAA_ADD
#define WC_MXC_TPU_MAA_SUB 0b1010 #define MXC_TPU_MAA_SUB TPU_MAA_SUB
/* MAA Functions */ /* MAA Functions */
#define MXC_TPU_MAA_Compute MAA_Compute #define MXC_TPU_MAA_Compute MAA_Compute
@ -134,22 +136,12 @@
#define MXC_TPU_CIPHER_TYPE mxc_tpu_ciphersel_t #define MXC_TPU_CIPHER_TYPE mxc_tpu_ciphersel_t
#define MXC_TPU_MODE_TYPE mxc_tpu_modesel_t #define MXC_TPU_MODE_TYPE mxc_tpu_modesel_t
/* SHA Defines */ /* SHA Defines */
#define MXC_TPU_HASH_TYPE mxc_tpu_hashfunsel_t #define MXC_TPU_HASH_TYPE mxc_tpu_hashfunsel_t
/* MAA Defines */ /* MAA Defines */
/* Current SDK for TPU does not handle bit mask correctly */
/* with expected enum values, so calue need to be set */
/* manually to work with intended naming scheme */
#define MXC_TPU_MAA_TYPE mxc_tpu_maa_clcsel_t #define MXC_TPU_MAA_TYPE mxc_tpu_maa_clcsel_t
#define WC_MXC_TPU_MAA_EXP 0b0000
#define WC_MXC_TPU_MAA_SQ 0b0010
#define WC_MXC_TPU_MAA_MUL 0b0100
#define WC_MXC_TPU_MAA_SQMUL 0b0110
#define WC_MXC_TPU_MAA_ADD 0b1000
#define WC_MXC_TPU_MAA_SUB 0b1010
#endif #endif
@ -234,7 +226,6 @@
0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
0xaf, 0xd8, 0x07, 0x09}; 0xaf, 0xd8, 0x07, 0x09};
#endif /* NO_SHA */ #endif /* NO_SHA */
#if defined(WOLFSSL_SHA224) #if defined(WOLFSSL_SHA224)
@ -248,7 +239,6 @@
0x47, 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4, 0x47, 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4,
0x15, 0xa2, 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a, 0x15, 0xa2, 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a,
0xc5, 0xb3, 0xe4, 0x2f}; 0xc5, 0xb3, 0xe4, 0x2f};
#endif /* WOLFSSL_SHA224 */ #endif /* WOLFSSL_SHA224 */
#if !defined(NO_SHA256) #if !defined(NO_SHA256)
@ -262,9 +252,52 @@
0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}; 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55};
#endif /* NO_SHA256 */ #endif /* NO_SHA256 */
#if defined(WOLFSSL_SHA384)
typedef wc_MXC_Sha wc_Sha384;
#define WC_SHA384_TYPE_DEFINED
/* Define the SHA-384 digest for an empty string */
/* as a constant byte array */
static const unsigned char MXC_EMPTY_DIGEST_SHA384[48] = {
0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38,
0x4c, 0xd9, 0x32, 0x7e, 0xb1, 0xb1, 0xe3, 0x6a,
0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43,
0x4c, 0x0c, 0xc7, 0xbf, 0x63, 0xf6, 0xe1, 0xda,
0x27, 0x4e, 0xde, 0xbf, 0xe7, 0x6f, 0x65, 0xfb,
0xd5, 0x1a, 0xd2, 0xf1, 0x48, 0x98, 0xb9, 0x5b};
#endif /* WOLFSSL_SHA384 */
#if defined(WOLFSSL_SHA512)
typedef wc_MXC_Sha wc_Sha512;
typedef wc_MXC_Sha wc_Sha512_224;
typedef wc_MXC_Sha wc_Sha512_256;
#define WC_SHA512_TYPE_DEFINED
/* Does not support these SHA512 Macros */
#ifndef WOLFSSL_NOSHA512_224
#warning "MAX3266X Port does not support SHA-512/224"
#define WOLFSSL_NOSHA512_224
#endif
#ifndef WOLFSSL_NOSHA512_256
#warning "MAX3266X Port does not support SHA-512/256"
#define WOLFSSL_NOSHA512_256
#endif
/* Define the SHA-512 digest for an empty string */
/* as a constant byte array */
static const unsigned char MXC_EMPTY_DIGEST_SHA512[64] = {
0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd,
0xf1, 0x54, 0x28, 0x50, 0xd6, 0x6d, 0x80, 0x07,
0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc,
0x83, 0xf4, 0xa9, 0x21, 0xd3, 0x6c, 0xe9, 0xce,
0x47, 0xd0, 0xd1, 0x3c, 0x5d, 0x85, 0xf2, 0xb0,
0xff, 0x83, 0x18, 0xd2, 0x87, 0x7e, 0xec, 0x2f,
0x63, 0xb9, 0x31, 0xbd, 0x47, 0x41, 0x7a, 0x81,
0xa5, 0x38, 0x32, 0x7a, 0xf9, 0x27, 0xda, 0x3e};
#endif /* WOLFSSL_SHA512 */
WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Init(wc_MXC_Sha *hash); WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Init(wc_MXC_Sha *hash);
WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Update(wc_MXC_Sha *hash, WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Update(wc_MXC_Sha *hash,

View File

@ -135,6 +135,9 @@ enum {
#include "mcapi.h" #include "mcapi.h"
#include "mcapi_error.h" #include "mcapi_error.h"
#endif #endif
#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
#include "wolfssl/wolfcrypt/port/maxim/max3266x.h"
#endif
/* wc_Sha512 digest */ /* wc_Sha512 digest */
struct wc_Sha512 { struct wc_Sha512 {
#ifdef WOLFSSL_PSOC6_CRYPTO #ifdef WOLFSSL_PSOC6_CRYPTO