HSM / PKCS#11 / Hybrid KEM + ECDH
What you will do: Execute six steps in order: Alice and Bob X25519 keypairs, ECDH in both directions, an ML-KEM-768 keypair, encapsulation, then decapsulate and HKDF-combine both secrets into one 32-byte session key.
Worked example: Step 3 prints both ECDH secrets and confirms they match; Step 5 shows the 1088-byte ciphertext; Step 6 lists the HKDF inputs (ECDH secret, ML-KEM secret, info string) and the final 32-byte hybrid key.
Runtime and privacy: The cryptographic exercise runs in this browser. Review the site privacy terms before entering sensitive material; use synthetic inputs for learning and evaluation.
Browse all Crypto Lab tools · Learn with Hybrid Cryptography
For your role
- Developer / Engineer
- Walk the six steps from Generate Alice Keypair to the HKDF-SHA-256 combiner: each step's Field / Value / Description table names the PKCS#11 mechanism your code calls for X25519, ML-KEM-768 encapsulation and the final 32-byte session key.
- Security Architect
- The combiner is the design point: both the X25519 and the ML-KEM-768 secrets feed HKDF, so the session key stays secure if either component survives, and the step tables show the size each component adds to the exchange.
- Researcher / Academic
- Follow the mechanism and key-handle columns through the six steps to reproduce the exchange outside the browser; the PKCS#11 call log records every call with its return code.
Live HSM Mode Active
SoftHSM3 · PKCS#11 v3.2 · Rust · session open
Hybrid Key Establishment (X25519 + ML-KEM-768)
Live PKCS#11 demo: X25519 ECDH + ML-KEM-768 encapsulation + HKDF-SHA-256 over the concatenated secrets (ML-KEM first, as RFC 10024 §4.3 orders X25519MLKEM768). Both secrets contribute to the 32-byte hybrid session key, which stays secret as long as either component is unbroken, given an approved combiner form such as concatenation into an HKDF (FIPS 203 · RFC 5869).
Step 1 — Alice X25519 Keypair
Alice generates an ephemeral X25519 (Curve25519) keypair. The 32-byte public key will be shared with Bob for ECDH key agreement.
PKCS#11 v3.2 mechanism for Curve25519/Curve448 keypair generation
Montgomery-form elliptic curve; public key is the 32-byte u-coordinate
Key is authorized for CKM_ECDH1_DERIVE — required for ECDH key agreement
Compact vs 65 bytes for an uncompressed P-256 public key
| Field | Value | Description |
|---|---|---|
| Mechanism | CKM_EC_MONTGOMERY_KEY_PAIR_GEN (0x1056) | PKCS#11 v3.2 mechanism for Curve25519/Curve448 keypair generation |
| Curve | X25519 (Curve25519) | Montgomery-form elliptic curve; public key is the 32-byte u-coordinate |
| CKA_DERIVE | true | Key is authorized for CKM_ECDH1_DERIVE — required for ECDH key agreement |
| Public Key Size | 32 bytes | Compact vs 65 bytes for an uncompressed P-256 public key |
Combiner comparison. After you run Step 6, this spot shows the same two shared secrets combined three ways: this demo's HKDF, X-Wing (also the composite ML-KEM MLKEM768-X25519 formula), and plain concatenation.
Enable the HSM toggle and execute steps to see PKCS#11 traces.
Why combine ECDH and ML-KEM?
A Key Encapsulation Mechanism (KEM) is a one-sided primitive: the sender gives Encaps the receiver's public key and gets back a shared secret and a ciphertext, rather than supplying a key of its own choosing.
Combining X25519 ECDH with ML-KEM-768 via HKDF provides defense-in-depth:
- If a cryptographically-relevant quantum computer (CRQC) breaks X25519 via Shor's algorithm, the ML-KEM shared secret remains secret.
- If ML-KEM-768 has an unforeseen algebraic weakness, the X25519 shared secret remains secret.
What this construction does and does not do: its combiner has the form CMVP IG D.S accepts (both secrets concatenated and fed into an SP 800-56C KDF, HKDF included), but it mixes in only the two secrets and a fixed label, not the exchanged key shares or public keys. Deployed combiners bind those too (X-Wing hashes the X25519 key share and public key into its output; TLS 1.3 feeds the whole handshake transcript into its key schedule). A validated module must also enforce a fixed set of hybrid schemes and control the concatenation order itself, which this demo does not, so treat it as the idea, not a design to copy.
Then watch the same idea in a real TLS 1.3 handshake → The TLS simulator negotiates the X25519MLKEM768 group with real OpenSSL.
Note: softhsmv3 WASM is an in-browser educational PKCS#11 v3.2 sandbox (not a FIPS 140-3 CMVP-validated production HSM). It uses X25519 (Montgomery) for the classical leg via CKM_EC_MONTGOMERY_KEY_PAIR_GEN + CKM_ECDH1_DERIVE. Keys generated here are for learning only — in production, verify your HSM's active FIPS 140-3 CMVP certificate, Security Policy, and supported hybrid combiner profile.
Production Tool Capabilities & Verification Requirements
What this sample check establishes: Executes real in-browser ECDH (X25519 / P-256) + FIPS 203 ML-KEM encapsulation, combining both shared secrets through a KDF combiner to derive an AES-256-GCM key.
Browser sandbox limitation (non-certification boundary): Browser WASM/WebCrypto execution lacks constant-time hardware guarantees, side-channel protection, and FIPS 140-3 validated module boundaries.
What to require and test in your production tools:
- PQ/T hybrid KEM combiner built from an SP 800-56C-approved key-derivation method (SP 800-227 §4.6.2; ETSI TS 103 744), using HKDF-SHA256/384 or KMAC256; IETF RFC 9794 supplies the terminology.
- FIPS 203 §7.2 encapsulation-key (modulus) check, and implicit rejection in decapsulation (§6.3/§7.3), on tampered ML-KEM ciphertexts.
- Authenticated encryption (AES-256-GCM or ChaCha20-Poly1305) with strict nonce-uniqueness enforcement.
Try it
- 1. Predict before you run it.
- 2. Run or change the tool above.
- 3. Explain what the result shows.
In the six steps, where do the X25519 secret and the ML-KEM-768 secret meet?
The recipient can derive the classical contribution to a hybrid envelope, but its recovered post-quantum contribution is different. The envelope uses both in the key derivation. What should happen?
Next step
Turn it into a plan: Hybrid Transition PlannerThis tool practises the Hybrid Cryptography module, phase 5 (Pilots & Migration); Hybrid Transition Planner produces a deliverable of that phase.
Related content
Next in HSM / PKCS#11