Skip to content

Commit 83169f9

Browse files
committed
Fix ShaFinal overrun.
1 parent d111d7d commit 83169f9

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

wolfcrypt/src/sha.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,10 @@ int wc_ShaFinal(wc_Sha* sha, byte* hash)
841841

842842
/* pad with zeros */
843843
if (sha->buffLen > WC_SHA_PAD_SIZE) {
844-
XMEMSET(&local[sha->buffLen], 0, WC_SHA_BLOCK_SIZE - sha->buffLen);
844+
if (sha->buffLen < WC_SHA_BLOCK_SIZE) {
845+
XMEMSET(&local[sha->buffLen], 0, WC_SHA_BLOCK_SIZE - sha->buffLen);
846+
}
847+
845848
sha->buffLen += WC_SHA_BLOCK_SIZE - sha->buffLen;
846849

847850
#if defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW)

0 commit comments

Comments
 (0)