Key management

Tomcat

Professional
Messages
2,689
Reaction score
963
Points
113
To ensure the security of operations performed using the IPC, the card stores the keys of both symmetric and asymmetric encryption algorithms. Asymmetric encryption algorithms are used for offline dynamic card authentication procedures and encryption of the PIN-code transmitted by the terminal to the card. Key pairs (public and private) for asymmetric encryption algorithms are generated either directly by the IPC or by the card issuer. These keys are associated with the card issuer through the card's public key certificates generated by the card issuer.

The situation is different with symmetric encryption algorithms. These algorithms assume the existence of a shared secret between the parties using them and therefore are used in EMV only for the interaction of the card and its issuer.

To improve the security of operations in terms of the use of symmetric encryption algorithms, a hierarchical structure of key management is used. Symmetric keys in the EMV standard can be used for different purposes: to form cryptograms, to ensure confidentiality and integrity of information exchange between the card and the issuer. The issuer creates a master key for a specific purpose, designed to generate keys for a card of the same purpose. The issuer's master key is used for a number of issuer's cards, usually identified by an identifier issued to the bank by the payment system (Bank Identification Number, or BIN for short). With some by the issuer of the diversification fashion, it generates for each card from the aforementioned set a personal card key of the same purpose as the issuer's key. In turn, the card, using the card key and the diversification mode defined by the issuer, for each transaction generates a session key for the same purpose.

Such a hierarchical system for generating symmetric keys increases the costs of fraudsters for the implementation of fraud, which means that it can improve the security of transactions performed using the IPC. Indeed, a fraudster who has access only to the details of a card operation (the most accessible and, therefore, the cheapest option for a fraudster) can hope to compromise the card's session keys. Even by compromising these keys, the fraudster will achieve practically nothing, since the next operation will use new session keys and, in order to find them, the card keys must be compromised.

Having spent a lot of effort and compromising the card keys, the fraudster will be able to emulate transactions with only one card. To emulate the operations of other cards, knowledge of the issuer's key is required.

Thus, ensuring the confidentiality of the issuer's keys becomes the holy of holies in security schemes for IPC transactions. However, here is the time to remind you that the IPC stores a whole set of keys for symmetric and asymmetric encryption. So, compromising the key of an issuer of a certain purpose, in addition to being difficult to implement, practically does not give a fraudster a chance of success. Unfortunately, there are other methods of fraud using the IPC, which will be discussed separately in clause 6.6.

Let's consider algorithms for generating card keys and session keys.

3.16.1. Procedure for withdrawing card keys from the issuer's keys

The EMV card application for performing a transaction (about keys for personalizing cards is described in Chapter 5) can use the following 16-byte keys of symmetric encryption algorithms:
  • MKsd - ICC Master Key for AC generation (a key for outputting a session key intended for generating applied card cryptograms);
  • MK SMI - ICC Master Key for Secure Messaging for Integrity and Authentication (key for outputting the session key used to ensure the integrity of the data transmitted in the command and to authenticate the command sender);
  • MK SMC - ICC Master Key for Secure Messaging for Confidentiality (key for displaying the session key used to ensure the confidentiality of the data transmitted in the command);
  • MK IDN - ICC Master Key for ICC Dynamic Number Generation (the key used to generate the ICC Dynamic Number value).

All the listed keys, in turn, are obtained from the corresponding keys of the issuer of this card (Table 3.25).

Tab. 3.25. Matching card and issuer keys

ICC Master KeyWithdrawn from Issuer Master Key
mk AC1MK AC
MK SMIIMK SM ,
mk smcIMK smc
MK IDNIMK 1DN

In general, the choice of the algorithm for deriving the card key from the issuer's key is the prerogative of the issuer. Meanwhile, the EMV standard offers its own version of the key derivation. In addition, payment systems, on behalf of the card issuer, in case of unavailability of the latter (failure in the issuer's processing center or communication problems) perform the function of backup authorization on behalf of the issuer (Stand-In mode). To be able to do this, the payment system must be able to derive the card key and the session key from the issuer's key. As a result, in specific implementations, the algorithm for deriving the card key from the issuer's key is determined by the payment systems.

The EMV v.4.2 standard offers the following algorithm for deriving the key of the MK card from the key of the issuer IMK.

Case 1. The size of the PAN card number is 16 digits or less. An 8-byte number Y is obtained by concatenating the PAN data elements and the PAN Sequence Number (if the last data element on the card is not present, it is replaced by the '00'h byte). Note that if the concatenation of the PAN and PAN Sequence Number results in a number less than 8 bytes, then it is padded on the left with 'O'h nibbles to produce a number of 8 bytes. If the size is obtained g AH

MasterCard to J

If the number is more than 8 bytes, then the rightmost 8 bytes of this number are taken as Y.

After the number Y is obtained, the left and right components of the card key Z L and Z R are calculated :

Z L = DES3 (IMK) [Y];

Z R = DES3 (IMK) [Y ® (FF || 'FF' || 'FF' || 'FF' || 'FF' || 'FF' || 'FF' || 'FF')]; MK = (Z L || Z R ).

Case 2. The size of the PAN card number is more than 16 digits. In this case, the algorithm for deriving the card key is as follows:
  • 1) PAN and PAN Sequence Number data items are concatenated (if the last data item on the card is missing, it is replaced by the '00'h byte). If the card number contains an odd number of digits, then a nibble 'O'h is added to the left of the previously received sequence;
  • 2) the SHA-1 hashing algorithm is applied to the sequence obtained at the previous step. The result is an X sequence of 40 nibbles. Moving along the sequence X from left to right, we sequentially select those nibbles that correspond to decimal digits (0, 1, ..., 9). The result of this procedure is a sequence of decimal digits Y. If its size is more than 16 digits, then the leftmost 16 digits are selected from it. Otherwise (Y is less than 16 decimal digits), the nibbles of X corresponding to non-decimal digits are converted to nibbles corresponding to decimal digits using the decimalization table:
Nibble XAvwithDEF
"Decimized" nibble012345

When moving from left to right along the "decimylized" nibbles, the last one after another are added to the right of Y until a sequence of Y consisting of 16 decimal digits is obtained.

After receiving Y, the card key MK = (Z L || Z R ) is calculated as in case 1.

3.16.2. Session keys output procedure

The choice of the procedure for withdrawing the session key SK - (SK, || SK R ), where SK E and SK R are 8-byte numbers, from the card master key is the prerogative of the card issuer. In the EMV specifications prior to version 4.0, there was a single informal restriction on the transformation of the session key output SK = F (MK) [X], which was that the number of possible values of the function F was large enough and uniformly distributed. Later, in version 4.0 of the EMV standard, there was also a requirement that the probability of repetition of diversification data X was low, and also a key tree derivation algorithm (AVDK) was proposed for deriving the session key from the value of the card key and the ATC transaction counter.

In the EMV v.4.2 standard (Appendix A1.3.1), to display all session keys, it is proposed to use the SKD (MK) [X] function from the MK key, for which the session key is displayed, and the 8-byte diversification sequence X = (X o || X, || X 2 1 | X 3 1 | X 4 1 | X 5 1 | X 6 1 | X 7 ). The SKD (M) [X] function is defined by the equalities:

SKD (MK) [X] = (SK L || SK R );

SK L = DES3 (MK) [X 0 II Xi II 'F0' || X 3 1 | X 4 1 | X 5 1 | X 6 || X 7 ];

SK R = DES3 (MK) [X 0 II Xi II 'OF' || X 3 1 | X 4 || X 5 1 | X 6 || X 7 ],

When deriving the session key SK AC, which is necessary for calculating the applied cryptogram, the EMV standard uses the sequence

X = (ATC || '00' || '00' || '00' || '00' || '00' || '00')

8 bytes long, where ATC is a 2-byte application transaction counter. The resulting SK AC value is used to generate all cryptograms calculated by both the card and the issuer (to calculate the AR.PC cryptogram) during the transaction.

When outputting session keys SK SMC and SK SMI for Secure Messaging in the EMV standard, the sequence X - АС is used as a diversification mode, where АС is the cryptogram value of 8 bytes, returned by the card in response to the first GENERATE АС command.

The method for calculating session keys described above is called EMV CSK (Card Session Key). Note that the type of transformation SKD (M) [X] is explained, among other things, by the structure of the diversification mode. Indeed, the conversion value does not depend on the third byte X 2 , which, with the used diversification mode structure, always consists of zero bits, since the ATC unit has a size of 2 bytes.

Leading payment systems, along with the EMV CSK method, use their own methods for withdrawing session keys. In the MasterCard payment system, the method for withdrawing session keys is called MasterCard Proprietary SKD. In accordance with this method , the SKD (MK) [X] function is used to output the SK AC session key , and the sequence X - (АТС || '00' || '00' || UN) 8 bytes long, where ATC is a counter of application transactions of 2 bytes in size, UN is a random number (Unpredictable Number) of 4 bytes, generated by the terminal and transmitted to the card in the GENERATE AC command.

In this case, to display the ARPC cryptogram, the issuer uses the key of the MK AC card . The issuer does not withdraw the session key.

For the Secure Messaging procedure in accordance with the MasterCard Proprietary SKD, the issuer calculates its own session key for each Script Processing command. In this case, for the first Script Processing command, the cryptogram returned by the card in response to the first GENERATE AC command is used as a diversification mode. For each next Script Processing command, the diversification mode is obtained from the diversification mode for the previous command by increasing it by 1 (with a preliminary representation of the diversification mode in decimal notation).

The VSDC application has simplified its own procedure for displaying session keys as much as possible. When outputting session keys for the algorithm for ensuring the integrity of the data transmitted in the command and for authenticating the data source SK SMI , as well as for the algorithm for ensuring the confidentiality of the data transmitted in the command SK SMC , the following algorithm is used. The first component of the corresponding key for Secure Messaging is added modulo 2 with the PBX value padded on the right by six zero bytes, and the second component is added modulo 2 with the inverted PBX value padded on the right with six zero bytes. As a result, the compromise of the session key leads to the compromise of the card key, and the meaning of entering the session keys is largely lost.

As for the internal VSDC algorithm for outputting the session key for generating the SK AC cryptogram , in accordance with it, the session key coincides with the card key.

In version 4.0 of the EMV standard, an additional optional algorithm for deriving the key tree was proposed for calculating session keys, which is described below. This algorithm was also used in version 4.1 of the EMV standard.

A tree with height H and branching size of each vertex b is considered. Obviously, at the level 0 <i <H, the number of tree vertices is equal to b '. It is necessary that the number of vertices at the lowest level exceeds the maximum value of the ATC transaction counter, that is, for the inequality b "> 2 16 - 1 to hold.

Consider the transformation Ф (X, Y, j) of two 16-byte numbers X, Y, each 16 bytes in size, and an integer j into a 16-byte number. The transformation Ф (Х, Y, j) has the form:

Z = Ф (X, Y, j) = (DES3 (X) [Y l © j (mod b)] || DES3 (X) [Y R © j (mod b)]),

where Y l and Y r are 8-byte numbers such that Y = (Y L || Y R ).

Obviously, the inverse transformation exists and is determined by the equality:

Y = Ф'ЧХ, Y, j) = (DES3- 1 (X) [Z l ] © j (mod b) || DES3 " 1 (X) [Z R ] © j (mod b)),

where Z L and Z R are 8-byte numbers such that Z = (Z L || Z R ).

For each vertex of the tree, recursively define 16-byte numbers 1K ( j as follows:

1K 0 .o = MK,

where MK is the master key of the card;

1K C = F (MK, IV, j),

where IV is an initial sequence of 16 bytes, 0 <j <b - 1;

IKi, j = F (1K W / L , IKi 2 . J / bS j),

where the sign "/" denotes division entirely (only the whole part of the number obtained as a result of division remains), 2 <i <H, 0 <j <b 1 - 1.

Then, for a given value of the ATC, we determine the value of the session key SK (ATC): = IK H ATC © 1K n _ 2> dts / b 2,

Note that the above definition has one very important property. To determine the value of SK (ATC), it is required to calculate only the values of IK, ATC / b n-> for 0 <i < H . Note that all points of the form i, ATC / b H-1 , where 1 <i <H, lie on one branch of the tree originating from its root (0, 0). Therefore, for any 1 <i <H, the value of IK, ATC / b low depends on

g an

MasterCard

^? 9

IK values. j for two adjacent vertices of this branch of the tree located directly above the vertex (i, ATC / b H “').

Consider the following PBX representation:

ATC = a 0 b n 1 4- a, b n 2 4- ... 4- a n _ 2 b 4- a H _ v

Then the recurrent definition of SK (ATC) can be expressed as the following algorithm:

GP: = MK;

P: = F (MK, IV, a 0 );

For 1 <i <H - 1 do

T: = P;

P: = F (P, GP, aD;

GP: = T

end;

SK (ATC): = F (P, GP, a n _!) © GP.

The VISA payment system for the withdrawal of session keys has included the described AVDK algorithm in its VIS 1.4.x specifications. The applied cryptogram resulting from the use of AVDK was named after the version number of the application "Cryptogram version 14". Due to some legal problems related to the patent purity of using the AVDK algorithm, the payment system sent a letter to participating banks at the beginning of September 2005 to discontinue the use of Cryptogram 14 in VISA cards.

In the latest version of the EMV standard (v.4.2), the AVDK algorithm is absent. It should be admitted that among the known algorithms AVDK is the most "unpredictable" algorithm for generating session keys. This means that it is almost impossible to make any useful assumptions about the new value of the session key from the PBX value and the previously generated session key values.

3.16.3. Limitations on the size of asymmetric encryption keys

Recall that for the lengths (expressed in bytes) of the asymmetric encryption public key modules of the payment system certification authority N ca , the issuer N, and the N IC card , the following relationship is true: NIC <N, < N ac <248.

At the same time, there are additional restrictions on the size of the modules of the specified keys. In particular, the length of the Value field of the AEF Data Template does not exceed 251 bytes (see 3.6). This means that the ICC Public Key Certificate (Tag '9F46') and ICC PIN Encipherment Public Key Certificate (Tag '9F2D') data objects are less than or equal to 251 bytes. Since when the length of the key module exceeds 127 bytes, the length of the Length field of these objects is 2 bytes, it follows that the size of the Value field does not exceed 247 bytes. Since the length of the card key certificate is equal to the length of the issuer's public key module, it follows that the inequality N IC <N, <247 always holds .

The CDA method also imposes a limitation on the size of the N IC card key module . The structure of the Response Template (Tag '77') in the response to the AC GENERATE command when using the CDA method is shown in Table. 3.26 (all sizes in bytes).

Tab. 3.26. Structure of the Response Template

Data objectTagLength field sizeValue sizeOverall size
Response Template123
CID2114
ATC2125
Signed Dynamic Data22NcN IC + 4
Issuer Application Data21Up to 32Up to 35

Since the Issuer Application Data object is optional, then, as follows from table. 3.26, the Response Template size ranges from N IC 4-16 to N 1C + 51 bytes. On the other hand, according to EMV, the size of the command response data field does not exceed 256 bytes.

Hence, when using the CDA method, the size of the card key module can vary in the range from 205 to 240 bytes. Today, on cards, keys with a card's public key module length of 128 bytes are most often used. Therefore, the considered limitation is not yet critical.

The size limitation of the N IC card key module may be imposed by the DDA card authentication method. The response to the INTERNAL AUTHENTICATE command may, in addition to the mandatory Signed Dynamic Application Data data element, contain some special data objects not specified by the EMV standard, presented in the encoding

MasierCa k

BER-TLV. In this case, format 2 of the command response data field is used (the Tag '77' template is used for composite data objects represented in the BER-TLV encoding). This means that 7 bytes will be spent on the Tag and Length fields of the template and the Signed Dynamic Application Data (Tag '9F4B') data object. Thus, the limit on the size of the card's public key modulus, expressed in bytes, in this case is as follows: N IC <249 - Z, where Z is the total size of all special data objects returned to the terminal in response to the INTERNAL AUTHENTICATE command.

Chapter 4
 
Last edited by a moderator:
Key management issues for an EMV microprocessor card are discussed in Sections 10 and 11 of Book 2 of the EMV 4.2 standard. Considerable attention in these sections is paid to the issues of implementation and maintenance of PKI infrastructure. PKI infrastructure is an integral part of a payment system that works with EMV cards and an important element to ensure a high level of security for transactions performed using microprocessor cards. Offline card authentication methods are based on PKI infrastructure.

The payment system certification authority (Certification Authority, or CA for short) is controlled by the payment system and is designed to calculate the public key certificates of the system issuers. CA public keys are sent to serving banks for verification of issuer key certificates. The issuer key certificate is verified during transaction processing when performing offline card authentication and encrypting the PIN block.

In addition, the issuer can use the system key for a one-time validation of its public key certificate received from the CA.

To exchange information between the bank and the CA, it is necessary to establish a secure channel that excludes the possibility of forgery - providing the public keys of the system and the certificate of the issuer's key from the false certification authority of the system. In other words, the transfer procedure

Chapter 6. FEATURES OF MIGRATION ON MICROPROCESSOR CARDS 485

the system's public keys or the issuer's key certificate to the bank must ensure the authentication of the payment system certification center and the integrity of the information transmitted by it.

It is necessary to pay special attention to the issue of protection from entering false system keys into the terminal application. When entering false keys in a terminal, fraudsters can personalize cards under these system keys and use them in terminals with previously loaded false system keys.

Each public key of the system has a validity period, after which it must be revoked from use. This procedure is called the revocation procedure of the key. Key revocation can be planned (after the system key expires) and accelerated (for example, due to key compromise). In the second case, the payment system notifies its participants about the change in the key validity period . Serving banks are obliged to revoke the system keys in all their terminals within 6 months from the date of the key expiration.

All public keys of the system will expire on December 31st. If the key is revoked, the date may be different (not December 31), since the key expiration date changes. However, the six-month period provided by the payment system to servicing banks for revoking the key from the terminals remains in this case as well.

The system certification authority must distribute the new public system keys by January 1 of next year. After that, the servicing banks must download the new system keys to their terminals within 6 months, that is, until June 30 of the next year.

Payment systems allow the use of new system keys in terminals only from January 1, despite the fact that the keys can be brought to banks by January 1. At the same time, the payment system begins to use new system keys to create certificates of the issuer's public keys not earlier than June 30 of the same year.

Payment systems require that the validity period of all certificates used for offline card authentication and encryption of the PIN-block, if such a key is used, should be longer than the card's validity period. This is necessary in order for the hybrid card to be able to carry out a transaction on the chip throughout its entire life cycle.

It is necessary to pay special attention to the issues of secure storage of keys in the issuer's system. In general, the following types of keys are stored in the issuer's system, intended for the issue of IPC:
  • 1MK AS - a key for generating the master key of the MK AS card, intended for outputting the session key for generating applied cryptograms;
  • IMK SMI - a key for generating a master key of the IMK SMI card, designed to display the session key used to ensure the integrity of the data transmitted in the command and to authenticate the data source;
  • IMK SMC - a key for generating a master key of the MK SMC card, designed to display the session key used to ensure the confidentiality of the data transmitted in the command;
  • IMK IDN - a key for generating the MK IDN card master key, intended for calculating the ICC Dynamic Number value;
  • IMK DAC - a key for generating the MK DAC card master key for calculating the DAC value (Data Authentication Code);
  • the issuer key used to calculate the card's public key certificates.
Compromising, for example, the issuer's key used when performing the offline card authentication procedure, leads to the possibility of creating a card that successfully authorizes transactions offline. The EMV v.4.2 standard does not pay attention to the distribution of CRL-lists (certificate revocation lists) to servicing banks in case of compromise of the issuer's keys. These issues should be reflected in the operating rules of specific payment systems.

It is necessary to work out the question of the bank's reaction in the event of a compromise of its keys. Elaboration should begin with defining the settings for card risk management parameters. For example, to combat the compromise of any symmetric key of a card that supports offline dynamic authentication, it will be useful to set the Offline Dynamic Authentication Failed bit in the Card Issuer Action Code - Offline and Card Issuer Action Code - Online objects to 1. This will prevent successful completion of operations using of cards with compromised symmetric keys in offline mode and control the issue of compromising the keys of the issuer and its cards on the host of the issuer. Indeed, not knowing the asymmetric card key, the fake card will fail its dynamic authentication procedure, and the terminal will send an authorization operation to the issuer,

Of course, the issuer can do more radically and reliably by setting the Offline Dynamic Authentication Failed bit in the Card Issuer Action Code - Decline object equal to 1, thereby declaring the fact of the card's dynamic authentication failure sufficient to reject the transaction. However, in this case, the card's use in the terminal network of the payment system may be limited. We have already mentioned the reasons for this limitation: the absence of the system key on the terminal, with which the issuer's key was certified, errors in the terminal application (for example, the terminal did not present a random number to the card), etc.
 
Top