Skip to content

Commit

Permalink
correct widening
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Dec 17, 2023
1 parent 28f7b20 commit a84995f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/algorithms/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ pub fn rsa_decrypt<R: CryptoRngCore + ?Sized>(
// reduce c first
// TODO: constant time
// TODO: store NonZero?
let c = c.rem_vartime(&NonZero::new(p.clone()).unwrap());
let c = c
.rem_vartime(&NonZero::new(p.clone()).unwrap())
.widen(p_params.bits_precision());
std::dbg!(c.bits_precision(), p_params.bits_precision());
let cp = BoxedResidue::new(c.clone(), p_params.clone());
std::dbg!(cp.bits_precision(), dp.bits_precision());
let mut m1 = cp.pow(&dp);
// m2 = c^dQ mod q
let cq = BoxedResidue::new(c, q_params.clone());
Expand All @@ -114,7 +118,7 @@ pub fn rsa_decrypt<R: CryptoRngCore + ?Sized>(
match ir {
Some(ref ir) => {
// unblind
let res = unblind(&m, ir, n_params);
let res = unblind(&m.widen(n.bits_precision()), ir, n_params);
Ok(res)
}
None => Ok(m),
Expand Down
4 changes: 2 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ impl RsaPrivateKey {
let q_params = BoxedResidueParams::new_vartime(q.clone()).unwrap();

let x = NonZero::new(p.wrapping_sub(&BoxedUint::one())).unwrap();
let dp = d.rem_vartime(&x);
let dp = d.rem_vartime(&x).widen(p_params.bits_precision());
let x = NonZero::new(q.wrapping_sub(&BoxedUint::one())).unwrap();
let dq = d.rem_vartime(&x);
let dq = d.rem_vartime(&x).widen(q_params.bits_precision());
let qinv = BoxedResidue::new(q.clone(), p_params.clone());
let qinv = qinv.invert();
if qinv.is_none().into() {
Expand Down

0 comments on commit a84995f

Please sign in to comment.