# RC4

**RC4**（里维斯特密码4）是由RSA数据安全公司（RSA Data Security）的罗恩·里维斯特（Ron Rivest）于1987年设计的流密码。它用密钥调度一个256字节的置换表，逐字节生成伪随机密钥流，每个明文字节通过与对应密钥流字节异或来加密。<sup>[1](https://eprint.iacr.org/2013/176)</sup><sup> • </sup><sup>[2](https://www.iacr.org/workshops/fse2013/slides/Slides05_2.pdf)</sup> 在1994年9月一篇匿名发帖公开该算法之前，RSA数据安全公司一直将其作为商业秘密保留；此后，它成为实际应用中最广泛部署的流密码之一，用于保护TLS Web流量以及WEP和WPA无线协议。<sup>[3](https://time.com/archive/6912978/the-secrets-out/)</sup><sup> • </sup><sup>[1](https://eprint.iacr.org/2013/176)</sup><sup> • </sup><sup>[4](https://isg.rhul.ac.uk/tls/)</sup> 其密钥流中累积的统计偏差导致针对TLS的实际明文恢复攻击，互联网工程任务组（IETF）于2015年禁止在TLS中使用RC4密码套件。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup><sup> • </sup><sup>[5](https://www.rfc-editor.org/info/rfc7465/)

| 关键事实 | 详情 |
|---|---|
| 设计者与日期 | 罗恩·里维斯特（Ron Rivest），RSA数据安全公司（RSA Data Security），1987年<sup>[1](https://eprint.iacr.org/2013/176)</sup> |
| 公开披露 | 算法于1994年9月被匿名发布到Usenet新闻组sci.crypt和Cypherpunks邮件列表<sup>[3](https://time.com/archive/6912978/the-secrets-out/)</sup> |
| 结构 | 基于256字节状态表的密钥调度算法（Key Scheduling Algorithm，KSA）和伪随机生成算法（Pseudorandom Generation Algorithm，PRGA）<sup>[2](https://www.iacr.org/workshops/fse2013/slides/Slides05_2.pdf)</sup> |
| RFC 6229中测试的密钥长度 | 40、56、64、80、128、192和256位，密钥流偏移量为0到4096字节<sup>[6](https://www.rfc-editor.org/info/rfc6229/)</sup> |
| TLS占比峰值 | 截至2013年，约50%的TLS流量由RC4保护<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> |
| TLS攻击成本 | 单字节偏差攻击用约2<sup>30</sup>个会话恢复220个明文字节；双字节攻击恢复16个连续字节需要约10·2<sup>30</sup>次加密<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> |
| 标准状态 | RFC 7465（2015年2月）要求TLS客户端和服务器永不协商RC4密码套件；RFC 9325重申实现不得协商RC4<sup>[5](https://www.rfc-editor.org/info/rfc7465/)</sup><sup> • </sup><sup>[7](https://www.rfc-editor.org/rfc/rfc9325.html)</sup> |

## 设计

RC4是一种流密码：它把秘密密钥扩展为长密钥流，加密就是将该密钥流与明文异或。该算法由两部分组成。密钥调度算法（Key Scheduling Algorithm，KSA）用秘密密钥初始化数字0到255的一个置换，随后伪随机生成算法（Pseudorandom Generation Algorithm，PRGA）反复交换表中的两个条目，并在每一步输出一个密钥流字节。<sup>[2](https://www.iacr.org/workshops/fse2013/slides/Slides05_2.pdf)</sup> 该密码接受可变密钥长度；RFC 6229中的测试向量覆盖40到256位的密钥，且加密与解密使用相同的密钥流。<sup>[6](https://www.rfc-editor.org/info/rfc6229/)</sup>

该设计紧凑，在软件中速度快，这解释了它为何被用于硬件受限的协议。硬件实现进一步推动了它：FPGA设计每个时钟周期处理两个或四个密钥流字节，将RC4加密和解密作为协处理器嵌入，并通过以太网通信。<sup>[8](https://arxiv.org/abs/1401.2727)</sup>

## 商业秘密与1994年泄露

RC4由罗恩·里维斯特（Ron Rivest）为RSA数据安全公司（RSA Data Security）开发，并作为商业秘密保留。<sup>[9](https://faculty.kfupm.edu.sa/COE/talalkh/Sec/crept_Stream.pdf)</sup> 1994年9月9日，声称实现该算法的源代码被匿名发布到Cypherpunks邮件列表和Usenet新闻组sci.crypt。<sup>[3](https://time.com/archive/6912978/the-secrets-out/)</sup><sup> • </sup><sup>[10](https://citeseerx.ist.psu.edu/document?doi=a56701deba204b45a54116a6077d017d353575ca&repid=rep1&type=pdf)</sup> 由于该代码产生的输出与RC4实现相符，它被称为“据称的RC4”，并于1996年出现在[布鲁斯·施奈尔](https://www.edgepedia.org/zh/bruce-schneier)（Bruce Schneier）的《应用密码学》（*Applied Cryptography*）中。<sup>[11](https://web.stanford.edu/class/cs259/WWW08/slides/02-Crypto.pdf)</sup> 算法公开后，RC4不再能被当作专有算法，其使用通过已经将其标准化的协议传播开来。<sup>[10](https://citeseerx.ist.psu.edu/document?doi=a56701deba204b45a54116a6077d017d353575ca&repid=rep1&type=pdf)</sup>

## 部署

RC4曾在三种主要场景中服役。在保护Web和电子商务流量的TLS协议中，基于RC4的密码套件（如TLS_RSA_WITH_RC4_128_SHA）得到广泛支持，并常被服务器优先选用；约2013年，全部TLS流量中大约一半使用RC4，部分原因是针对TLS中CBC模式加密的攻击使评论者建议将其作为替代方案。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> 在无线网络中，RC4在WEP以及WPA/TKIP中加密流量；WPA/TKIP是电气电子工程师学会（IEEE）为WEP制定的后继协议。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup>

## 密码分析弱点

**统计偏差。** RC4密钥流并非均匀随机。早期输出字节对特定值表现出强烈偏差，密码分析结果表明，使用前应丢弃流输出的初始部分；RFC 6229因此公布了偏移量最高达4096字节的测试向量，以便实现者验证丢弃方案。<sup>[6](https://www.rfc-editor.org/info/rfc6229/)</sup> 后来的工作表明，问题并不局限于流的开头：两类新的统计偏差表明，无论丢弃多少个初始字节，RC4密钥流都可与随机流区分开。<sup>[1](https://eprint.iacr.org/2013/176)</sup>

**针对TLS的攻击。** 2013年，伦敦大学皇家霍洛韦学院（Royal Holloway, University of London）和伊利诺伊大学芝加哥分校（University of Illinois at Chicago）的纳代姆·阿尔法丹（Nadhem AlFardan）、丹尼尔·J. 伯恩斯坦（Daniel J. Bernstein）、肯尼思·G. 帕特森（Kenneth G. Paterson）、贝特拉姆·珀特林（Bertram Poettering）和雅各布·C. N. 舒尔特（Jacob C. N. Schuldt）提出了当TLS选择RC4加密时的唯密文明文恢复攻击。<sup>[12](https://www.usenix.org/conference/usenixsecurity13/technical-sessions/paper/alFardan)</sup> 这些攻击利用密钥流中的统计缺陷，当同一明文在多个会话中被反复加密时，这些缺陷会显现出来。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> 单字节偏差攻击是一种多会话攻击，利用前256个密钥流字节中的偏差：在TLS记录协议（Record Protocol）中使用SHA-1哈希时，前36个明文字节来自不可预测的Finished消息，无法恢复，因此该攻击恢复220字节的TLS明文，可靠恢复需要约2<sup>30</sup>个会话，而某些字节仅需2<sup>24</sup>个会话即可恢复。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> 双字节偏差攻击建立在弗卢勒-麦格鲁（Fluhrer-McGrew）偏差之上，在单个会话内工作，并针对任意位置的明文；可靠恢复16个连续字节大约需要10·2^30次加密，而6·2<sup>30</sup>个会话给出50%的可靠性。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup><sup> • </sup><sup>[18](https://www.isg.rhul.ac.uk/tls/index.html)</sup> 由于它不需要重新运行TLS握手，在实践中可能比单字节攻击更高效。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> 后续工作利用动态规划扩展了曼廷（Mantin）偏差攻击，以恢复更长的明文，例如HTTP会话cookie和密码，使用2<sup>31</sup>个密文以80%的成功率恢复16字节明文。<sup>[13](https://openalex.org/W2599300409)</sup> 后续研究在阿尔法丹等人的结果基础上，形式化证明了与TLS攻击相关的偏差。<sup>[14](https://doi.org/10.1007/s10623-014-0003-0)</sup>

**无线协议。** 历史上最著名的RC4攻击针对WEP，利用初始化期间秘密密钥与公开初始化向量结合的方式；这些攻击不适用于TLS中的RC4，后者需要新的攻击思路。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> 2013年的TLS攻击也直接适用于WPA/TKIP，成功率相近，因为WPA/TKIP使用逐包RC4密钥，其结构在前256个密钥流字节中产生另一组偏差。<sup>[4](https://isg.rhul.ac.uk/tls/)</sup> 一篇RC4密码分析综述得出结论：安全使用需要消除包括偏差字节、密钥碰撞以及WEP和WPA特有的密钥恢复攻击在内的弱点。<sup>[15](https://www.mecs-press.org/ijcnis/ijcnis-v7-n7/v7n7-5.html)</sup>

**提出的修复方案。** 保罗（Paul）和普雷尼尔（Preneel）在FSE 2004上为增强RC4而提出的RC4A，本身也被发现易受类似的区分攻击；同一篇论文提出了一种新的伪随机比特生成器RC4B，据信对已知攻击具有更好的免疫力。<sup>[1](https://eprint.iacr.org/2013/176)</sup> 一个相关变体Spritz已在密码模式下用DieHarder统计测试套件进行评估。<sup>[16](https://arxiv.org/abs/1502.01763)</sup> 2018年一项对RC4统计特性的分析发现，大多数攻击建立在算法本身之上，即算法易受分析攻击和弱密钥影响，并认为安全问题出现在RC4与特定协议结合时，而非来自每一种可能的使用方式。<sup>[17](https://papers.ssrn.com/sol3/Delivery.cfm/5212317.pdf?abstractid=5212317&mirid=1)</sup>

## 弃用

标准层面的回应是禁止而非修补。RFC 7465由微软（Microsoft）的阿哈龙·波波夫（Aharon Popov）代表IETF TLS工作组于2015年2月发布，要求TLS客户端和服务器在任何TLS版本中都永不协商RC4密码套件：客户端不得在ClientHello消息中包含RC4套件，服务器不得选择它们，而只收到RC4提议的服务器必须终止握手，并可能给出insufficient_security致命警报。<sup>[5](https://www.rfc-editor.org/info/rfc7465/)</sup> 该RFC的理由引用了近期的密码分析；当时该分析需要2^26个会话或约10⋅2^30次加密，并被判断为正处于可实际利用的边缘。<sup>[5](https://www.rfc-editor.org/info/rfc7465/)</sup><sup> • </sup><sup>[19](https://www.rfc-editor.org/rfc/rfc7465.html)</sup><sup> • </sup><sup>[18](https://www.isg.rhul.ac.uk/tls/index.html)</sup> RFC 9325是目前安全使用TLS和DTLS的建议，重申实现不得协商RC4密码套件，并指出DTLS已经专门禁止RC4。<sup>[7](https://www.rfc-editor.org/rfc/rfc9325.html)</sup> RFC 8996后来作为弃用TLS 1.0和TLS 1.1的一部分更新了RFC 7465。<sup>[5](https://www.rfc-editor.org/info/rfc7465/)</sup>

RC4从TLS中移除后，在其他地方留下了遗留依赖。

## References

1. [Jing Lv, Bin Zhang, and Dongdai Lin (2013). Distinguishing Attacks on RC4 and A New Improvement of the Cipher. Cryptology ePrint Archive 2013/176.](https://eprint.iacr.org/2013/176)
2. [FSE 2013 session slides: RC4 stream cipher, KSA and PRGA. IACR.](https://www.iacr.org/workshops/fse2013/slides/Slides05_2.pdf)
3. [The Secret's Out. Time, September 20, 1994.](https://time.com/archive/6912978/the-secrets-out/)
4. [On the Security of RC4 in TLS. AlFardan, Bernstein, Paterson, Poettering, Schuldt. Royal Holloway, University of London.](https://isg.rhul.ac.uk/tls/)
5. [RFC 7465: Prohibiting RC4 Cipher Suites. A. Popov, February 2015. RFC Editor.](https://www.rfc-editor.org/info/rfc7465/)
6. [RFC 6229: Test Vectors for the Stream Cipher RC4. J. Strombergson and S. Josefsson, May 2011. RFC Editor.](https://www.rfc-editor.org/info/rfc6229/)
7. [RFC 9325: Recommendations for Secure Use of TLS and DTLS. RFC Editor.](https://www.rfc-editor.org/rfc/rfc9325.html)
8. [Hardware Implementation of four byte per clock RC4 algorithm. arXiv:1401.2727.](https://arxiv.org/abs/1401.2727)
9. [Stream ciphers lecture notes, KFUPM.](https://faculty.kfupm.edu.sa/COE/talalkh/Sec/crept_Stream.pdf)
10. [Web Security & Commerce. CiteSeerX.](https://citeseerx.ist.psu.edu/document?doi=a56701deba204b45a54116a6077d017d353575ca&repid=rep1&type=pdf)
11. [Cryptography Overview slides, Stanford CS259.](https://web.stanford.edu/class/cs259/WWW08/slides/02-Crypto.pdf)
12. [On the Security of RC4 in TLS. 22nd USENIX Security Symposium, 2013.](https://www.usenix.org/conference/usenixsecurity13/technical-sessions/paper/alFardan)
13. [Analysing and exploiting the Mantin biases in RC4. OpenAlex record.](https://openalex.org/W2599300409)
14. [Proving TLS-attack related open biases of RC4. Sarkar, Sen Gupta, Paul, Maitra et al.](https://doi.org/10.1007/s10623-014-0003-0)
15. [A Survey on RC4 Stream Cipher. IJCNIS vol. 7 no. 7.](https://www.mecs-press.org/ijcnis/ijcnis-v7-n7/v7n7-5.html)
16. [Randomness of Spritz via DieHarder testing. arXiv:1502.01763.](https://arxiv.org/abs/1502.01763)
17. [Yaqoob Alshamsi (Khalifa University). On Statistical Properties of RC4: Identification of Weaknesses. SSRN.](https://papers.ssrn.com/sol3/Delivery.cfm/5212317.pdf?abstractid=5212317&mirid=1)
18. [On the Security of RC4 in TLS](https://www.isg.rhul.ac.uk/tls/index.html)
19. [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc7465.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: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Security governance and internet policy › Cryptographic protocols › Formal models and protocol analysis

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/rc4

English original: https://www.edgepedia.org/rc4
