globalplatform
scp.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 OPGP_SCP_H
36 #define OPGP_SCP_H
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #include "globalplatform/library.h"
44 #include "globalplatform/types.h"
45 #include "globalplatform/error.h"
47 
48 typedef struct {
49  BYTE keyInformationDataLength;
50  BYTE cardChallenge[8];
51  BYTE cardChallengeLength;
52  BYTE sequenceCounter[3];
53  BYTE sequenceCounterLength;
54  BYTE cardCryptogram[8];
56 
57 typedef struct {
58  BYTE caseAPDU;
59  DWORD lc;
60  DWORD wrappedLength;
61  DWORD paddingSize;
62  DWORD headerLength;
63  BOOL isExtended;
65 
66 OPGP_NO_API
67 OPGP_ERROR_STATUS scp_parse_initialize_update_response(
68  BYTE secureChannelProtocol,
69  BYTE *secureChannelProtocolImpl,
70  BYTE securityLevel,
71  PBYTE keyInformationData,
72  PBYTE recvBuffer,
73  DWORD recvBufferLength,
75 
76 OPGP_NO_API
77 OPGP_ERROR_STATUS scp_derive_session_keys_and_verify_card_cryptogram(
78  BYTE secureChannelProtocol,
79  GP211_SECURITY_INFO *secInfo,
80  PBYTE baseKey,
81  PBYTE sEnc,
82  PBYTE sMac,
83  PBYTE dek,
84  DWORD keyLength,
85  PBYTE hostChallenge,
86  const SCP_INITIALIZE_UPDATE_RESPONSE *response);
87 
88 OPGP_NO_API
89 OPGP_ERROR_STATUS scp_prepare_external_authentication(
90  BYTE secureChannelProtocol,
91  GP211_SECURITY_INFO *secInfo,
92  DWORD keyLength,
93  BYTE securityLevel,
94  PBYTE hostChallenge,
95  const SCP_INITIALIZE_UPDATE_RESPONSE *response,
96  PBYTE hostCryptogram,
97  PBYTE mac);
98 
99 OPGP_NO_API
100 OPGP_ERROR_STATUS scp_wrap_command_by_protocol(
101  GP211_SECURITY_INFO *secInfo,
102  PBYTE apduCommand,
103  PBYTE wrappedApduCommand,
104  SCP_WRAP_COMMAND_CONTEXT *context,
105  PBYTE encryption,
106  PDWORD encryptionLength,
107  PBYTE mac);
108 
109 OPGP_NO_API
110 OPGP_ERROR_STATUS scp11a_generate_ephemeral_keypair(
111  BYTE keyParameterReference,
112  PBYTE privateKey,
113  PDWORD privateKeyLength,
114  PBYTE publicKey,
115  PDWORD publicKeyLength);
116 
117 OPGP_NO_API
118 BYTE map_scp11a_key_usage_qualifier(BYTE securityLevel);
119 
120 OPGP_NO_API
121 BYTE map_scp11a_security_level(BYTE keyUsageQualifier);
122 
123 OPGP_NO_API
124 BYTE map_scp11a_scp03_impl(BYTE keyUsageQualifier);
125 
126 OPGP_NO_API
127 DWORD scp11_private_key_length_from_key_parameter_reference(BYTE keyParameterReference);
128 
129 OPGP_NO_API
130 OPGP_ERROR_STATUS extract_scp11_sd_public_key_from_certificate_store(PBYTE certificateStore, DWORD certificateStoreLength,
131  PBYTE sdPublicKey, PDWORD sdPublicKeyLength, BYTE *keyParameterReference);
132 
133 OPGP_NO_API
134 OPGP_ERROR_STATUS parse_scp11_mutual_authentication_response(PBYTE responseData, DWORD responseDataLength,
135  PBYTE sdEphemeralPublicKey, PDWORD sdEphemeralPublicKeyLength, PBYTE receipt, PDWORD receiptLength);
136 
137 OPGP_NO_API
138 OPGP_ERROR_STATUS scp11a_derive_session_keys_and_verify_receipt(
139  GP211_SECURITY_INFO *secInfo,
140  BYTE keyLength,
141  BYTE keyParameterReference,
142  PBYTE oceStaticPrivateKey,
143  DWORD oceStaticPrivateKeyLength,
144  PBYTE sdStaticPublicKey,
145  DWORD sdStaticPublicKeyLength,
146  PBYTE oceEphemeralPrivateKey,
147  DWORD oceEphemeralPrivateKeyLength,
148  PBYTE sdEphemeralPublicKey,
149  DWORD sdEphemeralPublicKeyLength,
150  PBYTE sharedInfo,
151  DWORD sharedInfoLength,
152  PBYTE receiptInput,
153  DWORD receiptInputLength,
154  PBYTE receipt,
155  DWORD receiptLength);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif
Definition: security.h:243
Definition: error.h:58
Definition: scp.h:48
Definition: scp.h:57
unsigned char BYTE
A Microsoft/Muscle BYTE definition.
Definition: types.h:67
unsigned char * PBYTE
A Microsoft/Muscle LPBYTE, pointer to unsigned char.
Definition: types.h:64
unsigned long * PDWORD
A Microsoft LPDWORD/Muscle pointer to a DWORD.
Definition: types.h:66
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:68