kem: move Kem for *Decapsulate/Encapsulate to associated type#2282
Merged
kem: move Kem for *Decapsulate/Encapsulate to associated type#2282
Kem for *Decapsulate/Encapsulate to associated type#2282Conversation
Also adds (back) a `Decapsulator` trait. This is effectively a followup to #2243 which added the `Kem` trait but made it a generic argument to `*Decapsulate`/`Encapsulate`, and removed the previous `Decapsulator` trait. Having it be a generic argument is annoying: these types should simply know what KEM algorithm they implement. The only reason I didn't do it that way at the time was I was having trouble making it work, and that was a fairly large refactor to begin with. This adds an associated `Kem` to `Encapsulate`, but for `Decapsulate`/`TryDecapsulate` we need a common trait to hang it off of, so this adds back the `Decapsulator` trait. It's not so bad as the previous hack introduced in #2243 of using `AsRef` to obtain an `EncapsulationKey` from a `Decapsulator` has been replaced with a semantically clear `Decapsulator::encapsulation_key` method.
tarcieri
added a commit
to RustCrypto/KEMs
that referenced
this pull request
Feb 5, 2026
Member
Author
|
This was simple enough to implement in RustCrypto/KEMs#248 and should definitely make it much easier to use, especially in a generic context |
tarcieri
added a commit
to RustCrypto/KEMs
that referenced
this pull request
Feb 5, 2026
tarcieri
added a commit
to RustCrypto/KEMs
that referenced
this pull request
Feb 5, 2026
Companion PR to RustCrypto/traits#2282
tarcieri
added a commit
that referenced
this pull request
Feb 5, 2026
Includes `Decapsulate`/`Encapsulate` changes from #2282 This should hopefully be the last `.rc` before a final stable release, as I'm otherwise happy with the API now
Merged
tarcieri
added a commit
that referenced
this pull request
Feb 5, 2026
Includes `Decapsulate`/`Encapsulate` changes from #2282 This should hopefully be the last `.rc` before a final stable release, as I'm otherwise happy with the API now
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 (back) a
Decapsulatortrait.This is effectively a followup to #2243 which added the
Kemtrait but made it a generic argument to*Decapsulate/Encapsulate, and removed the previousDecapsulatortrait.Having it be a generic argument is annoying: these types should simply know what KEM algorithm they implement. The only reason I didn't do it that way at the time was I was having trouble making it work, and that was a fairly large refactor to begin with.
This adds an associated
KemtoEncapsulate, but forDecapsulate/TryDecapsulatewe need a common trait to hang it off of, so this adds back theDecapsulatortrait.It's not so bad as the previous hack introduced in #2243 of using
AsRefto obtain anEncapsulationKeyfrom aDecapsulatorhas been replaced with a semantically clearDecapsulator::encapsulation_keymethod.