Skip to content

Commit 5de081c

Browse files
authored
build(deps): update rand to v0.10 (#2987)
1 parent 254aca5 commit 5de081c

15 files changed

Lines changed: 127 additions & 87 deletions

File tree

dc/s2n-quic-dc/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ libc = "0.2"
4343
num-rational = { version = "0.4", default-features = false }
4444
once_cell = "1"
4545
pin-project-lite = "0.2"
46-
rand = { version = "0.9", features = ["small_rng"] }
47-
rand_chacha = "0.9"
46+
rand = "0.10"
4847
s2n-codec = { version = "=0.75.0", path = "../../common/s2n-codec", default-features = false }
49-
s2n-quic = { version = "=1.75.0", path = "../../quic/s2n-quic", features = ["unstable-provider-dc"] }
48+
s2n-quic = { version = "=1.75.0", path = "../../quic/s2n-quic", features = ["unstable-provider-dc", "unstable-provider-random"] }
5049
s2n-quic-core = { version = "=0.75.0", path = "../../quic/s2n-quic-core", default-features = false }
5150
s2n-quic-platform = { version = "=0.75.0", path = "../../quic/s2n-quic-platform" }
5251
s2n-tls = "0.3"

dc/s2n-quic-dc/src/path/secret/map/cleaner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
event::{self, EndpointPublisher as _},
77
path::secret::map::store::Store,
88
};
9-
use rand::Rng as _;
9+
use rand::RngExt as _;
1010
use s2n_quic_core::time;
1111
use std::{
1212
sync::{

dc/s2n-quic-dc/src/path/secret/receiver/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use super::*;
55
use crate::credentials::Id;
66
use bolero::{check, ValueGenerator};
7-
use rand::{seq::SliceRandom, Rng, SeedableRng};
7+
use rand::{seq::SliceRandom, RngExt, SeedableRng};
88
use std::collections::{binary_heap::PeekMut, BinaryHeap, HashSet};
99

1010
#[test]

dc/s2n-quic-dc/src/psk/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use super::{client, server};
55
use crate::path::secret;
66
use cfg_if::cfg_if;
7-
use rand::Rng;
7+
use rand::RngExt;
88
use s2n_quic::{
99
provider::{
1010
dc::{ConfirmComplete, MtuConfirmComplete},

dc/s2n-quic-dc/src/random.rs

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,53 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use rand::{rngs::ReseedingRng, RngCore};
5-
use rand_chacha::ChaChaCore;
4+
use rand::rand_core::TryRng;
65

76
pub use s2n_quic_core::random::*;
87

98
struct AwsLc;
109

11-
impl RngCore for AwsLc {
10+
impl TryRng for AwsLc {
11+
type Error = core::convert::Infallible;
12+
1213
#[inline]
13-
fn next_u32(&mut self) -> u32 {
14+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
1415
let mut v = [0; 4];
15-
self.fill_bytes(&mut v);
16-
u32::from_ne_bytes(v)
16+
aws_lc_rs::rand::fill(&mut v).unwrap();
17+
Ok(u32::from_ne_bytes(v))
1718
}
1819

1920
#[inline]
20-
fn next_u64(&mut self) -> u64 {
21+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
2122
let mut v = [0; 8];
22-
self.fill_bytes(&mut v);
23-
u64::from_ne_bytes(v)
23+
aws_lc_rs::rand::fill(&mut v).unwrap();
24+
Ok(u64::from_ne_bytes(v))
2425
}
2526

2627
#[inline]
27-
fn fill_bytes(&mut self, dest: &mut [u8]) {
28-
aws_lc_rs::rand::fill(dest).unwrap()
28+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
29+
aws_lc_rs::rand::fill(dest).unwrap();
30+
Ok(())
2931
}
3032
}
3133

32-
pub struct Random {
33-
public: ReseedingRng<ChaChaCore, AwsLc>,
34-
private: ReseedingRng<ChaChaCore, AwsLc>,
35-
}
34+
pub struct Random(s2n_quic::provider::random::Random<AwsLc>);
3635

3736
impl Default for Random {
3837
#[inline]
3938
fn default() -> Self {
40-
Self {
41-
public: build_rng(),
42-
private: build_rng(),
43-
}
39+
Self(s2n_quic::provider::random::Random::new(AwsLc, AwsLc))
4440
}
4541
}
4642

47-
// Constructs a `ReseedingRng` with a ChaCha RNG initially seeded from the OS,
48-
// that will reseed from the OS after RESEED_THRESHOLD is exceeded
49-
fn build_rng() -> ReseedingRng<ChaChaCore, AwsLc> {
50-
// Number of generated bytes after which to reseed the public and private random
51-
// generators.
52-
//
53-
// This value is based on THREAD_RNG_RESEED_THRESHOLD from
54-
// [rand::rngs::thread.rs](https://github.com/rust-random/rand/blob/ef75e56cf5824d33c55622bf84a70ec6e22761ba/src/rngs/thread.rs#L39)
55-
const RESEED_THRESHOLD: u64 = 1024 * 64;
56-
ReseedingRng::<ChaChaCore, AwsLc>::new(RESEED_THRESHOLD, AwsLc)
57-
.unwrap_or_else(|err| panic!("could not initialize random generator: {err}"))
58-
}
59-
6043
impl Generator for Random {
6144
#[inline]
6245
fn public_random_fill(&mut self, dest: &mut [u8]) {
63-
self.public.fill_bytes(dest);
46+
self.0.public_random_fill(dest);
6447
}
6548

6649
#[inline]
6750
fn private_random_fill(&mut self, dest: &mut [u8]) {
68-
self.private.fill_bytes(dest);
51+
self.0.private_random_fill(dest);
6952
}
7053
}

quic/s2n-quic-qns/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ futures = "0.3"
2222
http = "1.0"
2323
humansize = "2"
2424
lru = "0.16"
25-
rand = "0.9"
25+
rand = "0.10"
2626
s2n-codec = { path = "../../common/s2n-codec" }
2727
s2n-quic-core = { path = "../s2n-quic-core", features = ["testing"] }
2828
s2n-quic-h3 = { path = "../s2n-quic-h3" }

quic/s2n-quic-qns/src/intercept.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use lru::LruCache;
5-
use rand::{Rng as _, RngCore};
5+
use rand::Rng as _;
66
use s2n_codec::encoder::scatter;
77
use s2n_quic_core::{
88
event::api::Subject,
@@ -43,7 +43,7 @@ impl havoc::Random for Random {
4343
return start;
4444
}
4545

46-
rand::rng().random_range(start..end)
46+
rand::random_range(start..end)
4747
}
4848
}
4949

quic/s2n-quic-sim/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ indicatif = { version = "0.18", features = ["rayon"] }
1818
jiff = "0.2"
1919
once_cell = "1"
2020
prost = "0.14"
21-
rand = "0.9"
21+
rand = "0.10"
2222
rayon = "1"
2323
s2n-quic = { path = "../s2n-quic", features = ["unstable-provider-io-testing", "provider-event-tracing"] }
2424
s2n-quic-core = { path = "../s2n-quic-core", features = ["testing"] }

quic/s2n-quic-tests/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ publish = false
1414
bach = "0.1.0"
1515
bytes = { version = "1", default-features = false }
1616
futures = { version = "0.3", default-features = false, features = ["std"] }
17-
rand = "0.9"
18-
rand_chacha = "0.9"
17+
rand = { version = "0.10", features = ["chacha"] }
1918
s2n-codec = { path = "../../common/s2n-codec" }
2019
s2n-quic-core = { path = "../s2n-quic-core", features = ["branch-tracing", "event-tracing", "probe-tracing", "testing"] }
2120
s2n-quic = { path = "../s2n-quic", features = ["provider-event-tracing", "unstable-provider-io-testing", "unstable-provider-dc", "unstable-provider-packet-interceptor", "unstable-provider-random", "unstable-offload-tls"] }

quic/s2n-quic-tests/src/lib.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use rand::{
5+
rand_core::{Rng, SeedableRng, TryRng},
6+
rngs::ChaCha8Rng,
7+
RngExt,
8+
};
49
use s2n_quic::{
510
client::Connect,
611
provider::{
@@ -11,8 +16,6 @@ use s2n_quic::{
1116
Client, Server,
1217
};
1318
use s2n_quic_core::{crypto::tls::testing::certificates, havoc, stream::testing::Data};
14-
15-
use rand::{Rng, RngCore};
1619
use std::net::SocketAddr;
1720

1821
pub mod recorder;
@@ -281,39 +284,41 @@ pub fn build_client(handle: &Handle, network_env: Model, with_blocklist: bool) -
281284
}
282285

283286
pub struct Random {
284-
inner: rand_chacha::ChaCha8Rng,
287+
inner: ChaCha8Rng,
285288
}
286289

287290
impl Random {
288291
pub fn with_seed(seed: u64) -> Self {
289-
use rand::SeedableRng;
290292
Self {
291-
inner: rand_chacha::ChaCha8Rng::seed_from_u64(seed),
293+
inner: ChaCha8Rng::seed_from_u64(seed),
292294
}
293295
}
294296
}
295297

296298
impl havoc::Random for Random {
297299
fn fill(&mut self, bytes: &mut [u8]) {
298-
self.fill_bytes(bytes);
300+
Rng::fill_bytes(&mut self.inner, bytes);
299301
}
300302

301303
fn gen_range(&mut self, range: std::ops::Range<u64>) -> u64 {
302304
self.inner.random_range(range)
303305
}
304306
}
305307

306-
impl RngCore for Random {
307-
fn fill_bytes(&mut self, dest: &mut [u8]) {
308-
self.inner.fill_bytes(dest)
308+
impl TryRng for Random {
309+
type Error = core::convert::Infallible;
310+
311+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
312+
Ok(Rng::next_u32(&mut self.inner))
309313
}
310314

311-
fn next_u32(&mut self) -> u32 {
312-
self.inner.next_u32()
315+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
316+
Ok(Rng::next_u64(&mut self.inner))
313317
}
314318

315-
fn next_u64(&mut self) -> u64 {
316-
self.inner.next_u64()
319+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
320+
Rng::fill_bytes(&mut self.inner, dest);
321+
Ok(())
317322
}
318323
}
319324

@@ -329,11 +334,11 @@ impl s2n_quic::provider::random::Provider for Random {
329334

330335
impl s2n_quic::provider::random::Generator for Random {
331336
fn public_random_fill(&mut self, dest: &mut [u8]) {
332-
self.fill_bytes(dest);
337+
Rng::fill_bytes(self, dest);
333338
}
334339

335340
fn private_random_fill(&mut self, dest: &mut [u8]) {
336-
self.fill_bytes(dest);
341+
Rng::fill_bytes(self, dest);
337342
}
338343
}
339344

0 commit comments

Comments
 (0)