API参考
载入中...
搜索中...
未找到
sm2_local.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 SM2_LOCAL_H
17#define SM2_LOCAL_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_SM2
21
22#include <stdint.h>
23#include "crypt_sm2.h"
24#include "crypt_local_types.h"
25#include "crypt_ecc_pkey.h"
26#include "sal_atomic.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif /* __cpluscplus */
31
32#define SM2_MAX_ID_BITS 65535
33#define SM2_MAX_ID_LENGTH (SM2_MAX_ID_BITS / 8)
34#define SM2_MAX_PUBKEY_DATA_LENGTH 65
35#define MAX_MD_SIZE 64
36#define SM3_MD_SIZE 32
37#define SM2_POINT_SINGLE_COORDINATE_LEN 32
38#define SM2_POINT_COORDINATE_LEN 65
39#define SM2_TWO_POINT_COORDINATE_LEN 128
40#define SM2_X_LEN 32
41
42#ifdef HITLS_CRYPTO_ACVP_TESTS
43typedef struct {
44 BN_BigNum *k; // random k
45} SM2_ParaEx;
46#endif
47
48/* SM2 key context */
49struct SM2_Ctx {
50 ECC_Pkey *pkey;
51 uint32_t pkgImpl;
52 ECC_Point *pointR; // Local R
53 const EAL_MdMethod *hashMethod;
54 BN_BigNum *r; // Local r
55 uint8_t *userId; // User ID
56 uint32_t userIdLen; // the length of User ID
57 int32_t server; // 1: the initiator, 0: the receiver, and the default value is 1.
58 uint8_t sumCheck[SM3_MD_SIZE]; // Hash value used as a check
59 uint8_t sumSend[SM3_MD_SIZE]; // Hash value sent to the peer end
60 uint8_t isSumValid; // Indicates whether the checksum is valid. 1: valid; 0: invalid.
61 BSL_SAL_RefCount references;
62
63#ifdef HITLS_CRYPTO_ACVP_TESTS
64 SM2_ParaEx paraEx;
65#endif
66};
67
79int32_t Sm2ComputeZDigest(const CRYPT_SM2_Ctx *ctx, uint8_t *out, uint32_t *outLen);
80
81#if defined(HITLS_CRYPTO_SM2_EXCH) || defined(HITLS_CRYPTO_SM2_CRYPT)
95int32_t KdfGmt0032012(uint8_t *out, const uint32_t *outlen, const uint8_t *z, uint32_t zlen,
96 const EAL_MdMethod *hashMethod);
97
98#ifdef HITLS_CRYPTO_ACVP_TESTS
106int32_t CRYPT_SM2_SetK(CRYPT_SM2_Ctx *ctx, uint8_t *val, uint32_t len);
107#endif
108
109#endif
110
111#ifdef __cplusplus
112}
113#endif
114
115#endif // HITLS_CRYPTO_SM2
116
117#endif // SM2_LOCAL_H
定义 crypt_local_types.h:63