Skip to content

Commit

Permalink
Remove dependence on rand_jitter
Browse files Browse the repository at this point in the history
This is a breaking change for anyone using rngs::JitterRng;
such users should switch to rand_jitter::JitterRng.
  • Loading branch information
dhardy committed Apr 3, 2019
1 parent 8cfe210 commit b231ac2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 52 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ appveyor = { repository = "rust-random/rand" }
[features]
default = ["std"] # without "std" rand uses libcore
nightly = ["simd_support"] # enables all features requiring nightly rust
std = ["rand_core/std", "alloc", "getrandom", "rand_jitter/std"]
std = ["rand_core/std", "alloc", "getrandom"]
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
i128_support = [] # enables i128 and u128 support
simd_support = ["packed_simd"] # enables SIMD support
Expand All @@ -49,7 +49,6 @@ members = [
[dependencies]
rand_core = { path = "rand_core", version = "0.4" }
rand_pcg = { path = "rand_pcg", version = "0.1" }
rand_jitter = { path = "rand_jitter", version = "0.1" }
rand_hc = { path = "rand_hc", version = "0.1" }
getrandom = { version = "0.1", optional = true }
log = { version = "0.4", optional = true }
Expand Down
20 changes: 1 addition & 19 deletions benches/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use test::{black_box, Bencher};

use rand::prelude::*;
use rand::rngs::adapter::ReseedingRng;
use rand::rngs::{OsRng, JitterRng};
use rand::rngs::OsRng;
use rand_isaac::{IsaacRng, Isaac64Rng};
use rand_chacha::ChaChaRng;
use rand_hc::{Hc128Rng, Hc128Core};
Expand Down Expand Up @@ -129,17 +129,6 @@ gen_uint!(gen_u64_std, u64, StdRng::from_entropy());
gen_uint!(gen_u64_small, u64, SmallRng::from_entropy());
gen_uint!(gen_u64_os, u64, OsRng::new().unwrap());

// Do not test JitterRng like the others by running it RAND_BENCH_N times per,
// measurement, because it is way too slow. Only run it once.
#[bench]
fn gen_u64_jitter(b: &mut Bencher) {
let mut rng = JitterRng::new().unwrap();
b.iter(|| {
rng.gen::<u64>()
});
b.bytes = size_of::<u64>() as u64;
}

macro_rules! init_gen {
($fnn:ident, $gen:ident) => {
#[bench]
Expand Down Expand Up @@ -170,13 +159,6 @@ init_gen!(init_isaac, IsaacRng);
init_gen!(init_isaac64, Isaac64Rng);
init_gen!(init_chacha, ChaChaRng);

#[bench]
fn init_jitter(b: &mut Bencher) {
b.iter(|| {
JitterRng::new().unwrap()
});
}


const RESEEDING_THRESHOLD: u64 = 1024*1024*1024; // something high enough to get
// deterministic measurements
Expand Down
32 changes: 6 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

#[cfg(feature="simd_support")] extern crate packed_simd;

extern crate rand_jitter;
#[cfg(feature = "getrandom")]
extern crate getrandom;

Expand Down Expand Up @@ -480,35 +479,16 @@ impl_as_byte_slice_arrays!(!div 4096, N,N,N,N,N,N,N,);
/// [`OsRng`]: rngs::OsRng
#[cfg(feature="std")]
pub trait FromEntropy: SeedableRng {
/// Creates a new instance, automatically seeded with fresh entropy.
/// Creates a new instance of the RNG seeded from [`OsRng`].
///
/// Normally this will use `OsRng`, but if that fails `JitterRng` will be
/// used instead. Both should be suitable for cryptography. It is possible
/// that both entropy sources will fail though unlikely; failures would
/// almost certainly be platform limitations or build issues, i.e. most
/// applications targetting PC/mobile platforms should not need to worry
/// about this failing.
/// This method is equivalent to `SeedableRng::from_rng(OsRng).unwrap()`.
///
/// # Panics
///
/// If all entropy sources fail this will panic. If you need to handle
/// errors, use the following code, equivalent aside from error handling:
///
/// ```
/// # use rand::Error;
/// use rand::prelude::*;
/// use rand::rngs::OsRng;
///
/// # fn try_inner() -> Result<(), Error> {
/// // This uses StdRng, but is valid for any R: SeedableRng
/// let mut rng = StdRng::from_rng(OsRng)?;
///
/// println!("random number: {}", rng.gen_range(1, 10));
/// # Ok(())
/// # }
///
/// # try_inner().unwrap()
/// ```
/// If [`OsRng`] is unable to obtain secure entropy this method will panic.
/// It is also possible for an RNG overriding the [`SeedableRng::from_rng`]
/// method to cause a panic. Both causes are extremely unlikely to occur;
/// most users need not worry about this.
fn from_entropy() -> Self;
}

Expand Down
9 changes: 4 additions & 5 deletions src/rngs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
//!
//! Generally the operating system will collect some entropy, remove bias, and
//! use that to seed its own PRNG; [`OsRng`] provides an interface to this.
//! [`JitterRng`] is an entropy collector included with Rand that measures
//! jitter in the CPU execution time, and jitter in memory access time.
//! Some alternatives are available although not normally required; see the
//! [`rdrand`] and [`rand_jitter`] crates.
//!
//! ## Pseudo-random number generators
//!
Expand Down Expand Up @@ -136,11 +136,12 @@
//! [`SmallRng`]: rngs::SmallRng
//! [`StdRng`]: rngs::StdRng
//! [`ThreadRng`]: rngs::ThreadRng
//! [`JitterRng`]: rngs::JitterRng
//! [`mock::StepRng`]: rngs::mock::StepRng
//! [`adapter::ReadRng`]: rngs::adapter::ReadRng
//! [`adapter::ReseedingRng`]: rngs::adapter::ReseedingRng
//! [`ChaChaRng`]: ../../rand_chacha/struct.ChaChaRng.html
//! [`rdrand`]: https://crates.io/crates/rdrand
//! [`rand_jitter`]: https://crates.io/crates/rand_jitter
pub mod adapter;

Expand All @@ -151,8 +152,6 @@ mod small;
mod std;
#[cfg(feature="std")] pub(crate) mod thread;


pub use rand_jitter::{JitterRng, TimerError};
#[allow(deprecated)]
#[cfg(feature="std")] pub use self::entropy::EntropyRng;

Expand Down

0 comments on commit b231ac2

Please sign in to comment.