Skip to content
The Compression Function
step 1/5

Reading — step 1 of 5

Read

~1 min readThe Compression Function

The Compression Function

For each 64-byte block, the compression function updates the running hash state (a,b,c,d,e,f,g,h):

Initialize: (a,b,c,d,e,f,g,h) = (H[0]..H[7])

For i = 0 to 63:
    T1 = h + Σ1(e) + Ch(e,f,g) + K[i] + W[i]
    T2 = Σ0(a) + Maj(a,b,c)
    h = g
    g = f
    f = e
    e = d + T1
    d = c
    c = b
    b = a
    a = T1 + T2
                       (all + mod 2^32)

After 64 rounds:
    H[0] += a
    H[1] += b
    ...
    H[7] += h

Each round shifts the state; T1 and T2 are computed FROM the current state and mixed in. After all 64 rounds the state is added back to H.

This is a one-way function: knowing the output H gives no efficient way to recover the input bytes. That's why hashes are used for password storage, content addressing (Git, IPFS), and digital signatures.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…