Support HPKE DHKEM suite IDs#327
Closed
tob-joe wants to merge 1 commit into
Closed
Conversation
Add KEM-ID-aware HPKE labeled extract and expand helpers so non-P-256 DHKEM users do not derive values under the P-256 suite ID. Keep the existing labeled HPKE helpers as P-256-compatible wrappers, export public HPKE DHKEM KEM ID constants, and add an RFC 9180 X25519 export-only regression test. Co-authored-by: GPT-5.5 <codex@openai.com>
tarcieri
added a commit
that referenced
this pull request
Jul 9, 2026
Also adds a common `Error` type for the `TryDecapsulate` implementations to use. The `HpkeKemId` trait makes it possible to associate one of the KEM IDs from RFC9180 §7.1 with a given type. The trait is now impl'd for all KEMs in that table we support (the only one we currently don't is X448). The generic `EncapsulationKey::encapsulate(_with_rng)_and_expand` as well as `DecapsulationKey::decapsulate_and_expand` methods provide a convenient way to initialize an `Expander` from the shared key output by the KEM. HPKE mandates an all-zero check for the X25519 output (occurs if the input is all-zero or a low order point) in RFC9810 §7.1.4, which this also adds as the check needs to occur before `Expander` is initialized, so this switches `X25519Kem` to use the fallible `TryDecapsulate`. Closes #262, #268, #327
tarcieri
added a commit
that referenced
this pull request
Jul 9, 2026
Also adds a common `Error` type for the `TryDecapsulate` implementations to use. The `HpkeKemId` trait makes it possible to associate one of the KEM IDs from RFC9180 §7.1 with a given type. The trait is now impl'd for all KEMs in that table we support (the only one we currently don't is X448). The generic `EncapsulationKey::encapsulate(_with_rng)_and_expand` as well as `DecapsulationKey::decapsulate_and_expand` methods provide a convenient way to initialize an `Expander` from the shared key output by the KEM. HPKE mandates an all-zero check for the X25519 output (occurs if the input is all-zero or a low order point) in RFC9810 §7.1.4, which this also adds as the check needs to occur before `Expander` is initialized, so this switches `X25519Kem` to use the fallible `TryDecapsulate`. Closes #262, #268, #327
Member
|
Closing in favor of #360 |
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.
This fixes HPKE labeled extract/expand support for non-P-256 DHKEMs.
The existing
Expander::new_labeled_hpkeandExpander::expand_labeled_hpkehelpers always use suite IDKEM\x00\x10,which is DHKEM(P-256, HKDF-SHA256). That is correct for P-256, but not
for other DHKEMs exposed by the crate.
This adds KEM-ID-aware helper methods and public KEM ID constants, while
leaving the existing helpers as P-256-compatible wrappers. The regression
test covers the RFC 9180 X25519 export-only vector.
Verification:
This work was completed by Trail of Bits as part of the Patch The Planet project in collaboration with OpenAI. The vulnerability was identified primarily by the Codex coding agent, and manually reviewed before submission.