Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace rand with rand_core+rand_os #222

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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 = []

Expand Down
4 changes: 2 additions & 2 deletions benches/dalek_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
///
Expand All @@ -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<T: Rng + CryptoRng>(rng: &mut T) -> Self {
pub fn random<T: RngCore + CryptoRng>(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)
}
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
///
Expand All @@ -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<T: Rng + CryptoRng>(rng: &mut T) -> Self {
pub fn random<T: RngCore + CryptoRng>(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)
}

Expand Down