API参考
载入中...
搜索中...
未找到
crypt_sm9.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_SM9_H__
17#define __CRYPT_SM9_H__
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_SM9
21
22#include "sm9.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
34struct SM9_Ctx_st {
35 uint8_t sig_msk[SM9_SIG_SYS_PRIKEY_BYTES];
36 uint8_t sig_mpk[SM9_SIG_SYS_PUBKEY_BYTES];
37 uint8_t sig_dsk[SM9_SIG_USR_PRIKEY_BYTES];
38 uint8_t sig_g[12 * SM9_CURVE_MODULE_BYTES];
39
40 uint8_t enc_msk[SM9_ENC_SYS_PRIKEY_BYTES];
41 uint8_t enc_mpk[SM9_ENC_SYS_PUBKEY_BYTES];
42 uint8_t enc_dek[SM9_ENC_USR_PRIKEY_BYTES];
43 uint8_t enc_g[12 * SM9_CURVE_MODULE_BYTES];
44
45 uint8_t user_id[256];
46 uint32_t user_id_len;
47
48 uint8_t keyex_r[SM9_CURVE_MODULE_BYTES];
49 uint8_t keyex_R[SM9_KEYEX_RA_BYTES];
50
51 uint32_t has_sig_sys : 1;
52 uint32_t has_sig_usr : 1;
53 uint32_t has_sig_g : 1;
54 uint32_t has_enc_sys : 1;
55 uint32_t has_enc_usr : 1;
56 uint32_t has_enc_g : 1;
57};
58
59typedef struct SM9_Ctx_st SM9_Ctx;
60
61void SM9_ResetCtx(SM9_Ctx *ctx);
62SM9_Ctx* SM9_NewCtx(void);
63void SM9_FreeCtx(SM9_Ctx *ctx);
64
65int32_t SM9_SetSignMasterKey(SM9_Ctx *ctx, uint8_t *msk);
66int32_t SM9_GenSignUserKey(SM9_Ctx *ctx, const uint8_t *user_id, uint32_t id_len);
67int32_t SM9_SetSignUserKey(SM9_Ctx *ctx, uint8_t *user_id, uint32_t id_len, uint8_t *dsk);
68
69int32_t SM9_SignCtx(const SM9_Ctx *ctx, const uint8_t *msg, uint32_t mlen, uint8_t *rand, uint8_t *sign);
70int32_t SM9_VerifyCtx(const SM9_Ctx *ctx, const uint8_t *user_id, uint32_t id_len,
71 const uint8_t *msg, uint32_t mlen, const uint8_t *sign);
72
73int32_t SM9_SetEncMasterKey(SM9_Ctx *ctx, uint8_t *msk);
74int32_t SM9_GenEncUserKey(SM9_Ctx *ctx, const uint8_t *user_id, uint32_t id_len);
75int32_t SM9_SetEncUserKey(SM9_Ctx *ctx, uint8_t *user_id, uint32_t id_len, uint8_t *dek);
76
77int32_t SM9_EncryptCtx(const SM9_Ctx *ctx, const uint8_t *user_id, uint32_t id_len,
78 const uint8_t *msg, uint32_t mlen, uint8_t *rand, uint8_t *cipher, uint32_t *clen);
79int32_t SM9_DecryptCtx(const SM9_Ctx *ctx, const uint8_t *cipher, uint32_t clen, uint8_t *msg, uint32_t *mlen);
80
81int32_t SM9_KeyExchangeInit(SM9_Ctx *ctx, uint8_t *peer_id, uint32_t peer_id_len,
82 int32_t is_initiator, uint8_t *rand, uint8_t *R);
83int32_t SM9_KeyExchangeConfirm(SM9_Ctx *ctx, uint8_t *peer_id, uint32_t peer_id_len,
84 int32_t is_initiator, uint8_t *peer_R, uint32_t klen,
85 uint8_t *shared_key, uint8_t *confirm_value);
86int32_t SM9_KeyExchangeVerify(SM9_Ctx *ctx, uint8_t *peer_id, uint32_t peer_id_len,
87 int32_t is_initiator, uint8_t *peer_R, uint8_t *peer_confirm);
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif // HITLS_CRYPTO_SM9
94#endif /* __CRYPT_SM9_H__ */