SHA-2 (Secure Hash Algorithm 2) is a set of cryptographic hash functions designed by the United States National Security Agency (NSA) and first published in 2001. They are built using the Merkle–Damgård construction, from a one-way compression function itself built using the Davies–Meyer structure from a specialized block cipher.
SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of six hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256. SHA-256 and SHA-512 are hash functions whose digests are eight 32-bit and 64-bit words, respectively. They use different shift amounts and additive constants, but their structures are otherwise virtually identical, differing only in the number of rounds. SHA-224 and SHA-384 are truncated versions of SHA-256 and SHA-512 respectively, computed with different initial values. SHA-512/224 and SHA-512/256 are also truncated versions of SHA-512, but the initial values are generated using the method described in Federal Information Processing Standards (FIPS) PUB 180-4.
SHA-2 was first published by the National Institute of Standards and Technology (NIST) as a U.S. federal standard. The SHA-2 family of algorithms are patented in the U.S. The United States has released the patent under a royalty-free license.
As of 2026, the SHA-2 cryptographic hash function remains secure against known attacks, including those from quantum computers.
Hash standard
With the publication of FIPS PUB 180-2, NIST added three additional hash functions in the SHA family. The algorithms are collectively known as SHA-2, named after their digest lengths (in bits): SHA-256, SHA-384, and SHA-512.
The algorithms were first published in 2001 in the draft FIPS PUB 180-2, at which time public review and comments were accepted. In August 2002, FIPS PUB 180-2 became the new Secure Hash Standard, replacing FIPS PUB 180-1, which was released in April 1995. The updated standard included the original SHA-1 algorithm, with updated technical notation consistent with that describing the inner workings of the SHA-2 family.Federal Register Notice 02-21599, Announcing Approval of FIPS Publication 180-2
In February 2004, a change notice was published for FIPS PUB 180-2, specifying an additional variant, SHA-224, defined to match the key length of two-key Triple DES. In October 2008, the standard was updated in FIPS PUB 180-3, including SHA-224 from the change notice, but otherwise making no fundamental changes to the standard. The primary motivation for updating the standard was relocating security information about the hash algorithms and recommendations for their use to Special Publications 800-107 and 800-57.Federal Register Notice E8-24743, Announcing Approval of FIPS Publication 180-3 Detailed test data and example message digests were also removed from the standard, and provided as separate documents.
In January 2011, NIST published SP800-131A, which specified a move from the then-current minimum of 80-bit security (provided by SHA-1) allowable for federal government use until the end of 2013, to 112-bit security (provided by SHA-2) being both the minimum requirement (starting in 2014) and the recommended security level (starting from the publication date in 2011).
In March 2012, the standard was updated in FIPS PUB 180-4, adding the hash functions SHA-512/224 and SHA-512/256, and describing a method for generating initial values for truncated versions of SHA-512. Additionally, a restriction on padding the input data prior to hash calculation was removed, allowing hash data to be calculated simultaneously with content generation, such as a real-time video or audio feed. Padding the final data block must still occur prior to hash output.Federal Register Notice 2012-5400, Announcing Approval of FIPS Publication 180-4.
In July 2012, NIST revised SP800-57, which provides guidance for cryptographic key management. The publication disallowed creation of digital signatures with a hash security lower than 112 bits after 2013. The previous revision from 2007 specified the cutoff to be the end of 2010. In August 2012, NIST revised SP800-107 in the same manner.
In March 2023, NIST announced its decision to revise FIPS 180-4.NIST, Decision to Revise FIPS 180-4, Secure Hash Standard (SHS) FIPS 180-5 will remove the SHA-1 specification, add guidance from SP 800-107, and include editorial updates.
The NIST hash function competition selected a new hash function, SHA-3, in 2012. The SHA-3 algorithm is not derived from SHA-2.
Applications
The SHA-2 hash function is implemented in some widely used security applications and protocols, including TLS and SSL, PGP, SSH, S/MIME, and IPsec. The inherent computational demand of SHA-2 algorithms has driven the proposal of more efficient solutions, such as those based on application-specific integrated circuits (ASICs) hardware accelerators.
SHA-256 is used for authenticating Debian software packages and in the DKIM message signing standard; SHA-512 is part of a system to authenticate archival video from the International Criminal Tribunal of the Rwandan genocide. SHA-256 and SHA-512 are used in DNSSEC. Linux distributions usually use 512-bit SHA-2 for secure password hashing.
Several cryptocurrencies, including Bitcoin, use SHA-256 for verifying transactions and calculating proof of work or proof of stake. The rise of ASIC SHA-2 accelerator chips has led to the use of scrypt-based proof-of-work schemes.
In both 4G and 5G mobile networks, HMAC-SHA-256 is utilized as a key derivation function (KDF) to generate cryptographic keys essential for securing communications. This process is defined in the 3rd Generation Partnership Project (3GPP) Technical Specifications TS 33.4013GPP TS 33.401, Security architecture and procedures for E-UTRAN and TS 33.501,3GPP TS 33.501, Security architecture and procedures for 5G systems which outline the security architecture and procedures for these networks.
SHA-1, SHA-2, and SHA-3 are the Secure Hash Algorithms required by law for use in certain U.S. Government applications, including use within other cryptographic algorithms and protocols, for the protection of sensitive unclassified information. FIPS PUB 180-1 also encouraged adoption and use of SHA-1 by private and commercial organizations. SHA-1 is being retired for most government uses; the U.S. National Institute of Standards and Technology says, "NIST recommends that federal agencies transition away from SHA-1 for all applications as soon as possible. Federal agencies should use SHA-2 or SHA-3 as an alternative to SHA-1.". NIST's directive that U.S. government agencies ought to, but not explicitly must, stop uses of SHA-1 after 2010 was hoped to accelerate migration away from SHA-1.
The SHA-2 functions were not quickly adopted initially, despite better security than SHA-1. Reasons might include lack of support for SHA-2 on systems running Windows XP SP2 or older and a lack of perceived urgency since SHA-1 collisions had not yet been found. The Google Chrome team announced a plan to make their web browser gradually stop honoring SHA-1-dependent TLS certificates over a period from late 2014 and early 2015. Similarly, Microsoft announced that Internet Explorer and Edge [Legacy] would stop honoring public SHA-1-signed TLS certificates from February 2017. Mozilla disabled SHA-1 in Firefox during early January 2016, but had to re-enable it temporarily via an update, after problems with web-based user interfaces of some router models and security appliances.
Cryptanalysis and validation For a hash function for which L is the number of bits in the message digest, finding a message that corresponds to a given message digest can always be done using a brute force search in 2L evaluations. This is called a preimage attack and may or may not be practical depending on L and the particular computing environment. The second criterion, finding two different messages that produce the same message digest, known as a collision, requires on average only 2L/2 evaluations using a birthday attack.
Some of the applications that use cryptographic hashes, such as password storage, are only minimally affected by a collision attack. Constructing a password that works for a given account requires a preimage attack, as well as access to the hash of the original password (typically in the shadow file) which may or may not be trivial. Reversing password encryption (e.g., to obtain a password to try against a user's account elsewhere) is not made possible by the attacks. (However, even a secure password hash cannot prevent brute-force attacks on weak passwords.)
In the case of document signing, an attacker could not simply fake a signature from an existing document—the attacker would have to produce a pair of documents, one innocuous and one damaging, and get the private key holder to sign the innocuous document. There are practical circumstances in which this is possible; until the end of 2008, it was possible to create forged SSL certificates using an MD5 collision which would be accepted by widely used web browsers.Alexander Sotirov, Marc Stevens, Jacob Appelbaum, Arjen Lenstra, David Molnar, Dag Arne Osvik, Benne de Weger, MD5 considered harmful today: Creating a rogue CA certificate. , accessed March 29, 2009.
Increased interest in cryptographic hash analysis during the SHA-3 competition produced several new attacks on the SHA-2 family, the best of which are given in the table below. Only the collision attacks are of practical complexity; none of the attacks extend to the full round hash function.
At FSE 2012, researchers at Sony gave a presentation suggesting pseudo-collision attacks could be extended to 52 rounds on SHA-256 and 57 rounds on SHA-512 by building upon the biclique pseudo-preimage attack.Ji Li, Takanori Isobe and Kyoji Shibutani, Sony China Research Laboratory and Sony Corporation, Converting Meet-in-the-Middle Preimage Attack into Pseudo Collision Attack: Application to SHA-2 . .
Published in Year Attack method Attack Variant Rounds Complexity New Collision Attacks Against Up To 24-step SHA-2. 2008 Differential Collision SHA-256 24/64 215.5 SHA-512 24/80 222.5 Preimages for step-reduced SHA-2 2009 Meet-in-the-middle Preimage SHA-256 42/64 2251.7 43/64 2254.9 SHA-512 42/80 2502.3 46/80 2511.5 Advanced meet-in-the-middle preimage attacks 2010 Meet-in-the-middle Preimage SHA-256 42/64 2248.4 SHA-512 42/80 2494.6 Higher-Order Differential Attack on Reduced SHA-256 2011 Differential Pseudo-collision SHA-256 46/64 2178 33/64 246 Bicliques for Preimages: Attacks on Skein-512 and the SHA-2 family 2011 Biclique Preimage SHA-256 45/64 2255.5 SHA-512 50/80 2511.5 Pseudo-preimage SHA-256 52/64 2255 SHA-512 57/80 2511 Improving Local Collisions: New Attacks on Reduced SHA-256 2013 Differential Collision SHA-256 31/64 265.5 Pseudo-collision SHA-256 38/64 237 Branching Heuristics in Differential Collision Search with Applications to SHA-512 2014 Heuristic differential Pseudo-collision SHA-512 38/80 240.5 Analysis of SHA-512/224 and SHA-512/256 2016 Differential Collision SHA-256 28/64 practical SHA-512 27/80 practical Pseudo-collision SHA-512 39/80 practical New Records in Collision Attacks on SHA-2 2024 Differential Collision SHA-256 31/64 249.8 SHA-512 31/80 2115.6 Pseudo-collision SHA-256 39/64 practical
Official validation
Implementations of all FIPS-approved security functions can be officially validated through the CMVP program, jointly run by the National Institute of Standards and Technology (NIST) and the Communications Security Establishment (CSE). For informal verification, a package to generate a high number of test vectors is made available for download on the NIST site; the resulting verification, however, does not replace the formal CMVP validation, which is required by law for certain applications.