|
WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
|
#include "hal_pke_reg.h"#include "hal_pke.h"#include "crypto_osal_adapt.h"#include "crypto_drv_common.h"#include "drv_common_pke.h"#include "rsa.h"
结构体 | |
| struct | rrn_loop_table |
宏定义 | |
| #define | pke_data_ptr_chk(ptr) crypto_chk_return((ptr) == TD_NULL, PKE_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "%s is NULL\n", #ptr) |
| #define | DRV_PKE_CAL_LEN_1536 192 |
| #define | DRV_PKE_CAL_LEN_320 40 |
| #define | MAX_OFFSET_OF_VALID_BIT 2 |
| #define | LOOP_NUMBER_4096 8 |
| #define | LOOP_NUMBER_3072 10 |
| #define | LOOP_NUMBER_2048 7 |
| #define | LOOP_NUMBER_1536 9 |
| #define | LOOP_NUMBER_1024 6 |
| #define | LOOP_NUMBER_192 6 |
| #define | LOOP_NUMBER_256 4 |
| #define | LOOP_NUMBER_320 6 |
| #define | LOOP_NUMBER_384 7 |
| #define | LOOP_NUMBER_512 5 |
| #define | MAX_RRN_SUPPORT_TYPE 10 |
枚举 | |
| enum | rsa_mod_mode { RSA_MOD_ADD , RSA_MOD_SUB , RSA_MOD_MUL } |
函数 | |
| td_s32 | rsa_rrn (const td_u8 *n, const td_u32 key_size, const td_u32 aligned_len, td_u8 *rrn) |
| rrn = 2^(2*n_bit_len) mod n. | |
| td_s32 | update_rsa_modulus (const td_u8 *n, const td_u32 n_len, const td_u32 aligned_len CIPHER_CHECK_WORD) |
| td_s32 | rsa_regular_mul (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *c CIPHER_CHECK_WORD) |
| td_s32 | rsa_mod (const drv_pke_data *a, const drv_pke_data *p, const drv_pke_data *c CIPHER_CHECK_WORD) |
| c = a mod p. | |
| td_s32 | pke_rsa_mod_common_process (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *p, td_u32 *aligned_len, rsa_mod_mode mode) |
| td_s32 | rsa_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) |
| c = (a + b) mod p | |
| td_s32 | rsa_sub_mod (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *p, const drv_pke_data *c CIPHER_CHECK_WORD) |
| c = (a - b) mod p. a could be smaller than b. | |
| td_s32 | rsa_mul_mod (const drv_pke_data *a, const drv_pke_data *b, const drv_pke_data *p, const drv_pke_data *c CIPHER_CHECK_WORD) |
| c = (a * b) mod p use montgomery modular multiplication. before call this API, you should have call rsa_rrn API to set rrn into rsa_addr_rr DRAM. | |
| td_s32 | rsa_inv_mod (const drv_pke_data *a, const drv_pke_data *p, const drv_pke_data *c CIPHER_CHECK_WORD) |
| c = ~a mod p. where a * c mod p = 1 mod p. | |
| td_s32 | rsa_exp_mod (const drv_pke_data *n, const drv_pke_data *k, const drv_pke_data *in, const drv_pke_data *out CIPHER_CHECK_WORD) |
| out = in ^ k mod n. | |
变量 | |
| const rrn_loop_table | g_rrn_loop_table [10] |
| #define DRV_PKE_CAL_LEN_1536 192 |
| #define DRV_PKE_CAL_LEN_320 40 |
| #define LOOP_NUMBER_1024 6 |
| #define LOOP_NUMBER_1536 9 |
| #define LOOP_NUMBER_192 6 |
| #define LOOP_NUMBER_2048 7 |
| #define LOOP_NUMBER_256 4 |
| #define LOOP_NUMBER_3072 10 |
| #define LOOP_NUMBER_320 6 |
| #define LOOP_NUMBER_384 7 |
| #define LOOP_NUMBER_4096 8 |
| #define LOOP_NUMBER_512 5 |
| #define MAX_OFFSET_OF_VALID_BIT 2 |
| #define MAX_RRN_SUPPORT_TYPE 10 |
| #define pke_data_ptr_chk | ( | ptr | ) | crypto_chk_return((ptr) == TD_NULL, PKE_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "%s is NULL\n", #ptr) |
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved. Description: RSA algorithm emplement.
Create: 2022-08-18
| enum rsa_mod_mode |
| td_s32 pke_rsa_mod_common_process | ( | const drv_pke_data * | a, |
| const drv_pke_data * | b, | ||
| const drv_pke_data * | p, | ||
| td_u32 * | aligned_len, | ||
| rsa_mod_mode | mode | ||
| ) |
| td_s32 rsa_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 | ||
| ) |
c = (a + b) mod p
| td_s32 rsa_exp_mod | ( | const drv_pke_data * | n, |
| const drv_pke_data * | k, | ||
| const drv_pke_data * | in, | ||
| const drv_pke_data *out | CIPHER_CHECK_WORD | ||
| ) |
out = in ^ k mod n.
| n | the input modulo. |
| k | the exponent. |
| in | the input data. |
| out | the output data. |
| CIPHER_CHECK_WORD | ifdef SEC_ENHANCE, the value is XOR result of parameters, otherwise it doesn't exist. |
| td_s32 rsa_inv_mod | ( | const drv_pke_data * | a, |
| const drv_pke_data * | p, | ||
| const drv_pke_data *c | CIPHER_CHECK_WORD | ||
| ) |
c = ~a mod p. where a * c mod p = 1 mod p.
| td_s32 rsa_mod | ( | const drv_pke_data * | a, |
| const drv_pke_data * | p, | ||
| const drv_pke_data *c | CIPHER_CHECK_WORD | ||
| ) |
c = a mod p.
| a | the input data, which bit length shouldn't more than 2 * p->bit_length. |
| p | 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 rsa_mul_mod | ( | const drv_pke_data * | a, |
| const drv_pke_data * | b, | ||
| const drv_pke_data * | p, | ||
| const drv_pke_data *c | CIPHER_CHECK_WORD | ||
| ) |
c = (a * b) mod p use montgomery modular multiplication. before call this API, you should have call rsa_rrn API to set rrn into rsa_addr_rr DRAM.
| td_s32 rsa_regular_mul | ( | const drv_pke_data * | a, |
| const drv_pke_data * | b, | ||
| const drv_pke_data *c | CIPHER_CHECK_WORD | ||
| ) |
rrn = 2^(2*n_bit_len) mod n.
Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved. Description: RSA algorithm header file.
Create: 2022-08-18
| n | for rsa n = p * q, for ecc it's prime the order of the base point G. |
| key_size | rsa key length in byte or ecc curve key length in byte. |
| rrn | the output rrn data. for RSA there is no need to get this data out to reset it into rsa_addr_rr, but for ecc, it's necessary, for there are two different address. which byte length is the same with n. |
| aligned_len | aligned length for calculate. |
| td_s32 rsa_sub_mod | ( | const drv_pke_data * | a, |
| const drv_pke_data * | b, | ||
| const drv_pke_data * | p, | ||
| const drv_pke_data *c | CIPHER_CHECK_WORD | ||
| ) |
c = (a - b) mod p. a could be smaller than b.
| td_s32 update_rsa_modulus | ( | const td_u8 * | n, |
| const td_u32 | n_len, | ||
| const td_u32 aligned_len | CIPHER_CHECK_WORD | ||
| ) |
| const rrn_loop_table g_rrn_loop_table[10] |