SHA-2
The NIST Merkle–Damgård hash family behind most of today's TLS, signatures and software
Overview
SHA-2 is a family of hash functions designed by the NSA and published by NIST in FIPS 180. SHA-256 and SHA-512 are the most widely deployed cryptographic hashes in use, and the family remains unbroken after more than two decades of analysis.
SHA-2 follows the Merkle–Damgård construction. The message is padded with a single 1 bit, zeros and a length field, split into fixed-size blocks, and fed through a compression function built in Davies–Meyer style from a dedicated block cipher. SHA-256 works on 32-bit words with 64 rounds over 512-bit blocks; SHA-512 uses 64-bit words with 80 rounds over 1024-bit blocks. Each round combines additions, rotations and the Ch and Maj boolean functions.
NextSSL carries SHA-224 and SHA-256 from the 32-bit branch, and SHA-384, SHA-512, SHA-512/224 and SHA-512/256 from the 64-bit branch. The truncated variants use distinct initial values, so they are not simple prefixes of the full outputs. SHA-512/256 is often faster than SHA-256 on 64-bit processors while offering the same nominal collision resistance.
SHA-256 and SHA-512 were introduced in FIPS 180-2 in 2002, SHA-224 was added in 2004, and the SHA-512/t variants arrived with FIPS 180-4. RFC 6234 provides a reference implementation. The family is used throughout TLS, X.509, code signing, Git's SHA-256 object format and many blockchains. It is the default hash in most libraries and the one auditors expect to see.
History
2001–2012SHA-256, SHA-384 and SHA-512 proposed
Published in FIPS 180-2
SHA-224 added
Specified in RFC 6234
SHA-512/224 and SHA-512/256 added in FIPS 180-4
How it works
- Pad the message and append its bit length
- Split into 512-bit (SHA-256) or 1024-bit (SHA-512) blocks
- Expand each block into a message schedule of 64 or 80 words
- Run the compression rounds and add the result into the chaining state
- Output the final state, truncated for the shorter variants
Security notes
No practical collision or preimage attacks are known against full SHA-2. SHA-256 and SHA-512 are vulnerable to length-extension, so they must not be used as a MAC by simple prefixing a key; use HMAC instead. SHA-384 and SHA-512/256 are not length-extendable because their output is truncated.
Typical uses
Variants in NextSSL
6| Algorithm | Tier | Sizes (bytes) | Standards | API |
|---|---|---|---|---|
| SHA-256 sha256 |
safe FIPS | out 32 | FIPS 180-4, RFC 6234 | safe |
| SHA-384 sha384 |
safe FIPS | out 48 | FIPS 180-4, RFC 6234 | safe |
| SHA-512 sha512 |
safe FIPS | out 64 | FIPS 180-4, RFC 6234 | safe |
| SHA-512-224 sha512-224 |
safe FIPS | out 28 | FIPS 180-4 | safe |
| SHA-512-256 sha512-256 |
safe FIPS | out 32 | FIPS 180-4 | safe |
| SHA-224 sha224 |
standard FIPS | out 28 | FIPS 180-4, RFC 6234 | safe |
Frequently asked questions
Which SHA-2 variants does NextSSL include?
NextSSL registers 6 SHA-2 variants: sha256, sha384, sha512, sha512-224, sha512-256, sha224.
Families with similar names
Other hash functions
All 424Related
NIST SP 800-90A deterministic random bit generator built on HMAC
BLAKE2A fast, secure successor to BLAKE with built-in keying, salting and tree hashing
SHA-3 and KeccakThe Keccak sponge, standardised by NIST in FIPS 202 as a structural alternative to SHA-2
HKDFHMAC-based extract-and-expand key derivation function (RFC 5869)
BLAKE2A fast, secure successor to BLAKE with built-in keying, salting and tree hashing
HMACThe standard way to build a MAC from a cryptographic hash (RFC 2104, FIPS 198-1)