Skip to content

Commit d4f8f0d

Browse files
committed
Revert XMEMSET 0 after free in copy process for digest/hashing functions
1 parent 39ab81b commit d4f8f0d

5 files changed

Lines changed: 0 additions & 14 deletions

File tree

wolfcrypt/src/md5.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,6 @@ int wc_Md5Copy(wc_Md5* src, wc_Md5* dst)
540540
/* Free dst resources before copy to prevent memory leaks (e.g.,
541541
* hardware contexts). XMEMCPY overwrites dst. */
542542
wc_Md5Free(dst);
543-
XMEMSET(dst, 0, sizeof(wc_Md5));
544-
545543
XMEMCPY(dst, src, sizeof(wc_Md5));
546544

547545
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_MD5)

wolfcrypt/src/sha.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,6 @@ int wc_ShaCopy(wc_Sha* src, wc_Sha* dst)
11751175
/* Free dst resources before copy to prevent memory leaks (e.g., msg
11761176
* buffer, W cache, hardware contexts). XMEMCPY overwrites dst. */
11771177
wc_ShaFree(dst);
1178-
XMEMSET(dst, 0, sizeof(wc_Sha));
1179-
11801178
XMEMCPY(dst, src, sizeof(wc_Sha));
11811179

11821180
#if defined(WOLFSSL_SILABS_SE_ACCEL) && defined(WOLFSSL_SILABS_SE_ACCEL_3)

wolfcrypt/src/sha256.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,8 +2585,6 @@ int wc_Sha224_Grow(wc_Sha224* sha224, const byte* in, int inSz)
25852585
/* Free dst resources before copy to prevent memory leaks (e.g., msg
25862586
* buffer, W cache, hardware contexts). XMEMCPY overwrites dst. */
25872587
wc_Sha224Free(dst);
2588-
XMEMSET(dst, 0, sizeof(wc_Sha224));
2589-
25902588
XMEMCPY(dst, src, sizeof(wc_Sha224));
25912589

25922590
#ifdef WOLFSSL_SMALL_STACK_CACHE
@@ -2736,8 +2734,6 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
27362734
/* Free dst resources before copy to prevent memory leaks (e.g., msg
27372735
* buffer, W cache, hardware contexts). XMEMCPY overwrites dst. */
27382736
wc_Sha256Free(dst);
2739-
XMEMSET(dst, 0, sizeof(wc_Sha256));
2740-
27412737
XMEMCPY(dst, src, sizeof(wc_Sha256));
27422738

27432739
#ifdef WOLFSSL_MAXQ10XX_CRYPTO

wolfcrypt/src/sha3.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,6 @@ static int wc_Sha3Copy(wc_Sha3* src, wc_Sha3* dst)
13091309
/* Free dst resources before copy to prevent memory leaks (e.g.,
13101310
* hardware contexts). XMEMCPY overwrites dst. */
13111311
wc_Sha3Free(dst);
1312-
XMEMSET(dst, 0, sizeof(wc_Sha3));
1313-
13141312
XMEMCPY(dst, src, sizeof(wc_Sha3));
13151313

13161314
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3)

wolfcrypt/src/sha512.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,8 +2252,6 @@ int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
22522252
/* Free dst resources before copy to prevent memory leaks (e.g., msg
22532253
* buffer, W cache, hardware contexts). XMEMCPY overwrites dst. */
22542254
wc_Sha512Free(dst);
2255-
XMEMSET(dst, 0, sizeof(wc_Sha512));
2256-
22572255
XMEMCPY(dst, src, sizeof(wc_Sha512));
22582256
#ifdef WOLFSSL_SMALL_STACK_CACHE
22592257
/* This allocation combines the customary W buffer used by
@@ -2695,8 +2693,6 @@ int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
26952693
/* Free dst resources before copy to prevent memory leaks (e.g., msg
26962694
* buffer, W cache, hardware contexts). XMEMCPY overwrites dst. */
26972695
wc_Sha384Free(dst);
2698-
XMEMSET(dst, 0, sizeof(wc_Sha384));
2699-
27002696
XMEMCPY(dst, src, sizeof(wc_Sha384));
27012697

27022698
#ifdef WOLFSSL_SMALL_STACK_CACHE

0 commit comments

Comments
 (0)