Skip to content

Commit

Permalink
wrap: use RsaPrivateKey::from_p_q
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Nov 28, 2023
1 parent 06e816a commit d3e6fdb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ ccm = { version = "0.5", features = ["std"] }
ecdsa = { version = "0.16", default-features = false }
ed25519 = "2"
log = "0.4"
num-bigint = { version = "0.8.2", features = ["i128", "prime", "zeroize"], default-features = false, package = "num-bigint-dig" }
num-traits = "0.2"
p256 = { version = "0.13", default-features = false, features = ["ecdsa"] }
p384 = { version = "0.13", default-features = false, features = ["ecdsa"] }
serde = { version = "1", features = ["serde_derive"] }
rand_core = { version = "0.6", features = ["std"] }
rsa = "0.9"
rsa = "0.9.5"
signature = { version = "2", features = ["derive"] }
subtle = "2"
thiserror = "1"
Expand Down
15 changes: 5 additions & 10 deletions src/wrap/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use ecdsa::{
},
PrimeCurve,
};
use num_bigint::traits::ModInverse;
use num_traits::{cast::FromPrimitive, identities::One};
use num_traits::cast::FromPrimitive;
use rsa::{BigUint, RsaPrivateKey};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -141,19 +140,15 @@ impl Plaintext {

let p = BigUint::from_bytes_be(reader.read(component_size)?);
let q = BigUint::from_bytes_be(reader.read(component_size)?);
let dp = BigUint::from_bytes_be(reader.read(component_size)?);
let dq = BigUint::from_bytes_be(reader.read(component_size)?);
let _dp = BigUint::from_bytes_be(reader.read(component_size)?);
let _dq = BigUint::from_bytes_be(reader.read(component_size)?);
let _qinv = BigUint::from_bytes_be(reader.read(component_size)?);
let n = BigUint::from_bytes_be(reader.read(modulus_size)?);
let _n = BigUint::from_bytes_be(reader.read(modulus_size)?);
const EXP: u64 = 65537;
let e = BigUint::from_u64(EXP).expect("invalid static exponent");

let d = e
.clone()
.mod_inverse((dp - BigUint::one()) * (dq - BigUint::one()))?
.to_biguint()?;
let private_key = RsaPrivateKey::from_p_q(p, q, e).ok()?;

let private_key = RsaPrivateKey::from_components(n, e, d, vec![p, q]).ok()?;
Some(private_key)
}
}
Expand Down

0 comments on commit d3e6fdb

Please sign in to comment.