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

