53 static const BYTE ICV[8] = {0};
54 static const BYTE SCP03_ICV[32] = {0};
66 BYTE keyCheckValue[3]);
73 PDWORD encryptedDataLength);
82 BYTE keyCheckValue[3], BOOL includeKeyCheckValue);
90 BYTE sequenceCounter[2],
PBYTE sessionKey);
94 char *passPhrase,
PBYTE signature,
PDWORD signatureLength);
98 char *passPhrase,
PBYTE signature,
PDWORD signatureLength);
102 char *passPhrase,
PBYTE signature,
PDWORD signatureLength);
106 char *passPhrase,
PBYTE signature,
DWORD signatureLength);
114 BYTE *encryption,
DWORD *encryptionLength);
118 BYTE *encryption,
DWORD *encryptionLength);
129 BYTE *encryption,
DWORD *encryptionLength);
133 BYTE cardChallenge[8],
134 BYTE hostChallenge[8],
135 BYTE cardCryptogram[8]);
139 BYTE sequenceCounter[2],
141 BYTE hostChallenge[8],
142 BYTE cardCryptogram[8]);
146 BYTE cardChallenge[8],
147 BYTE hostChallenge[8],
148 BYTE hostCryptogram[8]);
152 BYTE sequenceCounter[2],
154 BYTE hostChallenge[8],
155 BYTE hostCryptogram[8]);
159 BYTE hostChallenge[8],
PBYTE sessionKey);
164 BYTE sequenceCounter[3],
166 DWORD invokingAIDLength,
167 BYTE cardChallenge[8]);
172 BYTE cardChallenge[8],
173 BYTE hostChallenge[8],
174 BYTE cardCryptogram[8]);
179 BYTE cardChallenge[8],
180 BYTE hostChallenge[8],
181 BYTE hostCryptogram[8]);
191 DWORD responseDataLength,
PBYTE unwrappedResponseData,
202 DWORD *encryptionLength);
221 PBYTE executableLoadFileAID,
DWORD executableLoadFileAIDLength,
222 PBYTE applicationAID,
DWORD applicationAIDLength,
232 PBYTE executableLoadFileAID,
DWORD executableLoadFileAIDLength,
233 PBYTE securityDomainAID,
DWORD securityDomainAIDLength,
238 PBYTE oldSecurityDomainAID,
DWORD oldSecurityDomainAIDLength,
239 PBYTE newSecurityDomainAID,
DWORD newSecurityDomainAIDLength,
240 PBYTE applicationOrExecutableLoadFileAID,
241 DWORD applicationOrExecutableLoadFileAIDLength,
246 PBYTE oldSecurityDomainAID,
DWORD oldSecurityDomainAIDLength,
247 PBYTE applicationAID,
DWORD applicationAIDLength,
248 PBYTE newSecurityDomainAID,
DWORD newSecurityDomainAIDLength,
249 DWORD applicationPrivileges,
250 PBYTE registryUpdateParameters,
DWORD registryUpdateParametersLength,
283 DWORD certificateChainDataLength,
PBYTE authorityIdentifier,
PDWORD authorityIdentifierLength);
293 DWORD generatorLength;
297 DWORD cofactorLength;
304 PBYTE eccKeyComponentType,
PBYTE keyParameterReference,
311 PBYTE eccKeyComponentType,
PBYTE keyParameterReference);
323 PBYTE peerPublicKey,
DWORD peerPublicKeyLength,
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: security.h:337
Definition: security.h:243
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