Fix MD5 and SHA buffer overrun.

This commit is contained in:
jordan
2024-02-02 19:50:22 -06:00
parent 4ed197d487
commit d111d7da1b
3 changed files with 13 additions and 4 deletions

View File

@ -461,7 +461,9 @@ int wc_Md5Final(wc_Md5* md5, byte* hash)
/* pad with zeros */
if (md5->buffLen > WC_MD5_PAD_SIZE) {
XMEMSET(&local[md5->buffLen], 0, WC_MD5_BLOCK_SIZE - md5->buffLen);
if (md5->buffLen < WC_MD5_BLOCK_SIZE) {
XMEMSET(&local[md5->buffLen], 0, WC_MD5_BLOCK_SIZE - md5->buffLen);
}
md5->buffLen += WC_MD5_BLOCK_SIZE - md5->buffLen;
#if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU_SHA)

View File

@ -1321,8 +1321,11 @@ static int InitSha256(wc_Sha256* sha256)
/* pad with zeros */
if (sha256->buffLen > WC_SHA256_PAD_SIZE) {
XMEMSET(&local[sha256->buffLen], 0,
WC_SHA256_BLOCK_SIZE - sha256->buffLen);
if (sha256->buffLen < WC_SHA256_BLOCK_SIZE) {
XMEMSET(&local[sha256->buffLen], 0,
WC_SHA256_BLOCK_SIZE - sha256->buffLen);
}
sha256->buffLen += WC_SHA256_BLOCK_SIZE - sha256->buffLen;
#if defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW) && \

View File

@ -942,7 +942,11 @@ static WC_INLINE int Sha512Final(wc_Sha512* sha512)
/* pad with zeros */
if (sha512->buffLen > WC_SHA512_PAD_SIZE) {
XMEMSET(&local[sha512->buffLen], 0, WC_SHA512_BLOCK_SIZE - sha512->buffLen);
if (sha512->buffLen < WC_SHA512_BLOCK_SIZE ) {
XMEMSET(&local[sha512->buffLen], 0,
WC_SHA512_BLOCK_SIZE - sha512->buffLen);
}
sha512->buffLen += WC_SHA512_BLOCK_SIZE - sha512->buffLen;
#if defined(LITTLE_ENDIAN_ORDER)
#if defined(USE_INTEL_SPEEDUP) && \