@@ -18,7 +18,7 @@ use crate::polyfill::prelude::*;
1818use super :: {
1919 super :: { montgomery:: * , MAX_LIMBS } ,
2020 boxed_limbs:: BoxedLimbs ,
21- unwrap_impossible_len_mismatch_error, unwrap_impossible_limb_slice_error, Modulus , Uninit ,
21+ unwrap_impossible_len_mismatch_error, unwrap_impossible_limb_slice_error, Mont , Uninit ,
2222} ;
2323use crate :: {
2424 bits:: BitLength ,
@@ -98,10 +98,7 @@ impl<M, E> Elem<M, E> {
9898/// fully reduced mod `m`.
9999///
100100/// WARNING: Takes a `Storage` as an in/out value.
101- pub ( super ) fn from_montgomery_amm < M > (
102- mut in_out : BoxedLimbs < M > ,
103- m : & Modulus < M > ,
104- ) -> Elem < M , Unencoded > {
101+ pub ( super ) fn from_montgomery_amm < M > ( mut in_out : BoxedLimbs < M > , m : & Mont < M > ) -> Elem < M , Unencoded > {
105102 let mut one = [ 0 ; MAX_LIMBS ] ;
106103 one[ 0 ] = 1 ;
107104 let one = & one[ ..m. limbs ( ) . len ( ) ] ;
@@ -118,7 +115,7 @@ pub(super) fn from_montgomery_amm<M>(
118115#[ cfg( any( test, not( target_arch = "x86_64" ) ) ) ]
119116impl < M > Elem < M , R > {
120117 #[ inline]
121- pub fn into_unencoded ( self , m : & Modulus < M > ) -> Elem < M , Unencoded > {
118+ pub fn into_unencoded ( self , m : & Mont < M > ) -> Elem < M , Unencoded > {
122119 from_montgomery_amm ( self . limbs , m)
123120 }
124121}
@@ -135,7 +132,7 @@ pub fn elem_mul_into<M, AF, BF>(
135132 out : Uninit < M > ,
136133 a : & Elem < M , AF > ,
137134 b : & Elem < M , BF > ,
138- m : & Modulus < M > ,
135+ m : & Mont < M > ,
139136) -> Result < Elem < M , <( AF , BF ) as ProductEncoding >:: Output > , LenMismatchError >
140137where
141138 ( AF , BF ) : ProductEncoding ,
@@ -156,7 +153,7 @@ where
156153pub fn elem_mul < M , AF , BF > (
157154 a : & Elem < M , AF > ,
158155 b : Elem < M , BF > ,
159- m : & Modulus < M > ,
156+ m : & Mont < M > ,
160157) -> Elem < M , <( AF , BF ) as ProductEncoding >:: Output >
161158where
162159 ( AF , BF ) : ProductEncoding ,
@@ -173,7 +170,7 @@ where
173170}
174171
175172// r *= 2.
176- pub fn elem_double < M , AF > ( r : & mut Elem < M , AF > , m : & Modulus < M > ) {
173+ pub fn elem_double < M , AF > ( r : & mut Elem < M , AF > , m : & Mont < M > ) {
177174 limb:: limbs_double_mod ( r. limbs . as_mut ( ) , m. limbs ( ) )
178175 . unwrap_or_else ( unwrap_impossible_len_mismatch_error)
179176}
@@ -185,7 +182,7 @@ pub fn elem_double<M, AF>(r: &mut Elem<M, AF>, m: &Modulus<M>) {
185182pub fn elem_reduced_once < A , M > (
186183 r : Uninit < M > ,
187184 a : & Elem < A , Unencoded > ,
188- m : & Modulus < M > ,
185+ m : & Mont < M > ,
189186 other_modulus_len_bits : BitLength ,
190187) -> Elem < M , Unencoded > {
191188 assert_eq ! ( m. len_bits( ) , other_modulus_len_bits) ;
@@ -203,7 +200,7 @@ pub fn elem_reduced_once<A, M>(
203200pub fn elem_reduced < Larger , Smaller > (
204201 r : Uninit < Smaller > ,
205202 a : & Elem < Larger , Unencoded > ,
206- m : & Modulus < Smaller > ,
203+ m : & Mont < Smaller > ,
207204 other_prime_len_bits : BitLength ,
208205) -> Elem < Smaller , RInverse > {
209206 // This is stricter than required mathematically but this is what we
@@ -227,7 +224,7 @@ pub fn elem_reduced<Larger, Smaller>(
227224#[ inline]
228225pub fn elem_squared < M , E > (
229226 a : Elem < M , E > ,
230- m : & Modulus < M > ,
227+ m : & Mont < M > ,
231228) -> Elem < M , <( E , E ) as ProductEncoding >:: Output >
232229where
233230 ( E , E ) : ProductEncoding ,
@@ -241,7 +238,7 @@ where
241238pub fn elem_widen < Larger , Smaller > (
242239 r : Uninit < Larger > ,
243240 a : Elem < Smaller , Unencoded > ,
244- m : & Modulus < Larger > ,
241+ m : & Mont < Larger > ,
245242 smaller_modulus_bits : BitLength ,
246243) -> Result < Elem < Larger , Unencoded > , error:: Unspecified > {
247244 if smaller_modulus_bits >= m. len_bits ( ) {
@@ -254,14 +251,14 @@ pub fn elem_widen<Larger, Smaller>(
254251}
255252
256253// TODO: Document why this works for all Montgomery factors.
257- pub fn elem_add < M , E > ( mut a : Elem < M , E > , b : Elem < M , E > , m : & Modulus < M > ) -> Elem < M , E > {
254+ pub fn elem_add < M , E > ( mut a : Elem < M , E > , b : Elem < M , E > , m : & Mont < M > ) -> Elem < M , E > {
258255 limb:: limbs_add_assign_mod ( a. limbs . as_mut ( ) , b. limbs . as_ref ( ) , m. limbs ( ) )
259256 . unwrap_or_else ( unwrap_impossible_len_mismatch_error) ;
260257 a
261258}
262259
263260// TODO: Document why this works for all Montgomery factors.
264- pub fn elem_sub < M , E > ( mut a : Elem < M , E > , b : & Elem < M , E > , m : & Modulus < M > ) -> Elem < M , E > {
261+ pub fn elem_sub < M , E > ( mut a : Elem < M , E > , b : & Elem < M , E > , m : & Mont < M > ) -> Elem < M , E > {
265262 prefixed_extern ! {
266263 // `r` and `a` may alias.
267264 fn LIMBS_sub_mod (
@@ -289,7 +286,7 @@ pub fn elem_sub<M, E>(mut a: Elem<M, E>, b: &Elem<M, E>, m: &Modulus<M>) -> Elem
289286pub fn verify_inverses_consttime < M > (
290287 a : & Elem < M , R > ,
291288 b : Elem < M , Unencoded > ,
292- m : & Modulus < M > ,
289+ m : & Mont < M > ,
293290) -> Result < ( ) , error:: Unspecified > {
294291 let r = elem_mul ( a, b, m) ;
295292 limb:: verify_limbs_equal_1_leak_bit ( r. limbs . as_ref ( ) )
@@ -317,7 +314,7 @@ pub mod testutil {
317314 pub fn consume_elem < M > (
318315 test_case : & mut crate :: testutil:: TestCase ,
319316 name : & str ,
320- m : & Modulus < M > ,
317+ m : & Mont < M > ,
321318 ) -> Elem < M , Unencoded > {
322319 let value = test_case. consume_bytes ( name) ;
323320 m. alloc_uninit ( )
0 commit comments