• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __HVB_SM2_BN_H__
16 #define __HVB_SM2_BN_H__
17 
18 #include <stdint.h>
19 #include "hvb_gm_common.h"
20 
21 #define SM2_SWORD_BIT_SIZE         32
22 #define SM2_KEY_LEN                32
23 #define SM2_DATA_DWORD_SIZE        4
24 #define SM2_BN_OK                  0
25 #define SM2_BN_INVALID             (-1)
26 #define SM2_BN_NOT_INDOMAIN        (-2)
27 #define SM2_BN_MEMORY_ERR          (-3)
28 
29 
30 struct sm2_point_jcb {
31     uint64_t x[SM2_DATA_DWORD_SIZE];
32     uint64_t y[SM2_DATA_DWORD_SIZE];
33     uint64_t z[SM2_DATA_DWORD_SIZE];
34 };
35 
36 struct sm2_point_aff {
37     uint64_t x[SM2_DATA_DWORD_SIZE];
38     uint64_t y[SM2_DATA_DWORD_SIZE];
39 };
40 
41 void invert_copy_byte(uint8_t *dst, uint8_t *src, uint32_t len);
42 
43 uint8_t *sm2_bn_get_param_a(void);
44 
45 uint8_t *sm2_bn_get_param_b(void);
46 
47 uint8_t *sm2_bn_get_param_gx(void);
48 
49 uint8_t *sm2_bn_get_param_gy(void);
50 
51 int sm2_bn_check_indomain_n(uint64_t a[]);
52 
53 int sm2_bn_add_mod_n(uint64_t a[], uint64_t b[], uint64_t r[]);
54 
55 int sm2_bn_is_valid(uint64_t a[]);
56 
57 int sm2_bn_cmp(uint64_t a[], uint64_t b[]);
58 
59 int sm2_point_mul_add(const uint64_t k1[], const uint64_t k2[], struct sm2_point_aff *p,
60     struct sm2_point_aff *r);
61 
62 #endif