DHKEM
Diffie-Hellman KEM from RFC 9180 (HPKE).
from oxcrypto.kem.dhkem import DHKEM
private_key = DHKEM.X25519_HKDF_SHA256.generate()
ciphertext, shared_secret = private_key.public_key().encapsulate()
assert private_key.decapsulate(ciphertext) == shared_secret| Variant | Private key | Public key | Ciphertext | Shared secret |
|---|---|---|---|---|
X25519_HKDF_SHA256 | 32 bytes | 32 bytes | 32 bytes | 32 bytes |
The shared secret is the RFC 9180 ExtractAndExpand output over the
Diffie-Hellman value and enc || pkR, so it matches the shared_secret of
HPKE Encap/Decap. The ciphertext is the ephemeral public key enc.
Private keys serialize clamped, as RFC 9180 section 7.1.2 requires. A
ciphertext that gives an all-zero X25519 output raises ValueError, and so does
loading a low-order public key, because every encapsulation to it would give an
all-zero output (RFC 9180 section 7.1.4).
- Standard: RFC 9180 (February 2022), DHKEM(X25519, HKDF-SHA256).
- Crate: RustCrypto
dhkem0.1.1 withx25519-dalek3.0.0 andhkdf/sha2, stable releases, no published audit. Builds with Rust 1.88. - Vectors: RFC 9180 Appendix A.1.1, A.1.2, A.2.1 and A.2.2 (the X25519 modes without sender authentication).
Zeroization
Retained state: the X25519 StaticSecret. x25519-dalek wipes it on drop
when its zeroize feature is on. dhkem's own zeroize feature does not
enable it, so oxcrypto enables x25519-dalek/zeroize directly. The gap is
tracked upstream in
RustCrypto/KEMs#395.
Short-lived copies not wiped by the upstream crate: the ephemeral X25519 secret during encapsulation and the HKDF state; oxcrypto wipes the raw Diffie-Hellman value and the derived shared secret it handles.