|
| 1 | +/* |
| 2 | + * Copyright (c) The mldsa-native project authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 | + */ |
| 5 | + |
| 6 | +#ifndef MLD_NATIVE_RV32IM_SRC_ARITH_NATIVE_RV32IM_H |
| 7 | +#define MLD_NATIVE_RV32IM_SRC_ARITH_NATIVE_RV32IM_H |
| 8 | + |
| 9 | +#include "../../../cbmc.h" |
| 10 | +#include "../../../common.h" |
| 11 | + |
| 12 | +#define mld_rv32im_ntt_zetas MLD_NAMESPACE(rv32im_ntt_zetas) |
| 13 | + |
| 14 | +/* |
| 15 | + * Forward NTT zeta table for the RV32-IM backend. |
| 16 | + * |
| 17 | + * 255 logical entries, each a (zeta, zeta * QINV mod 2^32) pair, with |
| 18 | + * zeta in Montgomery form (i.e. R * w^{bitrev_8(k)} mod q where R = 2^32). |
| 19 | + * The order matches the consumption order of the 2+2+2+2 forward NTT. |
| 20 | + */ |
| 21 | +MLD_INTERNAL_DATA_DECLARATION const int32_t mld_rv32im_ntt_zetas[510]; |
| 22 | + |
| 23 | +#define mld_ntt_rv32im_asm MLD_NAMESPACE(ntt_rv32im_asm) |
| 24 | +void mld_ntt_rv32im_asm(int32_t *r, const int32_t *zetas) |
| 25 | +__contract__( |
| 26 | + requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N)) |
| 27 | + requires(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q)) |
| 28 | + requires(zetas == mld_rv32im_ntt_zetas) |
| 29 | + assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N)) |
| 30 | + ensures(array_abs_bound(r, 0, MLDSA_N, 9 * MLDSA_Q)) |
| 31 | +); |
| 32 | + |
| 33 | +#define mld_intt_rv32im_asm MLD_NAMESPACE(intt_rv32im_asm) |
| 34 | +void mld_intt_rv32im_asm(int32_t *r, const int32_t *zetas) |
| 35 | +__contract__( |
| 36 | + requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N)) |
| 37 | + requires(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q)) |
| 38 | + requires(zetas == mld_rv32im_ntt_zetas) |
| 39 | + assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N)) |
| 40 | + ensures(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q)) |
| 41 | +); |
| 42 | + |
| 43 | +#define mld_poly_pointwise_montgomery_rv32im_asm \ |
| 44 | + MLD_NAMESPACE(poly_pointwise_montgomery_rv32im_asm) |
| 45 | +void mld_poly_pointwise_montgomery_rv32im_asm(int32_t *a, const int32_t *b) |
| 46 | +__contract__( |
| 47 | + requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N)) |
| 48 | + requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N)) |
| 49 | + /* check-magic: off */ |
| 50 | + requires(array_abs_bound(a, 0, MLDSA_N, 75423753)) /* MLD_NTT_BOUND */ |
| 51 | + requires(array_abs_bound(b, 0, MLDSA_N, 75423753)) |
| 52 | + /* check-magic: on */ |
| 53 | + assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N)) |
| 54 | + ensures(array_abs_bound(a, 0, MLDSA_N, MLDSA_Q)) |
| 55 | +); |
| 56 | + |
| 57 | +#endif /* !MLD_NATIVE_RV32IM_SRC_ARITH_NATIVE_RV32IM_H */ |
0 commit comments