diff --git a/Cargo.toml b/Cargo.toml index 428f919..dea9dfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,9 +26,11 @@ features = ["nightly"] travis-ci = { repository = "dalek-cryptography/curve25519-dalek", branch = "master"} [dev-dependencies] +rand_os = "0.1.0" sha2 = { version = "0.8", default-features = false } bincode = "1" criterion = "0.2" +rand = "0.6" [[bench]] name = "dalek_benchmarks" @@ -41,7 +43,7 @@ harness = false # match exactly, since the build.rs uses the crate itself as a library. [dependencies] -rand = { version = "0.6.0", default-features = false } +rand_core = { version = "0.3.0", default-features = false } byteorder = { version = "^1.2.3", default-features = false, features = ["i128"] } digest = { version = "0.8", default-features = false } clear_on_drop = "=0.2.3" @@ -50,7 +52,7 @@ serde = { version = "1.0", optional = true } packed_simd = { version = "0.3.0", features = ["into_bits"], optional = true } [build-dependencies] -rand = { version = "0.6.0", default-features = false } +rand_core = { version = "0.3.0", default-features = false } byteorder = { version = "^1.2.3", default-features = false, features = ["i128"] } digest = { version = "0.8", default-features = false } clear_on_drop = "=0.2.3" @@ -61,7 +63,7 @@ packed_simd = { version = "0.3.0", features = ["into_bits"], optional = true } [features] nightly = ["subtle/nightly", "clear_on_drop/nightly"] default = ["std", "u64_backend"] -std = ["alloc", "subtle/std", "rand/std"] +std = ["alloc", "subtle/std", "rand_core/std"] alloc = [] yolocrypto = [] diff --git a/build.rs b/build.rs index 631515c..2d020e1 100644 --- a/build.rs +++ b/build.rs @@ -18,7 +18,7 @@ extern crate byteorder; extern crate clear_on_drop; extern crate core; extern crate digest; -extern crate rand; +extern crate rand_core; extern crate subtle; #[cfg(all(feature = "nightly", feature = "packed_simd"))] diff --git a/src/lib.rs b/src/lib.rs index 7fef688..07c3bef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,9 @@ extern crate packed_simd; extern crate byteorder; extern crate clear_on_drop; pub extern crate digest; -extern crate rand; +extern crate rand_core; +#[cfg(all(test, feature = "stage2_build"))] +extern crate rand_os; // Used for traits related to constant-time code. extern crate subtle; diff --git a/src/montgomery.rs b/src/montgomery.rs index da3c9a5..0cd6f8a 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -305,7 +305,7 @@ mod test { use super::*; #[cfg(feature = "rand")] - use rand::rngs::OsRng; + use rand_os::OsRng; /// Test Montgomery -> Edwards on the X/Ed25519 basepoint #[test] diff --git a/src/ristretto.rs b/src/ristretto.rs index 3851949..d3609ef 100644 --- a/src/ristretto.rs +++ b/src/ristretto.rs @@ -164,7 +164,7 @@ use core::ops::{Add, Neg, Sub}; use core::ops::{AddAssign, SubAssign}; use core::ops::{Mul, MulAssign}; -use rand::{CryptoRng, Rng}; +use rand_core::{CryptoRng, RngCore}; use digest::generic_array::typenum::U64; use digest::Digest; @@ -477,8 +477,8 @@ impl RistrettoPoint { /// ``` /// # extern crate curve25519_dalek; /// # use curve25519_dalek::ristretto::RistrettoPoint; - /// extern crate rand; - /// use rand::rngs::OsRng; + /// extern crate rand_os; + /// use rand_os::OsRng; /// /// # // Need fn main() here in comment so the doctest compiles /// # // See https://doc.rust-lang.org/book/documentation.html#documentation-as-tests @@ -626,7 +626,7 @@ impl RistrettoPoint { /// /// # Inputs /// - /// * `rng`: any RNG which implements the `rand::Rng` interface. + /// * `rng`: any RNG which implements the `RngCore + CryptoRng` interface. /// /// # Returns /// @@ -638,9 +638,9 @@ impl RistrettoPoint { /// discrete log of the output point with respect to any other /// point should be unknown. The map is applied twice and the /// results are added, to ensure a uniform distribution. - pub fn random(rng: &mut T) -> Self { + pub fn random(rng: &mut T) -> Self { let mut uniform_bytes = [0u8; 64]; - rng.fill(&mut uniform_bytes); + rng.fill_bytes(&mut uniform_bytes); RistrettoPoint::from_uniform_bytes(&uniform_bytes) } @@ -1076,7 +1076,7 @@ impl Debug for RistrettoPoint { #[cfg(all(test, feature = "stage2_build"))] mod test { #[cfg(feature = "rand")] - use rand::rngs::OsRng; + use rand_os::OsRng; use scalar::Scalar; use constants; diff --git a/src/scalar.rs b/src/scalar.rs index 3c78bee..abf44d9 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -151,7 +151,7 @@ use core::ops::{Sub, SubAssign}; #[allow(unused_imports)] use prelude::*; -use rand::{CryptoRng, Rng}; +use rand_core::{CryptoRng, RngCore}; use digest::generic_array::typenum::U64; use digest::Digest; @@ -507,7 +507,7 @@ impl Scalar { /// /// # Inputs /// - /// * `rng`: any RNG which implements the `rand::CryptoRng` interface. + /// * `rng`: any RNG which implements the `RngCore + CryptoRng` interface. /// /// # Returns /// @@ -516,20 +516,20 @@ impl Scalar { /// # Example /// /// ``` - /// extern crate rand; + /// extern crate rand_os; /// # extern crate curve25519_dalek; /// # /// # fn main() { /// use curve25519_dalek::scalar::Scalar; /// - /// use rand::OsRng; + /// use rand_os::OsRng; /// /// let mut csprng: OsRng = OsRng::new().unwrap(); /// let a: Scalar = Scalar::random(&mut csprng); /// # } - pub fn random(rng: &mut T) -> Self { + pub fn random(rng: &mut T) -> Self { let mut scalar_bytes = [0u8; 64]; - rng.fill(&mut scalar_bytes); + rng.fill_bytes(&mut scalar_bytes); Scalar::from_bytes_mod_order_wide(&scalar_bytes) }