Skip to content

Commit da946be

Browse files
authored
chacha feature, pub use ChaCha*Rng in rand/rngs (#1659)
2 parents 4afc333 + 9b48cd4 commit da946be

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1818
### Additions
1919
- Add fns `IndexedRandom::choose_iter`, `choose_weighted_iter` (#1632)
2020
- Pub export `Xoshiro128PlusPlus`, `Xoshiro256PlusPlus` prngs (#1649)
21+
- Pub export `ChaCha8Rng`, `ChaCha12Rng`, `ChaCha20Rng` behind `chacha` feature (#1659)
2122

2223
## [0.9.2 — 2025-07-20]
2324
### Deprecated

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)