🌑

Explore / Study / Computer Science / Cryptography 1.1k words | 7 minutes

§10 Hash Functions and Hash-and-MAC

  1. Hash Functions
    1. Hash Functions: Definition
    2. Collision-Finding Experiment Hash-collA,Π(n)\text {Hash-coll}_{\mathscr{A}, \Pi}(n)Hash-collA,Π​(n)
    3. Security Definition
    4. Weaker Notions of Security
    5. Generic Attacks on Hash Functions
    6. Birthday Attacks for finding collisions
    7. Birthday Attacks: Implications
  2. Hash-and-MAC
    1. The Hash-and-MAC construction (alternative to CBC-MAC)
    2. Security of Hash-and-MAC construction

Hash Functions

Hash Functions: Definition

  • Definition. A Hash Function with output length ll is a pair of probabilistic polynomial-time algorithms (Gen,H)(Gen, H) satisfying the following:
    • GenGen is a probabilistic algorithm that takes as input a security parameter 1n1^n and outputs key ss.
    • HH takes as input a key ss and a string x{0,1}x \in \{0,1\}^* and outputs a string Hs(x){0,1}l(n)H^s(x) \in \{0,1\}^{l(n)} where nn is the security parameter that is implicit in ss.

Collision-Finding Experiment Hash-collA,Π(n)\text {Hash-coll}_{\mathscr{A}, \Pi}(n)

  • For a Hash Function Π=(Gen,H)\Pi = (Gen, H), an adversary A\mathscr{A}, and a security parameter nn, the collision-finding experiment Hash-collA,Π(n)\text {Hash-coll}_{\mathscr{A}, \Pi}(n) is defined as follows:
    1. A key ss is generated by running Gen(1n)Gen (1^n).
    2. The adversary A\mathscr{A} is given ss and outputs x,xx, x'. If Π\Pi is a fixed-length hash function for inputs of length l(n)l'(n), then we require x,x{0,1}l(n)x, x' \in \{0,1\}^{l'(n)}.
    3. The adversary succeeds in finding a collision and the output of the experiment is defined to be 11 if and only if xxx \ne x' and Hs(x)=Hs(x)H^s(x) = H^s(x').

Security Definition

  • Definition. A Hash Function Π=(Gen,H)\Pi = (Gen, H) is collision-resistant if for all probabilistic polynomial-time adversaries 𝒜𝒜 there is a negligible function ϵ\epsilon such that

    Pr[Hash-collA,Π(n)]ϵ(n)\Pr[\text {Hash-coll}_{\mathscr{A}, \Pi}(n)] \le \epsilon(n)

Weaker Notions of Security

  • Definition. Second-preimage or target-collision resistance. A Hash Function Π=(Gen,H)\Pi = (Gen, H) is second preimage resistant if given ss, and uniform xx, it is infeasible for any PPT adversary to find xxx' \ne x, such that Hs(x)=Hs(x)H^s(x') = H^s(x).
    • Proposition. Collision Resistance \Longrightarrow Second Preimage Resistance
  • Definition. Preimage resistance. A Hash Function Π=(Gen,H)Π = (Gen, H) is preimage resistant if given ss, and uniform yy, it is infeasible for any PPT adversary to find xx, such that Hs(x)=yH^s(x) = y.
    • Proposition. Second Preimage Resistance \Longrightarrow Preimage Resistance

Generic Attacks on Hash Functions

  • Simple Collision-Finding Attack: Compute H(x1),,H(x2n+1)H(x_1), \ldots , H(x_{2^n+1}), for 2n+12^n + 1 distinct inputs.

    We are guaranteed to find a collision, by Pigeonhole Principle, if the output is of length nn. Running time of the attack: O(2n)O(2^n).

  • Birthday Attacks: Compute H(x1),,H(x2n/2)H(x_1),\ldots, H(x_{2^{n/2}} ).

    We are not guaranteed to find a collision. But with non-negligible probability, we can find two inputs that map to the same output. Running time of the attack: O(2n/2)O(2^{n/2}).

Birthday Attacks for finding collisions

  • Theorem. In the balls into bins problem with mm balls and NN bins, when mm is Θ(N1/2)\Theta(N^{1/2}), the probability of a collision, i.e., of two balls falling into the same bin is approximately 50%50\%.

  • Theorem. Let r1,,rm{1,,N}r_1,\ldots, r_m \in \{1,\ldots, N\} be independent identically distributed integers. When m=1.2Nm = 1.2\sqrt{N}, then Pr[ij:ri=rj]12\displaystyle \Pr\left[\exists i \neq j: r_{i}=r_{j}\right] \geq \frac{1}{2}.

  • Let Hs:M{0,1}nH^s : \mathscr{M} \leftarrow \{0,1\}^n be a hash function, with M2n|\mathscr{M}| \gg 2^n.

    The following is a generic algorithm to find a collision in time O(2n/2)O(2^{n/2}).

    1. Choose 2n/22^{n/2} random messages in M:m1,,m2n/2\mathscr{M} : m_1,\ldots, m_{2^{n/2}}.
    2. For i=1,,2n/2i = 1,\ldots,2^{n/2}, compute yi:=Hs(mi){0,1}ny_i := H^s(m_i) \in \{0,1\}^n.
    3. Look for a collision, i.e., look for yi=yjy_i = y_j. If not found, go back to step 1.

Birthday Attacks: Implications

  • Implication: We need Hash Functions HH with 2n2n-bit output length to get security against attackers trying to find collisions running in 2n2^n time.

Hash-and-MAC

The Hash-and-MAC construction (alternative to CBC-MAC)

  • Hash-and-MAC construction: Let Π=(Mac,Vrfy)\Pi = (Mac, Vrfy) be a MAC for messages of length l(n)l(n), and let ΠH=(GenH,H)\Pi_H = (Gen_H, H) be a hash function with output length l(n)l(n).
  • Construct a MAC Π=(Gen,Mac,Vrfy)Π' = (Gen' , Mac' , Vrfy' ) for arbitrary-length messages as follows:
    • GenGen': Given input 1n1^n, choose uniform k{0,1}nk \in \{0,1\}^n and run GenH(1n)Gen_H(1^n) to obtain ss, the key is k:=k,sk' := \langle k, s \rangle.
    • MacMac': Given input key k,s\langle k, s \rangle and a message m{0,1}m \in \{0,1\}^*, output tMack(Hs(m))t \leftarrow Mac_k(H^s(m)).
    • VrfyVrfy': Given input key k,s\langle k, s \rangle, a message m{0,1}m \in \{0,1\}^*, and a MAC tag tt, output 11 if and only if Vrfyk(Hs(m),t)=1Vrfy_k (H^s(m), t) = 1.

Security of Hash-and-MAC construction

  • Theorem: If Π\Pi is a secure MAC for short messages of length ll, and ΠH\Pi_H is collision-resistant, then the Hash-and-Mac construction Π\Pi' is a secure MAC for arbitrary-length messages.

— Feb 28, 2023

Creative Commons License
§10 Hash Functions and Hash-and-MAC by Lu Meng is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Permissions beyond the scope of this license may be available at About.