CIS 5371 Cryptography 4b. Collision Resistant Hash Functions B

advertisement
CIS 5371 Cryptography
4b. Collision Resistant Hash Functions
Based on: Jonathan Katz and Yehuda Lindell Introduction to Modern Cryptography
1
Collision Resistance
A collision in a function H is a pair of distinct
inputs x, x’ for which 𝐻 π‘₯ = 𝐻 π‘₯ ′ .
Collision resistance is trivial to achieve if
compression is not required (take for example
the identity function)
We shall be dealing with a family of hash
functions indexed by a key s.
H will take as input a key s and a string x and
output a string: 𝐻 𝑠 π‘₯ ≝ 𝐻 𝑠, π‘₯ .
2
Definition 5.1, Hash Function
A hash function is a pair of probabilistic
polynomial-time algorithms (Gen, 𝐻) such that:
• π†πžπ§: takes input the security parameter 1𝑛 and
outputs a key 𝑠.
•
H : there is a polynomial 𝑙 such that 𝐻 takes as
input a key 𝑠 and a string π‘₯ ∈ {0,1}∗ and outputs a
string 𝐻 𝑠 π‘₯ ∈ {0,1}𝑙(𝑛) .
3
A collision finding experiment
π‡πšπ¬π‘-𝐜𝐨π₯π₯(A,) (𝒏)
1. A ke𝑦 𝑠 is generated by running Gen 1𝑛 .
2. The adversary 𝐴 is given 𝑠 and outputs
a pair π‘₯, π‘₯′.
3. The output of the experiment i𝑠 1 if and only if
― π‘₯ ≠ π‘₯′, and
― 𝐻𝑠 π‘₯ = 𝐻𝑠 π‘₯′ .
4
Definition 4.12
Collision Resistant Hash Function
A hash function = (Gen, 𝐻) is collision resistant,
if for all probabilistic polynomial-time adversaries
𝐴, there is a negl function such that:
Pr[Hash-coll(A,) 𝑛 = 1] ≤ negl.
5
Weaker notions of security for
Hash Functions
1. Collision resistance. The strongest notion, as
defined earlier.
2. Second pre-image resistance. Informally, given a
key s and a string π‘₯ it is infeasible for a
probabilistic polynomial-time adversary to find
π‘₯′ ≠ π‘₯ such that 𝐻 𝑠 π‘₯ ′ = 𝐻 𝑠 π‘₯ .
3. Pre-image resistance. Informally, given a key s and
a string 𝑦 = 𝐻 𝑠 π‘₯ (but not π‘₯) for a randomly
chosen π‘₯, it is infeasible for a probabilistic
polynomial-time adversary to find π‘₯′ ≠ π‘₯ such that
𝐻 𝑠 π‘₯ ′ = 𝑦.
6
Weaker notions of security for
Hash Functions
1. Collision resistance οƒž Second pre-image resistance
If given π‘₯ the adversary can find π‘₯′ ≠ π‘₯ such that
𝐻 𝑠 π‘₯ ′ = 𝐻 𝑠 π‘₯ , then the adversary can find a pair
π‘₯′ ≠ π‘₯ with 𝐻 𝑠 π‘₯ ′ = 𝐻 𝑠 π‘₯ .
2. Second pre-image resistance οƒž Pre-image resistance
If it were possible to invert 𝑦 and find an π‘₯′ such that
𝐻 𝑠 π‘₯ ′ = 𝑦, then it would be possible to take a given
input π‘₯ , compute 𝐻 𝑠 (π‘₯), and then invert 𝑦 = 𝐻 𝑠 π‘₯
to find π‘₯′ ≠ π‘₯ such that 𝐻 𝑠 π‘₯ ′ = 𝑦.
7
Generic birthday attack
Birthday problem
Let 𝐻: {0,1}∗ → {0,1}𝑙 be a hash function .
Assume that the values 𝑦 = 𝐻 π‘₯ are uniformly
distributed in {0,1}𝑙 and independent .
Assume that π‘ž arbitrary inputs π‘₯1 , … , π‘₯π‘ž πœ– {0,1}∗ are
selected.
Then the probability that there is a collision using
π‘ž = Θ(2𝑙/2 ) hash evaluations is greater that ½.
The time taken is O(𝑙 βˆ™ 2𝑙/2 ).
(One has to sort outputs---assume that one can evaluate a hash function in
constant time.)
8
Improved birthday attack
Memory is a scarcer resource than time:
storing π‘ž = Θ(2𝑙/2 ) hash evaluations is costly.
9
Improved birthday attack
Improved birthday attack
Let 𝐻: {0,1}∗ → {0,1}𝑙 be a hash function.
Select a random initial value π‘₯0 .
For 𝑖 > 0
Compute π‘₯𝑖 ∢= 𝐻(π‘₯𝑖−1 ) and π‘₯2𝑖 ∢= 𝐻(𝐻 π‘₯2
𝑖−1
).
If π‘₯𝑖 = π‘₯2𝑖 there is a collusion; else continue.
It can be shown that we get a collision with
probability roughly ½ in π‘ž = Θ(2𝑙/2 ) steps.
10
Construction 4.12
The Merkle-Damgaard transform
(Gen, β„Ž) is a fixed-length collision-resistant hash function
with inputs of length 2𝑙 𝑛 and outputs of length 𝑙 𝑛 .
A variable-length hash function (Gen, 𝐻) is constructed as
follows.
•
•
π†πžπ§: on input 1𝑛 , output key 𝑠.
H : on input 𝑠 and π‘₯ Ο΅ {0,1}𝐿 , 𝐿 < 2𝑙(𝑛) do:
Set 𝐡: = 𝐿/𝑙, pad π‘₯ so that it can be parsed into 𝐡
blocks π‘₯1 , … , π‘₯𝐡 of length 𝑙.
Set π‘₯𝐡+1 ≔ 𝐿 (𝑙 bits).
2. Set 𝑧0 ≔ 0𝑙 .
3. For 𝑖 = 1, … , 𝐡 + 1, compute 𝑧𝑖 ≔ β„Ž 𝑠 (𝑧𝑖−1 ||π‘₯𝑖 ).
4. Output 𝑧𝐡+1 .
1.
11
The Merkle-Damgaard
transform
π‘₯2
π‘₯1
𝑧0
π‘₯𝐡
β„Žπ‘ 
β„Žπ‘ 
𝑧1
...
π‘₯𝐡+1 = 𝐿
β„Žπ‘ 
β„Žπ‘ 
𝑧𝐡
𝑧𝐡+1
(= 𝐻 𝑆 (𝑋))
12
Theorem 4.14
If (𝐺𝑒𝑛, β„Ž) is collision-resistant then so is
(𝐺𝑒𝑛, 𝐻) .
13
Hash Functions and Applications
Hash-and-MAC
Let Π = (Mac,Vrfy) be a MAC for messages of length 𝑙(𝑛)
and Π𝐻 = (GenH , H) be a hash function with output
length 𝑙(𝑛). Construct MAC Π′ = (Gen’,Mac’,Vrfy’) for
arbitrary length messages as follows:
• Gen’: on input1𝑛 output uniform π‘˜ πœ– {0,1}∗ and run GenH
(1𝑛 ) to get 𝑠. The Hash-and-Mac key is π‘˜, 𝑠 .
•
•
Mac’: on input π‘˜, 𝑠 and message m πœ– {0,1}∗ output
𝑑 ←Mack (Hs(m)) .
Vrfy’: on input a key π‘˜, 𝑠 , a message m πœ– {0,1}∗ and a
MAC tag t output 1 if and only if Vrfyk (H*(m), t)=1.
14
Hash Functions and Applications
HMAC
Let (GenH , H) be a hash function constructed using the
Merkle Damgaard transform to compression function
(GenH , β„Ž) of length 𝑛 + 𝑛′. Let opad and ipad be fixed
constants of length 𝑛′. Define MAC as follows:
• Gen: on input1𝑛 run GenH (1𝑛 ) to get 𝑠. Choose uniform
π‘˜ Ο΅ {0,1}𝑛′ . Output key is π‘˜, 𝑠 .
•
•
Mac: on input π‘˜, 𝑠 and message m πœ– {0,1}∗ output
𝑑 ≔ Mack (Hs(π‘˜β¨opad)||Hs(π‘˜β¨ipad||m)) .
Vrfy’: on input a key π‘˜, 𝑠 , a message m πœ– {0,1}∗ and a
MAC tag t output 1 if and only if
𝑑 = Mack (Hs(π‘˜β¨opad)||Hs(π‘˜β¨ipad)||m)) .
15
HMAC
k οƒ… ipad
IV
π‘š1
β„Žπ‘ 
β„Žπ‘ 
π‘˜π‘–π‘›
...
β„Žπ‘ 
k οƒ… opad
IV
β„Žπ‘ 
β„Žπ‘ 
π‘˜π‘œπ‘’π‘‘
𝑑
Download