SHA-2 and SHA-3
The SHA family's parameters and evolution, SHA-512's compression-function structure, and SHA-3's sponge construction, which fixes SHA-2's length-extension weakness by design.
- State the message size, block size, word size and digest size for each SHA-2 variant.
- Trace SHA-512's padding, block splitting and compression function, including the Davies-Meyer feedforward.
- Describe SHA-3's absorb and squeeze phases and the rate-versus-capacity tradeoff.
- Explain why SHA-3's sponge construction has no length-extension vulnerability, unlike SHA-2.
18 min read
Intuition
The birthday attack is why SHA-0 and SHA-1, both 160-bit hash functions, stopped being trusted: practical collision attacks against them made that 160-bit margin meaningless in practice, not just in theory. NIST’s response was two separate hash families, built on different internal designs on purpose, so that a weakness found in one does not automatically compromise the other.
Mechanism
SHA-2 replaced SHA-1 with three variants distinguished by output size: SHA-256, SHA-384 and SHA-512, with SHA-224, SHA-512/224 and SHA-512/256 added as shorter-digest options built on the same internal machinery. SHA-3, the newest member, followed in 2015 with SHA3-224, SHA3-256, SHA3-384 and SHA3-512, and is built on a completely different construction from SHA-2, discussed below.
| Algorithm | Message size | Block size | Word size | Digest size |
|---|---|---|---|---|
| SHA-1 | < 2^64 | 512 | 32 | 160 |
| SHA-224 | < 2^64 | 512 | 32 | 224 |
| SHA-256 | < 2^64 | 512 | 32 | 256 |
| SHA-384 | < 2^128 | 1024 | 64 | 384 |
| SHA-512 | < 2^128 | 1024 | 64 | 512 |
| SHA-512/224 | < 2^128 | 1024 | 64 | 224 |
| SHA-512/256 | < 2^128 | 1024 | 64 | 256 |
Aside
The notes date SHA-2’s introduction to 2002; the slides say 2001. NIST’s SHA-2 standard, FIPS 180-2, was published in August 2002, so the notes’ date is the one that checks out against the standard itself. Either way, the exact year is background, not something either source treats as a number to memorise, unlike the SHA parameters table above.
Mechanism
SHA-512’s structure. SHA-512 takes an input message shorter than bits and produces a 512-bit digest, processing the input in 1024-bit blocks.
Padding: the original -bit message is padded with a single 1 bit, then enough 0 bits to bring the total length to , leaving room at the end. A 128-bit encoding of is then appended, bringing the padded message to an exact multiple of 1024 bits.
Formula
SHA-512 padding
- the original message length, in bits
- a single appended 1 bit
- the number of 0 bits appended after it, chosen to satisfy the congruence
After this padding, a 128-bit encoding of L is appended, bringing the total to an exact multiple of 1024 bits.
Mechanism
The padded message splits into blocks of 1024 bits each, . is a fixed, publicly-specified 512-bit constant defined in the standard: not secret, not random, just the starting state fed into the first block.
Inside the compression function : the previous state is unpacked into eight 64-bit working registers through , transformed across 80 rounds. A message schedule expands the 1024-bit block into 80 round words , the same role AES’s key schedule plays in turning one key into many round keys. Each round mixes in one and one public round constant ; six of the eight registers just shift along unchanged, so only two new register values are actually computed per round. After round 79, the Davies-Meyer feedforward adds the final through , mod , back onto the original . The result of those eight additions is , passed on to the next block, or output as the digest after the last one.
Mechanism
SHA-3’s sponge construction is a different design entirely. Instead of eight separate working registers, SHA-3 keeps one unified state of bits, repeatedly transformed by a single permutation .
Absorbing phase. Each message block is XORed into the top bits of the state, then scrambles the entire state. The bottom bits are never touched directly by the message input, which is what protects the security margin.
Squeezing phase. Output is read from the top bits of the state, with applied again between each read. Squeezing can continue for as many bits as the caller needs, which makes SHA-3 naturally an extendable output function, not just a fixed-length digest.
Rate versus capacity. (the rate) and (the capacity) trade off against each other: a larger absorbs and squeezes more bits per application of , meaning faster hashing, but a smaller means a smaller security margin. The different SHA-3 variants change only where this split falls.
Formula
SHA-3 state size
- the total width of the permutation state, in bits
- the rate: bits absorbed or squeezed per application of the permutation f
- the capacity: bits held back from direct message input or output, the security margin
A larger r means faster hashing at the cost of a smaller c, and therefore less security margin.
Mechanism
No length-extension vulnerability. In SHA-2, an attacker who knows can compute without ever knowing itself, because is the full internal state after the last block, and the compression function can simply resume from there. SHA-3’s sponge eliminates this: squeezing only ever exposes the rate bits, never the capacity bits, so the full state needed to resume the permutation is never recoverable from the output alone.
Compare
Eight 64-bit working registers, transformed across 80 rounds using a message schedule and round constants, with a Davies-Meyer feedforward at the end. The digest is the full internal state, which is exactly what makes length extension possible.
One unified state of bits, repeatedly run through a single permutation : absorb the message into the rate bits, then squeeze output from the rate bits, as many times as needed. The capacity bits are never exposed, which is what closes the length-extension gap.
Exam detail
The SHA parameters table (message size, block size, word size, digest size) is the exact set of numbers this unit expects memorised, per algorithm. Beyond the numbers, the single most examinable structural contrast is length extension: SHA-2 is vulnerable to it because its output is the full compression-function state; SHA-3 is not, because its sponge construction never exposes the hidden capacity bits that would let an attacker resume the permutation.
Pitfall
Do not describe SHA-3 as “SHA-2 with more rounds” or assume it shares SHA-2’s eight-register structure. They are built on entirely different internal designs, Merkle-Damgård-style compression for SHA-2, a sponge for SHA-3, chosen specifically so a weakness in one family does not automatically threaten the other.
Recall
An attacker knows H(m) for a SHA-2 hash but not m itself. What can they compute, and why does the same trick fail against SHA-3?
Against SHA-2, they can compute H(m || extra) for any extra data, because H(m) is the full internal state after the last block, and the compression function can resume from exactly that state. Against SHA-3, the digest only ever reveals the rate bits from squeezing, never the hidden capacity bits, so the attacker cannot reconstruct the full state needed to resume the permutation and extend the message.
Source
Week 6 slides PDF