Card payments, part 1: four parties, a chip and a cryptogram

Security

A €100 tap at a supermarket takes about four seconds, and most of that is the customer typing a PIN. In that time a chip MACs the amount, a terminal decides it cannot approve on its own, four companies pass a binary message along, and a hardware security module at the issuing bank checks the MAC and computes a reply. The card never sees that reply: it went back into a pocket after 200 ms.

Approval is the first of four separate processes, and it moves no money:

ProcessQuestion it answersWhen
AuthorizationMay this purchase happen, and how much credit does it hold?During the tap
ClearingWhat did the merchant actually sell, and for how much?Hours to days later, in files
SettlementWhich bank owes which bank, net, today?Once or more per business day
RepaymentWhen does the cardholder pay the issuer back?Statement cycle

This series follows one purchase through all four and designs the issuing bank’s side as it would be built. Visa and Mastercard do not publish their internals, so the network side comes from published specifications only. Illustrative numbers are marked as such.

PartSubject
1 (this)Authorization on the wire: parties, chip ↔ terminal, ARQC and ARPC, PIN, network tokens, PCI scope
2The issuer’s authorization hot path: limits, the atomic credit reservation, durability, the latency budget
3Messages out of order: timeouts, reversals, stand-in processing, advices
4Clearing, FX, unmatched holds, a double-entry ledger, settlement, repayment
5The event platform: outbox/CDC, projections, what the banking app may trust

The running example

CardVisa consumer credit, issued by a German bank, billing currency EUR
Credit limit€5,000
Posted balance€1,200
Open authorizations (holds)€0
Available credit€3,800
Purchase€100.00 at a supermarket in the Netherlands (MCC 5411), contactless

Both sides use EUR, so there is no currency conversion. FX is the most common reason the authorized and cleared amounts differ, and it gets its own section in part 4.

Two separate rules decide whether this tap needs a PIN:

RuleWho applies itThresholdEffect at €100
Reader CVM limitthe terminal, from scheme configuration per country€50 in the Netherlandsabove it: the reader requires a cardholder verification (CVM)
SCA contactless exemption, RTS Art. 11the issuer, from its own counters> €50 per tap, or > €150 cumulative / > 5 taps since the last SCAabove it: the issuer must get SCA, so it soft-declines a PIN-less tap (Visa 1A, Mastercard 65)

The reader limit fires first: the terminal asks for a PIN before it sends anything. A phone wallet satisfies both rules with the biometric check on the phone instead.

Step through it

The simulator below walks the whole authorization, one command or one piece of work per step, with the bytes on the wire. Pick a scenario: contactless + PIN is our €100 purchase. Inserted chip shows the full contact EMV flow with offline PIN and the second GENERATE AC. Phone wallet shows a network token. Hover any system, arrow or value for an explanation; click a row to jump to it. Step numbers in the text below refer to the contactless scenario.

Open fullscreen


1. Four parties and a network

PartyRoleIn our example
CardholderHolds the card and owes the issuerthe customer
MerchantSells the goods and runs the terminal or checkoutthe supermarket
AcquirerContracts with the merchant, routes its transactions into the network, credits its accountthe supermarket’s bank
Network (scheme)Routes messages between acquirers and issuers, sets the rules, runs clearing and settlementVisa
IssuerIssued the card, extends the credit, makes the approve/decline decisionthe German bank

Four corrections to common assumptions:

A three-party network such as American Express is issuer and acquirer at once for its proprietary cards, so the network hop and the inter-bank settlement disappear. Amex cards issued by partner banks under its GNS programme run four-party.

The money runs backwards, later, minus fees

On a €100 purchase the merchant receives €100 minus its merchant service charge. Out of that charge come the interchange fee due to the issuer and the acquirer’s own share of scheme fees; the issuer pays scheme fees on its side too. Interchange is netted in settlement, not paid per transaction. For consumer cards issued and used in the EEA, the Interchange Fee Regulation caps interchange at 0.3 % for credit and 0.2 % for debit: at most €0.30 on our purchase. Scheme fees and the acquirer’s margin are commercial and vary. All of this happens in part 4. During authorization, only messages move.


2. One authorization, as messages

Credit cards use the dual-message model: an authorization message now, a clearing record later. The authorization is an ISO 8583 exchange. The leading 0 of each message type (MTI) means the 1987 version of the standard: Visa’s V.I.P. (BASE I) and Mastercard’s CIS (Banknet) are proprietary dialects built on ISO 8583:1987. The MTIs and core data elements are shared.

MTIMessageDirectionPart
0100 / 0110Authorization request / responseacquirer → issuer / back1–2
0120Authorization advice: “this was decided without you”network → issuer3
0400 / 0420Reversal request / reversal adviceacquirer → issuer3
0800 / 0810Network management: sign-on/off, echo test, key exchangenetwork ↔ issuer3
0200 / 0210Financial request: authorization and clearing in one message (single-message, typical for ATM and PIN debit)—not used here

The 0100 our acquirer builds (step 14):

DEFieldOur value
2Primary account numberthe PAN; with a phone wallet, a token (§6)
3Processing code000000: type 00 goods and services, default from/to accounts
4Amount, transaction000000010000: €100.00, in minor units of DE 49
7Transmission date and time1108091530: MMDDhhmmss in UTC
11System trace audit number004711: matches responses, reversals, duplicates (part 3)
12 / 13Local time / local date101530 / 1108: the terminal’s clock
14Expiry2911
18Merchant category code5411: grocery stores, supermarkets
19Acquiring institution country528: Netherlands
22POS entry mode071: contactless chip (07), terminal can accept PIN (1)
23Card sequence number001: the PAN sequence number, an input to key derivation
32Acquiring institution ID400050 (illustrative): part of the issuer’s de-duplication key (part 3)
35Track 2 dataPAN, expiry, service code, iCVV (§3.2)
37Retrieval reference number631209004711: acquirer-assigned (year digit, day of year, hour, sequence)
41 / 42 / 43Terminal ID / merchant ID / name and locationthe supermarket
49Currency, transaction978: ISO 4217 numeric for EUR, which also fixes the decimals (EUR 2, JPY 0, BHD 3)
52PIN datathe encrypted PIN block (§5)
55ICC datathe chip’s TLVs: ARQC, ATC, TVR, IAD… (§3–4)

And the 0110 the issuer returns (step 29):

DEFieldOur value
38Approval codeA1B2C3: printed on the receipt
39Response code00: approved
55ICC datatag 91: the ARPC (§4.2)
62.2 (Visa)Transaction identifierassigned by the network; clearing links back to the authorization through it, or through Mastercard’s trace ID (part 4). DE 37 is a secondary reference.

The network adds DE 6 / DE 51, amount and currency in the cardholder’s billing currency (000000010000 / 978 here, step 16); the hold is made in it. DE 4 and DE 6 differ once FX is involved (part 4). Whether DE 6/51 are present at all when the two currencies match is network-specific.


3. The chip conversation

The terminal and the chip exchange APDUs, the command/response unit of ISO/IEC 7816-4. Data comes back as BER-TLV: a tag, a length and a value. Contactless runs over ISO/IEC 14443 through a network kernel: EMV Contactless Book C-3 for Visa (kernel 3), C-2 for Mastercard (EMV specifications). Our tap, kernel 3:

StepCommand (CLA INS)Terminal sendsCard returns
1–2SELECT (00 A4)2PAY.SYS.DDF01, the contactless directory (PPSE)the application list, directly in the response: Visa AID A0000000031010, priority 1
3–4SELECT (00 A4)the AIDlabel, and a PDOL (9F38): 9 terminal values, 33 bytes, that the card wants next
5GET PROCESSING OPTIONS (80 A8)the PDOL values: amount, country, currency, date, TVR, TTQ 9F66 and a 4-byte unpredictable number 9F37—
6the ARQC (9F26), the incremented ATC (9F36), issuer application data (9F10), Track 2 equivalent (57), and the CTQ (9F6C)
7–8READ RECORD (00 B2)the records the AFL namesexpiry, issuer country, usage control, certificates
9beep: card can be removed
10—(PIN entered on the PIN pad)nothing: the card is gone

Steps 5 and 6 decide the CVM. The terminal’s TTQ 36 C0 40 00 says it supports online PIN and consumer-device CVM (40, for phones), and that a CVM is required, because €100 is above the reader CVM limit. The card’s CTQ answer 80 00 says online PIN required. So the PIN goes to the issuer (§5), not the card. Kernel 3 has no CVM list: the TTQ/CTQ pair replaces it.

Kernel 3 computes the cryptogram inside the GET PROCESSING OPTIONS response. There is no GENERATE AC, and all chip work is over in about 200 ms, comfortably inside the ~500 ms card–reader target the schemes set. By the time the issuer replies, the card is back in the customer’s pocket. The ARPC (§4.2) and any issuer scripts are normally not delivered to the card, and the terminal acts on the response code alone. Kernel 3 defines an optional issuer update second tap to deliver them; it is rarely deployed. Mastercard’s kernel 2 differs: it still issues GENERATE AC after the record reads, in the same single tap.

3.1 What an inserted card does differently

The inserted chip scenario in the simulator shows the full contact flow, 42 steps:

Contactless (kernel 3)Contact
DirectoryPPSE returns the listSELECT 1PAY.SYS.DDF01 returns only the directory’s SFI (88); READ RECORD lists the applications
Offline data authenticationfDDA, only for offline-capable transactionsSDA (static signature, deprecated), DDA (INTERNAL AUTHENTICATE: the card RSA-signs terminal random data) or CDA (the card signs the GENERATE AC response itself, binding signature and cryptogram). The terminal finds the network CA key by RID + index 8F, then walks issuer certificate 90 → card certificate 9F46
Cardholder verificationonline PIN, CDCVM, or none under the limitthe card’s CVM list (8E) picks the method. Offline PIN: VERIFY (00 20) to the chip, answer 90 00 or 63 Cx (x tries left). Online PIN: nothing goes to the card; the PIN pad builds the block for DE 52
Cryptogramin the GPO responseGENERATE AC (80 AE) with the CDOL1 values
After the issuer repliesnothing reaches the cardARPC to the card (inside the second GENERATE AC if CDOL2 asks for tag 91, otherwise in EXTERNAL AUTHENTICATE 00 82), then the second GENERATE AC returns a TC or AAC

Terminal action analysis (contact). During terminal risk management (floor limit, random selection, velocity) the terminal records every failed check as a bit in the 5-byte TVR (95): data authentication failed, PIN tries exceeded, above floor limit. It then ANDs the TVR with the Terminal Action Codes and the Issuer Action Codes, each in three variants. A bit in Denial → request an AAC. Otherwise a bit in Online → ARQC. Otherwise TC. Default applies only when the terminal cannot go online. The request is P1 of GENERATE AC:

P1RequestsMeans
00AACdecline offline
40TCapprove offline
80ARQCgo online to the issuer

The order is TC > ARQC > AAC. The card may downgrade a request (TC → ARQC → AAC) under its own risk rules; it never upgrades. A supermarket terminal in the EEA usually has a floor limit of zero, so a contact transaction goes online too.

3.2 The chip’s Track 2 is not the stripe’s Track 2

Tag 57 holds the same layout as magnetic-stripe Track 2: PAN, expiry, service code and discretionary data. The card-verification value inside it is an iCVV, computed with service code 999 instead of the card’s real one. Data skimmed from a chip transaction therefore fails verification if it is written onto a counterfeit stripe card.


4. The cryptogram

4.1 What the ARQC is

The ARQC is an 8-byte MAC computed by the chip over transaction data, under a key that exists in clear only inside the chip and the issuer’s HSMs. EMV Book 2 §8.1.1 recommends this minimum input, ten data elements:

TagData elementSourceWhy it is in the MAC
9F02Amount, authorisedterminal (PDOL/CDOL1)binds the amount
9F03Amount, otherterminalbinds cashback
9F1ATerminal country codeterminalbinds the country
95TVRterminalthe terminal’s risk findings reach the issuer unaltered
5F2ATransaction currency codeterminalbinds the currency
9ATransaction dateterminalbinds the date
9CTransaction typeterminalpurchase vs cash vs refund
9F37Unpredictable numberterminalfreshness: 4 random bytes per transaction
82AIPcardthe card’s declared capabilities
9F36ATCcardthe card’s counter, +1 per transaction

Card application specifications add the card’s own risk findings: the CVR (Visa CVN 10) or the whole issuer application data 9F10 (CVN 18/22).

Keys. The issuer holds one issuer master key (IMK-AC) per BIN range, inside its HSMs. Every card gets a unique card master key, derived from the IMK, the PAN and the PAN sequence number (EMV Book 2, Annex A1.4). The cryptogram version number (CVN, inside 9F10) says what happens next. Visa CVN 18 and 22, Mastercard M/Chip 4 with the EMV session-key option, and M/Chip Advance derive a session key from the card master key and the ATC (Annex A1.3); older M/Chip profiles use Mastercard’s own derivation over the ATC and the unpredictable number. Legacy Visa CVN 10, still common, MACs directly under the card master key. The MAC is ISO/IEC 9797-1 algorithm 3 (“retail MAC”) under triple-DES. EMV also defines AES variants, but deployed cards are still overwhelmingly triple-DES.

What it proves. A valid ARQC proves that a chip holding this card’s key produced it, for this amount, currency, country, date and terminal random number. Changing the amount by one cent invalidates it.

What stops a replay. A replayed ARQC still verifies cryptographically, because the old unpredictable number travels with it in DE 55. What stops it at the issuer is the ATC. The issuer keeps the highest ATC it has accepted per card. It rejects a repeated ATC, treats one below the highest seen with suspicion (offline transactions can arrive late), and flags a large jump as a sign of a counterfeit or a cloned key. This is per-card state that part 2 has to store and update atomically with the hold. The unpredictable number stops a different attack: cryptograms recorded in advance for a future transaction. That works only if the terminal’s number really is unpredictable (Bond et al., “Chip and Skim”, IEEE S&P 2014).

What it does not cover. The recommended input contains no merchant ID, terminal ID, MCC or POS entry mode. A cryptogram relayed in real time to another terminal in the same country, for the same amount, currency and date, still verifies. Pre-play attacks rely on this gap, combined with a predictable unpredictable number. A live relay needs no gap at all: the card answers the distant terminal’s own challenge, and only a timing check stops it. That is why Mastercard’s kernel 2 added the Relay Resistance Protocol (EXCHANGE RELAY RESISTANCE DATA).

4.2 What the issuer does with it, and what it sends back

In our purchase the issuer gateway sends four HSM commands (steps 19–22, 27–28):

  1. Verify ARQC, then iCVV: two separate commands, the second under the card verification key (CVK). For the ARQC the gateway sends the PAN, PSN, ATC, the MACed data and the ARQC. The HSM derives the card and session keys internally, recomputes the MAC and returns match or no match. No key leaves the HSM.
  2. Verify PIN (§5).
  3. Generate ARPC. The reply cryptogram covers the ARQC and the issuer’s decision: in method 1 the 2-byte authorisation response code (ARC; approval is ASCII 00 = 30 30), in method 2 the 4-byte CSU. EMV defines two methods:
Method 1Method 2
ComputationARPC = encrypt(K, ARQC ⊕ (ARC ‖ zero padding))ARPC = MAC(K, ARQC ‖ CSU ‖ proprietary data)
ARPC length8 bytes4 bytes
Returned in tag 91ARPC ‖ ARCARPC ‖ CSU ‖ optional data

K is the session key or the card master key, as the cryptogram version specifies. The 4-byte CSU (card status update) in method 2 carries the decision (byte 2 bit 8: issuer approves; our approval is 00 80 00 00) and lets the issuer tell the card things like “reset offline counters” or “block application”.

Because the ARPC covers the decision, some HSM work always sits on the critical path after the decision. The issuer has two ways to arrange it:

ArrangementHSM calls after the decisionCost
Verify the ARQC early, in parallel with the other checks; generate the ARPC once the decision is made (the simulator)1two cryptogram calls in total, plus iCVV and PIN verification
One combined verify-and-generate call made after the decision; repeat it with a decline code if the ARQC turns out invalid1, rarely 2the decision waits for nothing, but cannot depend on the ARQC result until the call returns

Both go into the latency budget in part 2.

For our contactless purchase the ARPC goes into DE 55 of the 0110 and stops at the terminal. On contact, the terminal passes it to the card. The card verifies it, which proves the answer came from its own issuer, and answers the second GENERATE AC with a TC. The cryptogram that travels in the clearing record (part 4) is therefore the TC on contact and the ARQC on one-tap contactless.

On contact only, the card can refuse after the issuer approved: the ARPC fails, or the card’s own rules say no. The card answers AAC, the terminal declines, and the acquirer must reverse an authorization the issuer already counted. Part 3 covers that case.


5. An online PIN never exists in clear outside tamper-resistant hardware

The PIN pad builds an ISO 9564 PIN block the moment the PIN is entered (step 10). Format 0 is the PIN field XORed with 12 digits of the PAN, so a block cannot be moved to another card. Format 0 is used with triple-DES; format 4 is required with AES. For our PIN 1234 and test PAN 4111 1111 1111 1111:

PIN field   04 12 34 FF FF FF FF FF     0 = format, 4 = length, PIN, F fill
PAN field   00 00 11 11 11 11 11 11     0000 + 12 rightmost digits, check digit excluded
PIN block   04 12 25 EE EE EE EE EE     XOR (the simulator computes this live)

The block is encrypted under a key unique to this transaction, derived by DUKPT (ANSI X9.24) from a key injected into the PIN pad. The key serial number (KSN) travels with the block, so the acquirer’s HSM can derive the same key from its base derivation key.

HopEncrypted underHSM operation
PIN pad → acquirerDUKPT transaction key + KSNacquirer HSM: translate to the zone PIN key shared with the network (steps 12–13)
acquirer → networkzone PIN key (acquirer–network)network HSM: translate to the issuer’s zone PIN key (step 16)
network → issuerzone PIN key (network–issuer)issuer HSM: verify, against the stored PVV or IBM 3624 offset (steps 21–22)

Each translation decrypts and re-encrypts inside one HSM command. The issuer’s authorization service only learns correct / incorrect. On failure it increments the try counter; on success it resets it. Zone keys are rotated with 0800 key-exchange messages.

Offline PIN differs. For an inserted card with offline plaintext PIN, the PIN crosses the card contacts in clear inside VERIFY. Offline enciphered PIN encrypts it to the card’s public key instead. The card keeps its own try counter, independent of the issuer’s. Issuers keep the two in step if they choose to: the CVR reports the card’s counter, and an issuer script can reset it. Scripts reach the card on contact, or on the rarely used kernel-3 second tap (§3).


6. When the “card” is a phone: network tokens

If the customer pays with a phone wallet, the terminal never sees the card number. It sees a token: a number from a token BIN range (usually 16 digits; the framework allows 13–19), with its own expiry, issued by the network’s token service provider (TSP) under the EMVCo Payment Tokenisation framework. Visa’s TSP is Visa Token Service, Mastercard’s is MDES.

Card PANNetwork token
Visible to the merchantyes (masked on receipts)yes, but useless elsewhere
Bound tothe accounta domain: one wallet on one device, or one merchant’s card-on-file
Cryptogram keyderived from the issuer’s IMK, in the chiptoken keys in a secure element, or limited-use keys for host card emulation, provisioned by the TSP
Transaction counter (ATC)the chip’sits own, per token: the wallet scenario’s token is at 0007 while the plastic card is at 002B
Cryptogram verified bythe issuer’s HSMthe TSP, on the issuer’s behalf (or the issuer, if it hosts the token keys)
Survives card replacementrenewal: same PAN, new expiry and CVV; lost or stolen: new PANyes: the TSP re-maps the token to the new PAN or expiry
Links related credentials—PAR (payment account reference, 29 characters): the same for the PAN and all its tokens, and not usable to pay

The authorization changes in four places (phone-wallet scenario):

  1. Provisioning, once, when the card is added to the wallet: the TSP asks the issuer to approve binding a token to this device. The issuer may require extra verification (an OTP or an app login) first.
  2. At the till, the token runs the same contactless kernel as a card. Cardholder verification is CDCVM (consumer-device CVM: biometric or device passcode), done on the phone before the tap and reported in the CTQ. It counts as SCA, so the €100 needs no PIN.
  3. In the network, the token service checks the token’s domain restriction controls and rejects a token used outside its domain, such as a device token keyed into a web form. It validates the cryptogram and detokenizes: the real PAN goes into DE 2 for the issuer, and the token, its requestor and the validation result go into token fields. The issuer decides on its own account, as for a plastic card, and can see which device and wallet paid.
  4. On the way back, the network puts the token back into DE 2 of the 0110. The acquirer and merchant never see the PAN.

For the issuer’s systems, a token is another credential that resolves to the same account. Part 2’s data model keeps a credential → card → account mapping rather than using the PAN as a key: several tokens per card, several cards per account, and a PAN that changes when a card is replaced.


What the issuer receives

Shortly after the tap, the issuer’s gateway holds an 0100 that says:

The network’s response timer is running. The issuer now has to verify, decide, reserve €100 of credit durably, generate the ARPC and reply before that timer runs out. If it misses, the network answers on its behalf. Part 2 is that hot path, and part 3 covers what happens when the timer wins.


Where card data may live

PCI DSS puts in scope every system that stores, processes or transmits the PAN, and every system connected to that environment or able to affect its security. Merchants and acquirers may not store sensitive authentication data (full track or chip data, CVV, PIN blocks) after authorization (Req. 3.3.1). Issuers are the exception: Req. 3.3.3 lets them keep it with a documented business need, encrypted. The design in parts 2–5 places the data like this:

DataWhere it may existWhere it must not
PIN, PIN blockPIN pad, HSMs, encrypted in transitat rest anywhere; any log
PVV / PIN offsetthe card record in the cardholder-data environmentanywhere else
CVV / iCVV / track 2 equivalentin memory during authorization; issuer storage only with a documented need, encrypted (Req. 3.3.3)event streams, analytics, logs
Card and issuer keysin clear: HSMs only; elsewhere only as encrypted key blocksanywhere in clear
Full PANan encrypted vault in the cardholder-data environment; the “show card details” feature goes vault → device over a dedicated channelevent streams, analytics, logs, the app’s backend and API
Truncated PAN (first 6–8 + last 4)support tools, analytics, the app—
Internal card ID, account IDeverywhere—

The event platform in part 5 carries internal IDs and amounts, never PANs. That is necessary for keeping Kafka, the history store and analytics out of PCI scope, but not sufficient: they must also be segmented from the cardholder-data environment. The issuer’s own internal tokenization is separate from the network tokens in §6.

Sources

Questions? Let's Chat :)

card payments