Documentation

Complexity.Probability.BitString.LinearHash

Binary linear hashing #

A uniformly random Boolean matrix is a two-universal family: hashing a nonzero input gives a uniform output. Prefixes of one public matrix supply every shorter hash length, including zero. The list implementation reads fixed-width rows, pads missing seed bits with false, and takes an AND/XOR fold. It reuses the existing block representation and ordinary list operations.

Main definitions #

Main results #

References #

Adapted from Probability/LinearHash.lean on the cslib crypto branch at 5ff69ca93402e7c947208dc56396d6d86203ccd8, in the shared bit-string namespace.

def Cslib.BitString.LinearHash.hash {n m : ℕ} (rows : Fin m → BitString n) (input : BitString n) :

Hash an n-bit input to m bits using the m rows of a Boolean matrix.

Instances For
    theorem Cslib.BitString.LinearHash.uniform_hash_nonzero {n m : ℕ} (input : BitString n) (hinput : input ≠ 0) :

    Hashing any nonzero input by a uniform matrix gives a uniform output.

    The difference of the hashes of distinct inputs is uniform.

    Uniform Boolean matrices are a 2⁻ᵐ-Δ-universal hash family: the bitwise XOR of two hashes of distinct inputs is uniform.

    Uniform Boolean matrices are a universal hash family, including zero-width outputs.

    Prefixes of one public matrix give universal hashes at every shorter output length.

    theorem Cslib.BitString.LinearHash.isTwoUniversal_flat (inputBits outputBits : ℕ) :
    Probability.IsTwoUniversal (Probability.PMF.uniformOfFintype (BitString (outputBits * inputBits))) fun (seed : BitString (outputBits * inputBits)) => hash (blocksEquiv seed)

    A uniformly sampled flat matrix gives the usual two-universal family.

    A word implementation of binary matrix hashing. Missing seed bits are zero.

    Instances For
      @[simp]
      theorem Cslib.BitString.LinearHash.length_wordHash (count : ℕ) (seed input : List Bool) :
      (wordHash count seed input).length = count

      Every row contributes one output bit, including when the input has length zero.

      theorem Cslib.BitString.LinearHash.wordHash_eq_ofFn {n m : ℕ} (seed : List Bool) (input : BitString n) :
      wordHash m seed (List.ofFn input) = List.ofFn (hash (ofList (m * n) seed).block input)

      On a fixed-length source word, the executable hash is exactly the finite matrix hash.