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


结构体 | |
| 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. | |
| 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.
| a | the first data. |
| b | the second data. |
| p | the module. |
| c | the output result. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: sm2 common algorithm implementation
Create: 2023-06-05
| 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.
| a | the input data. |
| n | the modulus. |
| c | the output data. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
| 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_inv | the result of 1/k. |
| e | the input hash result of message. |
| d | the input private key. |
| r | the r value of signature. |
| n | the modulus. |
| s | the output data s of signature. |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: ecc sign algorithm implementation
Create: 2023-06-05
| 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_inv | the input modular inverse of s value. |
| e | the input hash result of message. |
| r | the r value of signature. |
| n | the modulus. |
| u1 | the output value u1 = s_inv * e. |
| u2 | the output value u2 = s_inv * r mod n. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: ecc verify algorithm implementation
Create: 2023-06-05
| 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.
| ecc | the input ecc curve parameter. |
| sig | the signature to be verified. |
| out_v | the calculated verify value. |
| 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).
| in | the input point in affine system. |
| mod_p | the modulur. |
| 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.
| r | store the result. |
| work_len | work_len = celing(aligned_len/64). |
| td_s32 ecc_ecfp_demontgomery_data_jac_z | ( | const drv_pke_data * | z, |
| td_u32 | work_len | ||
| ) |
| 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_len | aligned_len work_len = celing(bitWidth/64). |
| mod_p | the consistent of modulus n, n = p * q. |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. Description: ecc common algorithm implementation
Create: 2023-06-05
| 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.
| in | intput point in affine coordinate system. |
| mod_p | modulus. |
| out | output point in affine coordinate system. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
| 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.
| in | intput point in affine coordinate system. |
| mod_p | modulus. |
| out | output point in affine coordinate system. |
| 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.
| ecc | input ecc curve param. |
| u1 | the scalar. |
| u2 | the scalar. |
| q | the input point(public key), which is in affine coordinate system. |
| r | the output point. result is in (ecc_addr_cx, ecc_addr_cy, ecc_addr_cz). |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
| 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.
| ecc | input ecc curve param. |
| k | the scalar. |
| p | the input point. |
| r | the output point. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
| 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_len | work_len = align_len / ALIGNED_TO_WORK_LEN_IN_BYTE. |
| k | the scalar. |
| 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.
| ecc | the input ecc curve parameter. |
| pub_key | the input public key to be checked. |
| is_on_curve | the output result, true: is on the curve, false: is not on the curve. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
Get the random key object range in [1, n-1]
| n | range. |
| size | the byte length of number n. |
| rand | the output random data. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
| 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.
| param | the other data that is used for sm2 hash calculate. |
| msg | the input message that need to be calculate hash. |
| hash | the hash result. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
| 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_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.
| k | the input data k. |
| d | the input private key. |
| n | the order of G point of the curve. |
| r | the input r of signature and the output r(demontgomeried) of signature. |
| s | the result s(demontgomeried) of the signature. |
| 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?
| rx | the input Rx. |
| hash | the input hash value. |
| r | the input r of signature. |
| n | the input modulo. |
| out | the output value of r` - r. |
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.
| n | the new modulus |
| n_len | the byte length of new modulus. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |