|
WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
|


结构体 | |
| struct | instr_data_ram |
宏定义 | |
| #define | JAC_TO_AFF_INSTR_NUM 6 |
| #define | POINT_NAF_INSTR_NUM 3 |
| #define | LOCAL_STEP_CNT_INIT 0x96C3785A |
| #define | LOCAL_STEP_AUTH 11 |
| #define | local_step(cnt) (LOCAL_STEP_CNT_INIT + LOCAL_STEP_AUTH * (cnt)) |
| #define | ED25519_MAX_HASH_ELEMENTS 3 |
| #define | DRV_PKE_SM2_LEN_IN_BYTES 32 |
| #define | HALF_BYTE_VALUE 128 |
| #define | BYTE_VALUE 256 |
| #define | NEED_PAD_ZERO 1 |
| #define | NO_NEED_PAD_ZERO 0 |
| #define | gen_pke_data(len, value) ((drv_pke_data) {.length = (len), .data = (value)}) |
| #define | gen_pke_point(len, xvalue, yvalue) ((drv_pke_ecc_point) {.length = (len), .x = (xvalue), .y = (yvalue)}) |
| #define | PKE_COMPAT_ERRNO(err_code) DRV_COMPAT_ERRNO(ERROR_MODULE_PKE, err_code) |
| #define | crypto_dump_buffer(fmt, args...) |
函数 | |
| const drv_pke_ecc_curve * | crypto_drv_pke_common_get_ecc_curve (drv_pke_ecc_curve_type curve_type) |
| void | crypto_drv_pke_common_arry_right_shift_value (td_u8 *k, td_u32 k_len, td_u32 shift_bit) |
| void | crypto_drv_pke_common_array_add_plus_minus_one (td_u8 *k, td_u32 k_len, td_s32 value) |
| 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_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 high bit. which need to be reverse, or use from ki(high bit). | |
| td_s32 | crypto_drv_pke_common_montgomery_data_config (td_u8 *rr, td_u32 rr_len, td_u8 *rrp, td_u32 rrp_len) |
| td_bool | crypto_drv_pke_common_is_zero (const td_u8 *val, td_u32 klen) |
| td_void | crypto_drv_pke_common_array_sub_value (td_u8 *k, td_u32 k_len, td_s32 value) |
| minus the specified value. | |
| 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. | |
| 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) |
| td_void | crypto_drv_pke_common_normal_add (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *c) |
| td_s32 | crypto_drv_pke_common_set_mont_param (const drv_pke_data *p) |
| Get the montgomery param object and set it into register. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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, you should have set input data into the right PKE DRAM address. | |
| 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. | |
| td_s32 | crypto_drv_pke_common_resume (void) |
| lock, enable noise, and set mask random. | |
| void | crypto_drv_pke_common_suspend (void) |
| disable noise and unlock. | |
| td_s32 | crypto_drv_pke_common_limit_value_check (const td_u8 *in_buf, const td_u8 *limit_value, const td_u32 limit_len) |
| td_s32 | crypto_drv_pke_common_range_check (const td_u8 *in_buf, const td_u8 *limit_value, const td_u32 limit_len) |
| td_s32 | crypto_drv_pke_common_init_param (const drv_pke_ecc_curve *ecc) |
| According to curve type set init parameters into DRAM. | |
| 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) |
| 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) |
| 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) |
| 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) |
| 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_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_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) |
| td_s32 | normal_sub (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *c) |
变量 | |
| pke_default_parameters * | g_ecc_params |
| td_u32 * | g_ecc_num |
| #define BYTE_VALUE 256 |
| #define crypto_dump_buffer | ( | fmt, | |
| args... | |||
| ) |
| #define DRV_PKE_SM2_LEN_IN_BYTES 32 |
| #define ED25519_MAX_HASH_ELEMENTS 3 |
| #define gen_pke_data | ( | len, | |
| value | |||
| ) | ((drv_pke_data) {.length = (len), .data = (value)}) |
| #define gen_pke_point | ( | len, | |
| xvalue, | |||
| yvalue | |||
| ) | ((drv_pke_ecc_point) {.length = (len), .x = (xvalue), .y = (yvalue)}) |
| #define HALF_BYTE_VALUE 128 |
| #define JAC_TO_AFF_INSTR_NUM 6 |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved. Description: the common function head file of drv_layer.
Create: 2022-10-27
| #define local_step | ( | cnt | ) | (LOCAL_STEP_CNT_INIT + LOCAL_STEP_AUTH * (cnt)) |
| #define LOCAL_STEP_AUTH 11 |
| #define LOCAL_STEP_CNT_INIT 0x96C3785A |
| #define NEED_PAD_ZERO 1 |
| #define NO_NEED_PAD_ZERO 0 |
| #define PKE_COMPAT_ERRNO | ( | err_code | ) | DRV_COMPAT_ERRNO(ERROR_MODULE_PKE, err_code) |
| #define POINT_NAF_INSTR_NUM 3 |
minus the specified value.
| k | the input data. |
| k_len | the byte length of the input k. |
| value | the specified value that is to be subtracted. |
batch instruction calculation, which include set_mode->start->wait_done.
| batch_instr | the batch instruction that need to process. |
| work_len | work_len = aligned_len / 8. |
| 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 | ||
| ) |
| 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.
| arr | the input multi-buffer that need to be calculate hash. |
| arr_len | the buffer number that need to be calculate hash. |
| hash_type | the hash type user want. |
| hash | the ouput hash result. |
| 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 high bit. which need to be reverse, or use from ki(high bit).
| k | the normal scalar |
| k_len | the byte length of k. |
| k_naf | the non-adjacent-form of k. the output data from k0 to ki is from low bit to high bit. which need to be reverse, or use from ki(high bit). |
| k_naf_len | the length of k_naf, k_naf_len = k_len * 8 or k_naf_len = k_len * 8 + 1; |
| 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 | ||
| ) |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: ecc sign function implement.
Create: 2023-05-19
| 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 | ||
| ) |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: for secure boot.
Create: 2023-02-23
| 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 | ||
| ) |
| const drv_pke_ecc_curve * crypto_drv_pke_common_get_ecc_curve | ( | drv_pke_ecc_curve_type | curve_type | ) |
| 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.
| instr_cmd | instr mode CMD_MUL_MOD | CMD_ADD_MOD | CMD_SUB_MOD. |
| data_ram | instr parameter ram section. |
| out_instr | the generated instruction. |
| td_s32 crypto_drv_pke_common_init_param | ( | const drv_pke_ecc_curve * | ecc | ) |
According to curve type set init parameters into DRAM.
| ecc | Curve parameter. |
| 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.
| batch_instr | the batch instructions array, which include a series of instructions to be used for calculation. It include 6 instructions: pre_process, j2a_exp_00, j2a_exp_01, j2a_exp_10, j2a_exp_11. |
| batch_instr_num | the batch instructions num. |
| mod_p | the modulur used for calculation. |
| td_s32 crypto_drv_pke_common_limit_value_check | ( | const td_u8 * | in_buf, |
| const td_u8 * | limit_value, | ||
| const td_u32 | limit_len | ||
| ) |
| 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.
| output_endian | output value. |
| input_endian | input value. |
| byte_len | the byte length of the value to be processed. |
| td_s32 crypto_drv_pke_common_montgomery_data_config | ( | td_u8 * | rr, |
| td_u32 | rr_len, | ||
| td_u8 * | rrp, | ||
| td_u32 | rrp_len | ||
| ) |
| td_void crypto_drv_pke_common_normal_add | ( | const drv_pke_data * | a, |
| const drv_pke_data * | b, | ||
| const drv_pke_data * | c | ||
| ) |
| 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, you should have set input data into the right PKE DRAM address.
| batch_instr | the batch instructions array, which include a series of instructions to be used for calculation. It include 6 instructions: pre_process, j2a_exp_00, j2a_exp_01, j2a_exp_10, j2a_exp_11. |
| batch_instr_num | the batch instructions num. |
| k | the invariant that participate in the calculation. |
| work_len | work_len = align_len / ALIGNED_TO_WORK_LEN_IN_BYTE. |
| td_s32 crypto_drv_pke_common_range_check | ( | const td_u8 * | in_buf, |
| const td_u8 * | limit_value, | ||
| const td_u32 | limit_len | ||
| ) |
| td_s32 crypto_drv_pke_common_resume | ( | void | ) |
lock, enable noise, and set mask random.
| 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.
| p | input prime. |
| td_s32 crypto_drv_pke_common_set_mont_param | ( | const drv_pke_data * | p | ) |
Get the montgomery param object and set it into register.
| p | input prime. |
single instruction calculation, which include set_mode->start->wait_done.
| single_instr | the single instruction that need to process. |
| work_len | work_len = aligned_len / 8. |
| 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 | ||
| ) |
| 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_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_sm2_sign | ( | const drv_pke_data * | priv_key, |
| const drv_pke_data * | hash, | ||
| const drv_pke_ecc_sig * | sig | ||
| ) |
| 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 | ||
| ) |
| void crypto_drv_pke_common_suspend | ( | void | ) |
disable noise and unlock.
| td_s32 normal_sub | ( | const drv_pke_data * | a, |
| const drv_pke_data * | b, | ||
| const drv_pke_data * | c | ||
| ) |
|
extern |
|
extern |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved. Description: the common function implementation of drv_layer.
Create: 2022-10-27