Documentation

CslibFrontier.Crypto.Primitives.Garbling.Basic

Garbled circuits #

A point-and-permute garbling of Boolean circuits over an arbitrary signature, in the style of Yao [Yao86] with the point-and-permute technique of Beaver, Micali and Rogaway [BMR90], following the garbling-scheme syntax of Bellare, Hoang and Rogaway [BHR12b]: garble, encode, evaluate, decode.

Each wire w has two labels (key (w, c), c), one for each colour c : Bool. The colour of the label carrying bit b is b + perm w, for a secret permutation bit perm w. Labels live in K × Bool for a finite additive group K of keys, and a keyed function F : K → T → K × Bool (a PRF in the security analysis) masks the table. Each gate g has one table row for each colour vector ρ of its arguments; the row holds the label of the gate's output for the bits those colours encode, masked by ∑ k, F (key (w_k, ρ k)) (tw (ρ, k)), where w_k is the k-th argument wire and tw assigns a tweak to each argument slot of each row. For binary gates this is a double encryption under the two argument keys. The evaluator holding one label per argument wire selects the row named by their colours and removes the mask with their keys; the decoding information is the permutation bit of each output wire.

Correctness (Garbled.run_garbleWith) holds for every keyed function F, tweak assignment tw, choice of keys and permutation bits, and input. Evaluation follows every wire labelling that is a fixed point of one evaluation round (evaluate_eq_of_evalStep), for every topology whose gates read only earlier wires, since such a round is local (isLocal_evalStep); this also gives correctness of the simulator. Garbling uses the circuit's operations only through its truth tables; the table shape depends only on the topology.

Main definitions #

Main results #

References #

@[reducible, inline]

A row of a garbled table: a gate together with a colour for each of its arguments.

@[reducible, inline]

An argument slot of a table row; each slot has its own tweak.

def Cslib.Crypto.Garbling.inputEncoding {n : ℕ} {K : Type} {g : ℕ} (key : Circuits.Wire n g × Bool → K) (perm : Circuits.Wire n g → Bool) :
Fin n → Bool → K × Bool

The input encoding: bit b of input i is the label of colour b + perm (input i).

The output decoding information: the permutation bit of each output wire.

def Cslib.Crypto.Garbling.encode {n : ℕ} {L : Type} (e : Fin n → Bool → L) (x : Fin n → Bool) :
Fin n → L

Encode an input with an input encoding.

def Cslib.Crypto.Garbling.decode {m : ℕ} {K : Type} (d : Fin m → Bool) (Y : Fin m → K × Bool) :
Fin m → Bool

Decode output labels: the output bit is the colour plus the permutation bit.

def Cslib.Crypto.Garbling.plainRow {σ : Circuits.Signature} {n m : ℕ} {K : Type} (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (key : Circuits.Wire n C.size × Bool → K) (perm : Circuits.Wire n C.size → Bool) (r : Row C.topology) :

The plaintext of a row: the label of the gate's output for the input bits that the row's colours encode.

structure Cslib.Crypto.Garbling.Garbled {n m s : ℕ} (τ : Circuits.Circuit.Topology n m s) (K : Type) :

A garbled circuit: its table, input encoding and output decoding.

  • table : Row τ → K × Bool

    The garbled table.

  • encoding : Fin n → Bool → K × Bool

    The label of each bit of each input.

  • decoding : Fin m → Bool

    The permutation bit of each output wire.

def Cslib.Crypto.Garbling.activeLabel {σ : Circuits.Signature} {n m : ℕ} {K : Type} (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (key : Circuits.Wire n C.size × Bool → K) (perm : Circuits.Wire n C.size → Bool) (x : Fin n → Bool) (w : Circuits.Wire n C.size) :

The label of each wire that the evaluator holds on input x: the label of colour trace w + perm w.

theorem Cslib.Crypto.Garbling.plainRow_trace {σ : Circuits.Signature} {n m : ℕ} {K : Type} (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (key : Circuits.Wire n C.size × Bool → K) (perm : Circuits.Wire n C.size → Bool) (x : Fin n → Bool) (g : Fin C.size) :
plainRow C I key perm ⟨g, fun (k : Fin (C.topology.arity g)) => (activeLabel C I key perm x (C.topology.wires g k)).2⟩ = activeLabel C I key perm x (Circuits.Wire.gate g)

The row named by the active colours of a gate's arguments holds the gate's active label.

def Cslib.Crypto.Garbling.rowMask {n m s : ℕ} {K T : Type} [AddCommGroup K] (τ : Circuits.Circuit.Topology n m s) (F : K → T → K × Bool) (tw : Slot τ → T) (key : Circuits.Wire n s × Bool → K) (r : Row τ) :

The mask of a row: the sum, over its arguments, of the keyed function at the argument's key of the row's colour and the slot's tweak.

def Cslib.Crypto.Garbling.garbleTable {σ : Circuits.Signature} {n m : ℕ} {K T : Type} [AddCommGroup K] (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (F : K → T → K × Bool) (tw : Slot C.topology → T) (key : Circuits.Wire n C.size × Bool → K) (perm : Circuits.Wire n C.size → Bool) :

The garbled table: each row's plaintext plus its mask.

def Cslib.Crypto.Garbling.garbleWith {σ : Circuits.Signature} {n m : ℕ} {K T : Type} [AddCommGroup K] (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (F : K → T → K × Bool) (tw : Slot C.topology → T) (key : Circuits.Wire n C.size × Bool → K) (perm : Circuits.Wire n C.size → Bool) :

Garble a circuit with the given keys and permutation bits.

noncomputable def Cslib.Crypto.Garbling.garble {σ : Circuits.Signature} {n m : ℕ} {K T : Type} [AddCommGroup K] [Fintype K] [Nonempty K] (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (F : K → T → K × Bool) (tw : Slot C.topology → T) :

Garble a circuit with uniform keys and permutation bits.

def Cslib.Crypto.Garbling.evalStep {n m s : ℕ} {K T : Type} [AddCommGroup K] (τ : Circuits.Circuit.Topology n m s) (F : K → T → K × Bool) (tw : Slot τ → T) (table : Row τ → K × Bool) (X : Fin n → K × Bool) (labels : Circuits.Wire n s → K × Bool) :

One round of evaluation: an input reads its label, and a gate reads the row named by the colours of its arguments' labels and removes the mask with their keys.

def Cslib.Crypto.Garbling.evaluate {n m s : ℕ} {K T : Type} [AddCommGroup K] (τ : Circuits.Circuit.Topology n m s) (F : K → T → K × Bool) (tw : Slot τ → T) (table : Row τ → K × Bool) (X : Fin n → K × Bool) :
Fin m → K × Bool

Evaluate a garbled table on input labels: n + s rounds from the zero labelling, which reach every wire of an ordered topology, then read the output wires.

def Cslib.Crypto.Garbling.Garbled.run {n m s : ℕ} {K T : Type} [AddCommGroup K] {τ : Circuits.Circuit.Topology n m s} (G : Garbled τ K) (F : K → T → K × Bool) (tw : Slot τ → T) (x : Fin n → Bool) :
Fin m → Bool

Evaluate a garbled circuit on an input and decode the result.

theorem Cslib.Crypto.Garbling.isLocal_evalStep {n m s : ℕ} {K T : Type} [AddCommGroup K] {τ : Circuits.Circuit.Topology n m s} (hτ : τ.IsOrdered) (F : K → T → K × Bool) (tw : Slot τ → T) (table : Row τ → K × Bool) (X : Fin n → K × Bool) :
Circuits.IsLocal (evalStep τ F tw table X)

On an ordered topology, an evaluation round is local: a gate reads only the labels of its arguments, which have lower wire numbers.

theorem Cslib.Crypto.Garbling.evaluate_eq_of_evalStep {n m s : ℕ} {K T : Type} [AddCommGroup K] {τ : Circuits.Circuit.Topology n m s} (hτ : τ.IsOrdered) (F : K → T → K × Bool) (tw : Slot τ → T) (table : Row τ → K × Bool) (X : Fin n → K × Bool) (A : Circuits.Wire n s → K × Bool) (hA : ∀ (w : Circuits.Wire n s), evalStep τ F tw table X A w = A w) :
evaluate τ F tw table X = A ∘ τ.outputs

On an ordered topology, evaluation follows every wire labelling A that one evaluation round leaves unchanged: the evaluated output labels are those of A.

theorem Cslib.Crypto.Garbling.evalStep_activeLabel {σ : Circuits.Signature} {n m : ℕ} {K T : Type} [AddCommGroup K] (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (F : K → T → K × Bool) (tw : Slot C.topology → T) (key : Circuits.Wire n C.size × Bool → K) (perm : Circuits.Wire n C.size → Bool) (x : Fin n → Bool) (w : Circuits.Wire n C.size) :
evalStep C.topology F tw (garbleTable C I F tw key perm) (encode (inputEncoding key perm) x) (activeLabel C I key perm x) w = activeLabel C I key perm x w

Removing the mask with the active labels of the arguments gives the gate's active label.

theorem Cslib.Crypto.Garbling.Garbled.run_garbleWith {σ : Circuits.Signature} {n m : ℕ} {K T : Type} [AddCommGroup K] (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (F : K → T → K × Bool) (tw : Slot C.topology → T) (key : Circuits.Wire n C.size × Bool → K) (perm : Circuits.Wire n C.size → Bool) (x : Fin n → Bool) :
(garbleWith C I F tw key perm).run F tw x = C.eval I x

Correctness: evaluating a garbled circuit on an encoded input and decoding gives the circuit's output, for every keyed function, tweak assignment, keys and permutation bits.

theorem Cslib.Crypto.Garbling.Garbled.run_of_mem_support {σ : Circuits.Signature} {n m : ℕ} {K T : Type} [AddCommGroup K] [Fintype K] [Nonempty K] (C : Circuits.Circuit σ n m) (I : Circuits.Interpretation σ Bool) (F : K → T → K × Bool) (tw : Slot C.topology → T) {G : Garbled C.topology K} (hG : G ∈ (garble C I F tw).eval.support) (x : Fin n → Bool) :
G.run F tw x = C.eval I x

Correctness of the randomized garbling: every garbled circuit it can output evaluates correctly on every input.