Documentation

CslibFrontier.Crypto.Protocols.Cipher.LinearCryptanalysis

Linear cryptanalysis by majority vote #

A keyed function E : BitString h → BitString n → BitString n satisfies a linear relation for masks (S₀, S₁, S₂) and bias ε ([BS23], Section 4.3.1, eq. (4.14)) when for every key k : BitString h, the parity relation parityOn S₀ m ^^ parityOn S₁ (E k m) = parityOn S₂ k holds with probability at least 1 / 2 + ε over uniform plaintexts m : BitString n. Evaluating linearKeyBitEstimate on t independent uniform plaintext/ciphertext pairs recovers parityOn S₂ k with probability at least 1 - Real.exp (-2 * t * ε ^ 2) (HasLinearRelation.prob_linearKeyBitEstimate_ge), strengthening the printed bound 1 - Real.exp (-(t * ε ^ 2 / 2)) of Lemma 4.3 / eq. (4.15).

Differences from the book. Boneh–Shoup does not say how Majority resolves a tied vote (its two examples have three bits); linearKeyBitEstimate uses Cslib.ProbComp.plurality false, which returns the majority bit whenever one bit has more than t / 2 votes, the first vote on a tie, and false when t = 0. The function E need not be a permutation, and decryption is not used. The book's attack assumes ε > 0; here 0 ≤ ε is a hypothesis of HasLinearRelation.prob_linearKeyBitEstimate_ge rather than part of HasLinearRelation, and the bound fails for negative ε. The module makes no running-time or query-cost claim and recovers only the single key parity bit parityOn S₂ k.

Main definitions #

Main results #

References #

def Cslib.Crypto.LinearCryptanalysis.HasLinearRelation {h n : ℕ} (E : BitString h → BitString n → BitString n) (S₀ S₁ : Finset (Fin n)) (S₂ : Finset (Fin h)) (ε : ℝ) :

A keyed function E : BitString h → BitString n → BitString n satisfies a linear relation with masks (S₀, S₁, S₂) and bias ε ([BS23], Section 4.3.1, eq. (4.14)) if for every key k : BitString h, parityOn S₀ m ^^ parityOn S₁ (E k m) = parityOn S₂ k holds for at least 1 / 2 + ε of plaintexts m : BitString n.

Majority-vote estimator for the key parity bit parityOn S₂ k from t plaintext/ciphertext pairs, implemented with Cslib.ProbComp.plurality false. It returns the majority bit whenever one bit has more than t / 2 votes, the first vote on a tie, and false when t = 0.

theorem Cslib.Crypto.LinearCryptanalysis.HasLinearRelation.prob_linearKeyBitEstimate_ge {h n : ℕ} {E : BitString h → BitString n → BitString n} {S₀ S₁ : Finset (Fin n)} {S₂ : Finset (Fin h)} {ε : ℝ} (hrel : HasLinearRelation E S₀ S₁ S₂ ε) (hε : 0 ≤ ε) (k : BitString h) (t : ℕ) :
1 - Real.exp (-2 * ↑t * ε ^ 2) ≤ ((Probability.PMF.uniformOfFintype (Fin t → BitString n)).toOuterMeasure {m : Fin t → BitString n | (linearKeyBitEstimate S₀ S₁ fun (i : Fin t) => (m i, E k (m i))) = parityOn S₂ k}).toReal

Linear cryptanalysis key-bit recovery ([BS23], Section 4.3.1, Lemma 4.3 / eq. (4.15), sharpened with Hoeffding exponent -2 * t * ε ^ 2). When 0 ≤ ε, linearKeyBitEstimate on t independent uniform plaintext/ciphertext pairs recovers parityOn S₂ k with probability at least 1 - Real.exp (-2 * t * ε ^ 2), implying the printed bound 1 - Real.exp (-(t * ε ^ 2 / 2)).