22
33use core:: cmp:: Ordering ;
44
5- use crypto_bigint:: modular:: { BoxedMontyForm , BoxedMontyParams } ;
6- use crypto_bigint:: { BoxedUint , Gcd , NonZero , Odd , RandomMod , Resize } ;
5+ use crypto_bigint:: {
6+ modular:: { BoxedMontyForm , BoxedMontyParams } ,
7+ BoxedUint , ConcatenatingMul , ConcatenatingSquare , Gcd , NonZero , Odd , RandomMod , Resize ,
8+ } ;
79use rand_core:: TryCryptoRng ;
810use zeroize:: Zeroize ;
911
@@ -117,7 +119,8 @@ pub fn rsa_decrypt<R: TryCryptoRng + ?Sized>(
117119
118120 // m = m2 + h.q
119121 let m2 = m2. try_resize ( n. bits_precision ( ) ) . ok_or ( Error :: Internal ) ?;
120- let hq = ( h * q)
122+ let hq = h
123+ . concatenating_mul ( & q)
121124 . try_resize ( n. bits_precision ( ) )
122125 . ok_or ( Error :: Internal ) ?;
123126 m2. wrapping_add ( & hq)
@@ -275,14 +278,14 @@ pub fn recover_primes(
275278 let d = d. resize_unchecked ( d. bits_precision ( ) ) ;
276279 let n = n. resize_unchecked ( bits) ;
277280
278- let a1 = d * e - & one;
281+ let a1 = d. concatenating_mul ( & e ) - & one;
279282 let a2 = ( n. as_ref ( ) - & one) . gcd ( & a1) ;
280- let a = a1 * a2 ;
283+ let a = a1. concatenating_mul ( & a2 ) ;
281284 let n = n. resize_unchecked ( a. bits_precision ( ) ) ;
282285
283286 // 2. Let m = floor(a /n) and r = a – m n, so that a = m n + r and 0 ≤ r < n.
284287 let m = & a / & n;
285- let r = a - & m * n . as_ref ( ) ;
288+ let r = a - m . concatenating_mul ( & * n ) ;
286289 let n = n. get ( ) ;
287290
288291 // 3. Let b = ( (n – r)/(m + 1) ) + 1; if b is not an integer or b^2 ≤ 4n, then output an error indicator,
@@ -294,8 +297,8 @@ pub fn recover_primes(
294297 let b = ( ( & n - & r) / NonZero :: new ( & m + & one) . expect ( "adding one" ) ) + one;
295298
296299 let four = BoxedUint :: from ( 4u32 ) ;
297- let four_n = & n * four;
298- let b_squared = b. square ( ) ;
300+ let four_n = n . concatenating_mul ( & four) ;
301+ let b_squared = b. concatenating_square ( ) ;
299302
300303 if b_squared <= four_n {
301304 return Err ( Error :: InvalidArguments ) ;
@@ -306,7 +309,7 @@ pub fn recover_primes(
306309 // then output an error indicator, and exit without further processing.
307310 let y = b_squared_minus_four_n. floor_sqrt ( ) ;
308311
309- let y_squared = y. square ( ) ;
312+ let y_squared = y. concatenating_square ( ) ;
310313 let sqrt_is_whole_number = y_squared == b_squared_minus_four_n;
311314 if !sqrt_is_whole_number {
312315 return Err ( Error :: InvalidArguments ) ;
@@ -327,7 +330,7 @@ pub(crate) fn compute_modulus(primes: &[BoxedUint]) -> Odd<BoxedUint> {
327330 let mut primes = primes. iter ( ) ;
328331 let mut out = primes. next ( ) . expect ( "must at least be one prime" ) . clone ( ) ;
329332 for p in primes {
330- out *= p ;
333+ out = out . concatenating_mul ( & p ) ;
331334 }
332335 Odd :: new ( out) . expect ( "modulus must be odd" )
333336}
@@ -346,7 +349,7 @@ pub(crate) fn compute_private_exponent_euler_totient(
346349 let mut totient = BoxedUint :: one_with_precision ( bits) ;
347350
348351 for prime in primes {
349- totient *= prime - & BoxedUint :: one ( ) ;
352+ totient = totient . concatenating_mul ( & ( prime - & BoxedUint :: one ( ) ) ) ;
350353 }
351354 let exp = exp. resize_unchecked ( totient. bits_precision ( ) ) ;
352355
@@ -379,7 +382,7 @@ pub(crate) fn compute_private_exponent_carmicheal(
379382
380383 // LCM inlined
381384 let gcd = p1. gcd ( & q1) ;
382- let lcm = p1 / NonZero :: new ( gcd) . expect ( "gcd is non zero" ) * & q1;
385+ let lcm = ( p1 / NonZero :: new ( gcd) . expect ( "gcd is non zero" ) ) . concatenating_mul ( & q1) ;
383386 let exp = exp. resize_unchecked ( lcm. bits_precision ( ) ) ;
384387 if let Some ( d) = exp. invert_mod ( & NonZero :: new ( lcm) . expect ( "non zero" ) ) . into ( ) {
385388 Ok ( d)
0 commit comments