• 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 __CRYP_RSA_H_
20 #define __CRYP_RSA_H_
21 
22 #include "drv_cipher_kapi.h"
23 #include "drv_osal_lib.h"
24 #include "drv_srsa.h"
25 
26 #define CRYP_TRNG_TIMEOUT  (-1)
27 
28 typedef enum {
29     RSA_BLOCK_TYPE_0 = 0X0,
30     RSA_BLOCK_TYPE_1,
31     RSA_BLOCK_TYPE_2,
32 } rsa_pkcs1_padding_type;
33 
34 typedef struct {
35     hi_u32 mode;
36     hi_u32 klen;
37     hi_u8 *in;
38     hi_u32 in_len;
39     hi_u8 *out;
40     hi_u32 *out_len;
41     hi_u8 bt;
42 } rsa_padding_pack;
43 
44 /*
45  * brief          Initialize crypto of rsa *
46  */
47 hi_s32 cryp_rsa_init(hi_void);
48 
49 /*
50  * brief          Deinitialize crypto of rsa *
51  */
52 hi_void cryp_rsa_deinit(hi_void);
53 
54 /*
55  * brief RSA encryption a plaintext with a RSA key.
56  * param[in] key:         rsa key.
57  * param[in] rsa_crypt:   rsa encrypt data.
58  * retval ::HI_SUCCESS  Call this API successful.
59  * retval ::HI_FAILURE  Call this API fails.
60  * see \n
61  * N/A
62  */
63 hi_s32 cryp_rsa_encrypt(const cryp_rsa_key *key, cryp_rsa_crypt_data *rsa_crypt);
64 
65 /*
66  * brief RSA decryption a plaintext with a RSA key.
67  * param[in] key:         rsa key.
68  * param[in] rsa_crypt:   rsa decrypt data.
69  * retval ::HI_SUCCESS  Call this API successful.
70  * retval ::HI_FAILURE  Call this API fails.
71  * see \n
72  * N/A
73  */
74 hi_s32 cryp_rsa_decrypt(const cryp_rsa_key *key, cryp_rsa_crypt_data *rsa_crypt);
75 
76 /*
77  * brief RSA sign a hash value with a RSA private key.
78  * param[in] key:         rsa key.
79  * param[in] rsa_sign:    rsa sign data.
80  * retval ::HI_SUCCESS  Call this API successful.
81  * retval ::HI_FAILURE  Call this API fails.
82  * see \n
83  * N/A
84  */
85 hi_s32 cryp_rsa_sign_hash(const cryp_rsa_key *key, cryp_rsa_sign_data *rsa_sign);
86 
87 /*
88  * brief RSA verify a hash value with a RSA public key.
89  * param[in] key:         rsa key.
90  * param[in] rsa_verify:  rsa sign data.
91  * retval ::HI_SUCCESS  Call this API successful.
92  * retval ::HI_FAILURE  Call this API fails.
93  * see \n
94  * N/A
95  */
96 hi_s32 cryp_rsa_verify_hash(const cryp_rsa_key *key, const cryp_rsa_sign_data *rsa_verify);
97 
98 hi_s32 cryp_rsa_bn_exp_mod(cryp_rsa_exp_mod *exp_mod);
99 
100 /*
101  * brief Generate random.
102  * N/A
103  */
104 int mbedtls_get_random(hi_void *param, hi_u8 *rand, size_t size);
105 #endif
106