Debugging an ARQC mismatch

By · published · technically reviewed

Runs in your browser. This page loads no analytics or third-party scripts and does not send what you type.

An ARQC mismatch means the card and the host computed different cryptograms from what should be the same inputs. The host’s error rarely says which input differs. Check the inputs in the order below. Use test keys only.

Step 0: identify the cryptogram version

Read the Cryptogram Version Number (CVN) from the Issuer Application Data (tag 9F10). The CVN decides the card key derivation, the session key, the data elements in the cryptogram and their padding. If the host assembles the data for a different version, nothing after this can match. The tag page for 9F10 decodes the Visa IAD formats and shows the CVN.

Card key: Option A or Option B

The card’s master key for application cryptograms (often called the UDK) is derived from the issuer master key with the PAN and PAN Sequence Number (EMV Book 2, Annex A1.4). Option A uses the rightmost 16 digits of PAN ‖ PSN. Option B applies to PANs longer than 16 digits: it hashes PAN ‖ PSN with SHA-1 and decimalises the result. For a PAN of 16 digits or fewer, Option B gives the same key as Option A, so the option only matters for longer PANs.

Confirm the card key by its KCV before going further. The KCV calculator gives it for a key you enter; the verifier shows the KCV of each derived key.

Session key

VersionCard keySession keyPaddingARPC
Visa CVN 10Option Anone: the card key is used directlyISO 9797-1 method 1 (zeros)method 1
Visa CVN 18Option BEMV common session key, diversified by the ATCISO 9797-1 method 2 (80 00 …)method 2

These are the settings of pyemv’s VisaCVN10 and VisaCVN18 classes. AWS Payment Cryptography’s Visa documentation agrees where it covers them: Option A and no session key for CVN 10, the EMV common session key for CVN 18. It also documents Visa CVN 22 as using the same derivation as CVN 18 with different transaction data.

For the EMV common session key, the ATC (9F36) is part of the derivation: if the host takes the ATC from the wrong field, or with its bytes swapped, the session key is wrong.

Mastercard versions differ. AWS documents Mastercard CVN 14 and 15 as using the EMV common session key, and CVN 12 and 13 as an older Mastercard-specific derivation that includes the unpredictable number. The verifier below can compute the first with its “EMV common session key” setting and the transaction data the Mastercard version defines; it does not implement the second.

Transaction data and padding

Check the data elements, their order and their lengths against the version. For Visa CVN 10 and 18 the data start with the elements EMV Book 2 recommends, in this order: amount, other amount, terminal country code, TVR, transaction currency code, transaction date, transaction type, unpredictable number, AIP and ATC. CVN 18 then adds the full IAD; CVN 10 adds the CVR. Amounts, dates, codes and the transaction type are numeric fields in BCD; one transposed field changes the whole MAC.

Padding is the other common difference: method 1 pads with zeros to a multiple of 8 bytes, method 2 adds 80 and then zeros. Some systems log the data already padded. The verifier accepts the data with or without the padding.

ATC and unpredictable number

The ATC and the unpredictable number (9F37) are inputs to the cryptogram. If the host logged the UN differently from what the terminal sent to the card, the result will not match. Compare the raw values in the authorisation message (DE 55; the ISO 8583 decoder parses it) with the values in the terminal’s APDU log, not the parsed or reformatted ones.

The response cryptogram (ARPC)

When the ARQC verifies but the card rejects the issuer’s response, check the ARPC method. Method 1 encrypts the ARQC XORed with the response code: an 8-byte ARPC. Method 2 computes a MAC over the ARQC, the Card Status Update and optional proprietary data: a 4-byte ARPC. Visa CVN 10 uses method 1 and CVN 18 method 2. The ARPC must be computed over the ARQC the card sent, even when the issuer’s own expected ARQC differs.

Host side or card side

If the card is a known-good test card, treat its cryptogram as correct and investigate the host. If neither side is trusted, compute the cryptogram independently and compare it with both.

Verifier

The verifier re-runs the computation with common mistakes and reports any variation that reproduces the expected value. A matching variation points to one input difference to investigate; it does not prove the cause. Load one of the published examples first to see the published value next to the tool’s result.

Input

Option B card key, EMV common session key, Method 2 padding, ARPC method 2. Option B only differs from Option A for PANs longer than 16 digits.
Amount, other amount, terminal country, TVR, currency, date, type, UN, AIP, ATC, IAD/CVR, concatenated per the CVN template.
Is the data already padded?
ARQC generated: AD2EC3522E88CDED

Result

ARQC (generated)
AD2EC3522E88CDED
The data the MAC covers
data000000001000000000000008400000000000098000000000000825000100padding8000

Labelled in the EMV Book 2 recommended order, which Visa CVN 10 and 18 follow; check other versions against their own layout. The MAC runs over 4 blocks of 8 bytes:

Block 10000000010000000
Block 20000000840000000
Block 30000098000000000
Block 40008250001008000
Derivation trace (7 steps)
IMK0123456789ABCDEFFEDCBA9876543210KCV 08D7B4
Y = Option B with a PAN of 16 digits or fewer = Option A: rightmost 16 digits of PAN ‖ PSN0000000000000200
UDK = TDES(IMK, Y) ‖ TDES(IMK, Y ⊕ FF…), odd parity: EMV Option B13FD323701FBFEE07C49DF575D9B1A62KCV BB9805
Session key = EMV CSK(UDK, ATC)506B8DED1F5BCE86B10B3333497DE380ATC 0001 · KCV 67CFC5
Transaction data00000000100000000000000840000000000009800000000000082500010030 bytes
Padded: ISO 9797-1 Method 2 (80 then zeros)0000000010000000000000084000000000000980000000000008250001008000
ARQC = Retail-MAC(SK, padded)AD2EC3522E88CDED

Every intermediate value is shown so you can find which input is wrong. Runs in your browser. Test keys only.

The EMV transaction walkthrough shows an ARQC and ARPC being computed in a full transaction, for Visa CVN 10 and CVN 18. For a version the tool does not cover, or a mismatch that no variation explains, see EMV troubleshooting.

References

See also

Related tools