HSM / PKCS#11 / Envelope Encryption

What you will do: Pick a KEK algorithm (ML-KEM-512/768/1024 or RSA-2048/4096) and a wrap mechanism (AES-KW, AES-KWP or AES-GCM), press Execute (Live WASM), then step through the five-step classical-vs-PQC comparison.

Worked example: With ML-KEM-768 and AES-KW the run generates an AES-256 DEK, encapsulates a 1088 B KEM ciphertext, wraps the DEK into 40 B and unwraps it again; the Key Integrity Verification panel shows the DEK before and after match.

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 KMS & PQC Key Management

For your role

Security Architect
Set the KEK algorithm to RSA-2048 and then ML-KEM-768 and run the five steps for each: the Artifact Sizes by Step chart shows what the three-step encapsulate, KDF and AES-wrap flow costs against a one-step RSA-OAEP wrap.
Researcher / Academic
Choose AES-KW, AES-KWP or AES-GCM as the wrap mechanism and compare the wrapped-key sizes in the Envelope Encryption Flow; the KMS PQC Known Answer Tests panel checks the ML-KEM and wrap implementations and labels each result with its evidence class.
IT Ops / DevOps
Run the ML-KEM-768 / AES-KW flow with Execute (Live WASM): the PKCS#11 call log is the sequence of calls a KMS makes for every data key, which is what a migration changes on your HSM partitions.

Envelope Encryption Demo

Step through the complete envelope encryption flow. Compare how RSA-OAEP directly wraps a DEK in one step versus the 3-step ML-KEM process: encapsulate → KDF → AES wrap (AES-KW / AES-KWP / AES-GCM).

Live HSM Mode Active

SoftHSM3 · PKCS#11 v3.2 · Rust · session open

KEK Algorithm

Wrap Mechanism

Run ML-KEM-768 / AES-KW Envelope Encryption

Progress0% Complete
Step 1 of 5

Generate KEK Pair

The ML-KEM-768 encapsulation key is 4.6 times the width of the RSA-2048 modulus (1,184 B vs 256 B). Measure the complete encoded keys or certificates when budgeting distribution bandwidth.
CLASSICALRSA-OAEP

Generate RSA-2048 key pair. Public key is used by clients to wrap DEKs.

Artifact

RSA-2048 Public Key

Size:256 bytes
PQCML-KEM-768

Generate ML-KEM-768 key pair. Public encapsulation key is distributed to clients.

Artifact

ML-KEM-768 Encapsulation Key

Size:1,184 bytes

The ML-KEM-768 encapsulation key is 4.6 times the width of the RSA-2048 modulus (1,184 B vs 256 B). Measure the complete encoded keys or certificates when budgeting distribution bandwidth.

Classical (RSA-OAEP)
1. Generate RSA-2048 key pair
2. RSA-OAEP wrap DEK → 256 B
3. (no KDF step)
4. (DEK already wrapped)
5. RSA-OAEP unwrap → DEK · compare
PQC (ML-KEM-768 + AES-KW)
1. Generate ML-KEM-768 key pair
2. Encaps → ct + shared secret
3. HKDF(ss) → wrapping key (RFC 5869)
4. AES-KW wrap DEK
5. Decaps → HKDF → unwrap → DEK · compare
StepOperationClassicalPQC (ML-KEM-768)
1Generate KEK Pair256 B1,184 B
2Encapsulate / Wrap256 B1,088 + 32 B
3Derive Wrapping Key (PQC only)N/A32 B
4Wrap DEK256 B1,088 + 40 B
5Decapsulate / Unwrap32 B32 B

Run the live demo for this step to unlock Complete & Next.

Migration Path: Use Hybrid (Classical + PQC)

This demo shows a binary choice — RSA-OAEP or ML-KEM. NIST SP 800-227 describes hybrid (PQ/T) key establishment, in which the shared secrets of all components are combined with an approved key combiner so that a well-designed scheme is secure if at least one component is secure; the document says combining schemes can be advantageous for some applications, for example during the migration to post-quantum cryptography. In this module's illustration, a combined shared secret is derived via HKDF from both outputs (e.g. P-256 ECDH ‖ ML-KEM-768 → HKDF → AES-256 KEK). This hybrid approach is available in the HSM / PKCS#11 → Key Wrapping tool which supports P-256+ML-KEM and X25519+ML-KEM multi-algorithm key-establishment combiner modes (not sourced in the Library).

Educational sandbox vs. production: SoftHSMv3 WASM runs locally in the browser and is not a FIPS 140-3 CMVP-validated production HSM. In production KMS/HSM deployments, verify your module's active CMVP certificate, enforce non-extractable DEK/KEK policies, and test against your provider's documented envelope format.

KMS PQC Known Answer Tests

FIPS 203 · SP 800-56C Rev 2 · SP 800-38D · RFC 3394 · RFC 5649 · RFC 5869

Predict a one-byte change

This fictional sample generates fresh ML-KEM-512 keys. Predict whether changing the selected byte should preserve verification or key confirmation, then run the actual operation.

Click Run known-answer checks to run 11 use-case scenarios. Evidence in this set: NIST ACVP-Server reference sample — Expected values copied from the public NIST ACVP-Server repository with immutable source identity; Published standard KAT — Expected values printed in a cited standard or consensus RFC; Functional round-trip — Output produced by an implementation is consumed by the same or paired implementation.

Reference samples from the public NIST ACVP-Server repository · FIPS 203 · SP 800-56C Rev 2 · SP 800-38D · RFC 3394 · RFC 5649 · RFC 5869 · Generated keys are for educational use only.

AES-KWP published vectors (RFC 5649 §6)

The AES-KWP row above is a length check and a round-trip, so it cannot catch a wrong answer. RFC 5649 §6 publishes two examples, both for a 192-bit KEK. This module wraps with a 256-bit KEK, so these vectors show that the CKM_AES_KEY_WRAP_KWP mechanism reproduces a published ciphertext and recovers the published key data; they are not an AES-256 vector.

Click 'Execute' to run the live envelope encryption flow.

No keys yet — click Execute to run the provisioning flow.

Production Tool Capabilities & Verification Requirements

What this sample check establishes: Demonstrates two-tier DEK/KEK envelope encryption where a random 256-bit Data Encryption Key encrypts bulk payload data and is wrapped via ML-KEM key encapsulation.

Browser sandbox limitation (non-certification boundary): Ephemeral keys reside in browser memory; it does not validate cloud KMS IAM access policies, HSM key-wrapping boundaries, or persistent storage rotation.

What to require and test in your production tools:

  • Cloud KMS / HSM support for ML-KEM-768/1024 key encapsulation (`Encapsulate` / `Decapsulate`) bound to AES-256-GCM / AES-256-KWP DEK wrapping.
  • Cryptographic binding of key-context metadata (AAD) to prevent confused-deputy ciphertext substitution across tenants.
  • Online KEK re-wrapping without requiring bulk re-encryption of terabyte-scale underlying data.

Try it

  1. 1. Predict before you run it.
  2. 2. Run or change the tool above.
  3. 3. Explain what the result shows.

Compare the RSA-2048 and ML-KEM-768 runs: how many steps does the ML-KEM path add before the AES wrap?

A team changes the wrapping key while the data-encryption key and encrypted object stay the same. Which operation should the reviewer look for?

Next step

Turn it into a plan: Infrastructure Modernization Planner

This tool practises the KMS & PQC Key Management module, phase 6 (Infrastructure & Performance); Infrastructure Modernization Planner produces a deliverable of that phase.