Skip to content

Commit 9adbf94

Browse files
authored
Update dependencies and refactor RNG usage to StdRng (#10)
1 parent c212158 commit 9adbf94

5 files changed

Lines changed: 44 additions & 41 deletions

File tree

Cargo.lock

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ license = "MIT OR Apache-2.0"
88
readme = "README.md"
99

1010
[dependencies]
11-
num-bigint-dig = { version = "0.8", features = [
11+
num-bigint-dig = { version = "0.9.1", features = [
1212
"zeroize",
1313
"prime",
1414
"rand",
1515
"u64_digit",
1616
] }
1717
num-traits = "0.2"
1818
num-integer = "0.1"
19-
rand = "0.8"
19+
rand = "0.9.3"
2020
zeroize = { version = "1.8", features = ["derive"] }
2121
thiserror = "2"
2222
# Constant-time modular arithmetic for the decryption hot path (SECURITY-2).

src/key.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
use num_bigint_dig::{BigUint, ModInverse, RandBigInt};
55
use num_integer::Integer;
66
use num_traits::{One, Zero};
7-
use rand::rngs::OsRng;
7+
use rand::rngs::StdRng;
8+
use rand::SeedableRng;
89
use zeroize::{Zeroize, ZeroizeOnDrop};
910

1011
use crate::util::l_function;
@@ -214,7 +215,7 @@ impl KeyPair {
214215
});
215216
}
216217

217-
let mut rng = OsRng;
218+
let mut rng = StdRng::from_os_rng();
218219
let p_bits = bit_length / 3;
219220
let q_bits = bit_length - (2 * p_bits);
220221

src/okuchi.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
use num_bigint_dig::{BigUint, RandBigInt};
55
use num_integer::Integer;
66
use num_traits::{One, Zero};
7-
use rand::rngs::OsRng;
7+
use rand::rngs::StdRng;
8+
use rand::SeedableRng;
89

910
use crate::ciphertext::Ciphertext;
1011
use crate::error::{Error, Result};
@@ -52,7 +53,7 @@ impl Okuchi {
5253
return Err(Error::PlaintextTooLarge);
5354
}
5455

55-
let mut rng = OsRng;
56+
let mut rng = StdRng::from_os_rng();
5657

5758
// OU requires gcd(r, n) = 1. With n = p²q the failure probability is
5859
// ≈ 1/p + 1/q. This is negligible but the protocol is undefined otherwise.

src/util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crypto_bigint::modular::{BoxedMontyForm, BoxedMontyParams};
99
use crypto_bigint::{BoxedUint, Odd};
1010
use num_bigint_dig::{BigUint, RandPrime};
1111
use num_traits::One;
12-
use rand::rngs::OsRng;
12+
use rand::rngs::StdRng;
13+
use rand::SeedableRng;
1314

1415
use crate::{Error, Result};
1516

@@ -98,6 +99,6 @@ pub fn generate_prime(bits: usize) -> Result<BigUint> {
9899
"prime bit length must be >= 2".into(),
99100
));
100101
}
101-
let mut rng = OsRng;
102+
let mut rng = StdRng::from_os_rng();
102103
Ok(rng.gen_prime(bits)) // gen_prime uses Miller-Rabin internally
103104
}

0 commit comments

Comments
 (0)