Hash Functions & Merkle Structures

  • Hash properties: preimage, second preimage, collision
  • Merkle-Damgard construction
  • Padding and length encoding
  • Length extension attacks
  • Merkle trees and proofs
  • Domain separation and encoding
1 / 10

Hash security goals

  • Preimage ~ 2^n
  • Second preimage ~ 2^n
  • Collision ~ 2^(n/2)

Collision resistance is weaker

2 / 10

Merkle-Damgard

  • Pad message to block size
  • Iterate compression function
  • Final chaining value is digest

Streaming but length extension exists

3 / 10

Padding

  • Append 0x80
  • Zeros until length mod 64 == 56
  • Append 64-bit bit length

Padding is part of the message

4 / 10

Length extension

  • MAC = H(key || msg) is unsafe
  • Attacker can append data and forge MAC
  • Fix: HMAC or AEAD
5 / 10

HMAC intuition

  • Inner hash and outer hash are both keyed
  • Breaks the continuation property
  • Safe against length extension
6 / 10

Merkle trees

  • Leaves hashed, nodes hash children
  • Root commits to all leaves
  • Proof size O(log N)
7 / 10

Domain separation

  • Tag inputs: leaf vs node
  • Encode lengths or use canonical formats
  • Avoid ambiguous concatenation
8 / 10

Pitfalls

  • Raw hash as MAC
  • No domain separation
  • Non-canonical encodings
  • Assuming collision resistance implies preimage
9 / 10

What you will build

  • SHA-256 from scratch
  • Merkle root + proofs
  • Length extension attack
  • Hash commitments
10 / 10
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.