Skip to content

Commit 041ad74

Browse files
committed
deps(rand): update rand and rand_core to 0.10
1 parent 3a3cb7c commit 041ad74

File tree

19 files changed

+306
-95
lines changed

19 files changed

+306
-95
lines changed

Cargo.lock

Lines changed: 248 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ hybrid-array = { version = "0.4.7", features = ["bytemuck"] }
3333
libc = "0.2.169"
3434
ndarray = "0.17.2"
3535
num-traits = "0.2.19"
36-
rand = "0.9.0"
37-
rand_core = "0.9.0"
36+
rand = "0.10.0"
37+
rand_core = "0.10.0"
3838
rand_core_0_6 = { package = "rand_core", version = "0.6" }
3939
rayon = "1.10.0"
4040
s2n-quic = "1.37.0"

cryprot-codes/benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bytemuck::cast_slice_mut;
22
use criterion::{Criterion, criterion_group, criterion_main};
33
use cryprot_codes::ex_conv::ExConvCode;
44
use cryprot_core::{Block, buf::Buf};
5-
use rand::{RngCore, rng};
5+
use rand::{Rng, rng};
66

77
fn criterion_benchmark(c: &mut Criterion) {
88
{

cryprot-codes/src/ex_conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ mod tests {
286286
use bytemuck::cast_slice_mut;
287287
use cryprot_core::block::Block;
288288
#[cfg(feature = "libote-compat")]
289-
use rand::{RngCore, SeedableRng, rngs::StdRng};
289+
use rand::{Rng, SeedableRng, rngs::StdRng};
290290

291291
use super::*;
292292

cryprot-codes/src/ex_conv/expander.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl ExpanderCode {
129129
#[cfg(test)]
130130
mod tests {
131131
use bytemuck::cast_slice_mut;
132-
use rand::{RngCore, SeedableRng, rngs::StdRng};
132+
use rand::{Rng, SeedableRng, rngs::StdRng};
133133

134134
use super::*;
135135

cryprot-codes/src/ex_conv/expander_modd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl ExpanderModd {
9595

9696
#[cfg(test)]
9797
mod tests {
98-
use rand::{Rng, SeedableRng, rngs::StdRng};
98+
use rand::{RngExt, SeedableRng, rngs::StdRng};
9999

100100
use super::*;
101101

cryprot-codes/src/ex_conv/fast_aes_rng.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bytemuck::{cast_mut, cast_ref, cast_slice, cast_slice_mut};
22
use cryprot_core::{Block, aes_rng::AesRng};
3-
use rand::{RngCore, SeedableRng};
3+
use rand::{Rng, SeedableRng};
44

55
// Simple PRNG implementation for the accumulator
66
pub(crate) struct FastAesRng {

cryprot-core/benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cryprot_core::{
66
buf::Buf,
77
transpose::{avx2, portable},
88
};
9-
use rand::{RngCore, rng};
9+
use rand::{Rng, rng};
1010

1111
fn criterion_benchmark(c: &mut Criterion) {
1212
let rows = 128;

cryprot-core/src/aes_rng.rs

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ use aes::{
1515
Aes128,
1616
cipher::{BlockCipherEncrypt, KeyInit},
1717
};
18-
use rand::{CryptoRng, Rng, RngCore, SeedableRng};
19-
use rand_core::block::{BlockRng, BlockRngCore, CryptoBlockRng};
18+
use rand::{RngExt, SeedableRng};
19+
use rand_core::{
20+
TryCryptoRng, TryRng,
21+
block::{BlockRng, Generator},
22+
};
2023

2124
use crate::{AES_PAR_BLOCKS, Block};
2225

@@ -28,23 +31,25 @@ use crate::{AES_PAR_BLOCKS, Block};
2831
#[derive(Clone, Debug)]
2932
pub struct AesRng(BlockRng<AesRngCore>);
3033

31-
impl RngCore for AesRng {
34+
impl TryRng for AesRng {
35+
type Error = core::convert::Infallible;
36+
3237
#[inline]
33-
fn next_u32(&mut self) -> u32 {
34-
self.0.next_u32()
38+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
39+
Ok(self.0.next_word())
3540
}
3641

3742
#[inline]
38-
fn next_u64(&mut self) -> u64 {
39-
self.0.next_u64()
43+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
44+
Ok(self.0.next_u64_from_u32())
4045
}
4146

4247
#[inline]
43-
fn fill_bytes(&mut self, dest: &mut [u8]) {
48+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
4449
let block_size = mem::size_of::<aes::Block>();
4550
let block_len = dest.len() / block_size * block_size;
4651
let (block_bytes, rest_bytes) = dest.split_at_mut(block_len);
47-
// fast path so we don't unnecessarily copy u32 from BlockRngCore::generate into
52+
// fast path so we don't unnecessarily copy u32 from Generator::generate into
4853
// dest
4954
let blocks = bytemuck::cast_slice_mut::<_, aes::Block>(block_bytes);
5055
for chunk in blocks.chunks_mut(AES_PAR_BLOCKS) {
@@ -55,7 +60,8 @@ impl RngCore for AesRng {
5560
self.0.core.aes.encrypt_blocks(chunk);
5661
}
5762
// handle the tail
58-
self.0.fill_bytes(rest_bytes)
63+
self.0.fill_bytes(rest_bytes);
64+
Ok(())
5965
}
6066
}
6167

@@ -64,11 +70,11 @@ impl SeedableRng for AesRng {
6470

6571
#[inline]
6672
fn from_seed(seed: Self::Seed) -> Self {
67-
AesRng(BlockRng::<AesRngCore>::from_seed(seed))
73+
AesRng(BlockRng::new(AesRngCore::from_seed(seed)))
6874
}
6975
}
7076

71-
impl CryptoRng for AesRng {}
77+
impl TryCryptoRng for AesRng {}
7278

7379
impl AesRng {
7480
/// Create a new random number generator using a random seed from
@@ -107,15 +113,14 @@ impl std::fmt::Debug for AesRngCore {
107113
}
108114
}
109115

110-
impl BlockRngCore for AesRngCore {
111-
type Item = u32;
112-
// This is equivalent to `[Block; 9]`
113-
type Results = hidden::ParBlockWrapper;
116+
impl Generator for AesRngCore {
117+
// This is equivalent to `[aes::Block; AES_PAR_BLOCKS]`
118+
type Output = [u32; AES_PAR_BLOCKS * std::mem::size_of::<u32>()];
114119

115120
// Compute `E(state)` nine times, where `state` is a counter.
116121
#[inline]
117-
fn generate(&mut self, results: &mut Self::Results) {
118-
let blocks = bytemuck::cast_slice_mut::<_, aes::Block>(results.as_mut());
122+
fn generate(&mut self, results: &mut Self::Output) {
123+
let blocks = bytemuck::cast_slice_mut::<_, aes::Block>(results);
119124
blocks.iter_mut().for_each(|blk| {
120125
// aes::Block is a type alias to Array, but type aliases can't be used as
121126
// constructors
@@ -126,32 +131,6 @@ impl BlockRngCore for AesRngCore {
126131
}
127132
}
128133

129-
mod hidden {
130-
/// Equivalent to [aes::Block; 9] (which is the parralel block size for the
131-
/// aes-ni backend). Since size 36 arrays don't impl Default we write a
132-
/// wrapper.
133-
#[derive(Copy, Clone)]
134-
pub struct ParBlockWrapper([u32; 36]);
135-
136-
impl Default for ParBlockWrapper {
137-
fn default() -> Self {
138-
Self([0; 36])
139-
}
140-
}
141-
142-
impl AsMut<[u32]> for ParBlockWrapper {
143-
fn as_mut(&mut self) -> &mut [u32] {
144-
&mut self.0
145-
}
146-
}
147-
148-
impl AsRef<[u32]> for ParBlockWrapper {
149-
fn as_ref(&self) -> &[u32] {
150-
&self.0
151-
}
152-
}
153-
}
154-
155134
impl SeedableRng for AesRngCore {
156135
type Seed = Block;
157136

@@ -165,8 +144,6 @@ impl SeedableRng for AesRngCore {
165144
}
166145
}
167146

168-
impl CryptoBlockRng for AesRngCore {}
169-
170147
impl From<AesRngCore> for AesRng {
171148
#[inline]
172149
fn from(core: AesRngCore) -> Self {

cryprot-core/src/block/gf128.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ mod clmul {
224224

225225
use std::{hint::black_box, mem::transmute};
226226

227-
use rand::{Rng, rng};
227+
use rand::{RngExt, rng};
228228
use test::Bencher;
229229

230230
#[bench]
@@ -443,7 +443,7 @@ mod scalar {
443443
extern crate test;
444444

445445
use criterion::black_box;
446-
use rand::{Rng, rng};
446+
use rand::{RngExt, rng};
447447
use test::Bencher;
448448

449449
#[bench]
@@ -466,7 +466,7 @@ mod scalar {
466466
mod scalar_simd_tests {
467467
use std::mem::transmute;
468468

469-
use rand::{Rng, rng};
469+
use rand::{RngExt, rng};
470470

471471
use super::{clmul, scalar};
472472

0 commit comments

Comments
 (0)