Payment Cryptography, Hands-On
Module 2 · Foundations

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.

By the end you can
  • 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

Master key — MFK (Futurex, Atalla) / LMK (Thales)Lives only inside the HSM. Loaded once from components by custodians. Every other key stored outside the HSM is encrypted under it.
Key-encrypting keys — KEK (Key Encryption Key), ZMK (Zone Master Key), KBPK (Key Block Protection Key), TMK (Terminal Master Key)Protect keys while they travel between organisations or devices. A ZMK is a KEK shared with one partner.
Working keys — CVK (Card Verification Key), IMK (Issuer Master Key), ZPK (Zone PIN Key), PVK (PIN Verification Key), MAC (Message Authentication Code) keys…Do the actual work on card and transaction data.
Data — CVVs, PIN blocks, cryptogramsWhat the business cares about.

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”.

In real life Real HSMs don’t encrypt stored keys with plain ECB (Electronic Codebook) like this toy. They use key variants (Thales LMK pairs, older Atalla/Futurex) or key blocks (TR-31-style, module 4) so the key’s type is bound to it. The principle — app holds cryptograms, HSM holds the master key — is the same.

4. Vendors and their words

VendorProductsMaster keyCommand languageNote
ThalespayShieldLMKHost commands (two letters, e.g. CW = generate CVV)Most common payment HSM
FuturexVectera, Excrypt, VirtuCrypt (cloud)MFKExcrypt API: [AOxxxx;…;] tagged commandsAlso sells key management and HSM-as-a-service
Atalla (Utimaco)Atalla AT1000MFKAtalla commandsInvented the original key block, AKB
AWSAWS Payment Cryptography(managed)REST APICloud 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