Network Security - Hash Functions
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)
-
Developed: 1991 by Ronald Rivest
-
Output size: 128 bits (16 bytes)
-
Process:
-
Pads the message to a multiple of 512 bits
-
Divides the message into 512-bit blocks
-
Processes each block through a series of bitwise operations
-
Produces a 128-bit hash
-
Pros:
-
Fast and widely supported
-
Simple to implement
Cons:
-
Vulnerable to collision attacks → not secure for cryptographic use
-
Not recommended for digital signatures
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:
-
Slower than MD5 for some applications (trading speed for security)
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 |