WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
drv_common_pke.h 文件参考
#include "crypto_pke_struct.h"
#include "hal_pke.h"
#include "rom_lib.h"
drv_common_pke.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

结构体

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_curvecrypto_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_parametersg_ecc_params
 
td_u32g_ecc_num
 

宏定义说明

◆ BYTE_VALUE

#define BYTE_VALUE   256

◆ crypto_dump_buffer

#define crypto_dump_buffer (   fmt,
  args... 
)

◆ DRV_PKE_SM2_LEN_IN_BYTES

#define DRV_PKE_SM2_LEN_IN_BYTES   32

◆ ED25519_MAX_HASH_ELEMENTS

#define ED25519_MAX_HASH_ELEMENTS   3

◆ gen_pke_data

#define gen_pke_data (   len,
  value 
)    ((drv_pke_data) {.length = (len), .data = (value)})

◆ gen_pke_point

#define gen_pke_point (   len,
  xvalue,
  yvalue 
)    ((drv_pke_ecc_point) {.length = (len), .x = (xvalue), .y = (yvalue)})

◆ HALF_BYTE_VALUE

#define HALF_BYTE_VALUE   128

◆ JAC_TO_AFF_INSTR_NUM

#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

◆ local_step

#define local_step (   cnt)    (LOCAL_STEP_CNT_INIT + LOCAL_STEP_AUTH * (cnt))

◆ LOCAL_STEP_AUTH

#define LOCAL_STEP_AUTH   11

◆ LOCAL_STEP_CNT_INIT

#define LOCAL_STEP_CNT_INIT   0x96C3785A

◆ NEED_PAD_ZERO

#define NEED_PAD_ZERO   1

◆ NO_NEED_PAD_ZERO

#define NO_NEED_PAD_ZERO   0

◆ PKE_COMPAT_ERRNO

#define PKE_COMPAT_ERRNO (   err_code)    DRV_COMPAT_ERRNO(ERROR_MODULE_PKE, err_code)

◆ POINT_NAF_INSTR_NUM

#define POINT_NAF_INSTR_NUM   3

函数说明

◆ crypto_drv_pke_common_array_add_plus_minus_one()

void crypto_drv_pke_common_array_add_plus_minus_one ( td_u8 k,
td_u32  k_len,
td_s32  value 
)

◆ crypto_drv_pke_common_array_sub_value()

td_void crypto_drv_pke_common_array_sub_value ( td_u8 k,
td_u32  k_len,
td_s32  value 
)

minus the specified value.

参数
kthe input data.
k_lenthe byte length of the input k.
valuethe specified value that is to be subtracted.

◆ crypto_drv_pke_common_arry_right_shift_value()

void crypto_drv_pke_common_arry_right_shift_value ( td_u8 k,
td_u32  k_len,
td_u32  shift_bit 
)

◆ crypto_drv_pke_common_batch_instr_process()

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.

参数
batch_instrthe batch instruction that need to process.
work_lenwork_len = aligned_len / 8.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_byte_stream_to_int_array()

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 
)

◆ crypto_drv_pke_common_calc_hash()

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.

参数
arrthe input multi-buffer that need to be calculate hash.
arr_lenthe buffer number that need to be calculate hash.
hash_typethe hash type user want.
hashthe ouput hash result.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_convert_normal_scalar_to_naf()

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).

参数
kthe normal scalar
k_lenthe byte length of k.
k_nafthe 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_lenthe length of k_naf, k_naf_len = k_len * 8 or k_naf_len = k_len * 8 + 1;
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_ecc_sign()

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

◆ crypto_drv_pke_common_ecc_verify()

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

◆ crypto_drv_pke_common_get_binary_data()

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 
)

◆ crypto_drv_pke_common_get_ecc_curve()

const drv_pke_ecc_curve * crypto_drv_pke_common_get_ecc_curve ( drv_pke_ecc_curve_type  curve_type)

◆ crypto_drv_pke_common_get_single_instr()

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_cmdinstr mode CMD_MUL_MOD | CMD_ADD_MOD | CMD_SUB_MOD.
data_raminstr parameter ram section.
out_instrthe generated instruction.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_init_param()

td_s32 crypto_drv_pke_common_init_param ( const drv_pke_ecc_curve ecc)

According to curve type set init parameters into DRAM.

参数
eccCurve parameter.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_is_zero()

td_bool crypto_drv_pke_common_is_zero ( const td_u8 val,
td_u32  klen 
)

◆ crypto_drv_pke_common_jac_to_aff_cal()

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_instrthe 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_numthe batch instructions num.
mod_pthe modulur used for calculation.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_limit_value_check()

td_s32 crypto_drv_pke_common_limit_value_check ( const td_u8 in_buf,
const td_u8 limit_value,
const td_u32  limit_len 
)

◆ crypto_drv_pke_common_little_big_endian_trans()

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_endianoutput value.
input_endianinput value.
byte_lenthe byte length of the value to be processed.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_montgomery_data_config()

td_s32 crypto_drv_pke_common_montgomery_data_config ( td_u8 rr,
td_u32  rr_len,
td_u8 rrp,
td_u32  rrp_len 
)

◆ crypto_drv_pke_common_normal_add()

td_void crypto_drv_pke_common_normal_add ( const drv_pke_data a,
const drv_pke_data b,
const drv_pke_data c 
)

◆ crypto_drv_pke_common_point_mul_naf()

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_instrthe 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_numthe batch instructions num.
kthe invariant that participate in the calculation.
work_lenwork_len = align_len / ALIGNED_TO_WORK_LEN_IN_BYTE.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_range_check()

td_s32 crypto_drv_pke_common_range_check ( const td_u8 in_buf,
const td_u8 limit_value,
const td_u32  limit_len 
)

◆ crypto_drv_pke_common_resume()

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()

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.

参数
pinput prime.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_set_mont_param()

td_s32 crypto_drv_pke_common_set_mont_param ( const drv_pke_data p)

Get the montgomery param object and set it into register.

参数
pinput prime.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_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.

参数
single_instrthe single instruction that need to process.
work_lenwork_len = aligned_len / 8.
返回
td_s32 TD_SUCCESS or others.

◆ crypto_drv_pke_common_sm2_dsa_hash()

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 
)

◆ crypto_drv_pke_common_sm2_private_decrypt()

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 
)

◆ crypto_drv_pke_common_sm2_public_encrypt()

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 
)

◆ crypto_drv_pke_common_sm2_sign()

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 
)

◆ crypto_drv_pke_common_sm2_verify()

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 
)

◆ crypto_drv_pke_common_suspend()

void crypto_drv_pke_common_suspend ( void  )

disable noise and unlock.

◆ normal_sub()

td_s32 normal_sub ( const drv_pke_data a,
const drv_pke_data b,
const drv_pke_data c 
)

变量说明

◆ g_ecc_num

td_u32* g_ecc_num
extern

◆ g_ecc_params

pke_default_parameters* g_ecc_params
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