Skip to content

Commit d343ea6

Browse files
authored
Merge pull request #10190 from rlm2002/mlkem_valgrind
Nightly-multi-test valgrind fix
2 parents ae0a387 + 9a8610c commit d343ea6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

wolfcrypt/src/wc_mlkem_poly.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ static int mlkem_gen_matrix_k2_avx2(sword16* a, byte* seed, int transposed)
22922292
byte *rand = NULL;
22932293
word64 *state = NULL;
22942294
#else
2295-
byte rand[4 * GEN_MATRIX_SIZE + 2];
2295+
byte rand[4 * GEN_MATRIX_SIZE + 4];
22962296
word64 state[25 * 4];
22972297
#endif
22982298
unsigned int ctr0;
@@ -2302,7 +2302,7 @@ static int mlkem_gen_matrix_k2_avx2(sword16* a, byte* seed, int transposed)
23022302
byte* p;
23032303

23042304
#ifdef WOLFSSL_SMALL_STACK
2305-
rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 2, NULL,
2305+
rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 4, NULL,
23062306
DYNAMIC_TYPE_TMP_BUFFER);
23072307
state = (word64*)XMALLOC(sizeof(word64) * 25 * 4, NULL,
23082308
DYNAMIC_TYPE_TMP_BUFFER);
@@ -2313,9 +2313,11 @@ static int mlkem_gen_matrix_k2_avx2(sword16* a, byte* seed, int transposed)
23132313
}
23142314
#endif
23152315

2316-
/* Loading 64 bits, only using 48 bits. Loading 2 bytes more than used. */
2316+
/* Loading 64 bits, only using 48 bits. Loading 4 bytes more than used. */
23172317
rand[4 * GEN_MATRIX_SIZE + 0] = 0xff;
23182318
rand[4 * GEN_MATRIX_SIZE + 1] = 0xff;
2319+
rand[4 * GEN_MATRIX_SIZE + 2] = 0xff;
2320+
rand[4 * GEN_MATRIX_SIZE + 3] = 0xff;
23192321

23202322
if (!transposed) {
23212323
state[4*4 + 0] = 0x1f0000 + 0x000;
@@ -2403,7 +2405,7 @@ static int mlkem_gen_matrix_k3_avx2(sword16* a, byte* seed, int transposed)
24032405
byte *rand = NULL;
24042406
word64 *state = NULL;
24052407
#else
2406-
byte rand[4 * GEN_MATRIX_SIZE + 2];
2408+
byte rand[4 * GEN_MATRIX_SIZE + 4];
24072409
word64 state[25 * 4];
24082410
#endif
24092411
unsigned int ctr0;
@@ -2413,7 +2415,7 @@ static int mlkem_gen_matrix_k3_avx2(sword16* a, byte* seed, int transposed)
24132415
byte* p;
24142416

24152417
#ifdef WOLFSSL_SMALL_STACK
2416-
rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 2, NULL,
2418+
rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 4, NULL,
24172419
DYNAMIC_TYPE_TMP_BUFFER);
24182420
state = (word64*)XMALLOC(sizeof(word64) * 25 * 4, NULL,
24192421
DYNAMIC_TYPE_TMP_BUFFER);
@@ -2424,9 +2426,11 @@ static int mlkem_gen_matrix_k3_avx2(sword16* a, byte* seed, int transposed)
24242426
}
24252427
#endif
24262428

2427-
/* Loading 64 bits, only using 48 bits. Loading 2 bytes more than used. */
2429+
/* Loading 64 bits, only using 48 bits. Loading 4 bytes more than used. */
24282430
rand[4 * GEN_MATRIX_SIZE + 0] = 0xff;
24292431
rand[4 * GEN_MATRIX_SIZE + 1] = 0xff;
2432+
rand[4 * GEN_MATRIX_SIZE + 2] = 0xff;
2433+
rand[4 * GEN_MATRIX_SIZE + 3] = 0xff;
24302434

24312435
for (k = 0; k < 2; k++) {
24322436
for (i = 0; i < 4; i++) {
@@ -2559,7 +2563,7 @@ static int mlkem_gen_matrix_k4_avx2(sword16* a, byte* seed, int transposed)
25592563
byte *rand = NULL;
25602564
word64 *state = NULL;
25612565
#else
2562-
byte rand[4 * GEN_MATRIX_SIZE + 2];
2566+
byte rand[4 * GEN_MATRIX_SIZE + 4];
25632567
word64 state[25 * 4];
25642568
#endif
25652569
unsigned int ctr0;
@@ -2569,7 +2573,7 @@ static int mlkem_gen_matrix_k4_avx2(sword16* a, byte* seed, int transposed)
25692573
byte* p;
25702574

25712575
#ifdef WOLFSSL_SMALL_STACK
2572-
rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 2, NULL,
2576+
rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 4, NULL,
25732577
DYNAMIC_TYPE_TMP_BUFFER);
25742578
state = (word64*)XMALLOC(sizeof(word64) * 25 * 4, NULL,
25752579
DYNAMIC_TYPE_TMP_BUFFER);
@@ -2580,9 +2584,11 @@ static int mlkem_gen_matrix_k4_avx2(sword16* a, byte* seed, int transposed)
25802584
}
25812585
#endif
25822586

2583-
/* Loading 64 bits, only using 48 bits. Loading 2 bytes more than used. */
2587+
/* Loading 64 bits, only using 48 bits. Loading 4 bytes more than used. */
25842588
rand[4 * GEN_MATRIX_SIZE + 0] = 0xff;
25852589
rand[4 * GEN_MATRIX_SIZE + 1] = 0xff;
2590+
rand[4 * GEN_MATRIX_SIZE + 2] = 0xff;
2591+
rand[4 * GEN_MATRIX_SIZE + 3] = 0xff;
25862592

25872593
for (k = 0; k < 4; k++) {
25882594
for (i = 0; i < 4; i++) {

0 commit comments

Comments
 (0)