Skip to content

Commit

Permalink
Hack: use chacha20 crate for StdRng and ThreadRng implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Oct 20, 2019
1 parent 9221d93 commit 3818d08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nightly = ["simd_support"] # enables all features requiring nightly rust
serde1 = [] # does nothing, deprecated

# Optional dependencies:
std = ["rand_core/std", "rand_chacha/std", "alloc", "getrandom"]
std = ["rand_core/std", "alloc", "getrandom"]
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
# re-export optional WASM dependencies to avoid breakage:
# Warning: wasm-bindgen and stdweb features will be removed in rand 0.8;
Expand Down Expand Up @@ -73,14 +73,19 @@ libc = { version = "0.2.22", default-features = false }
# Emscripten does not support 128-bit integers, which are used by ChaCha code.
# We work around this by using a different RNG.
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
rand_chacha = { path = "rand_chacha", version = "0.2.1", default-features = false }
# rand_chacha = { path = "rand_chacha", version = "0.2.1", default-features = false }
chacha20 = { path = "../stream-ciphers/chacha20", features = ["rng"] }
[target.'cfg(target_os = "emscripten")'.dependencies]
rand_hc = { path = "rand_hc", version = "0.2" }

[dev-dependencies]
rand_pcg = { path = "rand_pcg", version = "0.2" }
# Only for benches:
rand_hc = { path = "rand_hc", version = "0.2" }
rand_chacha = { path = "rand_chacha" }

[package.metadata.docs.rs]
all-features = true

[patch.crates-io]
rand_core = { path = "rand_core", version = "0.5" }
6 changes: 4 additions & 2 deletions src/rngs/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ use crate::{RngCore, CryptoRng, Error, SeedableRng};
#[cfg(all(any(test, feature = "std"), target_os = "emscripten"))]
pub(crate) use rand_hc::Hc128Core as Core;
#[cfg(all(any(test, feature = "std"), not(target_os = "emscripten")))]
pub(crate) use rand_chacha::ChaCha20Core as Core;
// pub(crate) use rand_chacha::ChaCha20Core as Core;
pub(crate) use chacha20::ChaCha20RngCore as Core;

#[cfg(target_os = "emscripten")] use rand_hc::Hc128Rng as Rng;
#[cfg(not(target_os = "emscripten"))] use rand_chacha::ChaCha20Rng as Rng;
// #[cfg(not(target_os = "emscripten"))] use rand_chacha::ChaCha20Rng as Rng;
#[cfg(not(target_os = "emscripten"))] use chacha20::ChaCha20Rng as Rng;

/// The standard RNG. The PRNG algorithm in `StdRng` is chosen to be efficient
/// on the current platform, to be statistically strong and unpredictable
Expand Down

0 comments on commit 3818d08

Please sign in to comment.