Refactor dependencies to use 'num' crate instead of 'num-bigint' and update related code
This commit is contained in:
parent
5edac13e00
commit
35ef48b721
3 changed files with 9 additions and 8 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -202,6 +202,7 @@ version = "0.4.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
||||
dependencies = [
|
||||
"num-bigint 0.4.6",
|
||||
"num-complex",
|
||||
"num-integer",
|
||||
"num-iter",
|
||||
|
@ -229,7 +230,6 @@ checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
|
|||
dependencies = [
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"rand 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -280,6 +280,7 @@ version = "0.4.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
||||
dependencies = [
|
||||
"num-bigint 0.4.6",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
@ -413,7 +414,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"colog",
|
||||
"log",
|
||||
"num-bigint 0.4.6",
|
||||
"num",
|
||||
"num-primes",
|
||||
"num-traits",
|
||||
"rand 0.8.5",
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
colog = "1.3.0"
|
||||
log = "0.4.22"
|
||||
num-bigint = { version = "0.4.6", features = ["rand"] }
|
||||
num = "0.4"
|
||||
num-traits = "0.2.19"
|
||||
num-primes = "0.3"
|
||||
rand = "0.8"
|
10
src/main.rs
10
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use colog;
|
||||
use log::{info, error};
|
||||
use num_bigint::BigUint;
|
||||
use num::BigUint;
|
||||
use num_primes::Generator;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use num_traits::One;
|
||||
|
@ -19,15 +19,15 @@ impl RSA {
|
|||
let q = Generator::new_prime(key_size);
|
||||
|
||||
// Convert num-primes::BigUint to num-bigint::BigUint
|
||||
let p_bigint = num_bigint::BigUint::parse_bytes(p.to_string().as_bytes(), 10).unwrap();
|
||||
let q_bigint = num_bigint::BigUint::parse_bytes(q.to_string().as_bytes(), 10).unwrap();
|
||||
let p_bigint = num::BigUint::parse_bytes(p.to_string().as_bytes(), 10).unwrap();
|
||||
let q_bigint = num::BigUint::parse_bytes(q.to_string().as_bytes(), 10).unwrap();
|
||||
|
||||
let n = &p_bigint * &q_bigint;
|
||||
|
||||
let phi =
|
||||
(&p_bigint - num_bigint::BigUint::one()) * (&q_bigint - num_bigint::BigUint::one());
|
||||
(&p_bigint - num::BigUint::one()) * (&q_bigint - num::BigUint::one());
|
||||
|
||||
let e = num_bigint::BigUint::from(65537u32);
|
||||
let e = num::BigUint::from(65537u32);
|
||||
|
||||
// Calculate private key
|
||||
let d = BigUint::modinv(&e, &phi)
|
||||
|
|
Loading…
Add table
Reference in a new issue