Skip to content

Conversation

@tarcieri
Copy link
Member

Adds a companion trait to KeyInit* for exporting a key to a byte array sized according to KeySizeUser.

This is needed when generating e.g. asymmetric secret keys types using the Generate trait and it returns an actual key type (e.g. SigningKey, DecryptionKey, DecapsulationKey) as opposed to its serialized byte representation.

This PR also shows another use case for it: there's currently a gap in the kem crate around serialization where you can generically go from Decapsulate::encapsulator to the associated encapsulation key for a KEM, but there is currently no generic way to serialize it.

It adds TryKeyInit and KeyExport bounds to kem::Encapsulate, because as the public key component we should always be able to serialize/deserialize it.

(NOTE: happy to split the kem changes out, that would probably be for the best, but I thought it would help illustrate the use case)

Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not forget to update the changelog.

@tarcieri tarcieri force-pushed the crypto-common/add-key-export-trait branch from 0ff46b3 to 416dfd8 Compare January 22, 2026 18:13
Adds a companion trait to `KeyInit*` for exporting a key to a byte array
sized according to `KeySizeUser`.

This is needed when generating e.g. asymmetric secret keys types using
the `Generate` trait and it returns an actual key type (e.g.
`SigningKey`, `DecryptionKey`, `DecapsulationKey`) as opposed to its
serialized byte representation.
@tarcieri tarcieri force-pushed the crypto-common/add-key-export-trait branch from 416dfd8 to 419d83c Compare January 22, 2026 18:14
@tarcieri
Copy link
Member Author

Removed the kem changes and added a CHANGELOG entry in 419d83c

@tarcieri tarcieri merged commit ee5e408 into master Jan 22, 2026
20 checks passed
@tarcieri tarcieri deleted the crypto-common/add-key-export-trait branch January 22, 2026 18:16
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.

3 participants