Skip to content

kem: move Kem for *Decapsulate/Encapsulate to associated type#2282

Merged
tarcieri merged 1 commit intomasterfrom
kem/associated-kem-types
Feb 5, 2026
Merged

kem: move Kem for *Decapsulate/Encapsulate to associated type#2282
tarcieri merged 1 commit intomasterfrom
kem/associated-kem-types

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Feb 5, 2026

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.

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
@tarcieri
Copy link
Member Author

tarcieri commented Feb 5, 2026

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 tarcieri merged commit 62a42bc into master Feb 5, 2026
10 checks passed
@tarcieri tarcieri deleted the kem/associated-kem-types branch February 5, 2026 15:55
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
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
@tarcieri tarcieri mentioned this pull request Feb 5, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant