Skip to content

Commit c93f7e1

Browse files
committed
Switches to use "unsigned" not "int" for all coefficient indexes.
Consistent with a similar change to the reference code on main branch. Signed-off-by: Rod Chapman <[email protected]>
1 parent cb650de commit c93f7e1

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

mlkem/ntt.c

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@
121121
/* contracts, so it is "inlined for proof" by CBMC */
122122
/* This allows CBMC to keep track of the ranges of the */
123123
/* modified coefficients in the calling functions. */
124-
static INLINE void ct_butterfly(int16_t r[MLKEM_N], const int coeff1_index,
125-
const int coeff2_index, const int16_t zeta)
124+
static INLINE void ct_butterfly(int16_t r[MLKEM_N], const unsigned coeff1_index,
125+
const unsigned coeff2_index, const int16_t zeta)
126126
{
127127
int16_t t1 = r[coeff1_index];
128128
int16_t t2 = fqmul(r[coeff2_index], zeta);
@@ -166,14 +166,14 @@ __contract__(
166166
{
167167
/* 8 coeffifient indexes, starting at element j */
168168
/* and increasing in strides of 32 */
169-
const int ci0 = j;
170-
const int ci1 = ci0 + 32;
171-
const int ci2 = ci0 + 64;
172-
const int ci3 = ci0 + 96;
173-
const int ci4 = ci0 + 128;
174-
const int ci5 = ci0 + 160;
175-
const int ci6 = ci0 + 192;
176-
const int ci7 = ci0 + 224;
169+
const unsigned ci0 = j;
170+
const unsigned ci1 = ci0 + 32;
171+
const unsigned ci2 = ci0 + 64;
172+
const unsigned ci3 = ci0 + 96;
173+
const unsigned ci4 = ci0 + 128;
174+
const unsigned ci5 = ci0 + 160;
175+
const unsigned ci6 = ci0 + 192;
176+
const unsigned ci7 = ci0 + 224;
177177

178178
/* Layer 1 */
179179
ct_butterfly(r, ci0, ci4, l1zeta1);
@@ -226,10 +226,10 @@ __contract__(
226226
{
227227
/* 4 coeffifient indexes, starting at element j + start */
228228
/* and increasing in strides of 8 */
229-
const int ci1 = j + start;
230-
const int ci2 = ci1 + 8;
231-
const int ci3 = ci1 + 16;
232-
const int ci4 = ci1 + 24;
229+
const unsigned ci1 = j + start;
230+
const unsigned ci2 = ci1 + 8;
231+
const unsigned ci3 = ci1 + 16;
232+
const unsigned ci4 = ci1 + 24;
233233

234234
/* Layer 4 */
235235
ct_butterfly(r, ci1, ci3, z1);
@@ -286,8 +286,8 @@ __contract__(
286286
invariant(array_abs_bound(r, start + 4, start + j + 4, NTT_BOUND7))
287287
invariant(array_abs_bound(r, start + j + 4, MLKEM_N, NTT_BOUND6)))
288288
{
289-
const int ci1 = j + start;
290-
const int ci2 = ci1 + 4;
289+
const unsigned ci1 = j + start;
290+
const unsigned ci2 = ci1 + 4;
291291

292292
ct_butterfly(r, ci1, ci2, zeta);
293293
}
@@ -325,10 +325,10 @@ __contract__(
325325
ensures (array_abs_bound(r, start + 4, MLKEM_N, NTT_BOUND7)))
326326
{
327327
const int32_t zeta = (int32_t)layer7_zetas[zeta_index];
328-
const unsigned int ci0 = start;
329-
const unsigned int ci1 = ci0 + 1;
330-
const unsigned int ci2 = ci0 + 2;
331-
const unsigned int ci3 = ci0 + 3;
328+
const unsigned ci0 = start;
329+
const unsigned ci1 = ci0 + 1;
330+
const unsigned ci2 = ci0 + 2;
331+
const unsigned ci3 = ci0 + 3;
332332

333333
ct_butterfly(r, ci0, ci2, zeta);
334334
ct_butterfly(r, ci1, ci3, zeta);
@@ -457,8 +457,8 @@ void poly_ntt(poly *p)
457457
/* Like ct_butterfly(), this functions is inlined */
458458
/* for both compilation and proof. */
459459
static INLINE void gs_butterfly_reduce(int16_t r[MLKEM_N],
460-
const int coeff1_index,
461-
const int coeff2_index,
460+
const unsigned coeff1_index,
461+
const unsigned coeff2_index,
462462
const int16_t zeta)
463463
{
464464
const int16_t t1 = r[coeff1_index];
@@ -470,8 +470,8 @@ static INLINE void gs_butterfly_reduce(int16_t r[MLKEM_N],
470470
/* As gs_butterfly_reduce(), but does not reduce the */
471471
/* coefficient denoted by coeff1_index */
472472
static INLINE void gs_butterfly_defer(int16_t r[MLKEM_N],
473-
const int coeff1_index,
474-
const int coeff2_index,
473+
const unsigned coeff1_index,
474+
const unsigned coeff2_index,
475475
const int16_t zeta)
476476
{
477477
const int16_t t1 = r[coeff1_index];
@@ -495,10 +495,10 @@ __contract__(
495495
)
496496
{
497497
const int32_t zeta = (int32_t)layer7_zetas[zeta_index];
498-
const int ci0 = start;
499-
const int ci1 = ci0 + 1;
500-
const int ci2 = ci0 + 2;
501-
const int ci3 = ci0 + 3;
498+
const unsigned ci0 = start;
499+
const unsigned ci1 = ci0 + 1;
500+
const unsigned ci2 = ci0 + 2;
501+
const unsigned ci3 = ci0 + 3;
502502

503503
/* Invert and reduce all coefficients here the first time they */
504504
/* are read. This is efficient, and also means we can accept */
@@ -547,14 +547,14 @@ __contract__(
547547
)
548548
{
549549
const int32_t zeta = (int32_t)layer6_zetas[zeta_index];
550-
const int ci0 = start;
551-
const int ci1 = ci0 + 1;
552-
const int ci2 = ci0 + 2;
553-
const int ci3 = ci0 + 3;
554-
const int ci4 = ci0 + 4;
555-
const int ci5 = ci0 + 5;
556-
const int ci6 = ci0 + 6;
557-
const int ci7 = ci0 + 7;
550+
const unsigned ci0 = start;
551+
const unsigned ci1 = ci0 + 1;
552+
const unsigned ci2 = ci0 + 2;
553+
const unsigned ci3 = ci0 + 3;
554+
const unsigned ci4 = ci0 + 4;
555+
const unsigned ci5 = ci0 + 5;
556+
const unsigned ci6 = ci0 + 6;
557+
const unsigned ci7 = ci0 + 7;
558558

559559
/* Defer reduction of coefficients 0, 1, 2, and 3 here so they */
560560
/* are bounded to NTT_BOUND2 after Layer6 */
@@ -618,10 +618,10 @@ __contract__(
618618
invariant(array_abs_bound(r, start + 24, start + j + 24, NTT_BOUND1))
619619
invariant(array_abs_bound(r, start + j + 24, MLKEM_N, NTT_BOUND2)))
620620
{
621-
const int ci0 = j + start;
622-
const int ci8 = ci0 + 8;
623-
const int ci16 = ci0 + 16;
624-
const int ci24 = ci0 + 24;
621+
const unsigned ci0 = j + start;
622+
const unsigned ci8 = ci0 + 8;
623+
const unsigned ci16 = ci0 + 16;
624+
const unsigned ci24 = ci0 + 24;
625625

626626
/* Layer 5 - Defer reduction of coeffs 0 and 16 here */
627627
gs_butterfly_defer(r, ci0, ci8, l5zeta2);
@@ -675,14 +675,14 @@ __contract__(
675675
invariant(array_abs_bound(r, j + 96, 128, NTT_BOUND1))
676676
invariant(array_abs_bound(r, 128, MLKEM_N, NTT_BOUND1)))
677677
{
678-
const int ci0 = j + 0;
679-
const int ci32 = j + 32;
680-
const int ci64 = j + 64;
681-
const int ci96 = j + 96;
682-
const int ci128 = j + 128;
683-
const int ci160 = j + 160;
684-
const int ci192 = j + 192;
685-
const int ci224 = j + 224;
678+
const unsigned ci0 = j + 0;
679+
const unsigned ci32 = j + 32;
680+
const unsigned ci64 = j + 64;
681+
const unsigned ci96 = j + 96;
682+
const unsigned ci128 = j + 128;
683+
const unsigned ci160 = j + 160;
684+
const unsigned ci192 = j + 192;
685+
const unsigned ci224 = j + 224;
686686

687687
/* Layer 3 */
688688
gs_butterfly_defer(r, ci0, ci32, l3zeta7);

0 commit comments

Comments
 (0)