Key blocks: TR-31, AKB and X9.143
Encrypting a key under a ZMK (Zone Master Key) hides it, but it doesn’t say what the key is for. Attackers exploited exactly that gap for decades. Key blocks close it: the key travels together with its permitted use, and a MAC (Message Authentication Code) glues them so neither can be changed.
- explain the key-usage attack that key blocks prevent;
- read any TR-31 header: version, usage, algorithm, mode, exportability;
- unwrap a TR-31 block and verify it with the KCV;
- place AKB, TR-31, X9.143 and TR-34 in history.
1. The problem: a key without a label
Suppose an HSM (Hardware Security Module) receives encrypt(ZMK, K) and the caller says “this is a data key”. In reality K is a PIN (Personal Identification Number) key. The HSM imports it as a data key, and the attacker asks it to decrypt data with K — handing them clear PIN blocks. HSM vendors patched this with key variants (XOR the KEK with a constant per key type before wrapping), but variants were proprietary and fragile.
The real fix: put the key’s attributes inside the protected structure.
2. History in four lines
- AKB — Atalla Key Block: 8-byte header + 3DES-CBC encrypted key + MAC. The original.
- TR-31 — the ANSI (American National Standards Institute) technical report that standardised the idea (versions A, B, C with 3DES; D with AES). PCI (Payment Card Industry) PIN requires key blocks for key exchange.
- ANSI X9.143 — TR-31’s successor (2022); essentially the same format.
- TR-34 — different problem: delivering a key using RSA (Rivest–Shamir–Adleman, a public-key algorithm) and certificates, no paper components (used for remote key loading and cloud HSMs).
3. Anatomy of a TR-31 key block
The header is readable by anyone — that’s fine, it contains no secret. But because the MAC covers it, changing a single character (say, turning a PIN key into a data key) makes the block invalid.
For version B and D, the block protection key (KBPK — the ZMK, in a zone) is never used directly: two keys are derived from it with CMAC (Cipher-based MAC), one for encryption (KBEK) and one for the MAC (KBAK). The MAC doubles as the IV (Initialization Vector) of the CBC (Cipher Block Chaining) encryption.
The default block above is the worked example from the TR-31 specification itself. Press Unwrap, then Tamper and unwrap again.
4. The header fields that matter
| Position | Field | Values you will meet |
|---|---|---|
| 1 | Version | B 3DES with derived keys · D AES · A/C legacy variants |
| 2–5 | Length | Whole block, in characters |
| 6–7 | Key usage | K0 KEK/ZMK · P0 PIN key · C0 CVK · E0 EMV MK-AC · E1 MK-SMC · E2 MK-SMI · E4 dynamic numbers · V2 PVV key · B0 BDK |
| 8 | Algorithm | T 3DES · A AES |
| 9 | Mode of use | E encrypt · D decrypt · B both · C generate+verify · G generate · V verify · X derive keys · N no restriction |
| 10–11 | Key version | 00 unless versioned |
| 12 | Exportability | E exportable under a trusted key · N never · S sensitive |
| 13–14 | Optional blocks | count; e.g. KS key set ID, KC KCV, PB padding |
| 15–16 | Reserved | 00 |
Note mode X: issuer master keys (E0–E6) are used to derive card keys, not to encrypt anything directly.
5. Build your own
Exercises
Which two-character key usage code marks a card verification key (used for CVV/CVC)?
Hint
See the table, positions 6–7.Header D0144P0AE00N0000. Which statement is right?
- An AES (Advanced Encryption Standard) PIN-encryption key, encrypt-only, that may never be exported
- A 3DES (Triple DES) data key that can be exported
- An exportable AES MAC key
Paste the spec example into the inspector and change position 6–7 from P0 to D0. Unwrap with the right KBPK (Key Block Protection Key). What happens?
- MAC check fails — the block is rejected
- It imports as a data key
- It decrypts to a different key
An issuer master key for application cryptograms is used only to derive card keys. Which mode-of-use character should its header have?
Hint
TR-31 inspector: paste the block, put the KBPK, Unwrap. The KCV is shown.Write the 16-character header (use 0000 for the length; the builder fills it) for: version B, a CVK (Card Verification Key), 3DES, used to both generate and verify, key version 00, exportable under a trusted key, no optional blocks.
Hint
Version · 0000 · usage · algorithm · mode · version · exportability · 00 · 00.Solution
B0000C0TC00E0000 — B, length, C0, T, C, 00, E, 00 optional blocks, 00 reserved.You wrap the same CVK twice with the builder, same KBPK, same header. The two key blocks differ. Your colleague says the wrapping is broken. Who’s right, and how would you prove the key inside is the same?
- You: random padding makes every wrap different; equal KCVs prove it’s the same key
- Your colleague: a deterministic standard must give the same output