liveBook · Manning

Merkle–Damgård construction

As explained in Real-World Cryptography

The Merkle–Damgård construction builds an arbitrary-length hash function by iteratively applying a fixed-size compression function to padded message blocks.

The Merkle–Damgård construction turns a fixed-size compression function into a hash function for messages of arbitrary length. It processes the message block by block, carrying each intermediate result into the next call. section 2.5.1

The construction follows two practical steps:

  • Pad the message until its length is a multiple of the compression function’s block size, then split it into equal-sized blocks. section 2.5.1
  • Apply the compression function to each block and the previous intermediate value; the final result becomes the digest. section 2.5.1

SHA-256 example

SHA-256 uses 512-bit blocks. A padded message is divided into those blocks, processed sequentially, and reduced to a final digest. SHA-2 builds its compression function with Davies–Meyer. section 2.5.1

$ echo -n "hello world" | openssl dgst -sha224
2f05477fc24bb4faefd86517156dafdecec45b8ad3cf2522a563582b
$ echo -n "hello world" | openssl dgst -sha256
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
$ echo -n "hello world" | openssl dgst -sha384
fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3
   e417cb71ce646efd0819dd8c088de1bd
$ echo -n "hello world" | openssl dgst -sha512
309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f
   989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f

Compare SHA-224, SHA-256, SHA-384, and SHA-512 digest outputs for the same input using OpenSSL. section 2.5.1

How Real-World Cryptography covers it

How deep it goes
Defines padding, blocking, and chaining, but treats the compression function as a black box.
Examples
Uses SHA-256’s 512-bit blocks, block-processing diagrams, and OpenSSL digest commands for SHA-2 variants.
What it assumes
Assumes only a compression function as a black box and postpones detailed block-cipher mechanics.
What you can do after
Evaluate/understand how fixed-size compression supports arbitrary-length hashing and where collision resistance comes from.
How it connects
Connects compression functions with padding, block ciphers, Davies–Meyer, collision resistance, and SHA-2.

Also explained in

Compare how 2 books explain Merkle–Damgård construction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.