# SHA-2

**SHA-2**（安全哈希算法2）是由美国国家标准与技术研究院（NIST）于2002年在联邦信息处理标准（FIPS）180-2中规定的一族加密哈希函数，包含六种算法，可生成224至512位的消息摘要。<sup>[1](https://csrc.nist.gov/nist-cyber-history/cryptography/chapter)</sup><sup> • </sup><sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup> NIST设计该族算法，旨在提供与[高级加密标准](https://www.edgepedia.org/zh/advanced-encryption-standard)（AES）相匹配的哈希强度，并在SHA-1预期的弱点成为现实之前将其取代；2005年宣布了对SHA-1的理论攻击，此后SHA-2成为联邦和[互联网安全](https://www.edgepedia.org/zh/internet-security)标准中的默认哈希族。<sup>[1](https://csrc.nist.gov/nist-cyber-history/cryptography/chapter)</sup><sup> • </sup><sup>[3](https://csrc.nist.gov/Projects/Hash-Functions?trk=article-ssr-frontend-pulse_little-text-block)</sup>

| 关键事实 | 详情 |
|---|---|
| 标准 | 规定于FIPS 180-2（2002年）；现行修订版为FIPS 180-4，2015年8月发布<sup>[1](https://csrc.nist.gov/nist-cyber-history/cryptography/chapter)</sup><sup> • </sup><sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup> |
| 成员 | SHA-224、SHA-256、SHA-384、SHA-512、SHA-512/224、SHA-512/256<sup>[3](https://csrc.nist.gov/Projects/Hash-Functions?trk=article-ssr-frontend-pulse_little-text-block)</sup> |
| 摘要长度 | 视算法不同，为224至512位<sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup> |
| 消息长度限制 | SHA-224和SHA-256最高2<sup>64</sup>位；SHA-384、SHA-512、SHA-512/224和SHA-512/256最高2<sup>128</sup>位<sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup> |
| 安全强度 | SHA-256、SHA-384和SHA-512发布时宣布的抗碰撞性分别为2<sup>128</sup>、2<sup>192</sup>和2<sup>256</sup>次操作，与AES密钥长度相匹配<sup>[4](https://www.sciencedirect.com/science/article/pii/S0045790605000820)</sup> |
| 已知弱点 | Merkle–Damgård结构允许长度扩展攻击；HMAC构造不受影响<sup>[5](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)</sup> |
| 密码分析现状 | 尚无已知的针对完整SHA-2函数的碰撞或原像攻击；最好的攻击仅覆盖缩减轮数的版本<sup>[6](https://arxiv.org/abs/2406.20072)</sup> |

## 家族成员与设计

FIPS 180-4规定了七种哈希算法：SHA-1以及六种SHA-2函数SHA-224、SHA-256、SHA-384、SHA-512、SHA-512/224和SHA-512/256。<sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup><sup> • </sup><sup>[3](https://csrc.nist.gov/Projects/Hash-Functions?trk=article-ssr-frontend-pulse_little-text-block)</sup> 该族有两种主要设计。SHA-256和SHA-512结构相似，SHA-256以32位字运算，SHA-512以64位字运算。<sup>[7](https://crypto.stanford.edu/~mironov/papers/hash_survey.pdf)</sup> 截断变体由这两种派生而来：SHA-224基于SHA-256，而SHA-384、SHA-512/224和SHA-512/256基于SHA-512；NIST还另行定义了一种通用截断程序，适用于最长512位的任意输出长度。<sup>[8](https://www.cryptrec.go.jp/exreport/cryptrec-ex-2401-2014.pdf)</sup>

所有成员均采用Merkle–Damgård结构。填充后的消息被划分为块，SHA-224和SHA-256为512位一块，SHA-384和SHA-512为1024位一块，每块与当前链接值一起送入压缩函数；最终的链接值即为消息摘要。<sup>[8](https://www.cryptrec.go.jp/exreport/cryptrec-ex-2401-2014.pdf)</sup><sup> • </sup><sup>[9](https://datatracker.ietf.org/doc/html/rfc6234)</sup> SHA-512将每个1024位块拆分为十六个64位字，并将其扩展为80个扩展消息字，用于80步状态更新；SHA-256同样在64步中扩展十六个32位字。<sup>[8](https://www.cryptrec.go.jp/exreport/cryptrec-ex-2401-2014.pdf)</sup><sup> • </sup><sup>[9](https://datatracker.ietf.org/doc/html/rfc6234)</sup> 初始哈希值取自素数平方根的小数部分，轮常数取自最初若干素数立方根的小数部分，因此这些常数不携带任何隐藏结构。<sup>[9](https://datatracker.ietf.org/doc/html/rfc6234)</sup>

## 用途与安全性质

哈希算法将任意长度的消息映射为固定长度的摘要，用于检测消息自摘要生成以来是否发生变化。<sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup> 这些算法之所以被称为安全的，是因为对于给定算法，要找到与给定摘要匹配的消息，或找到两条摘要相同的不同消息，在计算上均不可行；消息的任何改动都极有可能改变摘要，从而导致数字签名或基于密钥的哈希消息认证码（HMAC）中的验证失败。<sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup> SHA-2函数通常与数字签名算法和HMAC配合使用，或用于生成随机比特。<sup>[2](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)</sup>

**长度扩展。** 由于Merkle–Damgård哈希的最终输出即其内部状态，攻击者若看到SHA-256(secret + message)并知道合并后的长度，便可将哈希状态设为该输出，继续对追加数据进行哈希，从而在不知密钥的情况下为扩展后的消息生成有效标签。<sup>[5](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)</sup> HMAC构造通过内外两轮嵌套运算对密钥和消息进行哈希，两次迭代均输入秘密值，从而阻止了这种扩展攻击，HMAC-SHA-2变体被批准用于消息认证。<sup>[5](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)</sup><sup> • </sup><sup>[3](https://csrc.nist.gov/Projects/Hash-Functions?trk=article-ssr-frontend-pulse_little-text-block)</sup> SHA-384和SHA-224等截断输出也减少了暴露面，因为它们计算更大的内部哈希并丢弃部分状态。<sup>[5](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)</sup>

## 标准化历史

NIST于1993年发布了最初的安全哈希标准FIPS 180，定义了后来成为SHA-1的算法。到2005年，中国的研究人员已发现对SHA-1抗碰撞性的理论攻击，但NIST早已预见到既需要与AES强度匹配的更大哈希函数，也预见到SHA-1可能存在漏洞，并于2002年在FIPS 180-2中规定了SHA-2族。<sup>[1](https://csrc.nist.gov/nist-cyber-history/cryptography/chapter)</sup> 2006年3月，NIST告知联邦机构尽快停止将SHA-1用于数字签名和时间戳，并在2010年之后将SHA-2用于这些应用。<sup>[10](https://csrc.nist.gov/projects/hash-functions/nist-policy-on-hash-functions)</sup>

由于SHA-1和SHA-2设计相似，NIST判断开发一种全新的哈希函数是审慎之举，于2007年11月2日宣布启动SHA-3竞赛，2012年10月2日选定Keccak，并于2015年8月在FIPS 202中定义了SHA-3。<sup>[1](https://csrc.nist.gov/nist-cyber-history/cryptography/chapter)</sup> SHA-3采用基于置换的海绵结构而非Merkle–Damgård结构，但NIST的政策指出，无需将应用从SHA-2迁移到SHA-3；SHA-2算法历经时间考验，已被纳入硬件，SHA-3实质上处于储备状态，除非发现SHA-2的重大弱点。<sup>[1](https://csrc.nist.gov/nist-cyber-history/cryptography/chapter)</sup><sup> • </sup><sup>[10](https://csrc.nist.gov/projects/hash-functions/nist-policy-on-hash-functions)</sup> NIST鼓励应用和协议设计者为任何需要互操作性的哈希应用至少实现SHA-256。<sup>[10](https://csrc.nist.gov/projects/hash-functions/nist-policy-on-hash-functions)</sup>

SHA-1事件塑造了SHA-2的采用时间线。NIST于2011年通过SP 800-131A弃用SHA-1，并于2013年底禁止将其用于数字签名；2022年12月，NIST发布计划，要在2030年12月31日前摆脱SHA-1的剩余用途，此后任何将SHA-1列为已批准的FIPS 140模块将移入历史列表；联邦机构被要求改用SHA-2或SHA-3。<sup>[3](https://csrc.nist.gov/Projects/Hash-Functions?trk=article-ssr-frontend-pulse_little-text-block)</sup><sup> • </sup><sup>[11](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)</sup> 2023年3月的一份规划说明记载，NIST已在两轮公开征求意见后决定修订FIPS 180-4。<sup>[12](https://csrc.nist.gov/pubs/fips/180-4/upd1/final)</sup>

## 密码分析现状

尚无已发表的攻击能破解完整的SHA-2函数。最好的碰撞攻击仅对缩减步数的版本有效：SHA-256和SHA-512的首个22步碰撞于2008年发表，<sup>[13](https://arxiv.org/abs/0803.1220)</sup> 2024年宣布了SHA-256的实用31步碰撞和39步半自由起始碰撞，随后一种SAT与计算机代数混合求解器复现了38步半自由起始碰撞。<sup>[6](https://arxiv.org/abs/2406.20072)</sup> 对底层结构的分析得出结论：Chabaud–Joux攻击和Dobbertin式攻击均不适用，差分攻击和线性攻击也不适用于该结构本身。<sup>[14](https://crypto.orange-labs.fr/acg/publication/infoPublication.php?id=35)</sup>

量子计算机改变的是程度而非性质。在NTT，研究人员发现了SHA-256和SHA-512的碰撞，这些碰撞在经典计算下失败，但在量子机器上会成功；他们推断，一旦此类机器问世，针对SHA-2的碰撞攻击将能够破解更多步数。<sup>[15](https://www.rd.ntt/e/research/JN202305_21871.html)</sup>

## 部署

SHA-2广泛嵌入互联网安全标准之中。TLS 1.2用HMAC定义其伪随机函数，对该规范中的所有密码套件使用SHA-256，并指示新密码套件使用SHA-256或更强的标准哈希函数。<sup>[16](https://www.rfc-editor.org/info/rfc5246/)</sup> X.509证书为ECDSA和DSA签名与SHA-224、SHA-256、SHA-384和SHA-512的组合使用专用算法标识符。<sup>[17](https://www.rfc-editor.org/info/rfc5758/)</sup> SHA-256是比特币中广泛使用的哈希函数，SHA-256和SHA-512在ECDSA和EdDSA等传统公钥系统以及较新的协议中均用作密钥派生函数。<sup>[18](https://arxiv.org/abs/2407.08284)</sup><sup> • </sup><sup>[19](https://eprint.iacr.org/2024/478.pdf)</sup>

该族算法也在专用硬件中实现。FPGA研究探索了SHA-256和SHA-512的架构，其中多操作数模加主导芯片面积和关键路径延迟，所报道的核在Xilinx XC2VP30-7器件上分别达到SHA-256 1.4 Gbit/s和SHA-512 1.8 Gbit/s的吞吐量。<sup>[4](https://www.sciencedirect.com/science/article/pii/S0045790605000820)</sup><sup> • </sup><sup>[20](https://researchportal.ulisboa.pt/en/publications/improving-sha-2-hardware-implementations/)</sup> 由于在HMAC等用途中部分输入是秘密的，实现也是侧信道攻击的目标；2021年的一项研究提出了首个针对HMAC-SHA-2真实硬件实现的实用模板攻击，并已证明对HMAC-SHA-2的差分功耗分析可揭示秘密初始状态并实现伪造。<sup>[21](https://cris.technion.ac.il/en/publications/first-full-fledged-side-channel-attack-on-hmac-sha-2/)</sup><sup> • </sup><sup>[19](https://eprint.iacr.org/2024/478.pdf)</sup>

## References

1. [Cryptography, NIST CSRC Cyber History](https://csrc.nist.gov/nist-cyber-history/cryptography/chapter)
2. [FIPS 180-4, Secure Hash Standard (SHS), NIST](https://csrc.nist.gov/files/pubs/fips/180-4/final/docs/fips180-4.pdf)
3. [Hash Functions, NIST CSRC](https://csrc.nist.gov/Projects/Hash-Functions?trk=article-ssr-frontend-pulse_little-text-block)
4. [Hardware implementation analysis of SHA-256 and SHA-512 algorithms on FPGAs, Computers and Electrical Engineering (2005)](https://www.sciencedirect.com/science/article/pii/S0045790605000820)
5. [Network Security: Private Communication in a Public World, 3rd Edition, NIST](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)
6. [SHA-256 Collision Attack with Programmatic SAT, arXiv (2024)](https://arxiv.org/abs/2406.20072)
7. [Hash survey, Stanford University](https://crypto.stanford.edu/~mironov/papers/hash_survey.pdf)
8. [The SHA-2 Family of Hash Functions, CRYPTREC report](https://www.cryptrec.go.jp/exreport/cryptrec-ex-2401-2014.pdf)
9. [RFC 6234: US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF), IETF](https://datatracker.ietf.org/doc/html/rfc6234)
10. [NIST Policy on Hash Functions, NIST CSRC](https://csrc.nist.gov/projects/hash-functions/nist-policy-on-hash-functions)
11. [NIST Transitioning Away from SHA-1 for All Applications, NIST (2022)](https://www.nist.gov/news-events/news/2022/12/nist-transitioning-away-sha-1-all-applications)
12. [FIPS 180-4, Secure Hash Standard (SHS), NIST CSRC publication page](https://csrc.nist.gov/pubs/fips/180-4/upd1/final)
13. [22-Step Collisions for SHA-2, arXiv (2008)](https://arxiv.org/abs/0803.1220)
14. [Security Analysis of SHA-256 and Sisters, Orange Labs ACG](https://crypto.orange-labs.fr/acg/publication/infoPublication.php?id=35)
15. [Security of Hash Functions against Attacks Using Quantum Computers, NTT R&D](https://www.rd.ntt/e/research/JN202305_21871.html)
16. [RFC 5246: The Transport Layer Security (TLS) Protocol Version 1.2, IETF](https://www.rfc-editor.org/info/rfc5246/)
17. [RFC 5758: Internet X.509 Public Key Infrastructure, Additional Algorithms and Identifiers for DSA and ECDSA, IETF](https://www.rfc-editor.org/info/rfc5758/)
18. [Performance Evaluation of Hashing Algorithms on Commodity Hardware, arXiv (2024)](https://arxiv.org/abs/2407.08284)
19. [The Insecurity of SHA2 under the Differential Fault Characteristic of Boolean Functions, IACR ePrint](https://eprint.iacr.org/2024/478.pdf)
20. [Improving SHA-2 hardware implementations, University of Lisbon](https://researchportal.ulisboa.pt/en/publications/improving-sha-2-hardware-implementations/)
21. [First Full-Fledged Side Channel Attack on HMAC-SHA-2, Technion, COSADE 2021](https://cris.technion.ac.il/en/publications/first-full-fledged-side-channel-attack-on-hmac-sha-2/)

---
*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: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Numerical, string, and geometric algorithms › Pseudorandomness and hashing algorithms

Copyright 2026 Edgepedia

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

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

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