WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
drv_common_pke.h
浏览该文件的文档.
1
8#ifndef DRV_COMMON_PKE_H
9#define DRV_COMMON_PKE_H
10
11#include "crypto_pke_struct.h"
12#include "hal_pke.h"
13#include "rom_lib.h"
14
15#ifdef __cplusplus
16#if __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19#endif /* __cplusplus */
20
21/************************************************** pke common MICRO start************************************/
22#define JAC_TO_AFF_INSTR_NUM 6
23#define POINT_NAF_INSTR_NUM 3
24
25#define LOCAL_STEP_CNT_INIT 0x96C3785A
26#define LOCAL_STEP_AUTH 11
27#define local_step(cnt) (LOCAL_STEP_CNT_INIT + LOCAL_STEP_AUTH * (cnt))
28
29#define ED25519_MAX_HASH_ELEMENTS 3
30#ifndef DRV_PKE_SM2_LEN_IN_BYTES
31#define DRV_PKE_SM2_LEN_IN_BYTES 32
32#endif
33#define HALF_BYTE_VALUE 128
34#define BYTE_VALUE 256
35
36#define NEED_PAD_ZERO 1
37#define NO_NEED_PAD_ZERO 0
38
39#define gen_pke_data(len, value) ((drv_pke_data) {.length = (len), .data = (value)})
40#define gen_pke_point(len, xvalue, yvalue) ((drv_pke_ecc_point) {.length = (len), .x = (xvalue), .y = (yvalue)})
41
42#define PKE_COMPAT_ERRNO(err_code) DRV_COMPAT_ERRNO(ERROR_MODULE_PKE, err_code)
43
44#if (defined(CRYPTO_LOG_LEVEL) && (CRYPTO_LOG_LEVEL == 2 || CRYPTO_LOG_LEVEL == 3 || CRYPTO_LOG_LEVEL == 4))
45#define crypto_dump_buffer(buffer_name, buffer, len) crypto_dump_data(buffer_name, buffer, len)
46#else
47#define crypto_dump_buffer(fmt, args...)
48#endif
49/************************************************** pke common MICRO end************************************/
50
51/************************************************ pke common global variable start************************************/
52typedef struct {
53 td_u32 ram_section_a; /* input data a ram section. */
54 td_u32 ram_section_b; /* input data b ram section. */
55 td_u32 ram_section_c; /* out data ram section. */
56 td_u32 ram_section_tp; /* intermediate parameter ram section. */
59
60extern td_u32 *g_ecc_num;
61/************************************************ pke common global variable end************************************/
62
63/************************************************** pke common API start************************************/
65
66/* right shift any bit you want, the shift_bit should be [1, 8], and the k should be bigendian data. */
68
69/* add or minus one. */
71
72td_s32 crypto_drv_pke_common_get_binary_data(const td_u8 *mod_p, const td_u32 mod_p_len, td_u8 *mod_p_bin,
73 td_u32 *mod_p_bin_len, td_u32 flag);
74
87 td_u32 *k_naf_len);
88
89/* config data for montgomery calculation. */
91
92/* whether the data is whole zero. */
94
102
110td_s32 crypto_drv_pke_common_little_big_endian_trans(td_u8 *output_endian, const td_u8 *input_endian, td_u32 byte_len);
111
112td_s32 crypto_drv_pke_common_byte_stream_to_int_array(const td_u8 *byte_stream, const td_u32 stream_length,
113 td_u32 *int_array, td_u32 array_length);
114
116
123
137
145td_s32 crypto_drv_pke_common_get_single_instr(td_u32 instr_cmd, const instr_data_ram *data_ram, td_u32 *out_instr);
153
154#ifdef PKE_V5_DEBUG
161td_s32 crypto_drv_pke_common_batch_instr_single_process_test(const rom_lib *signle_instr_list, td_u32 work_len);
162#endif
163
172td_s32 crypto_drv_pke_common_jac_to_aff_cal(const rom_lib *batch_instr, const td_u32 batch_instr_num,
173 const drv_pke_data *mod_p);
174
185td_s32 crypto_drv_pke_common_point_mul_naf(const rom_lib *batch_instr, const td_u32 batch_instr_num,
186 const drv_pke_data *k, td_u32 work_len);
187
196td_s32 crypto_drv_pke_common_calc_hash(const drv_pke_data* arr, const td_u32 arr_len, const drv_pke_hash_type hash_type,
197 drv_pke_data *hash);
198
204
209
210/* check whether y >= p, if yes, return failure. */
211td_s32 crypto_drv_pke_common_limit_value_check(const td_u8 *in_buf, const td_u8 *limit_value, const td_u32 limit_len);
212
213td_s32 crypto_drv_pke_common_range_check(const td_u8 *in_buf, const td_u8 *limit_value, const td_u32 limit_len);
214
222
223/************************************************** pke common API end************************************/
225 const drv_pke_data *hash, const drv_pke_ecc_sig *sig);
226
228 const drv_pke_data *hash, const drv_pke_ecc_sig *sig);
229
231 const drv_pke_ecc_sig *sig);
232
234 const drv_pke_ecc_sig *sig);
235
237 const drv_pke_data *cipher_text);
238
240 const drv_pke_data *plain_text);
241
243 const drv_pke_msg *msg, const drv_pke_data *hash);
244
245td_s32 normal_sub(const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *c);
246
247#ifdef __cplusplus
248#if __cplusplus
249}
250#endif /* __cplusplus */
251#endif /* __cplusplus */
252
253#endif /* DRV_COMMON_PKE_H */
drv_pke_hash_type
Definition crypto_pke_struct.h:57
drv_pke_ecc_curve_type
Definition crypto_pke_struct.h:32
td_s32 crypto_drv_pke_common_ecc_verify(drv_pke_ecc_curve_type curve_type, const drv_pke_ecc_point *pub_key, const drv_pke_data *hash, const drv_pke_ecc_sig *sig)
Definition drv_pke_ecc_verify.c:12
const drv_pke_ecc_curve * crypto_drv_pke_common_get_ecc_curve(drv_pke_ecc_curve_type curve_type)
Definition drv_common_pke.c:26
td_s32 crypto_drv_pke_common_little_big_endian_trans(td_u8 *output_endian, const td_u8 *input_endian, td_u32 byte_len)
littleendian and bigendian transform to get the right value.
Definition drv_common_pke.c:203
td_s32 crypto_drv_pke_common_ecc_sign(drv_pke_ecc_curve_type curve_type, const drv_pke_data *priv_key, const drv_pke_data *hash, const drv_pke_ecc_sig *sig)
Definition drv_pke_ecc_sign.c:12
td_s32 normal_sub(const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *c)
Definition drv_common_pke.c:302
td_s32 crypto_drv_pke_common_point_mul_naf(const rom_lib *batch_instr, const td_u32 batch_instr_num, const drv_pke_data *k, td_u32 work_len)
main process of NAF(non-adjacent-form) point multiplication. Q = k * G. Before call this function,...
Definition drv_common_pke.c:626
void crypto_drv_pke_common_arry_right_shift_value(td_u8 *k, td_u32 k_len, td_u32 shift_bit)
Definition drv_common_pke.c:37
td_s32 crypto_drv_pke_common_range_check(const td_u8 *in_buf, const td_u8 *limit_value, const td_u32 limit_len)
Definition drv_common_pke.c:792
td_s32 crypto_drv_pke_common_set_ecc_mont_param(const drv_pke_data *p)
Get the montgomery param object and set it into register.
Definition drv_common_pke.c:444
td_s32 crypto_drv_pke_common_calc_hash(const drv_pke_data *arr, const td_u32 arr_len, const drv_pke_hash_type hash_type, drv_pke_data *hash)
calculate hash for sm2 and ed25519.
Definition drv_common_pke.c:704
pke_default_parameters * g_ecc_params
Definition drv_common_pke.c:18
td_s32 crypto_drv_pke_common_convert_normal_scalar_to_naf(const td_u8 *k, const td_u32 k_len, td_s32 *k_naf, td_u32 *k_naf_len)
convert normal scalar value to non-adjacent-form. the output data from k0 to ki is from low bit to hi...
Definition drv_common_pke.c:106
td_s32 crypto_drv_pke_common_sm2_private_decrypt(const drv_pke_data *priv_key, const drv_pke_data *cipher_text, const drv_pke_data *plain_text)
td_s32 crypto_drv_pke_common_jac_to_aff_cal(const rom_lib *batch_instr, const td_u32 batch_instr_num, const drv_pke_data *mod_p)
Jacobin to Affine coordinate transfer calculation.
Definition drv_common_pke.c:563
void crypto_drv_pke_common_array_add_plus_minus_one(td_u8 *k, td_u32 k_len, td_s32 value)
Definition drv_common_pke.c:89
td_s32 crypto_drv_pke_common_sm2_dsa_hash(const drv_pke_data *sm2_id, const drv_pke_ecc_point *pub_key, const drv_pke_msg *msg, const drv_pke_data *hash)
Definition drv_pke_sm2_dsa_hash.c:78
td_s32 crypto_drv_pke_common_byte_stream_to_int_array(const td_u8 *byte_stream, const td_u32 stream_length, td_u32 *int_array, td_u32 array_length)
Definition drv_common_pke.c:226
td_s32 crypto_drv_pke_common_get_binary_data(const td_u8 *mod_p, const td_u32 mod_p_len, td_u8 *mod_p_bin, td_u32 *mod_p_bin_len, td_u32 flag)
td_s32 crypto_drv_pke_common_resume(void)
lock, enable noise, and set mask random.
Definition drv_common_pke.c:740
td_s32 crypto_drv_pke_common_limit_value_check(const td_u8 *in_buf, const td_u8 *limit_value, const td_u32 limit_len)
Definition drv_common_pke.c:770
td_u32 * g_ecc_num
Definition drv_common_pke.c:19
td_s32 crypto_drv_pke_common_sm2_public_encrypt(const drv_pke_ecc_point *pub_key, const drv_pke_data *plain_text, const drv_pke_data *cipher_text)
td_s32 crypto_drv_pke_common_batch_instr_process(const rom_lib *batch_instr, td_u32 work_len)
batch instruction calculation, which include set_mode->start->wait_done.
Definition drv_common_pke.c:488
td_s32 crypto_drv_pke_common_sm2_verify(const drv_pke_ecc_point *pub_key, const drv_pke_data *hash, const drv_pke_ecc_sig *sig)
Definition drv_pke_sm2_verify.c:29
td_s32 crypto_drv_pke_common_montgomery_data_config(td_u8 *rr, td_u32 rr_len, td_u8 *rrp, td_u32 rrp_len)
Definition drv_common_pke.c:140
td_s32 crypto_drv_pke_common_get_single_instr(td_u32 instr_cmd, const instr_data_ram *data_ram, td_u32 *out_instr)
get instr for single instr process.
Definition drv_common_pke.c:506
td_bool crypto_drv_pke_common_is_zero(const td_u8 *val, td_u32 klen)
Definition drv_common_pke.c:167
td_s32 crypto_drv_pke_common_single_instr_process(td_u32 single_instr, td_u32 work_len)
single instruction calculation, which include set_mode->start->wait_done.
Definition drv_common_pke.c:521
td_void crypto_drv_pke_common_normal_add(const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *c)
Definition drv_common_pke.c:250
td_void crypto_drv_pke_common_array_sub_value(td_u8 *k, td_u32 k_len, td_s32 value)
minus the specified value.
Definition drv_common_pke.c:186
td_s32 crypto_drv_pke_common_init_param(const drv_pke_ecc_curve *ecc)
According to curve type set init parameters into DRAM.
Definition drv_common_pke.c:802
td_s32 crypto_drv_pke_common_sm2_sign(const drv_pke_data *priv_key, const drv_pke_data *hash, const drv_pke_ecc_sig *sig)
void crypto_drv_pke_common_suspend(void)
disable noise and unlock.
Definition drv_common_pke.c:761
td_s32 crypto_drv_pke_common_set_mont_param(const drv_pke_data *p)
Get the montgomery param object and set it into register.
Definition drv_common_pke.c:352
Definition crypto_pke_struct.h:74
Definition crypto_pke_struct.h:96
Definition crypto_pke_struct.h:80
Definition crypto_pke_struct.h:89
Definition crypto_pke_struct.h:111
Definition drv_common_pke.h:52
td_u32 ram_section_a
Definition drv_common_pke.h:53
td_u32 ram_section_tp
Definition drv_common_pke.h:56
td_u32 ram_section_c
Definition drv_common_pke.h:55
td_u32 ram_section_b
Definition drv_common_pke.h:54
Definition crypto_pke_struct.h:157
Definition rom_lib.h:14
unsigned char td_u8
Definition td_type.h:36
td_u8 td_bool
Definition td_type.h:50
void td_void
Definition td_type.h:49
unsigned int td_u32
Definition td_type.h:38
int td_s32
Definition td_type.h:44