use hmac-drbg as prng in libcrux provider (#1545) - #1546
Conversation
franziskuskiefer
left a comment
There was a problem hiding this comment.
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.
|
|
||
| ### Changed | ||
|
|
||
| - (hpke-rs-libcrux) [#1545](https://github.com/celabshq/libcrux/issues/1545): Use DRBG as the PRNG in the HPKE provider |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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.
9fac2aa to
facdd5e
Compare
|
Thanks for the review!
Let me know if that looks good! |
franziskuskiefer
left a comment
There was a problem hiding this comment.
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]), |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
The comment in here doesn't make sense anymore.
This should also address celabshq#1544. There's some overlap with celabshq#1546.
This PR updates the
hpke-rs-libcruxcrypto provider to use the newly restoredlibcrux-hmac-drbgas its pseudo-random number generator,.Changes
libcrux-hmac-drbg(with therandfeature) tocrates/protocols/hpke/libcrux_provider/Cargo.toml.HpkeLibcruxPrngto storeHmacSha256DrbgRng<rand_chacha::ChaCha20Rng>instead of justChaCha20Rng.prng()factory method, using the existing OS-seededChaCha20Rngas the underlying entropy source for automatic reseeding, and an empty array&[0u8; 32]for the personalization string.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.