Go to the documentation of this file.
40 static const BYTE ICV[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
41 static const BYTE SCP03_ICV[16] = {0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
45 int messageLength,
BYTE chainingValue[16],
56 BYTE keyCheckValue[3]);
60 BYTE hostChallenge[8],
BYTE sessionKey[16]);
64 BYTE sequenceCounter[2],
BYTE sessionKey[16]);
68 char *passPhrase,
BYTE signature[128]);
76 BYTE cardChallenge[8],
77 BYTE hostChallenge[8],
78 BYTE cardCryptogram[8]);
82 BYTE sequenceCounter[2],
83 BYTE cardChallenge[6],
84 BYTE hostChallenge[8],
85 BYTE cardCryptogram[8]);
89 BYTE cardChallenge[8],
90 BYTE hostChallenge[8],
91 BYTE hostCryptogram[8]);
95 BYTE sequenceCounter[2],
96 BYTE cardChallenge[6],
97 BYTE hostChallenge[8],
98 BYTE hostCryptogram[8]);
102 BYTE hostChallenge[8],
BYTE sessionKey[16]);
106 BYTE sequenceCounter[3],
108 DWORD invokingAIDLength,
109 BYTE cardChallenge[8]);
113 BYTE cardChallenge[8],
114 BYTE hostChallenge[8],
115 BYTE cardCryptogram[8]);
119 BYTE cardChallenge[8],
120 BYTE hostChallenge[8],
121 BYTE hostCryptogram[8]);
131 DWORD responseDataLength,
PBYTE unwrappedResponseData,
141 int messageLength,
BYTE *encryption,
142 int *encryptionLength);
146 BYTE receipt[16],
BYTE receiptKey[16],
BYTE secureChannelProtocol);
154 DWORD cardUniqueDataLength,
156 PBYTE executableLoadFileAID,
DWORD executableLoadFileAIDLength,
157 PBYTE applicationAID,
DWORD applicationAIDLength,
BYTE secureChannelProtocol);
161 DWORD cardUniqueDataLength,
167 DWORD cardUniqueDataLength,
169 PBYTE executableLoadFileAID,
DWORD executableLoadFileAIDLength,
170 PBYTE securityDomainAID,
DWORD securityDomainAIDLength,
BYTE secureChannelProtocol);
unsigned long * PDWORD
A Microsoft LPDWORD/Muscle pointer to a DWORD.
Definition: types.h:50
OPGP_NO_API OPGP_ERROR_STATUS calculate_rsa_signature(PBYTE message, DWORD messageLength, OPGP_STRING PEMKeyFileName, char *passPhrase, BYTE signature[128])
Definition: crypto.c:1070
unsigned char * PBYTE
A Microsoft/Muscle LPBYTE, pointer to unsigned char.
Definition: types.h:48
OPGP_NO_API OPGP_ERROR_STATUS calculate_card_cryptogram_SCP03(BYTE S_MACSessionKey[16], BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE cardCryptogram[8])
Definition: crypto.c:555
OPGP_NO_API OPGP_ERROR_STATUS get_random(BYTE *random, int randomLength)
Definition: crypto.c:2109
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:498
OPGP_NO_API OPGP_ERROR_STATUS calculate_sha256_hash(PBYTE message, DWORD messageLength, BYTE hash[32])
Calculates a SHA-256 hash.
Definition: crypto.c:2015
unsigned char BYTE
A Microsoft/Muscle BYTE definition.
Definition: types.h:51
OPGP_NO_API OPGP_ERROR_STATUS read_public_rsa_key(OPGP_STRING PEMKeyFileName, char *passPhrase, BYTE rsaModulus[128], LONG *rsaExponent)
Reads a public RSA key from a file.
Definition: crypto.c:1922
OPGP_NO_API OPGP_ERROR_STATUS validate_receipt(PBYTE validationData, DWORD validationDataLength, BYTE receipt[16], BYTE receiptKey[16], BYTE secureChannelProtocol)
Definition: crypto.c:1215
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:611
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. decrypts and checks the R-MAC of a response APDU with the necessary security...
Definition: crypto.c:1797
long LONG
A long value.
Definition: types.h:53
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:1855
OPGP_NO_API OPGP_ERROR_STATUS create_session_key_SCP03(BYTE key[16], BYTE derivationConstant, BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE sessionKey[16])
Definition: crypto.c:765
Definition: security.h:203
OPGP_NO_API OPGP_ERROR_STATUS calculate_card_cryptogram_SCP02(BYTE S_ENCSessionKey[16], BYTE sequenceCounter[2], BYTE cardChallenge[6], BYTE hostChallenge[8], BYTE cardCryptogram[8])
Definition: crypto.c:525
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:52
OPGP_NO_API OPGP_ERROR_STATUS calculate_enc_ecb_two_key_triple_des(BYTE key[16], BYTE *message, int messageLength, BYTE *encryption, int *encryptionLength)
Definition: crypto.c:790
OPGP_NO_API OPGP_ERROR_STATUS create_session_key_SCP02(BYTE key[16], BYTE constant[2], BYTE sequenceCounter[2], BYTE sessionKey[16])
Definition: crypto.c:730
OPGP_NO_API OPGP_ERROR_STATUS calculate_sha1_hash(PBYTE message, DWORD messageLength, BYTE hash[20])
Calculates a SHA-1 hash.
Definition: crypto.c:2024
OPGP_NO_API OPGP_ERROR_STATUS calculate_MAC_des_3des(BYTE _3des_key[16], BYTE *message, int messageLength, BYTE initialICV[8], BYTE mac[8])
Definition: crypto.c:1133
OPGP_NO_API OPGP_ERROR_STATUS calculate_host_cryptogram_SCP02(BYTE S_ENCSessionKey[16], BYTE sequenceCounter[2], BYTE cardChallenge[6], BYTE hostChallenge[8], BYTE hostCryptogram[8])
Definition: crypto.c:640
Definition: security.h:280
OPGP_NO_API OPGP_ERROR_STATUS calculate_host_cryptogram_SCP03(BYTE S_MACSessionKey[16], BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE hostCryptogram[8])
Definition: crypto.c:670
OPGP_NO_API OPGP_ERROR_STATUS create_session_key_SCP01(BYTE key[16], BYTE cardChallenge[8], BYTE hostChallenge[8], BYTE sessionKey[16])
Definition: crypto.c:698
char * OPGP_STRING
A Microsoft/Muscle LPTSTR.
Definition: types.h:46
OPGP_NO_API OPGP_ERROR_STATUS calculate_card_challenge_SCP03(BYTE S_ENC[16], BYTE sequenceCounter[3], PBYTE invokingAID, DWORD invokingAIDLength, BYTE cardChallenge[8])
Definition: crypto.c:583
OPGP_NO_API OPGP_ERROR_STATUS calculate_MAC(BYTE sessionKey[16], BYTE *message, int messageLength, BYTE icv[8], BYTE mac[8])
Definition: crypto.c:915
OPGP_NO_API OPGP_ERROR_STATUS calculate_MAC_right_des_3des(BYTE key[16], BYTE *message, int messageLength, BYTE mac[8])
Calculates a MAC using first DES and 3DES for the final round when the padding is applied.
Definition: crypto.c:2035
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:1390
OPGP_NO_API OPGP_ERROR_STATUS calculate_CMAC_aes(BYTE sMacKey[16], BYTE *message, int messageLength, BYTE chainingValue[16], BYTE mac[16])
Creates a MAC for commands (APDUs) using CMAC AES. This is used by SCP03. The MAC for the message are...
Definition: crypto.c:149