Skip to content

Commit ae21f7b

Browse files
committed
CBMC: Improve performance of polyvec_basemul_acc_montgomery proof
Signed-off-by: Hanno Becker <[email protected]>
1 parent 1ed3c4a commit ae21f7b

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

mlkem/poly_k.c

+9-12
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,19 @@ void mlk_polyvec_basemul_acc_montgomery_cached(
138138
invariant(array_abs_bound(r->coeffs, 0, 2 * i, INT16_MAX/2)))
139139
{
140140
unsigned k;
141-
int32_t t0 = 0, t1 = 0;
141+
int32_t t[2] = {0};
142142
for (k = 0; k < MLKEM_K; k++)
143143
__loop__(
144-
invariant(k <= MLKEM_K && i <= MLKEM_N / 2 &&
145-
t0 <= ((int32_t) k * 2 * MLKEM_UINT12_LIMIT * MLK_NTT_BOUND) &&
146-
t0 >= - ((int32_t) k * 2 * MLKEM_UINT12_LIMIT * MLK_NTT_BOUND) &&
147-
t1 <= ((int32_t) k * 2 * MLKEM_UINT12_LIMIT * MLK_NTT_BOUND) &&
148-
t1 >= - ((int32_t) k * 2 * MLKEM_UINT12_LIMIT * MLK_NTT_BOUND)))
144+
invariant(k <= MLKEM_K && i <= MLKEM_N / 2)
145+
invariant(array_abs_bound(t, 0, 2, k * 2 * MLKEM_UINT12_LIMIT * MLK_NTT_BOUND + 1)))
149146
{
150-
t0 += (int32_t)a->vec[k].coeffs[2 * i + 1] * b_cache->vec[k].coeffs[i];
151-
t0 += (int32_t)a->vec[k].coeffs[2 * i] * b->vec[k].coeffs[2 * i];
152-
t1 += (int32_t)a->vec[k].coeffs[2 * i] * b->vec[k].coeffs[2 * i + 1];
153-
t1 += (int32_t)a->vec[k].coeffs[2 * i + 1] * b->vec[k].coeffs[2 * i];
147+
t[0] += (int32_t)a->vec[k].coeffs[2 * i + 1] * b_cache->vec[k].coeffs[i];
148+
t[0] += (int32_t)a->vec[k].coeffs[2 * i] * b->vec[k].coeffs[2 * i];
149+
t[1] += (int32_t)a->vec[k].coeffs[2 * i] * b->vec[k].coeffs[2 * i + 1];
150+
t[1] += (int32_t)a->vec[k].coeffs[2 * i + 1] * b->vec[k].coeffs[2 * i];
154151
}
155-
r->coeffs[2 * i + 0] = mlk_montgomery_reduce(t0);
156-
r->coeffs[2 * i + 1] = mlk_montgomery_reduce(t1);
152+
r->coeffs[2 * i + 0] = mlk_montgomery_reduce(t[0]);
153+
r->coeffs[2 * i + 1] = mlk_montgomery_reduce(t[1]);
157154
}
158155
}
159156

0 commit comments

Comments
 (0)