API参考
载入中...
搜索中...
未找到
crypt_sm2.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
16#ifndef CRYPT_SM2_H
17#define CRYPT_SM2_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_SM2
21
22#include <stdint.h>
23#include "crypt_types.h"
24#include "crypt_ecc.h"
25#include "bsl_params.h"
26#include "crypt_params_key.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif /* __cpluscplus */
31
32typedef struct SM2_Ctx CRYPT_SM2_Ctx;
33/* SM2 parameter structure */
34typedef struct EccPara CRYPT_Sm2Para;
35
43CRYPT_SM2_Ctx *CRYPT_SM2_NewCtx(void);
44
54CRYPT_SM2_Ctx *CRYPT_SM2_NewCtxEx(void *libCtx);
55
64CRYPT_SM2_Ctx *CRYPT_SM2_DupCtx(CRYPT_SM2_Ctx *ctx);
65
72void CRYPT_SM2_FreeCtx(CRYPT_SM2_Ctx *ctx);
73
83uint32_t CRYPT_SM2_GetBits(const CRYPT_SM2_Ctx *ctx);
84
96int32_t CRYPT_SM2_Gen(CRYPT_SM2_Ctx *ctx);
97
98#ifdef HITLS_CRYPTO_SM2_SIGN
108uint32_t CRYPT_SM2_GetSignLen(const CRYPT_SM2_Ctx *ctx);
109
131int32_t CRYPT_SM2_Sign(const CRYPT_SM2_Ctx *ctx, int32_t algId, const uint8_t *data, uint32_t dataLen,
132 uint8_t *sign, uint32_t *signLen);
133
154int32_t CRYPT_SM2_SignData(const CRYPT_SM2_Ctx *ctx, const uint8_t *data, uint32_t dataLen,
155 uint8_t *sign, uint32_t *signLen);
156
176int32_t CRYPT_SM2_Verify(const CRYPT_SM2_Ctx *ctx, int32_t algId, const uint8_t *data, uint32_t dataLen,
177 const uint8_t *sign, uint32_t signLen);
178
197int32_t CRYPT_SM2_VerifyData(const CRYPT_SM2_Ctx *ctx, const uint8_t *data, uint32_t dataLen,
198 const uint8_t *sign, uint32_t signLen);
199#endif
200
213int32_t CRYPT_SM2_SetPrvKey(CRYPT_SM2_Ctx *ctx, const CRYPT_Sm2Prv *prv);
214
227int32_t CRYPT_SM2_SetPubKey(CRYPT_SM2_Ctx *ctx, const CRYPT_Sm2Pub *pub);
228
241int32_t CRYPT_SM2_GetPrvKey(const CRYPT_SM2_Ctx *ctx, CRYPT_Sm2Prv *prv);
242
255int32_t CRYPT_SM2_GetPubKey(const CRYPT_SM2_Ctx *ctx, CRYPT_Sm2Pub *pub);
256
257#ifdef HITLS_BSL_PARAMS
270int32_t CRYPT_SM2_SetPrvKeyEx(CRYPT_SM2_Ctx *ctx, const BSL_Param *para);
271
284int32_t CRYPT_SM2_SetPubKeyEx(CRYPT_SM2_Ctx *ctx, const BSL_Param *para);
285
298int32_t CRYPT_SM2_GetPrvKeyEx(const CRYPT_SM2_Ctx *ctx, BSL_Param *para);
299
312int32_t CRYPT_SM2_GetPubKeyEx(const CRYPT_SM2_Ctx *ctx, BSL_Param *para);
313#endif
314
328int32_t CRYPT_SM2_Ctrl(CRYPT_SM2_Ctx *ctx, int32_t opt, void *val, uint32_t len);
329
330#ifdef HITLS_CRYPTO_SM2_EXCH
344int32_t CRYPT_SM2_KapComputeKey(const CRYPT_SM2_Ctx *selfCtx, const CRYPT_SM2_Ctx *peerCtx, uint8_t *out,
345 uint32_t *outlen);
346#endif
347
348#ifdef HITLS_CRYPTO_SM2_CRYPT
362int32_t CRYPT_SM2_Encrypt(CRYPT_SM2_Ctx *ctx, const uint8_t *data, uint32_t datalen, uint8_t *out, uint32_t *outlen);
363
377int32_t CRYPT_SM2_Decrypt(CRYPT_SM2_Ctx *ctx, const uint8_t *data, uint32_t datalen, uint8_t *out, uint32_t *outlen);
378#endif
379
380#ifdef HITLS_CRYPTO_SM2_CMP
391int32_t CRYPT_SM2_Cmp(const CRYPT_SM2_Ctx *a, const CRYPT_SM2_Ctx *b);
392#else
393#define CRYPT_SM2_Cmp NULL
394#endif
395
404int32_t CRYPT_SM2_GetSecBits(const CRYPT_SM2_Ctx *ctx);
405
406#ifdef HITLS_CRYPTO_KEY_DECODE_CHAIN
414int32_t CRYPT_SM2_Import(CRYPT_SM2_Ctx *ctx, const BSL_Param *params);
415
423int32_t CRYPT_SM2_Export(const CRYPT_SM2_Ctx *ctx, BSL_Param *params);
424#endif
425
426#ifdef HITLS_CRYPTO_SM2_CHECK
438int32_t CRYPT_SM2_Check(uint32_t checkType, const CRYPT_SM2_Ctx *pkey1, const CRYPT_SM2_Ctx *pkey2);
439
440#endif // HITLS_CRYPTO_SM2_CHECK
441
442#ifdef __cplusplus
443}
444#endif
445
446#endif // HITLS_CRYPTO_SM2
447
448#endif // CRYPT_SM2_H
Parameter identifiers
CRYPT_Data CRYPT_Sm2Prv
定义 crypt_types.h:289
CRYPT_Data CRYPT_Sm2Pub
定义 crypt_types.h:428