# AES 指令集

AES 指令集是一组处理器指令，直接在硬件中实现高级加密标准（AES）分组密码的轮运算和密钥编排，使软件每轮只需发出几条指令即可完成加密和解密，而不必执行表驱动的代码。最著名的例子是英特尔（Intel）的 AES 新指令（AES-NI），随 2010 年代号 Westmere 的[英特尔酷睿](https://www.edgepedia.org/zh/intel-core)处理器家族引入；Armv8 加密扩展以及 RISC-V 标量和向量加密扩展中也有类似的扩展。<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup><sup> • </sup><sup>[2](https://documentation-service.arm.com/static/5e7b694016d2907d59402500)</sup>

| 关键事实 | 详情 |
|---|---|
| x86 首次出现 | 英特尔 AES-NI，2010 年英特尔酷睿处理器家族（Westmere 微架构）<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup> |
| AES-NI 内容 | 六条指令：AESENC、AESENCLAST、AESDEC、AESDECLAST、AESIMC、AESKEYGENASSIST；CLMUL 作为第七条一同发布<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup><sup> • </sup><sup>[3](https://www.intel.com/content/dam/doc/white-paper/enterprise-security-aes-ni-white-paper.pdf)</sup> |
| 加速比 | 相比纯软件实现提升 3 至 10 倍；CBC 加密为 2 至 3 倍，CBC 解密和 CTR 等可并行模式约 10 倍<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup> |
| 吞吐量示例 | 在英特尔酷睿 i7-980X 单核上，并行模式下 AES-128 约为 1.3 周期/字节<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup> |
| 检测方式（x86） | CPUID.01H:ECX.AESNI[第 25 位] = 1<sup>[4](https://www.intel.com/content/www/us/en/developer/articles/technical/trusted-cpu-feature-detection-library-for-intel-software-guard-extensions-intel-sgx.html)</sup> |
| 安全属性 | 指令在数据无关的时间内运行，不使用查表，消除了基于表的软件 AES 的主要时序和缓存攻击面<sup>[5](https://www.intel.com/content/www/us/en/developer/articles/tool/intel-advanced-encryption-standard-aes-instructions-set.html)</sup> |
| 其他架构 | Armv8 为高级 SIMD 增加 AESE、AESD、AESMC 和 AESIMC；RISC-V 将 AES 加速分散到标量 Zkne 和 Zknd 扩展以及向量 Zvkned 扩展中<sup>[2](https://documentation-service.arm.com/static/5e7b694016d2907d59402500)</sup><sup> • </sup><sup>[6](https://docs.riscv.org/reference/isa/v20240411/unpriv/scalar-crypto.html)</sup> |

## 硬件 AES 指令为何存在

AES 是一种对称分组密码，通过若干轮对固定的 128 位分组进行加密；密钥长度为 128、192 或 256 位时，轮数分别为 10、12 或 14，每轮使用密钥编排中的子密钥执行 SubBytes、ShiftRows、MixColumns 和 AddRoundKey。<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup> 在纯软件中，SubBytes 步骤通常实现为对 256 字节 S 盒表的查找，而查找索引取决于秘密密钥材料。

这种表结构正是这些指令旨在消除的安全问题。2005 年，时任伊利诺伊大学芝加哥分校数学家和密码学家的丹尼尔·J·伯恩斯坦（Daniel J. Bernstein）展示了一种针对 AES 软件的远程缓存时序攻击，利用的正是这种依赖秘密的内存访问模式。<sup>[7](https://arxiv.org/abs/1403.7293)</sup> 英特尔关于 S 盒的指南指出，一个间谍进程观察存放该表的四条缓存线中哪一条被访问，每次观察可获得关于秘密轮密钥的 2 比特信息，使用 CacheBleed 等更精细的技术最多可获得 6 比特；反复观察可以揭示整个密钥。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/secure-coding/mitigate-timing-side-channel-crypto-implementation.html)</sup>

硬件 AES 指令通过在逻辑中计算替换而非从内存读取来解决这个问题。英特尔表示，其 AES 指令在数据无关的时间内运行且不使用表，消除了威胁基于表实现的主要时序和缓存攻击，同时减小了代码体积和无意引入侧信道泄漏的风险。<sup>[5](https://www.intel.com/content/www/us/en/developer/articles/tool/intel-advanced-encryption-standard-aes-instructions-set.html)</sup> RISC-V 规范在其文本中提出了同样的要求：每条 AES 指令“实现时必须始终确保其执行延迟不依赖于所操作的数据。”<sup>[9](https://docs.riscv.org/reference/isa/unpriv/scalar-crypto.html)</sup>

## 英特尔 AES-NI 指令

AES-NI 由六条指令组成，覆盖算法中计算密集的部分。<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup>

- **AESENC** 执行一个完整的加密轮，将 ShiftRows、SubBytes、MixColumns 和 AddRoundKey 合并为一条指令。
- **AESENCLAST** 执行最后一轮加密，省略 MixColumns。
- **AESDEC** 和 **AESDECLAST** 对解密执行相同操作，使用逆步骤 InvShiftRows、InvSubBytes、InvMixColumns 和 AddRoundKey。
- **AESKEYGENASSIST** 生成用于加密的轮密钥，接受一个 8 位轮常量。<sup>[10](https://www.intel.com/content/dam/develop/public/us/en/documents/10tb-24-breakthrough-aes-performance-with-intel-aes-new-instructions-final-secure.pdf)</sup>
- **AESIMC** 将加密轮密钥转换为等效逆密码解密所需的形式。<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup>

六条指令均对 XMM 寄存器中的 128 位状态进行操作。这些指令支持所有标准密钥长度和标准工作模式，英特尔指出它们还可以支持 AES 的非标准或未来变体。<sup>[5](https://www.intel.com/content/www/us/en/developer/articles/tool/intel-advanced-encryption-standard-aes-instructions-set.html)</sup> 应用程序在使用前通过检查 CPUID.01H:ECX.AESNI[第 25 位] 来检测支持情况。<sup>[4](https://www.intel.com/content/www/us/en/developer/articles/technical/trusted-cpu-feature-detection-library-for-intel-software-guard-extensions-intel-sgx.html)</sup>

**与 AES 一同推出的 CLMUL。** AES-NI 的推出还包含无进位乘法指令 PCLMULQDQ，英特尔将其描述为该指令集中的第七条新指令。<sup>[3](https://www.intel.com/content/dam/doc/white-paper/enterprise-security-aes-ni-white-paper.pdf)</sup> 其用途是[伽罗瓦/计数器模式](https://www.edgepedia.org/zh/galois-counter-mode)（GCM）的 GHASH 认证器：GCM 通过 AES 加密提供机密性，并通过二元域上的通用哈希提供认证，而 PCLMULQDQ 使该域乘法快到足以支持高吞吐量的 GCM。<sup>[11](https://www.intel.com/content/dam/www/public/us/en/documents/software-support/enabling-high-performance-gcm.pdf)</sup> 英特尔的优化 GCM 代码在酷睿 i7 2600 单核上使用 AES-NI 和 PCLMULQDQ 达到了约 2.2 周期/字节的 GCM 加密速度。<sup>[11](https://www.intel.com/content/dam/www/public/us/en/documents/software-support/enabling-high-performance-gcm.pdf)</sup>

## 向量扩展与后续 x86 发展

最初的 AES-NI 指令一次处理一个 128 位分组。后来的 VAES 扩展将相同的轮指令扩展到 256 位和 512 位向量寄存器，一次对两个或四个 128 位分组执行一轮 AES；英特尔表示这有助于可并行 AES 模式比传统 AES-NI 更高效地运行，CLMUL 的向量形式也以类似方式改进 AES-GCM。<sup>[12](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-ipp-crypto-multi-buffer-acceleration.html)</sup> 英特尔的加密加速路线图将 VAES 描述为使用 512 位 ZMM 寄存器最多处理四个 AES 分组，在正确使用时惠及所有 AES 工作模式。<sup>[13](https://www.intel.com/content/www/us/en/newsroom/article/crypto-acceleration-enabling-path-future-computing.html)</sup> 在英特尔 IPP Crypto 上测量，启用较新的指令集后，在测试硬件上 1024 字节缓冲区长度下 AES128-GCM 从 1.35 周期/字节降至 0.344 周期/字节。<sup>[12](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-ipp-crypto-multi-buffer-acceleration.html)</sup>

## Arm 和 RISC-V 的对应方案

**Armv8 加密扩展。** Arm 的方法将 AES 指令添加到高级 SIMD 寄存器组中：AESE（单轮加密）、AESD（单轮解密）、AESMC（列混合）和 AESIMC（逆列混合），另有 SHA-1 和 SHA-2 的独立指令以及用于 GCM 的多项式乘法。<sup>[2](https://documentation-service.arm.com/static/5e7b694016d2907d59402500)</sup> 该扩展在某些核心中是可选的；例如 Cortex-A65AE 仅在附加许可下提供。<sup>[14](https://documentation-service.arm.com/static/605df846256fc952d8c37836?token=)</sup> 后来的 Arm 架构级别将该思想扩展到可伸缩向量扩展，从 ARMv9.0-A 起 FEAT_SVE_AES 提供可伸缩向量 AES 指令。<sup>[15](https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain)</sup>

**RISC-V。** RISC-V 标量加密扩展采取了不同的设计思路：不是每条指令执行一个完整轮，其 RV32 AES 轮指令对选定的字节进行操作并产生 32 位结果，而 RV64 AES 轮指令产生下一轮 AES 输出的一半，处理状态的 64 位部分，因此一轮由通用 X 寄存器上的多条指令组合而成。<sup>[20](https://riscv.github.io/riscv-unified-db/manual/html/isa/isa_20240411/chapters/scalar-crypto.html)</sup> 加密指令位于 Zkne 扩展中，解密位于 Zknd 中，两条 RV64 密钥编排指令 aes64ks1i 和 aes64ks2 同时出现在两者中；所有这些均在 1.0.0 版本获得批准。<sup>[6](https://docs.riscv.org/reference/isa/v20240411/unpriv/scalar-crypto.html)</sup> 32 位指令源自学术工作并贡献给了该扩展，设计空间在论文《RISC-V 标量 AES 指令集扩展的设计》中进行了探索；64 位指令由任务组协作开发。<sup>[6](https://docs.riscv.org/reference/isa/v20240411/unpriv/scalar-crypto.html)</sup>

## 实际性能与采用情况

这些指令的性能优势很大且因模式而异。英特尔报告整体相比软件加速 3 至 10 倍，其中 CBC [加密](https://www.edgepedia.org/zh/encryption)等串行模式增益较小为 2 至 3 倍，因为每个分组依赖前一个分组，而 CBC 解密和 CTR 等可并行模式约为 10 倍，因为许多分组可以并发处理。<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup> 由于 AES 广泛应用于网络加密（SSL、TLS、IPsec、HTTPS、SSH）以及磁盘和文件加密，这些指令通过标准库到达应用；英特尔列出的支持 AES-NI 的软件包括 OpenSSL 1.0（或打补丁后的 0.9.8k 及更高版本）、英特尔 IPP 6.1 及更高版本，以及 [Windows 7](https://www.edgepedia.org/zh/windows-7) 的下一代加密 API，编译器支持包括 GCC 4.4 及以后、英特尔 C/C++ 11.1 及以后、以及 Visual C++ 2008 SP1 及以后。<sup>[1](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)</sup>

这些指令还改变了嵌入式和开放指令集的实现实践。2020 年一项关于轻量级 AES 和 SM4 指令集扩展的研究表明，十六条指令（外加一次子密钥加载）足以实现一轮 AES，而原本需要八十条普通指令，且此类扩展消除了缓慢的、依赖秘密的查表并减少了软件占用。<sup>[17](https://arxiv.org/abs/2002.07041)</sup> RISC-V 安全模型工作指出，一个高保证任务组正在开发进一步的指令集扩展，包括旨在允许有效的抗侧信道实现、可能优于现有基于轮的指令的全轮向量 AES。<sup>[18](https://github.com/riscv/riscv-security-model/blob/main/specification/src/chapter3.adoc)</sup>

## 硬件保证的局限

AES 指令的数据无关延迟消除了基于表 AES 的缓存时序信道，但其本身并不能使密码程序无侧信道。英特尔的指南区分了传统时序信道、软件可见的物理时序信道（如频率节流）以及推测执行信道，并建议在所有涉及秘密的代码中对运行时间、代码访问模式和数据访问模式采用常数时间原则。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/secure-coding/mitigate-timing-side-channel-crypto-implementation.html)</sup> 对于频率节流信道，英特尔指出当 CPU 具备 AES-NI 或 VAES 时可进行缓解。<sup>[19](https://www.intel.com/content/www/us/en/docs/crypto-primitives-library/developer-guide-reference/2025-0/mitigation-for-frequency-throttling.html)</sup>

## References

1. [Intel Advanced Encryption Standard Instructions (AES-NI), Intel Developer Zone](https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-encryption-standard-instructions-aes-ni.html)
2. [ARM Cortex-A72 MPCore Processor Cryptography Extension Technical Reference Manual](https://documentation-service.arm.com/static/5e7b694016d2907d59402500)
3. [Intel AES-NI: Securing the Enterprise, white paper](https://www.intel.com/content/dam/doc/white-paper/enterprise-security-aes-ni-white-paper.pdf)
4. [Trusted CPU Feature Detection Library for Intel SGX, Intel Developer Zone](https://www.intel.com/content/www/us/en/developer/articles/technical/trusted-cpu-feature-detection-library-for-intel-software-guard-extensions-intel-sgx.html)
5. [Intel Advanced Encryption Standard (AES) Instructions Set, Rev 3.01](https://www.intel.com/content/www/us/en/developer/articles/tool/intel-advanced-encryption-standard-aes-instructions-set.html)
6. [RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions, Version 1.0.1](https://docs.riscv.org/reference/isa/v20240411/unpriv/scalar-crypto.html)
7. [Constant time encryption as a countermeasure against remote cache timing attacks, arXiv:1403.7293](https://arxiv.org/abs/1403.7293)
8. [Guidelines for Mitigating Timing Side Channels Against Cryptographic Implementations, Intel](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/secure-coding/mitigate-timing-side-channel-crypto-implementation.html)
9. [Cryptography Extensions: Scalar & Entropy Source Instructions, RISC-V Ratified Specifications Library](https://docs.riscv.org/reference/isa/unpriv/scalar-crypto.html)
10. [Efficient AES Implementations on Westmere, Intel](https://www.intel.com/content/dam/develop/public/us/en/documents/10tb-24-breakthrough-aes-performance-with-intel-aes-new-instructions-final-secure.pdf)
11. [Enabling High-Performance Galois-Counter-Mode on Intel Architecture Processors, white paper](https://www.intel.com/content/dam/www/public/us/en/documents/software-support/enabling-high-performance-gcm.pdf)
12. [IPP Crypto acceleration Ice Lake, Intel Developer Zone](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-ipp-crypto-multi-buffer-acceleration.html)
13. [Crypto Acceleration: Enabling a Path to the Future of Computing, Intel Newsroom](https://www.intel.com/content/www/us/en/newsroom/article/crypto-acceleration-enabling-path-future-computing.html)
14. [Arm Cortex-A65AE Core Cryptographic Extension Technical Reference Manual](https://documentation-service.arm.com/static/605df846256fc952d8c37836?token=)
15. [Arm GNU Toolchain feature list](https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain)
16. [Cryptography Extensions: Vector Instructions, Version 1.0, RISC-V Ratified Specifications Library](https://docs.riscv.org/reference/isa/v20250508/unpriv/vector-crypto.html)
17. [A Lightweight ISA Extension for AES and SM4, arXiv:2002.07041](https://arxiv.org/abs/2002.07041)
18. [RISC-V security model specification, chapter 3, GitHub](https://github.com/riscv/riscv-security-model/blob/main/specification/src/chapter3.adoc)
19. [Mitigation for Frequency Throttling Side-Channel Attack, Intel IPP Crypto documentation](https://www.intel.com/content/www/us/en/docs/crypto-primitives-library/developer-guide-reference/2025-0/mitigation-for-frequency-throttling.html)
20. [Untitled :: RISC-V ISA Manual](https://riscv.github.io/riscv-unified-db/manual/html/isa/isa_20240411/chapters/scalar-crypto.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Instruction set architectures › x86 ISA extensions

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/aes-instruction-set

English original: https://www.edgepedia.org/aes-instruction-set
