Skip to content

Commit

Permalink
Merge pull request #8075 from night1rider/MAX-HW-SHA-FIX
Browse files Browse the repository at this point in the history
Fixing CB needing HAVE_AES_ECB and SHA struct issue for MAX32666/5 port
  • Loading branch information
douzzer authored Oct 16, 2024
2 parents 0c640eb + 1449f4f commit cc421dd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 65 deletions.
4 changes: 2 additions & 2 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,7 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
outBlock, (unsigned int)keySize);
}
#endif
#ifdef MAX3266X_CB /* Can do a basic ECB block */
#if defined(MAX3266X_CB) && defined(HAVE_AES_ECB) /* Can do a basic ECB block */
#ifndef WOLF_CRYPTO_CB_FIND
if (aes->devId != INVALID_DEVID)
#endif
Expand Down Expand Up @@ -3668,7 +3668,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
}
#endif

#ifdef MAX3266X_CB /* Can do a basic ECB block */
#if defined(MAX3266X_CB) && defined(HAVE_AES_ECB) /* Can do a basic ECB block */
#ifndef WOLF_CRYPTO_CB_FIND
if (aes->devId != INVALID_DEVID)
#endif
Expand Down
60 changes: 30 additions & 30 deletions wolfcrypt/src/port/maxim/max3266x.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,35 +789,35 @@ WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId)
}
(void)heap;
(void)devId;
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha);
return wc_MXC_TPU_SHA_Init(&(sha->mxcCtx));
}

WOLFSSL_API int wc_ShaUpdate(wc_Sha* sha, const unsigned char* data,
unsigned int len)
{
return wc_MXC_TPU_SHA_Update(sha, data, len);
return wc_MXC_TPU_SHA_Update(&(sha->mxcCtx), data, len);
}

WOLFSSL_API int wc_ShaFinal(wc_Sha* sha, unsigned char* hash)
{
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha, hash,
return wc_MXC_TPU_SHA_Final(&(sha->mxcCtx), hash,
MXC_TPU_HASH_SHA1);
}

WOLFSSL_API int wc_ShaGetHash(wc_Sha* sha, unsigned char* hash)
{
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha, hash,
return wc_MXC_TPU_SHA_GetHash(&(sha->mxcCtx), hash,
MXC_TPU_HASH_SHA1);
}

WOLFSSL_API int wc_ShaCopy(wc_Sha* src, wc_Sha* dst)
{
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
}

WOLFSSL_API void wc_ShaFree(wc_Sha* sha)
{
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha);
wc_MXC_TPU_SHA_Free(&(sha->mxcCtx));
return;
}

Expand All @@ -832,7 +832,7 @@ WOLFSSL_API int wc_InitSha224_ex(wc_Sha224* sha224, void* heap, int devId)
}
(void)heap;
(void)devId;
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha224);
return wc_MXC_TPU_SHA_Init(&(sha224->mxcCtx));
}

WOLFSSL_API int wc_InitSha224(wc_Sha224* sha224)
Expand All @@ -843,29 +843,29 @@ WOLFSSL_API int wc_InitSha224(wc_Sha224* sha224)
WOLFSSL_API int wc_Sha224Update(wc_Sha224* sha224, const unsigned char* data,
unsigned int len)
{
return wc_MXC_TPU_SHA_Update(sha224, data, len);
return wc_MXC_TPU_SHA_Update(&(sha224->mxcCtx), data, len);
}

WOLFSSL_API int wc_Sha224Final(wc_Sha224* sha224, unsigned char* hash)
{
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha224, hash,
return wc_MXC_TPU_SHA_Final(&(sha224->mxcCtx), hash,
MXC_TPU_HASH_SHA224);
}

WOLFSSL_API int wc_Sha224GetHash(wc_Sha224* sha224, unsigned char* hash)
{
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha224, hash,
return wc_MXC_TPU_SHA_GetHash(&(sha224->mxcCtx), hash,
MXC_TPU_HASH_SHA224);
}

WOLFSSL_API int wc_Sha224Copy(wc_Sha224* src, wc_Sha224* dst)
{
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
}

WOLFSSL_API void wc_Sha224Free(wc_Sha224* sha224)
{
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha224);
wc_MXC_TPU_SHA_Free(&(sha224->mxcCtx));
return;
}

Expand All @@ -880,7 +880,7 @@ WOLFSSL_API int wc_InitSha256_ex(wc_Sha256* sha256, void* heap, int devId)
}
(void)heap;
(void)devId;
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha256);
return wc_MXC_TPU_SHA_Init(&(sha256->mxcCtx));
}

WOLFSSL_API int wc_InitSha256(wc_Sha256* sha256)
Expand All @@ -891,29 +891,29 @@ WOLFSSL_API int wc_InitSha256(wc_Sha256* sha256)
WOLFSSL_API int wc_Sha256Update(wc_Sha256* sha256, const unsigned char* data,
unsigned int len)
{
return wc_MXC_TPU_SHA_Update(sha256, data, len);
return wc_MXC_TPU_SHA_Update(&(sha256->mxcCtx), data, len);
}

WOLFSSL_API int wc_Sha256Final(wc_Sha256* sha256, unsigned char* hash)
{
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha256, hash,
return wc_MXC_TPU_SHA_Final(&(sha256->mxcCtx), hash,
MXC_TPU_HASH_SHA256);
}

WOLFSSL_API int wc_Sha256GetHash(wc_Sha256* sha256, unsigned char* hash)
{
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha256, hash,
return wc_MXC_TPU_SHA_GetHash(&(sha256->mxcCtx), hash,
MXC_TPU_HASH_SHA256);
}

WOLFSSL_API int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
{
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
}

WOLFSSL_API void wc_Sha256Free(wc_Sha256* sha256)
{
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha256);
wc_MXC_TPU_SHA_Free(&(sha256->mxcCtx));
return;
}

Expand All @@ -928,7 +928,7 @@ WOLFSSL_API int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
}
(void)heap;
(void)devId;
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha384);
return wc_MXC_TPU_SHA_Init(&(sha384->mxcCtx));
}

WOLFSSL_API int wc_InitSha384(wc_Sha384* sha384)
Expand All @@ -939,29 +939,29 @@ WOLFSSL_API int wc_InitSha384(wc_Sha384* sha384)
WOLFSSL_API int wc_Sha384Update(wc_Sha384* sha384, const unsigned char* data,
unsigned int len)
{
return wc_MXC_TPU_SHA_Update(sha384, data, len);
return wc_MXC_TPU_SHA_Update(&(sha384->mxcCtx), data, len);
}

WOLFSSL_API int wc_Sha384Final(wc_Sha384* sha384, unsigned char* hash)
{
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha384, hash,
return wc_MXC_TPU_SHA_Final(&(sha384->mxcCtx), 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,
return wc_MXC_TPU_SHA_GetHash(&(sha384->mxcCtx), 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);
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
}

WOLFSSL_API void wc_Sha384Free(wc_Sha384* sha384)
{
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha384);
wc_MXC_TPU_SHA_Free(&(sha384->mxcCtx));
return;
}

Expand All @@ -976,7 +976,7 @@ WOLFSSL_API int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
}
(void)heap;
(void)devId;
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha512);
return wc_MXC_TPU_SHA_Init(&(sha512->mxcCtx));
}

WOLFSSL_API int wc_InitSha512(wc_Sha512* sha512)
Expand All @@ -987,29 +987,29 @@ WOLFSSL_API int wc_InitSha512(wc_Sha512* sha512)
WOLFSSL_API int wc_Sha512Update(wc_Sha512* sha512, const unsigned char* data,
unsigned int len)
{
return wc_MXC_TPU_SHA_Update(sha512, data, len);
return wc_MXC_TPU_SHA_Update(&(sha512->mxcCtx), data, len);
}

WOLFSSL_API int wc_Sha512Final(wc_Sha512* sha512, unsigned char* hash)
{
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha512, hash,
return wc_MXC_TPU_SHA_Final(&(sha512->mxcCtx), 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,
return wc_MXC_TPU_SHA_GetHash(&(sha512->mxcCtx), 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);
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
}

WOLFSSL_API void wc_Sha512Free(wc_Sha512* sha512)
{
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha512);
wc_MXC_TPU_SHA_Free(&(sha512->mxcCtx));
return;
}

Expand Down
33 changes: 3 additions & 30 deletions wolfssl/wolfcrypt/port/maxim/max3266x.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,16 @@

#if defined(MAX3266X_SHA) || defined(MAX3266X_SHA_CB)

/* Need to update this struct accordingly if other SHA Structs change */
/* This is a generic struct to use so only this is needed */

typedef struct {
unsigned char *msg;
unsigned int used;
unsigned int size;
#ifdef WOLFSSL_HASH_FLAGS
unsigned int flags; /* enum wc_HashFlags in hash.h */
#endif
} wc_MXC_Sha;

#if !defined(NO_SHA)
#ifndef MAX3266X_SHA_CB
typedef wc_MXC_Sha wc_Sha;
#define WC_SHA_TYPE_DEFINED
#endif /* !MAX3266X_SHA_CB */

/* Define the SHA digest for an empty string */
/* as a constant byte array */
static const unsigned char MXC_EMPTY_DIGEST_SHA1[20] = {
Expand All @@ -260,11 +255,6 @@
#endif /* NO_SHA */

#if defined(WOLFSSL_SHA224)
#ifndef MAX3266X_SHA_CB
typedef wc_MXC_Sha wc_Sha224;
#define WC_SHA224_TYPE_DEFINED
#endif /* !MAX3266X_SHA_CB */

/* Define the SHA-224 digest for an empty string */
/* as a constant byte array */
static const unsigned char MXC_EMPTY_DIGEST_SHA224[28] = {
Expand All @@ -275,11 +265,6 @@
#endif /* WOLFSSL_SHA224 */

#if !defined(NO_SHA256)
#ifndef MAX3266X_SHA_CB
typedef wc_MXC_Sha wc_Sha256;
#define WC_SHA256_TYPE_DEFINED
#endif /* !MAX3266X_SHA_CB */

/* Define the SHA-256 digest for an empty string */
/* as a constant byte array */
static const unsigned char MXC_EMPTY_DIGEST_SHA256[32] = {
Expand All @@ -290,11 +275,6 @@
#endif /* NO_SHA256 */

#if defined(WOLFSSL_SHA384)
#ifndef MAX3266X_SHA_CB
typedef wc_MXC_Sha wc_Sha384;
#define WC_SHA384_TYPE_DEFINED
#endif /* !MAX3266X_SHA_CB */

/* Define the SHA-384 digest for an empty string */
/* as a constant byte array */
static const unsigned char MXC_EMPTY_DIGEST_SHA384[48] = {
Expand All @@ -307,13 +287,6 @@
#endif /* WOLFSSL_SHA384 */

#if defined(WOLFSSL_SHA512)
#ifndef MAX3266X_SHA_CB
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
#endif /* !MAX3266X_SHA_CB */

/* Does not support these SHA512 Macros */
#ifndef WOLFSSL_NOSHA512_224
#warning "MAX3266X Port does not support SHA-512/224"
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct wc_Sha {
int devId;
void* devCtx; /* generic crypto callback context */
#endif
#ifdef MAX3266X_SHA_CB
#if defined(MAX3266X_SHA_CB) || defined(MAX3266X_SHA)
wc_MXC_Sha mxcCtx;
#endif
#ifdef WOLFSSL_IMXRT1170_CAAM
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ struct wc_Sha256 {
#ifdef WOLFSSL_DEVCRYPTO_HASH
WC_CRYPTODEV ctx;
#endif
#ifdef MAX3266X_SHA_CB
#if defined(MAX3266X_SHA_CB) || defined(MAX3266X_SHA)
wc_MXC_Sha mxcCtx;
#endif
#if defined(WOLFSSL_DEVCRYPTO_HASH) || defined(WOLFSSL_HASH_KEEP)
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/sha512.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ struct wc_Sha512 {
int devId;
void* devCtx; /* generic crypto callback context */
#endif
#ifdef MAX3266X_SHA_CB
#if defined(MAX3266X_SHA_CB) || defined(MAX3266X_SHA)
wc_MXC_Sha mxcCtx;
#endif
#ifdef WOLFSSL_HASH_FLAGS
Expand Down

0 comments on commit cc421dd

Please sign in to comment.