Skip to content

Commit c4233e7

Browse files
authored
Merge pull request #6288 from JacobBarthelmeh/Testing
avoid callback buffer overwrite with sha512_224 and remove min from w…
2 parents 7fb9540 + edad8d1 commit c4233e7

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

wolfcrypt/src/port/caam/wolfcaam_cmac.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ int wc_CAAM_Cmac(Cmac* cmac, const byte* key, word32 keySz, const byte* in,
9999
WOLFSSL_MSG("Error with CMAC buffer size");
100100
return -1;
101101
}
102-
add = min(sz, (int)(AES_BLOCK_SIZE - cmac->bufferSz));
102+
add = (sz < ((int)(AES_BLOCK_SIZE - cmac->bufferSz))) ? sz :
103+
(int)(AES_BLOCK_SIZE - cmac->bufferSz);
103104
XMEMCPY(&cmac->buffer[cmac->bufferSz], pt, add);
104105

105106
cmac->bufferSz += add;

wolfcrypt/src/sha512.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,9 +1152,12 @@ static int Sha512_Family_Final(wc_Sha512* sha512, byte* hash, size_t digestSz,
11521152

11531153
#ifdef WOLF_CRYPTO_CB
11541154
if (sha512->devId != INVALID_DEVID) {
1155-
ret = wc_CryptoCb_Sha512Hash(sha512, NULL, 0, hash);
1156-
if (ret != CRYPTOCB_UNAVAILABLE)
1155+
byte localHash[WC_SHA512_DIGEST_SIZE];
1156+
ret = wc_CryptoCb_Sha512Hash(sha512, NULL, 0, localHash);
1157+
if (ret != CRYPTOCB_UNAVAILABLE) {
1158+
XMEMCPY(hash, localHash, digestSz);
11571159
return ret;
1160+
}
11581161
/* fall-through when unavailable */
11591162
}
11601163
#endif

0 commit comments

Comments
 (0)