Documentation

CslibFrontier.Crypto.Primitives.PRF.PrefixFreeEncoding

Deterministic Prefix-Free Encodings #

Prefix-free encodings ([BS23], Sections 6.6–6.6.1, pp. 235–236): functions into nonempty lists of blocks whose range is a prefix-free set (InformationTheory.IsPrefixFree).

Main definitions #

Main results #

Differences from the book #

References #

structure Cslib.Crypto.PRF.IsPrefixFreeEncoding {M : Type u_1} {X : Type u_2} (pf : M → List X) :

A function pf : M → List X is a prefix-free encoding ([BS23], Section 6.6, p. 235) if every output is nonempty, pf is injective, and Set.range pf is a prefix-free set.

theorem Cslib.Crypto.PRF.IsPrefixFreeEncoding.iff_forall_prefix {M : Type u_1} {X : Type u_3} {pf : M → List X} :
IsPrefixFreeEncoding pf ↔ (∀ (m : M), pf m ≠ []) ∧ ∀ (m₁ m₂ : M), pf m₁ <+: pf m₂ → m₁ = m₂

A function is a prefix-free encoding iff every output is nonempty and pf m₁ <+: pf m₂ implies m₁ = m₂.

theorem Cslib.Crypto.PRF.IsPrefixFreeEncoding.comp_injective {M : Type u_1} {M' : Type u_2} {X : Type u_3} {pf : M → List X} (h : IsPrefixFreeEncoding pf) {e : M' → M} (he : Function.Injective e) :

Precomposing a prefix-free encoding with an injective map yields a prefix-free encoding.

Method 2 stop-bit encoding ([BS23], Section 6.6.1, p. 236): appends false to every block except the last and true to the last block, mapping n-bit blocks to (n + 1)-bit blocks. Empty input maps to [].

@[simp]

stopBitEncode preserves the number of blocks.

Method 2 (stop bits) ([BS23], Section 6.6.1, p. 236): stopBitEncode is a prefix-free encoding on nonempty lists of n-bit blocks.

def Cslib.Crypto.PRF.separatingBlock {X : Type u_1} [BEq X] (a b : X) (u v : List X) :
X

Choose a common block to append to two queries. At the end of the shorter query, the chosen block differs from the block at that position in the longer query. The two candidate blocks are supplied by the caller. This is a preparation step for [BS23], v0.6, Theorem 7.3 (printed pp. 258–259), using one extra block even for incomparable queries.

theorem Cslib.Crypto.PRF.separatingBlock_prefix_incomparable {X : Type u_1} [BEq X] [LawfulBEq X] {a b : X} (hab : a ≠ b) {u v : List X} (hne : u ≠ v) :
have c := separatingBlock a b u v; ¬u ++ [c] <+: v ++ [c] ∧ ¬v ++ [c] <+: u ++ [c]

Appending the chosen common block makes two distinct queries prefix-incomparable.

def Cslib.Crypto.PRF.findFreshBlock {α : Type u_1} [BEq α] {size : ℕ} (blockAt : Fin size → α) (used : List α) :

Find the first unused block among at most used.length + 1 entries in an indexed alphabet.

Search the first min (2 ^ n) (b + 1) bit strings for a block absent from messages, where b counts all block occurrences. This is the block-selection step of [BS23], v0.6, Theorem 7.4 (printed pp. 259–260). It returns none when the batch uses the whole alphabet.

theorem Cslib.Crypto.PRF.isPrefixFree_append_of_notMem_flatten {α : Type u_1} {messages : List (List α)} {block : α} (hfresh : block ∉ messages.flatten) :
InformationTheory.IsPrefixFree ((fun (msg : List α) => msg ++ [block]) '' {msg : List α | msg ∈ messages})

An absent block delimits each message, so appending it to the batch makes a prefix-free set.

theorem Cslib.Crypto.PRF.isPrefixFree_append_of_freshBatchBlock_eq_some {n : ℕ} {messages : List (List (BitString n))} {block : BitString n} (hblock : freshBatchBlock messages = some block) :
InformationTheory.IsPrefixFree ((fun (msg : List (BitString n)) => msg ++ [block]) '' {msg : List (BitString n) | msg ∈ messages})

Appending a block returned by the batch search makes the extended messages prefix-free.

theorem Cslib.Crypto.PRF.isPrefixFree_append_freshBatchBlock {n : ℕ} {messages : List (List (BitString n))} (hsize : messages.flatten.length < 2 ^ n) :
∃ (block : BitString n), freshBatchBlock messages = some block ∧ InformationTheory.IsPrefixFree ((fun (msg : List (BitString n)) => msg ++ [block]) '' {msg : List (BitString n) | msg ∈ messages})

The batch search supplies a fresh delimiter whenever the total block count is below the alphabet size. Appending it to every message gives a prefix-free set, including when an original message is empty or is a prefix of another. This is the query preparation step for (7.9).