Cryptographic Hashing
Cryptographic hash functions are fundamental building blocks of blockchain technology, providing data integrity, unique identification, and security guarantees.
What Is a Hash Function?
A hash function takes input of any size and produces a fixed-size output called a digest or hash.
Text
Hash Functions in Practice
TypeScript
Common Hash Algorithms
| Algorithm | Output Size | Security | Use Case |
|---|---|---|---|
| MD5 | 128 bits | Broken | Legacy checksums only |
| SHA-1 | 160 bits | Weak | Legacy, avoid |
| SHA-256 | 256 bits | Strong | Bitcoin, general use |
| SHA-512 | 512 bits | Strong | High security needs |
| Keccak-256 | 256 bits | Strong | Ethereum |
| BLAKE3 | Variable | Strong | High performance |
Blockchain Applications
Transaction Hashing
TypeScript
Block Hashing
TypeScript
Merkle Root
TypeScript
Address Derivation
Blockchain addresses are typically derived from public keys using hashing:
TypeScript
Security Properties
Preimage Resistance
Given a hash h, it's computationally infeasible to find any message m such that hash(m) = h.
TypeScript
Collision Resistance
It's computationally infeasible to find two different messages that produce the same hash.
TypeScript
Proof of Work
Hash functions enable proof of work through difficulty targeting:
TypeScript
Best Practices
| Practice | Description |
|---|---|
| Use modern algorithms | SHA-256, SHA-3, BLAKE3 |
| Never use MD5/SHA-1 | Cryptographically broken |
| Salt sensitive data | Add random salt before hashing passwords |
| Use constant-time comparison | Prevent timing attacks |
| Verify integrity | Always verify hashes match expectations |
Next: Public/Private Keys - Asymmetric cryptography and key pairs.