API参考
载入中...
搜索中...
未找到
hitls_crypt_reg.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
21
22#ifndef HITLS_CRYPT_REG_H
23#define HITLS_CRYPT_REG_H
24
25#include <stdint.h>
26#include "hitls_type.h"
27#include "hitls_crypt_type.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36typedef struct {
37 HITLS_NamedGroup groupId;
38 uint8_t *peerPubkey;
39 uint32_t pubKeyLen;
40 uint8_t *ciphertext;
41 uint32_t *ciphertextLen;
42 uint8_t *sharedSecret;
43 uint32_t *sharedSecretLen;
45
55typedef int32_t (*CRYPT_RandBytesCallback)(uint8_t *buf, uint32_t len);
56
66typedef HITLS_CRYPT_Key *(*CRYPT_GenerateEcdhKeyPairCallback)(HITLS_Ctx *ctx, const HITLS_ECParameters *curveParams);
67
74typedef void (*CRYPT_FreeEcdhKeyCallback)(HITLS_CRYPT_Key *key);
75
87typedef int32_t (*CRYPT_GetEcdhEncodedPubKeyCallback)(HITLS_CRYPT_Key *key, uint8_t *pubKeyBuf, uint32_t bufLen,
88 uint32_t *pubKeyLen);
89
103typedef int32_t (*CRYPT_CalcEcdhSharedSecretCallback)(HITLS_CRYPT_Key *key, uint8_t *peerPubkey, uint32_t pubKeyLen,
104 uint8_t *sharedSecret, uint32_t *sharedSecretLen);
105
127typedef int32_t (*CRYPT_KemDecapsulateCallback)(HITLS_CRYPT_Key *key, const uint8_t *ciphertext, uint32_t ciphertextLen,
128 uint8_t *sharedSecret, uint32_t *sharedSecretLen);
129
141 uint8_t *sharedSecret, uint32_t *sharedSecretLen);
142
151typedef HITLS_CRYPT_Key *(*CRYPT_GenerateDhKeyBySecbitsCallback)(int32_t secbits);
152
164typedef HITLS_CRYPT_Key *(*CRYPT_GenerateDhKeyByParamsCallback)(uint8_t *p, uint16_t plen, uint8_t *g, uint16_t glen);
165
173typedef HITLS_CRYPT_Key *(*CRYPT_DupDhKeyCallback)(HITLS_CRYPT_Key *key);
174
181typedef void (*CRYPT_FreeDhKeyCallback)(HITLS_CRYPT_Key *key);
182
197typedef int32_t (*CRYPT_DHGetParametersCallback)(HITLS_CRYPT_Key *key, uint8_t *p, uint16_t *plen,
198 uint8_t *g, uint16_t *glen);
199
211typedef int32_t (*CRYPT_GetDhEncodedPubKeyCallback)(HITLS_CRYPT_Key *key, uint8_t *pubKeyBuf, uint32_t bufLen,
212 uint32_t *pubKeyLen);
213
227typedef int32_t (*CRYPT_CalcDhSharedSecretCallback)(HITLS_CRYPT_Key *key, uint8_t *peerPubkey, uint32_t pubKeyLen,
228 uint8_t *sharedSecret, uint32_t *sharedSecretLen);
229
238typedef uint32_t (*CRYPT_HmacSizeCallback)(HITLS_HashAlgo hashAlgo);
239
250typedef HITLS_HMAC_Ctx *(*CRYPT_HmacInitCallback)(HITLS_HashAlgo hashAlgo, const uint8_t *key, uint32_t len);
251
260typedef int32_t (*CRYPT_HmacReInitCallback)(HITLS_HMAC_Ctx *ctx);
261
268typedef void (*CRYPT_HmacFreeCallback)(HITLS_HMAC_Ctx *ctx);
269
280typedef int32_t (*CRYPT_HmacUpdateCallback)(HITLS_HMAC_Ctx *ctx, const uint8_t *data, uint32_t len);
281
292typedef int32_t (*CRYPT_HmacFinalCallback)(HITLS_HMAC_Ctx *ctx, uint8_t *out, uint32_t *len);
293
308typedef int32_t (*CRYPT_HmacCallback)(HITLS_HashAlgo hashAlgo, const uint8_t *key, uint32_t keyLen,
309 const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
310
319typedef uint32_t (*CRYPT_DigestSizeCallback)(HITLS_HashAlgo hashAlgo);
320
329typedef HITLS_HASH_Ctx *(*CRYPT_DigestInitCallback)(HITLS_HashAlgo hashAlgo);
330
339typedef HITLS_HASH_Ctx *(*CRYPT_DigestCopyCallback)(HITLS_HASH_Ctx *ctx);
340
347typedef void (*CRYPT_DigestFreeCallback)(HITLS_HASH_Ctx *ctx);
348
359typedef int32_t (*CRYPT_DigestUpdateCallback)(HITLS_HASH_Ctx *ctx, const uint8_t *data, uint32_t len);
360
371typedef int32_t (*CRYPT_DigestFinalCallback)(HITLS_HASH_Ctx *ctx, uint8_t *out, uint32_t *len);
372
385typedef int32_t (*CRYPT_DigestCallback)(HITLS_HashAlgo hashAlgo, const uint8_t *in, uint32_t inLen,
386 uint8_t *out, uint32_t *outLen);
387
406typedef int32_t (*CRYPT_EncryptCallback)(const HITLS_CipherParameters *cipher, const uint8_t *in, uint32_t inLen,
407 uint8_t *out, uint32_t *outLen);
408
423typedef int32_t (*CRYPT_DecryptCallback)(const HITLS_CipherParameters *cipher, const uint8_t *in, uint32_t inLen,
424 uint8_t *out, uint32_t *outLen);
425
432typedef void (*CRYPT_CipherFreeCallback)(HITLS_Cipher_Ctx *ctx);
443typedef int32_t (*CRYPT_HkdfExtractCallback)(const HITLS_CRYPT_HkdfExtractInput *input, uint8_t *prk, uint32_t *prkLen);
444
455typedef int32_t (*CRYPT_HkdfExpandCallback)(
456 const HITLS_CRYPT_HkdfExpandInput *input, uint8_t *outputKeyMaterial, uint32_t outputKeyMaterialLen);
457
485
501
518
523typedef struct {
524 CRYPT_HkdfExtractCallback hkdfExtract;
525 CRYPT_HkdfExpandCallback hkdfExpand;
527
538
549
559int32_t HITLS_CRYPT_RegisterDhMethod(const HITLS_CRYPT_DhMethod *userCryptCallBack);
560
571
572#ifdef __cplusplus
573}
574#endif
575#endif
int32_t(* CRYPT_CalcEcdhSharedSecretCallback)(HITLS_CRYPT_Key *key, uint8_t *peerPubkey, uint32_t pubKeyLen, uint8_t *sharedSecret, uint32_t *sharedSecretLen)
ECDH: Calculate the shared key based on the local key and peer public key. Ref RFC 8446 section 7....
定义 hitls_crypt_reg.h:103
int32_t(* CRYPT_HmacCallback)(HITLS_HashAlgo hashAlgo, const uint8_t *key, uint32_t keyLen, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen)
Function for calculating the HMAC for a single time
定义 hitls_crypt_reg.h:308
int32_t HITLS_CRYPT_RegisterDhMethod(const HITLS_CRYPT_DhMethod *userCryptCallBack)
Register the callback function of the DH.
定义 crypt.c:183
HITLS_CRYPT_Key *(* CRYPT_GenerateDhKeyBySecbitsCallback)(int32_t secbits)
Generate a key pair based on secbits.
定义 hitls_crypt_reg.h:151
void(* CRYPT_HmacFreeCallback)(HITLS_HMAC_Ctx *ctx)
Release the HMAC context.
定义 hitls_crypt_reg.h:268
HITLS_HMAC_Ctx *(* CRYPT_HmacInitCallback)(HITLS_HashAlgo hashAlgo, const uint8_t *key, uint32_t len)
Initialize the HMAC context.
定义 hitls_crypt_reg.h:250
int32_t(* CRYPT_DHGetParametersCallback)(HITLS_CRYPT_Key *key, uint8_t *p, uint16_t *plen, uint8_t *g, uint16_t *glen)
DH: Obtain p g plen glen by using the key handle.
定义 hitls_crypt_reg.h:197
void(* CRYPT_FreeDhKeyCallback)(HITLS_CRYPT_Key *key)
Release the key.
定义 hitls_crypt_reg.h:181
void(* CRYPT_CipherFreeCallback)(HITLS_Cipher_Ctx *ctx)
Release the cipher ctx.
定义 hitls_crypt_reg.h:432
int32_t(* CRYPT_HmacFinalCallback)(HITLS_HMAC_Ctx *ctx, uint8_t *out, uint32_t *len)
Output the HMAC result.
定义 hitls_crypt_reg.h:292
int32_t(* CRYPT_KemDecapsulateCallback)(HITLS_CRYPT_Key *key, const uint8_t *ciphertext, uint32_t ciphertextLen, uint8_t *sharedSecret, uint32_t *sharedSecretLen)
KEM: Decapsulate the ciphertext to recover shared secret.
定义 hitls_crypt_reg.h:127
void(* CRYPT_DigestFreeCallback)(HITLS_HASH_Ctx *ctx)
Release the hash context.
定义 hitls_crypt_reg.h:347
int32_t HITLS_CRYPT_RegisterHkdfMethod(HITLS_CRYPT_KdfMethod *userCryptCallBack)
Register the callback function of the HKDF.
int32_t(* CRYPT_CalcDhSharedSecretCallback)(HITLS_CRYPT_Key *key, uint8_t *peerPubkey, uint32_t pubKeyLen, uint8_t *sharedSecret, uint32_t *sharedSecretLen)
DH: Calculate the shared key based on the local key and peer public key. Ref RFC 5246 section 5....
定义 hitls_crypt_reg.h:227
int32_t(* CRYPT_GetEcdhEncodedPubKeyCallback)(HITLS_CRYPT_Key *key, uint8_t *pubKeyBuf, uint32_t bufLen, uint32_t *pubKeyLen)
ECDH: Extract the public key data.
定义 hitls_crypt_reg.h:87
int32_t(* CRYPT_HmacUpdateCallback)(HITLS_HMAC_Ctx *ctx, const uint8_t *data, uint32_t len)
Add the HMAC input data.
定义 hitls_crypt_reg.h:280
HITLS_CRYPT_Key *(* CRYPT_GenerateDhKeyByParamsCallback)(uint8_t *p, uint16_t plen, uint8_t *g, uint16_t glen)
DH: Generate a key pair based on the dh parameter.
定义 hitls_crypt_reg.h:164
void(* CRYPT_FreeEcdhKeyCallback)(HITLS_CRYPT_Key *key)
Release the key.
定义 hitls_crypt_reg.h:74
int32_t(* CRYPT_DigestCallback)(HITLS_HashAlgo hashAlgo, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen)
Hash function
定义 hitls_crypt_reg.h:385
int32_t(* CRYPT_GetDhEncodedPubKeyCallback)(HITLS_CRYPT_Key *key, uint8_t *pubKeyBuf, uint32_t bufLen, uint32_t *pubKeyLen)
DH: Extract the Dh public key data.
定义 hitls_crypt_reg.h:211
int32_t(* CRYPT_HmacReInitCallback)(HITLS_HMAC_Ctx *ctx)
reinit the HMAC context.
定义 hitls_crypt_reg.h:260
int32_t(* CRYPT_HkdfExpandCallback)(const HITLS_CRYPT_HkdfExpandInput *input, uint8_t *outputKeyMaterial, uint32_t outputKeyMaterialLen)
HKDF-Expand
定义 hitls_crypt_reg.h:455
HITLS_CRYPT_Key *(* CRYPT_DupDhKeyCallback)(HITLS_CRYPT_Key *key)
Deep copy key
定义 hitls_crypt_reg.h:173
int32_t HITLS_CRYPT_RegisterBaseMethod(HITLS_CRYPT_BaseMethod *userCryptCallBack)
Register the basic callback function.
定义 crypt.c:97
int32_t(* CRYPT_DigestFinalCallback)(HITLS_HASH_Ctx *ctx, uint8_t *out, uint32_t *len)
Output the hash result.
定义 hitls_crypt_reg.h:371
uint32_t(* CRYPT_DigestSizeCallback)(HITLS_HashAlgo hashAlgo)
Obtain the hash length.
定义 hitls_crypt_reg.h:319
int32_t(* CRYPT_RandBytesCallback)(uint8_t *buf, uint32_t len)
Obtain the random number.
定义 hitls_crypt_reg.h:55
int32_t(* CRYPT_HkdfExtractCallback)(const HITLS_CRYPT_HkdfExtractInput *input, uint8_t *prk, uint32_t *prkLen)
HKDF-Extract
定义 hitls_crypt_reg.h:443
int32_t(* CRYPT_DigestUpdateCallback)(HITLS_HASH_Ctx *ctx, const uint8_t *data, uint32_t len)
Hash Add input data.
定义 hitls_crypt_reg.h:359
HITLS_HASH_Ctx *(* CRYPT_DigestCopyCallback)(HITLS_HASH_Ctx *ctx)
Copy the hash context.
定义 hitls_crypt_reg.h:339
int32_t(* CRYPT_DecryptCallback)(const HITLS_CipherParameters *cipher, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen)
TLS decryption
定义 hitls_crypt_reg.h:423
int32_t(* CRYPT_EncryptCallback)(const HITLS_CipherParameters *cipher, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen)
TLS encryption
定义 hitls_crypt_reg.h:406
HITLS_HASH_Ctx *(* CRYPT_DigestInitCallback)(HITLS_HashAlgo hashAlgo)
Initialize the hash context.
定义 hitls_crypt_reg.h:329
int32_t(* CRYPT_Sm2CalcEcdhSharedSecretCallback)(HITLS_Sm2GenShareKeyParameters *sm2Params, uint8_t *sharedSecret, uint32_t *sharedSecretLen)
SM2 calculates the shared key based on the local key and peer public key.
定义 hitls_crypt_reg.h:140
uint32_t(* CRYPT_HmacSizeCallback)(HITLS_HashAlgo hashAlgo)
Obtain the HMAC length based on the hash algorithm.
定义 hitls_crypt_reg.h:238
HITLS_CRYPT_Key *(* CRYPT_GenerateEcdhKeyPairCallback)(HITLS_Ctx *ctx, const HITLS_ECParameters *curveParams)
ECDH: Generate a key pair based on elliptic curve parameters.
定义 hitls_crypt_reg.h:66
int32_t(* CRYPT_KemEncapsulateCallback)(HITLS_KemEncapsulateParams *params)
KEM: Encapsulate a shared secret using peer's public key.
定义 hitls_crypt_reg.h:114
int32_t HITLS_CRYPT_RegisterEcdhMethod(HITLS_CRYPT_EcdhMethod *userCryptCallBack)
Register the ECDH callback function.
定义 crypt.c:163
struct TlsCtx HITLS_Ctx
HITLS context
定义 hitls_type.h:35
Callback function that must be registered
定义 hitls_crypt_reg.h:462
CRYPT_HmacFreeCallback hmacFree
定义 hitls_crypt_reg.h:468
CRYPT_DigestCallback digest
定义 hitls_crypt_reg.h:478
CRYPT_DigestInitCallback digestInit
定义 hitls_crypt_reg.h:473
CRYPT_DigestFreeCallback digestFree
定义 hitls_crypt_reg.h:475
CRYPT_CipherFreeCallback cipherFree
定义 hitls_crypt_reg.h:483
CRYPT_HmacSizeCallback hmacSize
定义 hitls_crypt_reg.h:464
CRYPT_DigestCopyCallback digestCopy
定义 hitls_crypt_reg.h:474
CRYPT_HmacUpdateCallback hmacUpdate
定义 hitls_crypt_reg.h:469
CRYPT_DigestUpdateCallback digestUpdate
定义 hitls_crypt_reg.h:476
CRYPT_HmacFinalCallback hmacFinal
定义 hitls_crypt_reg.h:470
CRYPT_RandBytesCallback randBytes
定义 hitls_crypt_reg.h:463
CRYPT_HmacCallback hmac
定义 hitls_crypt_reg.h:471
CRYPT_EncryptCallback encrypt
定义 hitls_crypt_reg.h:479
CRYPT_HmacReInitCallback hmacReinit
定义 hitls_crypt_reg.h:467
CRYPT_DecryptCallback decrypt
定义 hitls_crypt_reg.h:481
CRYPT_DigestSizeCallback digestSize
定义 hitls_crypt_reg.h:472
CRYPT_HmacInitCallback hmacInit
定义 hitls_crypt_reg.h:466
CRYPT_DigestFinalCallback digestFinal
定义 hitls_crypt_reg.h:477
DH Callback function to be registered
定义 hitls_crypt_reg.h:506
CRYPT_DHGetParametersCallback getDhParameters
定义 hitls_crypt_reg.h:512
CRYPT_GenerateDhKeyBySecbitsCallback generateDhKeyBySecbits
定义 hitls_crypt_reg.h:507
CRYPT_CalcDhSharedSecretCallback calcDhSharedSecret
定义 hitls_crypt_reg.h:515
CRYPT_DupDhKeyCallback dupDhKey
定义 hitls_crypt_reg.h:510
CRYPT_FreeDhKeyCallback freeDhKey
定义 hitls_crypt_reg.h:511
CRYPT_GetDhEncodedPubKeyCallback getDhPubKey
定义 hitls_crypt_reg.h:514
CRYPT_GenerateDhKeyByParamsCallback generateDhKeyByParams
定义 hitls_crypt_reg.h:508
ECDH Callback function to be registered
定义 hitls_crypt_reg.h:490
CRYPT_GenerateEcdhKeyPairCallback generateEcdhKeyPair
定义 hitls_crypt_reg.h:491
CRYPT_KemDecapsulateCallback kemDecapsulate
定义 hitls_crypt_reg.h:499
CRYPT_GetEcdhEncodedPubKeyCallback getEcdhPubKey
定义 hitls_crypt_reg.h:494
CRYPT_FreeEcdhKeyCallback freeEcdhKey
定义 hitls_crypt_reg.h:493
CRYPT_CalcEcdhSharedSecretCallback calcEcdhSharedSecret
定义 hitls_crypt_reg.h:495
CRYPT_KemEncapsulateCallback kemEncapsulate
定义 hitls_crypt_reg.h:498
HKDF-Expand Input
定义 hitls_crypt_type.h:281
HKDF-Extract Input
定义 hitls_crypt_type.h:269
KDF function
定义 hitls_crypt_reg.h:523
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
uint32_t * ciphertextLen
定义 hitls_crypt_reg.h:41
HITLS_NamedGroup groupId
定义 hitls_crypt_reg.h:37
uint8_t * ciphertext
定义 hitls_crypt_reg.h:40
uint32_t pubKeyLen
定义 hitls_crypt_reg.h:39
uint32_t * sharedSecretLen
定义 hitls_crypt_reg.h:43
uint8_t * peerPubkey
定义 hitls_crypt_reg.h:38
uint8_t * sharedSecret
定义 hitls_crypt_reg.h:42
sm2 ecdhe negotiation key parameters
定义 hitls_crypt_type.h:254