20#include "hitls_crypt_type.h"
22#include "hitls_crypt_reg.h"
29#define MAX_SIGN_SIZE 1024
33 HITLS_HashAlgo hashAlgo;
34 const uint8_t *secret;
40 HITLS_Lib_Ctx *libCtx;
44enum HITLS_CryptoCallBack {
45 HITLS_CRYPT_CALLBACK_RAND_BYTES = 0,
46 HITLS_CRYPT_CALLBACK_HMAC_SIZE,
47 HITLS_CRYPT_CALLBACK_HMAC_INIT,
48 HITLS_CRYPT_CALLBACK_HMAC_FREE,
49 HITLS_CRYPT_CALLBACK_HMAC_UPDATE,
50 HITLS_CRYPT_CALLBACK_HMAC_FINAL,
51 HITLS_CRYPT_CALLBACK_HMAC,
52 HITLS_CRYPT_CALLBACK_DIGEST_SIZE,
53 HITLS_CRYPT_CALLBACK_DIGEST_INIT,
54 HITLS_CRYPT_CALLBACK_DIGEST_COPY,
55 HITLS_CRYPT_CALLBACK_DIGEST_FREE,
56 HITLS_CRYPT_CALLBACK_DIGEST_UPDATE,
57 HITLS_CRYPT_CALLBACK_DIGEST_FINAL,
58 HITLS_CRYPT_CALLBACK_DIGEST,
59 HITLS_CRYPT_CALLBACK_ENCRYPT,
60 HITLS_CRYPT_CALLBACK_DECRYPT,
62 HITLS_CRYPT_CALLBACK_GENERATE_ECDH_KEY_PAIR,
63 HITLS_CRYPT_CALLBACK_FREE_ECDH_KEY,
64 HITLS_CRYPT_CALLBACK_GET_ECDH_ENCODED_PUBKEY,
65 HITLS_CRYPT_CALLBACK_CALC_ECDH_SHARED_SECRET,
66 HITLS_CRYPT_CALLBACK_SM2_CALC_ECDH_SHARED_SECRET,
68 HITLS_CRYPT_CALLBACK_GENERATE_DH_KEY_BY_SECBITS,
69 HITLS_CRYPT_CALLBACK_GENERATE_DH_KEY_BY_PARAMS,
70 HITLS_CRYPT_CALLBACK_DUP_DH_KEY,
71 HITLS_CRYPT_CALLBACK_FREE_DH_KEY,
72 HITLS_CRYPT_CALLBACK_DH_GET_PARAMETERS,
73 HITLS_CRYPT_CALLBACK_GET_DH_ENCODED_PUBKEY,
74 HITLS_CRYPT_CALLBACK_CALC_DH_SHARED_SECRET,
76 HITLS_CRYPT_CALLBACK_HKDF_EXTRACT,
77 HITLS_CRYPT_CALLBACK_HKDF_EXPAND,
78 HITLS_CRYPT_CALLBACK_KEM_ENCAPSULATE,
79 HITLS_CRYPT_CALLBACK_KEM_DECAPSULATE,
93int32_t SAL_CRYPT_Rand(HITLS_Lib_Ctx *libCtx, uint8_t *buf, uint32_t len);
102uint32_t SAL_CRYPT_HmacSize(HITLS_HashAlgo hashAlgo);
122HITLS_HMAC_Ctx *SAL_CRYPT_HmacInit(HITLS_Lib_Ctx *libCtx,
const char *attrName,
123 HITLS_HashAlgo hashAlgo,
const uint8_t *key, uint32_t len);
132int32_t SAL_CRYPT_HmacReInit(HITLS_HMAC_Ctx *ctx);
139void SAL_CRYPT_HmacFree(HITLS_HMAC_Ctx *hmac);
152int32_t SAL_CRYPT_HmacUpdate(HITLS_HMAC_Ctx *hmac,
const uint8_t *data, uint32_t len);
165int32_t SAL_CRYPT_HmacFinal(HITLS_HMAC_Ctx *hmac, uint8_t *out, uint32_t *len);
188int32_t SAL_CRYPT_Hmac(HITLS_Lib_Ctx *libCtx,
const char *attrName,
189 HITLS_HashAlgo hashAlgo,
const uint8_t *key, uint32_t keyLen,
190 const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
213uint32_t SAL_CRYPT_DigestSize(HITLS_HashAlgo hashAlgo);
232HITLS_HASH_Ctx *SAL_CRYPT_DigestInit(HITLS_Lib_Ctx *libCtx,
const char *attrName, HITLS_HashAlgo hashAlgo);
241HITLS_HASH_Ctx *SAL_CRYPT_DigestCopy(HITLS_HASH_Ctx *ctx);
248void SAL_CRYPT_DigestFree(HITLS_HASH_Ctx *ctx);
261int32_t SAL_CRYPT_DigestUpdate(HITLS_HASH_Ctx *ctx,
const uint8_t *data, uint32_t len);
274int32_t SAL_CRYPT_DigestFinal(HITLS_HASH_Ctx *ctx, uint8_t *out, uint32_t *len);
303int32_t SAL_CRYPT_Digest(HITLS_Lib_Ctx *libCtx,
const char *attrName,
304 HITLS_HashAlgo hashAlgo,
const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
322int32_t SAL_CRYPT_Encrypt(HITLS_Lib_Ctx *libCtx,
const char *attrName,
324 uint8_t *out, uint32_t *outLen);
342int32_t SAL_CRYPT_Decrypt(HITLS_Lib_Ctx *libCtx,
const char *attrName,
344 uint8_t *out, uint32_t *outLen);
351void SAL_CRYPT_CipherFree(HITLS_Cipher_Ctx *ctx);
360HITLS_CRYPT_Key *SAL_CRYPT_GenEcdhKeyPair(TLS_Ctx *ctx,
const HITLS_ECParameters *curveParams);
367void SAL_CRYPT_FreeEcdhKey(HITLS_CRYPT_Key *key);
381int32_t SAL_CRYPT_EncodeEcdhPubKey(HITLS_CRYPT_Key *key, uint8_t *pubKeyBuf, uint32_t bufLen, uint32_t *usedLen);
399int32_t SAL_CRYPT_CalcEcdhSharedSecret(HITLS_Lib_Ctx *libCtx,
const char *attrName,
400 HITLS_CRYPT_Key *key, uint8_t *peerPubkey, uint32_t pubKeyLen,
401 uint8_t *sharedSecret, uint32_t *sharedSecretLen);
417int32_t SAL_CRYPT_CalcSm2dhSharedSecret(HITLS_Lib_Ctx *libCtx,
const char *attrName,
419 uint32_t *sharedSecretLen);
429HITLS_CRYPT_Key *SAL_CRYPT_GenerateDhKeyBySecbits(TLS_Ctx *ctx,
445HITLS_CRYPT_Key *SAL_CRYPT_GenerateDhKeyByParams(HITLS_Lib_Ctx *libCtx,
446 const char *attrName, uint8_t *p, uint16_t plen, uint8_t *g, uint16_t glen);
455HITLS_CRYPT_Key *SAL_CRYPT_DupDhKey(HITLS_CRYPT_Key *key);
462void SAL_CRYPT_FreeDhKey(HITLS_CRYPT_Key *key);
475int32_t SAL_CRYPT_GetDhParameters(HITLS_CRYPT_Key *key, uint8_t *p, uint16_t *plen,
476 uint8_t *g, uint16_t *glen);
490int32_t SAL_CRYPT_EncodeDhPubKey(HITLS_CRYPT_Key *key, uint8_t *pubKeyBuf, uint32_t bufLen, uint32_t *usedLen);
508int32_t SAL_CRYPT_CalcDhSharedSecret(HITLS_Lib_Ctx *libCtx,
const char *attrName,
509 HITLS_CRYPT_Key *key, uint8_t *peerPubkey, uint32_t pubKeyLen,
510 uint8_t *sharedSecret, uint32_t *sharedSecretLen);
526int32_t SAL_CRYPT_HkdfExtract(HITLS_Lib_Ctx *libCtx,
const char *attrName,
543int32_t SAL_CRYPT_HkdfExpand(HITLS_Lib_Ctx *libCtx,
const char *attrName,
559 uint8_t *outSecret, uint32_t outLen);
584int32_t SAL_CRYPT_KemDecapsulate(HITLS_CRYPT_Key *key,
const uint8_t *ciphertext, uint32_t ciphertextLen,
585 uint8_t *sharedSecret, uint32_t *sharedSecretLen);
Key parameters
定义 hitls_crypt_type.h:235
Elliptic curve parameter
定义 hitls_crypt_type.h:222
Input parameters for KEM encapsulation
定义 hitls_crypt_reg.h:36
sm2 ecdhe negotiation key parameters
定义 hitls_crypt_type.h:254