globalplatform
security.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005-2026, Karsten Ohme
3  * This file is part of GlobalPlatform.
4  *
5  * GlobalPlatform is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * GlobalPlatform is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with GlobalPlatform. If not, see <https://www.gnu.org/licenses/>.
17  *
18  * In addition, as a special exception, the copyright holders give
19  * permission to link the code of portions of this program with the
20  * OpenSSL library under certain conditions as described in each
21  * individual source file, and distribute linked combinations
22  * including the two.
23  * You must obey the GNU Lesser General Public License in all respects
24  * for all of the code used other than OpenSSL. If you modify
25  * file(s) with this exception, you may extend this exception to your
26  * version of the file(s), but you are not obligated to do so. If you
27  * do not wish to do so, delete this exception statement from your
28  * version.
29  */
30 
35 #ifndef SECURITY_H_
36 #define SECURITY_H_
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #include "types.h"
44 
45 #define OP_201 201
46 #define GP_211 211
47 
48 /* Secure Channel stuff */
49 
50 #define GP211_SCP01 0x01
51 #define GP211_SCP02 0x02
52 #define GP211_SCP03 0x03
53 #define GP211_SCP11 0x11
54 
58 #define GP211_SCP01_IMPL_i05 0x05
62 #define GP211_SCP01_IMPL_i15 0x15
63 
68 #define GP211_SCP02_IMPL_i44 0x44
74 #define GP211_SCP02_IMPL_i45 0x45
79 #define GP211_SCP02_IMPL_i54 0x54
84 #define GP211_SCP02_IMPL_i55 0x55
88 #define GP211_SCP02_IMPL_i04 0x04
92 #define GP211_SCP02_IMPL_i05 0x05
96 #define GP211_SCP02_IMPL_i0A 0x0A
100 #define GP211_SCP02_IMPL_i0B 0x0B
105 #define GP211_SCP02_IMPL_i14 0x14
110 #define GP211_SCP02_IMPL_i15 0x15
114 #define GP211_SCP02_IMPL_i1A 0x1A
118 #define GP211_SCP02_IMPL_i1B 0x1B
119 
122 #define GP211_SCP03_IMPL_i00 0x00
126 #define GP211_SCP03_IMPL_i10 0x10
127 
131 #define GP211_SCP03_IMPL_i30 0x30
132 
136 #define GP211_SCP03_IMPL_i20 0x20
137 
141 #define GP211_SCP03_IMPL_i60 0x60
142 
146 #define GP211_SCP03_IMPL_i70 0x70
147 
148 #define GP211_SCP01_SECURITY_LEVEL_C_DEC_C_MAC 0x03
149 #define GP211_SCP01_SECURITY_LEVEL_C_MAC 0x01
150 #define GP211_SCP01_SECURITY_LEVEL_NO_SECURE_MESSAGING 0x00
151 
152 #define GP211_SCP02_SECURITY_LEVEL_C_DEC_C_MAC_R_MAC 0x13
153 #define GP211_SCP02_SECURITY_LEVEL_C_MAC_R_MAC 0x11
154 #define GP211_SCP02_SECURITY_LEVEL_R_MAC 0x10
155 #define GP211_SCP02_SECURITY_LEVEL_C_DEC_C_MAC 0x03
156 #define GP211_SCP02_SECURITY_LEVEL_C_MAC 0x01
157 #define GP211_SCP02_SECURITY_LEVEL_NO_SECURE_MESSAGING 0x00
158 
159 // Philip Wendland: added SCP03 security level identifiers
160 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_C_MAC 0x03
161 #define GP211_SCP03_SECURITY_LEVEL_C_MAC 0x01
162 #define GP211_SCP03_SECURITY_LEVEL_NO_SECURE_MESSAGING 0x00
163 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_R_ENC_C_MAC_R_MAC 0x33
164 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_C_MAC_R_MAC 0x13
165 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_C_MAC_R_ENC_R_MAC 0x33
166 #define GP211_SCP03_SECURITY_LEVEL_C_MAC_R_MAC 0x11
167 #define GP211_SCP03_SECURITY_LEVEL_R_MAC 0x10
168 #define GP211_SCP03_SECURITY_LEVEL_R_ENC_R_MAC 0x30
169 
170 #define GP211_SCP11_KEY_USAGE_QUALIFIER_C_MAC_R_MAC 0x34
171 #define GP211_SCP11_KEY_USAGE_QUALIFIER_C_DEC_R_ENC_C_MAC_R_MAC 0x3C
172 
173 #define GP211_KEY_TYPE_RSA 0xF0
174 #define GP211_KEY_TYPE_ECC 0xF1
175 #define GP211_KEY_TYPE_RSA_PUB_E 0xA0
176 #define GP211_KEY_TYPE_RSA_PUB_N 0xA1
177 #define GP211_KEY_TYPE_RSA_PRIV_ENC_N 0xA2
178 #define GP211_KEY_TYPE_RSA_PRIV_D 0xA3
179 #define GP211_KEY_TYPE_RSA_PRIV_P 0xA4
180 #define GP211_KEY_TYPE_RSA_PRIV_Q 0xA5
181 #define GP211_KEY_TYPE_RSA_PRIV_PQ 0xA6
182 #define GP211_KEY_TYPE_RSA_PRIV_DP1 0xA7
183 #define GP211_KEY_TYPE_RSA_PRIV_DQ1 0xA8
184 #define GP211_KEY_TYPE_ECC_PUBLIC_OR_PRIVATE 0xB0
185 #define GP211_KEY_TYPE_ECC_PRIVATE 0xB1
186 #define GP211_KEY_TYPE_ECC_FIELD_PARAMETER_P 0xB2
187 #define GP211_KEY_TYPE_ECC_FIELD_PARAMETER_A 0xB3
188 #define GP211_KEY_TYPE_ECC_FIELD_PARAMETER_B 0xB4
189 #define GP211_KEY_TYPE_ECC_FIELD_PARAMETER_G 0xB5
190 #define GP211_KEY_TYPE_ECC_FIELD_PARAMETER_N 0xB6
191 #define GP211_KEY_TYPE_ECC_SM2_PUBLIC_OR_PRIVATE 0xB7
192 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE 0xF0
193 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_P256 0x00
194 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_P384 0x01
195 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_P521 0x02
196 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_BRAINPOOLP256R1 0x03
197 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_BRAINPOOLP256T1 0x04
198 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_BRAINPOOLP384R1 0x05
199 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_BRAINPOOLP384T1 0x06
200 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_BRAINPOOLP512R1 0x07
201 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_BRAINPOOLP512T1 0x08
202 #define GP211_KEY_TYPE_ECC_KEY_PARAMETER_REFERENCE_SM2P256V1 0x09
203 
204 
205 #define GP211_KEY_TYPE_3DES 0x81
206 #define GP211_KEY_TYPE_DES 0x80
207 #define GP211_KEY_TYPE_3DES_CBC 0x82
208 #define GP211_KEY_TYPE_DES_ECB 0x83
209 #define GP211_KEY_TYPE_DES_CBC 0x84
210 #define GP211_KEY_TYPE_PSK_TLS 0x85
211 #define GP211_KEY_TYPE_AES 0x88
212 #define GP211_KEY_TYPE_SM4 0x89
213 
214 #define OP201_SECURITY_LEVEL_ENC_MAC 0x03
215 #define OP201_SECURITY_LEVEL_MAC 0x01
216 #define OP201_SECURITY_LEVEL_PLAIN 0x00
217 
218 #define OP201_KEY_TYPE_RSA 0xF0
219 #define OP201_KEY_TYPE_RSA_PUP_N 0xA1
220 #define OP201_KEY_TYPE_RSA_PUP_E 0xA0
221 #define OP201_KEY_TYPE_DES 0x80
222 #define OP201_KEY_TYPE_DES_ECB 0x81
223 #define OP201_KEY_TYPE_DES_CBC 0x82
224 
228 typedef struct {
230  BYTE sessionMacKey[16];
231  BYTE sessionEncKey[16];
232  BYTE lastMac[8];
233  /* Augusto: added two more attributes for key information */
236  /* end */
238 
239 
243 typedef struct {
247  BYTE C_MACSessionKey[32];
248  BYTE R_MACSessionKey[32];
249  BYTE encryptionSessionKey[32];
250  BYTE dataEncryptionSessionKey[32];
251  /*
252  * Philip Wendland: lastC_MAC must be 16 Bytes for SCP03 because the MAC chaining value
253  * for MAC code generation is 16 Bytes (according to GP 2.2 Amendment D), not 8.
254  */
255  BYTE lastC_MAC[16];
256  BYTE lastR_MAC[8];
257  /* Augusto: added two more attributes for key information */
260  BYTE invokingAid[16];
265 
271 typedef struct {
273  BYTE securityDomainAID[16];
275  BYTE signature[128];
277 
278 
279 
283 typedef struct {
285  BYTE receipt[8];
287  BYTE confirmationCounter[2];
289  BYTE cardUniqueData[10];
291 
292 
293 
294 
298 typedef struct {
302 
306 typedef struct {
309  OP201_KEY_COMPONENT keyComponents[8];
312 
317 typedef struct {
319  BYTE securityDomainAID[16];
321  BYTE signature[512];
323 
324 
326 #define GP211_RECEIPT_MAX_LENGTH 512
328 #define GP211_RECEIPT_SD_UNIQUE_DATA_MAX_LENGTH 255
330 #define GP211_RECEIPT_TOKEN_IDENTIFIER_MAX_LENGTH 255
332 #define GP211_RECEIPT_TOKEN_DATA_DIGEST_MAX_LENGTH 255
333 
337 typedef struct {
341  BYTE confirmationCounter[2];
351 
352 
356 typedef struct {
358  USHORT keyLength;
359  USHORT keyUsage;
361  BOOL extended;
363 
364 
368 typedef struct {
371  GP211_KEY_COMPONENT keyComponents[8];
374 
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 #endif /* SECURITY_H_ */
#define GP211_RECEIPT_MAX_LENGTH
Maximum receipt length.
Definition: security.h:326
#define GP211_RECEIPT_TOKEN_IDENTIFIER_MAX_LENGTH
Maximum token identifier length in confirmation data.
Definition: security.h:330
#define GP211_RECEIPT_TOKEN_DATA_DIGEST_MAX_LENGTH
Maximum token data digest length in confirmation data.
Definition: security.h:332
#define GP211_RECEIPT_SD_UNIQUE_DATA_MAX_LENGTH
Maximum SD unique data length in confirmation data.
Definition: security.h:328
Definition: security.h:317
DWORD signatureLength
The length of the signature. Can be 8 for a 3DES signature or <= 512 for a RSA signature.
Definition: security.h:320
BYTE securityDomainAIDLength
The length of the Security Domain.
Definition: security.h:318
Definition: security.h:356
USHORT keyLength
The key length.
Definition: security.h:358
BYTE keyAccess
Key access used in extended format.
Definition: security.h:360
BYTE keyType
The key type.
Definition: security.h:357
USHORT keyUsage
Key usage used in extended format.
Definition: security.h:359
BOOL extended
Extended key information is returned.
Definition: security.h:361
Definition: security.h:368
BYTE keySetVersion
The key set version.
Definition: security.h:369
BYTE keyIndex
The key index.
Definition: security.h:370
BYTE numKeyComponents
The number of key components.
Definition: security.h:372
Definition: security.h:337
BYTE receiptLength
The length of the receipt DAP.
Definition: security.h:338
BOOL tokenDataDigestPresent
Whether the optional token data digest length/value field is present.
Definition: security.h:347
BOOL tokenIdentifierPresent
Whether the optional token identifier length/value field is present.
Definition: security.h:344
BYTE confirmationCounterLength
Length of the confirmation counter buffer.
Definition: security.h:340
BYTE tokenDataDigestLength
The length of the token data digest buffer.
Definition: security.h:348
BYTE cardUniqueDataLength
The length of SD unique data in the confirmation data.
Definition: security.h:342
BYTE tokenIdentifierLength
The length of the token identifier buffer.
Definition: security.h:345
Definition: security.h:243
LONG sessionEncryptionCounter
Session counter for SCP03 ICV encryption.
Definition: security.h:262
BYTE securityLevel
The security level.
Definition: security.h:244
BYTE secureChannelProtocolImpl
The Secure Channel Protocol implementation.
Definition: security.h:246
BYTE keySetVersion
The keyset version used in secure channel.
Definition: security.h:258
BYTE keyIndex
The key index used in secured channel.
Definition: security.h:259
BYTE secureChannelProtocol
The Secure Channel Protocol.
Definition: security.h:245
DWORD invokingAidLength
The length of the invoking AID buffer.
Definition: security.h:261
DWORD keyLength
The key length. 16,24 or 32 bytes.
Definition: security.h:263
Definition: security.h:271
BYTE signatureLength
The length of the signature. Can be 8 for a 3DES signature or 128 for a RSA signature.
Definition: security.h:274
BYTE securityDomainAIDLength
The length of the Security Domain.
Definition: security.h:272
Definition: security.h:298
BYTE keyType
The key type.
Definition: security.h:299
BYTE keyLength
The key length.
Definition: security.h:300
Definition: security.h:306
BYTE numKeyComponents
The number of key components.
Definition: security.h:310
BYTE keyIndex
The key index.
Definition: security.h:308
BYTE keySetVersion
The key set version.
Definition: security.h:307
Definition: security.h:283
BYTE receiptLength
The length of the receipt DAP.
Definition: security.h:284
BYTE cardUniqueDataLength
The length of the card unique data buffer.
Definition: security.h:288
BYTE confirmationCounterLength
Length of the confirmation counter buffer.
Definition: security.h:286
Definition: security.h:228
BYTE securityLevel
The security level.
Definition: security.h:229
BYTE keyIndex
The key index used in the secure channel.
Definition: security.h:235
BYTE keySetVersion
The keyset version used in the secure channel.
Definition: security.h:234
long LONG
A long value.
Definition: types.h:69
unsigned char BYTE
A Microsoft/Muscle BYTE definition.
Definition: types.h:67
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:68