Skip to content

Commit fa83071

Browse files
authored
Merge pull request #815 from dhardy/from-rng
Prepare new releases, from_rng Endianness and inlining
2 parents cdf9a16 + 7c8284f commit fa83071

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+139
-63
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md).
99
You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful.
1010

1111

12-
## Unreleased
12+
## [0.7.0 Pre-release] - 2019-06-06
13+
Many changes (TODO)
1314
- Enable fork protection of ReseedingRng without `std`
1415
- Remove dependency on `winapi`
1516

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand"
3-
version = "0.6.5"
3+
version = "0.7.0-pre.0"
44
authors = ["The Rand Project Developers", "The Rust Project Developers"]
55
license = "MIT/Apache-2.0"
66
readme = "README.md"
@@ -54,7 +54,7 @@ members = [
5454
]
5555

5656
[dependencies]
57-
rand_core = { path = "rand_core", version = "0.4" }
57+
rand_core = { path = "rand_core", version = "0.5" }
5858
rand_pcg = { path = "rand_pcg", version = "0.1", optional = true }
5959
# Do not depend on 'getrandom_package' directly; use the 'getrandom' feature!
6060
getrandom_package = { version = "0.1.1", package = "getrandom", optional = true }
@@ -114,4 +114,4 @@ required-features = ["small_rng"]
114114
all-features = true
115115

116116
[patch.crates-io]
117-
rand_core = { path = "rand_core", version = "0.4" }
117+
rand_core = { path = "rand_core", version = "0.5" }

rand_chacha/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.0] - 2019-06-06
8+
- Rewrite based on the much faster `c2-chacha` crate (#789)
9+
710
## [0.1.1] - 2019-01-04
811
- Disable `i128` and `u128` if the `target_os` is `emscripten` (#671: work-around Emscripten limitation)
912
- Update readme and doc links

rand_chacha/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_chacha"
3-
version = "0.2.1"
3+
version = "0.2.0"
44
authors = ["The Rand Project Developers", "The Rust Project Developers", "The CryptoCorrosion Contributors"]
55
license = "MIT/Apache-2.0"
66
readme = "README.md"
@@ -19,7 +19,7 @@ travis-ci = { repository = "rust-random/rand" }
1919
appveyor = { repository = "rust-random/rand" }
2020

2121
[dependencies]
22-
rand_core = { path = "../rand_core", version = "0.4" }
22+
rand_core = { path = "../rand_core", version = "0.5" }
2323
c2-chacha = { version = "0.2.2", default-features = false }
2424

2525
[build-dependencies]

rand_chacha/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ as an RNG. It is an improved variant of the Salsa20 cipher family, which was
1616
selected as one of the "stream ciphers suitable for widespread adoption" by
1717
eSTREAM[^2].
1818

19+
The RNGs provided by this crate are implemented via the fast stream ciphers of
20+
the [`c2-chacha`](https://crates.io/crates/c2-chacha) crate.
21+
1922
Links:
2023

2124
- [API documentation (master)](https://rust-random.github.io/rand/rand_chacha)
2225
- [API documentation (docs.rs)](https://docs.rs/rand_chacha)
23-
- [Changelog](CHANGELOG.md)
26+
- [Changelog](https://github.com/rust-random/rand/blob/master/rand_chacha/CHANGELOG.md)
2427

2528
[rand]: https://crates.io/crates/rand
2629
[^1]: D. J. Bernstein, [*ChaCha, a variant of Salsa20*](

rand_core/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.5.0] - 2019-06-06
8+
- Enable testing with Miri and fix incorrect pointer usages (#779, #780, #781, #783, #784)
9+
- Rewrite `Error` type and adjust API (#800)
10+
- Adjust usage of `#[inline]` for `BlockRng` and `BlockRng64`
11+
712
## [0.4.0] - 2019-01-24
813
- Disable the `std` feature by default (#702)
914

rand_core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_core"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
authors = ["The Rand Project Developers", "The Rust Project Developers"]
55
license = "MIT/Apache-2.0"
66
readme = "README.md"

rand_core/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Links:
2525

2626
- [API documentation (master)](https://rust-random.github.io/rand/rand_core)
2727
- [API documentation (docs.rs)](https://docs.rs/rand_core)
28-
- [Changelog](CHANGELOG.md)
28+
- [Changelog](https://github.com/rust-random/rand/blob/master/rand_core/CHANGELOG.md)
2929

3030
[rand]: https://crates.io/crates/rand
3131

@@ -42,6 +42,11 @@ The traits and error types are also available via `rand`.
4242

4343
## Versions
4444

45+
The current version is:
46+
```
47+
rand_core = "0.5.0"
48+
```
49+
4550
Rand libs have inter-dependencies and make use of the
4651
[semver trick](https://github.com/dtolnay/semver-trick/) in order to make traits
4752
compatible across crate versions. (This is especially important for `RngCore`

rand_core/src/block.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl<R: BlockRngCore + fmt::Debug> fmt::Debug for BlockRng<R> {
131131
impl<R: BlockRngCore> BlockRng<R> {
132132
/// Create a new `BlockRng` from an existing RNG implementing
133133
/// `BlockRngCore`. Results will be generated on first use.
134+
#[inline]
134135
pub fn new(core: R) -> BlockRng<R>{
135136
let results_empty = R::Results::default();
136137
BlockRng {
@@ -145,18 +146,21 @@ impl<R: BlockRngCore> BlockRng<R> {
145146
/// If this is equal to or larger than the size of the result buffer then
146147
/// the buffer is "empty" and `generate()` must be called to produce new
147148
/// results.
149+
#[inline(always)]
148150
pub fn index(&self) -> usize {
149151
self.index
150152
}
151153

152154
/// Reset the number of available results.
153155
/// This will force a new set of results to be generated on next use.
156+
#[inline]
154157
pub fn reset(&mut self) {
155158
self.index = self.results.as_ref().len();
156159
}
157160

158161
/// Generate a new set of results immediately, setting the index to the
159162
/// given value.
163+
#[inline]
160164
pub fn generate_and_set(&mut self, index: usize) {
161165
assert!(index < self.results.as_ref().len());
162166
self.core.generate(&mut self.results);
@@ -167,7 +171,7 @@ impl<R: BlockRngCore> BlockRng<R> {
167171
impl<R: BlockRngCore<Item=u32>> RngCore for BlockRng<R>
168172
where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
169173
{
170-
#[inline(always)]
174+
#[inline]
171175
fn next_u32(&mut self) -> u32 {
172176
if self.index >= self.results.as_ref().len() {
173177
self.generate_and_set(0);
@@ -178,7 +182,7 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
178182
value
179183
}
180184

181-
#[inline(always)]
185+
#[inline]
182186
fn next_u64(&mut self) -> u64 {
183187
let read_u64 = |results: &[u32], index| {
184188
if cfg!(any(target_endian = "little")) {
@@ -210,6 +214,7 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
210214
}
211215
}
212216

217+
#[inline]
213218
fn fill_bytes(&mut self, dest: &mut [u8]) {
214219
let mut read_len = 0;
215220
while read_len < dest.len() {
@@ -225,23 +230,26 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
225230
}
226231
}
227232

233+
#[inline(always)]
228234
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
229-
self.fill_bytes(dest);
230-
Ok(())
235+
Ok(self.fill_bytes(dest))
231236
}
232237
}
233238

234239
impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng<R> {
235240
type Seed = R::Seed;
236241

242+
#[inline(always)]
237243
fn from_seed(seed: Self::Seed) -> Self {
238244
Self::new(R::from_seed(seed))
239245
}
240246

247+
#[inline(always)]
241248
fn seed_from_u64(seed: u64) -> Self {
242249
Self::new(R::seed_from_u64(seed))
243250
}
244251

252+
#[inline(always)]
245253
fn from_rng<S: RngCore>(rng: S) -> Result<Self, Error> {
246254
Ok(Self::new(R::from_rng(rng)?))
247255
}
@@ -296,6 +304,7 @@ impl<R: BlockRngCore + fmt::Debug> fmt::Debug for BlockRng64<R> {
296304
impl<R: BlockRngCore> BlockRng64<R> {
297305
/// Create a new `BlockRng` from an existing RNG implementing
298306
/// `BlockRngCore`. Results will be generated on first use.
307+
#[inline]
299308
pub fn new(core: R) -> BlockRng64<R>{
300309
let results_empty = R::Results::default();
301310
BlockRng64 {
@@ -311,19 +320,22 @@ impl<R: BlockRngCore> BlockRng64<R> {
311320
/// If this is equal to or larger than the size of the result buffer then
312321
/// the buffer is "empty" and `generate()` must be called to produce new
313322
/// results.
323+
#[inline(always)]
314324
pub fn index(&self) -> usize {
315325
self.index
316326
}
317327

318328
/// Reset the number of available results.
319329
/// This will force a new set of results to be generated on next use.
330+
#[inline]
320331
pub fn reset(&mut self) {
321332
self.index = self.results.as_ref().len();
322333
self.half_used = false;
323334
}
324335

325336
/// Generate a new set of results immediately, setting the index to the
326337
/// given value.
338+
#[inline]
327339
pub fn generate_and_set(&mut self, index: usize) {
328340
assert!(index < self.results.as_ref().len());
329341
self.core.generate(&mut self.results);
@@ -335,7 +347,7 @@ impl<R: BlockRngCore> BlockRng64<R> {
335347
impl<R: BlockRngCore<Item=u64>> RngCore for BlockRng64<R>
336348
where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
337349
{
338-
#[inline(always)]
350+
#[inline]
339351
fn next_u32(&mut self) -> u32 {
340352
let mut index = self.index * 2 - self.half_used as usize;
341353
if index >= self.results.as_ref().len() * 2 {
@@ -361,7 +373,7 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
361373
}
362374
}
363375

364-
#[inline(always)]
376+
#[inline]
365377
fn next_u64(&mut self) -> u64 {
366378
if self.index >= self.results.as_ref().len() {
367379
self.core.generate(&mut self.results);
@@ -374,6 +386,7 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
374386
value
375387
}
376388

389+
#[inline]
377390
fn fill_bytes(&mut self, dest: &mut [u8]) {
378391
let mut read_len = 0;
379392
self.half_used = false;
@@ -392,6 +405,7 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
392405
}
393406
}
394407

408+
#[inline(always)]
395409
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
396410
Ok(self.fill_bytes(dest))
397411
}
@@ -400,14 +414,17 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
400414
impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng64<R> {
401415
type Seed = R::Seed;
402416

417+
#[inline(always)]
403418
fn from_seed(seed: Self::Seed) -> Self {
404419
Self::new(R::from_seed(seed))
405420
}
406421

422+
#[inline(always)]
407423
fn seed_from_u64(seed: u64) -> Self {
408424
Self::new(R::seed_from_u64(seed))
409425
}
410426

427+
#[inline(always)]
411428
fn from_rng<S: RngCore>(rng: S) -> Result<Self, Error> {
412429
Ok(Self::new(R::from_rng(rng)?))
413430
}

rand_distr/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ travis-ci = { repository = "rust-random/rand" }
1919
appveyor = { repository = "rust-random/rand" }
2020

2121
[dependencies]
22-
rand = { path = "..", version = ">=0.5, <=0.7" }
22+
rand = { path = "..", version = ">=0.5, <=0.7.0-pre.9" }
2323

2424
[dev-dependencies]
2525
rand_pcg = { version = "0.1", path = "../rand_pcg" }

rand_hc/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.1.1] - 2019-06-06
8+
- Bump `rand_core` version
9+
- Adjust usage of `#[inline]`
10+
711
## [0.1.0] - 2018-10-17
812
- Pulled out of the Rand crate

rand_hc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_hc"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["The Rand Project Developers"]
55
license = "MIT/Apache-2.0"
66
readme = "README.md"
@@ -18,4 +18,4 @@ travis-ci = { repository = "rust-random/rand" }
1818
appveyor = { repository = "rust-random/rand" }
1919

2020
[dependencies]
21-
rand_core = { path = "../rand_core", version = "0.4" }
21+
rand_core = { path = "../rand_core", version = "0.5" }

rand_hc/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Links:
1919

2020
- [API documentation (master)](https://rust-random.github.io/rand/rand_hc)
2121
- [API documentation (docs.rs)](https://docs.rs/rand_hc)
22-
- [Changelog](CHANGELOG.md)
22+
- [Changelog](https://github.com/rust-random/rand/blob/master/rand_hc/CHANGELOG.md)
2323

2424
[rand]: https://crates.io/crates/rand
2525
[^1]: Hongjun Wu (2008). ["The Stream Cipher HC-128"](

rand_hc/src/hc128.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,22 @@ const SEED_WORDS: usize = 8; // 128 bit key followed by 128 bit iv
6767
pub struct Hc128Rng(BlockRng<Hc128Core>);
6868

6969
impl RngCore for Hc128Rng {
70-
#[inline(always)]
70+
#[inline]
7171
fn next_u32(&mut self) -> u32 {
7272
self.0.next_u32()
7373
}
7474

75-
#[inline(always)]
75+
#[inline]
7676
fn next_u64(&mut self) -> u64 {
7777
self.0.next_u64()
7878
}
7979

80+
#[inline]
8081
fn fill_bytes(&mut self, dest: &mut [u8]) {
8182
self.0.fill_bytes(dest)
8283
}
8384

85+
#[inline]
8486
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
8587
self.0.try_fill_bytes(dest)
8688
}
@@ -89,10 +91,12 @@ impl RngCore for Hc128Rng {
8991
impl SeedableRng for Hc128Rng {
9092
type Seed = <Hc128Core as SeedableRng>::Seed;
9193

94+
#[inline]
9295
fn from_seed(seed: Self::Seed) -> Self {
9396
Hc128Rng(BlockRng::<Hc128Core>::from_seed(seed))
9497
}
9598

99+
#[inline]
96100
fn from_rng<R: RngCore>(rng: R) -> Result<Self, Error> {
97101
BlockRng::<Hc128Core>::from_rng(rng).map(Hc128Rng)
98102
}
@@ -268,6 +272,7 @@ impl Hc128Core {
268272
// Initialize an HC-128 random number generator. The seed has to be
269273
// 256 bits in length (`[u32; 8]`), matching the 128 bit `key` followed by
270274
// 128 bit `iv` when HC-128 where to be used as a stream cipher.
275+
#[inline(always)] // single use: SeedableRng::from_seed
271276
fn init(seed: [u32; SEED_WORDS]) -> Self {
272277
#[inline]
273278
fn f1(x: u32) -> u32 {

rand_isaac/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.1.2] - 2019-06-06
8+
- Bump `rand_core` version
9+
- Remove deprecated code
10+
- Adjust usage of `#[inline]`
11+
712
## [0.1.1] - 2018-11-26
813
- Fix `rand_core` version requirement
914
- Fix doc links

0 commit comments

Comments
 (0)