Skip to content

Commit 4f3586f

Browse files
authored
Merge pull request #9421 from SparkiDev/mlkem_to_bytes_fix
ML-KEM to bytes C: not reducing all values
2 parents 0829436 + b272f78 commit 4f3586f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

wolfcrypt/src/wc_mlkem_poly.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,7 +4775,7 @@ static MLKEM_NOINLINE void mlkem_csubq_c(sword16* p)
47754775
for (i = 0; i < MLKEM_N; ++i) {
47764776
sword16 t = p[i] - MLKEM_Q;
47774777
/* When top bit set, -ve number - need to add q back. */
4778-
p[i] = ((t >> 15) & MLKEM_Q) + t;
4778+
p[i] = (sword16)((word16)(-((word16)t >> 15)) & MLKEM_Q) + t;
47794779
}
47804780
}
47814781

@@ -6021,11 +6021,11 @@ static void mlkem_to_bytes_c(byte* b, sword16* p, int k)
60216021
int i;
60226022
int j;
60236023

6024-
/* Reduce each coefficient to mod q. */
6025-
mlkem_csubq_c(p);
6026-
/* All values are now positive. */
6027-
60286024
for (j = 0; j < k; j++) {
6025+
/* Reduce each coefficient to mod q. */
6026+
mlkem_csubq_c(p);
6027+
/* All values are now positive. */
6028+
60296029
for (i = 0; i < MLKEM_N / 2; i++) {
60306030
word16 t0 = p[2 * i];
60316031
word16 t1 = p[2 * i + 1];

0 commit comments

Comments
 (0)