diff --git a/Cargo.toml b/Cargo.toml index 847c5ed4b..17c478d7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ 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" @@ -41,7 +42,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 +51,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 +62,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/benches/dalek_benchmarks.rs b/benches/dalek_benchmarks.rs index 71792a3fa..6e51d29bd 100644 --- a/benches/dalek_benchmarks.rs +++ b/benches/dalek_benchmarks.rs @@ -1,7 +1,7 @@ #![allow(non_snake_case)] -extern crate rand; -use rand::rngs::OsRng; +extern crate rand_os; +use rand_os::OsRng; #[macro_use] extern crate criterion; diff --git a/build.rs b/build.rs index 284bce72d..411a5d831 100644 --- a/build.rs +++ b/build.rs @@ -10,7 +10,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 = "avx2_backend"))] diff --git a/src/lib.rs b/src/lib.rs index 4f52c9675..a791eda3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,10 +41,12 @@ extern crate std; #[cfg(all(feature = "nightly", feature = "avx2_backend"))] extern crate packed_simd; -extern crate rand; +extern crate rand_core; extern crate clear_on_drop; extern crate byteorder; pub extern crate digest; +#[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 da3c9a58b..0cd6f8a8a 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 e6375edae..30cbe82b4 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; @@ -462,8 +462,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 @@ -609,7 +609,7 @@ impl RistrettoPoint { /// /// # Inputs /// - /// * `rng`: any RNG which implements the `rand::Rng` interface. + /// * `rng`: any RNG which implements the `RngCore + CryptoRng` interface. /// /// # Returns /// @@ -621,9 +621,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) } @@ -1014,7 +1014,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 2e4d2560f..5c5006e7e 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) }