• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #ifndef __DRV_RSA_H__
20 #define __DRV_RSA_H__
21 
22 /* ************************** Structure Definition *************************** */
23 /* Define RSA 1024 key length */
24 #define RSA_KEY_LEN_1024             128
25 
26 /* Define RSA 2048 key length */
27 #define RSA_KEY_LEN_2048             256
28 
29 /* Define RSA 3072 key length */
30 #define RSA_KEY_LEN_3072             384
31 
32 /* Define RSA 4096 key length */
33 #define RSA_KEY_LEN_4096             512
34 
35 /* rsa capacity, 0-nonsupport, 1-support */
36 typedef struct {
37     hi_u32 rsa         : 1;    /* Support RSA */
38 } rsa_capacity;
39 
40 /* rsa key width */
41 typedef enum {
42     RSA_KEY_WIDTH_1024 = 0x00, /* RSA 1024 */
43     RSA_KEY_WIDTH_2048,        /* RSA 2048 */
44     RSA_KEY_WIDTH_4096,        /* RSA 4096 */
45     RSA_KEY_WIDTH_3072,        /* RSA 3072 */
46     RSA_KEY_WIDTH_COUNT,
47 } rsa_key_width;
48 
49 /*
50  * brief  Initialize the rsa module.
51  * retval     On success, HI_SUCCESS is returned.  On error, HI_FAILURE is returned.
52  */
53 hi_s32 drv_rsa_init(void);
54 
55 /*
56  * brief  Deinitialize the rsa module.
57  * retval     On success, HI_SUCCESS is returned.  On error, HI_FAILURE is returned.
58  */
59 hi_s32 drv_rsa_deinit(void);
60 
61 /*
62  * brief  RSA encrypt/decrypt use rsa exponent-modular arithmetic.
63  * param[in]  n The N of rsa key.
64  * param[in]  k The d/e of rsa key.
65  * param[in]  in The input data.
66  * param[out] out The input data.
67  * retval     On success, HI_SUCCESS is returned.  On error, HI_FAILURE is returned.
68  */
69 hi_s32 drv_ifep_rsa_exp_mod(hi_u32 ca_type, const hi_u8 *n, const hi_u8 *k,
70     const hi_u8 *in, hi_u8 *out, rsa_key_width width);
71 
72 /*
73  * brief  get the hash capacity.
74  * param[out] capacity The hash capacity.
75  * retval     NA.
76  */
77 void drv_ifep_rsa_get_capacity(rsa_capacity *capacity);
78 
79 /*
80  * brief  get the hash capacity.
81  * param[out] capacity The hash capacity.
82  * retval     NA.
83  */
84 void drv_sic_rsa_get_capacity(rsa_capacity *capacity);
85 #endif /* End of __DRV_RSA_H__ */
86