Skip to content

Commit 69ddefb

Browse files
committed
Zero-initialize stack-declared hash contexts in GetHash functions before passing to Copy, which now calls Free(dst) and requires valid fields.
1 parent 4c5e321 commit 69ddefb

4 files changed

Lines changed: 8 additions & 0 deletions

File tree

wolfcrypt/src/md5.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ int wc_Md5GetHash(wc_Md5* md5, byte* hash)
522522
if (md5 == NULL || hash == NULL)
523523
return BAD_FUNC_ARG;
524524

525+
XMEMSET(&tmpMd5, 0, sizeof(tmpMd5));
525526
ret = wc_Md5Copy(md5, &tmpMd5);
526527
if (ret == 0) {
527528
ret = wc_Md5Final(&tmpMd5, hash);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash)
10311031
}
10321032
else {
10331033
wc_Sha256 tmpSha256;
1034+
XMEMSET(&tmpSha256, 0, sizeof(tmpSha256));
10341035
/* Create a copy of the hash to finalize. */
10351036
ret = wc_Sha256Copy(sha256, &tmpSha256);
10361037
if (ret == 0) {
@@ -1350,6 +1351,7 @@ int wc_Sha224GetHash(wc_Sha224* sha224, byte* hash)
13501351
}
13511352
else {
13521353
wc_Sha224 tmpSha224;
1354+
XMEMSET(&tmpSha224, 0, sizeof(tmpSha224));
13531355
/* Create a copy of the hash to finalize. */
13541356
ret = wc_Sha224Copy(sha224, &tmpSha224);
13551357
if (ret == 0) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,7 @@ int wc_Sha512GetHash(wc_Sha512* sha512, byte* hash)
11401140
}
11411141
else {
11421142
wc_Sha512 tmpSha512;
1143+
XMEMSET(&tmpSha512, 0, sizeof(tmpSha512));
11431144
/* Create a copy of the hash to finalize. */
11441145
ret = wc_Sha512Copy(sha512, &tmpSha512);
11451146
if (ret == 0) {
@@ -1357,6 +1358,7 @@ int wc_Sha512_224GetHash(wc_Sha512* sha512, byte* hash)
13571358
}
13581359
else {
13591360
wc_Sha512 tmpSha512;
1361+
XMEMSET(&tmpSha512, 0, sizeof(tmpSha512));
13601362
/* Create a copy of the hash to finalize. */
13611363
ret = wc_Sha512Copy(sha512, &tmpSha512);
13621364
if (ret == 0) {
@@ -1456,6 +1458,7 @@ int wc_Sha512_256GetHash(wc_Sha512* sha512, byte* hash)
14561458
}
14571459
else {
14581460
wc_Sha512 tmpSha512;
1461+
XMEMSET(&tmpSha512, 0, sizeof(tmpSha512));
14591462
/* Create a copy of the hash to finalize. */
14601463
ret = wc_Sha512Copy(sha512, &tmpSha512);
14611464
if (ret == 0) {
@@ -1671,6 +1674,7 @@ int wc_Sha384GetHash(wc_Sha384* sha384, byte* hash)
16711674
}
16721675
else {
16731676
wc_Sha384 tmpSha384;
1677+
XMEMSET(&tmpSha384, 0, sizeof(tmpSha384));
16741678
/* Create a copy of the hash to finalize. */
16751679
ret = wc_Sha384Copy(sha384, &tmpSha384);
16761680
if (ret == 0) {

wolfcrypt/src/sha3.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,7 @@ static int wc_Sha3GetHash(wc_Sha3* sha3, byte* hash, byte p, byte len)
13451345
if (sha3 == NULL || hash == NULL)
13461346
return BAD_FUNC_ARG;
13471347

1348+
XMEMSET(&tmpSha3, 0, sizeof(tmpSha3));
13481349
ret = wc_Sha3Copy(sha3, &tmpSha3);
13491350
if (ret == 0) {
13501351
ret = wc_Sha3Final(&tmpSha3, hash, p, len);

0 commit comments

Comments
 (0)