对称硬件加密引擎
概述
对称硬件加密引擎是 SoC 内置的硬件加速模块,用于执行 AES 加密和 HMAC 哈希运算。相比软件实现,硬件加密引擎具有以下优势:
高性能:硬件并行运算,大幅提升加解密速度
低功耗:专用电路减少 CPU 参与度,降低整体功耗
高安全性:密钥存储在 OTP 区域,软件无法直接读取;支持 TrustZone 隔离
减少 CPU 占用:DMA 模式下自主完成数据搬运和运算,释放 CPU 资源
该引擎的 AES 和 HMAC 算法已通过 NIST CAVP 认证,支持多种加密算法和操作模式,广泛应用于数据加密、安全启动、固件保护等安全场景。
工作原理
加密引擎采用硬件总线架构,通过 DMA 控制器或 APB 总线与系统交互:
DMA 模式:引擎内部 DMA 控制器直接访问内存,自主完成数据读取、运算和结果写回,适合大数据量加解密
从模式:CPU 通过 APB 总线将数据写入引擎 FIFO,适合小数据量运算
引擎支持 TrustZone 技术,自动识别 CPU 的安全状态(Secure/Non-Secure),并通过硬件互斥锁机制防止安全域和非安全域同时访问引发冲突。每次释放锁时,引擎自动清除寄存器中的敏感信息,防止侧信道攻击。
AES 引擎
AES 引擎根据由 NIST 定义的高级加密标准(AES)对数据进行加密或解密,支持消息自动填充。可以使用软件寄存器密钥和硬件 OTP 密钥。
AES 算法支持
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
引擎算法已通过 NIST CAVP 认证。
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
XTS (XEX-based Tweaked CodeBook mode with CipherText Stealing)
支持的消息认证码:
GMAC (Galois Message Authentication Code)
CMAC (Cipher Block Chaining-Message Authentication Code)
AES 算法
支持的密钥长度:AES-128、AES-192、AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
CCM (Counter with CBC-MAC)
支持的消息认证码:
GMAC (Galois Message Authentication Code)
CMAC (Cipher Block Chaining-Message Authentication Code)
SM4 算法
支持的密钥长度:SM4-128
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
CCM (Counter with CBC-MAC)
支持的消息认证码:
GMAC (Galois Message Authentication Code)
CMAC (Cipher Block Chaining-Message Authentication Code)
备注
SM4 与 AES 使用相同的硬件引擎,通过 CORE_SEL 位选择算法核心。
引擎算法已通过 NIST CAVP 认证。
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
XTS (XEX-based Tweaked CodeBook mode with CipherText Stealing)
支持的消息认证码:
GMAC (Galois Message Authentication Code)
CMAC (Cipher Block Chaining-Message Authentication Code)
AES 密钥
AES 引擎配备独立的密钥管理单元,支持软件密钥和 OTP 硬件密钥。
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储 6 组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
AES |
安全 |
0 |
S_IPSEC_Key1 |
AES |
安全 |
1 |
S_IPSEC_Key2 |
AES |
安全 |
2 |
RSIP_AES_Key1 |
AES |
安全 |
3 |
RSIP_AES_Key2 |
AES |
非安全 |
0 |
NS_IPSEC_Key1 |
AES |
非安全 |
1 |
NS_IPSEC_Key2 |
AES |
非安全 |
2 |
RSIP_AES_Key1 |
AES |
非安全 |
3 |
RSIP_AES_Key2 |
备注
上表中 AES 引擎的安全与非安全侧各列出 4 个密钥索引(共 8 项),但其中安全侧与非安全侧的 RSIP_AES_Key1、RSIP_AES_Key2 实际对应**同一组** OTP 物理密钥——该密钥由安全 AES 引擎与非安全 AES 引擎共同自动加载,并非两组独立密钥。去除重复后,OTP 物理存储区中实际仅存在 6 组互不相同的密钥(S_IPSEC_Key1/Key2、NS_IPSEC_Key1/Key2、RSIP_AES_Key1/Key2),这正是前文"OTP 物理存储区支持存储 6 组密钥"的由来。
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动 加载此密钥用于 HMAC 或 AES 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
RSIP_AES_Key1 |
逻辑地址 0x2c0 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全 AES 引擎和安全 AES 引擎 将自动加载此密钥用于 AES 算法 |
RSIP_AES_Key2 |
逻辑地址 0x2e0 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
RSIP_AES_Key1_Read_Protection |
物理地址 0x366[7] |
1 |
1 |
0:启用 RSIP_AES_Key1 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key1 读保护 |
RSIP_AES_Key1_Write_Protection |
物理地址 0x367[0] |
1 |
1 |
0:启用 RSIP_AES_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key1 写保护 |
RSIP_AES_Key2_Read_Protection |
物理地址 0x367[1] |
1 |
1 |
0:启用 RSIP_AES_Key2 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key2 读保护 |
RSIP_AES_Key2_Write_Protection |
物理地址 0x367[2] |
1 |
1 |
0:启用 RSIP_AES_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储 6 组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
AES |
安全 |
0 |
S_IPSEC_Key1 |
AES |
安全 |
1 |
S_IPSEC_Key2 |
AES |
安全 |
2 |
RSIP_AES_Key1 |
AES |
安全 |
3 |
RSIP_AES_Key2 |
AES |
非安全 |
0 |
NS_IPSEC_Key1 |
AES |
非安全 |
1 |
NS_IPSEC_Key2 |
AES |
非安全 |
2 |
RSIP_AES_Key1 |
AES |
非安全 |
3 |
RSIP_AES_Key2 |
备注
上表中 AES 引擎的安全与非安全侧各列出 4 个密钥索引(共 8 项),但其中安全侧与非安全侧的 RSIP_AES_Key1、RSIP_AES_Key2 实际对应**同一组** OTP 物理密钥——该密钥由安全 AES 引擎与非安全 AES 引擎共同自动加载,并非两组独立密钥。去除重复后,OTP 物理存储区中实际仅存在 6 组互不相同的密钥(S_IPSEC_Key1/Key2、NS_IPSEC_Key1/Key2、RSIP_AES_Key1/Key2),这正是前文"OTP 物理存储区支持存储 6 组密钥"的由来。
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动 加载此密钥用于 HMAC 或 AES 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
RSIP_AES_Key1 |
逻辑地址 0x2c0 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全 AES 引擎和安全 AES 引擎 将自动加载此密钥用于 AES 算法 |
RSIP_AES_Key2 |
逻辑地址 0x2e0 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
RSIP_AES_Key1_Read_Protection |
物理地址 0x366[7] |
1 |
1 |
0:启用 RSIP_AES_Key1 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key1 读保护 |
RSIP_AES_Key1_Write_Protection |
物理地址 0x367[0] |
1 |
1 |
0:启用 RSIP_AES_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key1 写保护 |
RSIP_AES_Key2_Read_Protection |
物理地址 0x367[1] |
1 |
1 |
0:启用 RSIP_AES_Key2 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key2 读保护 |
RSIP_AES_Key2_Write_Protection |
物理地址 0x367[2] |
1 |
1 |
0:启用 RSIP_AES_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储 6 组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
AES |
安全 |
0 |
S_IPSEC_Key1 |
AES |
安全 |
1 |
S_IPSEC_Key2 |
AES |
安全 |
2 |
RSIP_AES_Key1 |
AES |
安全 |
3 |
RSIP_AES_Key2 |
AES |
非安全 |
0 |
NS_IPSEC_Key1 |
AES |
非安全 |
1 |
NS_IPSEC_Key2 |
AES |
非安全 |
2 |
RSIP_AES_Key1 |
AES |
非安全 |
3 |
RSIP_AES_Key2 |
备注
上表中 AES 引擎的安全与非安全侧各列出 4 个密钥索引(共 8 项),但其中安全侧与非安全侧的 RSIP_AES_Key1、RSIP_AES_Key2 实际对应**同一组** OTP 物理密钥——该密钥由安全 AES 引擎与非安全 AES 引擎共同自动加载,并非两组独立密钥。去除重复后,OTP 物理存储区中实际仅存在 6 组互不相同的密钥(S_IPSEC_Key1/Key2、NS_IPSEC_Key1/Key2、RSIP_AES_Key1/Key2),这正是前文"OTP 物理存储区支持存储 6 组密钥"的由来。
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动 加载此密钥用于 HMAC 或 AES 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
RSIP_AES_Key1 |
逻辑地址 0x2c0 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全 AES 引擎和安全 AES 引擎 将自动加载此密钥用于 AES 算法 |
RSIP_AES_Key2 |
逻辑地址 0x2e0 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
RSIP_AES_Key1_Read_Protection |
物理地址 0x366[7] |
1 |
1 |
0:启用 RSIP_AES_Key1 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key1 读保护 |
RSIP_AES_Key1_Write_Protection |
物理地址 0x367[0] |
1 |
1 |
0:启用 RSIP_AES_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key1 写保护 |
RSIP_AES_Key2_Read_Protection |
物理地址 0x367[1] |
1 |
1 |
0:启用 RSIP_AES_Key2 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key2 读保护 |
RSIP_AES_Key2_Write_Protection |
物理地址 0x367[2] |
1 |
1 |
0:启用 RSIP_AES_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储 6 组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
AES |
安全 |
0 |
S_IPSEC_Key1 |
AES |
安全 |
1 |
S_IPSEC_Key2 |
AES |
安全 |
2 |
RSIP_AES_Key1 |
AES |
安全 |
3 |
RSIP_AES_Key2 |
AES |
非安全 |
0 |
NS_IPSEC_Key1 |
AES |
非安全 |
1 |
NS_IPSEC_Key2 |
AES |
非安全 |
2 |
RSIP_AES_Key1 |
AES |
非安全 |
3 |
RSIP_AES_Key2 |
备注
上表中 AES 引擎的安全与非安全侧各列出 4 个密钥索引(共 8 项),但其中安全侧与非安全侧的 RSIP_AES_Key1、RSIP_AES_Key2 实际对应**同一组** OTP 物理密钥——该密钥由安全 AES 引擎与非安全 AES 引擎共同自动加载,并非两组独立密钥。去除重复后,OTP 物理存储区中实际仅存在 6 组互不相同的密钥(S_IPSEC_Key1/Key2、NS_IPSEC_Key1/Key2、RSIP_AES_Key1/Key2),这正是前文"OTP 物理存储区支持存储 6 组密钥"的由来。
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动 加载此密钥用于 HMAC 或 AES 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
RSIP_AES_Key1 |
逻辑地址 0x2c0 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全 AES 引擎和安全 AES 引擎 将自动加载此密钥用于 AES 算法 |
RSIP_AES_Key2 |
逻辑地址 0x2e0 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
RSIP_AES_Key1_Read_Protection |
物理地址 0x366[7] |
1 |
1 |
0:启用 RSIP_AES_Key1 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key1 读保护 |
RSIP_AES_Key1_Write_Protection |
物理地址 0x367[0] |
1 |
1 |
0:启用 RSIP_AES_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key1 写保护 |
RSIP_AES_Key2_Read_Protection |
物理地址 0x367[1] |
1 |
1 |
0:启用 RSIP_AES_Key2 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key2 读保护 |
RSIP_AES_Key2_Write_Protection |
物理地址 0x367[2] |
1 |
1 |
0:启用 RSIP_AES_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储 6 组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
AES |
安全 |
0 |
S_IPSEC_Key1 |
AES |
安全 |
1 |
S_IPSEC_Key2 |
AES |
安全 |
2 |
RSIP_AES_Key1 |
AES |
安全 |
3 |
RSIP_AES_Key2 |
AES |
非安全 |
0 |
NS_IPSEC_Key1 |
AES |
非安全 |
1 |
NS_IPSEC_Key2 |
AES |
非安全 |
2 |
RSIP_AES_Key1 |
AES |
非安全 |
3 |
RSIP_AES_Key2 |
备注
上表中 AES 引擎的安全与非安全侧各列出 4 个密钥索引(共 8 项),但其中安全侧与非安全侧的 RSIP_AES_Key1、RSIP_AES_Key2 实际对应**同一组** OTP 物理密钥——该密钥由安全 AES 引擎与非安全 AES 引擎共同自动加载,并非两组独立密钥。去除重复后,OTP 物理存储区中实际仅存在 6 组互不相同的密钥(S_IPSEC_Key1/Key2、NS_IPSEC_Key1/Key2、RSIP_AES_Key1/Key2),这正是前文"OTP 物理存储区支持存储 6 组密钥"的由来。
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动 加载此密钥用于 HMAC 或 AES 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
RSIP_AES_Key1 |
逻辑地址 0x2c0 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全 AES 引擎和安全 AES 引擎 将自动加载此密钥用于 AES 算法 |
RSIP_AES_Key2 |
逻辑地址 0x2e0 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
RSIP_AES_Key1_Read_Protection |
物理地址 0x366[7] |
1 |
1 |
0:启用 RSIP_AES_Key1 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key1 读保护 |
RSIP_AES_Key1_Write_Protection |
物理地址 0x367[0] |
1 |
1 |
0:启用 RSIP_AES_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key1 写保护 |
RSIP_AES_Key2_Read_Protection |
物理地址 0x367[1] |
1 |
1 |
0:启用 RSIP_AES_Key2 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key2 读保护 |
RSIP_AES_Key2_Write_Protection |
物理地址 0x367[2] |
1 |
1 |
0:启用 RSIP_AES_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储 6 组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
AES |
安全 |
0 |
S_IPSEC_Key1 |
AES |
安全 |
1 |
S_IPSEC_Key2 |
AES |
安全 |
2 |
RSIP_AES_Key1 |
AES |
安全 |
3 |
RSIP_AES_Key2 |
AES |
非安全 |
0 |
NS_IPSEC_Key1 |
AES |
非安全 |
1 |
NS_IPSEC_Key2 |
AES |
非安全 |
2 |
RSIP_AES_Key1 |
AES |
非安全 |
3 |
RSIP_AES_Key2 |
备注
上表中 AES 引擎的安全与非安全侧各列出 4 个密钥索引(共 8 项),但其中安全侧与非安全侧的 RSIP_AES_Key1、RSIP_AES_Key2 实际对应**同一组** OTP 物理密钥——该密钥由安全 AES 引擎与非安全 AES 引擎共同自动加载,并非两组独立密钥。去除重复后,OTP 物理存储区中实际仅存在 6 组互不相同的密钥(S_IPSEC_Key1/Key2、NS_IPSEC_Key1/Key2、RSIP_AES_Key1/Key2),这正是前文"OTP 物理存储区支持存储 6 组密钥"的由来。
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动 加载此密钥用于 HMAC 或 AES 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
RSIP_AES_Key1 |
逻辑地址 0x2c0 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全 AES 引擎和安全 AES 引擎 将自动加载此密钥用于 AES 算法 |
RSIP_AES_Key2 |
逻辑地址 0x2e0 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
RSIP_AES_Key1_Read_Protection |
物理地址 0x366[7] |
1 |
1 |
0:启用 RSIP_AES_Key1 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key1 读保护 |
RSIP_AES_Key1_Write_Protection |
物理地址 0x367[0] |
1 |
1 |
0:启用 RSIP_AES_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key1 写保护 |
RSIP_AES_Key2_Read_Protection |
物理地址 0x367[1] |
1 |
1 |
0:启用 RSIP_AES_Key2 读保护,禁止密钥被读出 1:禁用 RSIP_AES_Key2 读保护 |
RSIP_AES_Key2_Write_Protection |
物理地址 0x367[2] |
1 |
1 |
0:启用 RSIP_AES_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 RSIP_AES_Key2 写保护 |
AES 引擎提供三种类型的密钥资源:
安全 OTP 密钥 (ID 0~5):密钥预烧录至 OTP 区域,烧录后可启用读写保护。保护启用后,软件无法读写密钥,仅硬件可使用。默认只能在安全状态下使用,如需在非安全状态使用,需先调用 crypto_aes_share_secure_key API 修改密钥使用权限
安全软件密钥 (ID 33~34):寄存器密钥,可由软件自由配置。只能由安全状态读写,非安全状态无法访问密钥寄存器。如需在安全状态配置、非安全状态使用,需先配置对应的 key share 寄存器位
非安全软件密钥 (ID 35~36):寄存器密钥,在安全或非安全状态下均可读写和使用
备注
AES-XTS 模式需要同时使用两把密钥。
AES密钥ID |
密钥类型 |
长度(比特) |
OTP地址 |
密钥使用权限 |
共享IP |
|---|---|---|---|---|---|
0 |
OTP |
256 |
0x200 |
安全(默认)/非安全 |
与HMAC共享 |
1 |
OTP |
256 |
0x220 |
安全(默认)/非安全 |
与HMAC共享 |
2 |
OTP |
256 |
0x240 |
安全(默认)/非安全 |
与HMAC共享 |
3 |
OTP |
256 |
0x260 |
安全(默认)/非安全 |
与HMAC共享 |
4 |
OTP |
256 |
0x2C0 |
安全(默认)/非安全 |
与RSIP共享 |
5 |
OTP |
256 |
0x2E0 |
安全(默认)/非安全 |
与RSIP共享 |
33 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
仅AES |
34 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
仅AES |
35 |
寄存器 |
256 |
不适用 |
非安全 |
仅AES |
36 |
寄存器 |
256 |
不适用 |
非安全 |
仅AES |
AES 引擎提供三种类型的密钥资源:
安全 OTP 密钥 (ID 0~5):密钥预烧录至 OTP 区域,烧录后可启用读写保护。保护启用后,软件无法读写密钥,仅硬件可使用。默认只能在安全状态下使用,如需在非安全状态使用,需先调用
crypto_aes_share_secure_keyAPI 修改密钥使用权限安全软件密钥 (ID 33):寄存器密钥,可由软件自由配置。只能由安全状态读写,非安全状态无法访问密钥寄存器。如需在安全状态配置、非安全状态使用,需先配置对应的 key share 寄存器位
共享软件密钥 (ID 34):寄存器密钥,在安全或非安全状态下均可读写和使用
备注
AES 密钥支持 128、192、256 位长度
SM4 密钥仅支持 128 位长度
AES密钥ID |
密钥类型 |
长度(比特) |
OTP地址 |
密钥使用权限 |
共享IP |
|---|---|---|---|---|---|
0 |
OTP |
256 |
0x200 |
安全(默认)/非安全 |
与HMAC共享 |
1 |
OTP |
256 |
0x220 |
安全(默认)/非安全 |
与HMAC共享 |
2 |
OTP |
256 |
0x240 |
安全(默认)/非安全 |
与HMAC共享 |
3 |
OTP |
256 |
0x260 |
安全(默认)/非安全 |
与HMAC共享 |
4 |
OTP |
256 |
0x2C0 |
安全(默认)/非安全 |
与RSIP共享 |
5 |
OTP |
256 |
0x2E0 |
安全(默认)/非安全 |
与RSIP共享 |
33 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
与HMAC共享 |
34 |
寄存器 |
256 |
不适用 |
安全/非安全 |
与HMAC共享 |
AES 引擎提供三种类型的密钥资源:
安全 OTP 密钥 (ID 0~7):密钥预烧录至 OTP 区域,烧录后可启用读写保护。保护启用后,软件无法读写密钥,仅硬件可使用。默认只能在安全状态下使用,如需在非安全状态使用,需先调用 crypto_aes_share_secure_key API 修改密钥使用权限
安全软件密钥 (ID 33~34):寄存器密钥,可由软件自由配置。只能由安全状态读写,非安全状态无法访问密钥寄存器。如需在安全状态配置、非安全状态使用,需先配置对应的 key share 寄存器位
非安全软件密钥 (ID 35~36):寄存器密钥,在安全或非安全状态下均可读写和使用
备注
AES-XTS 模式需要同时使用两把密钥。
AES密钥ID |
密钥类型 |
长度(比特) |
OTP地址 |
密钥使用权限 |
共享IP |
|---|---|---|---|---|---|
0 |
OTP |
256 |
0x280 |
安全(默认)/非安全 |
与HMAC共享 |
1 |
OTP |
256 |
0x2A0 |
安全(默认)/非安全 |
与HMAC共享 |
2 |
OTP |
256 |
0x2C0 |
安全(默认)/非安全 |
与HMAC共享 |
3 |
OTP |
256 |
0x2E0 |
安全(默认)/非安全 |
与HMAC共享 |
4 |
OTP |
256 |
0x380 |
安全(默认)/非安全 |
与RSIP共享 |
5 |
OTP |
256 |
0x3A0 |
安全(默认)/非安全 |
与RSIP共享 |
6 |
OTP |
256 |
0x300 |
非安全 |
与HMAC共享 |
7 |
OTP |
256 |
0x320 |
非安全 |
与HMAC共享 |
33 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
仅AES |
34 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
仅AES |
35 |
寄存器 |
256 |
不适用 |
非安全 |
仅AES |
36 |
寄存器 |
256 |
不适用 |
非安全 |
仅AES |
AES 引擎安全
AES 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
AES 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
AES 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
AES 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
AES 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
AES 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
AES 引擎支持 TrustZone 技术,可以自动识别 CPU 的访问是处于安全状态还是非安全状态。
硬件互斥锁机制
引擎内置硬件互斥锁,每次执行运算前 CPU 必须先获取锁,否则无法访问硬件寄存器。
Secure CPU 持有锁时,所有 Non-secure 访问都会被阻止
Non-secure CPU 持有锁时,Secure CPU 可通过专用抢占寄存器强制解除 Non-secure 锁并重置引擎,从而立即获得使用权
每次释放锁时,引擎自动清除硬件和寄存器状态中的敏感信息,防止信息泄漏。
侧信道攻击防护
AES 引擎在运算过程中采用多种技术防止侧信道攻击:
掩码:对中间计算值进行随机化处理,使得功耗或电磁辐射等侧信道信号难以获取有用信息。掩码在每次 AES 初始化时由 TRNG 随机产生
冗余操作:在加密或解密过程中插入额外操作,增加侧信道信号中的噪声,干扰侧信道分析
随机化:打乱操作或数据处理序列,使执行过程难以预测,避免产生可被利用的固定模式
上述技术综合运用,可有效提升引擎抵抗功耗分析、电磁分析等侧信道攻击的能力。
AES 引擎支持 TrustZone 技术,可以自动识别 CPU 的访问是处于安全状态还是非安全状态。
硬件互斥锁机制
引擎内置硬件互斥锁,每次执行运算前 CPU 必须先获取锁,否则无法访问硬件寄存器。
Secure CPU 持有锁时,所有 Non-secure 访问都会被阻止
Non-secure CPU 持有锁时,Secure CPU 可通过专用抢占寄存器强制解除 Non-secure 锁并重置引擎,从而立即获得使用权
每次释放锁时,引擎自动清除硬件和寄存器状态中的敏感信息,防止信息泄漏。
侧信道攻击防护
AES 引擎在运算过程中采用多种技术防止侧信道攻击:
掩码:对中间计算值进行随机化处理,使得功耗或电磁辐射等侧信道信号难以获取有用信息。掩码在每次 AES 初始化时由 TRNG 随机产生
冗余操作:在加密或解密过程中插入额外操作,增加侧信道信号中的噪声,干扰侧信道分析
随机化:打乱操作或数据处理序列,使执行过程难以预测,避免产生可被利用的固定模式
上述技术综合运用,可有效提升引擎抵抗功耗分析、电磁分析等侧信道攻击的能力。
备注
SM4 与 AES 使用相同的安全机制和侧信道攻击防护。
AES 引擎支持 TrustZone 技术,可以自动识别 CPU 的访问是处于安全状态还是非安全状态。
硬件互斥锁机制
引擎内置硬件互斥锁,每次执行运算前 CPU 必须先获取锁,否则无法访问硬件寄存器。
Secure CPU 持有锁时,所有 Non-secure 访问都会被阻止
Non-secure CPU 持有锁时,Secure CPU 可通过专用抢占寄存器强制解除 Non-secure 锁并重置引擎,从而立即获得使用权
每次释放锁时,引擎自动清除硬件和寄存器状态中的敏感信息,防止信息泄漏。
侧信道攻击防护
AES 引擎在运算过程中采用多种技术防止侧信道攻击:
掩码:对中间计算值进行随机化处理,使得功耗或电磁辐射等侧信道信号难以获取有用信息。掩码在每次 AES 初始化时由 TRNG 随机产生
冗余操作:在加密或解密过程中插入额外操作,增加侧信道信号中的噪声,干扰侧信道分析
随机化:打乱操作或数据处理序列,使执行过程难以预测,避免产生可被利用的固定模式
上述技术综合运用,可有效提升引擎抵抗功耗分析、电磁分析等侧信道攻击的能力。
AES 引擎使用模式
DMA 模式
DMA 模式下,AES 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,AES 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,AES 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,AES 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,AES 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,AES 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
AES 引擎支持两种操作方式:DMA 模式和从模式。两种模式都可以使用软件密钥或 OTP 密钥。
DMA 模式
DMA 模式下,AES 引擎使用内部 DMA 控制器的通道 0,直接在内存之间搬运数据并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有很高的运算效率。但需要注意以下约束:
数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致
驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理
如果地址或长度未对齐,系统会在串口日志中打印警告信息
从模式
从模式下,CPU 通过 APB 总线将数据写入 AES 引擎内部的 FIFO,引擎完成运算后返回结果。
该模式适用于小数据量(约 16 字节)的 AES 运算场景,具有以下特点:
没有地址和消息长度对齐限制,使用灵活
可与其他模式组合使用,实现更复杂的加密或消息认证码算法
CPU 参与度较高,适合对性能要求不高的场景
模式选择建议
大数据量加解密 (如文件加密):优先使用 DMA 模式,确保数据对齐以获得最佳性能
小数据量运算 (如密钥派生):可使用从模式,简化对齐处理
组合算法 (如 AES-GCM):从模式与其他模式配合,实现复杂加密流程
AES 引擎支持两种操作方式:DMA 模式和从模式。两种模式都可以使用软件密钥或 OTP 密钥。
DMA 模式
DMA 模式下,AES 引擎使用内部 DMA 控制器的通道 0,在内存间搬运数据并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有很高的运算效率。但需要注意以下约束:
数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存不一致
驱动已自动处理缓存清理和缓存无效化操作,用户无需额外处理
如果地址或长度未对齐,系统会在串口打印警告信息
从模式
从模式下,CPU 通过 APB 总线将数据写入 AES 引擎内部的 FIFO,引擎完成运算后返回结果。
该模式适用于小数据量(约 16 字节)的 AES 运算场景,具有以下特点:
没有地址和消息长度对齐限制,使用灵活
可与其他模式组合使用,实现更复杂的加密或消息认证码算法
CPU 参与度较高,适合对性能要求不高的场景
模式选择建议
大数据量加解密 (如文件加密):优先使用 DMA 模式,确保数据对齐以获得最佳性能
小数据量运算 (如密钥派生):可使用从模式,简化对齐处理
组合算法 (如 AES-GCM、AES-CCM):从模式与其他模式配合,实现复杂加密流程
备注
SM4 与 AES 使用相同的操作模式。
AES 引擎支持两种操作方式:DMA 模式和从模式。两种模式都可以使用软件密钥或 OTP 密钥。
DMA 模式
DMA 模式下,AES 引擎使用内部 DMA 控制器的通道 0,直接在内存之间搬运数据并在传输过程中完成加密或解密。
该模式适用于大数据量的加解密场景,具有很高的运算效率。但需要注意以下约束:
数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致
驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理
如果地址或长度未对齐,系统会在串口日志中打印警告信息
从模式
从模式下,CPU 通过 APB 总线将数据写入 AES 引擎内部的 FIFO,引擎完成运算后返回结果。
该模式适用于小数据量(约 16 字节)的 AES 运算场景,具有以下特点:
没有地址和消息长度对齐限制,使用灵活
可与其他模式组合使用,实现更复杂的加密或消息认证码算法
CPU 参与度较高,适合对性能要求不高的场景
模式选择建议
大数据量加解密 (如文件加密):优先使用 DMA 模式,确保数据对齐以获得最佳性能
小数据量运算 (如密钥派生):可使用从模式,简化对齐处理
组合算法 (如 AES-GCM):从模式与其他模式配合,实现复杂加密流程
AES API
Realtek 提供了 ROM API,用户无需关注具体的寄存器操作。为提升易用性,AES 硬件加速引擎已集成到 MbedTLS 中。
受软硬件限制,MbedTLS 的 CMAC 和 AES-GCM 算法未实现硬件加速,用户执行这两种运算时可直接调用 ROM API 以获得更好的性能。
MbedTLS API 仅支持软件密钥,使用 OTP 密钥时需调用 ROM API。
HMAC 引擎
HMAC 引擎是一款用于计算 HMAC、SHA2 的硬件加速器,支持消息自动填充。HMAC 算法支持软件寄存器密钥和硬件 OTP 密钥。
HMAC 算法支持
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
支持的密钥大小:AES-128,AES-192,AES-256
支持的加解密模式:
ECB (Electronic Codebook)
CBC (Cipher Block Chaining)
OFB (Output Feedback)
CFB (Cipher Feedback)
CTR (Counter)
GCM (Galois/Counter)
通用哈希函数
SHA2-224
SHA2-256
SHA2-384
SHA2-512
HMAC(基于哈希的消息认证码)
HMAC-SHA2-224
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512
通用哈希函数
SHA2-224
SHA2-256
SHA2-384
SHA2-512
SM3(256 位摘要)
HMAC(基于哈希的消息认证码)
HMAC-SHA2-224
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512
HMAC-SM3
备注
SM3 与 SHA2 使用相同的硬件引擎,通过 SM3_MODE 位选择算法核心。SM3 采用 64 字节块大小,与 SHA-256 相同。
通用哈希函数
SHA2-224
SHA2-256
SHA2-384
SHA2-512
HMAC(基于哈希的消息认证码)
HMAC-SHA2-224
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512
HMAC 密钥
HMAC 引擎配备独立的密钥管理单元,支持软件密钥和 OTP 硬件密钥。
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储多组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
SHA HMAC |
安全 |
0 |
S_IPSEC_Key1 |
SHA HMAC |
安全 |
1 |
S_IPSEC_Key2 |
SHA HMAC |
非安全 |
0 |
NS_IPSEC_Key1 |
SHA HMAC |
非安全 |
1 |
NS_IPSEC_Key2 |
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动加载此密钥 用于 HMAC 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
NS_IPSEC_Key1_Read_Protection |
物理地址 0x365[7] |
1 |
1 |
0:启用 NS_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key1 读保护 |
NS_IPSEC_Key1_Write_Protection |
物理地址 0x366[0] |
1 |
1 |
0:启用 NS_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key1 写保护 |
NS_IPSEC_Key2_Read_Protection |
物理地址 0x366[1] |
1 |
1 |
0:启用 NS_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key2 读保护 |
NS_IPSEC_Key2_Write_Protection |
物理地址 0x366[2] |
1 |
1 |
0:启用 NS_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储多组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
SHA HMAC |
安全 |
0 |
S_IPSEC_Key1 |
SHA HMAC |
安全 |
1 |
S_IPSEC_Key2 |
SHA HMAC |
非安全 |
0 |
NS_IPSEC_Key1 |
SHA HMAC |
非安全 |
1 |
NS_IPSEC_Key2 |
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动加载此密钥 用于 HMAC 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
NS_IPSEC_Key1_Read_Protection |
物理地址 0x365[7] |
1 |
1 |
0:启用 NS_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key1 读保护 |
NS_IPSEC_Key1_Write_Protection |
物理地址 0x366[0] |
1 |
1 |
0:启用 NS_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key1 写保护 |
NS_IPSEC_Key2_Read_Protection |
物理地址 0x366[1] |
1 |
1 |
0:启用 NS_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key2 读保护 |
NS_IPSEC_Key2_Write_Protection |
物理地址 0x366[2] |
1 |
1 |
0:启用 NS_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储多组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
SHA HMAC |
安全 |
0 |
S_IPSEC_Key1 |
SHA HMAC |
安全 |
1 |
S_IPSEC_Key2 |
SHA HMAC |
非安全 |
0 |
NS_IPSEC_Key1 |
SHA HMAC |
非安全 |
1 |
NS_IPSEC_Key2 |
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动加载此密钥 用于 HMAC 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
NS_IPSEC_Key1_Read_Protection |
物理地址 0x365[7] |
1 |
1 |
0:启用 NS_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key1 读保护 |
NS_IPSEC_Key1_Write_Protection |
物理地址 0x366[0] |
1 |
1 |
0:启用 NS_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key1 写保护 |
NS_IPSEC_Key2_Read_Protection |
物理地址 0x366[1] |
1 |
1 |
0:启用 NS_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key2 读保护 |
NS_IPSEC_Key2_Write_Protection |
物理地址 0x366[2] |
1 |
1 |
0:启用 NS_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储多组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
SHA HMAC |
安全 |
0 |
S_IPSEC_Key1 |
SHA HMAC |
安全 |
1 |
S_IPSEC_Key2 |
SHA HMAC |
非安全 |
0 |
NS_IPSEC_Key1 |
SHA HMAC |
非安全 |
1 |
NS_IPSEC_Key2 |
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动加载此密钥 用于 HMAC 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
NS_IPSEC_Key1_Read_Protection |
物理地址 0x365[7] |
1 |
1 |
0:启用 NS_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key1 读保护 |
NS_IPSEC_Key1_Write_Protection |
物理地址 0x366[0] |
1 |
1 |
0:启用 NS_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key1 写保护 |
NS_IPSEC_Key2_Read_Protection |
物理地址 0x366[1] |
1 |
1 |
0:启用 NS_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key2 读保护 |
NS_IPSEC_Key2_Write_Protection |
物理地址 0x366[2] |
1 |
1 |
0:启用 NS_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储多组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
SHA HMAC |
安全 |
0 |
S_IPSEC_Key1 |
SHA HMAC |
安全 |
1 |
S_IPSEC_Key2 |
SHA HMAC |
非安全 |
0 |
NS_IPSEC_Key1 |
SHA HMAC |
非安全 |
1 |
NS_IPSEC_Key2 |
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动加载此密钥 用于 HMAC 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
NS_IPSEC_Key1_Read_Protection |
物理地址 0x365[7] |
1 |
1 |
0:启用 NS_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key1 读保护 |
NS_IPSEC_Key1_Write_Protection |
物理地址 0x366[0] |
1 |
1 |
0:启用 NS_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key1 写保护 |
NS_IPSEC_Key2_Read_Protection |
物理地址 0x366[1] |
1 |
1 |
0:启用 NS_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key2 读保护 |
NS_IPSEC_Key2_Write_Protection |
物理地址 0x366[2] |
1 |
1 |
0:启用 NS_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key2 写保护 |
硬件加密引擎提供两种密钥加载方式:
软件传递:密钥由应用程序动态传入,软件可访问
OTP 自动加载:密钥预烧录至 OTP 物理存储区,软件无法访问,仅加密引擎可访问,防止被篡改或读取
OTP 物理存储区支持存储多组密钥,需通过串口命令烧录。
引擎类型 |
安全性 |
密钥索引 |
OTP 密钥 |
|---|---|---|---|
SHA HMAC |
安全 |
0 |
S_IPSEC_Key1 |
SHA HMAC |
安全 |
1 |
S_IPSEC_Key2 |
SHA HMAC |
非安全 |
0 |
NS_IPSEC_Key1 |
SHA HMAC |
非安全 |
1 |
NS_IPSEC_Key2 |
OTP 密钥的详细功能如下所示:
OTP 密钥名称 |
地址 |
比特数 |
默认值 |
描述 |
|---|---|---|---|---|
S_IPSEC_Key1 (RDP) |
逻辑地址 0x200 |
256 |
0xFF |
启用 OTPKey_init 功能时,安全加密引擎将自动加载此密钥 用于 HMAC 或 AES 算法 |
S_IPSEC_Key2 (安全启动 HMAC) |
逻辑地址 0x220 |
256 |
0xFF |
|
NS_IPSEC_Key1 |
逻辑地址 0x240 |
256 |
0xFF |
启用 OTPKey_init 功能时,非安全加密引擎将自动加载此密钥 用于 HMAC 算法 |
NS_IPSEC_Key2 |
逻辑地址 0x260 |
256 |
0xFF |
|
S_IPSEC_Key1_Read_Protection |
物理地址 0x365[3] |
1 |
1 |
0:启用 S_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key1 读保护 |
S_IPSEC_Key1_Write_Protection |
物理地址 0x365[4] |
1 |
1 |
0:启用 S_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key1 写保护 |
S_IPSEC_Key2_Read_Protection |
物理地址 0x365[5] |
1 |
1 |
0:启用 S_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 S_IPSEC_Key2 读保护 |
S_IPSEC_Key2_Write_Protection |
物理地址 0x365[6] |
1 |
1 |
0:启用 S_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 S_IPSEC_Key2 写保护 |
NS_IPSEC_Key1_Read_Protection |
物理地址 0x365[7] |
1 |
1 |
0:启用 NS_IPSEC_Key1 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key1 读保护 |
NS_IPSEC_Key1_Write_Protection |
物理地址 0x366[0] |
1 |
1 |
0:启用 NS_IPSEC_Key1 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key1 写保护 |
NS_IPSEC_Key2_Read_Protection |
物理地址 0x366[1] |
1 |
1 |
0:启用 NS_IPSEC_Key2 读保护,禁止密钥被读出 1:禁用 NS_IPSEC_Key2 读保护 |
NS_IPSEC_Key2_Write_Protection |
物理地址 0x366[2] |
1 |
1 |
0:启用 NS_IPSEC_Key2 写保护,禁止密钥被攻击者篡改为全 0 1:禁用 NS_IPSEC_Key2 写保护 |
HMAC 引擎提供三种类型的密钥资源:
安全 OTP 密钥 (ID 0~3):密钥预烧录至 OTP 区域,烧录后可启用读写保护。保护启用后,软件无法读写密钥,仅硬件可使用。默认只能在安全状态下使用,如需在非安全状态使用,需先调用 crypto_hmac_sha2_share_secure_key API 修改密钥使用权限
安全软件密钥 (ID 33):寄存器密钥,可由软件自由配置。只能由安全状态读写,非安全状态无法访问密钥寄存器。如需在安全状态配置、非安全状态使用,需先配置对应的 key share 寄存器位
非安全软件密钥 (ID 34):寄存器密钥,在安全或非安全状态下均可读写和使用
HMAC密钥ID |
密钥类型 |
长度(比特) |
OTP地址 |
密钥使用权限 |
共享IP |
|---|---|---|---|---|---|
0 |
OTP |
256 |
0x200 |
安全(默认)/非安全 |
与AES共享 |
1 |
OTP |
256 |
0x220 |
安全(默认)/非安全 |
与AES共享 |
2 |
OTP |
256 |
0x240 |
安全(默认)/非安全 |
与AES共享 |
3 |
OTP |
256 |
0x260 |
安全(默认)/非安全 |
与AES共享 |
33 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
仅HMAC |
34 |
寄存器 |
256 |
不适用 |
非安全 |
仅HMAC |
HMAC 引擎提供三种类型的密钥资源:
安全 OTP 密钥 (ID 0~5):密钥预烧录至 OTP 区域,烧录后可启用读写保护。保护启用后,软件无法读写密钥,仅硬件可使用。默认只能在安全状态下使用,如需在非安全状态使用,需先调用
crypto_hmac_share_secure_keyAPI 修改密钥使用权限安全软件密钥 (ID 33):寄存器密钥,可由软件自由配置。只能由安全状态读写,非安全状态无法访问密钥寄存器。如需在安全状态配置、非安全状态使用,需先配置对应的 key share 寄存器位
共享软件密钥 (ID 34):寄存器密钥,在安全或非安全状态下均可读写和使用
备注
HMAC 密钥支持 128、192、256 位长度。SM3-HMAC 同样使用这些密钥资源。
HMAC密钥ID |
密钥类型 |
长度(比特) |
OTP地址 |
密钥使用权限 |
共享IP |
|---|---|---|---|---|---|
0 |
OTP |
256 |
0x200 |
安全(默认)/非安全 |
与AES共享 |
1 |
OTP |
256 |
0x220 |
安全(默认)/非安全 |
与AES共享 |
2 |
OTP |
256 |
0x240 |
安全(默认)/非安全 |
与AES共享 |
3 |
OTP |
256 |
0x260 |
安全(默认)/非安全 |
与AES共享 |
4 |
OTP |
256 |
0x2C0 |
安全(默认)/非安全 |
与RSIP共享 |
5 |
OTP |
256 |
0x2E0 |
安全(默认)/非安全 |
与RSIP共享 |
33 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
与AES共享 |
34 |
寄存器 |
256 |
不适用 |
安全/非安全 |
与AES共享 |
HMAC 引擎提供三种类型的密钥资源:
安全 OTP 密钥 (ID 0~5):密钥预烧录至 OTP 区域,烧录后可启用读写保护。保护启用后,软件无法读写密钥,仅硬件可使用。默认只能在安全状态下使用,如需在非安全状态使用,需先调用 crypto_hmac_sha2_share_secure_key API 修改密钥使用权限
安全软件密钥 (ID 33):寄存器密钥,可由软件自由配置。只能由安全状态读写,非安全状态无法访问密钥寄存器。如需在安全状态配置、非安全状态使用,需先配置对应的 key share 寄存器位
非安全软件密钥 (ID 34):寄存器密钥,在安全或非安全状态下均可读写和使用
HMAC密钥ID |
密钥类型 |
长度(比特) |
OTP地址 |
密钥使用权限 |
共享IP |
|---|---|---|---|---|---|
0 |
OTP |
256 |
0x280 |
安全(默认)/非安全 |
与AES共享 |
1 |
OTP |
256 |
0x2A0 |
安全(默认)/非安全 |
与AES共享 |
2 |
OTP |
256 |
0x2C0 |
安全(默认)/非安全 |
与AES共享 |
3 |
OTP |
256 |
0x2E0 |
安全(默认)/非安全 |
与AES共享 |
4 |
OTP |
256 |
0x300 |
非安全 |
与AES共享 |
5 |
OTP |
256 |
0x320 |
非安全 |
与AES共享 |
33 |
寄存器 |
256 |
不适用 |
安全(默认)/非安全 |
仅HMAC |
34 |
寄存器 |
256 |
不适用 |
非安全 |
仅HMAC |
HMAC 引擎安全
HASH 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
HASH 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
HASH 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
HASH 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
HASH 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
HASH 架构通过硬件级隔离和智能仲裁,在保证安全性的同时实现高效加密处理:
两套独立寄存器组:
安全地址空间:0x5XXX_XXXX,映射到安全专用寄存器
非安全地址空间:0x4XXX_XXXX,映射到非安全专用寄存器
当安全域与非安全域同时请求加密引擎时的仲裁机制:
基础策略:轮询调度+FIFO 状态优先(满者优先)
原子性保障:必须完成整轮加密操作(LS=1)才切换引擎控制权
中断机制:
物理隔离设计:安全与非安全中断连接至不同的中断号
错误隔离上报:总线错误同时触发双中断,但需独立清除
特殊设定:中断安全属性仅支持硬件自动切换
引擎算法已通过 NIST CAVP 认证。
HASH 引擎支持 TrustZone 技术,可以自动识别 CPU 的访问是处于安全状态还是非安全状态。
硬件互斥锁机制
引擎内置硬件互斥锁,每次执行运算前 CPU 必须先获取锁,否则无法访问硬件寄存器。
Secure CPU 持有锁时,所有 Non-secure 访问都会被阻止
Non-secure CPU 持有锁时,Secure CPU 可通过专用抢占寄存器强制解除 Non-secure 锁并重置引擎,从而立即获得使用权
每次释放锁时,引擎自动清除硬件和寄存器状态中的敏感信息,防止信息泄漏。
HMAC 引擎支持 TrustZone 技术,可以自动识别 CPU 的访问是处于安全状态还是非安全状态。
硬件互斥锁机制
引擎内置硬件互斥锁,每次执行运算前 CPU 必须先获取锁,否则无法访问硬件寄存器。
Secure CPU 持有锁时,所有 Non-secure 访问都会被阻止
Non-secure CPU 持有锁时,Secure CPU 可通过专用抢占寄存器强制解除 Non-secure 锁并重置引擎,从而立即获得使用权
每次释放锁时,引擎自动清除硬件和寄存器状态中的敏感信息,防止信息泄漏。
备注
SM3 与 SHA2 使用相同的安全机制。
引擎算法已通过 NIST CAVP 认证。
HASH 引擎支持 TrustZone 技术,可以自动识别 CPU 的访问是处于安全状态还是非安全状态。
硬件互斥锁机制
引擎内置硬件互斥锁,每次执行运算前 CPU 必须先获取锁,否则无法访问硬件寄存器。
Secure CPU 持有锁时,所有 Non-secure 访问都会被阻止
Non-secure CPU 持有锁时,Secure CPU 可通过专用抢占寄存器强制解除 Non-secure 锁并重置引擎,从而立即获得使用权
每次释放锁时,引擎自动清除硬件和寄存器状态中的敏感信息,防止信息泄漏。
HMAC 引擎使用模式
DMA 模式
DMA 模式下,HASH 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中计算 HMAC。
该模式适用于大数据量的运算场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,HASH 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中计算 HMAC。
该模式适用于大数据量的运算场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,HASH 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中计算 HMAC。
该模式适用于大数据量的运算场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,HASH 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中计算 HMAC。
该模式适用于大数据量的运算场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,HASH 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中计算 HMAC。
该模式适用于大数据量的运算场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
DMA 模式
DMA 模式下,HASH 引擎使用 DMA 在内存和 FIFO 之间搬运数据,并在传输过程中计算 HMAC。
该模式适用于大数据量的运算场景,具有较高的运算效率。但数据地址和长度必须按 32 字节(缓存行长度)对齐,否则可能导致缓存数据不一致。驱动已自动处理源地址的缓存清理和目的地址的缓存无效化操作,用户无需额外处理。
如果地址或长度未对齐,系统会在串口日志中打印警告信息。
HMAC 引擎支持两种操作方式:DMA 模式和从模式。两种模式都可以使用软件密钥或 OTP 密钥。
DMA 模式
HMAC 引擎与 AES 引擎共用同一个 DMA 控制器,但使用独立的通道 1。
DMA 模式下,HMAC 引擎支持只读模式和拷贝模式:
只读模式:启动时仅指定源数据地址,引擎从该地址读取数据并计算哈希值,适用于数据完整性校验场景
拷贝模式:启动时需同时指定源地址和目的地址,引擎在计算哈希的同时将数据搬运到目的地址,适用于拷贝校验场景
从模式
从模式下,CPU 通过 APB 总线将消息写入引擎内部的 FIFO,然后读出哈希值。
该模式由底层驱动内部使用,用户无需关注具体实现细节。
HMAC 引擎支持两种操作方式:DMA 模式和从模式。两种模式都可以使用软件密钥或 OTP 密钥。
DMA 模式
HMAC 引擎与 AES 引擎共用同一个 DMA 控制器,但使用独立的通道 1。
DMA 模式下,HMAC 引擎支持只读模式和拷贝模式:
只读模式:启动时仅指定源数据地址,引擎从该地址读取数据并计算哈希值,适用于数据完整性校验场景
拷贝模式:启动时需同时指定源地址和目的地址,引擎在计算哈希的同时将数据搬运到目的地址,适用于拷贝校验场景
从模式
从模式下,CPU 通过 APB 总线将消息写入引擎内部的 FIFO,然后读出哈希值。
该模式由底层驱动内部使用,用户无需关注具体实现细节。
备注
SM3 与 SHA2 使用相同的操作模式。
HMAC 引擎支持两种操作方式:DMA 模式和从模式。两种模式都可以使用软件密钥或 OTP 密钥。
DMA 模式
HMAC 引擎与 AES 引擎共用同一个 DMA 控制器,但使用独立的通道 1。
DMA 模式下,HMAC 引擎支持只读模式和拷贝模式:
只读模式:启动时仅指定源数据地址,引擎从该地址读取数据并计算哈希值,适用于数据完整性校验场景
拷贝模式:启动时需同时指定源地址和目的地址,引擎在计算哈希的同时将数据搬运到目的地址,适用于拷贝校验场景
从模式
从模式下,CPU 通过 APB 总线将消息写入引擎内部的 FIFO,然后读出哈希值。
该模式由底层驱动内部使用,用户无需关注具体实现细节。
HMAC API
与 AES 引擎类似,Realtek 提供了 HMAC 底层 API,用户无需关注具体的寄存器操作。为提升易用性,SHA2 硬件加速引擎已集成到 MbedTLS 的 SHA2-Hash 和 HMAC API 中。SHA1、MD5 等其他哈希算法未实现硬件加速。
MbedTLS API 仅支持软件密钥。使用 OTP 密钥或 DMA 拷贝模式时,需调用底层 API。
密钥字节序
Crypto Engine 的密钥字节序与 MbedTLS 的数据结构相同,均采用小端序(little-endian)。 以下以 256-bit 密钥为例,说明从可读的十六进制字符串转换为数组并烧录至 OTP 的正确字节顺序。
开发阶段:密钥数组写法
在开发阶段,应用程序以字节数组形式将密钥传递给硬件 API,数组需按小端序排列。示例数组为 32 字节:
/* 256-bit key, little-endian byte order */
uint8_t key1[32] = {
0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01
};
生产阶段:OTP 密钥烧录
生产阶段需将密钥烧录至 OTP 物理存储区。以下以 NS_IPSEC_Key2 为例,使用 AT+OTP=WRAW 串口烧录命令 写入 OTP 0x260 物理地址(长度 0x20,32 字节):
AT+OTP=WRAW,0x260,0x20,ffeeddccbbaa99887766554433221100efcdab8967452301efcdab8967452301
量产阶段在密钥写入后,必须按照上述 OTP 表格的说明启用密钥读取保护和写入保护,防止 OTP 密钥被篡改或泄露。
备注
上述示例以 32 字节 NS_IPSEC_Key2 密钥为例,实际地址与长度需根据实际需要调整。
注意 OTP 烧录并重启系统后,OTP 密钥才能加载到引擎中。
此字节序规则适用于所有 IC 型号。
OTP 密钥内容对应
上述指令写入后,OTP 物理地址区段中的实际内容:
Address |
b0 |
b1 |
b2 |
b3 |
b4 |
b5 |
b6 |
b7 |
b8 |
b9 |
b10 |
b11 |
b12 |
b13 |
b14 |
b15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0x260 |
ff |
ee |
dd |
cc |
bb |
aa |
99 |
88 |
77 |
66 |
55 |
44 |
33 |
22 |
11 |
00 |
0x270 |
ef |
cd |
ab |
89 |
67 |
45 |
23 |
01 |
ef |
cd |
ab |
89 |
67 |
45 |
23 |
01 |
Raw API
AES Exported Types
-
struct AES_InitTypeDef
AES Init Structure Definition.
Public Members
-
u32 CipherMode
Specifies the AES cipher mode. This parameter can be a value of AES Cipher Mode.
-
u32 EngineMode
Specifies the AES engine mode. This parameter can be a value of AES Engine Mode.
-
u32 IsEnc
Specifies AES encrypt or decrypt. This parameter can be TRUE or FALSE.
-
u32 CipherLen
Specifies the AES cipher length in bytes.
-
u32 key_len
AES key length in bits. This parameter can be a value of AES Key Size.
-
u32 CipherMode
SHA Exported Types
-
struct SHA_InitTypeDef
SHA Init Structure Definition.
Public Members
-
u32 EngineMode
Specifies the SHA engine mode. This parameter can be a value of SHA Engine Mode.
-
u32 IcgEn
Specifies enable or disable SHA auto clock gating. This parameter can be ENABLE or DISABLE.
-
u32 DmaMode
Specifies SHA DMA mode. This parameter can be a value of SHA DMA Mode.
-
u32 HmacMode
Specifies the HMAC mode. This parameter can be a value of SHA HMAC Mode.
-
u32 EngineMode
-
struct SHA_context
SHA Context Structure Definition.
Public Members
-
u32 hmac_mode
HMAC operation mode. 0x0: hash mode. 0x1: HMAC mode.
-
u32 block_size
Block size. This parameter can be a value of SHA Block Size.
-
u32 ilen_bytes
Bytes occupied by input length storage.
-
u32 digest_len
Digest length.
-
u32 state[16]
Digest state
-
u8 buffer[128]
Data block being processed
-
u32 buf_used_bytes
Buffer bytes used
-
u32 total_len
The total number of data bytes to be processed
-
u8 dma_copy
DMA operation mode. 0x0: read-only mode. 0x1: copy mode
-
u8 seq_hash_first
Flag for sequential hash: 1 = this is the first block, 0 = subsequent block
-
u8 key_id
Key management key ID used for HMAC
-
u32 key_len_bits
HMAC key length in bits
-
u32 DMA_CTL_LOW
DMA control register low word value cached for this context
-
u32 hmac_mode
Hash Engine Mode
Not supported.
-
enum hash_engine_mode
Hash engine selector for SHA-2 and SM3 algorithms.
Values:
/* Use SHA-2 engine (supports SHA-224/256/384/512) */ HASH_SHA2_MODE = 0 /* Use SM3 engine */ HASH_SM3_MODE = 1
Crypto Symmetric Cipher Exported Types
Crypto Engine Mode
Not supported.
-
enum crypto_engine_mode
Cipher engine selector for unified symmetric cipher APIs.
Values:
/* Use AES cipher engine */ CRYPTO_AES_MODE = 0 /* Use SM4 cipher engine */ CRYPTO_SM4_MODE = 1
AES Exported Constants
AES Byte Swap Defaults
/* Default byte swap: key in native order, no swap */
#define AES_BYTE_SWAP_DEFAULTS AES_BIT_KEY_SWAP_DISABLE
/* Byte swap setting: key swap disabled (both key and payload in native order) */
#define AES_BYTE_SWAP_KEY_SWAP ((u32) 0x00)
AES Cipher Mode
/* AES encryption direction */
#define CIPHER_ENCRYPTION_MODE ((u8)0x01)
/* AES decryption direction */
#define CIPHER_DECRYPTION_MODE ((u8)0x00)
/* Electronic Codebook mode */
#define CIPHER_MODE_ECB ((u8)0x00)
/* Cipher Block Chaining mode */
#define CIPHER_MODE_CBC ((u8)0x01)
/* Cipher Feedback mode */
#define CIPHER_MODE_CFB ((u8)0x02)
/* Output Feedback mode */
#define CIPHER_MODE_OFB ((u8)0x03)
/* Counter mode */
#define CIPHER_MODE_CTR ((u8)0x04)
/* Galois Message Authentication Code mode */
#define CIPHER_MODE_GMAC ((u8)0x05)
/* Galois/Counter Mode (authenticated encryption) */
#define CIPHER_MODE_GCM ((u8)0x06)
/* Cipher-based Message Authentication Code mode */
#define CIPHER_MODE_CMAC ((u8)0x07)
/* XEX-based tweaked-codebook mode with ciphertext stealing */
#define CIPHER_MODE_XTS ((u8)0x08)
/* Check whether MODE is a valid AES cipher mode. */
#define IS_AES_CIPHER_MODE (((MODE) == CIPHER_MODE_ECB) || \
((MODE) == CIPHER_MODE_CBC) || \
((MODE) == CIPHER_MODE_CFB) || \
((MODE) == CIPHER_MODE_OFB) || \
((MODE) == CIPHER_MODE_CTR) || \
((MODE) == CIPHER_MODE_GMAC) || \
((MODE) == CIPHER_MODE_GCM) || \
((MODE) == CIPHER_MODE_CMAC) || \
((MODE) == CIPHER_MODE_XTS))
/* CBC-MAC mode */
#define CIPHER_MODE_CBC_MAC ((u8)0x09)
/* Counter with CBC-MAC mode (authenticated encryption) */
#define CIPHER_MODE_CCM ((u8)0x0A)
/* Check whether MODE is a valid AES cipher mode. */
#define IS_AES_CIPHER_MODE (((MODE) == CIPHER_MODE_ECB) || \
((MODE) == CIPHER_MODE_CBC) || \
((MODE) == CIPHER_MODE_CFB) || \
((MODE) == CIPHER_MODE_OFB) || \
((MODE) == CIPHER_MODE_CTR) || \
((MODE) == CIPHER_MODE_GMAC) || \
((MODE) == CIPHER_MODE_GCM) || \
((MODE) == CIPHER_MODE_CMAC))
AES DMA Size
/* AES block size in bytes */
#define AES_BLOCK_SIZE 16
/* AES block size in bits */
#define AES_BLOCK_SIZE_BIT 128
/* Maximum DMA block transfer size in transfer units */
#define AES_DMA_MAX_BLOCK_TS 536870910
/* Maximum DMA transfer size in bytes */
#define AES_DMA_MAX_BLOCK_BYTE (AES_DMA_MAX_BLOCK_TS * 1)
AES DMA Settings
/* DMA channel number for AES transfers */
#define AES_DMA_CH_NUM 0
/* DMA channel enable mask bit for AES */
#define AES_DMA_CH_MASK ((u32)0x00000001 << AES_DMA_CH_NUM)
AES Engine Mode
/* Slave mode: plaintext written directly to hardware registers */
#define AES_SLAVE_MODE ((u8)0x00)
/* DMA mode: plaintext transferred via DMA */
#define AES_DMA_MODE ((u8)0x01)
/* Check whether MODE is a valid AES engine mode. */
#define IS_AES_ENGINE_MODE (((MODE) == AES_SLAVE_MODE) || \
((MODE) == AES_DMA_MODE))
AES Key Size
/* Key size 128 bits */
#define AES_KEY_SIZE_128 ((u8)0x00)
/* Key size 192 bits */
#define AES_KEY_SIZE_192 ((u8)0x01)
/* Key size 256 bits */
#define AES_KEY_SIZE_256 ((u8)0x02)
AES Timeout
/* DMA mode operation timeout count */
#define AES_DMA_TIMEOUT ((u32) 10000000)
/* Engine mutex acquisition timeout count */
#define AES_MUTEX_TIMEOUT ((u32) 1000000)
/* Slave mode operation timeout count */
#define AES_SLAVE_TIMEOUT ((u32) 10000)
Crypto Block Size
Not supported.
/* AES/cipher block size in bytes */
#define CIPHER_BLOCK_SIZE 16
HW_CRYPTO_ENGINE Exported Constants
Crypto Key
/* 128 bits */
#define KEY_BIT_128 (128)
/* 192 bits */
#define KEY_BIT_192 (192)
/* 256 bits */
#define KEY_BIT_256 (256)
/* Reverse the byte order of a 32-bit word (swap big-endian and little-endian). */
#define BIG_LITTLE_SWAP32 ( (((*(long int *)&x) & 0xff000000) >> 24) | \
(((*(long int *)&x) & 0x00ff0000) >> 8) | \
(((*(long int *)&x) & 0x0000ff00) << 8) | \
(((*(long int *)&x) & 0x000000ff) << 24) )
/* Check whether LEN is a valid AES key length in bits. */
#define IS_KEY_LEN_BIT (((LEN) == KEY_BIT_128) || \
((LEN) == KEY_BIT_192) || \
((LEN) == KEY_BIT_256))
/* Check whether LEN is a valid AES key length in bits. */
#define CRYPTO_IS_KEY_LEN_BIT (((LEN) == KEY_BIT_128) || \
((LEN) == KEY_BIT_192) || \
((LEN) == KEY_BIT_256))
Crypto Process Status
/* Descriptor number out of valid range */
#define _ERRNO_CRYPTO_DESC_NUM_SET_OutRange -2
/* DMA burst number out of valid range */
#define _ERRNO_CRYPTO_BURST_NUM_SET_OutRange -3
/* NULL pointer passed as argument */
#define _ERRNO_CRYPTO_NULL_POINTER -4
/* Crypto engine not initialized */
#define _ERRNO_CRYPTO_ENGINE_NOT_INIT -5
/* Buffer address not 4-byte aligned */
#define _ERRNO_CRYPTO_ADDR_NOT_4Byte_Aligned -6
/* Key index out of valid range */
#define _ERRNO_CRYPTO_KEY_OutRange -7
/* Message length out of valid range */
#define _ERRNO_CRYPTO_MSG_OutRange -8
/* IV length out of valid range */
#define _ERRNO_CRYPTO_IV_OutRange -9
/* Authentication type mismatch */
#define _ERRNO_CRYPTO_AUTH_TYPE_NOT_MATCH -10
/* Cipher type mismatch */
#define _ERRNO_CRYPTO_CIPHER_TYPE_NOT_MATCH -11
/* Key and IV length mismatch */
#define _ERRNO_CRYPTO_KEY_IV_LEN_DIFF -12
/* hash_final called without prior hash_update */
#define _ERRNO_CRYPTO_HASH_FINAL_NO_UPDATE -13
/* Secure key access error */
#define _ERRNO_CRYPTO_KEY_SECURE_ERR -14
/* Invalid key length */
#define _ERRNO_CRYPTO_KEY_LENGTH_ERR -15
/* Key load failure */
#define _ERRNO_CRYPTO_KEY_LOAD_ERR -16
/* DMA transfer error */
#define _ERRNO_CRYPTO_DMA_ERR -17
/* Invalid message length */
#define _ERRNO_CRYPTO_MESSAGE_LEN_ERR -18
/* Tag length out of valid range */
#define _ERRNO_CRYPTO_TAG_OutRange -19
/* GCM authentication tag verification failed */
#define _ERRNO_CRYPTO_GCM_TAG_NOT_MATCH -20
/* Slave mode operation timeout */
#define _ERRNO_CRYPTO_SLAVE_TIME_OUT -21
/* Slave mode hardware error */
#define _ERRNO_CRYPTO_SLAVE_ERROR -22
Not supported.
/* AAD length out of valid range */
#define _ERRNO_CRYPTO_AAD_LENGTH_OutRange -23
/* DMA operation timeout */
#define _ERRNO_CRYPTO_DMA_TIMEOUT -24
/* Invalid cipher mode */
#define _ERRNO_CRYPTO_MODE_ERR -25
/* Output buffer too small */
#define _ERRNO_CRYPTO_BUFFER_TOO_SMALL -26
/* Authentication/tag verification failed */
#define _ERRNO_CRYPTO_AUTH_FAILED -27
SHA Exported Constants
Not supported.
/* Bitmask of SHA CONTROL register bits cleared when starting a new hash operation. */
#define HASH_INIT_MASK (SHA_BIT_SLAVE_MODE | SHA_BIT_DMA_MODE | SHA_BIT_HMAC_MODE | SHA_MASK_SHA2_MODE | SHA_BIT_SM3_MODE)
SHA Block Size
/* Block size in bytes for SHA-224/256 (512-bit block = 64 bytes) */
#define SHA_BLOCK_256 64
/* Block size in bytes for SHA-384/512 (1024-bit block = 128 bytes) */
#define SHA_BLOCK_512 128
SHA Byte Inversion
/* Native (big-endian) byte order */
#define SHA_NATIVE_ORDER ((u8)0x00)
/* Inverse (little-endian) byte order */
#define SHA_INVERSE_ORDER ((u8)0x01)
/* Check whether INV is a valid SHA byte inversion setting. */
#define IS_SHA_BYTE_INV (((INV) == SHA_NATIVE_ORDER) || \
((INV) == SHA_INVERSE_ORDER))
SHA Byte Swap Defaults
/* Bitmask for key and payload byte inversion bits in CONTROL register */
#define SHA_MASK_BYTE_INVERSION ((u32)0x00000003 << 12)
/* Default: key in native order, payload byte-inverted */
#define SHA_BYTE_SWAP_DEFAULTS ((u32)(~SHA_BIT_KEY_BYTE_INVERSION_ENABLE) & SHA_BIT_PAYLOAD_BYTE_INVERSION_ENABLE)
/* Both key and payload in inverse byte order */
#define SHA_BYTE_SWAP_KEY_SWAP ((u32) SHA_BIT_KEY_BYTE_INVERSION_ENABLE | SHA_BIT_PAYLOAD_BYTE_INVERSION_ENABLE)
/* Default: key in native order, payload byte-swapped */
#define SHA_BYTE_SWAP_DEFAULTS ((u32)(~SHA_BIT_KEY_BYTE_SWAP_ENABLE) & SHA_BIT_PAYLOAD_BYTE_SWAP_ENABLE)
/* Both key and payload in inverse byte order */
#define SHA_BYTE_SWAP_KEY_SWAP ((u32) SHA_BIT_KEY_BYTE_SWAP_ENABLE | SHA_BIT_PAYLOAD_BYTE_SWAP_ENABLE)
SHA Digest Length
/* SHA-224 digest output length in bytes */
#define SHA_DIGEST_224 28
/* SHA-256 digest output length in bytes */
#define SHA_DIGEST_256 32
/* SHA-384 digest output length in bytes */
#define SHA_DIGEST_384 48
/* SHA-512 digest output length in bytes */
#define SHA_DIGEST_512 64
SHA DMA
/* DMA channel number for SHA transfers */
#define SHA_DMA_CH_NUM 1
/* DMA channel enable mask bit for SHA */
#define SHA_DMA_CH_MASK ((u32)0x00000001 << SHA_DMA_CH_NUM)
/* Max DMA block transfer size for SHA-224/256 (64-byte aligned) */
#define SHA_DMA_MAX_BLOCK_TS_256 0x1FFFFFC0
/* Max DMA block transfer size for SHA-384/512 (128-byte aligned) */
#define SHA_DMA_MAX_BLOCK_TS_512 0x1FFFFF80
/* DMA destination transfer width: byte */
#define SHA_DMA_DST_TR_WIDTH TrWidthOneByte
/* DMA source transfer width: byte */
#define SHA_DMA_SRC_TR_WIDTH TrWidthOneByte
SHA DMA Beat
/* Write a 64-bit value into byte buffer at offset i in big-endian order; used for SHA padding. */
#define SHA_PUT_UINT64_BE { \
(b)[(i) ] = (unsigned char) ( (n) >> 56 ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 48 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 40 ); \
(b)[(i) + 3] = (unsigned char) ( (n) >> 32 ); \
(b)[(i) + 4] = (unsigned char) ( (n) >> 24 ); \
(b)[(i) + 5] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 6] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 7] = (unsigned char) ( (n) ); \
}
/* Write a 32-bit value into byte buffer at offset i in big-endian order; used for SHA padding. */
#define SHA_PUT_UINT32_BE { \
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 3] = (unsigned char) ( (n) ); \
}
SHA DMA Mode
/* DMA read-only mode: engine reads source, no output copy */
#define SHA_READ_MODE ((u8)0x00)
/* DMA copy mode: engine reads source and writes to destination */
#define SHA_COPY_MODE ((u8)0x01)
/* Switch from copy mode to read-only mode on next DMA transfer */
#define SHA_COPY_TO_READ_SWITCH ((u8)0x01)
/* Switch from read-only mode to copy mode on next DMA transfer */
#define SHA_READ_TO_COPY_SWITCH ((u8)0x02)
/* Check whether MODE is a valid SHA DMA mode. */
#define IS_SHA_DMA_MODE (((MODE) == SHA_READ_MODE) || \
((MODE) == SHA_COPY_MODE))
SHA Engine Mode
/* DMA mode: message data provided via DMA */
#define SHA_DMA_MODE ((u8)0x00)
/* Slave mode: message data written directly to FIFO */
#define SHA_SLAVE_MODE ((u8)0x01)
/* Check whether MODE is a valid SHA engine mode. */
#define IS_SHA_ENGINE_MODE (((MODE) == SHA_DMA_MODE) || \
((MODE) == SHA_SLAVE_MODE))
SHA HMAC Key Byte Length
/* HMAC key length: 16 bytes (128 bits) */
#define SHA_HMAC_KEY_BYTE_128 16
/* HMAC key length: 24 bytes (192 bits) */
#define SHA_HMAC_KEY_BYTE_192 24
/* HMAC key length: 32 bytes (256 bits) */
#define SHA_HMAC_KEY_BYTE_256 32
SHA HMAC Key Size
/* Register encoding for 128-bit HMAC key */
#define SHA_HMAC_KEY_SIZE_128 (0x00)
/* Register encoding for 192-bit HMAC key */
#define SHA_HMAC_KEY_SIZE_192 (0x01)
/* Register encoding for 256-bit HMAC key */
#define SHA_HMAC_KEY_SIZE_256 (0x02)
/* HMAC key length: 128 bits */
#define SHA_HMAC_KEY_BIT_128 128
/* HMAC key length: 192 bits */
#define SHA_HMAC_KEY_BIT_192 192
/* HMAC key length: 256 bits */
#define SHA_HMAC_KEY_BIT_256 256
/* Check whether SIZE is a valid HMAC key length in bits. */
#define IS_SHA_HMAC_KEY_BIT (((SIZE) == SHA_HMAC_KEY_BIT_128) || \
((SIZE) == SHA_HMAC_KEY_BIT_192) || \
((SIZE) == SHA_HMAC_KEY_BIT_256))
SHA HMAC Mode
/* Pure hash mode (no HMAC padding) */
#define SHA_HASH_MODE (0x00)
/* HMAC mode (i-pad and o-pad applied to key) */
#define SHA_HMAC_MODE (0x01)
/* Check whether MODE is a valid SHA/HMAC operation mode. */
#define IS_SHA_HMAC_MODE (((MODE) == SHA_HASH_MODE) || \
((MODE) == SHA_HMAC_MODE))
SHA Input Length Bytes
/* Input length field size for SHA-224/256: 8 bytes (64-bit) */
#define SHA_ILEN_BYTES_256 8
/* Input length field size for SHA-384/512: 16 bytes (128-bit) */
#define SHA_ILEN_BYTES_512 16
SHA Mode
/* SHA-224 algorithm */
#define SHA_224 ((u8)0x00)
/* SHA-256 algorithm */
#define SHA_256 ((u8)0x01)
/* SHA-384 algorithm */
#define SHA_384 ((u8)0x02)
/* SHA-512 algorithm */
#define SHA_512 ((u8)0x03)
/* Check whether MODE is a valid SHA-2 algorithm selection. */
#define IS_SHA_MODE (((MODE) == SHA_224) || \
((MODE) == SHA_256) || \
((MODE) == SHA_384) || \
((MODE) == SHA_512))
Not supported.
/* Bit flag set in sha_mode to indicate SM3 engine */
#define SHA_MODE_SM3_FLAG ((u8)0x80)
/* Check whether MODE indicates SM3 engine (high bit set). */
#define IS_SM3_MODE (((MODE) & SHA_MODE_SM3_FLAG) != 0)
SHA Timeout
/* DMA mode operation timeout count */
#define SHA_DMA_TIMEOUT ((u32) 1000000)
/* Engine mutex acquisition timeout count */
#define SHA_MUTEX_TIMEOUT ((u32) 1000000)
/* Slave mode operation timeout count */
#define SHA_SLAVE_TIMEOUT ((u32) 10000)
KEY_MANAGEMENT Exported Constants
KM Key
/* Secure Hardware Key_1, OTP raw address:0x200, size: 256-bit */
#define KM_HMAC_KEY_S_IPSEC_KEY1 ((u8)0x00)
/* Secure Hardware Key_2, OTP raw address:0x220, size: 256-bit */
#define KM_HMAC_KEY_S_IPSEC_KEY2 ((u8)0x01)
/* Secure Hardware Key_3, OTP raw address:0x240, size: 256-bit */
#define KM_HMAC_KEY_S_IPSEC_KEY3 ((u8)0x02)
/* Secure Hardware Key_4, OTP raw address:0x260, size: 256-bit */
#define KM_HMAC_KEY_S_IPSEC_KEY4 ((u8)0x03)
/* Secure Software Key, size: 256-bit */
#define KM_HMAC_KEY_S_SW ((u8)0x21)
/* Non-Secure Software Key, size: 256-bit */
#define KM_HMAC_KEY_NS_SW ((u8)0x22)
/* Secure Hardware Key_1, OTP raw address:0x200, size: 256-bit */
#define KM_AES_KEY_S_IPSEC_KEY1 ((u8)0x00)
/* Secure Hardware Key_2, OTP raw address:0x220, size: 256-bit */
#define KM_AES_KEY_S_IPSEC_KEY2 ((u8)0x01)
/* Secure Hardware Key_3, OTP raw address:0x240, size: 256-bit */
#define KM_AES_KEY_S_IPSEC_KEY3 ((u8)0x02)
/* Secure Hardware Key_4, OTP raw address:0x260, size: 256-bit */
#define KM_AES_KEY_S_IPSEC_KEY4 ((u8)0x03)
/* Secure Hardware Key_5, OTP raw address:0x2C0, size: 256-bit */
#define KM_AES_KEY_S_RSIP_ECB_KEY ((u8)0x04)
/* Secure Hardware Key_6, OTP raw address:0x2E0, size: 256-bit */
#define KM_AES_KEY_S_RSIP_CTR_KEY ((u8)0x05)
/* Secure Software Key, size: 256-bit */
#define KM_AES_KEY_S_SW1 ((u8)0x21)
/* Secure Software Key, size: 256-bit */
#define KM_AES_KEY_S_SW2 ((u8)0x22)
/* Non-Secure Software Key, size: 256-bit */
#define KM_AES_KEY_NS_SW1 ((u8)0x23)
/* Non-Secure Software Key, size: 256-bit */
#define KM_AES_KEY_NS_SW2 ((u8)0x24)
/* Secure Hardware Key_1, OTP raw address:0x200, size: 256-bit */
#define KM_KEY_S_IPSEC_KEY1 ((u8)0x00)
/* Secure Hardware Key_2, OTP raw address:0x220, size: 256-bit */
#define KM_KEY_S_IPSEC_KEY2 ((u8)0x01)
/* Secure Hardware Key_3, OTP raw address:0x240, size: 256-bit */
#define KM_KEY_S_IPSEC_KEY3 ((u8)0x02)
/* Secure Hardware Key_4, OTP raw address:0x260, size: 256-bit */
#define KM_KEY_S_IPSEC_KEY4 ((u8)0x03)
/* Secure Hardware Key_5, OTP raw address:0x2C0, size: 256-bit */
#define KM_KEY_S_RSIP_KEY1 ((u8)0x04)
/* Secure Hardware Key_6, OTP raw address:0x2E0, size: 256-bit */
#define KM_KEY_S_RSIP_KEY2 ((u8)0x05)
/* Secure Software Key, size: 256-bit */
#define KM_KEY_S_SW1 ((u8)0x21)
/* Non-Secure Software Key, size: 256-bit */
#define KM_KEY_NS_SW1 ((u8)0x22)
Crypto Symmetric Cipher Exported Constants
Not supported.
/* Magic value marking a symmetric cipher context as initialized */
#define CRYPTO_CTX_STARTED 0x96965a5a
Crypto Hash Exported Constants
Crypto Timeout
Not supported.
/* DMA mode operation timeout count */
#define CRYPTO_DMA_TIMEOUT ((u32) 1000000)
/* Engine mutex acquisition timeout count */
#define CRYPTO_MUTEX_TIMEOUT ((u32) 1000000)
/* Slave mode operation timeout count */
#define CRYPTO_SLAVE_TIMEOUT ((u32) 10000)
Hash Algorithm Selection
Not supported.
/* Select SHA-2 hash algorithm (SHA-224/256/384/512) */
#define HASH_ALGO_SHA2 ((u8)0x00)
/* Select SM3 hash algorithm */
#define HASH_ALGO_SM3 ((u8)0x01)
Hash Block Size
Not supported.
/* SHA-224 block size in bytes (512-bit block) */
#define HASH_BLOCK_SIZE_224 64
/* SHA-256 block size in bytes (512-bit block) */
#define HASH_BLOCK_SIZE_256 64
/* SHA-384 block size in bytes (1024-bit block) */
#define HASH_BLOCK_SIZE_384 128
/* SHA-512 block size in bytes (1024-bit block) */
#define HASH_BLOCK_SIZE_512 128
/* SM3 block size in bytes (512-bit block) */
#define HASH_BLOCK_SIZE_SM3 64
Hash Digest Length
Not supported.
/* SHA-224 digest output length in bytes */
#define HASH_DIGEST_224 28
/* SHA-256 digest output length in bytes */
#define HASH_DIGEST_256 32
/* SHA-384 digest output length in bytes */
#define HASH_DIGEST_384 48
/* SHA-512 digest output length in bytes */
#define HASH_DIGEST_512 64
/* SM3 digest output length in bytes */
#define HASH_DIGEST_SM3 32
SM4 Exported Constants
SM4 Cipher Mode
Not supported.
/* SM4 encryption direction */
#define SM4_ENCRYPTION_MODE ((u8)0x01)
/* SM4 decryption direction */
#define SM4_DECRYPTION_MODE ((u8)0x00)
/* Electronic Codebook mode */
#define SM4_MODE_ECB ((u8)0x00)
/* Cipher Block Chaining mode */
#define SM4_MODE_CBC ((u8)0x01)
/* Cipher Feedback mode */
#define SM4_MODE_CFB ((u8)0x02)
/* Output Feedback mode */
#define SM4_MODE_OFB ((u8)0x03)
/* Counter mode */
#define SM4_MODE_CTR ((u8)0x04)
SM3 Exported Constants
SM3 Mode
Not supported.
/* SM3 operates in a single mode equivalent to SHA-256 (256-bit block, 256-bit digest) */
#define SM3_256 SHA_256
SM3 Block Size
Not supported.
/* SM3 block size in bytes (512-bit block = 64 bytes) */
#define SM3_BLOCK_256 64
SM3 Digest Length
Not supported.
/* SM3 digest output length in bytes */
#define SM3_DIGEST_256 32
AES Exported Functions
-
int crypto_aes_cbc(u8 key_id, u32 key_len_bits, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform AES-CBC encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_cfb(u8 key_id, u32 key_len_bits, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform AES-CFB encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ctr(u8 key_id, u32 key_len_bits, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform AES-CTR encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ecb(u8 key_id, u32 key_len_bits, u8 is_encryption, const u8 *input, u32 len, u8 *output)
Perform AES-ECB encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ofb(u8 key_id, u32 key_len_bits, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform AES-OFB encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ctr_slave(u8 key_id, u32 key_len_bits, u8 is_encryption, const u8 input[16], u8 iv[16], u8 output[16])
Perform AES-CTR mode encryption and decryption in slave mode. In order to avoid the impact of 32-byte cache line alignment, an additional slave mode interface is provided. Input and output are limited to 16 bytes.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ecb_slave(u8 key_id, u32 key_len_bits, u8 is_encryption, const u8 input[16], u8 output[16])
Perform AES-ECB mode encryption and decryption in slave mode. In order to avoid the impact of 32-byte cache line alignment, an additional slave mode interface is provided. Input and output are limited to 16 bytes.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_set_sw_key(u8 key_id, u32 key_len_bits, const u8 *key_addr)
Set software key value for AES.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
key_addr -- Address to software key array
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
-
int crypto_aes_start(u8 key_id, u8 xts_key2_id, u32 key_len_bits, int aes_mode, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Generic AES DMA mode encryption and decryption for ECB, CBC, CFB, OFB, CTR, and XTS cipher modes. This is the underlying function called by mode-specific APIs such as crypto_aes_ecb(), crypto_aes_cbc(), etc.
- 参数:
key_id -- Value of KM Key. For XTS mode, this is key 1.
xts_key2_id -- XTS key 2 ID. For non-XTS modes, pass 0.
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
aes_mode -- AES cipher mode. This parameter can be a value of AES Cipher Mode. Supported modes: CIPHER_MODE_ECB, CIPHER_MODE_CBC, CIPHER_MODE_CFB, CIPHER_MODE_OFB, CIPHER_MODE_CTR, CIPHER_MODE_XTS.
is_encryption --
1: encryption
0: decryption
input -- The address of the input data.
len -- The length of the data in bytes.
iv -- IV array address. IV length must be 16 bytes. Pass NULL for ECB mode. For non-ECB modes, the updated IV is written back after the operation.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_xts(u8 key1_id, u8 key2_id, u32 key_len_bits, u8 is_encryption, const u8 *input, u32 len, u8 tweak[16], u8 *output)
AES-XTS encryption and decryption in DMA mode.
- 参数:
key1_id -- XTS key 1 ID
key2_id -- XTS key 2 ID
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
tweak -- Tweak array address. Tweak length must be 16 Bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_cmac(u8 key_id, u32 key_len_bits, const u8 *input, u32 len, u8 *tag)
Compute AES-CMAC authentication tag.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
input -- The address of the input data.
len -- The length of input data.
tag -- Pointer to the output tag address
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_gcm_auth_decrypt(u8 key_id, u32 key_len_bits, u32 len, u8 *iv_addr, u32 iv_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
AES-GCM mode decryption and authentication. While decrypting, the API will check whether the TAG generated by decryption is consistent with the input TAG. If the TAG is consistent, it will return success. Otherwise, the decryption verification fails.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
len -- The length of the message.
iv_addr -- IV array address.
iv_len -- IV length
aad_addr -- AAD address
aad_len -- AAD length
input -- The address of the input message.
output -- The address of output data
tag_len -- GCM tag length, max length is 16 bytes
tag -- GCM tag address (input for authentication)
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
This API supports 4 input modes of GCM mode:
Without AAD/PT/CT: set the input buffer to all 0, use slave mode to calculate tag (similar to CMAC mode input_len = 0)
Without PT/CT, with AAD: first use DMA + GMAC mode to calculate the temp tag of aad, then set the input buffer to all 0, and use slave + GCM mode to calculate the final tag
Without AAD, with PT or CT: slave + ECB mode to calculate ghash key, copy cpu_dataout reg to ghash_key reg. DMA+GCM mode, output tag
With AAD/PT or CT: Calculate IV, GMAC tag (GMAC mode) in order, output plaintext or ciphertext and tag This API is consistent with Mbedtls in various GCM modes. Users do not need to pay special attention to the calculation process. The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_gcm_encrypt_and_tag(u8 key_id, u32 key_len_bits, u8 is_encryption, u32 len, u8 *iv_addr, u32 iv_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
AES-GCM mode encryption and decryption.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
is_encryption --
1: Encryption
0: Decryption
len -- The length of the message.
iv_addr -- IV array address.
iv_len -- IV length
aad_addr -- AAD address
aad_len -- AAD length
input -- The address of the input message.
output -- The address of output data
tag_len -- GCM tag length, max length is 16 bytes
tag -- GCM tag output address
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
This API supports 4 input modes of GCM mode:
Without AAD/PT/CT: set the input buffer to all 0, use slave mode to calculate tag (similar to CMAC mode input_len = 0)
Without PT/CT, with AAD: first use DMA + GMAC mode to calculate the temp tag of aad, then set the input buffer to all 0, and use slave + GCM mode to calculate the final tag
Without AAD, with PT or CT: slave + ECB mode to calculate ghash key, copy cpu_dataout reg to ghash_key reg. DMA+GCM mode, output tag
With AAD/PT or CT: Calculate IV, GMAC tag (GMAC mode) in order, output plaintext or ciphertext and tag This API is consistent with Mbedtls in various GCM modes. Users do not need to pay special attention to the calculation process. The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ctr_slave(u8 key_id, u32 key_len_bits, u8 *key_addr, u8 is_encryption, const u8 input[16], u8 iv[16], u8 output[16])
Perform AES-CTR mode encryption and decryption in slave mode. In order to avoid the impact of 32-byte cache line alignment, an additional slave mode interface is provided. Input and output are limited to 16 bytes.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
key_addr -- Address to software key array
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ecb_slave(u8 key_id, u32 key_len_bits, u8 *key_addr, u8 is_encryption, const u8 input[16], u8 output[16])
Perform AES-ECB mode encryption and decryption in slave mode. In order to avoid the impact of 32-byte cache line alignment, an additional slave mode interface is provided. Input and output are limited to 16 bytes.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
key_addr -- Address to software key array
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_ccm_auth_decrypt(u8 key_id, u32 key_len_bits, u8 *key_addr, u32 msg_len, u8 *nonce_addr, u32 nonce_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform AES-CCM mode authenticated decryption (DMA mode).
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
key_addr -- Software key address, set to NULL if use hardware key
msg_len -- The length of the ciphertext.
nonce_addr -- Nonce array address.
nonce_len -- Nonce length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the ciphertext data.
output -- The address of the plaintext data.
tag_len -- The length of the tag.
tag -- The address of the tag input data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
-
int crypto_aes_ccm_encrypt_and_tag(u8 key_id, u32 key_len_bits, u8 *key_addr, u32 msg_len, u8 *nonce_addr, u32 nonce_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform AES-CCM mode encryption and tag generation (DMA mode).
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
key_addr -- Software key address, set to NULL if use hardware key
msg_len -- The length of the plaintext.
nonce_addr -- Nonce array address.
nonce_len -- Nonce length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the plaintext data.
output -- The address of the ciphertext data.
tag_len -- The length of the tag.
tag -- The address of the tag output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
-
int crypto_aes_cmac(u8 key_id, u32 key_len_bits, const u8 *input, u32 len, u8 *tag)
Compute AES-CMAC authentication tag.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
input -- The address of the input data.
len -- The length of input data.
tag -- Pointer to the output tag buffer
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
-
int crypto_aes_gcm_authenticated_decrypt(u8 key_id, u32 key_len_bits, u32 len, u8 *iv_addr, u32 iv_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform AES-GCM mode authenticated decryption (DMA mode).
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
len -- The length of the ciphertext.
iv_addr -- IV array address.
iv_len -- IV length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the ciphertext data.
output -- The address of the plaintext data.
tag_len -- The length of the tag.
tag -- The address of the tag input data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
-
int crypto_aes_gcm_encrypt_and_tag(u8 key_id, u32 key_len_bits, u32 len, u8 *iv_addr, u32 iv_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform AES-GCM mode encryption and tag generation (DMA mode).
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
len -- The length of the plaintext.
iv_addr -- IV array address.
iv_len -- IV length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the plaintext data.
output -- The address of the ciphertext data.
tag_len -- The length of the tag.
tag -- The address of the tag output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the AES engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
SHA Exported Functions
SHA HAL Functions
-
int crypto_hmac_sha2_final(SHA_context *ctx, u8 *output)
Perform HMAC final process.
- 参数:
ctx -- SHA context.
output -- The result of HMAC function
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The HMAC key will be reloaded before the final process. If a software key is used and the key is modified in final, the calculation result will be wrong. Ensure the software key is set to the correct value before calling the final process.
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the engine at the same time.
-
int crypto_hmac_sha2_init(SHA_context *ctx, u32 SHAtype, u8 key_id, u32 key_len_bits)
Initialize the HMAC-SHA2 context for read-only DMA mode computation.
- 参数:
SHAtype --
SHA_224
SHA_256
SHA_384
SHA_512
ctx -- SHA context.
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the engine at the same time.
-
int crypto_hmac_sha2_update(SHA_context *ctx, const u8 *input, u8 *dst, size_t len)
Update HMAC state.
- 参数:
ctx -- SHA context.
input -- Pointer to input data.
dst -- Pointer to output data. If in read-only mode, set it to NULL
len -- Input data length.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
If copy mode and read-only mode are mixed for update, then ensure that the message lengths of both copy mode and read-only mode are integer multiples of the SHA-BLOCK length. (64-byte alignment for SHA-224/256, 128-byte alignment for SHA-384/512)
The HMAC key will be reloaded before each update. If a software key is used, and the key is modified between updates, the calculation result will be wrong. Ensure the software key is set to the correct value before calling update.
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the engine at the same time.
In copy mode, the destination address and calculation length must be 32 bytes (cache line size) aligned.
-
int crypto_sha2_final(SHA_context *ctx, u8 *output)
Perform SHA final process.
- 参数:
ctx -- SHA context
output -- The result of SHA function
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
Since the SHA engine does not support hardware padding, software padding is performed instead.
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the engine at the same time.
-
int crypto_sha2_init(SHA_context *ctx, u32 SHAtype)
Initialize the SHA-2 context for read-only DMA mode computation.
- 参数:
SHAtype --
SHA_224
SHA_256
SHA_384
SHA_512
ctx -- SHA context. This function will initialize the context.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the engine at the same time.
-
int crypto_sha2_update(SHA_context *ctx, const u8 *input, u8 *dst, size_t len)
Update SHA state.
- 参数:
ctx -- SHA context
input -- Pointer to input data.
dst -- Pointer to output data. If in read-only mode, set it to NULL
len -- Input data length.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
If copy mode and read-only mode are mixed for update, then ensure that the message lengths of both copy mode and read-only mode are integer multiples of the SHA-BLOCK length. (64-byte alignment for SHA-224/256, 128-byte alignment for SHA-384/512)
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the engine at the same time.
In copy mode, the destination address and calculation length must be 32 bytes (cache line size) aligned.
-
int crypto_hmac_sha2_set_sw_key(u8 key_id, u32 key_len_bits, const u8 *key_addr)
Set software key value for HMAC.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
key_addr -- Address to software key array
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
Not supported.
SM3 Exported Functions
SM3 HMAC Functions
Not supported.
-
int crypto_hmac_sm3_final(SHA_context *ctx, u8 *output)
Finalize HMAC computation.
- 参数:
ctx -- SM3 context.
output -- The result of HMAC function
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The HMAC key will be reloaded before the final process. If a software key is used and the key is modified in final, the calculation result will be wrong. Ensure the software key is set to the correct value before calling the final process.
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM3 engine at the same time.
-
int crypto_hmac_sm3_init(SHA_context *ctx, u8 key_id, u32 key_len_bytes)
Initialize the HMAC-SM3 context for read-only DMA mode computation.
- 参数:
ctx -- SM3 context.
key_id -- Value of KM Key
key_len_bytes --
Key length in bytes (not bits, unlike crypto_hmac_sha2_init). Valid values:
16 (128-bit key)
24 (192-bit key)
32 (256-bit key)
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM3 engine at the same time.
-
int crypto_hmac_sm3_update(SHA_context *ctx, const u8 *input, u8 *dst, size_t len)
Update HMAC state.
- 参数:
ctx -- SM3 context.
input -- Pointer to input data.
dst -- Pointer to output data. If in read-only mode, set it to NULL
len -- Input data length.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
If copy mode and read-only mode are mixed for update, then ensure that the message lengths of both copy mode and read-only mode are integer multiples of the SM3-BLOCK length. (64-byte alignment for SM3-256)
The HMAC key will be reloaded before each update. If a software key is used, and the key is modified between updates, the calculation result will be wrong. Ensure the software key is set to the correct value before calling update.
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM3 engine at the same time.
In copy mode, the destination address and calculation length must be 32 bytes (cache line size) aligned.
SM3 Normal Functions
Not supported.
-
int crypto_sm3_final(SHA_context *ctx, u8 *output)
Finalize SM3 computation.
- 参数:
ctx -- SM3 context
output -- The result of SM3 function
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
Since SM3 does not support hardware padding, software padding must be applied.
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM3 engine at the same time.
-
int crypto_sm3_init(SHA_context *ctx)
Initialize the SM3 context for read-only DMA mode computation.
- 参数:
ctx -- SM3 context. This function will initialize the context.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The SM3 engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM3 engine at the same time.
-
int crypto_sm3_update(SHA_context *ctx, const u8 *input, u8 *dst, size_t len)
Update SM3 state.
- 参数:
ctx -- SM3 context
input -- Pointer to input data.
dst -- Pointer to output data. If in read-only mode, set it to NULL
len -- Input data length.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
If copy mode and read-only mode are mixed for update, then ensure that the message lengths of both copy mode and read-only mode are integer multiples of the SM3-BLOCK length. (64-byte alignment for SM3-256)
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM3 engine at the same time.
In copy mode, the destination address and calculation length must be 32 bytes (cache line size) aligned.
KEY_MANAGEMENT Exported Functions
Not supported.
-
int crypto_km_set_sw_key(u8 key_id, u32 key_len_bits, const u8 *key_addr)
Set software key value.
- 参数:
key_id -- Value of KM Key
key_len_bits --
KEY_BIT_128
KEY_BIT_192
KEY_BIT_256
key_addr -- Pointer to the software key array
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
SM4 Exported Functions
SM4 DMA Functions
Not supported.
-
int crypto_sm4_cbc(u8 key_id, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform SM4-CBC mode encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
SM4 only supports 128-bit key length.
-
int crypto_sm4_cfb(u8 key_id, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform SM4-CFB mode encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
SM4 only supports 128-bit key length.
-
int crypto_sm4_ctr(u8 key_id, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform SM4-CTR mode encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
SM4 only supports 128-bit key length.
-
int crypto_sm4_ecb(u8 key_id, u8 is_encryption, const u8 *input, u32 len, u8 *output)
Perform SM4-ECB mode encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
SM4 only supports 128-bit key length.
-
int crypto_sm4_ofb(u8 key_id, u8 is_encryption, const u8 *input, u32 len, u8 iv[16], u8 *output)
Perform SM4-OFB mode encryption and decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
is_encryption --
1: Encryption
0: Decryption
input -- The address of the input data.
len -- The length of the data.
iv -- IV array address. IV length must be 16 bytes.
output -- The address of the output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of encrypted and decrypted data must be 32-byte (cache line size) aligned. At the same time, the destination address is also 32-byte aligned. Otherwise, an error will be reported.
SM4 only supports 128-bit key length.
SM4 AEAD Functions
Not supported.
-
int crypto_sm4_ccm_auth_decrypt(u8 key_id, u8 *key_addr, u32 msg_len, u8 *nonce_addr, u32 nonce_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform SM4-CCM mode authenticated decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
key_addr -- Software key address, set to NULL if using a hardware key
msg_len -- The length of the ciphertext.
nonce_addr -- Nonce array address.
nonce_len -- Nonce length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the ciphertext data.
output -- The address of the plaintext data.
tag_len -- The length of the tag.
tag -- The address of the tag input data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
SM4 only supports 128-bit key length.
-
int crypto_sm4_ccm_encrypt_and_tag(u8 key_id, u8 *key_addr, u32 msg_len, u8 *nonce_addr, u32 nonce_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform SM4-CCM mode encryption and tag generation in DMA mode.
- 参数:
key_id -- Value of KM Key
key_addr -- Software key address, set to NULL if using a hardware key
msg_len -- The length of the plaintext.
nonce_addr -- Nonce array address.
nonce_len -- Nonce length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the plaintext data.
output -- The address of the ciphertext data.
tag_len -- The length of the tag.
tag -- The address of the tag output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
SM4 only supports 128-bit key length.
-
int crypto_sm4_gcm_authenticated_decrypt(u8 key_id, u32 len, u8 *iv_addr, u32 iv_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform SM4-GCM mode authenticated decryption in DMA mode.
- 参数:
key_id -- Value of KM Key
len -- The length of the ciphertext.
iv_addr -- IV array address.
iv_len -- IV length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the ciphertext data.
output -- The address of the plaintext data.
tag_len -- The length of the tag.
tag -- The address of the tag input data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
SM4 only supports 128-bit key length.
-
int crypto_sm4_gcm_encrypt_and_tag(u8 key_id, u32 len, u8 *iv_addr, u32 iv_len, u8 *aad_addr, u32 aad_len, const u8 *input, u8 *output, u32 tag_len, u8 *tag)
Perform SM4-GCM mode encryption and tag generation in DMA mode.
- 参数:
key_id -- Value of KM Key
len -- The length of the plaintext.
iv_addr -- IV array address.
iv_len -- IV length.
aad_addr -- The address of the AAD data.
aad_len -- The length of the AAD data.
input -- The address of the plaintext data.
output -- The address of the ciphertext data.
tag_len -- The length of the tag.
tag -- The address of the tag output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of input data, output data and aad data must be 32-byte (cache line size) aligned.
SM4 only supports 128-bit key length.
SM4 Authentication Functions
Not supported.
-
int crypto_sm4_cmac(u8 key_id, const u8 *input, u32 len, u8 *tag)
Compute SM4-CMAC authentication tag in DMA mode.
- 参数:
key_id -- Value of KM Key
input -- The address of the input data.
len -- The length of the data.
tag -- The address of the CMAC output data.
- 返回:
Process status:
0: success
Other: error code. Refer to Crypto Process Status
备注
The engine will be locked during the execution of this function, and will be unlocked after execution. Avoid multiple threads/CPUs using the SM4 engine at the same time.
The length of input data must be 32-byte (cache line size) aligned.
SM4 only supports 128-bit key length.