1. Hash Functions
Definition:
A hash function takes an input (message) and produces a fixed-size string of bytes, typically called a hash value or digest.
Properties of a secure hash function:
-
Deterministic: Same input → same hash
-
Fast computation: Easy to compute for any input
-
Pre-image resistance: Hard to reverse (cannot get original input from hash)
-
Collision resistance: Hard to find two different inputs with the same hash
-
Avalanche effect: Small change in input → large change in hash
Uses:
-
Data integrity verification
-
Digital signatures
-
Password storage (with salt)
-
Message authentication codes (MACs)
2. MD5 (Message Digest 5)
Pros:
Cons:
3. SHA (Secure Hash Algorithm)
SHA comes in multiple versions:
| Version |
Output Size |
Notes |
| SHA-1 |
160 bits |
Older, weaker, prone to collisions |
| SHA-2 |
224, 256, 384, 512 bits |
Stronger, widely used |
| SHA-3 |
224, 256, 384, 512 bits |
Latest standard, different internal structure (Keccak) |
Process (simplified):
-
Pad the message to a multiple of block size
-
Break message into blocks
-
Apply rounds of logical, modular, and bitwise operations
-
Produce a fixed-length hash output
Pros:
-
Stronger than MD5 (especially SHA-2 and SHA-3)
-
Widely used in certificates, digital signatures, and blockchain
Cons:
Comparison: MD5 vs SHA
| Feature |
MD5 |
SHA-2 / SHA-3 |
| Output size |
128 bits |
224, 256, 384, 512 bits |
| Security |
Weak (collision attacks) |
Strong |
| Speed |
Fast |
Slightly slower |
| Usage today |
Legacy / checksums |
Cryptography, security protocols |