Skip to content

dhkem: impl (Try)KeyInit/KeyExport for DecapsulationKey#227

Merged
tarcieri merged 1 commit intomasterfrom
dhkem/decapsulation-key-import-export
Jan 31, 2026
Merged

dhkem: impl (Try)KeyInit/KeyExport for DecapsulationKey#227
tarcieri merged 1 commit intomasterfrom
dhkem/decapsulation-key-import-export

Conversation

@tarcieri
Copy link
Member

Support for importing and exporting such keys is part of the HPKE spec, which it calls SerializePrivateKey and DeserializePrivateKey.

This changes the inner types of EcdhDecapsulationKey and X25519DecapsulationKey to elliptic_curve::SecretKey and x25519_dalek::StaticSecret respectively, and impls the traits appropriate to the descriptions in RFC9810 §7.1.2:

  • EcdhDecapsulationKey impls TryKeyInit because it MUST reject non-canonical (unreduced) scalar representatives
  • X25519DecapsulationKey supports infallible KeyInit via clamping

Both are able to implement KeyExport using their respective serialization formats.

This required some changes to elliptic-curve since there were gaps in the SecretKey/PublicKey types, so a temporary git dependency has been added.

Support for importing and exporting such keys is part of the HPKE spec,
which it calls `SerializePrivateKey` and `DeserializePrivateKey`.

This changes the inner types of `EcdhDecapsulationKey` and
`X25519DecapsulationKey` to `elliptic_curve::SecretKey` and
`x25519_dalek::StaticSecret` respectively, and impls the traits
appropriate to the descriptions in RFC9810 §7.1.2:

- `EcdhDecapsulationKey` impls `TryKeyInit` because it MUST reject
  non-canonical (unreduced) scalar representatives
- `X25519DecapsulationKey` supports infallible `KeyInit` via clamping

Both are able to implement `KeyExport` using their respective
serialization formats.

This required some changes to `elliptic-curve` since there were gaps in
the `SecretKey`/`PublicKey` types, so a temporary git dependency has
been added.
@tarcieri tarcieri merged commit 2f96158 into master Jan 31, 2026
44 checks passed
@tarcieri tarcieri deleted the dhkem/decapsulation-key-import-export branch January 31, 2026 15:45
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