dhkem: add HpkeKemId trait; make X25519Kem fallible#360
Merged
Conversation
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
This was referenced Jul 9, 2026
Merged
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.
Also adds a common
Errortype for theTryDecapsulateimplementations to use.The
HpkeKemIdtrait 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_expandas well asDecapsulationKey::decapsulate_and_expandmethods provide a convenient way to initialize anExpanderfrom 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
Expanderis initialized, so this switchesX25519Kemto use the fallibleTryDecapsulate.Closes #262, #268, #327