API GUIDE / RSA / LL
G32S10 RSA LL 接口
LL 层接口:LL helper 位于 ll_rsa.h,不维护状态、不校验参数、不整理 word 顺序、不等待完成。
1. LL 接口
LL helper 位于 ll_rsa.h,不维护状态、不校验参数、不整理 word 顺序、不等待完成。
1.1 实例
bool ll_rsa_is_supported_instance(const rsa_regs_t *rsax);
仅 rsax == RSA 返回 true。
1.2 RSAC
void ll_rsa_clear_control(rsa_regs_t *rsax); void ll_rsa_set_modulus_word_count(rsa_regs_t *rsax, uint32_t word_count); void ll_rsa_start_operation(rsa_regs_t *rsax); bool ll_rsa_is_operation_enabled(const rsa_regs_t *rsax);
clear_control() 写整个 RSAC = 0,只能在无活动操作时调用。word_count 合法范围是 3 到 128。
1.3 输入 FIFO
void ll_rsa_write_exponent_word(rsa_regs_t *rsax, uint32_t word); void ll_rsa_write_modulus_word(rsa_regs_t *rsax, uint32_t word); void ll_rsa_write_message_word(rsa_regs_t *rsax, uint32_t word);
这些寄存器为 write-only FIFO。LL 不处理 128-word padding 或 word 顺序。
1.4 结果 FIFO
uint32_t ll_rsa_read_result_word(const rsa_regs_t *rsax);
只能在 INT_DONE 后读取。完整结果需要读取 n_bits / 32 个 words。
1.5 RSACLR
void ll_rsa_clear_status(rsa_regs_t *rsax, uint32_t clear_mask);
RSACLR 为 W1C。LL 只保留 RSA_RSACLR_ALL_STATUS_MASK 范围内的位。
1.6 RSAINFO
uint32_t ll_rsa_get_status(const rsa_regs_t *rsax);
返回 RSA_RSAINFO_STATUS_MASK 范围内的状态:
N_CFG_DONEINT_DONEPRD_OFWRD_UFWWR_OFWN_EVEN
1.7 RSAEN
void ll_rsa_enable_interrupts(rsa_regs_t *rsax, uint32_t interrupt_mask); void ll_rsa_disable_interrupts(rsa_regs_t *rsax, uint32_t interrupt_mask); uint32_t ll_rsa_get_enabled_interrupts(const rsa_regs_t *rsax);
interrupt_mask 只保留 RSA_RSAEN_ALL_MASK。
1.8 debug
uint32_t ll_rsa_get_debug_state(const rsa_regs_t *rsax); uint32_t ll_rsa_get_p_length(const rsa_regs_t *rsax);
分别读取 RSADBG0.STATE 和 RSADBG1.P_LENGTH。正常完成仍以 RSAINFO 为准。
1.9 software reset
void ll_rsa_trigger_software_reset(rsa_regs_t *rsax); bool ll_rsa_is_reset_done(const rsa_regs_t *rsax);
向 RSARSTN.RSTN 写 0 触发复位,随后轮询直到读回 1。
2. 寄存器
| Offset | 寄存器 | 用途 |
|---|---|---|
0x0000 | RSAC | 控制、N_LEN、EN |
0x0004 | RSAE | exponent/key FIFO,write-only |
0x0008 | RSAN | modulus FIFO,write-only |
0x000C | RSAM | message FIFO,write-only |
0x0010 | RSAP | result FIFO,read-only |
0x0014 | RSACLR | 状态清除,W1C |
0x0018 | RSAINFO | 状态 |
0x001C | RSAEN | 中断使能 |
0x0020 | RSADBG0 | debug state |
0x0024 | RSADBG1 | debug progress |
0x0028 | RSARSTN | software reset |
关键字段:
| 寄存器 | 字段 | 说明 |
|---|---|---|
RSAC | N_LEN[10:3] | modulus word count |
RSAC | EN | start modular exponentiation |
RSAINFO | N_CFG_DONE | modulus 配置完成 |
RSAINFO | INT_DONE | 模幂完成 |
RSAINFO | PRD_OFW | 非致命 product FIFO warning |
RSAINFO | RD_UFW/WR_OFW/N_EVEN | 硬件错误 |