Skip to content

Commit d14b506

Browse files
anhuJacobBarthelmeh
authored andcommitted
Fix Dilithium with USE_INTEL_SPEEDUP (ZD 21417)
Add check before word32 addition in dilithium_hash256() that could wrap to zero, bypassing the size check. Also reject absurdly large msgLen (> UINT32_MAX/2) in wc_dilithium_verify_ctx_msg.
1 parent b3278af commit d14b506

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

wolfcrypt/src/dilithium.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ static int dilithium_hash256(wc_Shake* shake256, const byte* data1,
503503
word64* state = shake256->s;
504504
word8 *state8 = (word8*)state;
505505

506+
if (data2Len > (UINT32_MAX - data1Len)) {
507+
return BAD_FUNC_ARG;
508+
}
506509
if (data1Len + data2Len >= WC_SHA3_256_COUNT * 8) {
507510
XMEMCPY(state8, data1, data1Len);
508511
XMEMCPY(state8 + data1Len, data2, WC_SHA3_256_COUNT * 8 - data1Len);
@@ -10554,6 +10557,10 @@ int wc_dilithium_verify_ctx_msg(const byte* sig, word32 sigLen, const byte* ctx,
1055410557
if ((ret == 0) && (ctx == NULL) && (ctxLen > 0)) {
1055510558
ret = BAD_FUNC_ARG;
1055610559
}
10560+
/* Reject msgLen that would cause integer overflow in hash computations */
10561+
if ((ret == 0) && (msgLen > UINT32_MAX / 2)) {
10562+
ret = BAD_FUNC_ARG;
10563+
}
1055710564

1055810565
#ifdef WOLF_CRYPTO_CB
1055910566
if (ret == 0) {

0 commit comments

Comments
 (0)