Skip to content

Commit 47e9767

Browse files
committed
chacha feature, pub use ChaCha*Rng in rand/rngs
1 parent 4afc333 commit 47e9767

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ small_rng = []
5454
# Option: enable ThreadRng and rng()
5555
thread_rng = ["std", "std_rng", "os_rng"]
5656

57+
# Option: enable rand::rngs::ChaCha*Rng
58+
chacha = ["dep:chacha20"]
59+
5760
# Option: use unbiased sampling for algorithms supporting this option: Uniform distribution.
5861
# By default, bias affecting no more than one in 2^48 samples is accepted.
5962
# Note: enabling this option is expected to affect reproducibility of results.

src/rngs/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
//! platform-dependent.
3030
//!
3131
//! - [`StdRng`] is a CSPRNG chosen for good performance and trust of security
32-
//! (based on reviews, maturity and usage). The current algorithm is ChaCha12,
33-
//! which is well established and rigorously analysed.
32+
//! (based on reviews, maturity and usage). The current algorithm is
33+
//! [`ChaCha12Rng`], which is well established and rigorously analysed.
3434
//! [`StdRng`] is the deterministic generator used by [`ThreadRng`] but
3535
//! without the periodic reseeding or thread-local management.
3636
//! - [`SmallRng`] is a relatively simple, insecure generator designed to be
@@ -47,6 +47,8 @@
4747
//! 256 bits of state with good performance in statistical tests of quality
4848
//! - [`Xoshiro128PlusPlus`] is a very fast 32-bit insecure generator using
4949
//! 128 bits of state with good performance in statistical tests of quality
50+
//! - [`ChaCha8Rng`], [`ChaCha12Rng`] and [`ChaCha20Rng`] are generators over
51+
//! the ChaCha stream cipher designed by Daniel J. Bernstein[^1].
5052
//!
5153
//! ### Additional generators
5254
//!
@@ -73,6 +75,8 @@
7375
//!
7476
//! Use the [`rand_core`] crate when implementing your own RNGs.
7577
//!
78+
//! [^1]: D. J. Bernstein, [*ChaCha, a variant of Salsa20*](https://cr.yp.to/chacha.html)
79+
//!
7680
//! [guarantees of reproducibility]: https://rust-random.github.io/book/crate-reprod.html
7781
//! [Types of generators]: https://rust-random.github.io/book/guide-gen.html
7882
//! [Our RNGs]: https://rust-random.github.io/book/guide-rngs.html
@@ -122,5 +126,8 @@ pub use self::std::StdRng;
122126
#[cfg(feature = "thread_rng")]
123127
pub use self::thread::ThreadRng;
124128

129+
#[cfg(feature = "chacha")]
130+
pub use chacha20::{ChaCha8Rng, ChaCha12Rng, ChaCha20Rng};
131+
125132
#[cfg(feature = "os_rng")]
126133
pub use rand_core::OsRng;

0 commit comments

Comments
 (0)