Skip to content

Commit fe8541c

Browse files
Merge pull request #10193 from padelsbach/set-hashtype-in-ports
Set hashType in ports
2 parents 6a0303e + ea6af18 commit fe8541c

7 files changed

Lines changed: 93 additions & 9 deletions

File tree

wolfcrypt/src/port/caam/caam_sha.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,13 @@ int wc_Sha384Final(wc_Sha384* sha, byte* out)
376376
#ifdef WOLFSSL_SHA512
377377
int wc_InitSha512_ex(wc_Sha512* sha, void* heap, int devId)
378378
{
379-
return _InitSha(sha, heap, devId, SHA512_DIGEST_SIZE, CAAM_SHA512);
379+
int ret = _InitSha(sha, heap, devId, SHA512_DIGEST_SIZE, CAAM_SHA512);
380+
#if defined(WOLFSSL_SHA512_HASHTYPE)
381+
if (ret == 0) {
382+
sha->hashType = WC_HASH_TYPE_SHA512;
383+
}
384+
#endif
385+
return ret;
380386
}
381387

382388

wolfcrypt/src/port/cypress/psoc6_crypto.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ int wc_InitSha512_ex(wc_Sha512* sha, void* heap, int devid)
536536
/* Release the lock */
537537
wolfSSL_CryptHwMutexUnLock();
538538
}
539+
#if defined(WOLFSSL_SHA512_HASHTYPE)
540+
if (ret == 0) {
541+
sha->hashType = WC_HASH_TYPE_SHA512;
542+
}
543+
#endif
539544
return ret;
540545
}
541546

@@ -606,6 +611,11 @@ int wc_InitSha512_224_ex(wc_Sha512* sha, void* heap, int devid)
606611
/* Release the lock */
607612
wolfSSL_CryptHwMutexUnLock();
608613
}
614+
#if defined(WOLFSSL_SHA512_HASHTYPE)
615+
if (ret == 0) {
616+
sha->hashType = WC_HASH_TYPE_SHA512_224;
617+
}
618+
#endif
609619
return ret;
610620
}
611621

@@ -658,6 +668,11 @@ int wc_InitSha512_256_ex(wc_Sha512* sha, void* heap, int devid)
658668
/* Release the lock */
659669
wolfSSL_CryptHwMutexUnLock();
660670
}
671+
#if defined(WOLFSSL_SHA512_HASHTYPE)
672+
if (ret == 0) {
673+
sha->hashType = WC_HASH_TYPE_SHA512_256;
674+
}
675+
#endif
661676
return ret;
662677
}
663678

wolfcrypt/src/port/kcapi/kcapi_hash.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,17 @@ static const char WC_NAME_SHA512[] = "sha512";
427427
/* create KCAPI handle for SHA512 operation */
428428
int wc_InitSha512_ex(wc_Sha512* sha, void* heap, int devid)
429429
{
430+
int ret;
430431
if (sha == NULL) {
431432
return BAD_FUNC_ARG;
432433
}
433-
return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512);
434+
ret = KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512);
435+
#if defined(WOLFSSL_SHA512_HASHTYPE)
436+
if (ret == 0) {
437+
sha->hashType = WC_HASH_TYPE_SHA512;
438+
}
439+
#endif
440+
return ret;
434441
}
435442

436443

@@ -473,13 +480,20 @@ int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
473480
#if !defined(WOLFSSL_NOSHA512_224)
474481
static const char WC_NAME_SHA512_224[] = "sha512-224";
475482

476-
/* create KCAPI handle for SHA512 operation */
483+
/* create KCAPI handle for SHA512/224 operation */
477484
int wc_InitSha512_224_ex(wc_Sha512* sha, void* heap, int devid)
478485
{
486+
int ret;
479487
if (sha == NULL) {
480488
return BAD_FUNC_ARG;
481489
}
482-
return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512_224);
490+
ret = KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512_224);
491+
#if defined(WOLFSSL_SHA512_HASHTYPE)
492+
if (ret == 0) {
493+
sha->hashType = WC_HASH_TYPE_SHA512_224;
494+
}
495+
#endif
496+
return ret;
483497
}
484498

485499

@@ -512,13 +526,20 @@ int wc_Sha512_224Copy(wc_Sha512* src, wc_Sha512* dst)
512526
#if !defined(WOLFSSL_NOSHA512_256)
513527
static const char WC_NAME_SHA512_256[] = "sha512-256";
514528

515-
/* create KCAPI handle for SHA512 operation */
529+
/* create KCAPI handle for SHA512/256 operation */
516530
int wc_InitSha512_256_ex(wc_Sha512* sha, void* heap, int devid)
517531
{
532+
int ret;
518533
if (sha == NULL) {
519534
return BAD_FUNC_ARG;
520535
}
521-
return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512_256);
536+
ret = KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512_256);
537+
#if defined(WOLFSSL_SHA512_HASHTYPE)
538+
if (ret == 0) {
539+
sha->hashType = WC_HASH_TYPE_SHA512_256;
540+
}
541+
#endif
542+
return ret;
522543
}
523544

524545

wolfcrypt/src/port/maxim/max3266x.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,9 @@ WOLFSSL_API int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
11361136
(void)devId;
11371137
XMEMSET(sha512, 0, sizeof(*sha512));
11381138
sha512->heap = heap;
1139+
#if defined(WOLFSSL_SHA512_HASHTYPE)
1140+
sha512->hashType = WC_HASH_TYPE_SHA512;
1141+
#endif
11391142
return 0;
11401143
}
11411144

wolfcrypt/src/port/riscv/riscv-64-sha512.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
999999
int ret = InitSha512(sha512, heap, devId);
10001000
if (ret == 0) {
10011001
InitSha512_State(sha512);
1002+
#if defined(WOLFSSL_SHA512_HASHTYPE)
1003+
sha512->hashType = WC_HASH_TYPE_SHA512;
1004+
#endif
10021005
}
10031006
return ret;
10041007
}
@@ -1302,6 +1305,9 @@ int wc_InitSha512_224_ex(wc_Sha512* sha512, void* heap, int devId)
13021305
int ret = InitSha512(sha512, heap, devId);
13031306
if (ret == 0) {
13041307
InitSha512_224_State(sha512);
1308+
#if defined(WOLFSSL_SHA512_HASHTYPE)
1309+
sha512->hashType = WC_HASH_TYPE_SHA512_224;
1310+
#endif
13051311
}
13061312
return ret;
13071313
}
@@ -1402,6 +1408,9 @@ int wc_InitSha512_256_ex(wc_Sha512* sha512, void* heap, int devId)
14021408
int ret = InitSha512(sha512, heap, devId);
14031409
if (ret == 0) {
14041410
InitSha512_256_State(sha512);
1411+
#if defined(WOLFSSL_SHA512_HASHTYPE)
1412+
sha512->hashType = WC_HASH_TYPE_SHA512_256;
1413+
#endif
14051414
}
14061415
return ret;
14071416
}

wolfcrypt/src/port/silabs/silabs_hash.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,21 @@ int wc_Sha384Final(wc_Sha384* sha, byte* hash)
277277
#ifdef WOLFSSL_SILABS_SHA512
278278
int wc_InitSha512_ex(wc_Sha512* sha, void* heap, int devId)
279279
{
280+
int ret;
280281
if (sha == NULL) {
281282
return BAD_FUNC_ARG;
282283
}
283284

284285
(void)devId;
285286
(void)heap;
286287

287-
return wc_silabs_se_hash_init(&sha->silabsCtx, WC_HASH_TYPE_SHA512);
288+
ret = wc_silabs_se_hash_init(&sha->silabsCtx, WC_HASH_TYPE_SHA512);
289+
#if defined(WOLFSSL_SHA512_HASHTYPE)
290+
if (ret == 0) {
291+
sha->hashType = WC_HASH_TYPE_SHA512;
292+
}
293+
#endif
294+
return ret;
288295
}
289296

290297

wolfcrypt/src/sha512.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,31 @@
179179
#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH)
180180
int wc_InitSha512(wc_Sha512* sha512)
181181
{
182+
int ret;
182183
if (sha512 == NULL)
183184
return BAD_FUNC_ARG;
184-
return se050_hash_init(&sha512->se050Ctx, NULL);
185+
ret = se050_hash_init(&sha512->se050Ctx, NULL);
186+
#if defined(WOLFSSL_SHA512_HASHTYPE)
187+
if (ret == 0) {
188+
sha512->hashType = WC_HASH_TYPE_SHA512;
189+
}
190+
#endif
191+
return ret;
185192
}
186193
int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
187194
{
195+
int ret;
188196
if (sha512 == NULL) {
189197
return BAD_FUNC_ARG;
190198
}
191199
(void)devId;
192-
return se050_hash_init(&sha512->se050Ctx, heap);
200+
ret = se050_hash_init(&sha512->se050Ctx, heap);
201+
#if defined(WOLFSSL_SHA512_HASHTYPE)
202+
if (ret == 0) {
203+
sha512->hashType = WC_HASH_TYPE_SHA512;
204+
}
205+
#endif
206+
return ret;
193207
}
194208
int wc_Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
195209
{
@@ -252,6 +266,9 @@
252266

253267
XMEMSET(sha512, 0, sizeof(wc_Sha512));
254268
wc_Stm32_Hash_Init(&sha512->stmCtx);
269+
#if defined(WOLFSSL_SHA512_HASHTYPE)
270+
sha512->hashType = WC_HASH_TYPE_SHA512;
271+
#endif
255272
return 0;
256273
}
257274

@@ -2387,6 +2404,9 @@ int wc_InitSha512_224_ex(wc_Sha512* sha512, void* heap, int devId)
23872404

23882405
XMEMSET(sha512, 0, sizeof(wc_Sha512));
23892406
wc_Stm32_Hash_Init(&sha512->stmCtx);
2407+
#if defined(WOLFSSL_SHA512_HASHTYPE)
2408+
sha512->hashType = WC_HASH_TYPE_SHA512_224;
2409+
#endif
23902410
return 0;
23912411
}
23922412

@@ -2530,6 +2550,9 @@ int wc_Sha512_224Transform(wc_Sha512* sha, const unsigned char* data)
25302550

25312551
XMEMSET(sha512, 0, sizeof(wc_Sha512));
25322552
wc_Stm32_Hash_Init(&sha512->stmCtx);
2553+
#if defined(WOLFSSL_SHA512_HASHTYPE)
2554+
sha512->hashType = WC_HASH_TYPE_SHA512_256;
2555+
#endif
25332556
return 0;
25342557
}
25352558

0 commit comments

Comments
 (0)