# SHA-1

**SHA-1**（安全哈希算法1）是一种密码学哈希函数，从长度小于2<sup>64</sup>比特的任意输入消息计算160比特的消息摘要，以512比特的块为单位处理消息，每块由32比特的字组成。它由美国国家安全局设计，1995年首次在联邦信息处理标准（FIPS）180-1《安全哈希标准》中规定。<sup>[1](https://www.rfc-editor.org/info/rfc3174/)</sup><sup> • </sup><sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup><sup> • </sup><sup>[3](https://www.rfc-editor.org/rfc/rfc9054.html)</sup> SHA-1曾是最广泛部署的哈希函数之一，但自2011年起已在对碰撞敏感的用途中被弃用，NIST将于2030年12月31日前在所有应用中将其撤销。<sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 160比特消息摘要；接受长度小于2<sup>64</sup>比特的输入消息，以512比特的块为单位处理，每块由32比特的字组成<sup>[1](https://www.rfc-editor.org/info/rfc3174/)</sup><sup> • </sup><sup>[4](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup><sup> • </sup><sup>[12](https://datatracker.ietf.org/doc/html/rfc3174)</sup> |
| 起源 | 由美国国家安全局设计；1995年在FIPS 180-1中规定；2001年9月以RFC 3174面向互联网发布文档<sup>[3](https://www.rfc-editor.org/rfc/rfc9054.html)</sup><sup> • </sup><sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup><sup> • </sup><sup>[1](https://www.rfc-editor.org/info/rfc3174/)</sup> |
| 首次全轮碰撞攻击 | 2005年：估计可在2<sup>69</sup>次运算内找到全部80轮的碰撞<sup>[5](https://datatracker.ietf.org/doc/html/rfc6194)</sup><sup> • </sup><sup>[13](https://www.rfc-editor.org/rfc/rfc6194.html)</sup> |
| 首次实际碰撞 | SHAttered，2017年2月23日，由阿姆斯特丹CWI与谷歌研究院完成；两份不同的PDF文件具有相同的摘要`38762cf7f55934b34d179ae6a4c80cadccbb7f0a`<sup>[6](https://shattered.io/sha1-collision/)</sup> |
| 攻击成本 | 约2<sup>63.1</sup>次SHA-1压缩运算，约6500 CPU年和100 GPU年（项目页面称110 GPU年），比暴力搜索快10万倍以上<sup>[7](https://shattered.io/static/shattered.pdf)</sup><sup> • </sup><sup>[6](https://shattered.io/sha1-collision/)</sup> |
| 监管状态 | NIST于2011年将其从新数字签名中弃用；2013年底起禁止用于签名；2030年12月31日前全面撤销<sup>[8](https://datatracker.ietf.org/doc/html/rfc9155.txt)</sup><sup> • </sup><sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup> |
| 后继算法 | SHA-2系列（SHA-256等）和SHA-3（FIPS 202，2015年）<sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup> |

## 算法工作原理

SHA-1是MD-SHA族中的一种迭代式单向哈希函数，该族还包括MD5和SHA-2。消息经过填充后被解析为512比特的块，每块送入压缩函数，压缩函数更新一个160比特的内部状态，称为链接值，其初始值为固定值。最终的链接值即为消息摘要。<sup>[1](https://www.rfc-editor.org/info/rfc3174/)</sup><sup> • </sup><sup>[7](https://shattered.io/static/shattered.pdf)</sup>

每块经过80步处理。16个消息字通过递推式\( W_t = S^{1}(W_{t-3} \oplus W_{t-8} \oplus W_{t-14} \oplus W_{t-16}) \)扩展为80个字，每一步先计算\( \mathrm{TEMP} = S^{5}(A) + f_t(B,C,D) + E + W_t + K_t \)，然后旋转五个工作字。轮函数\( f_t \)和常量\( K_t \)在四个20步的轮中变化：第一轮使用选择函数，常量为0x5a827999；第二轮和第四轮使用异或，常量分别为0x6ed9eba1和0xca62c1d6；第三轮使用多数函数，常量为0x8f1bbcdc。<sup>[1](https://www.rfc-editor.org/info/rfc3174/)</sup><sup> • </sup><sup>[7](https://shattered.io/static/shattered.pdf)</sup>

设计目标是：找到与给定摘要匹配的消息应需要约\( 2^{n} \)步，找到任意两条具有相同摘要的消息应需要约\( 2^{n/2} \)步，其中n为以比特计的摘要长度；因此对于160比特摘要，碰撞基线约为\( 2^{80} \)次求值。<sup>[1](https://www.rfc-editor.org/info/rfc3174/)</sup><sup> • </sup><sup>[6](https://shattered.io/sha1-collision/)</sup>

## 密码分析

**2005年的理论攻击。** 对SHA-1的首次攻击发表于2005年初，描述了对缩减至53轮的版本的理论攻击。次月，Wang、Yin和Yu估计可在2<sup>69</sup>次运算内找到SHA-1全部80轮的碰撞。<sup>[13](https://www.rfc-editor.org/rfc/rfc6194.html)</sup> NIST于2006年回应，鼓励数字签名应用迅速迁移到SHA-2系列；2011年SP 800-131A将SHA-1从生成新数字签名中弃用。<sup>[5](https://datatracker.ietf.org/doc/html/rfc6194)</sup><sup> • </sup><sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup>

**2017年的SHAttered。** 2017年2月23日，阿姆斯特丹CWI密码学组与谷歌研究院共同宣布了一对不同的PDF文档产生相同的SHA-1摘要，这是针对完整函数的首个具有实际意义的公开碰撞。该攻击为相同前缀碰撞：两对精心构造的近碰撞块将SHA-1的内部状态驱动到相同值。前缀经过特意选择，使得可以伪造出两份哈希相同但视觉内容可任意选择且互不相同的PDF文件。<sup>[6](https://shattered.io/sha1-collision/)</sup><sup> • </sup><sup>[7](https://shattered.io/static/shattered.pdf)</sup> 该计算花费约2<sup>63.1</sup>次SHA-1压缩运算，据研究论文称约6500 CPU年和100 GPU年（项目页面描述为110 GPU年），仍比2<sup>80</sup>的暴力搜索基线快10万倍以上。<sup>[7](https://shattered.io/static/shattered.pdf)</sup><sup> • </sup><sup>[6](https://shattered.io/sha1-collision/)</sup>

**2019年和2020年的选择前缀攻击。** 2019年的一种生日近碰撞攻击使得选择前缀攻击可在2<sup>68</sup>次运算内完成，Gaëtan Leurent和Thomas Peyrin的《SHA-1 is a Shambles》（2020年）将选择前缀碰撞降至2<sup>63</sup>次运算。NIST引用Shambles的结果作为在所有应用中而不仅是签名中终止SHA-1使用的理由。<sup>[9](https://git-scm.com/docs/BreakingChanges)</sup><sup> • </sup><sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup>

**HMAC-SHA-1。** 已发表的碰撞攻击并不适用于作为密钥哈希的SHA-1。RFC 6194于2011年指出，没有迹象表明对SHA-1的攻击可以扩展到HMAC-SHA-1；RFC 9155将SHA-1从TLS 1.2和DTLS 1.2的数字签名中弃用，但明确不弃用在记录保护中使用的带HMAC的SHA-1。<sup>[5](https://datatracker.ietf.org/doc/html/rfc6194)</sup><sup> • </sup><sup>[8](https://datatracker.ietf.org/doc/html/rfc9155.txt)</sup>

## NIST的撤销

NIST对SHA-1的时间表从限制走向退役。联邦机构被要求停止将SHA-1用于数字签名、时间戳和其他抗碰撞应用，2010年后这些用途须使用SHA-2系列，而SHA-1仍允许用于HMAC、密钥派生函数和随机数生成。<sup>[10](https://csrc.nist.gov/Projects/Hash-Functions/NIST-Policy-on-Hash-Functions)</sup> 2022年12月，NIST宣布将在2030年12月31日前在所有应用中停止使用SHA-1来施加密码保护。在此之前，它计划发布FIPS 180-5（FIPS 180的修订版，移除SHA-1规范）、修订SP 800-131A及其他受影响的出版物，并为密码模块验证计划和密码算法验证计划发布过渡策略。终止日期之后，SHA-1规范仍将可供处理此前受保护的信息使用。<sup>[2](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup> 2030年12月31日之后，任何将SHA-1列为已批准算法的FIPS 140验证密码模块将被移入历史列表。<sup>[10](https://csrc.nist.gov/Projects/Hash-Functions/NIST-Policy-on-Hash-Functions)</sup>

## 实际使用与迁移

尽管已被弃用，SHA-1在2017年仍广泛用于文档和TLS证书签名，以及Git版本控制系统等软件中的完整性和备份用途。<sup>[7](https://shattered.io/static/shattered.pdf)</sup> Git使用SHA-1为其内容寻址对象存储中的内容命名，SHAttered攻击促使Git做出两项回应：Git v2.13.0及以后版本转向不受SHAttered影响的加固版SHA-1实现；2018年底该项目选择SHA-256作为后继哈希，新仓库的默认哈希函数计划从sha1改为sha256。<sup>[11](https://git-scm.com/docs/hash-function-transition/2.52.0.html)</sup><sup> • </sup><sup>[9](https://git-scm.com/docs/BreakingChanges)</sup>

协议组织也朝着同一方向推进。RFC 9155规定MD5和SHA-1不得用于TLS 1.2和DTLS 1.2中的数字签名，CA/浏览器论坛已将SHA-1从证书签名中弃用。<sup>[8](https://datatracker.ietf.org/doc/html/rfc9155.txt)</sup> 在[COSE](https://www.edgepedia.org/zh/cbor-object-signing-and-encryption)算法注册表中，SHA-1的注册建议为“仅过滤”，意味着它可用于不需要抗碰撞性的场合，例如过滤候选值，或用于仅实现SHA-1的老旧硬件安全模块。<sup>[3](https://www.rfc-editor.org/rfc/rfc9054.html)</sup>

## References

1. [RFC 3174: US Secure Hash Algorithm 1 (SHA1), Eastlake and Jones, September 2001](https://www.rfc-editor.org/info/rfc3174/)
2. [NIST Transitioning Away from SHA-1 for All Applications, December 15, 2022](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)
3. [RFC 9054: CBOR Object Signing and Encryption (COSE): Hash Algorithms](https://www.rfc-editor.org/rfc/rfc9054.html)
4. [FIPS 180-4, Secure Hash Standard (SHS), NIST](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)
5. [RFC 6194: Security Considerations for the SHA-0 and SHA-1 Message-Digest Algorithms, March 2011](https://datatracker.ietf.org/doc/html/rfc6194)
6. [The SHAttered SHA-1 Collision, Explained, shattered.io](https://shattered.io/sha1-collision/)
7. [Stevens, Bursztein, Karpman, Albertini, Markov. The first collision for full SHA-1 (shattered.pdf)](https://shattered.io/static/shattered.pdf)
8. [RFC 9155: Deprecating MD5 and SHA-1 Signature Hashes in TLS 1.2 and DTLS 1.2](https://datatracker.ietf.org/doc/html/rfc9155.txt)
9. [Git BreakingChanges Documentation, git-scm.com](https://git-scm.com/docs/BreakingChanges)
10. [NIST Policy on Hash Functions, CSRC](https://csrc.nist.gov/Projects/Hash-Functions/NIST-Policy-on-Hash-Functions)
11. [Git hash-function-transition Documentation, git-scm.com](https://git-scm.com/docs/hash-function-transition/2.52.0.html)
12. [RFC 3174: US Secure Hash Algorithm 1 (SHA1)](https://datatracker.ietf.org/doc/html/rfc3174)
13. [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc6194.html)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › 安全治理与互联网政策 › 密码协议 › 协议标准与规范

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/sha-1

English original: https://www.edgepedia.org/sha-1
