Everipedia Logo
Everipedia is now IQ.wiki - Join the IQ Brainlist and our Discord for early access to editing on the new platform and to participate in the beta testing.
SHA-2

SHA-2

SHA-2 (Secure Hash Algorithm 2) is a set of cryptographic hash functions designed by the United States National Security Agency (NSA).[3] They are built using the Merkle–Damgård structure, from a one-way compression function itself built using the Davies–Meyer structure from a (classified) 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 novel hash functions computed with 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 published in 2001 by the National Institute of Standards and Technology (NIST) a U.S. federal standard (FIPS). The SHA-2 family of algorithms are patented in US patent 6829355.[4] The United States has released the patent under a royalty-free license.[5]

Currently, the best public attacks break preimage resistance for 52 out of 64 rounds of SHA-256 or 57 out of 80 rounds of SHA-512, and collision resistance for 46 out of 64 rounds of SHA-256.[1][2]

SHA-2
Secure Hash Algorithms
Concepts
hash functions· SHA**·** DSA
Main standards
SHA-0**·** SHA-1**·** SHA-2**·** SHA-3
General
DesignersNational Security Agency
First published2001
Series(SHA-0), SHA-1, SHA-2, SHA-3
CertificationFIPS PUB 180-4, CRYPTREC, NESSIE
Detail
Digest sizes224, 256, 384, or 512 bits
StructureMerkle–Damgård construction with Davies–Meyer compression function
Rounds64 or 80
Best public cryptanalysis
A 2011 attack breaks preimage resistance for 57 out of 80 rounds of SHA-512, and 52 out of 64 rounds for SHA-256.[1]Pseudo-collision attack against up to 46 rounds of SHA-256.[2] SHA-256 and SHA-512 are prone to length extension attacks. By guessing the hidden part of the state, length extension attacks on SHA-224 and SHA-384 succeed with probability 2−(256−224)= 2−32
2
−224and 2−(512−384)= 2−128
2
−384respectively.

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.[6]

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.[7] 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.[8][9][10] Detailed test data and example message digests were also removed from the standard, and provided as separate documents.[11]

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).[12]

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.[13]

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.[10] In August 2012, NIST revised SP800-107 in the same manner.[9]

The NIST hash function competition selected a new hash function, SHA-3, in 2012.[14] 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.

SHA-256 partakes in the process of authenticating Debian software packages[15] 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.[16] SHA-256 and SHA-512 are proposed for use in DNSSEC.[17] Unix and Linux vendors are moving to using 256- and 512-bit SHA-2 for secure password hashing.[18]

Several cryptocurrencies like Bitcoin use SHA-256 for verifying transactions and calculating proof of work or proof of stake.[19] The rise of ASIC SHA-2 accelerator chips has led to the use of scrypt-based proof-of-work schemes.

SHA-1 and SHA-2 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, "Federal agencies should stop using SHA-1 for...applications that require collision resistance as soon as practical, and must use the SHA-2 family of hash functions for these applications after 2010" (emphasis in original).[20] NIST's directive that U.S. government agencies must stop uses of SHA-1 after 2010[21] 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[22] 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.[23][24][25] Similarly, Microsoft announced[26] that Internet Explorer and Edge would stop honoring public SHA-1-signed TLS certificates from February 2017. Mozilla disabled SHA-1 in early January 2016, but had to re-enable it temporarily via a Firefox update, after problems with web-based user interfaces of some router models and security appliances.[27]

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.[28]

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.[29]

Published inYearAttack methodAttackVariantRoundsComplexity
*New Collision Attacks Against
Up To 24-step SHA-2*[30]
2008DeterministicCollisionSHA-25624/64228.5
SHA-51224/80232.5
Preimages for step-reduced SHA-2[31]2009Meet-in-the-middlePreimageSHA-25642/642251.7
43/642254.9
SHA-51242/802502.3
46/802511.5
*Advanced meet-in-the-middle
preimage attacks*[32]
2010Meet-in-the-middlePreimageSHA-25642/642248.4
SHA-51242/802494.6
*Higher-Order Differential Attack
on Reduced SHA-256*[2]
2011DifferentialPseudo-collisionSHA-25646/642178
33/64246
*Bicliques for Preimages: Attacks on
Skein-512 and the SHA-2 family*[1]
2011BicliquePreimageSHA-25645/642255.5
SHA-51250/802511.5
Pseudo-preimageSHA-25652/642255
SHA-51257/802511
*Improving Local Collisions: New
Attacks on Reduced SHA-256*[33]
2013DifferentialCollisionSHA-25631/64265.5
Pseudo-collisionSHA-25638/64237
*Branching Heuristics in Differential Collision
Search with Applications to SHA-512*[34]
2014Heuristic differentialPseudo-collisionSHA-51238/80240.5
Analysis of SHA-512/224 and SHA-512/256[35]2016DifferentialCollisionSHA-25628/64practical
SHA-51227/80practical
Pseudo-collisionSHA-51239/80practical

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.

As of December 2013, there are over 1300 validated implementations of SHA-256 and over 900 of SHA-512, with only 5 of them being capable of handling messages with a length in bits not a multiple of eight while supporting both variants.[36]

Test vectors

Hash values of an empty string (i.e., a zero-length input text).

Even a small change in the message will (with overwhelming probability) result in a mostly different hash, due to the avalanche effect. For example, adding a period to the end of this sentence changes almost half (111 out of 224) of the bits in the hash:

Pseudocode

Pseudocode for the SHA-256 algorithm follows. Note the great increase in mixing between bits of the w[16..63] words compared to SHA-1.

The computation of the ch and maj values can be optimized the same way as described for SHA-1.

SHA-224 is identical to SHA-256, except that:

  • the initial hash values h0 through h7 are different, and

  • the output is constructed by omitting h7.

SHA-512 is identical in structure to SHA-256, but:

  • the message is broken into 1024-bit chunks,

  • the initial hash values and round constants are extended to 64 bits,

  • there are 80 rounds instead of 64,

  • the message schedule array w has 80 64-bit words instead of 64 32-bit words,

  • to extend the message schedule array w, the loop is from 16 to 79 instead of from 16 to 63,

  • the round constants are based on the first 80 primes 2..409,

  • the word size used for calculations is 64 bits long,

  • the appended length of the message (before pre-processing), in bits, is a 128-bit big-endian integer, and

  • the shift and rotate amounts used are different.

SHA-384 is identical to SHA-512, except that:

  • the initial hash values h0 through h7 are different (taken from the 9th through 16th primes), and

  • the output is constructed by omitting h6 and h7.

SHA-512/t is identical to SHA-512 except that:

  • the initial hash values h0 through h7 are given by the SHA-512/t IV generation function,

  • the output is constructed by truncating the concatenation of h0 through h7 at t bits,

  • t equal to 384 is not allowed, instead SHA-384 should be used as specified, and

  • t values 224 and 256 are especially mentioned as approved.

The SHA-512/t IV generation function evaluates a modified SHA-512 on the ASCII string "SHA-512/t", substituted with the decimal representation of t. The modified SHA-512 is the same as SHA-512 except its initial values h0 through h7 have each been XORed with the hexadecimal constant 0xa5a5a5a5a5a5a5a5.

Sample C implementation for SHA-2 family of hash functions can be found in RFC 6234 [55] .

Comparison of SHA functions

In the table below, internal state means the "internal hash sum" after each compression of a data block.

Comparison of SHA functions
Algorithm and variantOutput size
(bits)
Internal state size
(bits)
Block size
(bits)
RoundsOperationsSecurity (inbits) against collision attacksCapacity
against length extension attacks
Performance on Skylake (median cpb)[37]First published
long messages8 bytes
MD5 (as reference)128128
(4 × 32)
51264And, Xor, Rot,Add (mod 232),Or≤18
(collisions found)[38]
04.9955.001992
**SHA-0**160160
(5 × 32)
51280And, Xor, Rot,Add (mod 232),Or<34
(collisions found)
0≈ SHA-1≈ SHA-11993
**SHA-1**<63
(collisions found[39])
3.4752.001995
**SHA-2**SHA-224
SHA-256
224
256
256
(8 × 32)
51264And, Xor, Rot,Add (mod 232),Or, Shr112
128
32
0
7.62
7.63
84.50
85.25
2004
2001
SHA-384
SHA-512
384
512
512
(8 × 64)
102480And, Xor, Rot,Add (mod 264),Or, Shr192
256
128 (≤ 384)
0
5.12
5.06
135.75
135.50
2001
SHA-512/224

SHA-512/256
224
256
112
128
288
256
≈ SHA-384≈ SHA-3842012
**SHA-3**SHA3-224
SHA3-256
SHA3-384
SHA3-512
224
256
384
512
1600
(5 × 5 × 64)
1152
1088
832
576
24[40]And, Xor, Rot, Not112
128
192
256
448
512
768
1024
8.12
8.59
11.06
15.88
154.25
155.50
164.00
164.00
2015
SHAKE128
SHAKE256
d (arbitrary)
d (arbitrary)
1344
1088
min(d/2, 128)
min(d/2, 256)
256
512
7.08
8.59
155.25
155.50

In the bitwise operations column, "Rot" stands for rotate no carry, and "Shr" stands for right logical shift. All of these algorithms employ modular addition in some fashion except for SHA-3.

More detailed performance measurements on modern processor architectures are given in the table below.

CPU architectureFrequencyAlgorithmWord size (bits)Cycles/byte x86MiB/s x86Cycles/byte x86-64MiB/s x86-64
Intel Ivy Bridge3.5 GHzSHA-2563216.8019913.05256
SHA-5126443.66768.48394
AMD Piledriver APU3.8 GHzSHA-2563222.8715818.47196
SHA-5126488.364112.43292

The performance numbers labeled 'x86' were running using 32-bit code on 64-bit processors, whereas the 'x86-64' numbers are native 64-bit code. While SHA-256 is designed for 32-bit calculations, it does benefit from code optimized for 64-bit processors on the x86 architecture. 32-bit implementations of SHA-512 are significantly slower than their 64-bit counterparts. Variants of both algorithms with different output sizes will perform similarly, since the message expansion and compression functions are identical, and only the initial hash values and output sizes are different. The best implementations of MD5 and SHA-1 perform between 4.5 and 6 cycles per byte on modern processors.

Testing was performed by the University of Illinois at Chicago on their hydra8 system running an Intel Xeon E3-1275 V2 at a clock speed of 3.5 GHz, and on their hydra9 system running an AMD A10-5800K APU at a clock speed of 3.8 GHz.[41] The referenced cycles per byte speeds above are the median performance of an algorithm digesting a 4,096 byte message using the SUPERCOP cryptographic benchmarking software.[42] The MiB/s performance is extrapolated from the CPU clockspeed on a single core; real-world performance will vary due to a variety of factors.

Implementations

Below is a list of cryptography libraries that support SHA-2:

  • Botan

  • Bouncy Castle

  • Cryptlib

  • Crypto++

  • Libgcrypt

  • libsodium

  • Nettle

  • OpenSSL

  • wolfSSL

See also

  • Comparison of cryptographic hash functions

  • Comparison of cryptography libraries

  • Hashcash

  • HMAC

  • International Association for Cryptologic Research (IACR)

  • sha1sum (sha224sum, sha256sum, sha384sum and sha512sum) commands

  • Trusted timestamping

References

[1]
Citation Linkeprint.iacr.orgDmitry Khovratovich, Christian Rechberger & Alexandra Savelieva (2011). "Bicliques for Preimages: Attacks on Skein-512 and the SHA-2 family" (PDF). IACR Cryptology ePrint Archive. 2011:286.
Sep 24, 2019, 9:04 PM
[2]
Citation Linkeprint.iacr.orgMario Lamberger & Florian Mendel (2011). "Higher-Order Differential Attack on Reduced SHA-256" (PDF). IACR Cryptology ePrint Archive. 2011:37.
Sep 24, 2019, 9:04 PM
[3]
Citation Linkwww.staff.science.uu.nl"On the Secure Hash Algorithm family" (PDF). Archived from the original (PDF) on 2016-03-30.
Sep 24, 2019, 9:04 PM
[4]
Citation Linkworldwide.espacenet.comUS 6829355
Sep 24, 2019, 9:04 PM
[5]
Citation Linkdatatracker.ietf.org"Licensing Declaration for US patent 6829355". Retrieved 2008-02-17. Cite journal requires |journal= (help)
Sep 24, 2019, 9:04 PM
[6]
Citation Linkfederalregister.govFederal Register Notice 02-21599, Announcing Approval of FIPS Publication 180-2
Sep 24, 2019, 9:04 PM
[7]
Citation Linkcsrc.nist.gov"FIPS 180-2 with Change Notice 1" (PDF). csrc.nist.gov.
Sep 24, 2019, 9:04 PM
[8]
Citation Linkfederalregister.govFederal Register Notice E8-24743, Announcing Approval of FIPS Publication 180-3
Sep 24, 2019, 9:04 PM
[9]
Citation Linkcsrc.nist.govFIPS SP 800-107 Recommendation for Applications Using Approved Hash Algorithms
Sep 24, 2019, 9:04 PM
[10]
Citation Linkcsrc.nist.govFIPS SP 800-57 Recommendation for Key Management: Part 1: General
Sep 24, 2019, 9:04 PM
[11]
Citation Linkcsrc.nist.gov"NIST.gov – Computer Security Division – Computer Security Resource Center".
Sep 24, 2019, 9:04 PM
[12]
Citation Linkcsrc.nist.govFIPS SP 800-131A Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths
Sep 24, 2019, 9:04 PM
[13]
Citation Linkfederalregister.govFederal Register Notice 2012-5400, Announcing Approval of FIPS Publication 180-4
Sep 24, 2019, 9:04 PM
[14]
Citation Linkwww.nist.gov"NIST Selects Winner of Secure Hash Algorithm (SHA-3) Competition". Retrieved 24 February 2015.
Sep 24, 2019, 9:04 PM
[15]
Citation Linkgoogle.com"Debian codebase in Google Code". Archived from the original on November 7, 2011. Retrieved 2011-11-08.
Sep 24, 2019, 9:04 PM
[16]
Citation Linkwww.nytimes.comJohn Markoff, A Tool to Verify Digital Records, Even as Technology Shifts, New York Times, January 26, 2009
Sep 24, 2019, 9:04 PM
[17]
Citation Linkwww.rfc-editor.orgRFC 5702,RFC-Editor.org
Sep 24, 2019, 9:04 PM
[18]
Citation Linkpeople.redhat.comUlrich Drepper, Unix crypt with SHA-256/512
Sep 24, 2019, 9:04 PM
[19]
Citation Linkwww.mycryptopedia.com"What Is SHA-256 And How Is It Related to Bitcoin? - Mycryptopedia". Mycryptopedia. 2017-09-21. Retrieved 2018-09-17.
Sep 24, 2019, 9:04 PM
[20]
Citation Linkweb.archive.orgNational Institute on Standards and Technology Computer Security Resource Center, NIST's Policy on Hash Functions Archived 2011-06-09 at the Wayback Machine, accessed March 29, 2009.
Sep 24, 2019, 9:04 PM