Documentation

CslibFrontier.Crypto.Primitives.Garbling.HalfGates

Half-gates garbling #

The half-gates garbling scheme of Zahur, Rosulek and Evans [ZRE15] for Boolean circuits over the basis of binary XOR and AND gates. Labels live in K × Bool for a finite additive group K in which every element is its own negative; the Bool component is the label's colour (the least significant bit in [ZRE15]). A global offset Δ = (R, true) has colour true, and every wire w has the labels W w (bit 0) and W w + Δ (bit 1).

The garbled table therefore has exactly two entries per AND gate and none per XOR gate: it is indexed by Slot C (card_slot). The zero labels and the evaluator's labels are computed by one evaluation round iterated n + size times; on the ordered topology of a circuit the result is the unique labelling fixed by one round, since the round is local (Cslib.Circuits.IsLocal.iterate_eq_of_isFixed, Cslib.Circuits.IsLocal.isFixed_iterate).

Correctness (Garbled.run_garbleWith) holds for every hash and tweak assignment, every offset key and every choice of input zero labels, provided x + x = 0 in K: the evaluator holding the labels of an input holds, on every wire, the label of the bit that wire carries (evalStep_activeLabel).

Main definitions #

Main results #

References #

The XOR–AND basis #

The operations of the half-gates basis.

  • xor : Op

    Exclusive or.

  • and : Op

    Conjunction.

@[reducible, inline]

The XOR–AND signature: both operations are binary.

XOR is addition and AND is multiplication in the Boolean ring Bool.

Instances For
    @[reducible, inline]

    The operation of a gate.

    The first argument wire of a gate.

    The second argument wire of a gate.

    The value of a gate on an input, from the values of its arguments.

    @[reducible, inline]

    A ciphertext slot: an AND gate and one of its halves, false for the generator half and true for the evaluator half. XOR gates have no slots.

    @[reducible, inline]

    The AND gate of a slot.

    Two ciphertexts per AND gate: the garbled table has 2 * #AND entries.

    Garbling and evaluation #

    def Cslib.Crypto.Garbling.HalfGates.andEval {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (t t' : T) (TG TE a b : K × Bool) :

    The evaluator's AND gate: from argument labels a, b and ciphertexts TG, TE, the label (H(a, t) + s_a TG) + (H(b, t') + s_b (TE + a)), where s_a, s_b are the colours of a, b.

    def Cslib.Crypto.Garbling.HalfGates.genCt {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (Δ : K × Bool) (t : T) (a b : K × Bool) :

    The generator half-ciphertext H(a, t) + H(a + Δ, t) + p_b Δ of an AND gate with argument zero labels a, b, where p_b is the colour of b.

    def Cslib.Crypto.Garbling.HalfGates.evCt {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (Δ : K × Bool) (t : T) (a b : K × Bool) :

    The evaluator half-ciphertext H(b, t) + H(b + Δ, t) + a of an AND gate with argument zero labels a, b.

    def Cslib.Crypto.Garbling.HalfGates.evalStep {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (ct : Slot C → K × Bool) (X : Fin n → K × Bool) (A : Circuits.Wire n C.size → K × Bool) :

    One evaluation round with table ct and input labels X: an input reads its label, an XOR gate adds its argument labels, and an AND gate applies andEval to its argument labels and its two ciphertexts.

    theorem Cslib.Crypto.Garbling.HalfGates.evalStep_gate_congr {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) {ct ct' : Slot C → K × Bool} (X : Fin n → K × Bool) {A A' : Circuits.Wire n C.size → K × Bool} (g : Fin C.size) (hct : ∀ (h : op C g = Op.and) (b : Bool), ct (⟨g, h⟩, b) = ct' (⟨g, h⟩, b)) (hl : A (left C g) = A' (left C g)) (hr : A (right C g) = A' (right C g)) :
    evalStep C H tw ct X A (Circuits.Wire.gate g) = evalStep C H tw ct' X A' (Circuits.Wire.gate g)

    A gate's round reads only its ciphertexts and its argument labels.

    theorem Cslib.Crypto.Garbling.HalfGates.isLocal_evalStep {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (tab : (Circuits.Wire n C.size → K × Bool) → Slot C → K × Bool) (X : Fin n → K × Bool) (htab : ∀ (A B : Circuits.Wire n C.size → K × Bool) (p : Slot C), A (left C (Slot.gate C p)) = B (left C (Slot.gate C p)) → A (right C (Slot.gate C p)) = B (right C (Slot.gate C p)) → tab A p = tab B p) :
    Circuits.IsLocal fun (A : Circuits.Wire n C.size → K × Bool) => evalStep C H tw (tab A) X A

    A round whose table is computed from the labelling by a rule that reads, for each slot, only the labels of its gate's arguments, is local.

    def Cslib.Crypto.Garbling.HalfGates.garbleTable {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (Δ : K × Bool) (W : Circuits.Wire n C.size → K × Bool) (p : Slot C) :

    The garbled table for zero labels W: the generator and evaluator halves of each AND gate.

    def Cslib.Crypto.Garbling.HalfGates.zeroLabels {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (Δ : K × Bool) (Z : Fin n → K × Bool) :

    The zero labels: input zero labels Z, free XOR, and at each AND gate the evaluator's label on the zero labels of its arguments.

    theorem Cslib.Crypto.Garbling.HalfGates.isLocal_garble {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (Δ : K × Bool) (Z : Fin n → K × Bool) :
    Circuits.IsLocal fun (W : Circuits.Wire n C.size → K × Bool) => evalStep C H tw (garbleTable C H tw Δ W) Z W
    theorem Cslib.Crypto.Garbling.HalfGates.zeroLabels_isFixed {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (Δ : K × Bool) (Z : Fin n → K × Bool) :
    evalStep C H tw (garbleTable C H tw Δ (zeroLabels C H tw Δ Z)) Z (zeroLabels C H tw Δ Z) = zeroLabels C H tw Δ Z

    The zero labels are fixed by one garbling round.

    A half-gates garbled circuit: the ciphertexts, the input encoding and the output decoding.

    • table : Slot C → K × Bool

      The two ciphertexts of each AND gate.

    • encoding : Fin n → Bool → K × Bool

      The label of each bit of each input.

    • decoding : Fin m → Bool

      The colour of the zero label of each output wire.

    def Cslib.Crypto.Garbling.HalfGates.garbleWith {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (R : K) (Z : Fin n → K × Bool) :

    Garble with offset key R and input zero labels Z.

    noncomputable def Cslib.Crypto.Garbling.HalfGates.garble {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] [Fintype K] [Nonempty K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) :

    Garble with a uniform offset key and uniform input zero labels.

    def Cslib.Crypto.Garbling.HalfGates.evalLabels {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (ct : Slot C → K × Bool) (X : Fin n → K × Bool) :

    The evaluator's labels on all wires: n + size rounds from the zero labelling.

    theorem Cslib.Crypto.Garbling.HalfGates.isLocal_evalStep_const {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (ct : Slot C → K × Bool) (X : Fin n → K × Bool) :
    def Cslib.Crypto.Garbling.HalfGates.evaluate {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) (ct : Slot C → K × Bool) (X : Fin n → K × Bool) :
    Fin m → K × Bool

    Evaluate a garbled table on input labels: the labels of the output wires.

    def Cslib.Crypto.Garbling.HalfGates.Garbled.run {n m : ℕ} {K T : Type} [AddCommGroup K] {C : Circuits.Circuit signature n m} (G : Garbled C K) (H : K × Bool → T → K × Bool) (tw : Slot C → T) (x : Fin n → Bool) :
    Fin m → Bool

    Evaluate a garbled circuit on an input and decode: colour plus decoding bit.

    Correctness #

    theorem Cslib.Crypto.Garbling.HalfGates.add_self_label {K : Type} [AddCommGroup K] (hK : ∀ (k : K), k + k = 0) (a : K × Bool) :
    a + a = 0
    theorem Cslib.Crypto.Garbling.HalfGates.add_add_cancel_label {K : Type} [AddCommGroup K] (hK : ∀ (k : K), k + k = 0) (a b : K × Bool) :
    a + (a + b) = b
    theorem Cslib.Crypto.Garbling.HalfGates.andEval_active {K T : Type} [AddCommGroup K] (hK : ∀ (k : K), k + k = 0) (H : K × Bool → T → K × Bool) (R : K) (t t' : T) (a b : K × Bool) (va vb : Bool) :
    andEval H t t' (genCt H (CCR.offset R) t a b) (evCt H (CCR.offset R) t' a b) (a + bitOffset (CCR.offset R) va) (b + bitOffset (CCR.offset R) vb) = andEval H t t' (genCt H (CCR.offset R) t a b) (evCt H (CCR.offset R) t' a b) a b + bitOffset (CCR.offset R) (va * vb)

    The half-gates identity. With the two ciphertexts of an AND gate built from zero labels a, b, the evaluator holding the labels a + v_a Δ and b + v_b Δ obtains andEval … a b + (v_a v_b) Δ: the generator half contributes v_a p_b Δ, the evaluator half v_a (v_b + p_b) Δ.

    def Cslib.Crypto.Garbling.HalfGates.activeLabel {n m : ℕ} (C : Circuits.Circuit signature n m) {K : Type} [AddCommGroup K] (W : Circuits.Wire n C.size → K × Bool) (Δ : K × Bool) (x : Fin n → Bool) (w : Circuits.Wire n C.size) :

    The label of the bit that wire w carries on input x.

    theorem Cslib.Crypto.Garbling.HalfGates.evalStep_activeLabel {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (hK : ∀ (k : K), k + k = 0) (H : K × Bool → T → K × Bool) (tw : Slot C → T) (R : K) (Z : Fin n → K × Bool) (x : Fin n → Bool) (W : Circuits.Wire n C.size → K × Bool) (hW : evalStep C H tw (garbleTable C H tw (CCR.offset R) W) Z W = W) :
    evalStep C H tw (garbleTable C H tw (CCR.offset R) W) (fun (i : Fin n) => Z i + bitOffset (CCR.offset R) (x i)) (activeLabel C W (CCR.offset R) x) = activeLabel C W (CCR.offset R) x

    One round of evaluation on the garbled table, from the labels of the bits every wire carries, gives them back, for zero labels W fixed by one garbling round.

    theorem Cslib.Crypto.Garbling.HalfGates.Garbled.run_garbleWith {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (hK : ∀ (k : K), k + k = 0) (H : K × Bool → T → K × Bool) (tw : Slot C → T) (R : K) (Z : Fin n → K × Bool) (x : Fin n → Bool) :
    (garbleWith C H tw R Z).run H tw x = C.eval interpretation x

    Correctness: evaluating a garbled circuit on an encoded input and decoding gives the circuit's output, for every hash, tweak assignment, offset key and input zero labels.

    theorem Cslib.Crypto.Garbling.HalfGates.Garbled.run_of_mem_support {n m : ℕ} (C : Circuits.Circuit signature n m) {K T : Type} [AddCommGroup K] (hK : ∀ (k : K), k + k = 0) [Fintype K] [Nonempty K] (H : K × Bool → T → K × Bool) (tw : Slot C → T) {G : Garbled C K} (hG : G ∈ (garble C H tw).eval.support) (x : Fin n → Bool) :
    G.run H tw x = C.eval interpretation x

    Correctness of the randomized garbling.