@@ -114,7 +114,7 @@ impl Modulus {
114114 #[ must_use]
115115 pub const unsafe fn add_vt ( & self , a : u64 , b : u64 ) -> u64 {
116116 debug_assert ! ( a < self . p && b < self . p) ;
117- Self :: reduce1_vt ( a + b, self . p )
117+ unsafe { Self :: reduce1_vt ( a + b, self . p ) }
118118 }
119119
120120 /// Performs the modular subtraction of a and b in constant time.
@@ -141,7 +141,7 @@ impl Modulus {
141141 /// about the values being multiplied.
142142 const unsafe fn mul_vt ( & self , a : u64 , b : u64 ) -> u64 {
143143 debug_assert ! ( a < self . p && b < self . p) ;
144- Self :: reduce1_vt ( self . lazy_reduce_u128 ( ( a as u128 ) * ( b as u128 ) ) , self . p )
144+ unsafe { Self :: reduce1_vt ( self . lazy_reduce_u128 ( ( a as u128 ) * ( b as u128 ) ) , self . p ) }
145145 }
146146
147147 /// Optimized modular multiplication of a and b in constant time.
@@ -165,7 +165,7 @@ impl Modulus {
165165 debug_assert ! ( self . supports_opt) ;
166166 debug_assert ! ( a < self . p && b < self . p) ;
167167
168- self . reduce_opt_u128_vt ( ( a as u128 ) * ( b as u128 ) )
168+ unsafe { self . reduce_opt_u128_vt ( ( a as u128 ) * ( b as u128 ) ) }
169169 }
170170
171171 /// Modular negation in constant time.
@@ -185,7 +185,7 @@ impl Modulus {
185185 /// about the value being negated.
186186 const unsafe fn neg_vt ( & self , a : u64 ) -> u64 {
187187 debug_assert ! ( a < self . p) ;
188- Self :: reduce1_vt ( self . p - a, self . p )
188+ unsafe { Self :: reduce1_vt ( self . p - a, self . p ) }
189189 }
190190
191191 /// Compute the Shoup representation of a.
@@ -213,7 +213,7 @@ impl Modulus {
213213 /// This function is not constant time and its timing may reveal information
214214 /// about the values being multiplied.
215215 const unsafe fn mul_shoup_vt ( & self , a : u64 , b : u64 , b_shoup : u64 ) -> u64 {
216- Self :: reduce1_vt ( self . lazy_mul_shoup ( a, b, b_shoup) , self . p )
216+ unsafe { Self :: reduce1_vt ( self . lazy_mul_shoup ( a, b, b_shoup) , self . p ) }
217217 }
218218
219219 /// Lazy Shoup multiplication of a and b in constant time.
@@ -364,7 +364,7 @@ impl Modulus {
364364 let b_shoup = self . shoup ( b) ;
365365 self . arch . dispatch ( || {
366366 a. iter_mut ( )
367- . for_each ( |ai| * ai = self . mul_shoup_vt ( * ai, b, b_shoup) )
367+ . for_each ( |ai| * ai = unsafe { self . mul_shoup_vt ( * ai, b, b_shoup) } )
368368 } )
369369 }
370370
@@ -380,11 +380,13 @@ impl Modulus {
380380
381381 if self . supports_opt {
382382 self . arch . dispatch ( || {
383- izip ! ( a. iter_mut( ) , b. iter( ) ) . for_each ( |( ai, bi) | * ai = self . mul_opt_vt ( * ai, * bi) )
383+ izip ! ( a. iter_mut( ) , b. iter( ) )
384+ . for_each ( |( ai, bi) | * ai = unsafe { self . mul_opt_vt ( * ai, * bi) } )
384385 } )
385386 } else {
386387 self . arch . dispatch ( || {
387- izip ! ( a. iter_mut( ) , b. iter( ) ) . for_each ( |( ai, bi) | * ai = self . mul_vt ( * ai, * bi) )
388+ izip ! ( a. iter_mut( ) , b. iter( ) )
389+ . for_each ( |( ai, bi) | * ai = unsafe { self . mul_vt ( * ai, * bi) } )
388390 } )
389391 }
390392 }
@@ -426,8 +428,9 @@ impl Modulus {
426428 debug_assert_eq ! ( & b_shoup, & self . shoup_vec( b) ) ;
427429
428430 self . arch . dispatch ( || {
429- izip ! ( a. iter_mut( ) , b. iter( ) , b_shoup. iter( ) )
430- . for_each ( |( ai, bi, bi_shoup) | * ai = self . mul_shoup_vt ( * ai, * bi, * bi_shoup) )
431+ izip ! ( a. iter_mut( ) , b. iter( ) , b_shoup. iter( ) ) . for_each ( |( ai, bi, bi_shoup) | {
432+ * ai = unsafe { self . mul_shoup_vt ( * ai, * bi, * bi_shoup) }
433+ } )
431434 } )
432435 }
433436
@@ -460,8 +463,11 @@ impl Modulus {
460463 /// about the values being centered.
461464 #[ must_use]
462465 pub unsafe fn center_vec_vt ( & self , a : & [ u64 ] ) -> Vec < i64 > {
463- self . arch
464- . dispatch ( || a. iter ( ) . map ( |ai| self . center_vt ( * ai) ) . collect_vec ( ) )
466+ self . arch . dispatch ( || {
467+ a. iter ( )
468+ . map ( |ai| unsafe { self . center_vt ( * ai) } )
469+ . collect_vec ( )
470+ } )
465471 }
466472
467473 /// Reduce a vector in place in variable time.
@@ -470,8 +476,10 @@ impl Modulus {
470476 /// This function is not constant time and its timing may reveal information
471477 /// about the values being reduced.
472478 pub unsafe fn reduce_vec_vt ( & self , a : & mut [ u64 ] ) {
473- self . arch
474- . dispatch ( || a. iter_mut ( ) . for_each ( |ai| * ai = self . reduce_vt ( * ai) ) )
479+ self . arch . dispatch ( || {
480+ a. iter_mut ( )
481+ . for_each ( |ai| * ai = unsafe { self . reduce_vt ( * ai) } )
482+ } )
475483 }
476484
477485 /// Modular reduction of a i64 in constant time.
@@ -485,7 +493,7 @@ impl Modulus {
485493 /// This function is not constant time and its timing may reveal information
486494 /// about the values being reduced.
487495 const unsafe fn reduce_i64_vt ( & self , a : i64 ) -> u64 {
488- self . reduce_u128_vt ( ( ( ( self . p as i128 ) << 64 ) + ( a as i128 ) ) as u128 )
496+ unsafe { self . reduce_u128_vt ( ( ( ( self . p as i128 ) << 64 ) + ( a as i128 ) ) as u128 ) }
489497 }
490498
491499 /// Reduce a vector in place in constant time.
@@ -502,8 +510,11 @@ impl Modulus {
502510 /// about the values being reduced.
503511 #[ must_use]
504512 pub unsafe fn reduce_vec_i64_vt ( & self , a : & [ i64 ] ) -> Vec < u64 > {
505- self . arch
506- . dispatch ( || a. iter ( ) . map ( |ai| self . reduce_i64_vt ( * ai) ) . collect ( ) )
513+ self . arch . dispatch ( || {
514+ a. iter ( )
515+ . map ( |ai| unsafe { self . reduce_i64_vt ( * ai) } )
516+ . collect ( )
517+ } )
507518 }
508519
509520 /// Reduce a vector in constant time.
@@ -521,7 +532,7 @@ impl Modulus {
521532 #[ must_use]
522533 pub unsafe fn reduce_vec_new_vt ( & self , a : & [ u64 ] ) -> Vec < u64 > {
523534 self . arch
524- . dispatch ( || a. iter ( ) . map ( |bi| self . reduce_vt ( * bi) ) . collect ( ) )
535+ . dispatch ( || a. iter ( ) . map ( |bi| unsafe { self . reduce_vt ( * bi) } ) . collect ( ) )
525536 }
526537
527538 /// Modular negation of a vector in place in constant time.
@@ -539,8 +550,10 @@ impl Modulus {
539550 /// This function is not constant time and its timing may reveal information
540551 /// about the values being negated.
541552 pub unsafe fn neg_vec_vt ( & self , a : & mut [ u64 ] ) {
542- self . arch
543- . dispatch ( || a. iter_mut ( ) . for_each ( |ai| * ai = self . neg_vt ( * ai) ) )
553+ self . arch . dispatch ( || {
554+ a. iter_mut ( )
555+ . for_each ( |ai| * ai = unsafe { self . neg_vt ( * ai) } )
556+ } )
544557 }
545558
546559 /// Modular exponentiation in variable time.
@@ -596,7 +609,7 @@ impl Modulus {
596609 /// about the value being reduced.
597610 #[ must_use]
598611 pub const unsafe fn reduce_u128_vt ( & self , a : u128 ) -> u64 {
599- Self :: reduce1_vt ( self . lazy_reduce_u128 ( a) , self . p )
612+ unsafe { Self :: reduce1_vt ( self . lazy_reduce_u128 ( a) , self . p ) }
600613 }
601614
602615 /// Modular reduction of a u64 in constant time.
@@ -612,7 +625,7 @@ impl Modulus {
612625 /// about the value being reduced.
613626 #[ must_use]
614627 pub const unsafe fn reduce_vt ( & self , a : u64 ) -> u64 {
615- Self :: reduce1_vt ( self . lazy_reduce ( a) , self . p )
628+ unsafe { Self :: reduce1_vt ( self . lazy_reduce ( a) , self . p ) }
616629 }
617630
618631 /// Optimized modular reduction of a u128 in constant time.
@@ -629,7 +642,7 @@ impl Modulus {
629642 /// about the value being reduced.
630643 pub ( crate ) const unsafe fn reduce_opt_u128_vt ( & self , a : u128 ) -> u64 {
631644 debug_assert ! ( self . supports_opt) ;
632- Self :: reduce1_vt ( self . lazy_reduce_opt_u128 ( a) , self . p )
645+ unsafe { Self :: reduce1_vt ( self . lazy_reduce_opt_u128 ( a) , self . p ) }
633646 }
634647
635648 /// Optimized modular reduction of a u64 in constant time.
@@ -645,7 +658,7 @@ impl Modulus {
645658 /// about the value being reduced.
646659 #[ must_use]
647660 pub const unsafe fn reduce_opt_vt ( & self , a : u64 ) -> u64 {
648- Self :: reduce1_vt ( self . lazy_reduce_opt ( a) , self . p )
661+ unsafe { Self :: reduce1_vt ( self . lazy_reduce_opt ( a) , self . p ) }
649662 }
650663
651664 /// Return x mod p in constant time.
0 commit comments