diff --git a/CHANGELOG.md b/CHANGELOG.md index f2f641a9d..93cf30860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- (hpke-rs-libcrux) [#1545](https://github.com/celabshq/libcrux/issues/1545): Use DRBG as the PRNG in the HPKE provider + ## [0.0.5] (2026-07-15) ### Fixed diff --git a/crates/protocols/hpke/libcrux_provider/Cargo.toml b/crates/protocols/hpke/libcrux_provider/Cargo.toml index 18ef6cca5..429f17bf6 100644 --- a/crates/protocols/hpke/libcrux_provider/Cargo.toml +++ b/crates/protocols/hpke/libcrux_provider/Cargo.toml @@ -16,6 +16,7 @@ libcrux-hkdf.workspace = true libcrux-kem.workspace = true libcrux-aead.workspace = true libcrux-traits.workspace = true +libcrux-hmac-drbg = { workspace = true, features = ["rand"] } # RustCrypto curves not available in libcrux # TODO: These should be replaced with libcrux implementations as soon as they # are available. diff --git a/crates/protocols/hpke/libcrux_provider/src/lib.rs b/crates/protocols/hpke/libcrux_provider/src/lib.rs index ecc7a9cbe..f1b3e5ef7 100644 --- a/crates/protocols/hpke/libcrux_provider/src/lib.rs +++ b/crates/protocols/hpke/libcrux_provider/src/lib.rs @@ -34,7 +34,7 @@ pub struct HpkeLibcrux {} pub struct HpkeLibcruxPrng { #[cfg(feature = "deterministic-prng")] fake_rng: Vec, - rng: rand_chacha::ChaCha20Rng, + rng: libcrux_hmac_drbg::HmacSha256DrbgRng>, } impl Zeroize for HpkeLibcruxPrng { @@ -358,15 +358,19 @@ impl HpkeCrypto for HpkeLibcrux { { let mut fake_rng = alloc::vec![0u8; 256]; rand_chacha::ChaCha20Rng::from_rng(&mut UnwrapErr(SysRng)).fill_bytes(&mut fake_rng); + let rng = UnwrapErr(SysRng); HpkeLibcruxPrng { fake_rng, - rng: rand_chacha::ChaCha20Rng::from_rng(&mut UnwrapErr(SysRng)), + rng: libcrux_hmac_drbg::HmacSha256DrbgRng::new(rng, &[0u8; 32]), } } #[cfg(not(feature = "deterministic-prng"))] - HpkeLibcruxPrng { - rng: rand_chacha::ChaCha20Rng::from_rng(&mut UnwrapErr(SysRng)), + { + let rng = UnwrapErr(SysRng); + HpkeLibcruxPrng { + rng: libcrux_hmac_drbg::HmacSha256DrbgRng::new(rng, &[0u8; 32]), + } } } diff --git a/crates/protocols/hpke/src/lib.rs b/crates/protocols/hpke/src/lib.rs index 59efaf99e..c077efaea 100644 --- a/crates/protocols/hpke/src/lib.rs +++ b/crates/protocols/hpke/src/lib.rs @@ -507,6 +507,23 @@ impl Hpke { } } + /// Set up the configuration for HPKE with a custom PRNG. + pub fn new_with_prng( + mode: Mode, + kem_id: KemAlgorithm, + kdf_id: KdfAlgorithm, + aead_id: AeadAlgorithm, + prng: Crypto::HpkePrng, + ) -> Self { + Self { + mode, + kem_id, + kdf_id, + aead_id, + prng, + } + } + /// Set up an HPKE sender. /// /// For the base and PSK modes this encapsulates the public key `pk_r`