Skip to content

Commit 5bf5b1d

Browse files
committed
chore(deps): bump rand_core to 0.10.0-rc-5
1 parent 525c630 commit 5bf5b1d

11 files changed

Lines changed: 65 additions & 49 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 10 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ debug = true
1212

1313
[patch.crates-io]
1414
ml-kem = { path = "./ml-kem" }
15+
16+
x25519-dalek = { git = "https://github.com/baloo/curve25519-dalek.git", branch = "baloo/push-lpxummypqqox" }

dhkem/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ readme = "README.md"
1515

1616
[dependencies]
1717
kem = "0.4.0-rc.2"
18-
rand_core = "0.10.0-rc-3"
18+
rand_core = "0.10.0-rc-5"
1919

2020
# optional dependencies
2121
elliptic-curve = { version = "0.14.0-rc.21", optional = true, default-features = false }

dhkem/src/x25519_kem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{DhDecapsulator, DhEncapsulator, DhKem};
22
use core::convert::Infallible;
33
use kem::{Decapsulate, Encapsulate};
4-
use rand_core::{CryptoRng, TryCryptoRng};
4+
use rand_core::{CryptoRng, TryCryptoRng, UnwrapErr};
55
use x25519::{PublicKey, ReusableSecret, SharedSecret};
66

77
/// X22519 Diffie-Hellman KEM adapter.
@@ -17,7 +17,7 @@ impl Encapsulate<PublicKey, SharedSecret> for DhEncapsulator<PublicKey> {
1717
rng: &mut R,
1818
) -> Result<(PublicKey, SharedSecret), Self::Error> {
1919
// ECDH encapsulation involves creating a new ephemeral key pair and then doing DH
20-
let sk = ReusableSecret::random_from_rng(&mut rng.unwrap_mut());
20+
let sk = ReusableSecret::random_from_rng(&mut UnwrapErr(rng));
2121
let pk = PublicKey::from(&sk);
2222
let ss = sk.diffie_hellman(&self.0);
2323

dhkem/tests/hpke_p256_test.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
#![cfg(feature = "p256")]
22

3+
use core::convert::Infallible;
34
use dhkem::{DhKem, NistP256Kem};
45
use elliptic_curve::sec1::ToEncodedPoint;
56
use hex_literal::hex;
67
use hkdf::Hkdf;
78
use kem::{Decapsulate, Encapsulate};
8-
use rand_core::{CryptoRng, RngCore};
9+
use rand_core::{TryCryptoRng, TryRngCore};
910
use sha2::Sha256;
1011

1112
/// Constant RNG for testing purposes only.
1213
struct ConstantRng<'a>(pub &'a [u8]);
1314

14-
impl RngCore for ConstantRng<'_> {
15-
fn next_u32(&mut self) -> u32 {
15+
impl TryRngCore for ConstantRng<'_> {
16+
type Error = Infallible;
17+
18+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
1619
let (head, tail) = self.0.split_at(4);
1720
self.0 = tail;
18-
u32::from_be_bytes(head.try_into().unwrap())
21+
Ok(u32::from_be_bytes(head.try_into().unwrap()))
1922
}
2023

21-
fn next_u64(&mut self) -> u64 {
24+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
2225
let (head, tail) = self.0.split_at(8);
2326
self.0 = tail;
24-
u64::from_be_bytes(head.try_into().unwrap())
27+
Ok(u64::from_be_bytes(head.try_into().unwrap()))
2528
}
2629

27-
fn fill_bytes(&mut self, dest: &mut [u8]) {
30+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
2831
let (hd, tl) = self.0.split_at(dest.len());
2932
dest.copy_from_slice(hd);
3033
self.0 = tl;
34+
Ok(())
3135
}
3236
}
3337

3438
// this is only ever ok for testing
35-
impl CryptoRng for ConstantRng<'_> {}
39+
impl TryCryptoRng for ConstantRng<'_> {}
3640

3741
fn labeled_extract(salt: &[u8], label: &[u8], ikm: &[u8]) -> Vec<u8> {
3842
let labeled_ikm = [b"HPKE-v1".as_slice(), b"KEM\x00\x10".as_slice(), label, ikm].concat();

frodo-kem/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ serde = ["dep:hex", "dep:serde"]
5858
aes = { version = "0.9.0-rc.2", optional = true }
5959
hex = { version = "0.4", optional = true }
6060
openssl-sys = { version = "0.9.104", optional = true }
61-
rand_core = { version = "0.10.0-rc-3", features = [] }
61+
rand_core = { version = "0.10.0-rc-5", features = [] }
6262
serde = { version = "1.0", features = ["derive"], optional = true }
6363
serdect = "0.4"
6464
subtle = "2.6"
@@ -83,7 +83,7 @@ criterion = "0.7"
8383
getrandom = { version = "0.4.0-rc.0", features = ["sys_rng"] }
8484
hex = "0.4"
8585
hybrid-array = "0.4"
86-
chacha20 = { version = "0.10.0-rc.6", features = ["rng"] }
86+
chacha20 = { version = "0.10.0-rc.7", features = ["rng"] }
8787
rstest = "0.26"
8888
postcard = { version = "1.0", features = ["use-std"] }
8989
serde_bare = "0.5"

frodo-kem/tests/rng.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use aes::{
44
Aes256Enc, Block,
55
cipher::{BlockCipherEncrypt, KeyInit},
66
};
7+
use core::convert::Infallible;
78
use hybrid_array::{Array, typenum::U48};
8-
use rand_core::{CryptoRng, RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, TryCryptoRng, TryRngCore};
910

1011
/// Seed type for the AES-CTR DRBG
1112
pub type RngSeed = Array<u8, U48>;
@@ -29,20 +30,22 @@ impl SeedableRng for AesCtrDrbg {
2930
}
3031
}
3132

32-
impl RngCore for AesCtrDrbg {
33-
fn next_u32(&mut self) -> u32 {
33+
impl TryRngCore for AesCtrDrbg {
34+
type Error = Infallible;
35+
36+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
3437
let mut int = [0u8; 4];
3538
self.fill_bytes(&mut int);
36-
u32::from_le_bytes(int)
39+
Ok(u32::from_le_bytes(int))
3740
}
3841

39-
fn next_u64(&mut self) -> u64 {
42+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
4043
let mut int = [0u8; 8];
4144
self.fill_bytes(&mut int);
42-
u64::from_le_bytes(int)
45+
Ok(u64::from_le_bytes(int))
4346
}
4447

45-
fn fill_bytes(&mut self, dest: &mut [u8]) {
48+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
4649
let mut in_block = Block::default();
4750
let mut out_block = Block::default();
4851
let enc = Aes256Enc::new_from_slice(&self.key).unwrap();
@@ -64,10 +67,11 @@ impl RngCore for AesCtrDrbg {
6467

6568
self.update(None);
6669
self.reseed_counter += 1;
70+
Ok(())
6771
}
6872
}
6973

70-
impl CryptoRng for AesCtrDrbg {}
74+
impl TryCryptoRng for AesCtrDrbg {}
7175

7276
impl AesCtrDrbg {
7377
/// Reseed the DRBG with a new seed

ml-kem/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ zeroize = ["dep:zeroize"]
2727
[dependencies]
2828
kem = "0.4.0-rc.2"
2929
hybrid-array = { version = "0.4.4", features = ["extra-sizes", "subtle"] }
30-
rand_core = "0.10.0-rc-3"
30+
rand_core = "0.10.0-rc-5"
3131
sha3 = { version = "0.11.0-rc.3", default-features = false }
3232
subtle = { version = "2", default-features = false }
3333

ml-kem/tests/pkcs8.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use pkcs8::{
1111
asn1::{ContextSpecific, OctetStringRef},
1212
},
1313
};
14-
use rand_core::{CryptoRng, TryRngCore};
14+
use rand_core::{RngCore, TryCryptoRng, TryRngCore};
1515

1616
/// ML-KEM seed serialized as ASN.1.
1717
type SeedString<'a> = ContextSpecific<&'a OctetStringRef>;
@@ -111,28 +111,31 @@ where
111111
seed: [u8; SEED_LEN],
112112
}
113113

114-
impl rand_core::RngCore for SeedBasedRng {
115-
fn next_u32(&mut self) -> u32 {
114+
impl rand_core::TryRngCore for SeedBasedRng {
115+
type Error = core::convert::Infallible;
116+
117+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
116118
let mut buf = [0u8; 4];
117119
self.fill_bytes(&mut buf);
118-
u32::from_be_bytes(buf)
120+
Ok(u32::from_be_bytes(buf))
119121
}
120122

121-
fn next_u64(&mut self) -> u64 {
123+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
122124
let mut buf = [0u8; 8];
123125
self.fill_bytes(&mut buf);
124-
u64::from_be_bytes(buf)
126+
Ok(u64::from_be_bytes(buf))
125127
}
126128

127-
fn fill_bytes(&mut self, dst: &mut [u8]) {
129+
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
128130
for item in dst {
129131
*item = self.seed[self.index];
130132
self.index = self.index.wrapping_add(1) & ((1 << SEED_LEN.ilog2()) - 1);
131133
}
134+
Ok(())
132135
}
133136
}
134137

135-
impl CryptoRng for SeedBasedRng {}
138+
impl TryCryptoRng for SeedBasedRng {}
136139

137140
const SEED_LEN: usize = 64;
138141
assert_eq!(SEED_LEN & (SEED_LEN - 1), 0);

x-wing/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ zeroize = ["dep:zeroize", "ml-kem/zeroize", "x25519-dalek/zeroize"]
1919
[dependencies]
2020
kem = "0.4.0-rc.2"
2121
ml-kem = { version = "=0.3.0-pre.3", default-features = false, features = ["deterministic"] }
22-
rand_core = { version = "0.10.0-rc-3", default-features = false }
22+
rand_core = { version = "0.10.0-rc-5", default-features = false }
2323
sha3 = { version = "0.11.0-rc.3", default-features = false }
2424
x25519-dalek = { version = "=3.0.0-pre.4", default-features = false, features = ["static_secrets"] }
2525

@@ -29,7 +29,7 @@ zeroize = { version = "1.8.1", optional = true, default-features = true, feature
2929
[dev-dependencies]
3030
getrandom = { version = "0.4.0-rc.0", features = ["sys_rng"] }
3131
hex = { version = "0.4", features = ["serde"] }
32-
rand_core = "0.10.0-rc-3"
32+
rand_core = "0.10.0-rc-5"
3333
serde = { version = "1.0", features = ["derive"] }
3434
serde_json = "1.0"
3535

0 commit comments

Comments
 (0)