A TDES DUKPT terminal can encrypt exactly 1,048,575 transactions before someone has to re-inject it. One of the longer explainers ranking for this topic says 2^21, which is double the real figure, and the rest say roughly a million or give no number at all.
That is typical of what you find when you search for DUKPT. Wikipedia covers the triple-DES scheme only. The top vendor whitepaper is stamped 2017 and splits the key serial number 16/43/21 bits, a layout I can't find in any other source. Only one ranking page has an AES key serial number table, and it stops before the counter rules. None mentions that PCI suspended its format 4 PIN block deadlines in 2021 and never brought them back.
This guide fills those gaps. The derivation code below is tested against the published ANSI vectors, and where the public sources disagree I say so.
What Is DUKPT and Why Do Payment Terminals Use It?
DUKPT (Derived Unique Key Per Transaction) is a key management scheme. It is often described as an encryption algorithm, and it isn't one: the encryption is still triple DES or AES. DUKPT decides which key gets used.
Three things make it work:
- A base derivation key (BDK) lives in the acquirer's or processor's HSM. PCI PIN forbids loading it into a terminal.
- An initial key is derived from the BDK and a device identifier, then injected into the terminal. The TDES-era name is IPEK; X9.24-3 just calls it the initial key.
- A key serial number (KSN) travels in clear with every encrypted message. It holds the identifiers and a transaction counter.
The payoff is what a stolen terminal gives up. An attacker who extracts the registers learns nothing about past transactions and nothing about any other device.
What Is in a DUKPT KSN? 80 Bits vs 96 Bits
| TDES DUKPT | AES DUKPT | |
|---|---|---|
| Defined in | ANSI X9.24-1:2009 Annex A, kept as informative Annex C of X9.24-3-2017 | ANSI X9.24-3-2017 |
| KSN length | 80 bits (20 hex) | 96 bits (24 hex) |
| Fixed part | 59-bit initial KSN | 64-bit initial key ID: 32-bit BDK ID, 32-bit derivation ID |
| Transaction counter | 21 bits | 32 bits |
| Most one bits allowed in the counter | 10 | 16 |
| First counter skipped | 0x7FF (2,047) | 0x1FFFF (131,071) |
| Last valid counter | 0x1FF800 | 0xFFFF0000 |
| Usable transaction keys | 1,048,575 | 2,448,023,842 |
| Key registers in the device | 21 | 32 |
| BDK | Double-length TDES | AES-128, AES-192 or AES-256 |
| Working keys | TDES | AES-128/192/256, plus 2-key and 3-key TDEA |
The usable-key counts are arithmetic, not quotes. Count the 21-bit values with one to ten bits set and you get 2^20 − 1 = 1,048,575, which matches the figure in the IFSF security standard. The same sum over 32 bits with a ceiling of sixteen gives 2,448,023,842. Public sources only round it to two billion.
Sources disagree on how the 59 fixed bits of a TDES KSN divide. IFSF uses a 40-bit key set ID and a 19-bit device ID. Wikipedia describes a 6-5-5 hex-digit convention. AWS's user guide lists 24, 19 and 21 bits for a 10-byte KSN, which adds up to 64 bits, not 80. IBM's documentation has it right: only the 59 + 21 boundary is fixed. AWS says as much further down the same page: "We don't enforce the split between the first two parts of the KSN."
Treat the left 59 bits as opaque when you derive. How they divide between key set and device is your estate's convention, and your HSM vendor's KSN descriptor records it.
How Does TDES DUKPT Derive the Initial Key?
Zero the counter, take the leftmost 8 bytes of the KSN, and encrypt them twice. The left half of the initial key uses the BDK. The right half uses the BDK XORed with C0C0C0C000000000C0C0C0C000000000.
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.decrepit.ciphers.algorithms import TripleDES
def ecb(alg, block):
enc = Cipher(alg, modes.ECB()).encryptor()
return enc.update(block) + enc.finalize()
def tdes_initial_key(bdk: bytes, ksn: bytes) -> bytes:
base = (int.from_bytes(ksn, "big") & ~0x1FFFFF).to_bytes(10, "big")[:8]
mask = bytes.fromhex("C0C0C0C000000000C0C0C0C000000000")
bdk2 = bytes(a ^ b for a, b in zip(bdk, mask))
return ecb(TripleDES(bdk + bdk[:8]), base) + ecb(TripleDES(bdk2 + bdk2[:8]), base)
def aes128_derive(key: bytes, usage: int, context: bytes) -> bytes:
# version 01, block 01, usage, algorithm 0002 (AES-128), length 0080 bits
data = bytes.fromhex("0101") + usage.to_bytes(2, "big") + bytes.fromhex("00020080") + context
return ecb(algorithms.AES(key), data)
Run against the ANSI X9.24-1:2009 test data (BDK 0123456789ABCDEFFEDCBA9876543210, KSN FFFF9876543210E00000), tdes_initial_key returns 6AC292FAA1315B4D858AB3A3D7D5933A. That is the published value, and it is the first thing to check when a host and an injection facility disagree.
From the initial key, each transaction key is reached by one non-reversible step per set bit in the counter. That is why the counter is capped at ten one bits: the host never does more than ten derivations for a single message.
One transaction key then becomes several working keys by XOR. Each mask is applied to both 8-byte halves:
| Purpose | Variant mask per half | Extra step |
|---|---|---|
| PIN encryption | 00000000000000FF | None |
| MAC, request or both ways | 000000000000FF00 | None |
| MAC, response | 00000000FF000000 | None |
| Data encryption, request | 0000000000FF0000 | Each half TDES-encrypted under the variant key |
| Data encryption, response | 000000FF00000000 | Same one-way step |
If PINs verify and card data decrypts to noise, check for a missing one-way step on the data variant first.
TDES DUKPT vs AES DUKPT: What Changed in X9.24-3?
AES DUKPT replaces the XOR variants with a labelled derivation. Every key, including the initial key, is one AES-ECB encryption of a 16-byte derivation data block. It is not CMAC.
The block is laid out as version 01, a block counter, a 2-byte key usage, a 2-byte algorithm, a 2-byte length in bits, then 8 bytes of context. For the initial key the context is the full initial key ID. For everything else it is the derivation ID followed by the counter.
| Key usage | Code |
|---|---|
| Key-encryption key | 0002 |
| PIN encryption | 1000 |
| MAC generation / verification / both | 2000 / 2001 / 2002 |
| Data encrypt / decrypt / both | 3000 / 3001 / 3002 |
| Key derivation | 8000 |
| Initial key derivation | 8001 |
Algorithm codes run 0000 (2-key TDEA), 0001 (3-key TDEA), 0002 to 0004 (AES-128, 192, 256).
ASC X9 publishes its test vectors and a reference Python listing free of charge, which is rare for a paid standard. With BDK FEDCBA9876543210F1F1F1F1F1F1F1F1 and initial key ID 1234567890123456, the function above reproduces them:
bdk = bytes.fromhex("FEDCBA9876543210F1F1F1F1F1F1F1F1")
ikid = bytes.fromhex("1234567890123456")
ctx = ikid[4:] + (1).to_bytes(4, "big") # derivation ID + counter 1
ik = aes128_derive(bdk, 0x8001, ikid) # 1273671EA26AC29AFA4D1084127652A1
dk = aes128_derive(ik, 0x8000, ctx) # 4F21B565BAD9835E112B6465635EAE44
pin = aes128_derive(dk, 0x1000, ctx) # AF8CB133A78F8DC2D1359F18527593FB
Four differences matter in practice.
Direction is in the key. A terminal's MAC generation key (2000) and the host's verification key (2001) are different keys. A host that derives "the MAC key" without choosing a direction gets the wrong one.
AES can still feed TDES. X9's supplement says AES initial keys can derive 2-key and 3-key TDEA working keys, so an AES key hierarchy can sit under a terminal that still emits 8-byte PIN blocks. The IFSF profile forbids this, so check your scheme's profile before relying on it.
A working key may not be stronger than its parent. An AES-128 BDK cannot produce AES-256 working keys.
There is a remote reload path. Counter 0xFFFFFFFF is reserved for a "DUKPT update key", a key-encryption key for loading a new initial key without a trip to an injection room. The TDES scheme defines no equivalent.
How Many Transactions Before a DUKPT Terminal Runs Out of Keys?
For TDES, 1,048,575. A lane doing 2,000 transactions a day lasts about 524 days if each transaction burns one counter value. It lasts far less if the firmware advances the counter per message, so that an authorisation, its reversal and a MAC'd advice each take a key. IFSF recommends incrementing per transaction and raising an alert when the counter's top bit sets.
DUKPT is a poor fit for host-to-host links for the same reason. At 50 messages a second, the TDES key space is gone in under six hours.
AES DUKPT's 2.4 billion keys end that problem for terminals. The counter stops at 0xFFFF0000, after which X9's reference device calls a function named CeaseOperation.
There is one edge I would test. X9's reference listing sets MAX_WORK = 16, and openemv's dukpt_aes_ksn_advance skips any counter with more than sixteen one bits, citing section 6.1 of the standard. But the reference listing's update routine checks oneBits <= MAX_WORK on the current counter and then adds one. As I read it, that steps from 0x1FFFE to 0x1FFFF, which has seventeen bits set, and X9's test vectors include keys for counter 131,071. A host can derive a key for any counter, so this fails only if your host validates KSNs more strictly than your terminal vendor advances them. Put counter 131,071 in your certification pack.
The other failure is replay. The host algorithm will derive a key for any KSN it is handed, including one it saw last week. IFSF's standard warns about this in an appendix and tells hosts to accept counters only in ascending order per initial KSN. That means the host does need state after all: one last-seen counter per device.
DUKPT vs Master/Session Keys vs Fixed Key
PCI PIN v3.1 requirement 2-2 allows three key management methods for online PIN translation.
| Fixed key | Master/session | DUKPT | |
|---|---|---|---|
| Key lifetime | Until re-injection | One session | One transaction |
| Host stores | A key per terminal | A master key per terminal | One BDK per key set |
| Online key exchange | None | Required | None (AES has an optional update key) |
| Stolen terminal exposes | Every message under that key | The master key, and every session key exchanged under it | Nothing past, nothing from other devices |
| Status under PCI PIN | TDES fixed key banned in terminals and host-to-host since 1 January 2023 | Allowed | Allowed |
Master/session is still the norm on host-to-host links, where both ends are HSMs and a key exchange message is cheap. DUKPT wins wherever the device might end up in an attacker's bag.
DUKPT moves the risk rather than removing it. The BDK is a single secret for the whole key set, so PCI PIN requires BDKs to be segmented by institution, vendor or region, and reusing one BDK and KSN pair across two devices breaks the uniqueness the scheme is named after.
PIN Block Format 0 vs Format 4 Under PCI PIN
Format 0 is 8 bytes: a PIN field XORed with a PAN field built from the rightmost 12 PAN digits excluding the check digit, then encrypted once. Format 3 is the same with random fill. Format 1 carries no PAN.
Format 4 is 16 bytes and exists because an AES block is 16 bytes. It encrypts twice, with the PAN mixed in between. X9's test vectors give a worked example for PIN 1234 and PAN 4111111111111111 under the counter-1 PIN key derived above:
PIN field 441234AAAAAAAAAA 2F69ADDE2E9E7ACE control 4, length 4, PIN, A fill, 8 random bytes
PAN field 4411111111111111 1000000000000000 PAN length minus 12, then the PAN, zero padded
Block A AES(key, PIN field)
Block B Block A XOR PAN field
PIN block AES(key, Block B) = A912150391AB65A67E52883D81CE2D15
I reproduced that output locally. Two consequences follow.
The PIN block no longer fits the message. ISO 8583 field 52 is 64 bits, and PCI's own guidance on format 4 says the block needs another data element. If you are still mapping fields, the ISO 8583 guide covers where 52 and 53 sit.
The deadlines you may have read are dead. PCI PIN v3.0 required hosts to support format 4 decryption by 1 January 2023 and encryption by 1 January 2025. PCI suspended both on 11 March 2021, and no bulletin since has reinstated them.
Is TDES DUKPT Still Allowed in 2026?
Yes. NIST SP 800-131A Revision 2 disallows two-key TDEA for encryption and disallowed three-key after 31 December 2023, but PCI treats that as a US federal rule. PCI PIN v3.1, dated March 2021 and still current, asks for strength at least equal to double-length TDEA. I could not find a PCI sunset date for TDES DUKPT anywhere.
What PCI did enforce is key blocks. A 17 July 2020 bulletin set Phase 2 for 1 January 2023 and Phase 3 for 1 January 2025. Key blocks do not apply to DUKPT working keys inside a device, but they do apply to BDKs and initial keys, so BDK and initial key transport should already be in key blocks such as TR-31. Check values split the same way: TDES keys may use the legacy method (encrypt zeros, keep up to 6 hex digits), while AES keys must use CMAC and up to 10.
The next change is structural. PCI announced Key Management and Operations (KMO) v1.0 on 14 September 2026, consolidating the key management requirements of the PIN and P2PE standards. The announcement gives no retirement date for PIN v3.1.
My view, and it is an opinion: TDES DUKPT will not be killed by a deadline. It will be retired by hardware refresh, one terminal generation at a time, and it will still be in production in 2030. So don't wait for a date. Any estate you inject from now on should sit on an AES BDK, even if the terminals derive TDES working keys and send format 0 for a few more years. Changing a PIN block format at the host is a translation call. Changing a key hierarchy means touching every device.
AWS Payment Cryptography vs Azure Payment HSM for DUKPT
These two are the same job done in opposite ways.
AWS Payment Cryptography is a multi-tenant JSON API. A DUKPT PIN translation is one call:POST /pindata/translate
{
"EncryptedPinBlock": "<16 hex from the terminal>",
"IncomingKeyIdentifier": "arn:aws:payment-cryptography:eu-west-2:111122223333:key/",
"IncomingDukptAttributes": {
"KeySerialNumber": "FFFF9876543210E00008",
"DukptKeyDerivationType": "TDES_2KEY"
},
"IncomingTranslationAttributes": { "IsoFormat0": { "PrimaryAccountNumber": "" } },
"OutgoingKeyIdentifier": "arn:aws:payment-cryptography:eu-west-2:111122223333:key/",
"OutgoingTranslationAttributes": { "IsoFormat0": { "PrimaryAccountNumber": "" } }
}
The details that bite:
KeySerialNumberaccepts 16, 20 or 24 hex characters. The derivation type enum isTDES_2KEY | TDES_3KEY | AES_128 | AES_192 | AES_256, but a BDK itself may only beTDES_2KEYor one of the AES sizes.- The field is
DukptKeyDerivationTypeon PIN translation and data encryption, andDukptDerivationTypeonVerifyPinDataand MAC operations. Copying a struct between calls fails validation. - The BDK must be created with key usage
TR31_B0_BASE_DERIVATION_KEY. - You can export an initial key for injection with
ExportKeyandExportDukptInitialKey, wrapped in TR-31 or TR-34. It is regenerated on every export and never stored. That call wants 20 hex for TDES or 24 for AES, upper case only. - Format 4 translation works only for PIN blocks built with the legacy 12-digit PAN construction.
DecryptDatawith DUKPT attributes returns clear card data to your application, which AWS warns puts that application in PCI DSS scope.
G0 as the TDES DUKPT translation from BDK to ZPK; the Thales manual itself sits behind a login. The pricing page I fetched shows a grid of LMK count by 60, 250 and 2,500 CPS tiers with no dollar figures. A second service, Payment HSM v2 on Utimaco Atalla, is in gated preview in two regions.
| AWS Payment Cryptography | Azure Payment HSM | |
|---|---|---|
| Model | Shared service, IAM, per-call billing | Dedicated HSM, hourly billing |
| Interface | JSON over HTTPS | payShield host commands |
| AES DUKPT | Documented in the API | Depends on the payShield firmware you run |
| Key ceremony | API, or $3,000 per key for a physical exchange | Yours to run |
| Best fit | New builds, variable volume | Existing payShield code, sustained high volume |
If you run Stripe Terminal, Adyen or Square readers, none of this is exposed to you. The pages I checked never name a key scheme, and you never see a BDK or a KSN.
For a test oracle, openemv/dukpt (C, LGPL-2.1) and moov-io/dukpt (Go, Apache-2.0) both implement TDES and AES. jPOS and the dukpt package on PyPI are TDES only. There is no crate named dukpt on crates.io.
What This Means for Payment Engineers
1. Pin the vectors in CI. 6AC292FAA1315B4D858AB3A3D7D5933A for TDES and 1273671EA26AC29AFA4D1084127652A1 for AES-128 should be unit tests in any service that touches a KSN.
2. Store the KSN as an opaque string of 20 or 24 hex characters. Don't parse the device ID out of a TDES KSN unless you own the convention.
3. Track the last counter per initial KSN. Reject anything that goes backwards, and alert when a TDES counter passes 0x100000. About 59% of the keys are spent by then, so that is the moment to schedule re-injection.
4. Find out whether your terminals advance the counter per transaction or per message. Per-message counting can halve device lifetime or worse.
5. Choose key direction explicitly for AES DUKPT. Request and response MAC keys differ. So do encrypt and decrypt data keys.
6. Budget for format 4 in the message spec. Nothing mandates it today, but a 16-byte PIN block needs a field your ISO 8583 layout does not have yet.
7. Put new estates on an AES BDK. Translate to whatever the upstream link still needs.
Key Takeaways
- TDES DUKPT gives 1,048,575 keys per device from an 80-bit KSN. AES DUKPT gives about 2.4 billion from a 96-bit KSN.
- AES DUKPT derives every key with one AES-ECB encryption of a labelled 16-byte block, and separates keys by direction.
- PCI's format 4 PIN block deadlines were suspended in March 2021 and have not returned. TDES DUKPT has no PCI end date.
- AWS exposes DUKPT as JSON fields at $2 per 10,000 calls. Azure rents you a payShield and leaves the commands to you.