Skip to content

Commit 1449f4f

Browse files
committed
Fixing CB needing HAVE_AES_ECB and SHA struct issue for MAX3266X Hardware
1 parent 3e1f365 commit 1449f4f

6 files changed

Lines changed: 38 additions & 65 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,7 +2917,7 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
29172917
outBlock, (unsigned int)keySize);
29182918
}
29192919
#endif
2920-
#ifdef MAX3266X_CB /* Can do a basic ECB block */
2920+
#if defined(MAX3266X_CB) && defined(HAVE_AES_ECB) /* Can do a basic ECB block */
29212921
#ifndef WOLF_CRYPTO_CB_FIND
29222922
if (aes->devId != INVALID_DEVID)
29232923
#endif
@@ -3668,7 +3668,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
36683668
}
36693669
#endif
36703670

3671-
#ifdef MAX3266X_CB /* Can do a basic ECB block */
3671+
#if defined(MAX3266X_CB) && defined(HAVE_AES_ECB) /* Can do a basic ECB block */
36723672
#ifndef WOLF_CRYPTO_CB_FIND
36733673
if (aes->devId != INVALID_DEVID)
36743674
#endif

wolfcrypt/src/port/maxim/max3266x.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -789,35 +789,35 @@ WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId)
789789
}
790790
(void)heap;
791791
(void)devId;
792-
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha);
792+
return wc_MXC_TPU_SHA_Init(&(sha->mxcCtx));
793793
}
794794

795795
WOLFSSL_API int wc_ShaUpdate(wc_Sha* sha, const unsigned char* data,
796796
unsigned int len)
797797
{
798-
return wc_MXC_TPU_SHA_Update(sha, data, len);
798+
return wc_MXC_TPU_SHA_Update(&(sha->mxcCtx), data, len);
799799
}
800800

801801
WOLFSSL_API int wc_ShaFinal(wc_Sha* sha, unsigned char* hash)
802802
{
803-
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha, hash,
803+
return wc_MXC_TPU_SHA_Final(&(sha->mxcCtx), hash,
804804
MXC_TPU_HASH_SHA1);
805805
}
806806

807807
WOLFSSL_API int wc_ShaGetHash(wc_Sha* sha, unsigned char* hash)
808808
{
809-
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha, hash,
809+
return wc_MXC_TPU_SHA_GetHash(&(sha->mxcCtx), hash,
810810
MXC_TPU_HASH_SHA1);
811811
}
812812

813813
WOLFSSL_API int wc_ShaCopy(wc_Sha* src, wc_Sha* dst)
814814
{
815-
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
815+
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
816816
}
817817

818818
WOLFSSL_API void wc_ShaFree(wc_Sha* sha)
819819
{
820-
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha);
820+
wc_MXC_TPU_SHA_Free(&(sha->mxcCtx));
821821
return;
822822
}
823823

@@ -832,7 +832,7 @@ WOLFSSL_API int wc_InitSha224_ex(wc_Sha224* sha224, void* heap, int devId)
832832
}
833833
(void)heap;
834834
(void)devId;
835-
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha224);
835+
return wc_MXC_TPU_SHA_Init(&(sha224->mxcCtx));
836836
}
837837

838838
WOLFSSL_API int wc_InitSha224(wc_Sha224* sha224)
@@ -843,29 +843,29 @@ WOLFSSL_API int wc_InitSha224(wc_Sha224* sha224)
843843
WOLFSSL_API int wc_Sha224Update(wc_Sha224* sha224, const unsigned char* data,
844844
unsigned int len)
845845
{
846-
return wc_MXC_TPU_SHA_Update(sha224, data, len);
846+
return wc_MXC_TPU_SHA_Update(&(sha224->mxcCtx), data, len);
847847
}
848848

849849
WOLFSSL_API int wc_Sha224Final(wc_Sha224* sha224, unsigned char* hash)
850850
{
851-
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha224, hash,
851+
return wc_MXC_TPU_SHA_Final(&(sha224->mxcCtx), hash,
852852
MXC_TPU_HASH_SHA224);
853853
}
854854

855855
WOLFSSL_API int wc_Sha224GetHash(wc_Sha224* sha224, unsigned char* hash)
856856
{
857-
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha224, hash,
857+
return wc_MXC_TPU_SHA_GetHash(&(sha224->mxcCtx), hash,
858858
MXC_TPU_HASH_SHA224);
859859
}
860860

861861
WOLFSSL_API int wc_Sha224Copy(wc_Sha224* src, wc_Sha224* dst)
862862
{
863-
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
863+
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
864864
}
865865

866866
WOLFSSL_API void wc_Sha224Free(wc_Sha224* sha224)
867867
{
868-
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha224);
868+
wc_MXC_TPU_SHA_Free(&(sha224->mxcCtx));
869869
return;
870870
}
871871

@@ -880,7 +880,7 @@ WOLFSSL_API int wc_InitSha256_ex(wc_Sha256* sha256, void* heap, int devId)
880880
}
881881
(void)heap;
882882
(void)devId;
883-
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha256);
883+
return wc_MXC_TPU_SHA_Init(&(sha256->mxcCtx));
884884
}
885885

886886
WOLFSSL_API int wc_InitSha256(wc_Sha256* sha256)
@@ -891,29 +891,29 @@ WOLFSSL_API int wc_InitSha256(wc_Sha256* sha256)
891891
WOLFSSL_API int wc_Sha256Update(wc_Sha256* sha256, const unsigned char* data,
892892
unsigned int len)
893893
{
894-
return wc_MXC_TPU_SHA_Update(sha256, data, len);
894+
return wc_MXC_TPU_SHA_Update(&(sha256->mxcCtx), data, len);
895895
}
896896

897897
WOLFSSL_API int wc_Sha256Final(wc_Sha256* sha256, unsigned char* hash)
898898
{
899-
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha256, hash,
899+
return wc_MXC_TPU_SHA_Final(&(sha256->mxcCtx), hash,
900900
MXC_TPU_HASH_SHA256);
901901
}
902902

903903
WOLFSSL_API int wc_Sha256GetHash(wc_Sha256* sha256, unsigned char* hash)
904904
{
905-
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha256, hash,
905+
return wc_MXC_TPU_SHA_GetHash(&(sha256->mxcCtx), hash,
906906
MXC_TPU_HASH_SHA256);
907907
}
908908

909909
WOLFSSL_API int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
910910
{
911-
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
911+
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
912912
}
913913

914914
WOLFSSL_API void wc_Sha256Free(wc_Sha256* sha256)
915915
{
916-
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha256);
916+
wc_MXC_TPU_SHA_Free(&(sha256->mxcCtx));
917917
return;
918918
}
919919

@@ -928,7 +928,7 @@ WOLFSSL_API int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
928928
}
929929
(void)heap;
930930
(void)devId;
931-
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha384);
931+
return wc_MXC_TPU_SHA_Init(&(sha384->mxcCtx));
932932
}
933933

934934
WOLFSSL_API int wc_InitSha384(wc_Sha384* sha384)
@@ -939,29 +939,29 @@ WOLFSSL_API int wc_InitSha384(wc_Sha384* sha384)
939939
WOLFSSL_API int wc_Sha384Update(wc_Sha384* sha384, const unsigned char* data,
940940
unsigned int len)
941941
{
942-
return wc_MXC_TPU_SHA_Update(sha384, data, len);
942+
return wc_MXC_TPU_SHA_Update(&(sha384->mxcCtx), data, len);
943943
}
944944

945945
WOLFSSL_API int wc_Sha384Final(wc_Sha384* sha384, unsigned char* hash)
946946
{
947-
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha384, hash,
947+
return wc_MXC_TPU_SHA_Final(&(sha384->mxcCtx), hash,
948948
MXC_TPU_HASH_SHA384);
949949
}
950950

951951
WOLFSSL_API int wc_Sha384GetHash(wc_Sha384* sha384, unsigned char* hash)
952952
{
953-
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha384, hash,
953+
return wc_MXC_TPU_SHA_GetHash(&(sha384->mxcCtx), hash,
954954
MXC_TPU_HASH_SHA384);
955955
}
956956

957957
WOLFSSL_API int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
958958
{
959-
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
959+
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
960960
}
961961

962962
WOLFSSL_API void wc_Sha384Free(wc_Sha384* sha384)
963963
{
964-
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha384);
964+
wc_MXC_TPU_SHA_Free(&(sha384->mxcCtx));
965965
return;
966966
}
967967

@@ -976,7 +976,7 @@ WOLFSSL_API int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
976976
}
977977
(void)heap;
978978
(void)devId;
979-
return wc_MXC_TPU_SHA_Init((wc_MXC_Sha *)sha512);
979+
return wc_MXC_TPU_SHA_Init(&(sha512->mxcCtx));
980980
}
981981

982982
WOLFSSL_API int wc_InitSha512(wc_Sha512* sha512)
@@ -987,29 +987,29 @@ WOLFSSL_API int wc_InitSha512(wc_Sha512* sha512)
987987
WOLFSSL_API int wc_Sha512Update(wc_Sha512* sha512, const unsigned char* data,
988988
unsigned int len)
989989
{
990-
return wc_MXC_TPU_SHA_Update(sha512, data, len);
990+
return wc_MXC_TPU_SHA_Update(&(sha512->mxcCtx), data, len);
991991
}
992992

993993
WOLFSSL_API int wc_Sha512Final(wc_Sha512* sha512, unsigned char* hash)
994994
{
995-
return wc_MXC_TPU_SHA_Final((wc_MXC_Sha *)sha512, hash,
995+
return wc_MXC_TPU_SHA_Final(&(sha512->mxcCtx), hash,
996996
MXC_TPU_HASH_SHA512);
997997
}
998998

999999
WOLFSSL_API int wc_Sha512GetHash(wc_Sha512* sha512, unsigned char* hash)
10001000
{
1001-
return wc_MXC_TPU_SHA_GetHash((wc_MXC_Sha *)sha512, hash,
1001+
return wc_MXC_TPU_SHA_GetHash(&(sha512->mxcCtx), hash,
10021002
MXC_TPU_HASH_SHA512);
10031003
}
10041004

10051005
WOLFSSL_API int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
10061006
{
1007-
return wc_MXC_TPU_SHA_Copy((wc_MXC_Sha *)src, (wc_MXC_Sha *)dst);
1007+
return wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
10081008
}
10091009

10101010
WOLFSSL_API void wc_Sha512Free(wc_Sha512* sha512)
10111011
{
1012-
wc_MXC_TPU_SHA_Free((wc_MXC_Sha *)sha512);
1012+
wc_MXC_TPU_SHA_Free(&(sha512->mxcCtx));
10131013
return;
10141014
}
10151015

wolfssl/wolfcrypt/port/maxim/max3266x.h

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,16 @@
236236

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

239+
/* Need to update this struct accordingly if other SHA Structs change */
240+
/* This is a generic struct to use so only this is needed */
241+
239242
typedef struct {
240243
unsigned char *msg;
241244
unsigned int used;
242245
unsigned int size;
243-
#ifdef WOLFSSL_HASH_FLAGS
244-
unsigned int flags; /* enum wc_HashFlags in hash.h */
245-
#endif
246246
} wc_MXC_Sha;
247247

248248
#if !defined(NO_SHA)
249-
#ifndef MAX3266X_SHA_CB
250-
typedef wc_MXC_Sha wc_Sha;
251-
#define WC_SHA_TYPE_DEFINED
252-
#endif /* !MAX3266X_SHA_CB */
253-
254249
/* Define the SHA digest for an empty string */
255250
/* as a constant byte array */
256251
static const unsigned char MXC_EMPTY_DIGEST_SHA1[20] = {
@@ -260,11 +255,6 @@
260255
#endif /* NO_SHA */
261256

262257
#if defined(WOLFSSL_SHA224)
263-
#ifndef MAX3266X_SHA_CB
264-
typedef wc_MXC_Sha wc_Sha224;
265-
#define WC_SHA224_TYPE_DEFINED
266-
#endif /* !MAX3266X_SHA_CB */
267-
268258
/* Define the SHA-224 digest for an empty string */
269259
/* as a constant byte array */
270260
static const unsigned char MXC_EMPTY_DIGEST_SHA224[28] = {
@@ -275,11 +265,6 @@
275265
#endif /* WOLFSSL_SHA224 */
276266

277267
#if !defined(NO_SHA256)
278-
#ifndef MAX3266X_SHA_CB
279-
typedef wc_MXC_Sha wc_Sha256;
280-
#define WC_SHA256_TYPE_DEFINED
281-
#endif /* !MAX3266X_SHA_CB */
282-
283268
/* Define the SHA-256 digest for an empty string */
284269
/* as a constant byte array */
285270
static const unsigned char MXC_EMPTY_DIGEST_SHA256[32] = {
@@ -290,11 +275,6 @@
290275
#endif /* NO_SHA256 */
291276

292277
#if defined(WOLFSSL_SHA384)
293-
#ifndef MAX3266X_SHA_CB
294-
typedef wc_MXC_Sha wc_Sha384;
295-
#define WC_SHA384_TYPE_DEFINED
296-
#endif /* !MAX3266X_SHA_CB */
297-
298278
/* Define the SHA-384 digest for an empty string */
299279
/* as a constant byte array */
300280
static const unsigned char MXC_EMPTY_DIGEST_SHA384[48] = {
@@ -307,13 +287,6 @@
307287
#endif /* WOLFSSL_SHA384 */
308288

309289
#if defined(WOLFSSL_SHA512)
310-
#ifndef MAX3266X_SHA_CB
311-
typedef wc_MXC_Sha wc_Sha512;
312-
typedef wc_MXC_Sha wc_Sha512_224;
313-
typedef wc_MXC_Sha wc_Sha512_256;
314-
#define WC_SHA512_TYPE_DEFINED
315-
#endif /* !MAX3266X_SHA_CB */
316-
317290
/* Does not support these SHA512 Macros */
318291
#ifndef WOLFSSL_NOSHA512_224
319292
#warning "MAX3266X Port does not support SHA-512/224"

wolfssl/wolfcrypt/sha.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ struct wc_Sha {
163163
int devId;
164164
void* devCtx; /* generic crypto callback context */
165165
#endif
166-
#ifdef MAX3266X_SHA_CB
166+
#if defined(MAX3266X_SHA_CB) || defined(MAX3266X_SHA)
167167
wc_MXC_Sha mxcCtx;
168168
#endif
169169
#ifdef WOLFSSL_IMXRT1170_CAAM

wolfssl/wolfcrypt/sha256.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ struct wc_Sha256 {
213213
#ifdef WOLFSSL_DEVCRYPTO_HASH
214214
WC_CRYPTODEV ctx;
215215
#endif
216-
#ifdef MAX3266X_SHA_CB
216+
#if defined(MAX3266X_SHA_CB) || defined(MAX3266X_SHA)
217217
wc_MXC_Sha mxcCtx;
218218
#endif
219219
#if defined(WOLFSSL_DEVCRYPTO_HASH) || defined(WOLFSSL_HASH_KEEP)

wolfssl/wolfcrypt/sha512.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct wc_Sha512 {
189189
int devId;
190190
void* devCtx; /* generic crypto callback context */
191191
#endif
192-
#ifdef MAX3266X_SHA_CB
192+
#if defined(MAX3266X_SHA_CB) || defined(MAX3266X_SHA)
193193
wc_MXC_Sha mxcCtx;
194194
#endif
195195
#ifdef WOLFSSL_HASH_FLAGS

0 commit comments

Comments
 (0)