Documentation

CslibFrontier.Crypto.Primitives.PRF.RandPrefixFreeEncoding

Randomized prefix-free encodings #

Boneh and Shoup turn a PRF that is secure only on prefix-free query sets into a fully secure one by encoding its inputs with a keyed encoding that is prefix-free with high probability ([BS23], §6.7, pp. 236–237, and §6.10, p. 242). This file defines the notion and proves the collision bounds of the book's two examples. Theorem 6.9, the PRF built from such an encoding, is not proved here.

Main definitions #

Main results #

Differences from the book #

Encodings take values in List X and Definition 6.6's bound ≤ ℓ on the number of blocks is a separate length lemma; non-emptiness is part of the definition. Definition 6.6 is stated for any key law seed : PMF K and any ε : ℝ≥0∞; the book draws k uniformly and takes 0 ≤ ε ≤ 1. The simple encoding is proved for every finite additive group X (for Cslib.BitString n, + is XOR) on the non-empty lists; on all lists it fails, since [] is a prefix of everything. The CMAC encoding needs 0 < n, is defined on every bit string, and its length bound needs 1 ≤ ℓ; with a single key k₁ = k₂ the empty message and 1 ‖ 0^(n-1) collide for every key. Counterexamples for these hypotheses are in CslibFrontierTests.Crypto.RandPrefixFreeEncoding.

References #

Definitions 6.5 and 6.6 #

Prefix compatibility x ∼ y ([BS23], Definition 6.5): x is a prefix of y or y is a prefix of x.

Instances For
    structure Cslib.Crypto.PRF.IsRandPrefixFreeEncoding {K : Type u_1} {M : Type u_2} {X : Type u_3} (seed : PMF K) (rpf : K → M → List X) (ε : ENNReal) :

    A randomized ε-prefix-free encoding ([BS23], Definition 6.6): every encoding is non-empty, and for distinct messages the probability over k ← seed that their encodings are prefix-compatible is at most ε. The bound on the number of blocks is not part of the definition; the book also draws k uniformly and takes ε ≤ 1.

    theorem Cslib.Crypto.PRF.IsRandPrefixFreeEncoding.comp_injective {K : Type u_1} {M : Type u_2} {M' : Type u_3} {X : Type u_4} {seed : PMF K} {rpf : K → M → List X} {ε : ENNReal} (h : IsRandPrefixFreeEncoding seed rpf ε) {e : M' → M} (he : Function.Injective e) :
    IsRandPrefixFreeEncoding seed (fun (k : K) (m : M') => rpf k (e m)) ε

    Restricting a randomized prefix-free encoding along an injection of messages, for instance to the messages of bounded length, keeps its bound.

    theorem Cslib.Crypto.PRF.IsRandPrefixFreeEncoding.of_card_le {K : Type u_1} {M : Type u_2} {X : Type u_4} {rpf : K → M → List X} [Fintype K] [Nonempty K] [DecidableEq X] (hne : ∀ (k : K) (m : M), rpf k m ≠ []) {c : ℕ} (hc : ∀ (m₀ m₁ : M), m₀ ≠ m₁ → {k : K | PrefixCompatible (rpf k m₀) (rpf k m₁)}.card ≤ c) :

    For a uniform key on a finite type, it suffices to count: if at most c keys make the encodings of any two distinct messages prefix-compatible, the encoding is c / |K|-prefix-free.

    Adding a key to the last block #

    Adding a uniform key to the last block is a randomized 1/|X|-prefix-free encoding of the non-empty lists ([BS23], §6.7, "A simple rpf", pp. 236–237), for every finite additive group X; the book's is X = {0,1}ⁿ under XOR.

    CMAC's encoding #

    The unkeyed part of CMAC's encoding ([BS23], §6.10, p. 242): (true, blocks) when |m| is a positive multiple of n, with m cut into n-bit blocks, and otherwise (false, blocks of m ‖ 1 ‖ 0^*). The flag selects the key added to the last block.

    CMAC's randomized prefix-free encoding ([BS23], §6.10, p. 242). Cut m into n-bit blocks; if |m| is a positive multiple of n, add k₁ to the last block, and otherwise pad m with 1 ‖ 0^* to a positive multiple of n and add k₂ to the last block.

    theorem Cslib.Crypto.PRF.length_cmacRpf_le {n ℓ : ℕ} (hn : 0 < n) (hℓ : 1 ≤ ℓ) (k : BitString n × BitString n) {m : List Bool} (hm : m.length ≤ n * ℓ) :
    (cmacRpf n k m).length ≤ ℓ

    CMAC's encoding has the book's codomain: a message of at most nℓ bits has at most ℓ blocks, for 0 < n and 1 ≤ ℓ.

    CMAC's encoding with two independent uniform keys is a randomized 2⁻ⁿ-prefix-free encoding of all bit strings, for 0 < n ([BS23], §6.10, p. 242).