Hash Functions
Module 1 of Cryptography
What Is a Hash Function?
A hash function takes any input and produces a fixed-size output (the "hash" or "digest").
Input (any size) → Hash Function → Output (fixed size)
"Hello" → SHA-256 → "185f8db32271fe25f561a6fc938b2e26..."
"Hello World" → SHA-256 → "a591a6d40bf420404a011733cfb7b190..."
War and Peace → SHA-256 → "2c5d36be542f8f0e2ff4e801e9749966..."
No matter if input is 5 characters or 5 million, output is always the same size.
Properties of Cryptographic Hash Functions
1. Deterministic
Same input always produces same output.
2. One-Way (Pre-image Resistance)
Given a hash, you can't figure out the input.
3. Avalanche Effect
Tiny input change → completely different output.
4. Collision Resistance
Practically impossible to find two different inputs with the same hash.
Why These Properties Matter for Blockchain
- One-Way: Proof of Work mining
- Deterministic: Anyone can verify work instantly
- Avalanche Effect: Tamper evidence
- Collision Resistance: Unique identifiers
Common Hash Functions
| Function | Output Size | Used By |
|---|---|---|
| SHA-256 | 256 bits | Bitcoin |
| Keccak-256 | 256 bits | Ethereum |
| RIPEMD-160 | 160 bits | Bitcoin addresses |
Key Takeaways
- Hash functions compress arbitrary input to fixed output
- Cryptographic hashes are one-way, deterministic, with avalanche effect
- Blockchain uses hashes everywhere: block IDs, transaction IDs, addresses, mining