Notes
TR-31 and TR-34: two standards, one key journey
Every PIN that leaves a terminal is protected by a chain of symmetric keys. The cryptography protecting the PIN is rarely the weak link. The weak link is how keys are moved between systems. Two ANSI X9 documents shape how that is done today: TR-31 and TR-34. They are often mentioned in the same breath, but they solve different problems.
The problem: a key without its context
For a long time, a key exchanged between two systems was just an encrypted value. The receiver had to work out from a file name, a field position or an e-mail whether it was a PIN key, a MAC key or a key-encryption key. Nothing stopped a key meant for MAC calculation from being used to decrypt PIN blocks. Classic attacks on payment HSMs exploited exactly this: they convinced the device to use a key for the wrong purpose.
The answer is a key block: a structure that carries the encrypted key together with its attributes, and binds the two cryptographically so that neither can be changed without detection.
TR-31: the key block format
TR-31 (now published as ANSI X9.143; ISO 20038 is its international counterpart for AES) defines that structure. A TR-31 block has three parts:
- Header: in clear text, but authenticated. It carries the key usage (for example PIN encryption, MAC generation, data encryption, key encryption, DUKPT base key), algorithm, mode of use (encrypt only, decrypt only, generate, verify…), key version and exportability.
- Encrypted key data: the key itself, its length and padding, encrypted under a key-block protection key derived from the shared key-encryption key.
- Authenticator: a MAC over header and encrypted data, calculated with a second derived key.
Because the MAC covers the header, an attacker cannot turn a MAC key into a PIN key by editing two characters. An HSM that receives the block enforces the attributes: a key marked “verify only” will never generate a MAC. The block versions matter too: B (TDES with key derivation) and D (AES) are the ones to aim for; the original variant-based version A is deprecated.
PCI PIN Security requires key blocks, or an equivalent method, for symmetric keys that are stored or exchanged between parties. That is why acquirers, processors and HSM vendors have been migrating from older variant-based schemes over the past years.
TR-34: getting the first key there
TR-31 assumes that both sides already share a key-encryption key. But how does a brand-new terminal in a merchant’s shop get that first key, without a technician and a key-loading device on site? This is remote key loading, and TR-34 is the standard for it.
TR-34 uses public-key cryptography between a key distribution host (KDH: the acquirer’s or a trusted third party’s HSM-backed system) and a key receiving device (KRD: the terminal):
- Both sides hold certificates issued by a certificate authority both trust. The terminal’s private key is created and kept inside its secure processor.
- The terminal proves its identity with its certificate, and in the two-pass variant sends a random value that the host must echo back, so an old message cannot be replayed.
- The host builds a key token: the symmetric key, with key-block style attributes, encrypted under the terminal’s public key and signed with the host’s private key, packaged in CMS structures.
- The terminal verifies the signature, checks the nonce and decrypts the key inside its secure boundary.
The result: the terminal holds a symmetric key (typically a terminal master key or an initial DUKPT key) that no person and no intermediate system has seen in clear.
How they work together
In a typical terminal estate, the two standards are consecutive steps of one journey:
- Day one: the terminal receives its key-encryption key remotely with TR-34.
- Every day after: working keys (PIN, MAC and data keys) are rotated under that key-encryption key and travel as TR-31 key blocks; between hosts, the same key blocks carry zone keys.
National programmes add their own layer on top. In Türkiye, for example, BKM operates remote key loading for TechPOS terminals, and the acquirer side has to fit its HSM commands, certificates and terminal installation flow into that process.
What to check in your own estate
- HSM configuration: is your payment HSM running a key-block LMK, and do your host applications use the key-block forms of its import and export commands?
- Attribute discipline: are key usage, mode of use and exportability set as narrowly as possible, or is everything exported as “any use”?
- Terminal fleet: which terminal models support TR-34, and which still need a key-injection facility?
- Certificates: who runs the certificate authority for KDH and KRD credentials, and how are expiry and revocation handled?
- Testing: can you exercise key exchange end to end against an HSM simulator before touching production keys?
None of this is exotic, but each item is a place where a migration quietly stalls. Getting them right is what turns “we support key blocks” into keys that can only ever be used for what they were made for.