replace rand with rand_core+rand_os

This commit is contained in:
Артём Павлов [Artyom Pavlov] 2019-01-05 14:27:24 +03:00
parent 7de65dc32c
commit d6ca36fa0b
7 changed files with 24 additions and 21 deletions

View file

@ -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"]
alloc = []
yolocrypto = []

View file

@ -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;

View file

@ -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"))]

View file

@ -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;

View file

@ -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]

View file

@ -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<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)
}
@ -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;

View file

@ -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<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)
}