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 
41 
44 #define GP211_SCP01_IMPL_i05 0x05
45 
48 #define GP211_SCP01_IMPL_i15 0x15
49 
54 #define GP211_SCP02_IMPL_i44 0x44
55 
60 #define GP211_SCP02_IMPL_i45 0x45
61 
65 #define GP211_SCP02_IMPL_i54 0x54
66 
70 #define GP211_SCP02_IMPL_i55 0x55
71 
74 #define GP211_SCP02_IMPL_i04 0x04
75 
78 #define GP211_SCP02_IMPL_i05 0x05
79 
82 #define GP211_SCP02_IMPL_i0A 0x0A
83 
86 #define GP211_SCP02_IMPL_i0B 0x0B
87 
91 #define GP211_SCP02_IMPL_i14 0x14
92 
96 #define GP211_SCP02_IMPL_i15 0x15
97 
100 #define GP211_SCP02_IMPL_i1A 0x1A
101 
104 #define GP211_SCP02_IMPL_i1B 0x1B
105 
108 #define GP211_SCP03_IMPL_i00 0x00
109 
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 
185 
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[16];
208  BYTE R_MACSessionKey[16];
209  BYTE encryptionSessionKey[16];
210  BYTE dataEncryptionSessionKey[16];
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  * TODO This probably affects R_MAC too.
215  */
216  BYTE lastC_MAC[16];
217  BYTE lastR_MAC[8];
218  /* Augusto: added two more attributes for key information */
221  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_ */
GP211_KEY_INFORMATION::keySetVersion
BYTE keySetVersion
The key set version.
Definition: security.h:294
OP201_RECEIPT_DATA::confirmationCounterLength
BYTE confirmationCounterLength
Length of the confirmation counter buffer.
Definition: security.h:246
GP211_SECURITY_INFO::keySetVersion
BYTE keySetVersion
The keyset version used in secure channel.
Definition: security.h:219
GP211_SECURITY_INFO::keyIndex
BYTE keyIndex
The key index used in secured channel.
Definition: security.h:220
types.h
GP211_KEY_INFORMATION::keyUsage
BYTE keyUsage
Key usage used in extended format.
Definition: security.h:298
GP211_SECURITY_INFO::sessionEncryptionCounter
LONG sessionEncryptionCounter
Session counter for SCP03 ICV encryption.
Definition: security.h:223
BYTE
unsigned char BYTE
A Microsoft/Muscle BYTE definition.
Definition: types.h:51
LONG
long LONG
A long value.
Definition: types.h:53
GP211_SECURITY_INFO
Definition: security.h:203
GP211_KEY_INFORMATION::keyIndex
BYTE keyIndex
The key index.
Definition: security.h:295
OP201_SECURITY_INFO::keySetVersion
BYTE keySetVersion
The keyset version used in the secure channel.
Definition: security.h:194
OP201_RECEIPT_DATA::cardUniqueDataLength
BYTE cardUniqueDataLength
The length of the card unique data buffer.
Definition: security.h:248
OP201_DAP_BLOCK
Definition: security.h:231
GP211_DAP_BLOCK::signatureLength
BYTE signatureLength
The length of the signature. Can be 8 for a 3DES signature or 128 for a RSA signature.
Definition: security.h:272
OP201_DAP_BLOCK::securityDomainAIDLength
BYTE securityDomainAIDLength
The length of the Security Domain.
Definition: security.h:232
OP201_SECURITY_INFO::keyIndex
BYTE keyIndex
The key index used in the secure channel.
Definition: security.h:195
DWORD
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:52
GP211_SECURITY_INFO::invokingAidLength
DWORD invokingAidLength
The length of the invoking AID buffer.
Definition: security.h:222
OP201_SECURITY_INFO::securityLevel
BYTE securityLevel
The security level.
Definition: security.h:189
GP211_SECURITY_INFO::secureChannelProtocol
BYTE secureChannelProtocol
The Secure Channel Protocol.
Definition: security.h:205
OP201_KEY_INFORMATION::keyIndex
BYTE keyIndex
The key index.
Definition: security.h:260
GP211_KEY_INFORMATION::keyType
BYTE keyType
The key type.
Definition: security.h:296
GP211_RECEIPT_DATA
Definition: security.h:280
OP201_RECEIPT_DATA::receiptLength
BYTE receiptLength
The length of the receipt DAP.
Definition: security.h:244
GP211_RECEIPT_DATA::confirmationCounterLength
BYTE confirmationCounterLength
Length of the confirmation counter buffer.
Definition: security.h:283
OP201_SECURITY_INFO
Definition: security.h:188
GP211_RECEIPT_DATA::receiptLength
BYTE receiptLength
The length of the receipt DAP.
Definition: security.h:281
OP201_DAP_BLOCK::signatureLength
BYTE signatureLength
The length of the signature. Can be 8 for a 3DES signature or 128 for a RSA signature.
Definition: security.h:234
OP201_RECEIPT_DATA
Definition: security.h:243
GP211_RECEIPT_DATA::cardUniqueDataLength
BYTE cardUniqueDataLength
The length of the card unique data buffer.
Definition: security.h:285
GP211_KEY_INFORMATION::keyLength
USHORT keyLength
The key length.
Definition: security.h:297
OP201_KEY_INFORMATION::keyType
BYTE keyType
The key type.
Definition: security.h:261
GP211_DAP_BLOCK
Definition: security.h:269
GP211_DAP_BLOCK::securityDomainAIDLength
BYTE securityDomainAIDLength
The length of the Security Domain.
Definition: security.h:270
GP211_SECURITY_INFO::securityLevel
BYTE securityLevel
The security level.
Definition: security.h:204
OP201_KEY_INFORMATION::keySetVersion
BYTE keySetVersion
The key set version.
Definition: security.h:259
GP211_SECURITY_INFO::secureChannelProtocolImpl
BYTE secureChannelProtocolImpl
The Secure Channel Protocol implementation.
Definition: security.h:206
OP201_KEY_INFORMATION
Definition: security.h:258
GP211_KEY_INFORMATION::keyAccess
BYTE keyAccess
Key access used in extended format.
Definition: security.h:299
GP211_KEY_INFORMATION
Definition: security.h:293
OP201_KEY_INFORMATION::keyLength
BYTE keyLength
The key length.
Definition: security.h:262