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

浏览源代码.

结构体

struct  pke_ecc_point_jac
 

函数

td_s32 ecc_ecfp_jac_to_aff (const drv_pke_data *mod_p)
 Get final calculate result. trans (ecc_addr_cx, ecc_addr_cy, ecc_addr_cz) from jac to aff. aff_x = jac_x * ((jac_z)^-2); aff_y = jac_y * ((jac_z)^-3)
 
td_s32 ecc_ecfp_demontgomery_data_jac_z (const drv_pke_data *z, td_u32 work_len)
 
td_s32 ecc_ecfp_aff_to_jac (const drv_pke_ecc_point *in, const drv_pke_data *mod_p, pke_ecc_point_jac *out)
 trans coordinate system from affine to jacobin, before call this API, you should have set mont_1_p and const_0 into ecc_addr_mont_1_p and ecc_addr_const_0. (ecc_addr_px, ecc_addr_py) -> (ecc_addr_cx, ecc_addr_cy, ecc_addr_cz).
 
td_s32 ecc_ecfp_montgomery_data_aff_backup (const drv_pke_ecc_point *in, const drv_pke_data *mod_p, const drv_pke_ecc_point *out, const uintptr_t check_word)
 montgomery the point coordinate in affine coordinate system.
 
td_s32 ecc_ecfp_montgomery_data_aff (const drv_pke_ecc_point *in, const drv_pke_data *mod_p, const drv_pke_ecc_point *out CIPHER_CHECK_WORD)
 montgomery the point coordinate in affine coordinate system. Before call this API, you should have set curve initial parameters into the DRAM.
 
td_s32 ecc_ecfp_demontgomery_data_aff (const drv_pke_ecc_point *r, td_u32 work_len)
 demontgomery data, (ecc_addr_cx, ecc_addr_cy) -> (ecc_addr_cx, ecc_addr_cy). Before calculate demont, you should have set const_1 to ecc_addr_const_1.
 
td_s32 ecc_ecfp_mul_naf (const drv_pke_ecc_curve *ecc, const drv_pke_data *k, const drv_pke_ecc_point *p, const drv_pke_ecc_point *r CIPHER_CHECK_WORD)
 R = k * G, point multiplication.
 
td_s32 ecc_ecfp_mul_naf_cal (td_u32 work_len, const drv_pke_data *k)
 R = k * G, point multiplication. Before call this API, you should have set curve initial parameters, and set point coordinate into the DRAM.
 
td_s32 ecc_ecfp_mul_add (const drv_pke_ecc_curve *ecc, const drv_pke_data *u1, const drv_pke_data *u2, const drv_pke_ecc_point *q, const drv_pke_ecc_point *r CIPHER_CHECK_WORD)
 R = u1 * G + u2 * Q. Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_mont_a, ecc_addr_mont_1_p, ecc_addr_const_1, ecc_addr_const_0.
 
td_s32 ecc_ecfn_inv (const drv_pke_data *a, const drv_pke_data *n, const drv_pke_data *c CIPHER_CHECK_WORD)
 c = ~a mod n, ecc_addr_s = 1/ecc_addr_k. Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_rrn, ecc_addr_mont_1_n.
 
td_s32 get_random_key (const td_u8 *n, const td_u32 size, td_u8 *rand CIPHER_CHECK_WORD)
 Get the random key object range in [1, n-1]
 
td_s32 update_modulus (const td_u8 *n, const td_u32 n_len CIPHER_CHECK_WORD)
 update modulus into ecc_addr_m, and set new montgomery parameter into reg. Before call this API, you should have set initial parameters into PKE DRAM.
 
td_s32 ecc_ecfn_sign_s (const drv_pke_data *k_inv, const drv_pke_data *e, const drv_pke_data *d, const drv_pke_data *r, const drv_pke_data *n, const drv_pke_data *s CIPHER_CHECK_WORD)
 calculate the s value of signature. s = k_inv * (e + d * r) mod n. montgomery multiplication modulurs and twice modulo reduction to demontgomery, and make sure s, r in [1, n-1] Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_rrn, ecc_addr_const_1.
 
td_s32 ecc_ecfn_verify_u (const drv_pke_data *s_inv, const drv_pke_data *e, const drv_pke_data *r, const drv_pke_data *n, const drv_pke_data *u1, const drv_pke_data *u2 CIPHER_CHECK_WORD)
 calculate the u1 = s_inv * e mod n & u2 = s_inv * r mod n. montgomery multiplication modulurs and twice modulo reduction to demontgomery. Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_rrn, ecc_addr_const_1.
 
td_s32 ecc_ecfn_verify_v (const drv_pke_ecc_curve *ecc, const drv_pke_ecc_sig *sig, td_u8 *out_v)
 verify whether the v == r.
 
td_s32 ecc_ecfp_point_valid_standard (drv_pke_ecc_curve_type curve_type, const drv_pke_ecc_point *pub_key, td_bool *is_on_curve CIPHER_CHECK_WORD)
 the standard method to check whether the point is on the curve.
 
td_s32 ecc_ecfn_add_mod (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *p, const drv_pke_data *c CIPHER_CHECK_WORD)
 calculate modular addition on prime n domain. Here use instr_sm2_verify_t_3 as common add_mod calculate to calculate both ecc and sm2 signature value r.
 
td_s32 sm2_ecfn_sign_s (const drv_pke_data *k, const drv_pke_data *d, const drv_pke_data *n, const drv_pke_data *r, const drv_pke_data *s)
 calculate s for sm2 signature. s = (1 + d) * (k - r *d) mod n. and the output is the demontgomeried r & s.
 
td_s32 sm2_ecfn_add_mod (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *p, const drv_pke_data *c, uintptr_t const check_word)
 
td_s32 sm2_ecfn_verify_r (const drv_pke_data *rx, const drv_pke_data *hash, const drv_pke_data *r, const drv_pke_data *n, const drv_pke_data *out)
 calculate r= e + Rx mod n, and check whether r -r == 0?
 
td_s32 sign_verify_hash (const sm2_sign_verify_hash_pack *param, const drv_pke_msg *msg, drv_pke_data *hash CIPHER_CHECK_WORD)
 calculate hash for sm2.
 

函数说明

◆ ecc_ecfn_add_mod()

td_s32 ecc_ecfn_add_mod ( const drv_pke_data a,
const drv_pke_data b,
const drv_pke_data p,
const drv_pke_data *c  CIPHER_CHECK_WORD 
)

calculate modular addition on prime n domain. Here use instr_sm2_verify_t_3 as common add_mod calculate to calculate both ecc and sm2 signature value r.

参数
athe first data.
bthe second data.
pthe module.
cthe output result.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: sm2 common algorithm implementation

Create: 2023-06-05

◆ ecc_ecfn_inv()

td_s32 ecc_ecfn_inv ( const drv_pke_data a,
const drv_pke_data n,
const drv_pke_data *c  CIPHER_CHECK_WORD 
)

c = ~a mod n, ecc_addr_s = 1/ecc_addr_k. Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_rrn, ecc_addr_mont_1_n.

参数
athe input data.
nthe modulus.
cthe output data.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfn_sign_s()

td_s32 ecc_ecfn_sign_s ( const drv_pke_data k_inv,
const drv_pke_data e,
const drv_pke_data d,
const drv_pke_data r,
const drv_pke_data n,
const drv_pke_data *s  CIPHER_CHECK_WORD 
)

calculate the s value of signature. s = k_inv * (e + d * r) mod n. montgomery multiplication modulurs and twice modulo reduction to demontgomery, and make sure s, r in [1, n-1] Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_rrn, ecc_addr_const_1.

参数
k_invthe result of 1/k.
ethe input hash result of message.
dthe input private key.
rthe r value of signature.
nthe modulus.
sthe output data s of signature.
返回
td_s32 TD_SUCCESS or others.

Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: ecc sign algorithm implementation

Create: 2023-06-05

◆ ecc_ecfn_verify_u()

td_s32 ecc_ecfn_verify_u ( const drv_pke_data s_inv,
const drv_pke_data e,
const drv_pke_data r,
const drv_pke_data n,
const drv_pke_data u1,
const drv_pke_data *u2  CIPHER_CHECK_WORD 
)

calculate the u1 = s_inv * e mod n & u2 = s_inv * r mod n. montgomery multiplication modulurs and twice modulo reduction to demontgomery. Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_rrn, ecc_addr_const_1.

参数
s_invthe input modular inverse of s value.
ethe input hash result of message.
rthe r value of signature.
nthe modulus.
u1the output value u1 = s_inv * e.
u2the output value u2 = s_inv * r mod n.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: ecc verify algorithm implementation

Create: 2023-06-05

◆ ecc_ecfn_verify_v()

td_s32 ecc_ecfn_verify_v ( const drv_pke_ecc_curve ecc,
const drv_pke_ecc_sig sig,
td_u8 out_v 
)

verify whether the v == r.

参数
eccthe input ecc curve parameter.
sigthe signature to be verified.
out_vthe calculated verify value.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_aff_to_jac()

td_s32 ecc_ecfp_aff_to_jac ( const drv_pke_ecc_point in,
const drv_pke_data mod_p,
pke_ecc_point_jac out 
)

trans coordinate system from affine to jacobin, before call this API, you should have set mont_1_p and const_0 into ecc_addr_mont_1_p and ecc_addr_const_0. (ecc_addr_px, ecc_addr_py) -> (ecc_addr_cx, ecc_addr_cy, ecc_addr_cz).

参数
inthe input point in affine system.
mod_pthe modulur.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_demontgomery_data_aff()

td_s32 ecc_ecfp_demontgomery_data_aff ( const drv_pke_ecc_point r,
td_u32  work_len 
)

demontgomery data, (ecc_addr_cx, ecc_addr_cy) -> (ecc_addr_cx, ecc_addr_cy). Before calculate demont, you should have set const_1 to ecc_addr_const_1.

参数
rstore the result.
work_lenwork_len = celing(aligned_len/64).
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_demontgomery_data_jac_z()

td_s32 ecc_ecfp_demontgomery_data_jac_z ( const drv_pke_data z,
td_u32  work_len 
)

◆ ecc_ecfp_jac_to_aff()

td_s32 ecc_ecfp_jac_to_aff ( const drv_pke_data mod_p)

Get final calculate result. trans (ecc_addr_cx, ecc_addr_cy, ecc_addr_cz) from jac to aff. aff_x = jac_x * ((jac_z)^-2); aff_y = jac_y * ((jac_z)^-3)

参数
work_lenaligned_len work_len = celing(bitWidth/64).
mod_pthe consistent of modulus n, n = p * q.
返回
td_s32 TD_SUCCESS or others.

Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: ecc common algorithm implementation

Create: 2023-06-05

◆ ecc_ecfp_montgomery_data_aff()

td_s32 ecc_ecfp_montgomery_data_aff ( const drv_pke_ecc_point in,
const drv_pke_data mod_p,
const drv_pke_ecc_point *out  CIPHER_CHECK_WORD 
)

montgomery the point coordinate in affine coordinate system. Before call this API, you should have set curve initial parameters into the DRAM.

参数
inintput point in affine coordinate system.
mod_pmodulus.
outoutput point in affine coordinate system.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_montgomery_data_aff_backup()

td_s32 ecc_ecfp_montgomery_data_aff_backup ( const drv_pke_ecc_point in,
const drv_pke_data mod_p,
const drv_pke_ecc_point out,
const uintptr_t  check_word 
)

montgomery the point coordinate in affine coordinate system.

参数
inintput point in affine coordinate system.
mod_pmodulus.
outoutput point in affine coordinate system.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_mul_add()

td_s32 ecc_ecfp_mul_add ( const drv_pke_ecc_curve ecc,
const drv_pke_data u1,
const drv_pke_data u2,
const drv_pke_ecc_point q,
const drv_pke_ecc_point *r  CIPHER_CHECK_WORD 
)

R = u1 * G + u2 * Q. Before call this API, you should have set curve initial parameters into DRAM, which must include ecc_addr_mont_a, ecc_addr_mont_1_p, ecc_addr_const_1, ecc_addr_const_0.

参数
eccinput ecc curve param.
u1the scalar.
u2the scalar.
qthe input point(public key), which is in affine coordinate system.
rthe output point. result is in (ecc_addr_cx, ecc_addr_cy, ecc_addr_cz).
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_mul_naf()

td_s32 ecc_ecfp_mul_naf ( const drv_pke_ecc_curve ecc,
const drv_pke_data k,
const drv_pke_ecc_point p,
const drv_pke_ecc_point *r  CIPHER_CHECK_WORD 
)

R = k * G, point multiplication.

参数
eccinput ecc curve param.
kthe scalar.
pthe input point.
rthe output point.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_mul_naf_cal()

td_s32 ecc_ecfp_mul_naf_cal ( td_u32  work_len,
const drv_pke_data k 
)

R = k * G, point multiplication. Before call this API, you should have set curve initial parameters, and set point coordinate into the DRAM.

参数
work_lenwork_len = align_len / ALIGNED_TO_WORK_LEN_IN_BYTE.
kthe scalar.
返回
td_s32 TD_SUCCESS or others.

◆ ecc_ecfp_point_valid_standard()

td_s32 ecc_ecfp_point_valid_standard ( drv_pke_ecc_curve_type  curve_type,
const drv_pke_ecc_point pub_key,
td_bool *is_on_curve  CIPHER_CHECK_WORD 
)

the standard method to check whether the point is on the curve.

参数
eccthe input ecc curve parameter.
pub_keythe input public key to be checked.
is_on_curvethe output result, true: is on the curve, false: is not on the curve.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

◆ get_random_key()

td_s32 get_random_key ( const td_u8 n,
const td_u32  size,
td_u8 *rand  CIPHER_CHECK_WORD 
)

Get the random key object range in [1, n-1]

参数
nrange.
sizethe byte length of number n.
randthe output random data.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

◆ sign_verify_hash()

td_s32 sign_verify_hash ( const sm2_sign_verify_hash_pack param,
const drv_pke_msg msg,
drv_pke_data *hash  CIPHER_CHECK_WORD 
)

calculate hash for sm2.

参数
paramthe other data that is used for sm2 hash calculate.
msgthe input message that need to be calculate hash.
hashthe hash result.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.

◆ sm2_ecfn_add_mod()

td_s32 sm2_ecfn_add_mod ( const drv_pke_data a,
const drv_pke_data b,
const drv_pke_data p,
const drv_pke_data c,
uintptr_t const  check_word 
)

◆ sm2_ecfn_sign_s()

td_s32 sm2_ecfn_sign_s ( const drv_pke_data k,
const drv_pke_data d,
const drv_pke_data n,
const drv_pke_data r,
const drv_pke_data s 
)

calculate s for sm2 signature. s = (1 + d) * (k - r *d) mod n. and the output is the demontgomeried r & s.

参数
kthe input data k.
dthe input private key.
nthe order of G point of the curve.
rthe input r of signature and the output r(demontgomeried) of signature.
sthe result s(demontgomeried) of the signature.
返回
td_s32 TD_SUCCESS or others.

◆ sm2_ecfn_verify_r()

td_s32 sm2_ecfn_verify_r ( const drv_pke_data rx,
const drv_pke_data hash,
const drv_pke_data r,
const drv_pke_data n,
const drv_pke_data out 
)

calculate r= e + Rx mod n, and check whether r -r == 0?

参数
rxthe input Rx.
hashthe input hash value.
rthe input r of signature.
nthe input modulo.
outthe output value of r` - r.
返回
td_s32 TD_SUCCESS or others.

◆ update_modulus()

td_s32 update_modulus ( const td_u8 n,
const td_u32 n_len  CIPHER_CHECK_WORD 
)

update modulus into ecc_addr_m, and set new montgomery parameter into reg. Before call this API, you should have set initial parameters into PKE DRAM.

参数
nthe new modulus
n_lenthe byte length of new modulus.
CIPHER_CHECK_WORDifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist.
返回
td_s32 TD_SUCCESS or others.