|
WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
|
#include "crypto_osal_adapt.h"#include "crypto_drv_common.h"#include "drv_trng.h"#include "hal_common.h"#include "hal_pke_reg.h"#include "hal_pke.h"#include "drv_hash.h"#include "drv_common_pke.h"
结构体 | |
| struct | pke_ecc_alg_support_t |
宏定义 | |
| #define | SHA1_BLOCK_LENGTH 64 |
| #define | SHA224_BLOCK_LENGTH 64 |
| #define | SHA256_BLOCK_LENGTH 64 |
| #define | SHA384_BLOCK_LENGTH 128 |
| #define | SHA512_BLOCK_LENGTH 128 |
| #define | SM3_BLOCK_LENGTH 64 |
| #define | PKE_MAX_HASH_BLOCK_SIZE 128 |
| #define | SHA1_RESULT_LENGTH 20 |
| #define | SHA224_RESULT_LENGTH 28 |
| #define | SHA256_RESULT_LENGTH 32 |
| #define | SHA384_RESULT_LENGTH 48 |
| #define | SHA512_RESULT_LENGTH 64 |
| #define | SM3_RESULT_LENGTH 32 |
函数 | |
| 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) |
| CRYPTO_STATIC void | inner_bn_add_one (td_u8 *data, td_u32 len) |
| CRYPTO_STATIC void | inner_bn_sub_one (td_u8 *data, td_u32 len) |
| 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_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 | normal_sub (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. | |
变量 | |
| pke_default_parameters * | g_ecc_params = TD_NULL |
| td_u32 * | g_ecc_num = TD_NULL |
| #define PKE_MAX_HASH_BLOCK_SIZE 128 |
| #define SHA1_BLOCK_LENGTH 64 |
| #define SHA1_RESULT_LENGTH 20 |
| #define SHA224_BLOCK_LENGTH 64 |
| #define SHA224_RESULT_LENGTH 28 |
| #define SHA256_BLOCK_LENGTH 64 |
| #define SHA256_RESULT_LENGTH 32 |
| #define SHA384_BLOCK_LENGTH 128 |
| #define SHA384_RESULT_LENGTH 48 |
| #define SHA512_BLOCK_LENGTH 128 |
| #define SHA512_RESULT_LENGTH 64 |
| #define SM3_BLOCK_LENGTH 64 |
| #define SM3_RESULT_LENGTH 32 |
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; |
| 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. |
| void crypto_drv_pke_common_suspend | ( | void | ) |
disable noise and unlock.
| CRYPTO_STATIC void inner_bn_add_one | ( | td_u8 * | data, |
| td_u32 | len | ||
| ) |
| CRYPTO_STATIC void inner_bn_sub_one | ( | td_u8 * | data, |
| td_u32 | len | ||
| ) |
| 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_NULL |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved. Description: the common function implementation of drv_layer.
Create: 2022-10-27