• 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_RSA_H__
16 #define __HVB_RSA_H__
17 
18 #include <stdint.h>
19 
20 struct long_int_num {
21     unsigned long *p_uint;
22     unsigned long *data_mem;
23     uint32_t mem_size;
24     uint32_t valid_word_len;
25 };
26 
27 struct long_int_num *lin_create(uint32_t word_len);
28 void lin_free(struct long_int_num *p_long_int);
29 void lin_update_valid_len(struct long_int_num *p_a);
30 int lin_get_bitlen(struct long_int_num *p_a);
31 
32 /* The value of the |exp| power module |p_n| of |p_m| is calculated
33 * by using the algorithm of Montgomery module power.
34 *
35 * |n_n0_i| and |p_rr| are precomputed values stored in the public key.
36 *
37 * return the value of |p_m|^|exp| mod |p_m|
38 */
39 struct long_int_num *montgomery_mod_exp(struct long_int_num *p_m, struct long_int_num *p_n,
40                                         unsigned long n_n0_i, struct long_int_num *p_rr,
41                                         uint32_t exp);
42 
43 #endif
44