Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ exclude = [
resolver = "2"

[patch.crates-io]
rand_core = { git = "https://github.com/rust-random/rand_core.git", branch = "reduce-block-code" }
rand_core = { git = "https://github.com/rust-random/rand_core.git" }
5 changes: 2 additions & 3 deletions rand_hc/src/hc128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use core::fmt;
use rand_core::block::{BlockRng, CryptoGenerator, Generator};
use rand_core::{CryptoRng, RngCore, SeedableRng, le};
use rand_core::{CryptoRng, RngCore, SeedableRng, utils};

const SEED_WORDS: usize = 8; // 128 bit key followed by 128 bit iv

Expand Down Expand Up @@ -335,8 +335,7 @@ impl SeedableRng for Hc128Core {
/// 256 bits in length, matching the 128 bit `key` followed by 128 bit `iv`
/// when HC-128 where to be used as a stream cipher.
fn from_seed(seed: Self::Seed) -> Self {
let mut seed_u32 = [0u32; SEED_WORDS];
le::read_u32_into(&seed, &mut seed_u32);
let seed_u32: [u32; SEED_WORDS] = utils::read_words(&seed);
Self::init(seed_u32)
}
}
Expand Down
5 changes: 2 additions & 3 deletions rand_isaac/src/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use core::num::Wrapping as w;
use core::{fmt, slice};
use rand_core::block::{BlockRng, Generator};
use rand_core::{RngCore, SeedableRng, TryRngCore, le};
use rand_core::{RngCore, SeedableRng, TryRngCore, utils};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -343,8 +343,7 @@ impl SeedableRng for IsaacCore {
type Seed = [u8; 32];

fn from_seed(seed: Self::Seed) -> Self {
let mut seed_u32 = [0u32; 8];
le::read_u32_into(&seed, &mut seed_u32);
let seed_u32: [u32; 8] = utils::read_words(&seed);
// Convert the seed to `Wrapping<u32>` and zero-extend to `RAND_SIZE`.
let mut seed_extended = [w(0); RAND_SIZE];
for (x, y) in seed_extended.iter_mut().zip(seed_u32.iter()) {
Expand Down
5 changes: 2 additions & 3 deletions rand_isaac/src/isaac64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use core::num::Wrapping as w;
use core::{fmt, slice};
use rand_core::block::{BlockRng, Generator};
use rand_core::{RngCore, SeedableRng, TryRngCore, le};
use rand_core::{RngCore, SeedableRng, TryRngCore, utils};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -309,8 +309,7 @@ impl SeedableRng for Isaac64Core {
type Seed = [u8; 32];

fn from_seed(seed: Self::Seed) -> Self {
let mut seed_u64 = [0u64; 4];
le::read_u64_into(&seed, &mut seed_u64);
let seed_u64: [u64; 4] = utils::read_words(&seed);
// Convert the seed to `Wrapping<u64>` and zero-extend to `RAND_SIZE`.
let mut seed_extended = [w(0); RAND_SIZE];
for (x, y) in seed_extended.iter_mut().zip(seed_u64.iter()) {
Expand Down
4 changes: 2 additions & 2 deletions rand_jitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod error;
mod platform;

pub use crate::error::TimerError;
use rand_core::{RngCore, le};
use rand_core::{RngCore, utils};

use core::{fmt, mem, ptr};
#[cfg(feature = "std")]
Expand Down Expand Up @@ -760,6 +760,6 @@ where
//
// This is done especially for wrappers that implement `next_u32`
// themselves via `fill_bytes`.
le::fill_bytes_via_next(self, dest)
utils::fill_bytes_via_next_word(dest, || self.next_u64())
}
}
7 changes: 3 additions & 4 deletions rand_sfc/src/sfc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
use rand_core::utils::{fill_bytes_via_next_word, next_u64_via_u32, read_words};
use rand_core::{RngCore, SeedableRng};

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -60,7 +60,7 @@ impl RngCore for Sfc32 {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand All @@ -73,8 +73,7 @@ impl SeedableRng for Sfc32 {

/// Create a new `Sfc32`.
fn from_seed(seed: [u8; 12]) -> Sfc32 {
let mut s = [0; 3];
read_u32_into(&seed, &mut s);
let s: [u32; 3] = read_words(&seed);

let mut rng = Sfc32 {
a: s[0],
Expand Down
7 changes: 3 additions & 4 deletions rand_sfc/src/sfc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, read_u64_into};
use rand_core::utils::{fill_bytes_via_next_word, read_words};
use rand_core::{RngCore, SeedableRng};

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -63,7 +63,7 @@ impl RngCore for Sfc64 {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand All @@ -76,8 +76,7 @@ impl SeedableRng for Sfc64 {

/// Create a new `Sfc64`.
fn from_seed(seed: [u8; 24]) -> Sfc64 {
let mut s = [0; 3];
read_u64_into(&seed, &mut s);
let s: [u64; 3] = read_words(&seed);

let mut rng = Sfc64 {
a: s[0],
Expand Down
9 changes: 4 additions & 5 deletions rand_xorshift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

use core::fmt;
use core::num::Wrapping as w;
use rand_core::{RngCore, SeedableRng, TryRngCore, le};
use rand_core::{RngCore, SeedableRng, TryRngCore, utils};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -82,21 +82,20 @@ impl RngCore for XorShiftRng {

#[inline]
fn next_u64(&mut self) -> u64 {
le::next_u64_via_u32(self)
utils::next_u64_via_u32(self)
}

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
le::fill_bytes_via_next(self, dest)
utils::fill_bytes_via_next_word(dest, || self.next_u64())
}
}

impl SeedableRng for XorShiftRng {
type Seed = [u8; 16];

fn from_seed(seed: Self::Seed) -> Self {
let mut seed_u32 = [0u32; 4];
le::read_u32_into(&seed, &mut seed_u32);
let mut seed_u32: [u32; 4] = utils::read_words(&seed);

// Xorshift cannot be seeded with 0 and we cannot return an Error, but
// also do not wish to panic (because a random seed can legitimately be
Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/splitmix64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, read_u64_into};
use rand_core::utils::{fill_bytes_via_next_word, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -54,7 +54,7 @@ impl RngCore for SplitMix64 {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand All @@ -63,8 +63,7 @@ impl SeedableRng for SplitMix64 {

/// Create a new `SplitMix64`.
fn from_seed(seed: [u8; 8]) -> SplitMix64 {
let mut state = [0; 1];
read_u64_into(&seed, &mut state);
let state: [u64; 1] = read_words(&seed);
SplitMix64 { x: state[0] }
}

Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/xoroshiro128plus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, read_u64_into};
use rand_core::utils::{fill_bytes_via_next_word, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -75,7 +75,7 @@ impl RngCore for Xoroshiro128Plus {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}
impl SeedableRng for Xoroshiro128Plus {
Expand All @@ -85,8 +85,7 @@ impl SeedableRng for Xoroshiro128Plus {
/// mapped to a different seed.
fn from_seed(seed: [u8; 16]) -> Xoroshiro128Plus {
deal_with_zero_seed!(seed, Self, 16);
let mut s = [0; 2];
read_u64_into(&seed, &mut s);
let s: [u64; 2] = read_words(&seed);

Xoroshiro128Plus { s0: s[0], s1: s[1] }
}
Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/xoroshiro128plusplus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, read_u64_into};
use rand_core::utils::{fill_bytes_via_next_word, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -72,7 +72,7 @@ impl RngCore for Xoroshiro128PlusPlus {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand All @@ -83,8 +83,7 @@ impl SeedableRng for Xoroshiro128PlusPlus {
/// mapped to a different seed.
fn from_seed(seed: [u8; 16]) -> Xoroshiro128PlusPlus {
deal_with_zero_seed!(seed, Self, 16);
let mut s = [0; 2];
read_u64_into(&seed, &mut s);
let s: [u64; 2] = read_words(&seed);

Xoroshiro128PlusPlus { s0: s[0], s1: s[1] }
}
Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/xoroshiro128starstar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, read_u64_into};
use rand_core::utils::{fill_bytes_via_next_word, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -72,7 +72,7 @@ impl RngCore for Xoroshiro128StarStar {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand All @@ -83,8 +83,7 @@ impl SeedableRng for Xoroshiro128StarStar {
/// mapped to a different seed.
fn from_seed(seed: [u8; 16]) -> Xoroshiro128StarStar {
deal_with_zero_seed!(seed, Self, 16);
let mut s = [0; 2];
read_u64_into(&seed, &mut s);
let s: [u64; 2] = read_words(&seed);

Xoroshiro128StarStar { s0: s[0], s1: s[1] }
}
Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/xoroshiro64star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
use rand_core::utils::{fill_bytes_via_next_word, next_u64_via_u32, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -43,7 +43,7 @@ impl RngCore for Xoroshiro64Star {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand All @@ -54,8 +54,7 @@ impl SeedableRng for Xoroshiro64Star {
/// mapped to a different seed.
fn from_seed(seed: [u8; 8]) -> Xoroshiro64Star {
deal_with_zero_seed!(seed, Self, 8);
let mut s = [0; 2];
read_u32_into(&seed, &mut s);
let s: [u32; 2] = read_words(&seed);

Xoroshiro64Star { s0: s[0], s1: s[1] }
}
Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/xoroshiro64starstar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
use rand_core::utils::{fill_bytes_via_next_word, next_u64_via_u32, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -42,7 +42,7 @@ impl RngCore for Xoroshiro64StarStar {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand All @@ -53,8 +53,7 @@ impl SeedableRng for Xoroshiro64StarStar {
/// mapped to a different seed.
fn from_seed(seed: [u8; 8]) -> Xoroshiro64StarStar {
deal_with_zero_seed!(seed, Self, 8);
let mut s = [0; 2];
read_u32_into(&seed, &mut s);
let s: [u32; 2] = read_words(&seed);

Xoroshiro64StarStar { s0: s[0], s1: s[1] }
}
Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/xoshiro128plus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
use rand_core::utils::{fill_bytes_via_next_word, next_u64_via_u32, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -64,8 +64,7 @@ impl SeedableRng for Xoshiro128Plus {
#[inline]
fn from_seed(seed: [u8; 16]) -> Xoshiro128Plus {
deal_with_zero_seed!(seed, Self, 16);
let mut state = [0; 4];
read_u32_into(&seed, &mut state);
let state: [u32; 4] = read_words(&seed);
Xoshiro128Plus { s: state }
}

Expand All @@ -90,7 +89,7 @@ impl RngCore for Xoshiro128Plus {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand Down
7 changes: 3 additions & 4 deletions rand_xoshiro/src/xoshiro128plusplus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
use rand_core::utils::{fill_bytes_via_next_word, next_u64_via_u32, read_words};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -63,8 +63,7 @@ impl SeedableRng for Xoshiro128PlusPlus {
#[inline]
fn from_seed(seed: [u8; 16]) -> Xoshiro128PlusPlus {
deal_with_zero_seed!(seed, Self, 16);
let mut state = [0; 4];
read_u32_into(&seed, &mut state);
let state: [u32; 4] = read_words(&seed);
Xoshiro128PlusPlus { s: state }
}

Expand All @@ -89,7 +88,7 @@ impl RngCore for Xoshiro128PlusPlus {

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
fill_bytes_via_next(self, dest);
fill_bytes_via_next_word(dest, || self.next_u64());
}
}

Expand Down
Loading