From d3e6fdb3743c59cef6f4bd4fb45e59160f848fd2 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Tue, 21 Nov 2023 15:25:40 -0800 Subject: [PATCH] wrap: use `RsaPrivateKey::from_p_q` See https://github.com/RustCrypto/RSA/pull/386 --- Cargo.lock | 5 ++--- Cargo.toml | 3 +-- src/wrap/message.rs | 15 +++++---------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad759113..b5a76f6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -660,9 +660,9 @@ dependencies = [ [[package]] name = "rsa" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a3211b01eea83d80687da9eef70e39d65144a3894866a5153a2723e425a157f" +checksum = "af6c4b23d99685a1408194da11270ef8e9809aff951cc70ec9b17350b087e474" dependencies = [ "const-oid", "digest", @@ -941,7 +941,6 @@ dependencies = [ "hmac", "k256", "log", - "num-bigint-dig", "num-traits", "once_cell", "p256", diff --git a/Cargo.toml b/Cargo.toml index d9b8b661..4de1b3eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/wrap/message.rs b/src/wrap/message.rs index 1f696a71..5b6664ad 100644 --- a/src/wrap/message.rs +++ b/src/wrap/message.rs @@ -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}; @@ -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) } }