Week 5
Week 5
CS 555
Week 5:
• Cryptographic Hash Functions
• HMACs
• Generic Attacks
• Random Oracle Model
• Applications of Hashing
Readings: Katz and Lindell Chapter 5, Appendix A.4
Spring 2021 1
Recap
• Authenticated Encryption + CCA-Security
• Encrypt and Authenticate [SSL]
• Authenticate then Encrypt [TLS] (Caution Required)
• Encrypt then Authenticate!
• Secure Communication
• Attacks: Reflection/Replay/Reordering + Defenses
• AES-GCM
• Cryptographic Hash Functions
• Definitional Challenges
2
Week 5: Topic 1:
Cryptographic Hash
Functions
3
Keyed Hash Function Syntax
• Two Algorithms
• (Key-generation algorithm)
• Input: Random Bits R
• Output: Secret key
• (Hashing Algorithm)
• Input: key and message (unbounded length)
• Output: hash value
4
Collision Experiment ()
s
x1,x2
{
𝑠 𝑠
𝐻𝑎𝑠h𝐶𝑜𝑙𝑙 𝐴 , Π (𝑛)= 1𝑖𝑓 𝐻 ( 𝑥1 ) =𝐻 ( 𝑥2 )
0 𝑜𝑡h𝑒𝑟𝑤𝑖𝑠𝑒
s=Gen(1𝑛; 𝑅)
Definition: (Gen,H) is a collision resistant hash function
if
5
Collision Experiment ()
s
For simplicity we will
x1,x2
sometimes just say that H
(or Hs) is a collision 1𝑖𝑓 𝐻 𝑠 ( 𝑥 ) =𝐻 𝑠 ( 𝑥 ) Key is not key secret
𝐻𝑎𝑠h𝐶𝑜𝑙𝑙 𝐴 , Π (𝑛)=
{
resistant hash function 0 𝑜𝑡h𝑒𝑟𝑤𝑖𝑠𝑒
1 2
(just random)
s=Gen(1𝑛; 𝑅)
Definition: (Gen,H) is a collision resistant hash function
if
6
Concrete Security ()
s
x1,x2
{
𝑠 𝑠
𝐻𝑎𝑠h𝐶𝑜𝑙𝑙 𝐴 , Π (𝑛)= 1𝑖𝑓 𝐻 ( 𝑥1 ) =𝐻 ( 𝑥2 )
0 𝑜𝑡h𝑒𝑟𝑤𝑖𝑠𝑒
s=Gen(1𝑛; 𝑅)
Definition: (Gen,H) is a collision resistant hash
function if
7
Theory vs Practice
• Most cryptographic hash functions used in practice are un-keyed
• Examples: MD5, SHA1, SHA2, SHA3, Blake2B
• Tricky to formally define collision resistance for keyless hash function
• There is a PPT algorithm to find collisions
• We just usually can’t find this algorithm
• Guarantee for protocol using H
If we know an explicit efficient algorithm A
breaking our protocol then there is an efficient
blackbox reduction transforming A into an efficient
collision finding algorithm.
8
Weaker Requirements for
Cryptographic Hash
• Target-Collision Resistance
s,x
x’
{
s s
Hash Tgt Coll A , Π (𝑛)= 1 if H ( x ′ ) =H (x)
0 otherwise
s,
x
{
s
Hash PreImgRes A , Π (n) = 1 if H ( x )= y
0 otherwise
11
Merkle-Damgård Transform
Construction: (Gen,h) fixed length hash function from 2n bits to n bits
=
1. Break x into n bit segments x1,..,xd (pad last block by 0’s)
2. (initialization)
3. For i = 1 to d
12
Merkle-Damgård Transform
Theorem: If (Gen,h) is collision resistant then so is (Gen,H)
Proof: Show that any collision in Hs yields a collision in hs. Thus a PPT
attacker AH for (Gen,H) can be transformed into PPT attacker Ah for (Gen,h).
13
Merkle-Damgård Transform
Theorem: If (Gen,h) is collision resistant then so is (Gen,H)
No Found collision
Yes?
14
Merkle-Damgård Transform
Theorem: If (Gen,h) is collision resistant then so is (Gen,H)
No Found collision
Yes?
15
Merkle-Damgård Transform
Theorem: If (Gen,h) is collision resistant then so is (Gen,H)
16
Merkle-Damgård Transform
Theorem (Concrete Version): If (Gen,h) is -collision resistant then (Gen,H)
is is -collision resistant for where
Analysis: Run attacker AH to get pair x and x’ (time t), then compute
(resp. ) values to extract collision.
No Found collision
Yes?
17
Week 5: Topic 2:
HMACs and Generic
Attacks
18
MACs for Arbitrary Length Messages
MacK(m)=
• Select random n/4 bit string r
• Let for i=1,…,d
• (Note: encode i and as n/4 bit strings)
• Output
20
MACs for Arbitrary Length Messages
Disadvantages: Lose
Mac (m)=
Disadvantage 1: Long Strong-MAC Guarantee
K
random n/4 bit string r (Multiple valid MACs of
output
• Select
• Let for i=1,…,d same message)
• (Note: encode i and as n/4 bit strings)
• Output
21
Hash and MAC Construction
Start with , a secure MAC for messages of fixed length, and (Gen H,H) a collision
resistant hash function and define
Theorem 5.6: is a secure MAC for arbitrary length message assuming that is a
secure MAC and (GenH,H) is collision resistant.
Proof Intuition: If attacker successfully forges a valid MAC tag t’ for unseen message m’
then either
• Case 1: for some previously requested message mi
• Case 2: for every previously requested message mi
23
Hash and MAC Construction
Theorem 5.6: Above construction is a secure MAC.
24
Hash and MAC Construction
Start with (Mac,Vrfy) a MAC for messages of fixed length and (GenH,H) a collision resistant hash function
26
MAC from Collision Resistant Hash
• Failed Attempt:
❑ 𝑠
𝑀𝑎𝑐 ⟨𝑘 , 𝑆 ⟩ ( 𝑚 ) =𝐻 ( 𝑘 ∥𝑚 )
28
HMAC
29
HMAC
31
HMAC in Practice
• MD5 can no longer be viewed as collision resistant
32
Finding Collisions
• Ideal Hashing Algorithm
• Random function H from {0,1}* to {0,1}
• Suppose attacker has oracle access to H(.)
Can we do
• Attack 1: Evaluate H(.) on 2+1 distinct inputs. better?
33
Birthday Attack for Finding Collisions
• Ideal Hashing Algorithm
• Random function H from {0,1}* to {0,1}
• Suppose attacker has oracle access to H(.)
34
Birthday Attack for Finding Collisions
• Ideal Hashing Algorithm
• Random function H from {0,1}* to {0,1}
• Suppose attacker has oracle access to H(.)
𝑫𝟐
⏞
35
Birthday Attack for Finding Collisions
• Ideal Hashing Algorithm
• Random function H from {0,1}* to {0,1}
• Suppose attacker has oracle access to H(.)
36
Birthday Attack for Finding Collisions
• Ideal Hashing Algorithm
• Random function H from {0,1}* to {0,1}
• Suppose attacker has oracle access to H(.)
37
Birthday Attack for Finding Collisions
• Ideal Hashing Algorithm
• Random function H from {0,1}* to {0,1}
for
• Suppose attacker has oracle access to H(.)
38
Recap
• Collision Resistant Hash Functions
• Merkle–Damgård Construction
• Applications to MACs
• Hash and MAC
• Failed MAC:
• HMAC
• Birthday Attack: Finds collision in time (and space )
39
Birthday Attack for Finding Collisions
• Ideal Hashing Algorithm
• Random function H from {0,1}* to {0,1}
• Suppose attacker has oracle access to H(.)
40
Floyd’s Cycle Finding Algorithm
• A cycle denotes a hash collision
42
Small Space Birthday Attack
• Attack 2: Select random , define
• and
• Repeat for i=1,2,… Finds collision after
Osteps in
• now
• If x=x’ then break
expectation
• and set
• Repeat for j=1 to i
• If H(x) = H(x’) then output x,x’
• Else x:= H(x), x’ = H(x) Now x= AND
43
Small Space Birthday Attack
• Can be adapted to find “meaningful collisions” if we have a large message space O
• Example: with
• = Set of positive recommendation letters
• = Set of negative recommendation letters
𝑥 =𝐻 (𝑥
1
2
1
1 ) 𝑥 =𝐻 (𝑥
2
2
2
1 ) … 𝑥 =𝐻(𝑥
𝑠
2
𝑠
1 )
… … …
𝑥 1
𝑖 +1 =𝐻 ( 𝑥 1
𝑖 ) 𝑥 2
𝑖 +1 =𝐻 ( 𝑥 2
𝑖 ) …
𝑥 𝑠
𝑖 +1 =𝐻 ( 𝑥 𝑠
𝑖 )
… … …
2 𝑠
1
𝑥 =𝑒 𝑝 1
𝑡
𝑥 =𝑒 𝑝 2
𝑡 𝑥 =𝑒 𝑝 𝑠
𝑡 46
Pre-Computation Attacks for Targeted
Collision
• Precomputation ( steps, memory)
𝑗
𝑠𝑝 𝑗 =𝑥 1 • Goal: Find collision for target
… 𝑥 =𝐻(𝑥
𝑗
2 1
𝑗
) … 𝑦 0= 𝑦
…
𝑦 1= 𝐻 ( 𝑦 0 )
…
𝑥 𝑗
𝑖 +1 =𝐻 ( 𝑥 𝑖
𝑗
) … …
… 𝑦 𝑖=𝐻 ( 𝑦 𝑖 − 1)
𝑗 …
𝑥 =𝑒 𝑝 𝑗
𝑡 𝑦 𝑘=𝑒𝑝 𝑗 47
Pre-Computation Attacks for Targeted
Suppose for some ,
Collision
𝑥 =𝐻(𝑥
𝑗
)
𝑗 chance that
good
… 2 …,
for some
1 𝑦 0= 𝑦
…
𝑦 1= 𝐻 ( 𝑦 0 )
…
𝑥 𝑗
𝑖 +1 =𝐻 ( 𝑥 𝑖
𝑗
) … …
……
Not quite true…chains can intersect and
may not represent distinct points
𝑦 𝑖=𝐻 ( 𝑦 𝑖 − 1)
𝑗 …
𝑥 =𝑒 𝑝 𝑗
𝑡 𝑦 𝑘=𝑒𝑝 𝑗 48
Intersecting Chains
• Precomputation ( steps, memory)
𝑗 𝑗′
𝑠𝑝 𝑗 =𝑥 1 𝑠𝑝 𝑗 ′ =𝑥 1
Intersecting chains contain distinct
points.
𝑥 =𝐻(𝑥
𝑗
2 1
𝑗
) … 𝑥 =𝐻 (𝑥
𝑗′
2
𝑗′
1 )
… 𝑗 … After initial intersection the
𝑗𝑥
= 𝑥 𝑗′
𝑥 =𝐻 (𝑥
𝑖+ 1 𝑗′ 𝑗′
) chains merge together
= 𝐻 ( 𝑥𝑖 )
𝑗 𝑘 𝑘 𝑘
𝑥 𝑖 +1
…
𝑗 𝑗′
𝑥 =𝑒 𝑝 𝑗
𝑡
… 𝑥 =𝑒 𝑝 𝑗 ′
𝑡 49
Targeted Collision Attacks
Fact: If then chains contain distinct
• Precomputation ( steps, memory) points, but then
Pr[y in CHAIN]
2 𝑠
𝑠𝑝 1=𝑥
1
1
𝑠𝑝 2=𝑥 1 𝑠𝑝 𝑠 =𝑥 1
𝑥 =𝐻 (𝑥
1
2
1
1 ) 𝑥 =𝐻 (𝑥
2
2
2
1 ) … 𝑥 =𝐻(𝑥
𝑠
2
𝑠
1 )
… … …
Solution: Repeat T=O(t) times2 using
𝑥 1
𝑖 +1 𝑖 )
1 𝑥 2
= 𝐻 ( 𝑥different
𝑖 +1 = 𝐻 ( 𝑥
H1,…, HT where𝑖 ) …
𝑥𝑖 +1 = 𝐻 ( 𝑥𝑖 )
𝑠 𝑠
𝑥 𝑗 ,1
2 =𝐻 1 ( 𝑥 1
𝑗 ,1
)𝑥
𝑗, 2
2 =𝐻 2 ( 𝑥 𝑗, 2
1 )… 𝑥 𝑗, 𝑇
2 =𝐻 𝑇 ( 𝑥 𝑗,𝑠
1 )
… … …
𝑥 𝑗 ,1
𝑖 +1 =𝐻1( 𝑥 𝑖
𝑗 ,1
)𝑥
𝑗, 2
𝑖 +1 =𝐻2 ( 𝑥 𝑖
𝑗, 2
)… 𝑥 𝑗, 𝑇
𝑖 +1 =𝐻𝑇 ( 𝑥 𝑖
𝑗,𝑠
)
… … …
𝑗, 2 𝑗, 𝑇
1𝑗 ,1
𝑥 =𝑒
=𝑒
𝑡 𝑝𝑝
1 𝑗 ,1
𝑥 𝑡 =𝑒 𝑝 𝑗 ,2 𝑥 𝑡 =𝑒 𝑝 𝑗 ,𝑇
51
Repeat for each starting
Targeted
point withCollision 𝐻 𝑖 ( 𝑥 )= 𝐻
Attacks (𝐹 𝐾 ( 𝑥 ))
𝑖
𝑥 𝑗 ,1
2 =𝐻1( 𝑥 1
𝑗 ,1
)𝑥
𝑗, 2
2 =𝐻 2 ( 𝑥 𝑗, 2
1 )… 𝑥 𝑗, 𝑇
2 =𝐻 𝑇 ( 𝑥 𝑗,𝑠
1 )
… … …
𝑥 𝑗 ,1
𝑖 +1 =𝐻1( 𝑥 𝑖
𝑗 ,1
)𝑥
𝑗, 2
𝑖 +1 =𝐻2 ( 𝑥 𝑖
𝑗, 2
)… 𝑥 𝑗, 𝑇
𝑖 +1 =𝐻𝑇 ( 𝑥 𝑖
𝑗,𝑠
)
… … …
𝑗, 2 𝑗, 𝑇
1𝑗 ,1
𝑥 =𝑒
=𝑒
𝑡 𝑝𝑝
1 𝑗 ,1
𝑥 𝑡 =𝑒 𝑝 𝑗 ,2 𝑥 𝑡 =𝑒 𝑝 𝑗 ,𝑇 52
Targeted Collision Attacks
• Precomputation ( steps, memory) 𝐻 𝑖 ( 𝑥 )= 𝐻 ( 𝐹 𝐾 ( 𝑥 ) )
𝑖
𝑗 𝑗
𝑠𝑝 1𝑗 =𝑥
1𝑗
1
𝑠𝑝 𝑗 =𝑥 1 𝑠𝑝 𝑗 =𝑥 1
𝑥 𝑗 ,1
2 =𝐻 1 ( 𝑥 1
𝑗 ,1
)𝑥
𝑗, 2
=𝐻 𝑗, 2
2 Each Chains
2 … (𝑥
1 Contain: ) 𝑥 𝑗, 𝑇
=𝐻
distinct
2 𝑇 (𝑥
points
𝑗,𝑠
1 )
… … As long as …
𝑥 𝑗 ,1
𝑖 +1 =𝐻1( 𝑥 𝑖
𝑗 ,1
)𝑥
𝑗, 2
=𝐻 (𝑥
Untangling
𝑖 +1 𝑖 Chains:
𝑖 )
𝑗 ,2 …
𝑥𝑗, 𝑇
won’t remain =𝐻 (𝑥
𝑖 +1 tangled
𝑖 with
𝑖
𝑗, 𝑠
)
… … chains …
𝑗, 2 all chains cover points
𝑗, 𝑇
1𝑗 ,1
𝑥 =𝑒
=𝑒
𝑡 𝑝𝑝
1 𝑗 ,1
𝑥 𝑡 =𝑒 𝑝 𝑗 ,2 𝑥𝑡 =𝑒 𝑝 𝑗 ,𝑇 53
Post-Processing
Input: y 𝑦 0 ,𝑖 = 𝑦
For each // Compute T chains of length t
// Start each chain at 𝑦 1, 𝑖= 𝐻 𝑖 ( 𝑦 0 )
…
For each
//
𝑦 𝑗 , 𝑖=𝐻 𝑖 ( 𝑦 𝑗 −1 )
…
For each k’ such that
𝑦 𝑘 ,𝑖 =𝑒𝑝𝑘 ,𝑖 ′
// recompute chain at
For each
If return else
54
Post-Processing Observation 1: If y is on any of the chains
i.e., for some ,
We will hit the endpoint
Input: y 𝑦 0 ,𝑖 = 𝑦
We will find a pre-image of y
Input: y 𝑦 =𝑦
Let be an indicator random variable for
the event that even though y is not on the
,𝑖
0chain
For each // Compute T chains of length t
// Start each chain at 𝑦 1, 𝑖= 𝐻 𝑖 ( 𝑦 0)
Let Z be total number of false positives
…
For each
//
𝑦 𝑗 , 𝑖=𝐻 𝑖 ( 𝑦 𝑗 −1 )
…
For each k’ such that
𝑦 𝑘 ,𝑖 =𝑒𝑝𝑘 ,𝑖 ′
// recompute chain at
For each
If return else
56
Post-Processing Let Z be total number of false positives
Input: y 𝑦 0 ,𝑖 = 𝑦
Total Running Time:
For each // Compute T chains of length t
// Start each chain at 𝑦 1, 𝑖= 𝐻 𝑖 ( 𝑦 0 )
If and then total running time is
…
For each
//
𝑦 𝑗 , 𝑖=𝐻 𝑖 ( 𝑦 𝑗 −1 )
…
For each k’ such that
𝑦 𝑘 ,𝑖 =𝑒𝑝𝑘 ,𝑖 ′
// recompute chain at
For each
If return else
57
Targeted Collision Attacks
• Precomputation ( steps, memory)
𝑗
𝑠𝑝 𝑗 =𝑥 1 • Goal: Find collision for target
… 𝑥 𝑗
Set ,
2 = 𝐻 1 ( 𝑥 ) 𝑗
…
1 𝑦 0= 𝑦
…
Precomputation: 𝑦 1Total
=𝐻Cost1 ( 𝑦to
0 )find
… Space:
𝑥𝑖 +1 = 𝐻 𝑖 −1 ( 𝑥 𝑖 )…
𝑗 𝑗 …
targeted collisions is
Targeted Collision
… Search: =𝐻 𝑖 −1 ( 𝑦 𝑖 − 1 )
𝑦 𝑖just
𝑗 …
𝑥 =𝑒 𝑝 𝑗
𝑡 𝑦 𝑘=𝑒𝑝 𝑗 60
Applications
• Key-Recovery Attacks on Block Cipher
• Pre-Computation:
• Crack secret keys in total time with space
• Run prior attack with “hash function”
• for some random (fixed)
• Password Cracking
• Attacker is given ,…, for passwords with
• Goal: Recover passwords
• Can crack all passwords in total time with space
• Domain Challenge: with
• Define (pseudo)random mapping
• Run prior attack with “hash function” as
61
Week 5: Topic 3:
Random Oracle Model + Hashing
Applications
62
When Collision Resistance Isn’t
Enough
• Example: Message Commitment
• Alice sends Bob: (e.g., predicted winner of NCAA Tournament)
• Alice can later reveal message (e.g., after the tournament is over)
• Just send r and m (note: r has fixed length)
• Why can Alice not change her message?
• Collision Resistance Alice can’t find r’ and m’ s.t.
• In the meantime Bob shouldn’t learn anything about m
65
When Collision Resistance Isn’t
Enough
• Problem: Let (Gen,H’) be collision resistant then so is (Gen,H)
70
Random Oracle Model: Pros
• It is easier to prove security in Random Oracle Model
71
Random Oracle Model: Cons
• Lack of formal justification
• Why should security guarantees translate when we instantiate
random oracle with a real cryptographic hash function?
72
Random Oracle Model: Justification
“A proof of security in the random-oracle model is significantly better
than no proof at all.”
73
Hash Function Application:
Fingerprinting
• The hash h(x) of a file x is a unique identifier for the file
• Collision Resistance No need to worry about another file y with H(y)=H(y)
74
Tamper Resistant Storage
m1
H(m1) m1 ’
75
Tamper Resistant Storage
File Index Hash
1 H(m1) Disadvantage: Too
many hashes to store
2 H(m2)
3 H(m3)
m1,m2,m3
Send file 1
m1 ’
76
Tamper Resistant Storage
Disadvantage: Need all
files to compute hash
m1,m2,m3
H(m1,m2,m3)
m1,m2,m3
Send file 1
m1 ’
77
Merkle Trees
𝐱𝟏 𝐱𝟐 78
Merkle Trees
• Proof of Correctness for data block 2
Root: H1-4
m1,m2,m3,m4
Send file 2
m2’,h1,h3-4
81
Commitment Schemes
• Alice wants to commit a message m to Bob
• And possibly reveal it later at a time of her choosing
• Properties
• Hiding: commitment reveals nothing about m to Bob
• Binding: it is infeasible for Alice to alter message
82
Commitment Hiding ()
m0,m1
commit(r,mb)
b’
{
′
Hiding 𝐴 , 𝐶𝑜𝑚 (𝑛) = 1if 𝑏=𝑏
0 𝑜𝑡h𝑒𝑟𝑤𝑖𝑠𝑒
r = Gen(.)
Bit b
83
Commitment Binding ()
r0,r1,m0,m1
84
Secure Commitment Scheme
• Definition: A secure commitment scheme is hiding and binding
• Hiding
• Binding
85
Commitment Scheme in Random
Oracle Model
• Commit(r,m):=H(m|r)
• Reveal(c):= (m,r)
{
′
Hiding 𝐴 , 𝐶𝑜𝑚 (𝑛) = 1𝑖𝑓𝑏=𝑏
0 𝑜𝑡h𝑒𝑟𝑤𝑖𝑠𝑒
r = Gen(1n)
Bit b
87
Other Applications
• Password Hashing
• Key Derivation
88
Next Week
• Stream Ciphers
• Block Ciphers
• Feistel Networks
• DES, 3DES
• Read Katz and Lindell 6.1-6.2
89