Skip to content

Commit fc19c36

Browse files
committed
Dilithium: fix check hint
When all indeces are 0, then don't check hints against indeces.
1 parent 039853c commit fc19c36

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

tests/api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32389,6 +32389,12 @@ static int test_wc_dilithium_verify(void)
3238932389
0);
3239032390
ExpectIntEQ(res, 0);
3239132391
sig[100] ^= 0x80;
32392+
32393+
/* Set all indeces to 0. */
32394+
XMEMSET(sig + sigLen - 4, 0, 4);
32395+
ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
32396+
SIG_VERIFY_E);
32397+
ExpectIntEQ(res, 0);
3239232398
}
3239332399
#endif
3239432400

wolfcrypt/src/dilithium.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,11 +3183,11 @@ static int dilithium_check_hint(const byte* h, byte k, byte omega)
31833183
unsigned int i;
31843184

31853185
/* Skip polynomial index while count is 0. */
3186-
while ((h[omega + o] == 0) && (o < k)) {
3186+
while ((o < k) && (h[omega + o] == 0)) {
31873187
o++;
31883188
}
31893189
/* Check all possible hints. */
3190-
for (i = 1; i < omega; i++) {
3190+
for (i = 1; (o < k) && (i < omega); i++) {
31913191
/* Done with polynomial if index equals count of hints. */
31923192
if (i == h[omega + o]) {
31933193
/* Next polynomial index while count is index. */

0 commit comments

Comments
 (0)