Refactor authenticated DHKEM paths to eliminate intermediate heap allocation - #3
Merged
Merged
Conversation
nadimkobeissi
requested changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The authenticated KEM paths (
auth_encap,auth_decap, and the test-onlyauth_encap_with_ikm) previously concatenated their two DH outputs into an intermediateVecbefore passing them toextract_and_expand, which internally callslabeled_extract, which callsF::extract, which itself feeds the bytes intoHkdfExtract::input_ikmsequentially. Note that this was only necessary becauseextract_and_expandtook a single&[u8].This PR adds a sibling function
extract_and_expand_piecesthat accepts multiple DH slices directly, mirroring the existing pattern already used onkem_context, and accordingly updates all three auth paths to use it. It also addsauth_encapandauth_decapbenchmarks for X25519, which were previously missing from the benchmark suite.Benchmarking the codebase before and after the change shows no statistically significant difference in
auth_encaporauth_decaplatency, since both changes fall within measurement noise (note that the observedseal/openregressions are on paths that were not affected by the refactor).This is expected: modern allocators handle small short-lived allocations cheaply, and the two DH scalar multiplications that dominate the auth path cost largely outweigh any allocator overhead. As such, the change is a code quality improvement rather than a performance improvement.
Find attached a
.txtfile containing the benchmarking results:benchmark.txt