8#ifndef DRV_COMMON_PKE_H
9#define DRV_COMMON_PKE_H
22#define JAC_TO_AFF_INSTR_NUM 6
23#define POINT_NAF_INSTR_NUM 3
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))
29#define ED25519_MAX_HASH_ELEMENTS 3
30#ifndef DRV_PKE_SM2_LEN_IN_BYTES
31#define DRV_PKE_SM2_LEN_IN_BYTES 32
33#define HALF_BYTE_VALUE 128
36#define NEED_PAD_ZERO 1
37#define NO_NEED_PAD_ZERO 0
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)})
42#define PKE_COMPAT_ERRNO(err_code) DRV_COMPAT_ERRNO(ERROR_MODULE_PKE, err_code)
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)
47#define crypto_dump_buffer(fmt, args...)
161td_s32 crypto_drv_pke_common_batch_instr_single_process_test(
const rom_lib *signle_instr_list,
td_u32 work_len);
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
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