CSE4303 Introduction to Computer Security (Lecture 9)
Cryptographic Hash Functions
What is a Hash Function
A hash function maps a variable-length input to a fixed-length output.
Typical examples:
- Java hashCode(): input is an Object, output is a 4-byte integer.
- String polynomial hash example:
Key property:
- Domain is much larger than range .
- Collisions are unavoidable in principle since .
Main uses:
- Compact numerical representation
- Hash tables (Set, Map, dictionaries)
- Object comparison
- Integrity checking (fingerprint)
Security Properties
Let .
-
Preimage Resistance (One-way)
Given , it is computationally infeasible to find such that
. -
Second Preimage Resistance (Weak collision resistance)
Given a specific , it is computationally infeasible to find such that
. -
Collision Resistance (Strong collision resistance)
It is computationally infeasible to find any two distinct values such that
.
Adversarial definition:
Let where is much larger than .
is collision resistant if for all efficient algorithms :
outputs a collision for
is negligible.
Generic Collision Attack (Birthday Attack)
Let .
Generic algorithm to find a collision in time on the order of :
- Choose random messages .
- Compute .
- Look for .
Birthday phenomenon:
If the output space size is ,
high collision probability greater than occurs with about samples.
Thus:
- 128-bit hash gives about collision attack
- 256-bit hash gives about collision attack
Practical Hash Functions
From performance and security table (AMD Opteron 2.2 GHz):
- MD5: 128 bits, completely broken since 2004
- SHA-1: 160 bits, practical collision attack demonstrated
- SHA-256: 256 bits
- SHA-512: 512 bits
- Whirlpool: 512 bits
SHA-1 collision example: SHAttered attack (Google and CWI).
Two different PDF files were produced with identical SHA-1 hash.
Construction of Cryptographic Hash Functions
Merkle-Damgard Construction
Given compression function:
We build:
Process:
-
Split message into blocks .
-
Use fixed initialization vector .
-
Iterate chaining:
-
Apply padding: append concatenated with message length (64 bits).
If no space remains, add another block.
Theorem:
If compression function is collision resistant,
then is collision resistant.
Davies-Meyer Compression from Block Cipher
Given block cipher:
Define compression function:
If behaves like an ideal cipher,
finding a collision in takes about evaluations.
This is optimal for -bit output.
Example: SHA-256
Built using:
- Merkle-Damgard construction
- Davies-Meyer style compression
- Block cipher-like core: SHACAL-2
Structure:
- 512-bit message block
- 256-bit chaining value
- 256-bit output
Applications for Integrity and Authentication
Standalone Usage: Message Integrity
Application 1: Delayed Knowledge Verification
Idea:
Publish first.
Later reveal secret.
Anyone can recompute hash and verify.
Justification: Preimage resistance ensures secret is hidden until revealed.
Example: Stock market prediction commitment.
Example for delayed knowledge verification
- Publish .
- On May 1, reveal the prediction string.
- Anyone computes hash and checks equality.
Application 2: Password Storage
Model: System must verify password but not store plaintext.
Solution:
Store hash of password.
During login:
- Hash input
- Compare with stored value
Example:
Linux stores hashed passwords in the /etc/shadow file.
Includes:
- Salt
- Password hash
- Metadata
Security relies on:
- One-way property
- Salting to prevent precomputed attacks
Application 3: Trusted Timestamping and Blockchains
Goal: Prove document existed before a given date.
Methods:
- Publish document hash in newspaper.
- Time Stamping Authority signs hash.
- Publish hash in blockchain block.
Blockchain relies on:
- One-way hash functions
- Linking blocks via hash pointers
Application 4: Software Integrity with Secure Read-Only Space
Context: Trusted read-only public space (for example official website).
Process:
- Publisher computes .
- Publish hashes publicly.
- User downloads file and verifies hash.
If is collision resistant:
Attacker cannot modify file without detection.
No encryption required.
Public verifiability works if read-only space is trusted.
Symmetric Crypto Authentication: MACs and AE
This section can also be found here CSE442T Introduction to Cryptography (Lecture 18)
Message Authentication Codes (MACs)
Definition: MAC over
- yes or no
Security model:
Attacker can query .
Goal: produce new not previously seen such that accepts.
must be negligible.
MAC from PRF
Given PRF:
Define MAC:
accepts if
Theorem:
If is secure PRF and is large,
then derived MAC is secure.
Condition:
must be negligible.
Example: .