Randomness and Pseudorandomness
eecs-388
Length Extension Attacks
Overview
- Merkle-Damgard hash functions are susceptible to length extension attacks
- given for some unknown , attackers can calculate for arbitrary
- that is, given: an attacker can produce:
- this doesn’t violate preimage, second-preimage, or collision resistance
Why This Matters
- suppose Alice and Bob use this as a verifier:
graph LR
A["Alice"] -- m,v --> B["Mallory"] -- m',v' --> C["Bob"]
- Alice sends
- Mallory doesn’t know , but can apply length extension to to calculate for: m' = \text{"Please go to the bank. [original pad] Then transfer \10,000 to Mallory.”}$
- Since is the correct verifier for , Bob will accept the modified message as valid
Illustration
- let
- let be a 256-bit secret key
- run:
graph LR A["$$b_0$$"] --> B["h"] C["$$\text{constant }y_0$$"] --> B B --> D["$$y_1 = H(\text{S || ``Please go to the bank.``})$$"]
H(\text{"Please go to the bank." || [original padding] || "Then transfer \10,000 to Mallory.”}) :=$
- let
- let b_1 = \text{"Then transfer \10,000 to Mallory.” || [new padding]}$
- run:
graph LR A["$$b_0$$"] --> B["h"] C["$$\text{constant }y_0$$"] --> B B --> D["$$y_1$$"] E["$$b_1$$"] --> F["$$h$$"] D --> F F --> G["$$y_2 = \text{H(S || ``Please go to the bank.`` || [original padding] || ``Then transfer \$10,000 to Mallory.``)}$$"]
Solution: HMAC
-
Message Authentication Code (MAC) - secure verifier:
- inputs: key, arbitrary length data
- output: fixed-size digest (n bits)
-
HMAC construction turns any secure hash function into a MAC: where and
- this design protects against length extension
-
Alice and Bob can use this for protecting message integrity:
graph LR A["Alice"] -- m,v --> B["Mallory"] -- m',v' --> C["Bob"]- Alice computes and sends
- Bob rejects if
Choosing a “secret” Key
- select a uniform random value
- true randomness - output of a physical process that is inherently unpredictable
- inherent in all physical systems (Heisenberg)
- absent in simplest abstract Turing machine
- can’t determine a process is random by looking at the output
- requires assessing the generation procedure
- true randomness is expensive; we often want to take a small amount of it and create a longer sequence that’s “as good as random”
Pseudorandom Generator (PRG)
Pseudorandom Function (PRF):
- $f_k : \{0,1\}^m \rightarrow \{0,1\}^n$
- $m$-bit input and $n$-bit output
- cannot practically distinguish $f_k(x)$ from random function without knowing $k$
Pseudorandom Generator (PRG):
- $g_k : \perp \rightarrow \{0,1\}^n \text{ for } n = \text{poly}(|k|)$
- $k$ is a truly random seed
- no other inputs
- output is much larger than the input (can think of output as stream of bits)
- cannot practically distinguish $g_k()$ from a random stream of bits without knowing $k$
Security Definition (testing the effectiveness of PRF ):
- choose secret and an RF
- flip a coin to get bit
- if , let if , let
- Mallory chooses ; we announce repeat as many times as Mallory likes
- Mallory guesses in polynomial time
- we say PRF is a secure if Mallory can’t do meaningfully better than random at guessing if it’s a PRF or RF
- note that Mallory can always determine if a function is a PRF given infinite time via a brute force attack