Merkle-Damgård Construction

The hash-function structure that chains compression over message blocks, the basis of SHA-256 and its length-extension quirk.

Basically

A way of building a hash function by chewing through a message in fixed-size chunks and carrying the result forward.

Key Takeaways

  • It iterates a compression function over padded blocks, so one algorithm can hash any length of input.
  • The chaining adds a length-extension quirk: given a hash and the length, you can append data and predict the new hash.
  • SHA-256 is built this way, which is why length extension matters for naive MAC schemes.

The Structure

A Merkle-Damgård hash pads the message to a block boundary, then feeds each block into a compression function together with the previous chaining value. The final chaining value is the digest.

It is a construction, not a function: pair it with any secure compression function and you get a hash for arbitrary input length.

The Length-Extension Quirk

Because the digest is just the internal state, anyone who knows a digest and the message length can resume hashing from it. Appending data to the message yields a predictable new digest without knowing the message.

That breaks the naive pattern of authenticating with hash(secret

Defences and Replacements

HMAC, wide-pipe designs and length encoding all blunt the quirk, and SHA-3's sponge construction removes it structurally.

Bitcoin uses double SHA-256 for block hashing, which is enough for that role because length extension is not an attack there.

0

← All 1876 glossary terms