WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
rsa.c 文件参考
#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"
rsa.c 的引用(Include)关系图:

结构体

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]
 

宏定义说明

◆ DRV_PKE_CAL_LEN_1536

#define DRV_PKE_CAL_LEN_1536   192

◆ DRV_PKE_CAL_LEN_320

#define DRV_PKE_CAL_LEN_320   40

◆ LOOP_NUMBER_1024

#define LOOP_NUMBER_1024   6

◆ LOOP_NUMBER_1536

#define LOOP_NUMBER_1536   9

◆ LOOP_NUMBER_192

#define LOOP_NUMBER_192   6

◆ LOOP_NUMBER_2048

#define LOOP_NUMBER_2048   7

◆ LOOP_NUMBER_256

#define LOOP_NUMBER_256   4

◆ LOOP_NUMBER_3072

#define LOOP_NUMBER_3072   10

◆ LOOP_NUMBER_320

#define LOOP_NUMBER_320   6

◆ LOOP_NUMBER_384

#define LOOP_NUMBER_384   7

◆ LOOP_NUMBER_4096

#define LOOP_NUMBER_4096   8

◆ LOOP_NUMBER_512

#define LOOP_NUMBER_512   5

◆ MAX_OFFSET_OF_VALID_BIT

#define MAX_OFFSET_OF_VALID_BIT   2

◆ MAX_RRN_SUPPORT_TYPE

#define MAX_RRN_SUPPORT_TYPE   10

◆ pke_data_ptr_chk

#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

枚举类型说明

◆ rsa_mod_mode

枚举值
RSA_MOD_ADD 
RSA_MOD_SUB 
RSA_MOD_MUL 

函数说明

◆ pke_rsa_mod_common_process()

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 
)

◆ rsa_add_mod()

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

◆ rsa_exp_mod()

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.

参数
nthe input modulo.
kthe exponent.
inthe input data.
outthe 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.

◆ rsa_inv_mod()

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.

◆ rsa_mod()

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.

参数
athe input data, which bit length shouldn't more than 2 * p->bit_length.
pthe 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.

◆ rsa_mul_mod()

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.

◆ rsa_regular_mul()

td_s32 rsa_regular_mul ( const drv_pke_data a,
const drv_pke_data b,
const drv_pke_data *c  CIPHER_CHECK_WORD 
)

◆ rsa_rrn()

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.

Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved. Description: RSA algorithm header file.

Create: 2022-08-18

参数
nfor rsa n = p * q, for ecc it's prime the order of the base point G.
key_sizersa key length in byte or ecc curve key length in byte.
rrnthe 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_lenaligned length for calculate.
返回
td_s32 TD_SUCCESS or others.

◆ rsa_sub_mod()

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.

◆ update_rsa_modulus()

td_s32 update_rsa_modulus ( const td_u8 n,
const td_u32  n_len,
const td_u32 aligned_len  CIPHER_CHECK_WORD 
)

变量说明

◆ g_rrn_loop_table

const rrn_loop_table g_rrn_loop_table[10]
初始值:
= {
{ 192 , &instr_rsa_rrn_add_3072, 9 },
{ 40 , &instr_rsa_rrn_add_320, 6 },
}
@ DRV_PKE_LEN_1024
Definition crypto_pke_struct.h:23
@ DRV_PKE_LEN_3072
Definition crypto_pke_struct.h:26
@ DRV_PKE_LEN_4096
Definition crypto_pke_struct.h:27
@ DRV_PKE_LEN_256
Definition crypto_pke_struct.h:17
@ DRV_PKE_LEN_192
Definition crypto_pke_struct.h:15
@ DRV_PKE_LEN_2048
Definition crypto_pke_struct.h:25
@ DRV_PKE_LEN_512
Definition crypto_pke_struct.h:20
@ DRV_PKE_LEN_384
Definition crypto_pke_struct.h:18
const rom_lib instr_rsa_rrn_add
Definition rom_lib.c:474
const rom_lib instr_rsa_rrn_add_320
Definition rom_lib.c:486
const rom_lib instr_rsa_rrn_add_3072
Definition rom_lib.c:480