How a hash chain shows tampering

· 3 min read

#how-it-works#security

A hash chain is a list of records where each record carries the hash of the record before it. Edit one record in the middle and every record after it stops matching.

The short version

A hash function turns data into a digest, and if the data changes, the digest changes. That is why digests are used to detect changes (FIPS 180-4). In a chain, each record stores the previous record's hash next to its own data. Change record 2 and its hash changes, but record 3 still holds the old one, so the mismatch shows.

A hash chain of three records with one edited record Three records in a row. Record 1 holds data only, record 2 holds data plus hash 1, and record 3 holds data plus hash 2. Arrows carry each hash to the next record. Record 2 is edited, so its hash changes and no longer matches the copy stored in record 3, shown by a dashed arrow. Record 1 data (first record) Record 2 (edited) data + hash 1 Record 3 data + hash 2 1 hash 1 2 hash 2 3 stored copy no longer matches
Simplified: three records, labels instead of real hashes; the dashed arrow is the mismatch.

Step by step

  1. Hash record 1 to get hash 1.
  2. Store hash 1 inside record 2, then hash record 2 (its data plus hash 1) to get hash 2. Repeat for every record.
  3. To check the chain, recompute each hash and compare it with the copy stored in the next record.
  4. An edited record produces a new hash, so the copy in the next record no longer matches.

Why it matters

Git works like this: it names every object by a hash of its content, and a commit stores the hash of its parent. The Bitcoin white paper chains timestamps the same way, and changing one block would mean redoing the proof-of-work for that block and every block after it. My take: checking is one cheap pass of hashing, but a chain only shows tampering and cannot prevent it, and someone who rewrites every later record can make it look consistent unless you keep the latest hash somewhere you trust.

Sources