33use alloc:: borrow:: Cow ;
44use alloc:: vec:: Vec ;
55use crypto_bigint:: modular:: BoxedResidueParams ;
6- use crypto_bigint:: { BoxedUint , NonZero , Zero } ;
6+ use crypto_bigint:: { BoxedUint , NonZero } ;
77use num_bigint:: { BigInt , BigUint , IntoBigInt , IntoBigUint , ModInverse , RandBigInt , ToBigInt } ;
88use num_integer:: { sqrt, Integer } ;
99use num_traits:: { FromPrimitive , One , Pow , Signed , Zero as _} ;
@@ -326,22 +326,23 @@ pub(crate) fn compute_private_exponent_carmicheal(
326326 }
327327}
328328
329- fn blind_new < R : CryptoRngCore , K : PublicKeyParts > (
329+ fn blind_new < R : CryptoRngCore , K : PublicKeyPartsNew > (
330330 rng : & mut R ,
331331 key : & K ,
332332 c : & BoxedUint ,
333333 n_params : & BoxedResidueParams ,
334334) -> ( BoxedUint , BoxedUint ) {
335- let n = NonZero :: new ( to_uint ( key. n ( ) . clone ( ) ) ) . unwrap ( ) ;
336335 let mut r: BoxedUint ;
337336 let mut ir: CtOption < BoxedUint > ;
338337 let unblinder;
339338 loop {
340- r = todo ! ( ) ; // BoxedUint::random_mod(&mut rng, &n);
339+ // TODO: use constant time gen
340+ r = to_uint ( rng. gen_biguint_below ( & to_biguint ( & key. n ( ) ) ) ) ;
341+ // TODO: correct mapping
341342 if r. is_zero ( ) . into ( ) {
342343 r = BoxedUint :: one ( ) ;
343344 }
344- ir = r. inv_mod ( & n ) ;
345+ ir = r. inv_mod ( key . n ( ) ) ;
345346
346347 // TODO: constant time?
347348 if let Some ( ir) = ir. into ( ) {
@@ -350,13 +351,12 @@ fn blind_new<R: CryptoRngCore, K: PublicKeyParts>(
350351 }
351352 }
352353
353- let e = to_uint ( key. e ( ) . clone ( ) ) ;
354354 let c = {
355355 let r = reduce ( & r, n_params. clone ( ) ) ;
356- let rpowe = r. pow ( & e ) . retrieve ( ) ;
356+ let mut rpowe = r. pow ( key . e ( ) ) . retrieve ( ) ;
357357
358358 let c = c. wrapping_mul ( & rpowe) ;
359- let c = c. rem_vartime ( & n ) ;
359+ let c = c. rem_vartime ( key . n ( ) ) ;
360360
361361 rpowe. zeroize ( ) ;
362362
@@ -367,9 +367,8 @@ fn blind_new<R: CryptoRngCore, K: PublicKeyParts>(
367367}
368368
369369fn unblind_new ( key : & impl PublicKeyPartsNew , m : & BoxedUint , unblinder : & BoxedUint ) -> BoxedUint {
370- let n = key. n ( ) ;
371370 let a = m. wrapping_mul ( unblinder) ;
372- a. rem_vartime ( & n )
371+ a. rem_vartime ( key . n ( ) )
373372}
374373
375374pub fn rsa_decrypt_new < R : CryptoRngCore + ?Sized > (
0 commit comments