globalplatform
crypto.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_CRYPTO_H
36 #define OPGP_CRYPTO_H
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #ifdef WIN32
44 #include "stdafx.h"
45 #endif
46 
47 #include "globalplatform/types.h"
48 #include "globalplatform/library.h"
49 #include "globalplatform/unicode.h"
50 #include "globalplatform/error.h"
52 
53 static const BYTE ICV[8] = {0};
54 static const BYTE SCP03_ICV[32] = {0};
55 
56 OPGP_NO_API
57 OPGP_ERROR_STATUS calculate_CMAC_aes(PBYTE sMacKey, DWORD keyLength, BYTE *message,
58  DWORD messageLength, PBYTE chainingValue,
59  PBYTE mac);
60 
61 OPGP_NO_API
63  BYTE keyType,
64  PBYTE keyData,
65  DWORD keyDataLength,
66  BYTE keyCheckValue[3]);
67 
68 OPGP_NO_API
70  PBYTE data,
71  DWORD dataLength,
72  PBYTE encryptedData,
73  PDWORD encryptedDataLength);
74 
75 OPGP_NO_API
76 OPGP_ERROR_STATUS get_key_data_field(GP211_SECURITY_INFO *secInfo,
77  PBYTE keyData,
78  DWORD keyDataLength,
79  BYTE keyType,
80  PBYTE keyDataField,
81  PDWORD keyDataFieldLength,
82  BYTE keyCheckValue[3], BOOL includeKeyCheckValue);
83 
84 OPGP_NO_API
85 OPGP_ERROR_STATUS create_session_key_SCP01(BYTE key[16], BYTE cardChallenge[8],
86  BYTE hostChallenge[8], PBYTE sessionKey);
87 
88 OPGP_NO_API
90  BYTE sequenceCounter[2], PBYTE sessionKey);
91 
92 OPGP_NO_API
93 OPGP_ERROR_STATUS calculate_rsa_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName,
94  char *passPhrase, PBYTE signature, PDWORD signatureLength);
95 
96 OPGP_NO_API
97 OPGP_ERROR_STATUS calculate_ecc_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName,
98  char *passPhrase, PBYTE signature, PDWORD signatureLength);
99 
100 OPGP_NO_API
101 OPGP_ERROR_STATUS calculate_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName,
102  char *passPhrase, PBYTE signature, PDWORD signatureLength);
103 
104 OPGP_NO_API
105 OPGP_ERROR_STATUS validate_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName,
106  char *passPhrase, PBYTE signature, DWORD signatureLength);
107 
108 OPGP_NO_API
109 OPGP_ERROR_STATUS calculate_MAC(BYTE sessionKey[16], BYTE *message, DWORD messageLength,
110  BYTE icv[8], BYTE mac[8]);
111 
112 OPGP_NO_API
113 OPGP_ERROR_STATUS calculate_enc_cbc(BYTE key[16], BYTE *message, DWORD messageLength,
114  BYTE *encryption, DWORD *encryptionLength);
115 
116 OPGP_NO_API
117 OPGP_ERROR_STATUS calculate_enc_cbc_SCP02(BYTE key[16], BYTE *message, DWORD messageLength,
118  BYTE *encryption, DWORD *encryptionLength);
119 
120 OPGP_NO_API
121 OPGP_ERROR_STATUS calculate_enc_cbc_SCP03(BYTE key[32], DWORD keyLength, BYTE *message, DWORD messageLength,
122  PBYTE icv, PBYTE encryption, PDWORD encryptionLength);
123 
124 OPGP_NO_API
125 OPGP_ERROR_STATUS calculate_enc_icv_SCP03(PBYTE key, DWORD keyLength, LONG sessionEncryptionCounter, PBYTE icv, BOOL forResponse);
126 
127 OPGP_NO_API
128 OPGP_ERROR_STATUS calculate_enc_ecb_single_des(BYTE key[8], BYTE *message, DWORD messageLength,
129  BYTE *encryption, DWORD *encryptionLength);
130 
131 OPGP_NO_API
133  BYTE cardChallenge[8],
134  BYTE hostChallenge[8],
135  BYTE cardCryptogram[8]);
136 
137 OPGP_NO_API
139  BYTE sequenceCounter[2],
140  PBYTE cardChallenge,
141  BYTE hostChallenge[8],
142  BYTE cardCryptogram[8]);
143 
144 OPGP_NO_API
146  BYTE cardChallenge[8],
147  BYTE hostChallenge[8],
148  BYTE hostCryptogram[8]);
149 
150 OPGP_NO_API
152  BYTE sequenceCounter[2],
153  PBYTE cardChallenge,
154  BYTE hostChallenge[8],
155  BYTE hostCryptogram[8]);
156 
157 OPGP_NO_API
158 OPGP_ERROR_STATUS create_session_key_SCP03(BYTE key[32], DWORD keyLength, BYTE derivationConstant, BYTE cardChallenge[8],
159  BYTE hostChallenge[8], PBYTE sessionKey);
160 
161 OPGP_NO_API
163  DWORD keyLength,
164  BYTE sequenceCounter[3],
165  PBYTE invokingAID,
166  DWORD invokingAIDLength,
167  BYTE cardChallenge[8]);
168 
169 OPGP_NO_API
171  DWORD keyLength,
172  BYTE cardChallenge[8],
173  BYTE hostChallenge[8],
174  BYTE cardCryptogram[8]);
175 
176 OPGP_NO_API
178  DWORD keyLength,
179  BYTE cardChallenge[8],
180  BYTE hostChallenge[8],
181  BYTE hostCryptogram[8]);
182 
184 OPGP_NO_API
185 OPGP_ERROR_STATUS wrap_command(PBYTE apduCommand, DWORD apduCommandLength, PBYTE wrappedApduCommand,
186  PDWORD wrappedApduCommandLength, GP211_SECURITY_INFO *secInfo);
187 
189 OPGP_NO_API
190 OPGP_ERROR_STATUS unwrap_command(PBYTE apduCommand, DWORD apduCommandLength, PBYTE responseData,
191  DWORD responseDataLength, PBYTE unwrappedResponseData,
192  PDWORD unwrappedResponseDataLength, GP211_SECURITY_INFO *secInfo);
193 
195 OPGP_NO_API
196 OPGP_ERROR_STATUS GP211_check_R_MAC(PBYTE apduCommand, DWORD apduCommandLength, PBYTE responseData,
197  DWORD responseDataLength, PBYTE unwrappedResponseApdu, PDWORD unwrappedResponseApduLength, GP211_SECURITY_INFO *secInfo);
198 
199 OPGP_NO_API
201  DWORD messageLength, BYTE *encryption,
202  DWORD *encryptionLength);
203 
204 OPGP_NO_API
205 OPGP_ERROR_STATUS validate_receipt(PBYTE validationData, DWORD validationDataLength,
206  BYTE receipt[16], PBYTE receiptKey, DWORD keyLength, BYTE secureChannelProtocol);
207 
208 OPGP_NO_API
209 OPGP_ERROR_STATUS validate_receipt_ex(PBYTE validationData, DWORD validationDataLength,
210  PBYTE receipt, DWORD receiptLength,
211  PBYTE receiptKey, DWORD keyLength,
212  BYTE receiptKeyType,
213  OPGP_STRING PEMKeyFileName, char *passPhrase);
214 
215 OPGP_NO_API
216 OPGP_ERROR_STATUS calculate_MAC_des_3des(BYTE _3des_key[16], BYTE *message, DWORD messageLength,
217  BYTE initialICV[8], BYTE mac[8]);
218 
219 OPGP_NO_API
220 OPGP_ERROR_STATUS validate_install_receipt(PBYTE receiptKey, DWORD keyLength, GP211_RECEIPT_DATA receiptData,
221  PBYTE executableLoadFileAID, DWORD executableLoadFileAIDLength,
222  PBYTE applicationAID, DWORD applicationAIDLength,
223  BYTE receiptKeyType, OPGP_STRING PEMKeyFileName, char *passPhrase);
224 
225 OPGP_NO_API
226 OPGP_ERROR_STATUS validate_delete_receipt(PBYTE receiptKey, DWORD keyLength, GP211_RECEIPT_DATA receiptData,
227  PBYTE AID, DWORD AIDLength,
228  BYTE receiptKeyType, OPGP_STRING PEMKeyFileName, char *passPhrase);
229 
230 OPGP_NO_API
231 OPGP_ERROR_STATUS validate_load_receipt(PBYTE receiptKey, DWORD keyLength, GP211_RECEIPT_DATA receiptData,
232  PBYTE executableLoadFileAID, DWORD executableLoadFileAIDLength,
233  PBYTE securityDomainAID, DWORD securityDomainAIDLength,
234  BYTE receiptKeyType, OPGP_STRING PEMKeyFileName, char *passPhrase);
235 
236 OPGP_NO_API
237 OPGP_ERROR_STATUS validate_extradition_receipt(PBYTE receiptKey, DWORD keyLength, GP211_RECEIPT_DATA receiptData,
238  PBYTE oldSecurityDomainAID, DWORD oldSecurityDomainAIDLength,
239  PBYTE newSecurityDomainAID, DWORD newSecurityDomainAIDLength,
240  PBYTE applicationOrExecutableLoadFileAID,
241  DWORD applicationOrExecutableLoadFileAIDLength,
242  BYTE receiptKeyType, OPGP_STRING PEMKeyFileName, char *passPhrase);
243 
244 OPGP_NO_API
245 OPGP_ERROR_STATUS validate_registry_update_receipt(PBYTE receiptKey, DWORD keyLength, GP211_RECEIPT_DATA receiptData,
246  PBYTE oldSecurityDomainAID, DWORD oldSecurityDomainAIDLength,
247  PBYTE applicationAID, DWORD applicationAIDLength,
248  PBYTE newSecurityDomainAID, DWORD newSecurityDomainAIDLength,
249  DWORD applicationPrivileges,
250  PBYTE registryUpdateParameters, DWORD registryUpdateParametersLength,
251  BYTE receiptKeyType, OPGP_STRING PEMKeyFileName, char *passPhrase);
252 
254 OPGP_NO_API
255 OPGP_ERROR_STATUS read_public_rsa_key(OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE rsaModulus, PDWORD rsaModulusLength, LONG *rsaExponent);
256 
258 OPGP_NO_API
259 OPGP_ERROR_STATUS read_certificate_file(OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE certificateData, PDWORD certificateDataLength);
260 
262 OPGP_NO_API
263 BOOL contains_pem_certificate_header(const BYTE *data, DWORD dataLength);
264 
266 OPGP_NO_API
268  PBYTE derData, PDWORD derDataLength);
269 
271 OPGP_NO_API
273  PBYTE pemData, PDWORD pemDataLength);
274 
276 OPGP_NO_API
278  PBYTE preparedData, PDWORD preparedDataLength);
279 
281 OPGP_NO_API
283  DWORD certificateChainDataLength, PBYTE authorityIdentifier, PDWORD authorityIdentifierLength);
284 
285 typedef struct {
286  BYTE fieldP[512];
287  DWORD fieldPLength;
288  BYTE fieldA[512];
289  DWORD fieldALength;
290  BYTE fieldB[512];
291  DWORD fieldBLength;
292  BYTE generator[512];
293  DWORD generatorLength;
294  BYTE order[512];
295  DWORD orderLength;
296  BYTE cofactor[32];
297  DWORD cofactorLength;
299 
301 OPGP_NO_API
302 OPGP_ERROR_STATUS read_public_ecc_key(OPGP_STRING PEMKeyFileName, char *passPhrase,
303  PBYTE eccPublicPoint, PDWORD eccPublicPointLength,
304  PBYTE eccKeyComponentType, PBYTE keyParameterReference,
305  GP211_ECC_DOMAIN_PARAMETERS *domainParameters);
306 
308 OPGP_NO_API
309 OPGP_ERROR_STATUS read_public_ecc_key_from_der_certificate(const BYTE *certificateData, DWORD certificateDataLength,
310  PBYTE eccPublicPoint, PDWORD eccPublicPointLength,
311  PBYTE eccKeyComponentType, PBYTE keyParameterReference);
312 
314 OPGP_NO_API
316  PBYTE privateKey, PDWORD privateKeyLength,
317  PBYTE publicKey, PDWORD publicKeyLength);
318 
320 OPGP_NO_API
322  PBYTE privateKey, DWORD privateKeyLength,
323  PBYTE peerPublicKey, DWORD peerPublicKeyLength,
324  PBYTE sharedSecret, PDWORD sharedSecretLength);
325 
327 OPGP_NO_API
328 OPGP_ERROR_STATUS calculate_sha2_hash(PBYTE message, DWORD messageLength, BYTE hash[64], DWORD hashLength);
329 
331 OPGP_NO_API
332 OPGP_ERROR_STATUS calculate_sha1_hash(PBYTE message, DWORD messageLength, BYTE hash[20]);
333 
335 OPGP_NO_API
336 OPGP_ERROR_STATUS calculate_sm3_hash(PBYTE message, DWORD messageLength, BYTE hash[32]);
337 
339 OPGP_NO_API
340 OPGP_ERROR_STATUS calculate_MAC_right_des_3des(BYTE key[16], BYTE *message, DWORD messageLength, BYTE mac[8]);
341 
342 OPGP_NO_API
343 OPGP_ERROR_STATUS get_random(BYTE *random, int randomLength);
344 
345 #ifdef __cplusplus
346 }
347 #endif
348 
349 #endif
OPGP_ERROR_STATUS calculate_enc_cbc_SCP03(BYTE key[32], DWORD keyLength, BYTE *message, DWORD messageLength, BYTE icv[16], BYTE *encryption, DWORD *encryptionLength)
Definition: crypto.c:343
OPGP_NO_API OPGP_ERROR_STATUS calculate_sm3_hash(PBYTE message, DWORD messageLength, BYTE hash[32])
Calculates a SM3 hash.
Definition: crypto.c:4187
OPGP_NO_API OPGP_ERROR_STATUS calculate_MAC(BYTE sessionKey[16], BYTE *message, DWORD messageLength, BYTE icv[8], BYTE mac[8])
Definition: crypto.c:1005
OPGP_NO_API OPGP_ERROR_STATUS calculate_enc_cbc(BYTE key[16], BYTE *message, DWORD messageLength, BYTE *encryption, DWORD *encryptionLength)
Definition: crypto.c:1062
OPGP_NO_API OPGP_ERROR_STATUS calculate_enc_cbc_SCP02(BYTE key[16], BYTE *message, DWORD messageLength, BYTE *encryption, DWORD *encryptionLength)
Definition: crypto.c:517
OPGP_NO_API OPGP_ERROR_STATUS calculate_host_cryptogram_SCP01(BYTE S_ENCSessionKey[16], BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE hostCryptogram[8])
Definition: crypto.c:694
OPGP_NO_API OPGP_ERROR_STATUS calculate_MAC_right_des_3des(BYTE key[16], BYTE *message, DWORD messageLength, BYTE mac[8])
Calculates a MAC using first DES and 3DES for the final round when the padding is applied.
Definition: crypto.c:4198
OPGP_NO_API OPGP_ERROR_STATUS calculate_key_check_value(GP211_SECURITY_INFO *secInfo, BYTE keyType, PBYTE keyData, DWORD keyDataLength, BYTE keyCheckValue[3])
Definition: crypto.c:2026
OPGP_NO_API OPGP_ERROR_STATUS calculate_enc_ecb_single_des(BYTE key[8], BYTE *message, DWORD messageLength, BYTE *encryption, DWORD *encryptionLength)
Definition: crypto.c:942
OPGP_NO_API OPGP_ERROR_STATUS calculate_card_cryptogram_SCP03(BYTE S_MACSessionKey[32], DWORD keyLength, BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE cardCryptogram[8])
Definition: crypto.c:635
OPGP_NO_API OPGP_ERROR_STATUS calculate_rsa_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE signature, PDWORD signatureLength)
Definition: crypto.c:1388
OPGP_NO_API OPGP_ERROR_STATUS read_certificate_file(OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE certificateData, PDWORD certificateDataLength)
Reads a certificate from a PEM or DER file.
Definition: crypto.c:3628
OPGP_NO_API OPGP_ERROR_STATUS calculate_sha1_hash(PBYTE message, DWORD messageLength, BYTE hash[20])
Calculates a SHA-1 hash.
Definition: crypto.c:4178
OPGP_NO_API OPGP_ERROR_STATUS calculate_ecc_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE signature, PDWORD signatureLength)
Definition: crypto.c:1396
OPGP_NO_API OPGP_ERROR_STATUS GP211_check_R_MAC(PBYTE apduCommand, DWORD apduCommandLength, PBYTE responseData, DWORD responseDataLength, PBYTE unwrappedResponseApdu, PDWORD unwrappedResponseApduLength, GP211_SECURITY_INFO *secInfo)
Checks the R-MAC of an APDU with the necessary security information according to secInfo.
Definition: crypto.c:2826
OPGP_NO_API OPGP_ERROR_STATUS create_session_key_SCP02(BYTE key[16], BYTE constant[2], BYTE sequenceCounter[2], PBYTE sessionKey)
Definition: crypto.c:815
OPGP_NO_API OPGP_ERROR_STATUS get_random(BYTE *random, int randomLength)
Definition: crypto.c:4272
OPGP_NO_API OPGP_ERROR_STATUS extract_scp11_ca_kloc_identifier_from_certificate_chain(const BYTE *certificateChainData, DWORD certificateChainDataLength, PBYTE authorityIdentifier, PDWORD authorityIdentifierLength)
Extracts the CA-KLOC Identifier used to verify the first SCP11 certificate.
Definition: crypto.c:3558
OPGP_NO_API OPGP_ERROR_STATUS create_session_key_SCP01(BYTE key[16], BYTE cardChallenge[8], BYTE hostChallenge[8], PBYTE sessionKey)
Definition: crypto.c:783
OPGP_NO_API BOOL contains_pem_certificate_header(const BYTE *data, DWORD dataLength)
Checks whether data contains a PEM CERTIFICATE header.
Definition: crypto.c:3158
OPGP_NO_API OPGP_ERROR_STATUS calculate_host_cryptogram_SCP02(BYTE S_ENCSessionKey[16], BYTE sequenceCounter[2], PBYTE cardChallenge, BYTE hostChallenge[8], BYTE hostCryptogram[8])
Definition: crypto.c:723
OPGP_NO_API OPGP_ERROR_STATUS unwrap_command(PBYTE apduCommand, DWORD apduCommandLength, PBYTE responseData, DWORD responseDataLength, PBYTE unwrappedResponseData, PDWORD unwrappedResponseDataLength, GP211_SECURITY_INFO *secInfo)
Unwraps a response, i.e. decrypt and check the R-MAC of a response APDU with the necessary security i...
Definition: crypto.c:2737
OPGP_NO_API OPGP_ERROR_STATUS wrap_command(PBYTE apduCommand, DWORD apduCommandLength, PBYTE wrappedApduCommand, PDWORD wrappedApduCommandLength, GP211_SECURITY_INFO *secInfo)
Wraps a command, i.e. encrypts and add the MAC to the APDU with the necessary security information ac...
Definition: crypto.c:2172
OPGP_NO_API OPGP_ERROR_STATUS generate_ecc_keypair(int curveNid, PBYTE privateKey, PDWORD privateKeyLength, PBYTE publicKey, PDWORD publicKeyLength)
Generates an ECC key pair for a named OpenSSL curve.
Definition: crypto.c:2985
OPGP_NO_API OPGP_ERROR_STATUS encrypt_sensitive_data(GP211_SECURITY_INFO *secInfo, PBYTE data, DWORD dataLength, PBYTE encryptedData, PDWORD encryptedDataLength)
Definition: crypto.c:1986
OPGP_NO_API OPGP_ERROR_STATUS read_public_ecc_key_from_der_certificate(const BYTE *certificateData, DWORD certificateDataLength, PBYTE eccPublicPoint, PDWORD eccPublicPointLength, PBYTE eccKeyComponentType, PBYTE keyParameterReference)
Extracts a public ECC key from a DER encoded X.509 certificate.
Definition: crypto.c:3903
OPGP_NO_API OPGP_ERROR_STATUS calculate_sha2_hash(PBYTE message, DWORD messageLength, BYTE hash[64], DWORD hashLength)
Calculates a SHA-256 hash.
Definition: crypto.c:4167
OPGP_NO_API OPGP_ERROR_STATUS prepare_scp11_der_x509_certificate_chain(const BYTE *derData, DWORD derDataLength, PBYTE preparedData, PDWORD preparedDataLength)
Orders a DER X.509 chain for SCP11 verification and omits a self-issued trust anchor.
Definition: crypto.c:3353
OPGP_NO_API OPGP_ERROR_STATUS create_session_key_SCP03(BYTE key[32], DWORD keyLength, BYTE derivationConstant, BYTE cardChallenge[8], BYTE hostChallenge[8], PBYTE sessionKey)
Definition: crypto.c:851
OPGP_NO_API OPGP_ERROR_STATUS calculate_enc_icv_SCP03(PBYTE key, DWORD keyLength, LONG sessionEncryptionCounter, PBYTE icv, BOOL forResponse)
Definition: crypto.c:465
OPGP_NO_API OPGP_ERROR_STATUS convert_der_certificate_list_to_pem(const BYTE *derData, DWORD derDataLength, PBYTE pemData, PDWORD pemDataLength)
Converts one or more concatenated DER X.509 certificates to PEM CERTIFICATE blocks.
Definition: crypto.c:3266
OPGP_NO_API OPGP_ERROR_STATUS calculate_card_cryptogram_SCP02(BYTE S_ENCSessionKey[16], BYTE sequenceCounter[2], PBYTE cardChallenge, BYTE hostChallenge[8], BYTE cardCryptogram[8])
Definition: crypto.c:604
OPGP_NO_API OPGP_ERROR_STATUS convert_pem_certificate_list_to_der(const BYTE *pemData, DWORD pemDataLength, PBYTE derData, PDWORD derDataLength)
Converts one or more PEM CERTIFICATE blocks to concatenated DER certificates.
Definition: crypto.c:3174
OPGP_NO_API OPGP_ERROR_STATUS calculate_enc_ecb_two_key_triple_des(BYTE key[16], BYTE *message, DWORD messageLength, BYTE *encryption, DWORD *encryptionLength)
Definition: crypto.c:880
OPGP_NO_API OPGP_ERROR_STATUS calculate_card_cryptogram_SCP01(BYTE S_ENCSessionKey[16], BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE cardCryptogram[8])
Definition: crypto.c:577
OPGP_NO_API OPGP_ERROR_STATUS calculate_ecc_shared_secret(int curveNid, PBYTE privateKey, DWORD privateKeyLength, PBYTE peerPublicKey, DWORD peerPublicKeyLength, PBYTE sharedSecret, PDWORD sharedSecretLength)
Calculates an ECDH shared secret for a named OpenSSL curve.
Definition: crypto.c:3045
OPGP_NO_API OPGP_ERROR_STATUS calculate_CMAC_aes(PBYTE sMacKey, DWORD keyLength, BYTE *message, DWORD messageLength, PBYTE chainingValue, PBYTE mac)
Creates a MAC for commands (APDUs) using CMAC AES. This is used by SCP03. The MAC for the message is ...
Definition: crypto.c:172
OPGP_NO_API OPGP_ERROR_STATUS calculate_host_cryptogram_SCP03(BYTE S_MACSessionKey[32], DWORD keyLength, BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE hostCryptogram[8])
Definition: crypto.c:754
OPGP_NO_API OPGP_ERROR_STATUS calculate_MAC_des_3des(BYTE _3des_key[16], BYTE *message, DWORD messageLength, BYTE initialICV[8], BYTE mac[8])
Definition: crypto.c:1680
OPGP_NO_API OPGP_ERROR_STATUS read_public_rsa_key(OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE rsaModulus, PDWORD rsaModulusLength, LONG *rsaExponent)
Reads a public RSA key from a file.
Definition: crypto.c:3712
OPGP_NO_API OPGP_ERROR_STATUS calculate_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE signature, PDWORD signatureLength)
Definition: crypto.c:1347
OPGP_NO_API OPGP_ERROR_STATUS read_public_ecc_key(OPGP_STRING PEMKeyFileName, char *passPhrase, PBYTE eccPublicPoint, PDWORD eccPublicPointLength, PBYTE eccKeyComponentType, PBYTE keyParameterReference, GP211_ECC_DOMAIN_PARAMETERS *domainParameters)
Reads a public ECC key from a file.
Definition: crypto.c:3956
OPGP_NO_API OPGP_ERROR_STATUS calculate_card_challenge_SCP03(BYTE S_ENC[32], DWORD keyLength, BYTE sequenceCounter[3], PBYTE invokingAID, DWORD invokingAIDLength, BYTE cardChallenge[8])
Definition: crypto.c:665
Definition: crypto.h:285
Definition: security.h:337
Definition: security.h:243
Definition: error.h:58
long LONG
A long value.
Definition: types.h:69
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
char * OPGP_STRING
A Microsoft/Muscle LPTSTR.
Definition: types.h:62
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:68