• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ECP_SM2_H
17 #define ECP_SM2_H
18 
19 #include "hitls_build.h"
20 #if defined(HITLS_CRYPTO_ECC) && defined(HITLS_CRYPTO_SM2)
21 
22 #include "crypt_ecc.h"
23 #include "crypt_bn.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /**
30  * @ingroup sm2
31  * @brief   Calculate r = k * pt. When pt is NULL, calculate r = k * G
32  *
33  * @param   para [IN] Curve parameter information
34  * @param   r [OUT] Output point information
35  * @param   k [IN] Scalar
36  * @param   pt [IN] Point data, which can be set to NULL.
37  *
38  * @retval CRYPT_SUCCESS    succeeded.
39  * @retval For details about other errors, see crypt_errno.h
40  */
41 int32_t ECP_Sm2PointMul(ECC_Para *para, ECC_Point *r, const BN_BigNum *scalar, const ECC_Point *pt);
42 
43 /**
44  * @ingroup sm2
45  * @brief   Calculate r = a + b, where a is the Jacobian coordinate system and b is the affine coordinate system.
46  *
47  * @param   para [IN] Curve parameter information
48  * @param   r [OUT] Output point information
49  * @param   a,b [IN] Point data
50  *
51  * @retval CRYPT_SUCCESS    succeeded.
52  * @retval For details about other errors, see crypt_errno.h
53  */
54 int32_t ECP_Sm2PointAddAffine(const ECC_Para *para, ECC_Point *r, const ECC_Point *a, const ECC_Point *b);
55 
56 /**
57  * @ingroup sm2
58  * @brief   Calculate r = 2*a, where a is the Jacobian coordinate system.
59  *
60  * @param   para [IN] Curve parameter information
61  * @param   r [OUT] Output point information
62  * @param   a [IN] Point data
63  *
64  * @retval CRYPT_SUCCESS    succeeded.
65  * @retval For details about other errors, see crypt_errno.h
66  */
67 int32_t ECP_Sm2PointDouble(const ECC_Para *para, ECC_Point *r, const ECC_Point *a);
68 
69 /**
70  * @ingroup sm2
71  * @brief   Convert the point information pt to the affine coordinate system and refresh the data to r.
72  *
73  * @param   para [IN] Curve parameters
74  * @param   r [OUT] Output point information
75  * @param   a [IN] Input point information
76  *
77  * @retval CRYPT_SUCCESS    succeeded
78  * @retval For details about other errors, see crypt_errno.h
79  */
80 int32_t ECP_Sm2Point2Affine(const ECC_Para *para, ECC_Point *r, const ECC_Point *a);
81 
82 /**
83  * @ingroup sm2
84  * @brief   Calculate r = k * pt,
85  *          Non-consttime calculation
86  *
87  * @param   para [IN] Curve parameter information
88  * @param   r [OUT] Output point information
89  * @param   k [IN] Scalar
90  * @param   pt [IN] Point data, which can be set to NULL.
91  *
92  * @retval CRYPT_SUCCESS    succeeded.
93  * @retval For details about other errors, see crypt_errno.h
94  */
95 int32_t ECP_Sm2PointMulFast(ECC_Para *para, ECC_Point *r, const BN_BigNum *k, const ECC_Point *pt);
96 
97 int32_t ECP_Sm2OrderInv(const ECC_Para *para, BN_BigNum *r, const BN_BigNum *a);
98 
99 int32_t ECP_Sm2PointMulAdd(ECC_Para *para, ECC_Point *r, const BN_BigNum *k1, const BN_BigNum *k2,
100     const ECC_Point *pt);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif
107 #endif