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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"num-bigint 0.4.6",
|
||||||
"num-complex",
|
"num-complex",
|
||||||
"num-integer",
|
"num-integer",
|
||||||
"num-iter",
|
"num-iter",
|
||||||
|
@ -229,7 +230,6 @@ checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-integer",
|
"num-integer",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"rand 0.8.5",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -280,6 +280,7 @@ version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"num-bigint 0.4.6",
|
||||||
"num-integer",
|
"num-integer",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
@ -413,7 +414,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"colog",
|
"colog",
|
||||||
"log",
|
"log",
|
||||||
"num-bigint 0.4.6",
|
"num",
|
||||||
"num-primes",
|
"num-primes",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
colog = "1.3.0"
|
colog = "1.3.0"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
num-bigint = { version = "0.4.6", features = ["rand"] }
|
num = "0.4"
|
||||||
num-traits = "0.2.19"
|
num-traits = "0.2.19"
|
||||||
num-primes = "0.3"
|
num-primes = "0.3"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
10
src/main.rs
10
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
use colog;
|
use colog;
|
||||||
use log::{info, error};
|
use log::{info, error};
|
||||||
use num_bigint::BigUint;
|
use num::BigUint;
|
||||||
use num_primes::Generator;
|
use num_primes::Generator;
|
||||||
use num_traits::cast::ToPrimitive;
|
use num_traits::cast::ToPrimitive;
|
||||||
use num_traits::One;
|
use num_traits::One;
|
||||||
|
@ -19,15 +19,15 @@ impl RSA {
|
||||||
let q = Generator::new_prime(key_size);
|
let q = Generator::new_prime(key_size);
|
||||||
|
|
||||||
// Convert num-primes::BigUint to num-bigint::BigUint
|
// Convert num-primes::BigUint to num-bigint::BigUint
|
||||||
let p_bigint = num_bigint::BigUint::parse_bytes(p.to_string().as_bytes(), 10).unwrap();
|
let p_bigint = num::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 q_bigint = num::BigUint::parse_bytes(q.to_string().as_bytes(), 10).unwrap();
|
||||||
|
|
||||||
let n = &p_bigint * &q_bigint;
|
let n = &p_bigint * &q_bigint;
|
||||||
|
|
||||||
let phi =
|
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
|
// Calculate private key
|
||||||
let d = BigUint::modinv(&e, &phi)
|
let d = BigUint::modinv(&e, &phi)
|
||||||
|
|
Loading…
Add table
Reference in a new issue