The EMV (Europay, Mastercard, Visa) protocol is the global standard for secure chip-based payment transactions. It replaces magnetic-stripe cards with cryptographic authentication, ensuring tamper resistance and dynamic transaction validation. Below is a
deep dive into APDU commands and
ARQC (Authorization Request Cryptogram) generation, two core components of EMV transactions.
1. APDU Commands in EMV Transactions
Application Protocol Data Units (APDUs) are the structured commands exchanged between the payment terminal (POS) and the card during a transaction. These commands enable the terminal to interact with the card’s embedded chip, retrieve data, and execute cryptographic operations.
Key APDU Commands in EMV Flow
Command | Purpose | Example Use Case |
---|
SELECT | Selects the EMV application (e.g., Visa Credit, Mastercard Debit) by its AID (Application Identifier). | SELECT PPSE(Payment System Environment) to list available apps. |
GET PROCESSING OPTIONS (GPO) | Requests transaction parameters (e.g., AIP, AFL) after app selection. | Initiates the transaction flow. |
READ RECORD(S) | Retrieves static card data (e.g., cardholder name, expiry date) from the card. | Used to gather card details for authorization. |
INTERNAL AUTHENTICATE | Validates the card’s authenticity (for Static Data Authentication). | Rarely used in modern cards (replaced by DDA). |
GENERATE AC | Requests the card to generate a cryptogram (ARQC, ARPC, or TC). | Core step for transaction authorization. |
APDU Command Structure
Each APDU command follows a standardized format:
Code:
CLA | INS | P1 | P2 | Lc (data length) | Data | Le (expected response length)
- CLA: Class byte (e.g., 0x80 for proprietary EMV commands).
- INS: Instruction byte (e.g., 0xA8 for GENERATE AC).
- P1/P2: Parameters (e.g., P1=0x00 for ARQC generation).
- Data: Transaction-specific inputs (e.g., terminal-generated data for ARQC).
Example APDU Exchange
- SELECT AID:
00 A4 04 00 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31 00
Selects the Visa debit application.
- GET PROCESSING OPTIONS (GPO):
80 A8 00 00 02 83 00 00
Requests application-specific parameters (AFL, AIP).
- READ RECORD:
00 B2 01 0C 00
Reads record #1 in the SFI (Short File Identifier) 0C.
- GENERATE AC:
80 AE 80 00 2A [DATA] 00
Requests the card to generate an ARQC (see below for DATA structure).
2. ARQC Generation (Authorization Request Cryptogram)
ARQC is a cryptographic value generated by the card to prove the transaction’s authenticity. It ensures the card is genuine, the transaction data is unaltered, and the cardholder is authorized.
Steps to Generate ARQC
- Input Data Collection
The card aggregates transaction data, including:
- ATC (Application Transaction Counter): Monotonic counter to prevent replay attacks.
- Unpredictable Number (UN): Random value from the terminal.
- Transaction Data: Amount, currency, terminal ID, merchant ID, timestamp, etc.
- Card Data: Application PAN, AIP, TVR (Terminal Verification Results).
- Cryptographic Algorithm
The card applies a cryptographic algorithm (e.g., 3DES, AES, or RSA) using a secret key derived from:
- Issuer’s Master Key (KMC) and the card’s unique Key Derivation Data (KDD) (e.g., PAN, expiration date).
- For symmetric cryptography (e.g., Visa’s CVK):
- For asymmetric cryptography(e.g., DDA):
- Card uses its private key to sign the transaction data.
- ARQC Output
The result is a 64-bit or 128-bit cryptogram (e.g., 9F 26 08 12 34 56 78 90 AB CD EF 01 23 45 67 89).
Example ARQC Workflow
- Terminal sends GENERATE AC command with transaction data.
- Card concatenates:
- ATC (0x001A)
- UN (0x12345678)
- Transaction data hash (0xABCD...)
- Applies 3DES encryption with derived key:
Code:
ARQC = 3DES(K_DERIVED, ATC || UN || HASH)
- Returns ARQC to the terminal for transmission to the issuer.
Issuer Verification
- The issuer decrypts the ARQC using the same key.
- If valid, the transaction is approved (ARPC is sent back).
- If invalid, the transaction is declined (or further checks are triggered).
3. Security Mechanisms in ARQC
- Dynamic Data: Unlike static magnetic stripes, ARQC changes per transaction (due to ATC and UN).
- Key Hierarchy: Issuers derive card-specific keys from a master key, minimizing exposure.
- Tamper Resistance: EMV chips are designed to resist side-channel attacks (e.g., power analysis).
- Terminal Risk Management: Terminals enforce rules (e.g., TVR flags) to detect anomalies (e.g., invalid ATC).
4. Types of Cryptograms in EMV
Cryptogram | Purpose | Generated By | Notes |
---|
ARQC | Authorization Request | Card | Sent to issuer for approval. |
ARPC | Authorization Response | Issuer | Sent back to card to confirm approval. |
TC | Transaction Certificate | Card | Used for offline-only transactions (no issuer contact). |
5. Challenges and Mitigations
- Replay Attacks: Prevented by ATC and UN.
- Skimming: EMV’s dynamic cryptograms render skimmed data useless.
- Man-in-the-Middle (MitM): Secure channel protocols (e.g., EMV’s CDA) protect data integrity.
- Key Management: Issuers use Hardware Security Modules (HSMs) to securely derive and store keys.
6. Real-World Example
Scenario: A cardholder uses a chip card at a U.S. gas station.
- Terminal selects the Visa Debit AID (0x4F010000000000000001).
- Card returns AFL (0x940401020304) indicating data records to read.
- Terminal reads cardholder name, expiry, and public key certificate.
- Terminal generates UN (0x1A2B3C4D) and sends GENERATE AC with transaction data.
- Card computes ARQC using its derived key and returns it.
- Acquirer forwards ARQC to VisaNet, which validates it and approves the transaction.
Conclusion
EMV’s APDU commands and ARQC generation form the backbone of secure chip transactions. By combining structured data exchange (APDUs) with cryptographic authentication (ARQC), EMV ensures that each transaction is dynamic, tamper-proof, and resistant to fraud. Understanding these mechanisms is critical for developers, security researchers, and payment industry professionals aiming to secure modern payment systems.