-
Notifications
You must be signed in to change notification settings - Fork 931
Improve HMAC and SHA-2 Zeroing #9785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2347,7 +2347,19 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data, | |||||||||
| #if defined(PSOC6_HASH_SHA2) | ||||||||||
| wc_Psoc6_Sha_Free(); | ||||||||||
| #endif | ||||||||||
| #if !defined(FREESCALE_LTC_SHA) && \ | ||||||||||
| !(defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH)) && \ | ||||||||||
| !defined(STM32_HASH_SHA2) && \ | ||||||||||
| !defined(WOLFSSL_SILABS_SE_ACCEL) && \ | ||||||||||
| !defined(WOLFSSL_IMXRT_DCP) && \ | ||||||||||
| !defined(PSOC6_HASH_SHA2) | ||||||||||
| /* PSA compiles out the free function completely */ | ||||||||||
| ForceZero(sha224->buffer, sizeof(sha224->buffer)); | ||||||||||
| if (sha224->hiLen != 0 || sha224->loLen != 0) | ||||||||||
| ForceZero(sha224->digest, sizeof(sha224->digest)); | ||||||||||
|
Comment on lines
+2357
to
+2359
|
||||||||||
| #else | ||||||||||
| ForceZero(sha224, sizeof(*sha224)); | ||||||||||
| #endif | ||||||||||
| } | ||||||||||
| #endif /* !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_HASH) */ | ||||||||||
| #endif /* WOLFSSL_SHA224 */ | ||||||||||
|
|
@@ -2494,7 +2506,19 @@ void wc_Sha256Free(wc_Sha256* sha256) | |||||||||
| wc_Psoc6_Sha_Free(); | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| #if !defined(FREESCALE_LTC_SHA) && \ | ||||||||||
| !(defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH)) && \ | ||||||||||
| !defined(STM32_HASH_SHA2) && \ | ||||||||||
| !defined(WOLFSSL_SILABS_SE_ACCEL) && \ | ||||||||||
| !defined(WOLFSSL_IMXRT_DCP) && \ | ||||||||||
| !defined(PSOC6_HASH_SHA2) | ||||||||||
| /* PSA compiles out the free function completely */ | ||||||||||
| ForceZero(sha256->buffer, sizeof(sha256->buffer)); | ||||||||||
| if (sha256->hiLen != 0 || sha256->loLen != 0) | ||||||||||
| ForceZero(sha256->digest, sizeof(sha256->digest)); | ||||||||||
|
Comment on lines
+2516
to
+2518
|
||||||||||
| ForceZero(sha256->buffer, sizeof(sha256->buffer)); | |
| if (sha256->hiLen != 0 || sha256->loLen != 0) | |
| ForceZero(sha256->digest, sizeof(sha256->digest)); | |
| ForceZero(sha256, sizeof(*sha256)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1688,7 +1688,13 @@ void wc_Sha512Free(wc_Sha512* sha512) | |
| wc_Psoc6_Sha_Free(); | ||
| #endif | ||
|
|
||
| #if !defined(PSOC6_HASH_SHA2) | ||
| ForceZero(sha512->buffer, sizeof(sha512->buffer)); | ||
| if (!(sha512->hiLen == 0 && sha512->loLen == 0)) | ||
| ForceZero(sha512->digest, sizeof(sha512->digest)); | ||
|
Comment on lines
+1692
to
+1694
|
||
| #else | ||
| ForceZero(sha512, sizeof(*sha512)); | ||
| #endif | ||
| } | ||
| #endif | ||
|
|
||
|
|
@@ -2176,7 +2182,13 @@ void wc_Sha384Free(wc_Sha384* sha384) | |
| wc_MXC_TPU_SHA_Free(&(sha384->mxcCtx)); | ||
| #endif | ||
|
|
||
| #if !defined(PSOC6_HASH_SHA2) | ||
| ForceZero(sha384->buffer, sizeof(sha384->buffer)); | ||
| if (!(sha384->hiLen == 0 && sha384->loLen == 0)) | ||
| ForceZero(sha384->digest, sizeof(sha384->digest)); | ||
|
Comment on lines
+2186
to
+2188
|
||
| #else | ||
| ForceZero(sha384, sizeof(*sha384)); | ||
| #endif | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wc_HmacFreeno longer wipes thehmac->hash/i_hash/o_hashunions themselves. Several underlying hash*Freefunctions (e.g.wc_Md5Free,wc_ShaFree) do not zero their internal digest/buffer state, so keyed intermediate state from HMAC can be left in memory afterwc_HmacFree. Please explicitly zero the hash unions after callingHmacFreeHash(or otherwise ensure each possible hash*Freereliably wipes sensitive state) to avoid a security regression.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MD5 and Sha zeroing should be handled in their respective freeing function imo, however I thought to do that in a following PR instead of this one.