3
3
use alloc:: borrow:: Cow ;
4
4
use alloc:: vec:: Vec ;
5
5
use crypto_bigint:: modular:: BoxedResidueParams ;
6
- use crypto_bigint:: { BoxedUint , NonZero , Zero } ;
6
+ use crypto_bigint:: { BoxedUint , NonZero } ;
7
7
use num_bigint:: { BigInt , BigUint , IntoBigInt , IntoBigUint , ModInverse , RandBigInt , ToBigInt } ;
8
8
use num_integer:: { sqrt, Integer } ;
9
9
use num_traits:: { FromPrimitive , One , Pow , Signed , Zero as _} ;
@@ -326,22 +326,23 @@ pub(crate) fn compute_private_exponent_carmicheal(
326
326
}
327
327
}
328
328
329
- fn blind_new < R : CryptoRngCore , K : PublicKeyParts > (
329
+ fn blind_new < R : CryptoRngCore , K : PublicKeyPartsNew > (
330
330
rng : & mut R ,
331
331
key : & K ,
332
332
c : & BoxedUint ,
333
333
n_params : & BoxedResidueParams ,
334
334
) -> ( BoxedUint , BoxedUint ) {
335
- let n = NonZero :: new ( to_uint ( key. n ( ) . clone ( ) ) ) . unwrap ( ) ;
336
335
let mut r: BoxedUint ;
337
336
let mut ir: CtOption < BoxedUint > ;
338
337
let unblinder;
339
338
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
341
342
if r. is_zero ( ) . into ( ) {
342
343
r = BoxedUint :: one ( ) ;
343
344
}
344
- ir = r. inv_mod ( & n ) ;
345
+ ir = r. inv_mod ( key . n ( ) ) ;
345
346
346
347
// TODO: constant time?
347
348
if let Some ( ir) = ir. into ( ) {
@@ -350,13 +351,12 @@ fn blind_new<R: CryptoRngCore, K: PublicKeyParts>(
350
351
}
351
352
}
352
353
353
- let e = to_uint ( key. e ( ) . clone ( ) ) ;
354
354
let c = {
355
355
let r = reduce ( & r, n_params. clone ( ) ) ;
356
- let rpowe = r. pow ( & e ) . retrieve ( ) ;
356
+ let mut rpowe = r. pow ( key . e ( ) ) . retrieve ( ) ;
357
357
358
358
let c = c. wrapping_mul ( & rpowe) ;
359
- let c = c. rem_vartime ( & n ) ;
359
+ let c = c. rem_vartime ( key . n ( ) ) ;
360
360
361
361
rpowe. zeroize ( ) ;
362
362
@@ -367,9 +367,8 @@ fn blind_new<R: CryptoRngCore, K: PublicKeyParts>(
367
367
}
368
368
369
369
fn unblind_new ( key : & impl PublicKeyPartsNew , m : & BoxedUint , unblinder : & BoxedUint ) -> BoxedUint {
370
- let n = key. n ( ) ;
371
370
let a = m. wrapping_mul ( unblinder) ;
372
- a. rem_vartime ( & n )
371
+ a. rem_vartime ( key . n ( ) )
373
372
}
374
373
375
374
pub fn rsa_decrypt_new < R : CryptoRngCore + ?Sized > (
0 commit comments