Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/protocols/hpke/libcrux_provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions crates/protocols/hpke/libcrux_provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct HpkeLibcrux {}
pub struct HpkeLibcruxPrng {
#[cfg(feature = "deterministic-prng")]
fake_rng: Vec<u8>,
rng: rand_chacha::ChaCha20Rng,
rng: libcrux_hmac_drbg::HmacSha256DrbgRng<UnwrapErr<SysRng>>,
}

impl Zeroize for HpkeLibcruxPrng {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment in here doesn't make sense anymore.

Expand Down Expand Up @@ -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]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use some const bytes for the personalization. Something towards b"libcrux hpke".

}
}
}

Expand Down
17 changes: 17 additions & 0 deletions crates/protocols/hpke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,23 @@ impl<Crypto: HpkeCrypto> Hpke<Crypto> {
}
}

/// 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`
Expand Down