Documentation

CslibFrontier.Crypto.Protocols.MAC.PolynomialEvaluation

Polynomial-evaluation hashes for variable-length messages #

Over a finite field F, a message m = (m₁, …, m_{ℓ'-1}) of length less than ℓ is hashed with a key k ∈ F by appending a field element that encodes its length and evaluating a polynomial with these ℓ' coefficients at k ([KL20], Section 4.5.2). The four coefficient layouts studied there are:

Difference universality is Cslib.Probability.IsDeltaUniversalHash for a uniform key, the Δ-universal property of [KL20], Definition 4.14. Every layout without a constant term yields polynomials of degree at most ℓ, so it is ℓ / |F|-difference universal as soon as distinct messages give distinct polynomials (isDeltaUniversalHash_of_polynomial). The exercise layouts differ in when that happens:

Every evaluation is computed by Horner's rule.

Main definitions #

Main results #

References #

@[reducible, inline]

Messages of length less than ℓ, the set F^{<ℓ} of [KL20], Section 4.5.2.

def Cslib.Crypto.PolynomialEvaluation.coefficients {F : Type u_1} {ℓ : ℕ} (encodeLength : Fin ℓ → F) (m : Message F ℓ) :

The coefficient list (m₁, …, m_{ℓ'-1}, e (ℓ' - 1)) of a message: the message followed by the encoding of its length.

Horner evaluation of c₁ X + c₂ X ^ 2 + ⋯ + c_t X ^ t at k: the coefficient list starts at the linear term, so there is no constant term.

def Cslib.Crypto.PolynomialEvaluation.hash {F : Type u_1} [Field F] {ℓ : ℕ} (encodeLength : Fin ℓ → F) (k : F) (m : Message F ℓ) :
F

The hash of [KL20], Theorem 4.17: m₁ k ^ ℓ' + ⋯ + m_{ℓ'} k.

def Cslib.Crypto.PolynomialEvaluation.fixedTopHash {F : Type u_1} [Field F] {ℓ : ℕ} (encodeLength : Fin ℓ → F) (k : F) (m : Message F ℓ) :
F

Exercise 4.22(a): m₁ k ^ ℓ + ⋯ + m_{ℓ'} k ^ (ℓ - ℓ' + 1), the hash of Theorem 4.17 shifted so that the first coefficient always multiplies k ^ ℓ.

def Cslib.Crypto.PolynomialEvaluation.constantTermHash {F : Type u_1} [Field F] {ℓ : ℕ} (encodeLength : Fin ℓ → F) (k : F) (m : Message F ℓ) :
F

Exercise 4.22(b): m₁ k ^ (ℓ' - 1) + ⋯ + m_{ℓ'}, with the length code as constant term.

def Cslib.Crypto.PolynomialEvaluation.ascendingHash {F : Type u_1} [Field F] {ℓ : ℕ} (encodeLength : Fin ℓ → F) (k : F) (m : Message F ℓ) :
F

Exercise 4.22(c): m₁ k + m₂ k ^ 2 + ⋯ + m_{ℓ'} k ^ ℓ'.

Polynomials without constant term #

theorem Cslib.Crypto.PolynomialEvaluation.isDeltaUniversalHash_of_polynomial {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] {X : Type u_2} (P : X → Polynomial F) (hinj : Function.Injective P) (hcoeff : ∀ (x : X), (P x).coeff 0 = 0) (hdeg : ∀ (x : X), (P x).natDegree ≤ ℓ) :

A family of polynomials without constant term, of degree at most ℓ, that separates its inputs is ℓ / |F|-difference universal: a difference d of two distinct evaluations occurs only at the roots of the nonzero polynomial P x - P x' - d.

The coefficient polynomial #

Layouts whose linear coefficient fixes the length #

theorem Cslib.Crypto.PolynomialEvaluation.ascendingEval_concat {F : Type u_1} [Field F] (k : F) (cs : List F) (a : F) :
ascendingEval k (cs ++ [a]) = ascendingEval k cs + a * k ^ (cs.length + 1)

Appending a coefficient adds the next power of the key.

theorem Cslib.Crypto.PolynomialEvaluation.isDeltaUniversalHash_ascendingEval {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] {X : Type u_2} (coeffs : X → List F) (hinj : Function.Injective coeffs) (hhead : ∀ (x x' : X), (coeffs x).headD 0 = (coeffs x').headD 0 → (coeffs x).length = (coeffs x').length) (hlen : ∀ (x : X), (coeffs x).length ≤ ℓ) :
Probability.IsDeltaUniversalHash (Probability.PMF.uniformOfFintype F) (fun (k : F) (x : X) => ascendingEval k (coeffs x)) (↑ℓ / ↑(Fintype.card F))

An injective family of coefficient lists c₁ X + ⋯ + c_t X ^ t of length at most ℓ, whose linear coefficient c₁ determines the number of coefficients, is ℓ / |F|-difference universal. An empty list counts as having linear coefficient 0.

Theorem 4.17 #

theorem Cslib.Crypto.PolynomialEvaluation.isDeltaUniversalHash_hash {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] {encodeLength : Fin ℓ → F} (hencode : Function.Injective encodeLength) :

[KL20], Theorem 4.17. For an injective length encoding, the polynomial hash m₁ k ^ ℓ' + ⋯ + m_{ℓ'} k on F^{<ℓ} is ℓ / |F|-difference universal.

Exercise 4.22(a) #

theorem Cslib.Crypto.PolynomialEvaluation.isDeltaUniversalHash_fixedTopHash {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] {encodeLength : Fin ℓ → F} (hpos : ∀ (d : Fin ℓ), ↑d ≠ 0 → encodeLength d ≠ 0) :

[KL20], Exercise 4.22(a), positive part. If the length encoding sends no positive length to zero, the layout m₁ k ^ ℓ + ⋯ + m_{ℓ'} k ^ (ℓ - ℓ' + 1) is ℓ / |F|-difference universal.

theorem Cslib.Crypto.PolynomialEvaluation.not_isDeltaUniversalHash_fixedTopHash {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] {encodeLength : Fin ℓ → F} (h1 : 1 < ℓ) (hzero : encodeLength ⟨1, h1⟩ = 0) {ε : ENNReal} (hε : ε < 1) :

[KL20], Exercise 4.22(a), negative part. If the length 1 is encoded as zero and ℓ ≥ 2, the messages [] and [e 0] collide under every key, so the layout is not ε-difference universal for any ε < 1; in particular not ℓ / |F|-difference universal when ℓ < |F|.

Exercise 4.22(b) #

theorem Cslib.Crypto.PolynomialEvaluation.not_isDeltaUniversalHash_constantTermHash {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] (encodeLength : Fin ℓ → F) (h1 : 1 < ℓ) {ε : ENNReal} (hε : ε < 1) :

[KL20], Exercise 4.22(b). For ℓ ≥ 2 and every length encoding, the layout m₁ k ^ (ℓ' - 1) + ⋯ + m_{ℓ'} sends [] and [0] to hashes whose difference is the key-independent constant e 0 - e 1, so it is not ε-difference universal for any ε < 1.

Exercise 4.22(c) #

theorem Cslib.Crypto.PolynomialEvaluation.isDeltaUniversalHash_ascendingHash {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] {encodeLength : Fin ℓ → F} (hpos : ∀ (d : Fin ℓ), ↑d ≠ 0 → encodeLength d ≠ 0) :

[KL20], Exercise 4.22(c), positive part. If the length encoding sends no positive length to zero, the layout m₁ k + ⋯ + m_{ℓ'} k ^ ℓ' is ℓ / |F|-difference universal.

theorem Cslib.Crypto.PolynomialEvaluation.not_isDeltaUniversalHash_ascendingHash {F : Type u_1} [Field F] {ℓ : ℕ} [Fintype F] {encodeLength : Fin ℓ → F} (h1 : 1 < ℓ) (hzero : encodeLength ⟨1, h1⟩ = 0) {ε : ENNReal} (hε : ε < 1) :

[KL20], Exercise 4.22(c), negative part. If the length 1 is encoded as zero and ℓ ≥ 2, the messages [] and [e 0] collide under every key.