HSMs and the key hierarchy
Rule number one of payment cryptography: a clear key exists only inside a hardware security module. Everywhere else — database, config, secrets manager, email — a key is a cryptogram: the key encrypted under another key.
- say what an HSM is and what it refuses to do;
- draw the three-level key hierarchy and name each level;
- explain what “a key under the MFK/LMK” means in your app’s config;
- map vendor jargon (Thales, Futurex, Atalla) to the same concepts.
1. What an HSM is
A Hardware Security Module is a tamper-resistant computer whose job is to hold keys and use them without ever revealing them. Open the case and it erases itself. It’s certified (FIPS 140, PCI HSM) and it speaks a narrow command language: “generate a CVV (Card Verification Value) with this key for this card”, “verify this ARQC (Authorization Request Cryptogram)”, “translate this PIN (Personal Identification Number) block from zone A to zone B”. There is deliberately no command “show me the key”.
Your application never computes a CVV. It sends the HSM (Hardware Security Module) a command containing an encrypted key plus the card data, and gets back the answer.
2. The hierarchy
Two consequences that surprise newcomers:
- The same key has many “values”. Your CVK stored in the database is encrypted under the MFK (Master File Key); the same CVK sent to a partner is encrypted under their ZMK. Different hex, same key. The way to tell they’re the same is the KCV (Key Check Value) (module 3).
- Changing the master key means re-encrypting every stored key. That’s a planned migration, not a button.
3. Try it: a toy HSM
This simulator has a random master key hidden in its code. Generate a CVK and look at what your “application” gets: a cryptogram and a KCV. Then ask it to compute a CVV2 (Card Verification Value 2, the printed code). Then “steal the database”.
4. Vendors and their words
| Vendor | Products | Master key | Command language | Note |
|---|---|---|---|---|
| Thales | payShield | LMK | Host commands (two letters, e.g. CW = generate CVV) | Most common payment HSM |
| Futurex | Vectera, Excrypt, VirtuCrypt (cloud) | MFK | Excrypt API: [AOxxxx;…;] tagged commands | Also sells key management and HSM-as-a-service |
| Atalla (Utimaco) | Atalla AT1000 | MFK | Atalla commands | Invented the original key block, AKB |
| AWS | AWS Payment Cryptography | (managed) | REST API | Cloud payment HSM; its docs are an excellent free textbook |
When a partner sends you keys “in Atalla format” or “as a Thales cryptogram”, they mean the key is wrapped in that vendor’s way. Converting between vendors means importing under one format and exporting under another — inside the HSM.
5. Dual control and split knowledge
An HSM is only as safe as the people allowed to administer it. Two rules from PCI (Payment Card Industry) PIN Security run through everything:
- Split knowledge: no single person ever knows a whole key. (Keys are split into components — module 3.)
- Dual control: no single person can perform a sensitive operation alone. HSM admin functions need two or more smart cards/passwords, often “M of N” officers.
Exercises
Which key, in a Futurex HSM, sits at the very top of the hierarchy and never leaves the device?
- ZMK
- MFK
- CVK
Your service config contains a 32-hex-digit value called cvk. In a correctly built system, what is it most likely?
- The clear CVK
- The CVK encrypted under the HSM master key (or a key-block/handle)
- The CVK’s KCV
In the toy HSM, generate two CVKs. Are their cryptograms related in any visible way? Does it matter that both are encrypted under the same master key?
- No visible relation; it doesn’t matter
- They share a prefix identifying the master key
The security team decides to rotate the HSM master key. Which statement is right?
- Every partner must receive new keys
- All stored key cryptograms must be re-encrypted under the new master key, but their KCVs don’t change
- All cards must be reissued
A developer proposes: “Let’s cache the clear CVK in memory in the authorisation service for speed; the HSM adds 5 ms.” Give the two strongest reasons against. (Pick the best pair.)
- It breaks the rule that clear keys exist only in an HSM (PCI), and a memory dump or a bug would expose every card’s CVV
- It is slower than the HSM and uses more RAM
- The KCV would change