CSEC3616Cybersecurity Engineering

    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.

    AlgorithmMessage sizeBlock sizeWord sizeDigest size
    SHA-1< 2^6451232160
    SHA-224< 2^6451232224
    SHA-256< 2^6451232256
    SHA-384< 2^128102464384
    SHA-512< 2^128102464512
    SHA-512/224< 2^128102464224
    SHA-512/256< 2^128102464256

    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 21282^{128} bits and produces a 512-bit digest, processing the input in 1024-bit blocks.

    Padding: the original LL-bit message is padded with a single 1 bit, then enough 0 bits to bring the total length to 896(mod1024)896 \pmod{1024}, leaving room at the end. A 128-bit encoding of LL is then appended, bringing the padded message to an exact multiple of 1024 bits.

    Formula

    SHA-512 padding

    L+1+k896(mod1024)L + 1 + k \equiv 896 \pmod{1024}
    LL
    the original message length, in bits
    11
    a single appended 1 bit
    kk
    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 NN blocks of 1024 bits each, M1,,MNM_1, \dots, M_N. H(IV)H^{(IV)} 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 FF: the previous state Hi1H_{i-1} is unpacked into eight 64-bit working registers aa through hh, transformed across 80 rounds. A message schedule expands the 1024-bit block MiM_i into 80 round words W0,,W79W_0, \dots, W_{79}, the same role AES’s key schedule plays in turning one key into many round keys. Each round mixes in one WtW_t and one public round constant KtK_t; 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 aa through hh, mod 2642^{64}, back onto the original Hi1H_{i-1}. The result of those eight additions is HiH_i, 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 r+cr + c bits, repeatedly transformed by a single permutation ff.

    Absorbing phase. Each message block is XORed into the top rr bits of the state, then ff scrambles the entire state. The bottom cc bits are never touched directly by the message input, which is what protects the security margin.

    Squeezing phase. Output is read from the top rr bits of the state, with ff 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. rr (the rate) and cc (the capacity) trade off against each other: a larger rr absorbs and squeezes more bits per application of ff, meaning faster hashing, but a smaller cc means a smaller security margin. The different SHA-3 variants change only where this split falls.

    Formula

    SHA-3 state size

    b=r+cb = r + c
    bb
    the total width of the permutation state, in bits
    rr
    the rate: bits absorbed or squeezed per application of the permutation f
    cc
    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 H(m)H(m) can compute H(mextra)H(m \| \text{extra}) without ever knowing mm itself, because H(m)H(m) 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 rr rate bits, never the cc 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 r+cr + c bits, repeatedly run through a single permutation ff: 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.