Skip to content

Commit b4ac310

Browse files
committed
Consistently use mld_assert instead of cassert
cassert turns into a CBMC proof assertion inside of CBMC proofs, but it turns into a no-op otherwise. mld_assert behaves the save inside of CBMC proofs, but also turns into a run-time assertion in debug builds. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 387fbd5 commit b4ac310

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

mldsa/fips202/fips202.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ __contract__(
9393
{
9494
s[i] = 0;
9595
}
96-
97-
cassert(forall(k, 0, MLD_KECCAK_LANES, s[k] == 0));
9896
}
9997

10098
/*************************************************

mldsa/polyvec.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string.h>
77

88
#include "common.h"
9+
#include "debug.h"
910
#include "poly.h"
1011
#include "polyvec.h"
1112

@@ -270,20 +271,20 @@ void mld_polyvecl_pointwise_acc_montgomery(mld_poly *w, const mld_polyvecl *u,
270271
}
271272

272273
/* Substitute j == MLSDA_L into the loop invariant to get... */
273-
cassert(j == MLDSA_L);
274-
cassert(t >= -(int64_t)MLDSA_L * (MLDSA_Q - 1) * (MLD_NTT_BOUND - 1));
275-
cassert(t <= (int64_t)MLDSA_L * (MLDSA_Q - 1) * (MLD_NTT_BOUND - 1));
274+
mld_assert(j == MLDSA_L);
275+
mld_assert(t >= -(int64_t)MLDSA_L * (MLDSA_Q - 1) * (MLD_NTT_BOUND - 1));
276+
mld_assert(t <= (int64_t)MLDSA_L * (MLDSA_Q - 1) * (MLD_NTT_BOUND - 1));
276277

277278
/* ...and therefore... */
278-
cassert(t >= -MONTGOMERY_REDUCE_STRONG_DOMAIN_MAX);
279-
cassert(t < MONTGOMERY_REDUCE_STRONG_DOMAIN_MAX);
279+
mld_assert(t >= -MONTGOMERY_REDUCE_STRONG_DOMAIN_MAX);
280+
mld_assert(t < MONTGOMERY_REDUCE_STRONG_DOMAIN_MAX);
280281

281282
/* ...which meets the "strong" case of mld_montgomery_reduce() */
282283
r = mld_montgomery_reduce(t);
283284

284285
/* ...and therefore we can assert a stronger bound on r */
285-
cassert(r > -MLDSA_Q);
286-
cassert(r < MLDSA_Q);
286+
mld_assert(r > -MLDSA_Q);
287+
mld_assert(r < MLDSA_Q);
287288
w->coeffs[i] = r;
288289
}
289290
}

mldsa/rounding.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
#include <stdint.h>
66

7+
#include "debug.h"
78
#include "rounding.h"
89

910

@@ -17,20 +18,20 @@ void mld_decompose(int32_t *a0, int32_t *a1, int32_t a)
1718
{
1819
*a1 = (a + 127) >> 7;
1920
/* We know a >= 0 and a < MLDSA_Q, so... */
20-
cassert(*a1 >= 0 && *a1 <= 65472);
21+
mld_assert(*a1 >= 0 && *a1 <= 65472);
2122

2223
#if MLDSA_MODE == 2
2324
*a1 = (*a1 * 11275 + (1 << 23)) >> 24;
24-
cassert(*a1 >= 0 && *a1 <= 44);
25+
mld_assert(*a1 >= 0 && *a1 <= 44);
2526

2627
*a1 ^= ((43 - *a1) >> 31) & *a1;
27-
cassert(*a1 >= 0 && *a1 <= 43);
28+
mld_assert(*a1 >= 0 && *a1 <= 43);
2829
#else /* MLDSA_MODE == 2 */
2930
*a1 = (*a1 * 1025 + (1 << 21)) >> 22;
30-
cassert(*a1 >= 0 && *a1 <= 16);
31+
mld_assert(*a1 >= 0 && *a1 <= 16);
3132

3233
*a1 &= 15;
33-
cassert(*a1 >= 0 && *a1 <= 15);
34+
mld_assert(*a1 >= 0 && *a1 <= 15);
3435

3536
#endif /* MLDSA_MODE != 2 */
3637

0 commit comments

Comments
 (0)