Skip to content

use hmac-drbg as prng in libcrux provider (#1545) - #1546

Open
Arul-Sujith wants to merge 1 commit into
celabshq:mainfrom
Arul-Sujith:feat-hpke-drbg
Open

use hmac-drbg as prng in libcrux provider (#1545)#1546
Arul-Sujith wants to merge 1 commit into
celabshq:mainfrom
Arul-Sujith:feat-hpke-drbg

Conversation

@Arul-Sujith

Copy link
Copy Markdown
Contributor

This PR updates the hpke-rs-libcrux crypto provider to use the newly restored libcrux-hmac-drbg as its pseudo-random number generator,.

Changes

  • Dependency Update: Added libcrux-hmac-drbg (with the rand feature) to crates/protocols/hpke/libcrux_provider/Cargo.toml.
  • PRNG Swap: Upgraded HpkeLibcruxPrng to store HmacSha256DrbgRng<rand_chacha::ChaCha20Rng> instead of just ChaCha20Rng.
  • Initialization: Configured the new DRBG inside the prng() factory method, using the existing OS-seeded ChaCha20Rng as the underlying entropy source for automatic reseeding, and an empty array &[0u8; 32] for the personalization string.
  • Changelog: Logged the HPKE DRBG integration in CHANGELOG.md.

All local tests, HPKE integration tests, KATs, and the broader workspace successfully compile and pass.

Fixes #1545


AI Disclosure: Used an LLM to assist with this PR. Apply the DRBG struct replacement within the HPKE provider, and generate this PR description. Manually reviewed the modifications and ran the workspace test suite to verify the changes.

@franziskuskiefer franziskuskiefer left a comment

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.

Thanks for the contribution.

I think we should use a slightly different setup.
While you're at it. You could also add a function next to Hpke::new that allows passing in an rng. That would make the entire thing a little more flexible.

Comment thread CHANGELOG.md Outdated

### Changed

- (hpke-rs-libcrux) [#1545](https://github.com/celabshq/libcrux/issues/1545): Use DRBG as the PRNG in the HPKE provider

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.

This should go into the unreleased section.

#[cfg(feature = "deterministic-prng")]
fake_rng: Vec<u8>,
rng: rand_chacha::ChaCha20Rng,
rng: libcrux_hmac_drbg::HmacSha256DrbgRng<rand_chacha::ChaCha20Rng>,

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.

I don't think need another rng in here. We just need something that collects entropy for reseeding. The SysRng is good for that. That way we can get rid of the chacha20rng.

@Arul-Sujith

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

  • Moved the changelog entry to the unreleased section
  • Swapped out ChaCha20Rng for SysRng in the provider
  • Added the new_with_prng constructor to the main Hpke struct for better flexibility.

Let me know if that looks good!

@franziskuskiefer franziskuskiefer left a comment

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.

Thanks for the update. There's another place where the chacha rng is still used.

Can we use the drbg in kem_key_gen_derand as well?

The Chacha rng should not be needed anymore in the libcrux provider. There's also the fake_rng that still has it. That could be kept for dev builds if really neede. But it would be nicer if we could drop it there as well.

{
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".

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.

MavenRain pushed a commit to MavenRain/libcrux that referenced this pull request Aug 11, 2026
This should also address celabshq#1544.
There's some overlap with celabshq#1546.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use drbg in hpke

2 participants