@@ -117,11 +117,17 @@ pub(crate) fn mat_vec_mul<const K: usize, const L: usize>(
117
117
w_hat
118
118
}
119
119
120
- // Algorithm 44: `AddNTT()` and Algorithm 46 `AddVectorNTT()`
121
- /// Vector addition; e.g., fips 203 bottom of page 9, second row: `z_hat` = `u_hat` + `v_hat`
120
+
121
+ // Note Algorithm 44 has been dissolved into its place of use(s)
122
+
123
+ /// Algorithm 46: `AddVectorNTT(v_hat, w_hat)` on page 45.
124
+ /// Computes the sum `v_hat + w_hat` of two vectors `v_hat`, `w_hat` over `𝑇_𝑞`.
125
+ ///
126
+ /// **Input**: `ℓ ∈ ℕ, v_hat ∈ 𝑇_𝑞^ℓ , w_hat ∈ 𝑇_𝑞^ℓ`. <br>
127
+ /// **Output**: `u_hat ∈ 𝑇_𝑞^ℓ`.
122
128
#[ must_use]
123
- pub ( crate ) fn add_vector_ntt < const K : usize > ( vec_a : & [ R ; K ] , vec_b : & [ R ; K ] ) -> [ R ; K ] {
124
- core:: array:: from_fn ( |k| R ( core:: array:: from_fn ( |n| vec_a [ k] . 0 [ n] + vec_b [ k] . 0 [ n] ) ) )
129
+ pub ( crate ) fn add_vector_ntt < const K : usize > ( v_hat : & [ R ; K ] , w_hat : & [ R ; K ] ) -> [ R ; K ] {
130
+ core:: array:: from_fn ( |k| R ( core:: array:: from_fn ( |n| v_hat [ k] . 0 [ n] + w_hat [ k] . 0 [ n] ) ) )
125
131
}
126
132
127
133
@@ -145,6 +151,11 @@ pub(crate) fn infinity_norm<const ROW: usize>(w: &[R; ROW]) -> i32 {
145
151
}
146
152
147
153
154
+ /// Algorithm 49: MontgomeryReduce(𝑎) on page 50.
155
+ /// Computes 𝑎 ⋅ 2−32 mod 𝑞.
156
+ ///
157
+ /// **Input**: Integer 𝑎 with −231 𝑞 ≤ 𝑎 ≤ 231 𝑞.
158
+ /// **Output**: 𝑟 ≡ 𝑎 ⋅ 2−32 mod 𝑞.
148
159
#[ allow( clippy:: cast_possible_truncation) ] // a as i32, res as i32
149
160
pub ( crate ) const fn mont_reduce ( a : i64 ) -> i32 {
150
161
const QINV : i32 = 58_728_449 ; // (Q * QINV) % 2**32 = 1
0 commit comments