pq_crypto 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/SECURITY.md +7 -0
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +4 -4
- data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +3 -3
- metadata +41 -35
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
|
@@ -15,21 +15,22 @@
|
|
|
15
15
|
/* Absolute exclusive upper bound for the output of the inverse NTT*/
|
|
16
16
|
#define MLD_INTT_BOUND MLDSA_Q
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Element of R_q = Z_q[X]/(X^n + 1). Represents polynomial
|
|
20
|
+
* coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1].
|
|
21
|
+
*/
|
|
18
22
|
typedef struct
|
|
19
23
|
{
|
|
20
|
-
int32_t coeffs[MLDSA_N];
|
|
24
|
+
int32_t coeffs[MLDSA_N]; /**< Polynomial coefficients. */
|
|
21
25
|
} MLD_ALIGN mld_poly;
|
|
22
26
|
|
|
23
27
|
#define mld_poly_reduce MLD_NAMESPACE(poly_reduce)
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* Description: Inplace reduction of all coefficients of polynomial to
|
|
28
|
-
* representative in
|
|
29
|
-
*[-MLD_REDUCE32_RANGE_MAX,MLD_REDUCE32_RANGE_MAX].
|
|
28
|
+
/**
|
|
29
|
+
* In-place reduction of all coefficients of polynomial to representative in
|
|
30
|
+
* [-MLD_REDUCE32_RANGE_MAX, MLD_REDUCE32_RANGE_MAX].
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
-
|
|
32
|
+
* @param[in,out] a Pointer to input/output polynomial.
|
|
33
|
+
*/
|
|
33
34
|
MLD_INTERNAL_API
|
|
34
35
|
void mld_poly_reduce(mld_poly *a)
|
|
35
36
|
__contract__(
|
|
@@ -40,14 +41,12 @@ __contract__(
|
|
|
40
41
|
);
|
|
41
42
|
|
|
42
43
|
#define mld_poly_caddq MLD_NAMESPACE(poly_caddq)
|
|
43
|
-
|
|
44
|
-
*
|
|
44
|
+
/**
|
|
45
|
+
* For all coefficients of in/out polynomial add MLDSA_Q if coefficient is
|
|
46
|
+
* negative.
|
|
45
47
|
*
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
* Arguments: - mld_poly *a: pointer to input/output polynomial
|
|
50
|
-
**************************************************/
|
|
48
|
+
* @param[in,out] a Pointer to input/output polynomial.
|
|
49
|
+
*/
|
|
51
50
|
MLD_INTERNAL_API
|
|
52
51
|
void mld_poly_caddq(mld_poly *a)
|
|
53
52
|
__contract__(
|
|
@@ -57,16 +56,16 @@ __contract__(
|
|
|
57
56
|
ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
|
|
58
57
|
);
|
|
59
58
|
|
|
59
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_NO_SIGN_API) || \
|
|
60
|
+
defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
|
|
60
61
|
#define mld_poly_add MLD_NAMESPACE(poly_add)
|
|
61
|
-
|
|
62
|
-
*
|
|
62
|
+
/**
|
|
63
|
+
* Add polynomials. No modular reduction is performed.
|
|
63
64
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
* to r. Must be disjoint from r.
|
|
69
|
-
**************************************************/
|
|
65
|
+
* @param[in,out] r Pointer to input-output polynomial to be added to.
|
|
66
|
+
* @param[in] b Pointer to input polynomial that should be added to r.
|
|
67
|
+
* Must be disjoint from r.
|
|
68
|
+
*/
|
|
70
69
|
|
|
71
70
|
/*
|
|
72
71
|
* NOTE: The reference implementation uses a 3-argument poly_add.
|
|
@@ -84,18 +83,18 @@ __contract__(
|
|
|
84
83
|
ensures(forall(k3, 0, MLDSA_N, r->coeffs[k3] < MLD_REDUCE32_DOMAIN_MAX))
|
|
85
84
|
ensures(forall(k4, 0, MLDSA_N, r->coeffs[k4] >= INT32_MIN))
|
|
86
85
|
);
|
|
86
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API || \
|
|
87
|
+
MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
|
|
87
88
|
|
|
89
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
88
90
|
#define mld_poly_sub MLD_NAMESPACE(poly_sub)
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* Description: Subtract polynomials. No modular reduction is
|
|
93
|
-
* performed.
|
|
91
|
+
/**
|
|
92
|
+
* Subtract polynomials. No modular reduction is performed.
|
|
94
93
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
|
|
94
|
+
* @param[in,out] r Pointer to input-output polynomial.
|
|
95
|
+
* @param[in] b Pointer to input polynomial that should be subtracted from
|
|
96
|
+
* r. Must be disjoint from r.
|
|
97
|
+
*/
|
|
99
98
|
/*
|
|
100
99
|
* NOTE: The reference implementation uses a 3-argument poly_sub.
|
|
101
100
|
* We specialize to the accumulator form to avoid reasoning about aliasing.
|
|
@@ -110,16 +109,16 @@ __contract__(
|
|
|
110
109
|
assigns(memory_slice(r, sizeof(mld_poly)))
|
|
111
110
|
ensures(array_bound(r->coeffs, 0, MLDSA_N, INT32_MIN, MLD_REDUCE32_DOMAIN_MAX))
|
|
112
111
|
);
|
|
112
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
|
|
113
113
|
|
|
114
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
114
115
|
#define mld_poly_shiftl MLD_NAMESPACE(poly_shiftl)
|
|
115
|
-
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* Description: Multiply polynomial by 2^MLDSA_D without modular reduction.
|
|
119
|
-
*Assumes input coefficients to be less than 2^{31-MLDSA_D} in absolute value.
|
|
116
|
+
/**
|
|
117
|
+
* Multiply polynomial by 2^MLDSA_D without modular reduction. Assumes input
|
|
118
|
+
* coefficients to be less than 2^{31-MLDSA_D} in absolute value.
|
|
120
119
|
*
|
|
121
|
-
*
|
|
122
|
-
|
|
120
|
+
* @param[in,out] a Pointer to input/output polynomial.
|
|
121
|
+
*/
|
|
123
122
|
MLD_INTERNAL_API
|
|
124
123
|
void mld_poly_shiftl(mld_poly *a)
|
|
125
124
|
__contract__(
|
|
@@ -128,16 +127,14 @@ __contract__(
|
|
|
128
127
|
assigns(memory_slice(a, sizeof(mld_poly)))
|
|
129
128
|
ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
|
|
130
129
|
);
|
|
130
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
131
131
|
|
|
132
132
|
#define mld_poly_ntt MLD_NAMESPACE(poly_ntt)
|
|
133
|
-
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* Description: Inplace forward NTT. Coefficients can grow by
|
|
137
|
-
* 8*MLDSA_Q in absolute value.
|
|
133
|
+
/**
|
|
134
|
+
* In-place forward NTT. Coefficients can grow by 8*MLDSA_Q in absolute value.
|
|
138
135
|
*
|
|
139
|
-
*
|
|
140
|
-
|
|
136
|
+
* @param[in,out] a Pointer to input/output polynomial.
|
|
137
|
+
*/
|
|
141
138
|
MLD_INTERNAL_API
|
|
142
139
|
void mld_poly_ntt(mld_poly *a)
|
|
143
140
|
__contract__(
|
|
@@ -149,16 +146,14 @@ __contract__(
|
|
|
149
146
|
|
|
150
147
|
|
|
151
148
|
#define mld_poly_invntt_tomont MLD_NAMESPACE(poly_invntt_tomont)
|
|
152
|
-
|
|
153
|
-
*
|
|
149
|
+
/**
|
|
150
|
+
* In-place inverse NTT and multiplication by 2^{32}.
|
|
154
151
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* value and output coefficients are bounded by
|
|
158
|
-
* MLD_INTT_BOUND.
|
|
152
|
+
* Input coefficients need to be less than MLDSA_Q in absolute value and
|
|
153
|
+
* output coefficients are bounded by MLD_INTT_BOUND.
|
|
159
154
|
*
|
|
160
|
-
*
|
|
161
|
-
|
|
155
|
+
* @param[in,out] a Pointer to input/output polynomial.
|
|
156
|
+
*/
|
|
162
157
|
MLD_INTERNAL_API
|
|
163
158
|
void mld_poly_invntt_tomont(mld_poly *a)
|
|
164
159
|
__contract__(
|
|
@@ -168,71 +163,69 @@ __contract__(
|
|
|
168
163
|
ensures(array_abs_bound(a->coeffs, 0, MLDSA_N, MLD_INTT_BOUND))
|
|
169
164
|
);
|
|
170
165
|
|
|
166
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
|
|
167
|
+
defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
|
|
171
168
|
#define mld_poly_pointwise_montgomery MLD_NAMESPACE(poly_pointwise_montgomery)
|
|
172
|
-
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
|
|
182
|
-
**************************************************/
|
|
169
|
+
/**
|
|
170
|
+
* Pointwise multiplication of polynomials in NTT domain representation and
|
|
171
|
+
* multiplication of resulting polynomial by 2^{-32}. Destructive in the first
|
|
172
|
+
* argument.
|
|
173
|
+
*
|
|
174
|
+
* @param[in,out] a Pointer to first input/output polynomial. On entry, holds
|
|
175
|
+
* the first multiplicand; on exit, holds the product
|
|
176
|
+
* a * b * 2^{-32}.
|
|
177
|
+
* @param[in] b Pointer to second input polynomial.
|
|
178
|
+
*/
|
|
183
179
|
MLD_INTERNAL_API
|
|
184
|
-
void mld_poly_pointwise_montgomery(mld_poly *
|
|
185
|
-
const mld_poly *b)
|
|
180
|
+
void mld_poly_pointwise_montgomery(mld_poly *a, const mld_poly *b)
|
|
186
181
|
__contract__(
|
|
187
182
|
requires(memory_no_alias(a, sizeof(mld_poly)))
|
|
188
183
|
requires(memory_no_alias(b, sizeof(mld_poly)))
|
|
189
|
-
requires(memory_no_alias(c, sizeof(mld_poly)))
|
|
190
184
|
requires(array_abs_bound(a->coeffs, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
191
185
|
requires(array_abs_bound(b->coeffs, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
192
|
-
assigns(memory_slice(
|
|
193
|
-
ensures(array_abs_bound(
|
|
186
|
+
assigns(memory_slice(a, sizeof(mld_poly)))
|
|
187
|
+
ensures(array_abs_bound(a->coeffs, 0, MLDSA_N, MLDSA_Q))
|
|
194
188
|
);
|
|
189
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
|
|
190
|
+
MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
|
|
195
191
|
|
|
192
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
196
193
|
#define mld_poly_power2round MLD_NAMESPACE(poly_power2round)
|
|
197
|
-
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*to
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
|
|
207
|
-
* - mld_poly *a0: pointer to output polynomial with coefficients
|
|
208
|
-
*c0
|
|
209
|
-
* - const mld_poly *a: pointer to input polynomial
|
|
210
|
-
**************************************************/
|
|
194
|
+
/**
|
|
195
|
+
* For all coefficients c of the input polynomial, compute c0, c1 such that
|
|
196
|
+
* c mod MLDSA_Q = c1*2^MLDSA_D + c0 with -2^{MLDSA_D-1} < c0 <= 2^{MLDSA_D-1}.
|
|
197
|
+
* Assumes coefficients to be standard representatives.
|
|
198
|
+
*
|
|
199
|
+
* @param[out] a1 Pointer to output polynomial with coefficients c1.
|
|
200
|
+
* @param[out] a0 Pointer to output polynomial with coefficients c0; may alias
|
|
201
|
+
* the input polynomial a.
|
|
202
|
+
* @param[in] a Pointer to input polynomial.
|
|
203
|
+
*/
|
|
211
204
|
MLD_INTERNAL_API
|
|
212
205
|
void mld_poly_power2round(mld_poly *a1, mld_poly *a0, const mld_poly *a)
|
|
213
206
|
__contract__(
|
|
214
207
|
requires(memory_no_alias(a0, sizeof(mld_poly)))
|
|
215
208
|
requires(memory_no_alias(a1, sizeof(mld_poly)))
|
|
216
|
-
|
|
209
|
+
/* The implementation does not require a0 == a, but the single call site
|
|
210
|
+
* aliases them and asserting equality simplifies the proof. */
|
|
211
|
+
requires(a0 == a)
|
|
217
212
|
requires(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
|
|
218
213
|
assigns(memory_slice(a1, sizeof(mld_poly)))
|
|
219
214
|
assigns(memory_slice(a0, sizeof(mld_poly)))
|
|
220
215
|
ensures(array_bound(a0->coeffs, 0, MLDSA_N, -(MLD_2_POW_D/2)+1, (MLD_2_POW_D/2)+1))
|
|
221
216
|
ensures(array_bound(a1->coeffs, 0, MLDSA_N, 0, ((MLDSA_Q - 1) / MLD_2_POW_D) + 1))
|
|
222
217
|
);
|
|
218
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
223
219
|
|
|
224
220
|
#define mld_poly_uniform MLD_NAMESPACE(poly_uniform)
|
|
225
|
-
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* Description: Sample polynomial with uniformly random coefficients
|
|
229
|
-
* in [0,MLDSA_Q-1] by performing rejection sampling on the
|
|
230
|
-
* output stream of SHAKE128(seed|nonce)
|
|
221
|
+
/**
|
|
222
|
+
* Sample polynomial with uniformly random coefficients in [0, MLDSA_Q-1] by
|
|
223
|
+
* performing rejection sampling on the output stream of SHAKE128(seed|nonce).
|
|
231
224
|
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
|
|
225
|
+
* @param[out] a Pointer to output polynomial.
|
|
226
|
+
* @param[in] seed Byte array with seed of length MLDSA_SEEDBYTES and the
|
|
227
|
+
* packed 2-byte nonce.
|
|
228
|
+
*/
|
|
236
229
|
MLD_INTERNAL_API
|
|
237
230
|
void mld_poly_uniform(mld_poly *a, const uint8_t seed[MLDSA_SEEDBYTES + 2])
|
|
238
231
|
__contract__(
|
|
@@ -242,21 +235,20 @@ __contract__(
|
|
|
242
235
|
ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
|
|
243
236
|
);
|
|
244
237
|
|
|
245
|
-
#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) &&
|
|
238
|
+
#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) && \
|
|
239
|
+
(!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST))
|
|
246
240
|
#define mld_poly_uniform_4x MLD_NAMESPACE(poly_uniform_4x)
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
|
|
258
|
-
*
|
|
259
|
-
**************************************************/
|
|
241
|
+
/**
|
|
242
|
+
* Generate four polynomials using rejection sampling on (pseudo-)uniformly
|
|
243
|
+
* random bytes sampled from a seed.
|
|
244
|
+
*
|
|
245
|
+
* @param[out] vec0 Pointer to first polynomial to be sampled.
|
|
246
|
+
* @param[out] vec1 Pointer to second polynomial to be sampled.
|
|
247
|
+
* @param[out] vec2 Pointer to third polynomial to be sampled.
|
|
248
|
+
* @param[out] vec3 Pointer to fourth polynomial to be sampled.
|
|
249
|
+
* @param[in] seed Pointer to consecutive array of seed buffers of size
|
|
250
|
+
* MLDSA_SEEDBYTES + 2 each, plus padding for alignment.
|
|
251
|
+
*/
|
|
260
252
|
MLD_INTERNAL_API
|
|
261
253
|
void mld_poly_uniform_4x(mld_poly *vec0, mld_poly *vec1, mld_poly *vec2,
|
|
262
254
|
mld_poly *vec3,
|
|
@@ -276,19 +268,19 @@ __contract__(
|
|
|
276
268
|
ensures(array_bound(vec2->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
|
|
277
269
|
ensures(array_bound(vec3->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
|
|
278
270
|
);
|
|
279
|
-
#endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY && !MLD_CONFIG_REDUCE_RAM
|
|
271
|
+
#endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY && (!MLD_CONFIG_REDUCE_RAM || \
|
|
272
|
+
MLD_UNIT_TEST) */
|
|
280
273
|
|
|
274
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
281
275
|
#define mld_polyt1_pack MLD_NAMESPACE(polyt1_pack)
|
|
282
|
-
|
|
283
|
-
*
|
|
276
|
+
/**
|
|
277
|
+
* Bit-pack polynomial t1 with coefficients fitting in 10 bits. Input
|
|
278
|
+
* coefficients are assumed to be standard representatives.
|
|
284
279
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
|
|
289
|
-
* MLDSA_POLYT1_PACKEDBYTES bytes
|
|
290
|
-
* - const mld_poly *a: pointer to input polynomial
|
|
291
|
-
**************************************************/
|
|
280
|
+
* @param[out] r Pointer to output byte array with at least
|
|
281
|
+
* MLDSA_POLYT1_PACKEDBYTES bytes.
|
|
282
|
+
* @param[in] a Pointer to input polynomial.
|
|
283
|
+
*/
|
|
292
284
|
MLD_INTERNAL_API
|
|
293
285
|
void mld_polyt1_pack(uint8_t r[MLDSA_POLYT1_PACKEDBYTES], const mld_poly *a)
|
|
294
286
|
__contract__(
|
|
@@ -297,17 +289,17 @@ __contract__(
|
|
|
297
289
|
requires(array_bound(a->coeffs, 0, MLDSA_N, 0, 1 << 10))
|
|
298
290
|
assigns(memory_slice(r, MLDSA_POLYT1_PACKEDBYTES))
|
|
299
291
|
);
|
|
292
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
300
293
|
|
|
294
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
301
295
|
#define mld_polyt1_unpack MLD_NAMESPACE(polyt1_unpack)
|
|
302
|
-
|
|
303
|
-
*
|
|
296
|
+
/**
|
|
297
|
+
* Unpack polynomial t1 with 10-bit coefficients. Output coefficients are
|
|
298
|
+
* standard representatives.
|
|
304
299
|
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
|
|
308
|
-
* Arguments: - mld_poly *r: pointer to output polynomial
|
|
309
|
-
* - const uint8_t *a: byte array with bit-packed polynomial
|
|
310
|
-
**************************************************/
|
|
300
|
+
* @param[out] r Pointer to output polynomial.
|
|
301
|
+
* @param[in] a Byte array with bit-packed polynomial.
|
|
302
|
+
*/
|
|
311
303
|
MLD_INTERNAL_API
|
|
312
304
|
void mld_polyt1_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYT1_PACKEDBYTES])
|
|
313
305
|
__contract__(
|
|
@@ -316,18 +308,17 @@ __contract__(
|
|
|
316
308
|
assigns(memory_slice(r, sizeof(mld_poly)))
|
|
317
309
|
ensures(array_bound(r->coeffs, 0, MLDSA_N, 0, 1 << 10))
|
|
318
310
|
);
|
|
311
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
319
312
|
|
|
313
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
320
314
|
#define mld_polyt0_pack MLD_NAMESPACE(polyt0_pack)
|
|
321
|
-
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* Description: Bit-pack polynomial t0 with coefficients in ]-2^{MLDSA_D-1},
|
|
325
|
-
* 2^{MLDSA_D-1}].
|
|
315
|
+
/**
|
|
316
|
+
* Bit-pack polynomial t0 with coefficients in ]-2^{MLDSA_D-1}, 2^{MLDSA_D-1}].
|
|
326
317
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
|
|
318
|
+
* @param[out] r Pointer to output byte array with at least
|
|
319
|
+
* MLDSA_POLYT0_PACKEDBYTES bytes.
|
|
320
|
+
* @param[in] a Pointer to input polynomial.
|
|
321
|
+
*/
|
|
331
322
|
MLD_INTERNAL_API
|
|
332
323
|
void mld_polyt0_pack(uint8_t r[MLDSA_POLYT0_PACKEDBYTES], const mld_poly *a)
|
|
333
324
|
__contract__(
|
|
@@ -336,18 +327,16 @@ __contract__(
|
|
|
336
327
|
requires(array_bound(a->coeffs, 0, MLDSA_N, -(1<<(MLDSA_D-1)) + 1, (1<<(MLDSA_D-1)) + 1))
|
|
337
328
|
assigns(memory_slice(r, MLDSA_POLYT0_PACKEDBYTES))
|
|
338
329
|
);
|
|
330
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
339
331
|
|
|
340
|
-
|
|
332
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API) || defined(MLD_UNIT_TEST)
|
|
341
333
|
#define mld_polyt0_unpack MLD_NAMESPACE(polyt0_unpack)
|
|
342
|
-
|
|
343
|
-
*
|
|
334
|
+
/**
|
|
335
|
+
* Unpack polynomial t0 with coefficients in ]-2^{MLDSA_D-1}, 2^{MLDSA_D-1}].
|
|
344
336
|
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
|
|
348
|
-
* Arguments: - mld_poly *r: pointer to output polynomial
|
|
349
|
-
* - const uint8_t *a: byte array with bit-packed polynomial
|
|
350
|
-
**************************************************/
|
|
337
|
+
* @param[out] r Pointer to output polynomial.
|
|
338
|
+
* @param[in] a Byte array with bit-packed polynomial.
|
|
339
|
+
*/
|
|
351
340
|
MLD_INTERNAL_API
|
|
352
341
|
void mld_polyt0_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYT0_PACKEDBYTES])
|
|
353
342
|
__contract__(
|
|
@@ -356,29 +345,25 @@ __contract__(
|
|
|
356
345
|
assigns(memory_slice(r, sizeof(mld_poly)))
|
|
357
346
|
ensures(array_bound(r->coeffs, 0, MLDSA_N, -(1<<(MLDSA_D-1)) + 1, (1<<(MLDSA_D-1)) + 1))
|
|
358
347
|
);
|
|
348
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API || MLD_UNIT_TEST */
|
|
359
349
|
|
|
360
350
|
#define mld_poly_chknorm MLD_NAMESPACE(poly_chknorm)
|
|
361
|
-
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* Description: Check infinity norm of polynomial against given bound.
|
|
365
|
-
* Assumes input coefficients were reduced by mld_reduce32().
|
|
351
|
+
/**
|
|
352
|
+
* Check infinity norm of polynomial against given bound. Assumes input
|
|
353
|
+
* coefficients were reduced by mld_reduce32().
|
|
366
354
|
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
355
|
+
* @spec{The definition in FIPS-204 requires signed canonical reduction prior
|
|
356
|
+
* to applying the bounds check. However, `-B < (a mod± MLDSA_Q) < B` is
|
|
357
|
+
* equivalent to `-B < a < B` under the assumption that
|
|
358
|
+
* `B <= MLDSA_Q - MLD_REDUCE32_RANGE_MAX` (cf. the assertion in the code).
|
|
359
|
+
* Hence, the present spec and implementation are correct without reduction.}
|
|
369
360
|
*
|
|
370
|
-
*
|
|
371
|
-
* B
|
|
361
|
+
* @param[in] a Pointer to polynomial.
|
|
362
|
+
* @param B Norm bound.
|
|
372
363
|
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
|
|
376
|
-
* `-B < a < B` under the assumption that
|
|
377
|
-
* `B <= MLDSA_Q - MLD_REDUCE32_RANGE_MAX` (cf. the assertion in
|
|
378
|
-
* the code). Hence, the present spec and implementation are
|
|
379
|
-
* correct without reduction.
|
|
380
|
-
*
|
|
381
|
-
**************************************************/
|
|
364
|
+
* @return 0 if norm is strictly smaller than
|
|
365
|
+
* B <= (MLDSA_Q - MLD_REDUCE32_RANGE_MAX) and 0xFFFFFFFF otherwise.
|
|
366
|
+
*/
|
|
382
367
|
MLD_INTERNAL_API
|
|
383
368
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
384
369
|
uint32_t mld_poly_chknorm(const mld_poly *a, int32_t B)
|