globalplatform
security.h
Go to the documentation of this file.
1 /* Copyright (c) 2009, Karsten Ohme
2  * This file is part of GlobalPlatform.
3  *
4  * GlobalPlatform is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * GlobalPlatform is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with GlobalPlatform. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
22 #ifndef SECURITY_H_
23 #define SECURITY_H_
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
30 #include "types.h"
31 
32 #define OP_201 201
33 #define GP_211 211
34 
35 /* Secure Channel stuff */
36 
37 #define GP211_SCP01 0x01
38 #define GP211_SCP02 0x02
39 #define GP211_SCP03 0x03
40 
44 #define GP211_SCP01_IMPL_i05 0x05
48 #define GP211_SCP01_IMPL_i15 0x15
49 
54 #define GP211_SCP02_IMPL_i44 0x44
60 #define GP211_SCP02_IMPL_i45 0x45
65 #define GP211_SCP02_IMPL_i54 0x54
70 #define GP211_SCP02_IMPL_i55 0x55
74 #define GP211_SCP02_IMPL_i04 0x04
78 #define GP211_SCP02_IMPL_i05 0x05
82 #define GP211_SCP02_IMPL_i0A 0x0A
86 #define GP211_SCP02_IMPL_i0B 0x0B
91 #define GP211_SCP02_IMPL_i14 0x14
96 #define GP211_SCP02_IMPL_i15 0x15
100 #define GP211_SCP02_IMPL_i1A 0x1A
104 #define GP211_SCP02_IMPL_i1B 0x1B
105 
108 #define GP211_SCP03_IMPL_i00 0x00
112 #define GP211_SCP03_IMPL_i10 0x10
113 
117 #define GP211_SCP03_IMPL_i30 0x30
118 
122 #define GP211_SCP03_IMPL_i20 0x20
123 
127 #define GP211_SCP03_IMPL_i60 0x60
128 
132 #define GP211_SCP03_IMPL_i70 0x70
133 
134 #define GP211_SCP01_SECURITY_LEVEL_C_DEC_C_MAC 0x03
135 #define GP211_SCP01_SECURITY_LEVEL_C_MAC 0x01
136 #define GP211_SCP01_SECURITY_LEVEL_NO_SECURE_MESSAGING 0x00
137 
138 #define GP211_SCP02_SECURITY_LEVEL_C_DEC_C_MAC_R_MAC 0x13
139 #define GP211_SCP02_SECURITY_LEVEL_C_MAC_R_MAC 0x11
140 #define GP211_SCP02_SECURITY_LEVEL_R_MAC 0x10
141 #define GP211_SCP02_SECURITY_LEVEL_C_DEC_C_MAC 0x03
142 #define GP211_SCP02_SECURITY_LEVEL_C_MAC 0x01
143 #define GP211_SCP02_SECURITY_LEVEL_NO_SECURE_MESSAGING 0x00
144 
145 // Philip Wendland: added SCP03 security level identifiers
146 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_C_MAC 0x03
147 #define GP211_SCP03_SECURITY_LEVEL_C_MAC 0x01
148 #define GP211_SCP03_SECURITY_LEVEL_NO_SECURE_MESSAGING 0x00
149 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_R_ENC_C_MAC_R_MAC 0x33
150 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_C_MAC_R_MAC 0x13
151 #define GP211_SCP03_SECURITY_LEVEL_C_DEC_C_MAC_R_ENC_R_MAC 0x33
152 #define GP211_SCP03_SECURITY_LEVEL_C_MAC_R_MAC 0x11
153 #define GP211_SCP03_SECURITY_LEVEL_R_MAC 0x10
154 #define GP211_SCP03_SECURITY_LEVEL_R_ENC_R_MAC 0x30
155 
156 #define GP211_KEY_TYPE_RSA_PUB_N 0xA1
157 #define GP211_KEY_TYPE_RSA_PUB_E 0xA0
158 #define GP211_KEY_TYPE_RSA_PRIV_N 0xA2
159 #define GP211_KEY_TYPE_RSA_PRIV_D 0xA3
160 #define GP211_KEY_TYPE_RSA_PRIV_P 0xA4
161 #define GP211_KEY_TYPE_RSA_PRIV_Q 0xA5
162 #define GP211_KEY_TYPE_RSA_PRIV_PQ 0xA6
163 #define GP211_KEY_TYPE_RSA_PRIV_DP1 0xA7
164 #define GP211_KEY_TYPE_RSA_PRIV_DQ1 0xA8
165 
166 
167 #define GP211_KEY_TYPE_3DES 0x81
168 #define GP211_KEY_TYPE_DES 0x80
169 #define GP211_KEY_TYPE_3DES_CBC 0x82
170 #define GP211_KEY_TYPE_DES_ECB 0x83
171 #define GP211_KEY_TYPE_DES_CBC 0x84
172 #define GP211_KEY_TYPE_PSK_TLS 0x85
173 #define GP211_KEY_TYPE_AES 0x88
174 
175 #define OP201_SECURITY_LEVEL_ENC_MAC 0x03
176 #define OP201_SECURITY_LEVEL_MAC 0x01
177 #define OP201_SECURITY_LEVEL_PLAIN 0x00
178 
179 #define OP201_KEY_TYPE_RSA_PUP_N 0xA1
180 #define OP201_KEY_TYPE_RSA_PUP_E 0xA0
181 #define OP201_KEY_TYPE_DES 0x80
182 #define OP201_KEY_TYPE_DES_ECB 0x81
183 #define OP201_KEY_TYPE_DES_CBC 0x82
184 
188 typedef struct {
190  BYTE sessionMacKey[16];
191  BYTE sessionEncKey[16];
192  BYTE lastMac[8];
193  /* Augusto: added two more attributes for key information */
196  /* end */
198 
199 
203 typedef struct {
207  BYTE C_MACSessionKey[32];
208  BYTE R_MACSessionKey[32];
209  BYTE encryptionSessionKey[32];
210  BYTE dataEncryptionSessionKey[32];
211  /*
212  * Philip Wendland: lastC_MAC must be 16 Bytes for SCP03 because the MAC chaining value
213  * for MAC code generation is 16 Bytes (according to GP 2.2 Amendment D), not 8.
214  */
215  BYTE lastC_MAC[16];
216  BYTE lastR_MAC[8];
217  /* Augusto: added two more attributes for key information */
220  BYTE invokingAid[16];
225 
231 typedef struct {
233  BYTE securityDomainAID[16];
235  BYTE signature[128];
237 
238 
239 
243 typedef struct {
245  BYTE receipt[8];
247  BYTE confirmationCounter[2];
249  BYTE cardUniqueData[10];
251 
252 
253 
254 
258 typedef struct {
264 
269 typedef struct {
271  BYTE securityDomainAID[16];
273  BYTE signature[128];
275 
276 
280 typedef struct {
282  BYTE receipt[8];
284  BYTE confirmationCounter[2];
286  BYTE cardUniqueData[10];
288 
289 
293 typedef struct {
297  USHORT keyLength;
301 
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif /* SECURITY_H_ */
Definition: security.h:269
BYTE signatureLength
The length of the signature. Can be 8 for a 3DES signature or 128 for a RSA signature.
Definition: security.h:272
BYTE securityDomainAIDLength
The length of the Security Domain.
Definition: security.h:270
Definition: security.h:293
BYTE keySetVersion
The key set version.
Definition: security.h:294
BYTE keyType
The key type.
Definition: security.h:296
BYTE keyIndex
The key index.
Definition: security.h:295
BYTE keyUsage
Key usage used in extended format.
Definition: security.h:298
USHORT keyLength
The key length.
Definition: security.h:297
BYTE keyAccess
Key access used in extended format.
Definition: security.h:299
Definition: security.h:280
BYTE receiptLength
The length of the receipt DAP.
Definition: security.h:281
BYTE confirmationCounterLength
Length of the confirmation counter buffer.
Definition: security.h:283
BYTE cardUniqueDataLength
The length of the card unique data buffer.
Definition: security.h:285
Definition: security.h:203
LONG sessionEncryptionCounter
Session counter for SCP03 ICV encryption.
Definition: security.h:222
BYTE securityLevel
The security level.
Definition: security.h:204
BYTE secureChannelProtocolImpl
The Secure Channel Protocol implementation.
Definition: security.h:206
BYTE keySetVersion
The keyset version used in secure channel.
Definition: security.h:218
BYTE keyIndex
The key index used in secured channel.
Definition: security.h:219
BYTE secureChannelProtocol
The Secure Channel Protocol.
Definition: security.h:205
DWORD invokingAidLength
The length of the invoking AID buffer.
Definition: security.h:221
DWORD keyLength
The key length. 16,24 or 32 bytes.
Definition: security.h:223
Definition: security.h:231
BYTE signatureLength
The length of the signature. Can be 8 for a 3DES signature or 128 for a RSA signature.
Definition: security.h:234
BYTE securityDomainAIDLength
The length of the Security Domain.
Definition: security.h:232
Definition: security.h:258
BYTE keyType
The key type.
Definition: security.h:261
BYTE keyIndex
The key index.
Definition: security.h:260
BYTE keySetVersion
The key set version.
Definition: security.h:259
BYTE keyLength
The key length.
Definition: security.h:262
Definition: security.h:243
BYTE receiptLength
The length of the receipt DAP.
Definition: security.h:244
BYTE cardUniqueDataLength
The length of the card unique data buffer.
Definition: security.h:248
BYTE confirmationCounterLength
Length of the confirmation counter buffer.
Definition: security.h:246
Definition: security.h:188
BYTE securityLevel
The security level.
Definition: security.h:189
BYTE keyIndex
The key index used in the secure channel.
Definition: security.h:195
BYTE keySetVersion
The keyset version used in the secure channel.
Definition: security.h:194
long LONG
A long value.
Definition: types.h:53
unsigned char BYTE
A Microsoft/Muscle BYTE definition.
Definition: types.h:51
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:52