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 #include "drv_osal_lib.h"
20 #include "cryp_rsa.h"
21
22 /* ****************************** API Code **************************** */
23 /*
24 * brief Kapi Init.
25 * retval On success, HI_SUCCESS is returned. On error, HI_FAILURE is returned.
26 */
kapi_rsa_init(void)27 hi_s32 kapi_rsa_init(void)
28 {
29 hi_s32 ret;
30
31 hi_log_func_enter();
32
33 ret = cryp_rsa_init();
34 if (ret != HI_SUCCESS) {
35 hi_log_print_func_err(cryp_rsa_init, ret);
36 return ret;
37 }
38
39 hi_log_func_exit();
40 return HI_SUCCESS;
41 }
42
43 /*
44 * brief Kapi Deinitialize.
45 * retval On success, HI_SUCCESS is returned. On error, HI_FAILURE is returned.
46 */
kapi_rsa_deinit(void)47 hi_s32 kapi_rsa_deinit(void)
48 {
49 hi_log_func_enter();
50
51 cryp_rsa_deinit();
52
53 hi_log_func_exit();
54 return HI_SUCCESS;
55 }
56
kapi_rsa_encrypt(cryp_rsa_key * key,cryp_rsa_crypt_data * rsa)57 hi_s32 kapi_rsa_encrypt(cryp_rsa_key *key, cryp_rsa_crypt_data *rsa)
58 {
59 hi_s32 ret;
60
61 hi_log_func_enter();
62
63 ret = cryp_rsa_encrypt(key, rsa);
64 if (ret != HI_SUCCESS) {
65 hi_log_print_func_err(cryp_rsa_encrypt, ret);
66 return ret;
67 }
68
69 hi_log_func_exit();
70 return HI_SUCCESS;
71 }
72
kapi_rsa_decrypt(cryp_rsa_key * key,cryp_rsa_crypt_data * rsa)73 hi_s32 kapi_rsa_decrypt(cryp_rsa_key *key, cryp_rsa_crypt_data *rsa)
74 {
75 hi_s32 ret;
76
77 hi_log_func_enter();
78
79 ret = cryp_rsa_decrypt(key, rsa);
80 if (ret != HI_SUCCESS) {
81 hi_log_print_func_err(cryp_rsa_decrypt, ret);
82 return ret;
83 }
84
85 hi_log_func_exit();
86 return HI_SUCCESS;
87 }
88
kapi_rsa_sign_hash(cryp_rsa_key * key,cryp_rsa_sign_data * rsa)89 hi_s32 kapi_rsa_sign_hash(cryp_rsa_key *key, cryp_rsa_sign_data *rsa)
90 {
91 hi_s32 ret;
92
93 hi_log_func_enter();
94
95 ret = cryp_rsa_sign_hash(key, rsa);
96 if (ret != HI_SUCCESS) {
97 hi_log_print_func_err(cryp_rsa_sign_hash, ret);
98 return ret;
99 }
100
101 hi_log_func_exit();
102 return HI_SUCCESS;
103 }
104
kapi_rsa_verify_hash(cryp_rsa_key * key,cryp_rsa_sign_data * rsa)105 hi_s32 kapi_rsa_verify_hash(cryp_rsa_key *key, cryp_rsa_sign_data *rsa)
106 {
107 hi_s32 ret;
108
109 hi_log_func_enter();
110
111 ret = cryp_rsa_verify_hash(key, rsa);
112 if (ret != HI_SUCCESS) {
113 hi_log_print_func_err(cryp_rsa_verify_hash, ret);
114 return ret;
115 }
116
117 hi_log_func_exit();
118 return HI_SUCCESS;
119 }
120
kapi_rsa_bn_exp_mod(cryp_rsa_exp_mod * exp_mod)121 hi_s32 kapi_rsa_bn_exp_mod(cryp_rsa_exp_mod *exp_mod)
122 {
123 hi_s32 ret;
124
125 hi_log_func_enter();
126
127 ret = cryp_rsa_bn_exp_mod(exp_mod);
128 if (ret != HI_SUCCESS) {
129 hi_log_print_func_err(cryp_rsa_bn_exp_mod, ret);
130 return ret;
131 }
132
133 hi_log_func_exit();
134 return HI_SUCCESS;
135 }
136