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
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
#define MLD_REDUCE32_RANGE_MAX 6283009
|
|
58
58
|
/*
|
|
59
59
|
* This is the C<->native interface allowing for the drop-in of
|
|
60
|
-
* native code for performance
|
|
60
|
+
* native code for performance-critical arithmetic components of ML-DSA.
|
|
61
61
|
*
|
|
62
62
|
* A _backend_ is a specific implementation of (part of) this interface.
|
|
63
63
|
*
|
|
@@ -73,17 +73,15 @@
|
|
|
73
73
|
*/
|
|
74
74
|
|
|
75
75
|
#if defined(MLD_USE_NATIVE_NTT)
|
|
76
|
-
|
|
77
|
-
*
|
|
76
|
+
/**
|
|
77
|
+
* Computes negacyclic number-theoretic transform (NTT) of a polynomial
|
|
78
|
+
* in place.
|
|
78
79
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
80
|
+
* The input polynomial is assumed to be in normal order. The output
|
|
81
|
+
* polynomial is in bitreversed order.
|
|
81
82
|
*
|
|
82
|
-
*
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
* Arguments: - int32_t p[MLDSA_N]: pointer to in/output polynomial
|
|
86
|
-
**************************************************/
|
|
83
|
+
* @param[in,out] p Pointer to in/output polynomial.
|
|
84
|
+
*/
|
|
87
85
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
88
86
|
static MLD_INLINE int mld_ntt_native(int32_t p[MLDSA_N])
|
|
89
87
|
__contract__(
|
|
@@ -109,19 +107,16 @@ __contract__(
|
|
|
109
107
|
set if there are native implementations for NTT and INTT."
|
|
110
108
|
#endif
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* convert a polynomial in NTT domain from bitreversed
|
|
117
|
-
* order to the custom order output by the native NTT.
|
|
110
|
+
/**
|
|
111
|
+
* When MLD_USE_NATIVE_NTT_CUSTOM_ORDER is defined, convert a polynomial in
|
|
112
|
+
* NTT domain from bitreversed order to the custom order output by the native
|
|
113
|
+
* NTT.
|
|
118
114
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
115
|
+
* This must only be defined if there is native code for both the NTT and
|
|
116
|
+
* INTT.
|
|
121
117
|
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
**************************************************/
|
|
118
|
+
* @param[in,out] p Pointer to in/output polynomial.
|
|
119
|
+
*/
|
|
125
120
|
static MLD_INLINE void mld_poly_permute_bitrev_to_custom(int32_t p[MLDSA_N])
|
|
126
121
|
__contract__(
|
|
127
122
|
/* We don't specify that this should be a permutation, but only
|
|
@@ -136,17 +131,15 @@ __contract__(
|
|
|
136
131
|
|
|
137
132
|
|
|
138
133
|
#if defined(MLD_USE_NATIVE_INTT)
|
|
139
|
-
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* Description: Computes inverse of negacyclic number-theoretic transform
|
|
143
|
-
*(NTT) of a polynomial in place.
|
|
134
|
+
/**
|
|
135
|
+
* Computes inverse of negacyclic number-theoretic transform (NTT) of a
|
|
136
|
+
* polynomial in place.
|
|
144
137
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
138
|
+
* The input polynomial is in bitreversed order. The output polynomial is
|
|
139
|
+
* assumed to be in normal order.
|
|
147
140
|
*
|
|
148
|
-
*
|
|
149
|
-
|
|
141
|
+
* @param[in,out] p Pointer to in/output polynomial.
|
|
142
|
+
*/
|
|
150
143
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
151
144
|
static MLD_INLINE int mld_intt_native(int32_t p[MLDSA_N])
|
|
152
145
|
__contract__(
|
|
@@ -161,23 +154,22 @@ __contract__(
|
|
|
161
154
|
#endif /* MLD_USE_NATIVE_INTT */
|
|
162
155
|
|
|
163
156
|
#if defined(MLD_USE_NATIVE_REJ_UNIFORM)
|
|
164
|
-
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
**************************************************/
|
|
157
|
+
/**
|
|
158
|
+
* Run rejection sampling on uniform random bytes to generate uniform random
|
|
159
|
+
* integers in [0, MLDSA_Q-1].
|
|
160
|
+
*
|
|
161
|
+
* @param[out] r Pointer to output buffer.
|
|
162
|
+
* @param len Requested number of 32-bit integers (uniform mod
|
|
163
|
+
* MLDSA_Q).
|
|
164
|
+
* @param[in] buf Pointer to input buffer (assumed to be uniform random
|
|
165
|
+
* bytes).
|
|
166
|
+
* @param buflen Length of input buffer in bytes.
|
|
167
|
+
*
|
|
168
|
+
* @return - MLD_NATIVE_FUNC_FALLBACK if the native implementation does not
|
|
169
|
+
* support the input lengths.
|
|
170
|
+
* - Otherwise, the non-negative number of sampled 32-bit integers
|
|
171
|
+
* (at most len).
|
|
172
|
+
*/
|
|
181
173
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
182
174
|
static MLD_INLINE int mld_rej_uniform_native(int32_t *r, unsigned len,
|
|
183
175
|
const uint8_t *buf,
|
|
@@ -193,25 +185,25 @@ __contract__(
|
|
|
193
185
|
);
|
|
194
186
|
#endif /* MLD_USE_NATIVE_REJ_UNIFORM */
|
|
195
187
|
|
|
188
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
196
189
|
#if defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2)
|
|
197
190
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 2
|
|
198
|
-
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
|
|
214
|
-
**************************************************/
|
|
191
|
+
/**
|
|
192
|
+
* Run rejection sampling on uniform random bytes to generate uniform random
|
|
193
|
+
* integers in [-2, +2].
|
|
194
|
+
*
|
|
195
|
+
* @param[out] r Pointer to output buffer.
|
|
196
|
+
* @param len Requested number of 32-bit integers (uniform in
|
|
197
|
+
* [-2, +2]).
|
|
198
|
+
* @param[in] buf Pointer to input buffer (assumed to be uniform random
|
|
199
|
+
* bytes).
|
|
200
|
+
* @param buflen Length of input buffer in bytes.
|
|
201
|
+
*
|
|
202
|
+
* @return - MLD_NATIVE_FUNC_FALLBACK if the native implementation does not
|
|
203
|
+
* support the input lengths.
|
|
204
|
+
* - Otherwise, the non-negative number of sampled 32-bit integers
|
|
205
|
+
* (at most len).
|
|
206
|
+
*/
|
|
215
207
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
216
208
|
static MLD_INLINE int mld_rej_uniform_eta2_native(int32_t *r, unsigned len,
|
|
217
209
|
const uint8_t *buf,
|
|
@@ -230,23 +222,22 @@ __contract__(
|
|
|
230
222
|
|
|
231
223
|
#if defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4)
|
|
232
224
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 4
|
|
233
|
-
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
|
|
249
|
-
**************************************************/
|
|
225
|
+
/**
|
|
226
|
+
* Run rejection sampling on uniform random bytes to generate uniform random
|
|
227
|
+
* integers in [-4, +4].
|
|
228
|
+
*
|
|
229
|
+
* @param[out] r Pointer to output buffer.
|
|
230
|
+
* @param len Requested number of 32-bit integers (uniform in
|
|
231
|
+
* [-4, +4]).
|
|
232
|
+
* @param[in] buf Pointer to input buffer (assumed to be uniform random
|
|
233
|
+
* bytes).
|
|
234
|
+
* @param buflen Length of input buffer in bytes.
|
|
235
|
+
*
|
|
236
|
+
* @return - MLD_NATIVE_FUNC_FALLBACK if the native implementation does not
|
|
237
|
+
* support the input lengths.
|
|
238
|
+
* - Otherwise, the non-negative number of sampled 32-bit integers
|
|
239
|
+
* (at most len).
|
|
240
|
+
*/
|
|
250
241
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
251
242
|
static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len,
|
|
252
243
|
const uint8_t *buf,
|
|
@@ -262,26 +253,24 @@ __contract__(
|
|
|
262
253
|
);
|
|
263
254
|
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 4 */
|
|
264
255
|
#endif /* MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
|
|
256
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
265
257
|
|
|
258
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
266
259
|
#if defined(MLD_USE_NATIVE_POLY_DECOMPOSE_32)
|
|
267
260
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
|
|
268
261
|
(MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
|
|
281
|
-
* Arguments: - int32_t *a1: output polynomial with coefficients c1
|
|
282
|
-
* - int32_t *a0: input/output polynomial.
|
|
283
|
-
* Output has coefficients c0
|
|
284
|
-
**************************************************/
|
|
262
|
+
/**
|
|
263
|
+
* Native implementation of poly_decompose for GAMMA2 = (MLDSA_Q-1)/32.
|
|
264
|
+
*
|
|
265
|
+
* For all coefficients c of the input polynomial, compute high and low bits
|
|
266
|
+
* c0, c1 such c mod MLDSA_Q = c1*(2*GAMMA2) + c0 with
|
|
267
|
+
* -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except c1 = (MLDSA_Q-1)/(2*GAMMA2) where
|
|
268
|
+
* we set c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
|
|
269
|
+
* Assumes coefficients to be standard representatives.
|
|
270
|
+
*
|
|
271
|
+
* @param[out] a1 Output polynomial with coefficients c1.
|
|
272
|
+
* @param[in,out] a0 Input/output polynomial. Output has coefficients c0.
|
|
273
|
+
*/
|
|
285
274
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
286
275
|
static MLD_INLINE int mld_poly_decompose_32_native(int32_t *a1, int32_t *a0)
|
|
287
276
|
__contract__(
|
|
@@ -302,22 +291,18 @@ __contract__(
|
|
|
302
291
|
|
|
303
292
|
#if defined(MLD_USE_NATIVE_POLY_DECOMPOSE_88)
|
|
304
293
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
|
|
305
|
-
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
|
|
317
|
-
* Arguments: - int32_t *a1: output polynomial with coefficients c1
|
|
318
|
-
* - int32_t *a0: output polynomial with coefficients c0.
|
|
319
|
-
* Output has coefficients c0
|
|
320
|
-
**************************************************/
|
|
294
|
+
/**
|
|
295
|
+
* Native implementation of poly_decompose for GAMMA2 = (MLDSA_Q-1)/88.
|
|
296
|
+
*
|
|
297
|
+
* For all coefficients c of the input polynomial, compute high and low bits
|
|
298
|
+
* c0, c1 such c mod MLDSA_Q = c1*(2*GAMMA2) + c0 with
|
|
299
|
+
* -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except c1 = (MLDSA_Q-1)/(2*GAMMA2) where
|
|
300
|
+
* we set c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
|
|
301
|
+
* Assumes coefficients to be standard representatives.
|
|
302
|
+
*
|
|
303
|
+
* @param[out] a1 Output polynomial with coefficients c1.
|
|
304
|
+
* @param[in,out] a0 Input/output polynomial. Output has coefficients c0.
|
|
305
|
+
*/
|
|
321
306
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
322
307
|
static MLD_INLINE int mld_poly_decompose_88_native(int32_t *a1, int32_t *a0)
|
|
323
308
|
__contract__(
|
|
@@ -335,16 +320,14 @@ __contract__(
|
|
|
335
320
|
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
|
|
336
321
|
*/
|
|
337
322
|
#endif /* MLD_USE_NATIVE_POLY_DECOMPOSE_88 */
|
|
323
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
338
324
|
|
|
339
325
|
#if defined(MLD_USE_NATIVE_POLY_CADDQ)
|
|
340
|
-
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* Description: For all coefficients of in/out polynomial add Q if
|
|
344
|
-
* coefficient is negative.
|
|
326
|
+
/**
|
|
327
|
+
* For all coefficients of in/out polynomial add Q if coefficient is negative.
|
|
345
328
|
*
|
|
346
|
-
*
|
|
347
|
-
|
|
329
|
+
* @param[in,out] a Pointer to input/output polynomial.
|
|
330
|
+
*/
|
|
348
331
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
349
332
|
static MLD_INLINE int mld_poly_caddq_native(int32_t a[MLDSA_N])
|
|
350
333
|
__contract__(
|
|
@@ -358,33 +341,29 @@ __contract__(
|
|
|
358
341
|
);
|
|
359
342
|
#endif /* MLD_USE_NATIVE_POLY_CADDQ */
|
|
360
343
|
|
|
344
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
361
345
|
#if defined(MLD_USE_NATIVE_POLY_USE_HINT_32)
|
|
362
346
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
|
|
363
347
|
(MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
|
|
364
|
-
|
|
365
|
-
*
|
|
348
|
+
/**
|
|
349
|
+
* Native implementation of poly_use_hint for GAMMA2 = (MLDSA_Q-1)/32.
|
|
366
350
|
*
|
|
367
|
-
*
|
|
368
|
-
* Use hint polynomial to correct the high bits of a polynomial.
|
|
351
|
+
* Use hint h to correct the high bits of a in-place.
|
|
369
352
|
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
|
|
373
|
-
* - const int32_t *h: pointer to input hint polynomial
|
|
374
|
-
**************************************************/
|
|
353
|
+
* @param[in,out] a Input/output polynomial.
|
|
354
|
+
* @param[in] h Hint polynomial.
|
|
355
|
+
*/
|
|
375
356
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
376
|
-
static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *
|
|
377
|
-
const int32_t *h)
|
|
357
|
+
static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *a, const int32_t *h)
|
|
378
358
|
__contract__(
|
|
379
359
|
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
380
|
-
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
|
|
381
360
|
requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
|
|
382
361
|
requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
|
|
383
362
|
requires(array_bound(h, 0, MLDSA_N, 0, 2))
|
|
384
|
-
assigns(memory_slice(
|
|
363
|
+
assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
|
|
385
364
|
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
386
|
-
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(
|
|
387
|
-
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(
|
|
365
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
|
|
366
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a, MLDSA_N))
|
|
388
367
|
);
|
|
389
368
|
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
|
|
390
369
|
|| MLD_CONFIG_PARAMETER_SET == 87 */
|
|
@@ -392,54 +371,46 @@ __contract__(
|
|
|
392
371
|
|
|
393
372
|
#if defined(MLD_USE_NATIVE_POLY_USE_HINT_88)
|
|
394
373
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
|
|
395
|
-
|
|
396
|
-
*
|
|
374
|
+
/**
|
|
375
|
+
* Native implementation of poly_use_hint for GAMMA2 = (MLDSA_Q-1)/88.
|
|
397
376
|
*
|
|
398
|
-
*
|
|
399
|
-
* Use hint polynomial to correct the high bits of a polynomial.
|
|
377
|
+
* Use hint h to correct the high bits of a in-place.
|
|
400
378
|
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
|
|
404
|
-
* - const int32_t *h: pointer to input hint polynomial
|
|
405
|
-
**************************************************/
|
|
379
|
+
* @param[in,out] a Input/output polynomial.
|
|
380
|
+
* @param[in] h Hint polynomial.
|
|
381
|
+
*/
|
|
406
382
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
407
|
-
static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *
|
|
408
|
-
const int32_t *h)
|
|
383
|
+
static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *a, const int32_t *h)
|
|
409
384
|
__contract__(
|
|
410
385
|
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
411
|
-
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
|
|
412
386
|
requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
|
|
413
387
|
requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
|
|
414
388
|
requires(array_bound(h, 0, MLDSA_N, 0, 2))
|
|
415
|
-
assigns(memory_slice(
|
|
389
|
+
assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
|
|
416
390
|
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
417
|
-
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(
|
|
418
|
-
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(
|
|
391
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
|
|
392
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a, MLDSA_N))
|
|
419
393
|
);
|
|
420
394
|
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
|
|
421
395
|
*/
|
|
422
396
|
#endif /* MLD_USE_NATIVE_POLY_USE_HINT_88 */
|
|
397
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
423
398
|
|
|
424
399
|
#if defined(MLD_USE_NATIVE_POLY_CHKNORM)
|
|
425
|
-
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
|
|
439
|
-
* Returns MLD_NATIVE_FUNC_SUCCESS (0) if the infinity norm is strictly
|
|
440
|
-
* smaller than B
|
|
441
|
-
* Returns 1 otherwise
|
|
442
|
-
**************************************************/
|
|
400
|
+
/**
|
|
401
|
+
* Check infinity norm of polynomial against given bound. Assumes input
|
|
402
|
+
* coefficients were reduced by mld_reduce32().
|
|
403
|
+
*
|
|
404
|
+
* @param[in] a Pointer to polynomial.
|
|
405
|
+
* @param B Norm bound, which must be in the range
|
|
406
|
+
* 0 .. MLDSA_Q - MLD_REDUCE32_RANGE_MAX inclusive.
|
|
407
|
+
*
|
|
408
|
+
* @return - MLD_NATIVE_FUNC_FALLBACK if the target CPU cannot support a
|
|
409
|
+
* native implementation of this function.
|
|
410
|
+
* - MLD_NATIVE_FUNC_SUCCESS if the infinity norm is strictly smaller
|
|
411
|
+
* than B.
|
|
412
|
+
* - 1 otherwise.
|
|
413
|
+
*/
|
|
443
414
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
444
415
|
static MLD_INLINE int mld_poly_chknorm_native(const int32_t *a, int32_t B)
|
|
445
416
|
__contract__(
|
|
@@ -453,18 +424,18 @@ __contract__(
|
|
|
453
424
|
);
|
|
454
425
|
#endif /* MLD_USE_NATIVE_POLY_CHKNORM */
|
|
455
426
|
|
|
427
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
456
428
|
#if defined(MLD_USE_NATIVE_POLYZ_UNPACK_17)
|
|
457
429
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
|
|
458
|
-
|
|
459
|
-
*
|
|
430
|
+
/**
|
|
431
|
+
* Native implementation of polyz_unpack for GAMMA1 = 2^17.
|
|
460
432
|
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
|
|
433
|
+
* Unpack polynomial z with coefficients in
|
|
434
|
+
* [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
|
|
464
435
|
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
|
|
436
|
+
* @param[out] r Pointer to output polynomial.
|
|
437
|
+
* @param[in] a Byte array with bit-packed polynomial.
|
|
438
|
+
*/
|
|
468
439
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
469
440
|
static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a)
|
|
470
441
|
__contract__(
|
|
@@ -482,16 +453,15 @@ __contract__(
|
|
|
482
453
|
#if defined(MLD_USE_NATIVE_POLYZ_UNPACK_19)
|
|
483
454
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
|
|
484
455
|
(MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
|
|
485
|
-
|
|
486
|
-
*
|
|
456
|
+
/**
|
|
457
|
+
* Native implementation of polyz_unpack for GAMMA1 = 2^19.
|
|
487
458
|
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
* in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
|
|
459
|
+
* Unpack polynomial z with coefficients in
|
|
460
|
+
* [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
|
|
491
461
|
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
|
|
462
|
+
* @param[out] r Pointer to output polynomial.
|
|
463
|
+
* @param[in] a Byte array with bit-packed polynomial.
|
|
464
|
+
*/
|
|
495
465
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
496
466
|
static MLD_INLINE int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *a)
|
|
497
467
|
__contract__(
|
|
@@ -505,55 +475,51 @@ __contract__(
|
|
|
505
475
|
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
|
|
506
476
|
|| MLD_CONFIG_PARAMETER_SET == 87 */
|
|
507
477
|
#endif /* MLD_USE_NATIVE_POLYZ_UNPACK_19 */
|
|
478
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
|
|
508
479
|
|
|
480
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
|
|
481
|
+
defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
|
|
509
482
|
#if defined(MLD_USE_NATIVE_POINTWISE_MONTGOMERY)
|
|
510
|
-
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
* Description: Pointwise multiplication of polynomials in NTT domain
|
|
514
|
-
* with Montgomery reduction.
|
|
483
|
+
/**
|
|
484
|
+
* Pointwise multiplication of polynomials in NTT domain with Montgomery
|
|
485
|
+
* reduction. Destructive in the first argument.
|
|
515
486
|
*
|
|
516
|
-
*
|
|
517
|
-
* where R = 2^32.
|
|
487
|
+
* Computes a[i] = a[i] * b[i] * R^(-1) mod MLDSA_Q for all i, where R = 2^32.
|
|
518
488
|
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
|
|
522
|
-
**************************************************/
|
|
489
|
+
* @param[in,out] a First input/output polynomial.
|
|
490
|
+
* @param[in] b Second input polynomial.
|
|
491
|
+
*/
|
|
523
492
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
524
493
|
static MLD_INLINE int mld_poly_pointwise_montgomery_native(
|
|
525
|
-
int32_t
|
|
494
|
+
int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
|
|
526
495
|
__contract__(
|
|
527
496
|
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
528
497
|
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
|
|
529
|
-
requires(memory_no_alias(c, sizeof(int32_t) * MLDSA_N))
|
|
530
498
|
requires(array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
531
499
|
requires(array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
532
|
-
assigns(memory_slice(
|
|
500
|
+
assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
|
|
533
501
|
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
534
|
-
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(
|
|
502
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
|
|
535
503
|
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
536
504
|
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
537
|
-
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(c, MLDSA_N))
|
|
538
505
|
);
|
|
539
506
|
#endif /* MLD_USE_NATIVE_POINTWISE_MONTGOMERY */
|
|
507
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
|
|
508
|
+
MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
|
|
540
509
|
|
|
541
510
|
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4)
|
|
542
511
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 4
|
|
543
|
-
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
|
|
554
|
-
* - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
|
|
555
|
-
* - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
|
|
556
|
-
**************************************************/
|
|
512
|
+
/**
|
|
513
|
+
* Native implementation of polyvecl_pointwise_acc_montgomery for MLDSA_L = 4.
|
|
514
|
+
*
|
|
515
|
+
* Pointwise multiply vectors of polynomials of length MLDSA_L, multiply
|
|
516
|
+
* resulting vector by 2^{-32} and add (accumulate) polynomials in it.
|
|
517
|
+
* Input/output vectors are in NTT domain representation.
|
|
518
|
+
*
|
|
519
|
+
* @param[out] w Output polynomial.
|
|
520
|
+
* @param[in] u First input vector.
|
|
521
|
+
* @param[in] v Second input vector.
|
|
522
|
+
*/
|
|
557
523
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
558
524
|
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l4_native(
|
|
559
525
|
int32_t w[MLDSA_N], const int32_t u[4][MLDSA_N],
|
|
@@ -576,20 +542,17 @@ __contract__(
|
|
|
576
542
|
|
|
577
543
|
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5)
|
|
578
544
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 5
|
|
579
|
-
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
|
|
590
|
-
* - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
|
|
591
|
-
* - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
|
|
592
|
-
**************************************************/
|
|
545
|
+
/**
|
|
546
|
+
* Native implementation of polyvecl_pointwise_acc_montgomery for MLDSA_L = 5.
|
|
547
|
+
*
|
|
548
|
+
* Pointwise multiply vectors of polynomials of length MLDSA_L, multiply
|
|
549
|
+
* resulting vector by 2^{-32} and add (accumulate) polynomials in it.
|
|
550
|
+
* Input/output vectors are in NTT domain representation.
|
|
551
|
+
*
|
|
552
|
+
* @param[out] w Output polynomial.
|
|
553
|
+
* @param[in] u First input vector.
|
|
554
|
+
* @param[in] v Second input vector.
|
|
555
|
+
*/
|
|
593
556
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
594
557
|
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l5_native(
|
|
595
558
|
int32_t w[MLDSA_N], const int32_t u[5][MLDSA_N],
|
|
@@ -612,20 +575,17 @@ __contract__(
|
|
|
612
575
|
|
|
613
576
|
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7)
|
|
614
577
|
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 7
|
|
615
|
-
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
|
|
626
|
-
* - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
|
|
627
|
-
* - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
|
|
628
|
-
**************************************************/
|
|
578
|
+
/**
|
|
579
|
+
* Native implementation of polyvecl_pointwise_acc_montgomery for MLDSA_L = 7.
|
|
580
|
+
*
|
|
581
|
+
* Pointwise multiply vectors of polynomials of length MLDSA_L, multiply
|
|
582
|
+
* resulting vector by 2^{-32} and add (accumulate) polynomials in it.
|
|
583
|
+
* Input/output vectors are in NTT domain representation.
|
|
584
|
+
*
|
|
585
|
+
* @param[out] w Output polynomial.
|
|
586
|
+
* @param[in] u First input vector.
|
|
587
|
+
* @param[in] v Second input vector.
|
|
588
|
+
*/
|
|
629
589
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
630
590
|
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l7_native(
|
|
631
591
|
int32_t w[MLDSA_N], const int32_t u[7][MLDSA_N],
|