GP2 2SCP03
GP2 2SCP03
GP2 2SCP03
Public Review
May 2014
Document Reference: GPC_SPE_014
THIS SPECIFICATION OR OTHER WORK PRODUCT IS BEING OFFERED WITHOUT ANY WARRANTY
WHATSOEVER, AND IN PARTICULAR, ANY WARRANTY OF NON-INFRINGEMENT IS EXPRESSLY
DISCLAIMED. ANY IMPLEMENTATION OF THIS SPECIFICATION OR OTHER WORK PRODUCT SHALL
BE MADE ENTIRELY AT THE IMPLEMENTER’S OWN RISK, AND NEITHER THE COMPANY, NOR ANY
OF ITS MEMBERS OR SUBMITTERS, SHALL HAVE ANY LIABILITY WHATSOEVER TO ANY
IMPLEMENTER OR THIRD PARTY FOR ANY DAMAGES OF ANY NATURE WHATSOEVER DIRECTLY
OR INDIRECTLY ARISING FROM THE IMPLEMENTATION OF THIS SPECIFICATION OR OTHER
WORK PRODUCT.
Contents
1 Introduction ............................................................................................................................ 5
1.1 IPR Disclaimer....................................................................................................................................... 5
1.2 References ............................................................................................................................................ 5
1.3 Terminology and Definitions.................................................................................................................. 6
1.4 Abbreviations and Notations ................................................................................................................. 6
2 Revision History ..................................................................................................................... 8
3 Use Cases and Requirements ............................................................................................... 9
4 Specification Amendments .................................................................................................. 11
4.1 Algorithm ............................................................................................................................................. 11
4.1.1 Advanced Encryption Standard (AES) ......................................................................................... 11
4.1.2 Encryption/Decryption .................................................................................................................. 11
4.1.3 MACing ......................................................................................................................................... 11
4.1.4 AES Padding ................................................................................................................................ 11
4.1.5 Data Derivation Scheme .............................................................................................................. 12
5 Secure Channel Protocol Usage ......................................................................................... 13
5.1 Secure Communication Configuration ................................................................................................ 13
5.2 Mutual Authentication .......................................................................................................................... 13
5.3 Message Integrity ................................................................................................................................ 14
5.4 Message Data Confidentiality ............................................................................................................. 14
5.5 API and Security Level ........................................................................................................................ 15
5.6 Protocol Rules ..................................................................................................................................... 16
6 Cryptographic Keys ............................................................................................................. 17
6.1 AES Keys ............................................................................................................................................ 17
6.2 Cryptographic Usage .......................................................................................................................... 18
6.2.1 AES Session Keys ....................................................................................................................... 18
6.2.2 Challenges and Authentication Cryptograms............................................................................... 18
6.2.3 Message Integrity Using Explicit Secure Channel Initiation .........................................................19
6.2.4 APDU Command C-MAC Generation and Verification ................................................................ 20
6.2.5 APDU Response R-MAC Generation and Verification ................................................................ 21
6.2.6 APDU Command C-MAC and C-DECRYPTION Generation and Verification ............................23
6.2.7 APDU Response R-MAC and R-ENCRYPTION Generation and Verification .............................24
6.2.8 Key Sensitive Data Encryption Decryption .................................................................................. 25
7 Commands ............................................................................................................................ 26
7.1 Secure Channel Commands ............................................................................................................... 27
7.1.1 INITIALIZE UPDATE Command .................................................................................................. 27
7.1.2 EXTERNAL AUTHENTICATE Command .................................................................................... 28
7.1.3 BEGIN R-MAC SESSION Command........................................................................................... 29
7.1.4 END R-MAC SESSION Command .............................................................................................. 31
7.2 PUT KEY Command (AES Key-DEK) ................................................................................................. 33
7.2.1 Data Field Sent in the Command Message ................................................................................. 33
7.2.2 Key Check Value for AES Key ..................................................................................................... 33
7.3 STORE DATA (AES Key-DEK) ........................................................................................................... 34
8 AES for Card Content Management .................................................................................... 35
8.1 DAPs for AES ...................................................................................................................................... 35
8.2 Tokens for AES ................................................................................................................................... 35
8.3 Receipts for AES ................................................................................................................................. 35
Figures
Figure 6-1: APDU C-MAC Generation ............................................................................................................. 20
Figure 6-2: APDU R-MAC Generation ............................................................................................................. 21
Figure 6-3: MAC Chaining ............................................................................................................................... 22
Figure 6-4: APDU Command Data Field Encryption ....................................................................................... 23
Figure 6-5: APDU Response Data Field Encryption ....................................................................................... 24
Figure 6-6: Sensitive Data Encryption ............................................................................................................. 25
Tables
Table 1-1: Normative References ...................................................................................................................... 5
Table 1-2: Abbreviations and Notations ............................................................................................................ 6
Table 2-1: Revision History ............................................................................................................................... 8
Table 4-1: Data Derivation Constants ............................................................................................................. 12
Table 5-1: Values of Parameter “i” .................................................................................................................. 13
Table 6-1: Security Domain Secure Channel Keys ......................................................................................... 17
Table 6-2: AES Key Derivation Elements ........................................................................................................ 18
Table 7-1: SCP03 Command Support ............................................................................................................. 26
Table 7-2: INITIALIZE UPDATE Response Message ..................................................................................... 27
Table 7-3: EXTERNAL AUTHENTICATE Reference Control Parameter P1 ..................................................28
Table 7-4: BEGIN R-MAC SESSION Command Message ............................................................................. 29
Table 7-5: BEGIN R-MAC SESSION Reference Control Parameter P1 .........................................................29
Table 7-6: BEGIN R-MAC SESSION Reference Control Parameter P2 .........................................................30
Table 7-7: END R-MAC SESSION Command Message................................................................................. 31
Table 7-8: END R-MAC SESSION Reference Control Parameter P2 ............................................................ 31
Table 7-9: Key Data Field (AES Key-DEC) – Basic ........................................................................................ 33
Table 7-10: AES Key Data Field – Basic ......................................................................................................... 33
Table 8-1: Hash Selection ............................................................................................................................... 35
1 Introduction
This document proposes a new secure channel protocol based on AES keys and specifies:
• A new mechanism to generate session keys.
• The schemes to be used with AES for C-MAC, R-MAC, command data field encryption and response
data field encryption.
• The format of PUT KEY for AES.
This new protocol is based on existing SCP01 and SCP02 protocols. It supports AES-based cryptography in
lieu of TDEA. The protocol protects bidirectional communication between the Host and the card
(decryption/MAC verification for incoming commands, encryption/MAC generation on card response).
In addition, the document defines the formats and requirements for DAPs, Tokens and Receipts if AES is
used for card content management activities.
1.2 References
Table 1-1: Normative References
Note: C-MAC is the abbreviation used in [GPCS] for the MAC appended to command APDUs. This is not to
be confused with CMAC, which is the abbreviation for a MAC calculation scheme specified in NIST SP
800-38B [NIST 800-38B].
2 Revision History
Table 2-1: Revision History
NIST has also published another standard called “Cryptographic Algorithms and Key Sizes for Personal
Identify Verification”. This document, also freely available on the NIST website under the reference NIST SP
800-78-1 [NIST 800-78-1], is a mandatory standard for the Personal Identity Verification (PIV) cards for all
US Federal employees and contractors. It is referred to by the more widely known [FIPS 201-1]. According to
st
this standard, the time period to use RSA 1024 for digital signature expires on the 31 of December, 2008,
st
and the 2TDEA Keys cannot be used for card authentication after the 31 of December 2010.
According to the above standards, an AES key is more suitable for a transport key as:
• An AES-128 key can be used to encrypt 3TDEA Keys, RSA up to 3072, AES-128 and ECC with
f up to 383.
• An AES-192 key can be used in addition to encrypt RSA up to 7680, AES-192 and ECC with
f=384-511.
• An AES-256 key can be used in addition to encrypt RSA up to 15360, AES-256 and ECC with f=512+.
This should ensure the permanence of a secure channel based on AES from a crypto analysis standpoint for
several years.
4 Specification Amendments
4.1 Algorithm
4.1.1 Advanced Encryption Standard (AES)
The Advanced Encryption Standard (AES) is a symmetric cryptographic algorithm that requires the use of
the same secret key to encrypt and decrypt data. In its simplest form it uses a 16-byte key to encrypt a
16-byte block of data and the same 16-byte key to decrypt and retrieve the original clear text.
Two other versions of AES exist that involve 24-byte key and 32-byte key respectively. In these versions, the
clear text and the cipher text are still 16-byte long. The different “flavors” may be referred to as “AES-128”,
“AES-192”, and “AES-256”.
A specification of AES with its different versions may be found in “Advanced Encryption Standard (AES)”
[FIPS 197].
This complies with FIPS PUB 140-2 ([FIPS 140-2]) Annex A (Symmetric Key Encryption – 1).
4.1.2 Encryption/Decryption
AES in CBC mode is used as specified in [NIST 800-38A]. The ICV to be used is defined in sections 6.2.6
and 6.2.7.
This complies with [FIPS 140-2] Annex A (Symmetric Key Encryption – 1).
4.1.3 MACing
CMAC as specified in [NIST 800-38B] is used for MAC calculations. Note that [NIST 800-38B] also specifies
the padding to be applied to the input.
This complies with [FIPS 140-2] Annex A (Message authentication – 3).
Unless specified otherwise, padding prior to performing an AES operation across a block of data is achieved
in the following manner:
• Append an '80' to the right of the data block;
• If the resultant data block length is a multiple of 16, no further padding is required;
• Append binary zeroes to the right of the data block until the data block length is a multiple of 16.
This padding complies with one of the padding schemes proposed in [NIST 800-38A].
The following data derivation scheme is used to generate keys, pseudo-random card challenges or
cryptograms:
Data derivation shall use KDF in counter mode as specified in NIST SP 800-108 [NIST 800-108]. The PRF
used in the KDF shall be CMAC as specified in [NIST 800-38B], used with full 16 byte output length.
The “fixed input data” plus iteration counter shall be the concatenation of the following items in the given
sequence (note that [NIST 800-108] allows the reordering of input data fields as long as the order, coding
and length of each field is unambiguously defined):
• A 12 byte “label” consisting of 11 bytes with value '00' followed by a one byte derivation constant as
defined below.
• A one byte “separation indicator” with value '00'.
• A 2 byte integer “L” specifying the length in bits of the derived data (value '0040', '0080', '00C0', or
'0100').
• A 1 byte counter “i” as specified in the KDF (which may take the values '01' or '02'; value '02' is used
when “L” takes the values '00C0' and '0100', i.e. when the PRF of the KDF is to be called twice to
generate enough derived data).
• The “context” parameter of the KDF. Its content is further specified in the sections below applying the
data derivation scheme.
Definition of the derivation constant:
b8 b7 b6 b5 b4 b3 b2 b1 Description
0 0 0 0 0 0 0 x authentication cryptogram generation
0 0 0 0 0 0 0 0 - card cryptogram
0 0 0 0 0 0 0 1 - host cryptogram
0 0 0 0 0 0 1 0 card challenge generation
0 0 0 0 0 1 x x key derivation
0 0 0 0 0 1 0 0 - derivation of S-ENC
0 0 0 0 0 1 1 0 - derivation of S-MAC
0 0 0 0 0 1 1 1 - derivation of S-RMAC
all other values RFU
b8 b7 b6 b5 b4 b3 b2 b1 Description
X X X X RFU (set to 0)
0 Random card challenge
1 Pseudo-random card challenge
0 0 No R-MAC/R-ENCRYPTION support
0 1 R-MAC support / no R-ENCRYPTION support
1 1 R-MAC and R-ENCRYPTION support
X Reserved
Note: “i” is a sub identifier within an object identifier, and bit b8 is reserved for use in the structure of the
object identifier according to ISO/IEC 8825-1 [ISO 8825-1].
6 Cryptographic Keys
6.1 AES Keys
Table 6-1: Security Domain Secure Channel Keys
Session Secure Channel Encryption Used for data confidentiality Key-ENC Dynamically
Key length
(S-ENC)
Secure Channel Message Used for data and protocol integrity Key-MAC Dynamically
Authentication Code Key for length
Command
(S-MAC)
Secure Channel Message User for data and protocol integrity Key-MAC Dynamically
Authentication Code Key for length and
Response Conditional
(S-RMAC)
A Security Domain supporting Secure Channel Protocol '03', including the Issuer Security Domain, shall
have at least one complete key set containing a Key-ENC, a Key-MAC, and a Key-DEK key having the same
length. When loaded to the card, these keys should be encrypted with a key of same or higher strength. The
card issuer may require that this recommendation be enforced depending on its security policy.
AES session keys shall be generated every time a Secure Channel is initiated and are used in the mutual
authentication process. These same session keys may be used for subsequent commands if the Current
Security Level indicates that secure messaging is required.
Session keys are generated to ensure that a different set of keys is used for each Secure Channel Session.
The session keys are derived from the static Secure Channel keys. The encryption key S-ENC is derived
from Key-ENC. The Secure Channel MAC key S-MAC is derived from Key-MAC. Optionally (if the “i”
parameter indicates R-MAC support), the Secure Channel R-MAC key S-RMAC is derived from Key-MAC.
No AES session keys are generated for key and sensitive data encryption operations. That allows pre-
processed data loading and simplifies the personalization process.
Key derivation shall use the data derivation scheme defined in section 4.1.5 with the following settings:
Derived Session Key Key KI used in PRF Derivation Constant (see Table 4-1)
S-ENC Key-ENC '04'
S-MAC Key-MAC '06'
S-RMAC Key-MAC '07'
The length of the session keys shall be reflected in the parameter “L” (i.e. '0080' for AES-128 keys, '00C0' for
AES-192 keys and '0100' for AES-256 keys).
The “context” parameter shall be set to the concatenation of the host challenge (8 bytes) and the card
challenge (8 bytes).
Both the card and the off-card entity (host) each generate a challenge and an authentication cryptogram.
The off-card entity verifies the card cryptogram and the card verifies the host cryptogram. The cryptogram
lengths shall be the same as the length of the challenges.
As indicated in the “i” parameter (see Table 5-1), the card challenge shall either be random or pseudo-
random.
If the SCP03 for a Security Domain is configured for pseudo-random challenge generation, the card
challenge shall be calculated as follows:
• For each SCP03 keyset, the Security Domain shall have one sequence counter of three bytes length.
Whenever a keyset is created or the whole keyset is replaced by a single PUT KEY or STORE DATA
command, the sequence counter shall be set to zero.
• Whenever a challenge generation is triggered by an INITIALIZE UPDATE command, the sequence
counter shall be incremented and the new value shall be used in the calculation described below.
When the maximum value is reached, the INITIALIZE UPDATE command shall be rejected with
“conditions of use not satisfied”.
• The card challenge (8 bytes) is calculated using the data derivation scheme defined in section 4.1.5
with the static key Key-ENC and the derivation constant set to “card challenge generation” (i.e. '02').
The length of the challenge shall be reflected in the parameter “L” (i.e. '0040'). The “context”
parameter shall be set to the concatenation of the sequence counter (3 bytes) and the AID of the
application invoking the SecureChannel interface (5 to 16 bytes).
The card cryptogram (8 bytes) is calculated using the data derivation scheme defined in section 4.1.5 with
the session key S-MAC and the derivation constant set to “card authentication cryptogram generation”. The
length of the cryptogram shall be reflected in the parameter “L” (i.e. '0040').
The “context” parameter shall be set to the concatenation of the host challenge (8 bytes) and the card
challenge (8 bytes).
The host cryptogram (8 bytes) is calculated using the data derivation scheme defined in section 4.1.5 with
the session key S-MAC and the derivation constant set to “host authentication cryptogram generation”. The
length of the cryptogram shall be reflected in the parameter “L” (i.e. '0040').
The “context” parameter shall be set to the concatenation of the host challenge (8 bytes) and the card
challenge (8 bytes).
For the EXTERNAL AUTHENTICATE command MAC verification, the “MAC chaining value” is set to 16
bytes '00'.
Once the cryptograms are successfully verified, the full 16 byte C-MAC of the previous command becomes
the “MAC chaining value” for the subsequent C-MAC verification / R-MAC generation.
A C-MAC is generated by an off-card entity: it uses the S-MAC key and is applied across the MAC chaining
value concatenated with the full APDU command being transmitted to the card including the header (5 bytes)
and the data field in the command message. (It does not include Le.)
Modification of the APDU command header and padding is required prior to the MAC operation being
performed.
The Secure channel shall support a MAC of 8 bytes length (even if the AES block length is 16 bytes). Hence
the 8 most significant bytes are considered.
The rules for APDU command header modification are as follows:
• The length of the command message (Lc) shall be incremented by 8 to indicate the inclusion of the
C-MAC in the data field of the command message.
• The class byte shall be modified for the generation or verification of the C-MAC: The logical channel
number shall be set to zero, bit 4 shall be set to 0 and bit 3 shall be set to 1 to indicate GlobalPlatform
proprietary secure messaging. If the Secure Channel Session is occurring on a Supplementary Logical
Channel, the class byte shall be modified after the C-MAC generation to indicate the logical channel
number. If logical channel number 4 to 19 is used, the GlobalPlatform proprietary secure messaging is
indicated by setting bit 6 to 1 – see [GPCS] Table 11-11 and Table 11-12. Conversely the logical
channel number card is discarded and, if required, the secure messaging indication is adjusted for the
verification. The logical channel number is not part of the integrity protection by the channel because
is it established independently and outside of the scope of the Secure Channel establishment.
MAC chaining value (16 bytes) '84' Ins P1 P2 Lc+ 8 Command Data field (length Lc)
CMAC calculation
S-MAC
(NIST SP 800-38B)
8 most 8 least
significant bytes significant bytes
C-MAC
No R-MAC shall be generated and no protection shall be applied to a response that includes an error status
word: in this case only the status word shall be returned in the response. All status words shall be interpreted
as error status words except '9000' and warning status words (i.e. '62xx' and '63xx').
The EXTERNAL AUTHENTICATE command/response doesn’t return R-MAC.
The R-MAC is made of the first 8 bytes of the CMAC computed on the message made of the MAC chaining
value, the response data field (if present) and the status bytes. The R-MAC calculation uses the S-RMAC
key.
The R-MAC calculation is illustrated in Figure 6-2.
CMAC calculation
S-RMAC
(NIST SP 800-38B)
8 most 8 least
significant bytes significant bytes
R-MAC
The off-card entity shall perform the same CMAC calculation on the response and use the same R-MAC
session key employed by the card in order to verify the R-MAC.
The computed R-MAC becomes part of the response message.
Figure 6-3 illustrates the combined MAC chaining for command and responses.
8 bytes
MAC Chaining Value 2
8 bytes
MAC Chaining Value 3
8 bytes
...
Commands
Command Data 1 C-MAC 1 Command Data 2 C-MAC 2 Command Data 3 C-MAC 3
Responses
SW SW SW
RDF 1 R-MAC 1 RDF 2 R-MAC 2 RDF 3 R-MAC 3
1 2 3
Via the MAC changing value, consecutive commands are chained to each other, protecting their sequence.
Responses are linked to the respective command via the MAC changing value. As R-MAC uses a different
session key than C-MAC, the same MAC chaining value can be used for the response and the next
command. The scheme is adapted to the features of SCP03, where
• R-MAC is optional, and
• R-MAC may be switched on and off during a secure channel session (see BEGIN/END R-MAC
SESSION commands).
This section applies when both command confidentiality (C-DECRYPTION) and integrity (C-MAC) are
required.
Depending on the security level defined in the initiation of the Secure Channel, all subsequent APDU
commands within the Secure Channel may require secure messaging and such as use of a C-MAC
(integrity) and encryption (confidentiality).
For each APDU command sent within the secure channel session, the Off-Card Entity shall increment an
encryption counter:
• The encryption counter’s start value shall be set to 1 for the first command following a successful
EXTERNAL AUTHENTICATE command.
• The encryption counter’s binary value shall be left padded with zeroes to form a full block.
• This block shall be encrypted with S-ENC to produce an ICV for command encryption. This scheme
fulfils the requirement described in [NIST 800-38A] for unpredictable ICVs when using CBC mode.
No encryption shall be applied to a command where there is no command data field. In this case, the
encryption counter shall still be incremented as described above, but the message shall be protected as
defined in section 6.2.4. Otherwise the Off-Card Entity performs the process detailed hereafter.
The Off-Card Entity first encrypts the Command Data field and then computes the C-MAC on the command
with the ciphered data field as described in section 6.2.4.
The command message encryption and decryption uses the Secure Channel encryption (S-ENC) session
key and the AES encryption in CBC Mode. Prior to encrypting the data, the data shall be padded as defined
in section 4.1.4. This padding becomes part of the data field.
The final Lc value (Lcc) is the sum of:
initial Lc + length of the padding + length of C-MAC
C-MAC calculation as
defined in section 6.2.4 S-MAC
This section applies when both response confidentiality (R-ENCRYPTION) and integrity (R-MAC) are
required.
Depending on the security level defined in the initiation of the Secure Channel, all subsequent APDU
responses within the Secure Channel may require secure messaging and such as use of an R-MAC
(integrity) and encryption (confidentiality).
No encryption shall be applied to a response where there is no response data field: in this case the message
shall be protected as defined in section 6.2.5. Otherwise the Card performs the process detailed hereafter.
The Card first encrypts the Response Data field and then computes the R-MAC on the response with the
ciphered data field as described in section 6.2.5.
The response message encryption and decryption uses the Secure Channel encryption (S-ENC) session key
and the AES encryption in CBC Mode. Prior to encrypting the data, the data shall be padded as defined in
section 4.1.4. This padding becomes part of the data field.
The ICV shall be calculated as follows:
• The padded counter block used for the generation of the ICV for command encryption shall also be
used to generate the ICV for response encryption, however, with the following additional intermediate
step: Before encryption, the most significant byte of this block shall be set to '80'.
• This block shall be encrypted with S-ENC to produce an ICV for response encryption. This scheme
fulfils the requirements described in [NIST 800-38A] for unpredictable ICVs when using CBC mode.
The modification in the most significant byte guarantees that the ICVs for R-ENCRYPTION are
different from those used for C-DECRYPTION.
The final response APDU shall be the concatenation of the ciphered data, the R-MAC and the Status Word.
R-MAC calculation as
S-RMAC
defined in section 6.2.5
Status
Ciphered Response Data Field R-MAC
Word
Key data encryption is used when transmitting key sensitive data to the card and is over and beyond the
security level required for the Secure Channel. For instance all AES keys transmitted to a card should be
encrypted.
The Data encryption process uses the static data encryption key (Key-DEK) and the encryption method as
described in section 4.1.2.
If the sensitive data to be encrypted are AES keys (16 or 32 byte long), for instance for a Put Key command,
then no padding is required for the data field prior to encryption as data block are multiple of 16 byte long.
For the 24-byte AES keys, padding of 8 arbitrary bytes shall be appended prior to encryption. For the
encryption of other keys see section 7.2. For other sensitive data, padding is application specific and is out of
the scope of this document.
The AES CBC encryption with ICV set to zero is performed across the key sensitive data and the result of
each encryption becomes part of the encrypted key data. This encrypted key data becomes part of the “clear
text” data field in the command message.
The on-card decryption of key data is the exact opposite of the above operation.
7 Commands
The following table presents the commands involved in Secure Channel Initiation and R-MAC Session
Management.
See [GPCS] section D.4.1 for the structure of the INITIALIZE UPDATE command.
If any of the mandatory keys listed in section 6.1 is missing in the targeted key set version, the INITIALIZE
UPDATE command shall fail with error condition “Referenced data not found” as defined in [GPCS].
The data field of the response message shall contain the concatenation without delimiters of the following
data elements:
The key diversification data is data typically used by a backend system to derive the card static keys.
The key information includes the Key Version Number, the Secure Channel Protocol identifier, here '03', and
the Secure Channel Protocol “i” parameter used in initiating the Secure Channel Session.
The card challenge is an internally generated random or pseudo random number.
The card cryptogram is an authentication cryptogram.
Sequence Counter is only present when SCP03 is configured for pseudo-random challenge generation.
Except for the Reference control parameter P1 the GlobalPlatform External Authenticate is compliant with
[GPCS] section D.4.2 for the structure of the EXTERNAL AUTHENTICATE command.
The reference control parameter P1 defines the level of security for all secure messaging commands
following this EXTERNAL AUTHENTICATE command and within the Secure Channel Session.
b8 b7 b6 b5 b4 b3 b2 b1 Description
0 0 1 1 0 0 1 1 C-DECRYPTION, R-ENCRYPTION, C-MAC, and R-MAC
The BEGIN R-MAC SESSION command is used to initiate additional response security. The BEGIN R-MAC
SESSION command may only be issued to the card within a secure channel. It may only be used to increase
the security of the responses and only if command messages use at least the same security level.
The BEGIN R-MAC SESSION command message is coded according to the following table:
The reference control parameter P1 defines the level of security for all subsequent APDU response
messages following this BEGIN R-MAC SESSION command (it does not apply to this command).
b8 b7 b6 b5 b4 b3 b2 b1 Description
0 0 1 1 0 0 0 0 R-ENCRYPTION and R-MAC
0 0 0 1 0 0 0 0 R-MAC
When P1 is set to '10' each APDU response message during the R-MAC session includes an R-MAC. This
setting may only be used if the secure channel session does not use R-MAC.
When P1 is set to '30' each APDU response message during the R-MAC session uses R-MAC and
R-ENCRYPTION. This setting may only be used if the secure channel session does not use
R-ENCRYPTION.
The reference control parameter P2 defines the beginning of the session for APDU response message
integrity.
b8 b7 b6 b5 b4 b3 b2 b1 Description
0 0 0 0 0 0 0 1 Begin R-MAC session
The data field of the BEGIN R-MAC SESSION contains an LV coded ‘data’ element and optionally a C-MAC.
The card does not interpret the ‘data’. However since it is included in R-MAC calculation, this gives the off-
card entity the possibility to include a challenge in the R-MAC.
If R-MAC was specified in the previous EXTERNAL AUTHENTICATE command, then the response to the
BEGIN R-MAC Session shall contain an R-MAC. Otherwise, the data field of the response message is not
present.
A successful execution of the command shall be indicated by status bytes '90' '00'.
The card will respond with a '6985' status word without aborting the secure channel in the following cases:
• If R-ENCRYPTION was specified in the previous EXTERNAL AUTHENTICATE command;
• If P1 is set to '10' and R-MAC was specified in the previous EXTERNAL AUTHENTICATE command;
• If C-MAC was not specified in the previous EXTERNAL AUTHENTICATE command;
• If P1 is set to '30' and C-DECRYPTION was not specified in the previous EXTERNAL
AUTHENTICATE command.
This command may return a general error condition as listed in [GPCS] section 11.1.3, General Error
Conditions.
The END R-MAC SESSION command is used to terminate the additional response security that was initiated
by the preceding BEGIN R-MAC SESSION. The Secure Channel session returns to its original security
settings. The END R-MAC SESSION command may be issued to the card at any time during an R-MAC
session. If this command contains a wrong C-MAC, the entire Secure Channel session shall be aborted. In
all other cases, if this command returns an error status word, the R-MAC session shall not be ended. The
R-MAC session shall be ended if the secure channel is closed or the card is reset.
The END R-MAC SESSION command message is coded according to the following table:
b8 b7 b6 b5 b4 b3 b2 b1 Description
0 0 0 0 0 0 1 1 End R-MAC session & return R-MAC
The data field of the command message may optionally contain a C-MAC.
The data field of the response message contains the R-MAC of the current R-MAC session.
A successful execution of the command shall be indicated by status bytes '90' '00'.
This command may return a general error condition as listed in [GPCS] section 11.1.3. General Error
Conditions.
The general key data field for keys or key components encrypted by an AES Key-DEK takes is specified in
Table 7-9, which provides a precision to [GPCS] Table 11-68.
If the length of the key or key component is not an integer multiple of the block length of 16 bytes, padding of
arbitrary bytes shall be appended prior to encryption to fill the last block. Ciphering shall be done as specified
in section 6.2.8.
If an AES key is encrypted by an AES Key-DEK, the key data field takes the format according to Table 7-10.
The same precisions to the key or key component data shall apply for the extended key data field.
The key check value is calculated and checked by AES encrypting one block of 16 bytes with value '01' and
taking the three highest order bytes.
If a Load File Data Block Signature (DAP) is generated with an AES key, CMAC as defined in section 4.1.3
shall be used in the Signature Calculation operation specified in [GPCS] section C.3. The length of the
signature shall be 16 bytes.