AT-NFC 2.1 (win) AT-NFC kernel set

hal_crypt.h
Go to the documentation of this file.
1 #ifndef HAL_CRYPT_H
2 #define HAL_CRYPT_H
3
4 /* ******************** HAL terminal crypto functions API declaration ********************** */
8 /* ***************************************************************************************** */
9
10 /* set struct alignment */
11 #include <emv_platform_set_align.h>
12
13 /* ***************************************************************************************** */
20 /* ***************************************************************************************** */
21
22 /* ********************************* HAL Crypto marcos ************************************* */
27 /* ***************************************************************************************** */
28 #define KER_HASH_ALG_TC_HASH 0
29 #define KER_HASH_ALG_SHA1 1
30 #define KER_HASH_ALG_SHA256 2
31 #define KER_HASH_ALG_SHA512 3
32 #define KER_HASH_ALG_SHA3_256 4
33 #define KER_HASH_ALG_SHA3_512 5
34 #define KER_HASH_ALG_SM3 6
35 /* ***************************************************************************************** */
36 #define KER_CRYPT_ALG_DES 0
37 #define KER_CRYPT_ALG_AES 10
38 /* ***************************************************************************************** */
39 #define KER_CA_PK_SCHEME_NA 0
40 #define KER_CA_PK_SCHEME_RSA 1
41 #define KER_CA_PK_SCHEME_ECC 2
42 /* ***************************************************************************************** */
43 #define KER_REC_ALG_RSA_EMV 1
44 /* ***************************************************************************************** */
45 #define KER_HASH_SHA1_LEN 20
46 #define KER_HASH_SHA256_LEN 32
47 #define KER_HASH_SHA512_LEN 64
48 #define KER_HASH_SHA3_256_LEN 32
49 #define KER_HASH_SHA3_512_LEN 64
50 #define KER_HASH_SM3_LEN 32
51 /* ***************************************************************************************** */
52 #define KER_PK_MODULUS_LEN 248
53 #define KER_PK_EXP_LEN 3
54 #define KER_PK_HASH_LEN 20
55 #define KER_ECC_PK_P256_LEN 32
56 #define KER_ECC_PK_P521_LEN 66
57 /* ***************************************************************************************** */
58 #define KER_ECC_ASI_EC_SDSA_SHA256_P256 1
59 #define KER_ECC_ASI_EC_SDSA_SHA512_P521 2
60 #define KER_ECC_ASI_EC_SDSA_SHA3_256_P256 3
61 #define KER_ECC_ASI_EC_SDSA_SHA3_512_P521 4
62 #define KER_ECC_ASI_SM2_DSA_SM3_SM2_P256 5
63 #define KER_ECC_ASI_ODE_DH_EtM_AES_P256 20
64 #define KER_ECC_ASI_ODE_DH_EtM_AES_P521 21
65 #define KER_ECC_ASI_ODE_DH_EtM_SM4_SM2_P256 22
68 /* ******************************** hal_crypt_get_hash_len ********************************* */
77 extern KER_INT16U hal_crypt_get_hash_len(KER_CTX_PARAM KER_BYTE btAlg);
78
79 /* ******************************** hal_crypt_calc_hash ************************************ */
93 extern KER_BOOL hal_crypt_calc_hash(KER_CTX_PARAM KER_BYTE btAlg, KER_VOID* pExtra, const KER_BYTE* pbtDataBuffer, KER_INT16U usDataBufferLen, KER_BYTE* pbtHash, KER_INT16U* pusHashLen, KER_INT16U usHashSize);
94
95 /* ****************************** hal_crypt_calc_hash_init ********************************* */
105 extern KER_BOOL hal_crypt_calc_hash_init(KER_CTX_PARAM KER_BYTE btAlg, KER_VOID* pExtra, KER_VOID** ppHashHandle);
106
107 /* ***************************** hal_crypt_calc_hash_update ******************************** */
118 extern KER_BOOL hal_crypt_calc_hash_update(KER_CTX_PARAM KER_VOID* pHashHandle, KER_BYTE btAlg, const KER_BYTE* pbtDataBuffer, KER_INT16U usDataBufferLen);
119
120 /* **************************** hal_crypt_calc_hash_complete ******************************* */
132 extern KER_BOOL hal_crypt_calc_hash_complete(KER_CTX_PARAM KER_VOID* pHashHandle, KER_BYTE btAlg, KER_BYTE* pbtHash, KER_INT16U* pusHashLen, KER_INT16U usHashSize);
133
134 /* **************************** hal_crypt_unpredict_num_calc ******************************* */
143 extern KER_BOOL hal_crypt_unpredict_num_calc(KER_CTX_PARAM KER_INT16U usUnpredNumLen, KER_BYTE* pbtUnpredNum);
144
145 /* *************************** hal_crypt_unpredict_num_set_ac ****************************** */
156 extern KER_BOOL hal_crypt_unpredict_num_set_ac(KER_CTX_PARAM const KER_BYTE* pbtAc, KER_INT16U usAcLen);
157
158 /* ********************************** hal_crypt_encrypt ************************************ */
177 extern KER_BOOL hal_crypt_encrypt(KER_CTX_PARAM KER_BYTE btAlg, const KER_BYTE* pbtKey, KER_INT16U usKeyLen, const KER_BYTE* pbtIV, KER_INT16U usIVLen, const KER_BYTE* pbtData, KER_INT16U usDataLen, KER_BYTE* pbtResult, KER_INT16U* pusResultLen, KER_INT16U usMaxLen);
178
179 /* ********************************** hal_crypt_decrypt ************************************ */
198 extern KER_BOOL hal_crypt_decrypt(KER_CTX_PARAM KER_BYTE btAlg, const KER_BYTE* pbtKey, KER_INT16U usKeyLen, const KER_BYTE* pbtIV, KER_INT16U usIVLen, const KER_BYTE* pbtEncryptedData, KER_INT16U usEncryptedDataLen, KER_BYTE* pbtResult, KER_INT16U* pusResultLen, KER_INT16U usMaxLen);
199
203 typedef struct tag_HAL_CRYPT_PK
204 {
205 KER_INT16U usSize;
206 KER_BYTE btVer;
208 KER_BYTE btScheme;
210 union
211 {
212 struct
213 {
214 KER_BYTE btSignAlg;
215 KER_BYTE btHashAlg;
216 KER_BYTE ar_btModulus[KER_PK_MODULUS_LEN];
217 KER_INT16U usModulusLen;
218 KER_BYTE ar_btExp[KER_PK_EXP_LEN];
219 KER_INT16U usExpLen;
220 KER_BYTE ar_btHash[KER_PK_HASH_LEN];
221 KER_INT16U usHashLen;
222 }RSA;
223 struct
224 {
225 KER_BYTE btASI;
226 KER_BYTE ar_btPK[KER_ECC_PK_P521_LEN];
227 KER_INT16U usPKLen;
228 }ECC;
229 }Scheme;
231 }HAL_CRYPT_PK;
232
233 /* ********************************* hal_crypt_get_ca_pk *********************************** */
247 extern KER_BOOL hal_crypt_get_ca_pk(KER_CTX_PARAM KER_BYTE btKernelID, const KER_BYTE* pbtRID, KER_BYTE btRIDLen, KER_BYTE btKeyIndex, HAL_CRYPT_PK* pCA_PK);
248
249 /* ******************************* hal_crypt_msg_recovery ********************************** */
268 extern KER_BOOL hal_crypt_msg_recovery(KER_CTX_PARAM const KER_BYTE* pbtPK, KER_INT16U usPKLen, const KER_BYTE* pbtExp, KER_INT16U usExpLen, KER_BYTE btAlg,
269 const KER_BYTE* pbtMsg, KER_INT16U usMsgLen, KER_BYTE* pbtResult, KER_INT16U* pusResultLen, KER_INT16U usMaxLen);
270
271
275 typedef struct tag_HAL_CRYPT_CERT_INFO
276 {
277 KER_INT16U usSize;
278 KER_BYTE btVer;
280 const KER_BYTE* pbtCertSerial;
281 KER_INT16U usCertSerialLen;
282 }HAL_CRYPT_CERT_INFO;
283
284 /* *************************** hal_crypt_check_cert_revocation ***************************** */
298 extern KER_BOOL hal_crypt_check_cert_revocation(KER_CTX_PARAM KER_BYTE btKernelID, const KER_BYTE* pbtRID, KER_BYTE btRIDLen, KER_BYTE btKeyIndex, const HAL_CRYPT_CERT_INFO* pCert);
299
300 /* ************************* hal_crypt_check_ecc_cert_revocation *************************** */
314 extern KER_BOOL hal_crypt_check_ecc_cert_revocation(KER_CTX_PARAM KER_BYTE btKernelID, const KER_BYTE* pbtRID, KER_BYTE btRIDLen, KER_BYTE btKeyIndex, const HAL_CRYPT_CERT_INFO* pCert);
315
316 /* ******************************** hal_ecc_get_sign_len *********************************** */
325 extern KER_INT16U hal_ecc_get_sign_len(KER_CTX_PARAM KER_BYTE btASI);
326
327 /* ********************************** hal_ecc_get_pk_len *********************************** */
336 extern KER_INT16U hal_ecc_get_pk_len(KER_CTX_PARAM KER_BYTE btASI);
337
338 /* ******************************* hal_ecc_msg_sign_check ********************************** */
354 extern KER_BOOL hal_ecc_msg_sign_check(KER_CTX_PARAM KER_BYTE btASI, const KER_BYTE* pbtPK, KER_INT16U usPKLen, const KER_BYTE* pbtMsg, KER_INT16U usMsgLen, const KER_BYTE* pbtSignature, KER_INT16U usSignatureLen);
355
356 /* ********************************** hal_ecc_pk_check ************************************* */
368 extern KER_BOOL hal_ecc_pk_check(KER_CTX_PARAM KER_BYTE btASI, const KER_BYTE* pbtPK, KER_INT16U usPKLen);
369
370 /* ***************************** hal_ecc_msg_sign_check_init ******************************* */
385 extern KER_BOOL hal_ecc_msg_sign_check_init(KER_CTX_PARAM KER_BYTE btASI, const KER_BYTE* pbtPK, KER_INT16U usPKLen, const KER_BYTE* pbtSignature, KER_INT16U usSignatureLen, KER_VOID** ppCheckHandle);
386
387 /* **************************** hal_ecc_msg_sign_check_update ****************************** */
399 extern KER_BOOL hal_ecc_msg_sign_check_update(KER_CTX_PARAM KER_VOID* pCheckHandle, const KER_BYTE* pbtMsg, KER_INT16U usMsgLen);
400
401 /* ***************************** hal_ecc_msg_sign_check_complete ******************************* */
416 extern KER_BOOL hal_ecc_msg_sign_check_complete(KER_CTX_PARAM KER_VOID* pCheckHandle, KER_BYTE btASI, const KER_BYTE* pbtPK, KER_INT16U usPKLen, const KER_BYTE* pbtSignature, KER_INT16U usSignatureLen);
417
418 /* restore struct alignment */
419 #include <emv_platform_restore_align.h>
420
421 #endif /* HAL_CRYPT_H */
emv_platform_restore_align.h
emv_platform_set_align.h
KER_VOID
void KER_VOID
Definition: emv_platform.h:66
KER_BOOL
KER_INT8U KER_BOOL
Definition: emv_platform.h:67
KER_BYTE
uint8_t KER_BYTE
Definition: emv_platform.h:70
KER_INT16U
unsigned short KER_INT16U
Definition: emv_platform.h:61
KER_CTX_PARAM
#define KER_CTX_PARAM
Definition: emv_context.h:53
hal_ecc_get_sign_len
KER_INT16U hal_ecc_get_sign_len(KER_CTX_PARAM KER_BYTE btASI)
Returns ECC message signature length by ASI according to EMV Book 2, Appendix B2.4....
hal_ecc_pk_check
KER_BOOL hal_ecc_pk_check(KER_CTX_PARAM KER_BYTE btASI, const KER_BYTE *pbtPK, KER_INT16U usPKLen)
ECC pk check Recover the y-coordinate EMV Book 2, Appendix B2.2.1e.
KER_ECC_PK_P521_LEN
#define KER_ECC_PK_P521_LEN
Definition: hal_crypt.h:56
KER_PK_MODULUS_LEN
#define KER_PK_MODULUS_LEN
Definition: hal_crypt.h:52
hal_crypt_calc_hash_init
KER_BOOL hal_crypt_calc_hash_init(KER_CTX_PARAM KER_BYTE btAlg, KER_VOID *pExtra, KER_VOID **ppHashHandle)
Initiates hash calculation.
hal_crypt_calc_hash
KER_BOOL hal_crypt_calc_hash(KER_CTX_PARAM KER_BYTE btAlg, KER_VOID *pExtra, const KER_BYTE *pbtDataBuffer, KER_INT16U usDataBufferLen, KER_BYTE *pbtHash, KER_INT16U *pusHashLen, KER_INT16U usHashSize)
Calculates hash for data buffer provided.
hal_crypt_decrypt
KER_BOOL hal_crypt_decrypt(KER_CTX_PARAM KER_BYTE btAlg, const KER_BYTE *pbtKey, KER_INT16U usKeyLen, const KER_BYTE *pbtIV, KER_INT16U usIVLen, const KER_BYTE *pbtEncryptedData, KER_INT16U usEncryptedDataLen, KER_BYTE *pbtResult, KER_INT16U *pusResultLen, KER_INT16U usMaxLen)
Performs decryption.
HAL_CRYPT_PK
struct tag_HAL_CRYPT_PK HAL_CRYPT_PK
Get PK info structure.
hal_ecc_msg_sign_check_complete
KER_BOOL hal_ecc_msg_sign_check_complete(KER_CTX_PARAM KER_VOID *pCheckHandle, KER_BYTE btASI, const KER_BYTE *pbtPK, KER_INT16U usPKLen, const KER_BYTE *pbtSignature, KER_INT16U usSignatureLen)
ECC message signature check according to EMV Book 2, Appendix A2.2.3 (Completes check)
hal_crypt_msg_recovery
KER_BOOL hal_crypt_msg_recovery(KER_CTX_PARAM const KER_BYTE *pbtPK, KER_INT16U usPKLen, const KER_BYTE *pbtExp, KER_INT16U usExpLen, KER_BYTE btAlg, const KER_BYTE *pbtMsg, KER_INT16U usMsgLen, KER_BYTE *pbtResult, KER_INT16U *pusResultLen, KER_INT16U usMaxLen)
Message recovery according to EMV Book 2, Appendix A2.1.
hal_crypt_check_ecc_cert_revocation
KER_BOOL hal_crypt_check_ecc_cert_revocation(KER_CTX_PARAM KER_BYTE btKernelID, const KER_BYTE *pbtRID, KER_BYTE btRIDLen, KER_BYTE btKeyIndex, const HAL_CRYPT_CERT_INFO *pCert)
Checks ECC certificate against certificatye revocation list.
KER_PK_EXP_LEN
#define KER_PK_EXP_LEN
Definition: hal_crypt.h:53
hal_crypt_get_hash_len
KER_INT16U hal_crypt_get_hash_len(KER_CTX_PARAM KER_BYTE btAlg)
Returns HASH length by Hash ALG according to EMV Book 2, Appendix B3.
HAL_CRYPT_CERT_INFO
struct tag_HAL_CRYPT_CERT_INFO HAL_CRYPT_CERT_INFO
Check certificate revocation cert info structure.
KER_PK_HASH_LEN
#define KER_PK_HASH_LEN
Definition: hal_crypt.h:54
hal_crypt_get_ca_pk
KER_BOOL hal_crypt_get_ca_pk(KER_CTX_PARAM KER_BYTE btKernelID, const KER_BYTE *pbtRID, KER_BYTE btRIDLen, KER_BYTE btKeyIndex, HAL_CRYPT_PK *pCA_PK)
Get CA PK by index from repositoty.
hal_crypt_unpredict_num_calc
KER_BOOL hal_crypt_unpredict_num_calc(KER_CTX_PARAM KER_INT16U usUnpredNumLen, KER_BYTE *pbtUnpredNum)
Calculates unpredictable number.
hal_ecc_msg_sign_check
KER_BOOL hal_ecc_msg_sign_check(KER_CTX_PARAM KER_BYTE btASI, const KER_BYTE *pbtPK, KER_INT16U usPKLen, const KER_BYTE *pbtMsg, KER_INT16U usMsgLen, const KER_BYTE *pbtSignature, KER_INT16U usSignatureLen)
ECC message signature check according to EMV Book 2, Appendix A2.2.3.
hal_ecc_msg_sign_check_init
KER_BOOL hal_ecc_msg_sign_check_init(KER_CTX_PARAM KER_BYTE btASI, const KER_BYTE *pbtPK, KER_INT16U usPKLen, const KER_BYTE *pbtSignature, KER_INT16U usSignatureLen, KER_VOID **ppCheckHandle)
ECC message signature check according to EMV Book 2, Appendix A2.2.3 (Initiates check)
hal_crypt_check_cert_revocation
KER_BOOL hal_crypt_check_cert_revocation(KER_CTX_PARAM KER_BYTE btKernelID, const KER_BYTE *pbtRID, KER_BYTE btRIDLen, KER_BYTE btKeyIndex, const HAL_CRYPT_CERT_INFO *pCert)
Checks certificate against certificatye revocation list.
hal_ecc_msg_sign_check_update
KER_BOOL hal_ecc_msg_sign_check_update(KER_CTX_PARAM KER_VOID *pCheckHandle, const KER_BYTE *pbtMsg, KER_INT16U usMsgLen)
ECC message signature check according to EMV Book 2, Appendix A2.2.3 (Update wuth MSG data)
hal_crypt_calc_hash_update
KER_BOOL hal_crypt_calc_hash_update(KER_CTX_PARAM KER_VOID *pHashHandle, KER_BYTE btAlg, const KER_BYTE *pbtDataBuffer, KER_INT16U usDataBufferLen)
Passes data for hash calculation (can be executed several times)
hal_crypt_encrypt
KER_BOOL hal_crypt_encrypt(KER_CTX_PARAM KER_BYTE btAlg, const KER_BYTE *pbtKey, KER_INT16U usKeyLen, const KER_BYTE *pbtIV, KER_INT16U usIVLen, const KER_BYTE *pbtData, KER_INT16U usDataLen, KER_BYTE *pbtResult, KER_INT16U *pusResultLen, KER_INT16U usMaxLen)
Performs encryption.
hal_crypt_unpredict_num_set_ac
KER_BOOL hal_crypt_unpredict_num_set_ac(KER_CTX_PARAM const KER_BYTE *pbtAc, KER_INT16U usAcLen)
Updates unpredictable (random) number calculator with last AC (9F26) value (only if it was obtained f...
hal_crypt_calc_hash_complete
KER_BOOL hal_crypt_calc_hash_complete(KER_CTX_PARAM KER_VOID *pHashHandle, KER_BYTE btAlg, KER_BYTE *pbtHash, KER_INT16U *pusHashLen, KER_INT16U usHashSize)
Calculates hash on prev. provided data.
hal_ecc_get_pk_len
KER_INT16U hal_ecc_get_pk_len(KER_CTX_PARAM KER_BYTE btASI)
Returns ECC PK length by ASI according to EMV Book 2, Appendix B2.4.1.
tag_HAL_CRYPT_CERT_INFO
Check certificate revocation cert info structure.
Definition: hal_crypt.h:276
tag_HAL_CRYPT_CERT_INFO::usSize
KER_INT16U usSize
Definition: hal_crypt.h:277
tag_HAL_CRYPT_CERT_INFO::btVer
KER_BYTE btVer
Definition: hal_crypt.h:278
tag_HAL_CRYPT_CERT_INFO::pbtCertSerial
const KER_BYTE * pbtCertSerial
Definition: hal_crypt.h:280
tag_HAL_CRYPT_CERT_INFO::usCertSerialLen
KER_INT16U usCertSerialLen
Definition: hal_crypt.h:281
tag_HAL_CRYPT_PK
Get PK info structure.
Definition: hal_crypt.h:204
tag_HAL_CRYPT_PK::usHashLen
KER_INT16U usHashLen
Definition: hal_crypt.h:221
tag_HAL_CRYPT_PK::btSignAlg
KER_BYTE btSignAlg
Definition: hal_crypt.h:214
tag_HAL_CRYPT_PK::usSize
KER_INT16U usSize
Definition: hal_crypt.h:205
tag_HAL_CRYPT_PK::ECC
struct tag_HAL_CRYPT_PK::@3::@5 ECC
tag_HAL_CRYPT_PK::usExpLen
KER_INT16U usExpLen
Definition: hal_crypt.h:219
tag_HAL_CRYPT_PK::ar_btPK
KER_BYTE ar_btPK[KER_ECC_PK_P521_LEN]
Definition: hal_crypt.h:226
tag_HAL_CRYPT_PK::btHashAlg
KER_BYTE btHashAlg
Definition: hal_crypt.h:215
tag_HAL_CRYPT_PK::btVer
KER_BYTE btVer
Definition: hal_crypt.h:206
tag_HAL_CRYPT_PK::btScheme
KER_BYTE btScheme
Definition: hal_crypt.h:208
tag_HAL_CRYPT_PK::ar_btHash
KER_BYTE ar_btHash[KER_PK_HASH_LEN]
Definition: hal_crypt.h:220
tag_HAL_CRYPT_PK::ar_btExp
KER_BYTE ar_btExp[KER_PK_EXP_LEN]
Definition: hal_crypt.h:218
tag_HAL_CRYPT_PK::ar_btModulus
KER_BYTE ar_btModulus[KER_PK_MODULUS_LEN]
Definition: hal_crypt.h:216
tag_HAL_CRYPT_PK::btASI
KER_BYTE btASI
Definition: hal_crypt.h:225
tag_HAL_CRYPT_PK::Scheme
union tag_HAL_CRYPT_PK::@3 Scheme
tag_HAL_CRYPT_PK::usModulusLen
KER_INT16U usModulusLen
Definition: hal_crypt.h:217
tag_HAL_CRYPT_PK::usPKLen
KER_INT16U usPKLen
Definition: hal_crypt.h:227
tag_HAL_CRYPT_PK::RSA
struct tag_HAL_CRYPT_PK::@3::@4 RSA