Skip to content

Commit 4afc333

Browse files
authored
Replace rand_chacha dependency with chacha20 (#1642)
2 parents d28a658 + 4490b41 commit 4afc333

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1010

1111
## [0.10.0 — Unreleased]
1212
### Changes
13+
- The dependency on `rand_chacha` has been replaced with a dependency on `chacha20`. This changes the implementation behind `StdRng`, but the output remains the same. There may be some API breakage when using the ChaCha-types directly as these are now the ones in `chacha20` instead of `rand_chacha` (#1642).
1314
- Rename fns `IndexedRandom::choose_multiple` -> `sample`, `choose_multiple_array` -> `sample_array`, `choose_multiple_weighted` -> `sample_weighted`, struct `SliceChooseIter` -> `IndexedSamples` and fns `IteratorRandom::choose_multiple` -> `sample`, `choose_multiple_fill` -> `sample_fill` (#1632)
1415
- Use Edition 2024 and MSRV 1.85 (#1653)
1516
- Let `Fill` be implemented for element types, not sliceable types (#1652)

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ serde = ["dep:serde", "rand_core/serde"]
3434

3535
# Option (enabled by default): without "std" rand uses libcore; this option
3636
# enables functionality expected to be available on a standard platform.
37-
std = ["rand_core/std", "rand_chacha?/std", "alloc"]
37+
std = ["rand_core/std", "alloc"]
3838

3939
# Option: "alloc" enables support for Vec and Box when not using "std"
4040
alloc = []
@@ -46,7 +46,7 @@ os_rng = ["rand_core/os_rng"]
4646
simd_support = []
4747

4848
# Option (enabled by default): enable StdRng
49-
std_rng = ["dep:rand_chacha"]
49+
std_rng = ["dep:chacha20"]
5050

5151
# Option: enable SmallRng
5252
small_rng = []
@@ -70,11 +70,16 @@ members = [
7070
]
7171
exclude = ["benches", "distr_test"]
7272

73+
# Force chacha20 to use the local rand_code to avoid compiling two different "rand_core"s.
74+
# This is necessary even if the specified versions are the same.
75+
[patch.crates-io]
76+
rand_core = { path = "rand_core" }
77+
7378
[dependencies]
7479
rand_core = { path = "rand_core", version = "0.9.0", default-features = false }
7580
log = { version = "0.4.4", optional = true }
7681
serde = { version = "1.0.103", features = ["derive"], optional = true }
77-
rand_chacha = { path = "rand_chacha", version = "0.9.0", default-features = false, optional = true }
82+
chacha20 = { version = "=0.10.0-rc.2", default-features = false, features = ["rng"], optional = true }
7883

7984
[dev-dependencies]
8085
rand_pcg = { path = "rand_pcg", version = "0.9.0" }

benches/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ publish = false
88
# Option (requires nightly Rust): experimental SIMD support
99
simd_support = ["rand/simd_support"]
1010

11+
# Force chacha20 to use the local rand_code to avoid compiling two different "rand_core"s.
12+
# This is necessary even if the specified versions are the same.
13+
[patch.crates-io]
14+
rand_core = { path = "../rand_core" }
15+
1116
[dependencies]
1217

1318
[dev-dependencies]

examples/rayon-monte-carlo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
//! over BATCH_SIZE trials. Manually batching also turns out to be faster
3939
//! for the nondeterministic version of this program as well.
4040
41+
use chacha20::ChaCha8Rng;
4142
use rand::distr::{Distribution, Uniform};
42-
use rand_chacha::{ChaCha8Rng, rand_core::SeedableRng};
43+
use rand_core::SeedableRng;
4344
use rayon::prelude::*;
4445

4546
static SEED: u64 = 0;

src/rngs/reseeding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore};
5353
/// # Example
5454
///
5555
/// ```
56+
/// use chacha20::ChaCha20Core; // Internal part of ChaChaRng that
57+
/// // implements BlockRngCore
5658
/// use rand::prelude::*;
57-
/// use rand_chacha::ChaCha20Core; // Internal part of ChaChaRng that
58-
/// // implements BlockRngCore
5959
/// use rand::rngs::OsRng;
6060
/// use rand::rngs::ReseedingRng;
6161
///

src/rngs/std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use rand_core::{CryptoRng, RngCore, SeedableRng};
1212

1313
#[cfg(any(test, feature = "os_rng"))]
14-
pub(crate) use rand_chacha::ChaCha12Core as Core;
14+
pub(crate) use chacha20::ChaCha12Core as Core;
1515

16-
use rand_chacha::ChaCha12Rng as Rng;
16+
use chacha20::ChaCha12Rng as Rng;
1717

1818
/// A strong, fast (amortized), non-portable RNG
1919
///

0 commit comments

Comments
 (0)