Part IV Data Secure Transmission Control - 22.2
Part IV Data Secure Transmission Control - 22.2
April 2022
THIS PAGE IS INTENTIONALLY LEFT BLANK.
Part IV: Data Secure Transmission Control
Copyright
UnionPay International Co. Ltd. (“UnionPay International”) retains intellectual property rights concerning this
specifications document and all other documents referenced, attached, and produced by UnionPay International,
including but not limited to copyright, patents, trademarks, and trade secrets. Any use of this specifications
document by any legal and/or natural person is limited by the rules specified in the agreement signed by UnionPay
International Institution Services Portal (https://inst.unionpayintl.com) and UnionPay International. UnionPay
International shall not be liable for any errors or omissions in this specifications document or any losses resulting
therefrom.
Without UnionPay International’s written consent, you may not use this specifications document for uses and
purposes aside from matters involving cooperation with UnionPay International. Without UnionPay International’s
written consent, you may not download, forward, or, publically or in any other form, provide this specifications
document to third parties. If any legal and/or natural person used illegal means to obtain this specifications document,
please immediately delete it and notify UnionPay International.
UnionPay International makes no representations or warranties, including but not limited to, whether or not this
specifications document or its related documents infringe upon the intellectual property rights of third parties. The
user agrees that UnionPay International shall not be liable relating to whether or not the use of this specifications
document infringes on third party rights.
Trademarks
UnionPay International Co. Ltd. (“UnionPay International”) and its various forms are registered trademarks of
UnionPay International Co. Ltd. and its Affiliate(s). All other company or product names mentioned herein are
trademarks of their respective companies.
UPI CONFIDENTIAL I
Part IV: Data Secure Transmission Control
Table of Contents
ABOUT THIS DOCUMENT ...................................................................................................................................... III
SUMMARY OF REVISIONS ...................................................................................................................................... V
1 KEY MANAGEMENT AND CONTROL ................................................................................................................ 1
1.1 SECURITY MANAGEMENT .....................................................................................................................................1
1.2 KEY INTRODUCTION.............................................................................................................................................2
1.3 KEY GENERATION ................................................................................................................................................3
1.4 KEY DISTRIBUTION ..............................................................................................................................................4
1.5 KEY STORAGE .....................................................................................................................................................4
1.6 KEY DESTRUCTION ..............................................................................................................................................4
2 DATA ENCRYPTION ......................................................................................................................................... 5
2.1 PIN ENCRYPTION AND DECRYPTION .......................................................................................................................5
2.2 MAC CALCULATION FOR ONLINE MESSAGE .............................................................................................................7
2.3 MAC CALCULATION OF SEQUENTIAL FILE ..............................................................................................................12
2.4 ENCRYPTION AND DECRYPTION FOR INTERNET PAYMENT PIN ....................................................................................13
2.5 FILE ENCRYPTION AND DECRYPTION IN FLOW TRANSMISSION MODE ..........................................................................14
3 KEY RESET .................................................................................................................................................... 15
3.1 KEY RESET REQUEST INITIATED BY MEMBERS ..........................................................................................................15
3.2 KEY RESET INITIATED BY GSCS.............................................................................................................................17
3.3 SWITCHING BETWEEN NEW/OLD KEY (SYNCHRONOUS)............................................................................................20
3.4 KEY BLOCK ......................................................................................................................................................21
4 SECURITY SPECIFICATION ON UPI IC DEBIT/CREDIT STANDARD IC CARD ....................................................... 27
4.1 SECURITY AUTHENTICATION FUNCTION .................................................................................................................27
4.2 ARQC & ARPC ...............................................................................................................................................27
UPI CONFIDENTIAL II
Part IV: Data Secure Transmission Control
Audience
The audience of this document are UnionPay International (UPI) staff and UPI Members who have adopted message
format version 2.1 (the message format version is indicated in the online message header).
Document Version
Version 22.2 replaces the previous version.
Revisions
UPI will periodically issue updates to this document, as enhancements and changes are implemented or corrections
are required. Occasionally, updates to this document will be published in an Operation Bulletin.
Please refer to the Summary of Revisions for changes in this version.
Time Expressed
UPI has operation centers in several locations, including Shanghai and Beijing. For operational purposes, the time
frame in this document, unless particularly indicated, refers to “Beijing time”. Coordinated Universal Time (UTC) is
the global standard time by which the world follows. Beijing time is 8 hours ahead of UTC. There is no Daylight Saving
Time in China.
Unless otherwise specified, the “day” mentioned in this document refers to the calendar day. The “business day”
refers to the working day subject to local regulations of the country where the processing Member is located.
Application Scope
This document applies to all UPI Members.
References
The terms and conditions in this document have quoted the following publications. Any later versions of these
publications will be applied in this document unless otherwise specified. Members are encouraged to study the latest
versions of such documents and decide whether to apply.
OR UPI Operating Regulations
UICS UnionPay Integrated Circuit Card Specifications
EMV 4.3 Integrated Circuit Card Specification for Payment Systems: Book 1 ~ Book 4
Support
Please address your questions to your UnionPay representatives.
Word Convention
Convention Tone Implication
Shall Mandatory Must be followed without exception
Should Optional but recommended Required to follow but optional
Must Mandatory Required without exception
Must not Mandatory Not required
Could Optional Hypothetical
Can Optional Stating a capability
Cannot Optional Stating an incapability
May Optional Stating a possibility
Style Convention
Convention Description
boldface Note/emphasis
italic Publications/book titles
monospace Filename/Command
UPI CONFIDENTIAL IV
Part IV: Data Secure Transmission Control
Summary of Revisions
Description of Changes Location
No revision in this version.
UPI CONFIDENTIAL V
Part IV: Data Secure Transmission Control
Management Policies
Data Security for the whole network entails not only technical support but also establishment and implementation
of strict key management mechanism among UPI Members in terms of business operation. The basic requirements
are as follows:
• To adopt an encryption algorithm that is secure, reliable and widely accepted by bankcard information switch
systems
• To preserve keys and implement transaction information encryption/decryption in the HSM
• To comply with national and international regulations on data security and confidentiality in the financial
industry
• To enhance personnel management
• To change keys regularly
Note: It is recommended for Members to change keys every two years.
UPI CONFIDENTIAL 1
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 2
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 3
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 4
Part IV: Data Secure Transmission Control
2 Data Encryption
For secure data transmission, two cryptographies, i.e. PIN encryption and MAC, are adopted in network messages.
Issuing
Terminal 1 Acquirer 4 GSCS 7 Issuer 10
Bank
2 3 5 6 8 9
The encryption/decryption process between the terminal, the Acquirer, GSCS, and the Issuer is as follows:
1. Terminal sending out PIN cryptograph
2. Decryption by Acquirer with key defined by both Acquirer and terminal
3. Encryption by Acquirer with key defined by both Acquirer and GSCS
UPI CONFIDENTIAL 5
Part IV: Data Secure Transmission Control
PIN Length
A PIN is composed of 4~12 numeric digits.
PIN Block
The PIN Block format shall be consistent with the PAN information format published in ISO ANSI X9.8.
2.1.3.1 ANSI X9.8 (with PAN information)
A PIN Block is generated with the result of “PIN data block XOR PAN data block”. For Payment Token transaction, if
Field 2 is a card number in the message, the card number will be used in the PIN Block calculation. If Field 2 is a Token
in the message, the Token will be used in the PIN Block calculation.
PIN Block format shall be indicated in Field 53 of the message.
Table 7 PIN Data Block
Position Description
Byte 1 PIN length
Byte 2~8 4~12 digit PIN (each digit in 4 binary bits), padded with trailing 0xFF.
UPI CONFIDENTIAL 6
Part IV: Data Secure Transmission Control
Position Description
Byte 1 0x00
Byte 2 0x00
Byte 3~8 The last 12 digits of PAN (excluding the check digit).
It shall be right-justified with leading 0x00 if the length is less than 12 digits.
Example 1:
PIN in plaintext: 123456
PAN of magnetic stripe: 1234 5678 9012 3456 78
PAN intercepted: 6789 0123 4567
PAN data block: 0x00 0x00 0x67 0x89 0x01 0x23 0x45 0x67
PIN data block: 0x06 0x12 0x34 0x56 0xFF 0xFF 0xFF 0xFF
PIN Block (XOR Result): 0x06 0x12 0x53 0xDF 0xFE 0xDC 0xBA 0x98
Example 2:
PIN in plaintext: 123456
PAN of magnetic stripe: 1234 5678 9012 3456
PAN intercepted: 4567 8901 2345
PAN data block: 0x00 0x00 0x45 0x67 0x89 0x01 0x23 0x45
PIN data block: 0x06 0x12 0x34 0x56 0xFF 0xFF 0xFF 0xFF
PIN Block (XOR Result): 0x06 0x12 0x71 0x31 0x76 0xFE 0xDC 0xBA
UPI CONFIDENTIAL 7
Part IV: Data Secure Transmission Control
messages. It is not applicable to administrative messages (06XX) and other network management messages (08XX).
When Acquirers support MAC, they shall generate MACs in request/advice messages. GSCS will also generate MACs
in response messages.
When Issuers support MAC, GSCS will generate MACs in request/advice messages, and Issuers shall generate MACs
in approved response messages. (It is optional for Issuers to generate MACs in disapproved messages)
Fields for MAC Calculation
The fields for MAC calculation are defined by UPI. The MAC is calculated by a mode known as Cryptogram Block
Connection (CBC).
Generally, the following data fields are involved in MAC calculation:
• Unique data fields, including trace number, date, time, etc.
• Data fields representing message features, including message type, transaction type, etc.
• Data fields relating to transaction, including card number, amount, response code, etc.
2.2.2.1 Involved Data Fields for 01xx, 02xx, 04xx Messages
If the following data fields are present or meet certain conditions, they should be included in MAC calculation:
Table 9 Involved Data Fields for MAC Calculation in 01xx, 02xx, 04xx Messages
UPI CONFIDENTIAL 8
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 9
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 10
Part IV: Data Secure Transmission Control
1. XOR the next group with the result generated by using the left 64 bits in the double length-key to the first group
2. XOR the result of the Step a. with all the remaining groups repeatedly until the last group.
3. Decrypt the last XOR result with the right 64 bits in the double-length key, encrypt the result of decryption with
the left 64 bits in the double-length key, and get an eight-byte encryption value.
Example:
Assuming that an MAB can be divided into 4 groups: A1, A2, A3, and A4, and the double-length key can be divided
into 2 groups: K1 (the left 64 bits) and K2 (the right 64 bits), the operation process of double-length key is as follows:
1. Perform DES operation on A1 with K1 to generate B1
2. XOR B1 with A2 and perform DES operation on the result with K1 to generate B2
3. XOR B2 with A3 and perform DES operation on the result with K1 to generate B3
4. XOR B3 with A4 and perform DES operation on the result with K1 to generate B4
5. Decrypt B4 with K2 to generate B5
6. Encrypt B5 with K1 to generate the final encrypted value of 8 bytes.
2.2.4.1.3 Triple-length Key Algorithm
According to ANSI X9.9, an MAB shall be divided into groups of eight bytes (pad 0X00 to the right if the last group
contains less than eight bytes). The following operations will be performed with the MAK as the triple-length key:
1. Execute TDEA operation;
2. XOR the TDEA operation result with the eight bytes in the next group, and repeatedly TDEA the XOR result, and
then XOR the TDEA result with the following group. An eight-byte encryption value can be obtained by TDEA
operation on the last XOR result.
Example:
Assuming that an MAB can be divided into 4 groups: A1, A2, A3, and A4, the operation process of a triple-length MAK
is as followed:
1. Perform TDEA operation on A1 with the MAK to generate B1;
2. XOR B1 with A2, perform TDEA operation on the result with the MAK to generate B2;
3. XOR B2 with A3, perform TDEA operation on the result with the MAK to generate B3;
4. XOR B3 with A4, perform TDEA operation on the result with the MAK to generate the final encrypted value of 8
bytes.
2.2.4.2 MAC Field Value of Online Message
2.2.4.2.1 01xx, 02xx, 04xx Messages
The MAC field (Field 128), which is the first half of the 8-byte binary digit (a 4-byte binary digit) from MAC Calculation
by HSM, is presented in the form of a hex character string (eight hex characters).
2.2.4.2.2 Key (ECB Enciphered) Reset Initiated by GSCS
In the key (ECB enciphered) reset request message initiated by GSCS and the corresponding response message, the
MAK shall be the newly distributed key. Additionally, the newly distributed PIN key shall be adopted in MAC
calculation during PIN key reset.
MAC Calculation in Request Message
The MAC field (Field 128) of request message, an eight-byte binary number, is composed of two parts. The first part
UPI CONFIDENTIAL 11
Part IV: Data Secure Transmission Control
is the first half of the 8-byte binary number (a 4-byte binary number) obtained by MAC calculation, and the second
part is the first half of the 8-byte binary number (a 4-byte binary number) obtained by Check Value calculation.
MAC Calculation in Response Message
If an MAK or a PIK is to be reset, the MAC in response message is obtained by MAC calculation with the newly
distributed key.
Check Value Calculation
The Check Value can be obtained by MAC calculation on eight-byte binary 0 with the newly distributed key.
2.2.4.2.3 Key (TR-31 Key Block) Reset Initiated by GSCS
Field 128 in Request Message
For key (TR-31 key block) reset initiated by GSCS, Field 128 of request message, a 64-bit binary number, is composed
of two parts. The first part is the padding (32 bit ‘0’s), and the second part is the first 32 bits of the key check value
(a 32-bit binary number) obtained by Check Value calculation.
Field 128 in Response Message
Field 128 should not be present in the Response Message.
Check Value Calculation
The Check Value can be obtained by CMAC calculation (specified in ISO 9797-1) on all binary zero block (64-bit ‘0’s
for TDEA/DES keys) with the newly distributed key.
MAB Composition
Each record of the file (including file head and trailer records but excluding MAC Keys and MACs) shall be divided into
groups of 256 bytes and left-justified with trailing binary zeros if the length is less than 256 bytes; the MAC Block for
the sequential file is the result of performing XOR of each group.
MAC Calculation
UPI CONFIDENTIAL 12
Part IV: Data Secure Transmission Control
Where,
N- Internet Payment PIN length (8 bit);
P- Binary Internet Payment PIN digit (8 bit);
P/F- Binary Internet Payment PIN digit/Filler (8 bit);
F- Filler (8 bit)
Position Description
Byte 1~2 Length pf Internet Payment PIN
Byte The length of the Internet Payment PIN ranges from 6 to 20 digits (each character is 1 byte digit left-
3~24 justified with trailing spaces if there is any vacancy, i.e. 0xFF)
Example:
Assume the plaintext of the Internet Payment PIN is “Hello!123”:
As the Internet Payment PIN is displayed in plaintext, it has to be changed to the ASCII code.
Table 13 Internet Payment PIN Data Block Coding Example
UPI CONFIDENTIAL 13
Part IV: Data Secure Transmission Control
Plaintext H e l L o ! 1 2 3
ASCII Code 72 101 108 108 111 33 49 50 51
Hex Value 0x48 0x65 0x6C 0x6C 0x6F 0x21 0x31 0x32 0x33
As described in the table above, this Internet Payment PIN has 9 characters, so “09” is added in front of the PIN,
indicating the length, ASCII coded as 48 and 57; Hex coded as 0x30 and 0x39. Then 13 spaces is padded to the right,
forming the Hex code of 0xFF. Therefore, the result of Internet Payment PIN data block is as follows:
0x30 0x39 0x48 0x65 0x6C 0x6C 0x6F 0x21 0x31 0x32 0x33 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
Error Processing
Error processing and error response code is the same as the processing for PIN.
UPI CONFIDENTIAL 14
Part IV: Data Secure Transmission Control
3 Key Reset
3.1 Key Reset Request Initiated by Members
Transaction Flow
A Member sends the 0820 Key Reset Request advice message to GSCS. Upon receiving the 0820 advice message,
GSCS shall reply the 0830 response immediately. Meanwhile, GSCS shall start up the Key Renewal Module to generate
a new key and send the Member the new key in the 0800 Key Reset request message.
GSCS will drop the message in case GSCS fails to reply to the Key Reset Request or sends Key Reset to Member.
2
Member GSCS
3
Flowchart
UPI CONFIDENTIAL 15
Part IV: Data Secure Transmission Control
Start
Send RSI-MB-SC a N
Receive KSM-SC-MB
Verify MAC
Y N
with new key
End
Note a: RSI-MB-SC, Key Reset Request advice message (0820) sent by a Member to GSCS
Note b: RSI-SC-MB, Key Reset Request advice response message (0830) sent by GSCS to a Member
Note c: KSM-SC-MB, Key Reset request message (0800) sent by GSCS to a Member
Note d: KSM-MB-SC, Key Reset request response message (0810) sent by a Member to GSCS
UPI CONFIDENTIAL 16
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 17
Part IV: Data Secure Transmission Control
Member GSCS
Flowchart
UPI CONFIDENTIAL 18
Part IV: Data Secure Transmission Control
Start
Send KSM-SC-MB a N
Verify MAC
with new key
End
Note a: KSM-SC-MB, Key Reset request message (0800) sent by GSCS to a Member
Note b: KSM-MB-SC, Key Reset request response message (0810) sent by a Member to GSCS
UPI CONFIDENTIAL 19
Part IV: Data Secure Transmission Control
with the new key. If the MAC check is successful, GSCS will add a start-up tag to the new key, and all message delivered
shall be encrypted by using this new key. If the MAC check fails, GSCS will initiate manual processing, contacting the
Member to offer advice and assistance to the best of its ability.
The shift window for the new and old keys is defined as three minutes, during which the new and old keys coexist.
Within the time window, GSCS will perform decryption, conversion or verification for PIN and MAC information sent
by the Member with this new key. This operation shall be repeated with the old key in case errors found in PIN format
or MAC verification. If the error still exists, it shall be regarded as a material error and encryption/decryption failure,
and GSCS will directly contact the Member and try to offer assistance. The following operations shall be carried out
when the time window is exceeded:
• To replace old key with new one
• To eliminate start-up tag attached to new key
• To finish Key Reset
GSCS will activate manual processing by contacting the Member to look into the reason if the errors still occur during
encryption and decryption with the new key when the time window is exceeded.
For more information about the message format, Please refer to Section 4.3 Message Definition for Security Control
Message of Part II Online Message.
UPI CONFIDENTIAL 20
Part IV: Data Secure Transmission Control
Member GSCS
3 minutes
time slot
3 minutes
time slot
UPI CONFIDENTIAL 21
Part IV: Data Secure Transmission Control
KBMK CMAC
1. The confidential data to be encrypted is padded on the right with 0x00 until it is a multiple of 8 bytes;
2. CMAC by triple-length TDEA is applied to the entire payload, that is, the header concatenated with the
confidential data, including padding, using the KBMK to generate an 8-byte MAC;
3. Then, the confidential data is CBC-encrypted with TDEA by using the 8-byte MAC previously generated and the
KBEK, which yields a Ciphertext;
4. The hex-ASCII Ciphertext is transmitted along with the hex-ASCII MAC and the plaintext of Header.
UPI CONFIDENTIAL 22
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 23
Part IV: Data Secure Transmission Control
The following diagram illustrates how to derive triple-length KBEK and KBMK from a triple-length MMK:
UPI CONFIDENTIAL 24
Part IV: Data Secure Transmission Control
M1 M2 ... Mn*
+ + K1
TDEA by K
TDEA by K TDEA by K
MAC
UPI CONFIDENTIAL 25
Part IV: Data Secure Transmission Control
UPI CONFIDENTIAL 26
Part IV: Data Secure Transmission Control
UDK
UDK A UDK B
UPI CONFIDENTIAL 27
Part IV: Data Secure Transmission Control
2. To pad hex “0” to the left of the ATC (Tag 9F36) in the message to make it up to eight bytes and perform 3DES
operation on the result with the UDK to get the first eight bytes as Session Key A
3. To XOR the 16-bit ATC with a hex value of FFFF (16 bit) and pad hex “0” to the left of the result to make it up to
eight bytes, and then perform 3DES operation on the outcome with the UDK to get the last eight bytes as Session
Key B
4. To create the session key (totally 16 bytes) by combining the first eight bytes and the last eight bytes as follows:
Table 18 Dual-length Session Key Generation
Session Key
Session Key A Session Key B
The Session key must meet requirements for odd parity.
Algorithms of ARQC
4.2.4.1 Data Source
The Issuer may decide the data source and sequence for ARQC calculation at its discretion. The commonly-used data
source and sequence can be adopted if Issuer does not exercise its discretion.
Table 19 Data Source of ARQC
No. Data Element Data From Terminal Data Involved in Data in Corresponding
Terminals? Terminal Field Hash Value Card? Message Tag
Computation?
1 Authorized Amount √ √ 9F02
2 Other Amount √ √ 9F03
3 Terminal Country √ √ 9F1A
Code
4 Terminal Verification √ √ 95
Result
5 Transaction Currency √ √ 5F2A
Code
6 Transaction Date √ √ 9A
7 Transaction Type √ √ 9C
8 Unpredictable √ √ 9F37
Number
9 Application √ 82
Interchange Profile
(AIP)
10 Application √ 9F36
Transaction Counter
(ATC)
11 Issuer Applied Card √ 9F10
Verification Result
(CVR)
UPI CONFIDENTIAL 28
Part IV: Data Secure Transmission Control
These three data sources, i.e. terminal field, Hash value for terminal field, and data in card, shall be involved in ARQC
calculation according to the universal algorithm.
The Hash value for the terminal field will be obtained through SHA-1 and, comprising 20 bytes. In the wake of the
Hash value is the terminal data and the card data, which can be arranged one after another according to the sequence
shown in the above table with their values unchanged.
Hence, the source data for ARQC calculation is arranged in the following sequence:
Table 20 ARQC Source Data Sorting
UPI CONFIDENTIAL 29
Part IV: Data Secure Transmission Control
unit
The sequence of the data link in the message shall be identical to the order of corresponding data objects in the
TDOL.
Note: The definition of “n” is the same as that in UICS (UnionPay Integrated Circuit Card Specifications).
ARPC Calculation
ARPC is generated from ARQC. The detailed algorithm is as below:
1. To perform XOR operation on the Application Cryptogram with the response code for the Authorization
Response Cryptogram (in Tag 91). The Application Cryptogram is populated in the Tag 9F26 subfield of the
uploaded request message, generally the ARQC, or the AAC under special circumstances. Prior to XOR, the
response code for the Authorization Response Cryptogram should be left justified with six bytes trailing 0x00’s.
2. The result of the above mentioned is an 8-byte data block D1, which can lead to an 8-byte ARPC by 3DES
operation with the session key.
UPI CONFIDENTIAL 30