SHA-1 — Padding & Pipeline

The exam question your professor loves

Mission tie-in: SHA-1 exams often start with "how many padding zeros?" — master the 512-bit block layout before worrying about all 80 compression rounds.

What SHA-1 does

Takes any message → fixed 160-bit hash. One-way: you cannot recover the message. Tiny input change → completely different hash (avalanche effect).

Message M
Pad to 512-bit blocks
80 rounds / block
160-bit digest

Padding rule

  1. Append a single 1 bit
  2. Append k zero bits where (original_length + 1 + k) ≡ 448 (mod 512)
  3. Append original message length as a 64-bit big-endian integer
Total block size = 512 bits = message + 1 + zeros + 64

Worked example — 12-character message

12 chars × 8 bits = 96 bits original length. Use the calculator below to verify padding for any bit length.

StepBits so farCalculation
Original message9612 × 8
+ append "1"97
+ zeros448See calculator → 351 zeros
+ 64-bit length51296 + 1 + 351 + 64 = 512 ✓

Visual: one 512-bit block

Message (96)
1
··· 351 zeros ···
len=96

After padding — compression (overview)

Each 512-bit block is split into sixteen 32-bit words W₀…W₁₅. Words W₁₆…W₇₉ are expanded from earlier words. Five registers (A,B,C,D,E) update through 80 rounds using nonlinear functions and constants.

Your professor's SHA-1 example doc shows the round-by-round format — match that layout on exams.

Padding drill

A message is 96 bits long. How many zero bits are appended after the "1" bit?

Concept drill

Can you decrypt a SHA-1 hash to recover the original message?

Stuck? Ask: "How many padding zeros for a 200-bit message?" or "Walk me through W₁₆ expansion."