Documentation

CslibFrontier.Crypto.Primitives.Garbling.HalfGates.Scheme

Half-gates garbling as a garbling scheme #

Definitions and correctness only. The efficiency certificates of the scheme (CslibFrontier.Crypto.Primitives.Garbling.HalfGates.Efficient), its word simulator (CslibFrontier.Crypto.Primitives.Garbling.HalfGates.Simulator) and its simulation privacy (prv.sim) under CircularCorrelationRobust, by a certified reduction (CslibFrontier.Crypto.Primitives.Garbling.HalfGates.PrvSim), build on it.

The half-gates garbling of CslibFrontier.Crypto.Primitives.Garbling.HalfGates, after Zahur, Rosulek and Evans [ZRE15] (Figure 2, p. 9), as a garbling scheme in the sense of Bellare, Hoang and Rogaway [BHR12b] (Garbling.Scheme) over XOR–AND conventional circuits (XorAndCircuit): HalfGates.scheme hash, with the hash family hash.

At security parameter k, a label is a (k + 1)-bit key followed by its colour bit, and the hash of a label and a k-bit tweak is CCR.atLevel hash k (HalfGates.hashWord on words). Slot s of gate g, false for the generator half and true for the evaluator half, has the tweak 2 g + s, reduced modulo 2 ^ k (HalfGates.tweakWord). The coins are the k + 1 bits of the offset key R, then the n input zero labels; the offset is CCR.offset R = (R, true).

The tweaks of different slots need not differ: at k = 0 every tweak is empty, and at k = 1 the generator halves of gates 0 and 1 both get the tweak [false]. For a circuit with q gates they are all distinct when 2 q ≤ 2 ^ k. Correctness does not use distinct tweaks, and HalfGates.scheme_correct holds for every hash family.

Gb writes the garbled function F as the header (k, n, m, q), in unary, followed for each gate by its two argument wires A g and B g as w-bit numbers, w the bit length of n + q, a bit that is set for an AND gate, and for an AND gate its two ciphertexts, the generator half then the evaluator half. XOR gates have no ciphertexts [KS08]. The encoding information e lists the two labels of each input wire, for bit 0 and bit 1, as in point-and-permute garbling, so En is the projective encoding projectiveEncode; the decoding information d lists the colours of the zero labels of the m output wires, and De is PointPermute.decodeWord.

Three choices differ from Figure 2 of [ZRE15] (p. 9): the tweaks are numbered by gate, 2 g + s modulo 2 ^ k, where Figure 2 takes j and j' from the counter NextIndex, which advances only at AND gates; e is projective, listing both labels of each input, where Figure 2 sets e_i = W_i^0 and encodes X_i = e_i ⊕ x_i R; and labels have k + 2 bits, where Figure 2 has k-bit labels and R ∈ {0,1}^{k-1}1.

The scheme is correct (HalfGates.scheme_correct) but not valid in the sense of [BHR12b] (§3.1, p. 7). The length of F depends on the number of AND gates, so the length condition fails, and d holds the colours of output zero labels derived through the hash from the gates, so it depends on f and non-degeneracy fails too. The scheme of [ZRE15] behaves the same way: Figure 2 sends F_i only for AND gates and sets d_i = lsb(W_i^0). Simulation privacy does not use validity.

The garbler and the evaluator are list programs. The garbler writes the typed garbling HalfGates.garbleWith of HalfGates.toCircuit f (HalfGates.gb_eq_encodeGarbled), and the evaluator follows every fixed point of the typed evaluation round (HalfGates.evalWord_encodeFn), so correctness follows from HalfGates.Garbled.run_garbleWith and HalfGates.eval_toCircuit.

Main definitions #

Main results #

References #

Words #

The tweak of slot s of gate g at parameter k, s = false for the generator half: the k low bits of 2 g + s, least significant first. Different slots get the same tweak when 2 g + s agree modulo 2 ^ k; correctness does not need distinct tweaks.

The hash at parameter k on words: the first k + 2 bits of hash x t, padded with false. On a label and a k-bit tweak it is CCR.atLevel hash k (labelBits_atLevel).

bitOffset Δ b on words at parameter k: Δ when b is set, the zero label otherwise.

The colour of a label word at parameter k: its bit k + 1.

The generator half H(a, t) + H(a + Δ, t) + p_b Δ of gate g, from the zero labels a, b of its arguments (genCt).

The evaluator half H(b, t') + H(b + Δ, t') + a of gate g, from the zero labels a, b of its arguments (evCt).

def Cslib.Crypto.Garbling.HalfGates.andWord (hash : List Bool → List Bool → List Bool) (k g : ℕ) (TG TE a b : List Bool) :

The evaluator's AND gate g on words, from its ciphertexts TG, TE and the labels a, b of its arguments: (H(a, t) + s_a TG) + (H(b, t') + s_b (TE + a)) (andEval).

def Cslib.Crypto.Garbling.HalfGates.zeroGate (hash : List Bool → List Bool → List Bool) (k g : ℕ) (Δ a b : List Bool) (isAnd : Bool) :

The zero label of gate g from the zero labels a, b of its arguments under the offset Δ: the evaluator's AND gate on the gate's own ciphertexts, or the sum for an XOR gate.

The offset Δ = (R, 1) read from the coins: their first k + 1 bits, padded with false, then true.

The zero label of input i read from the coins: block i of k + 2 bits after the offset key.

The zero labels of the first n + s wires of f at parameter k, in wire order: the input zero labels read from the coins, then gate by gate zeroGate on the zero labels of the gate's arguments.

def Cslib.Crypto.Garbling.HalfGates.gateWord (hash : List Bool → List Bool → List Bool) (k w : ℕ) (f : ConventionalCircuit) (Δ : List Bool) (labels : List (List Bool)) (g : Fin f.q) :

The block of gate g in the garbled function, from the zero labels labels of all wires: the numbers of its argument wires as w-bit numbers, its AND bit, and for an AND gate its two ciphertexts.

The garbled function of f: the header (k, n, m, q), then the blocks of its gates.

The encoding information of f: for each input wire, the labels encoding 0 and 1; label j encodes bit j mod 2 of input j / 2.

The decoding information of f: the colours of the zero labels of its last m wires.

def Cslib.Crypto.Garbling.HalfGates.evalGate (hash : List Bool → List Bool → List Bool) (k w : ℕ) (body : List Bool) (state : List (List Bool) × ℕ) (g : ℕ) :

One gate of Ev, with the labels of the earlier wires and the position pos of the gate's block in the body: read the gate's argument wires and their labels, and append the sum of the labels for an XOR gate, or the evaluator's AND gate on the two ciphertexts for an AND gate.

Ev(F, X): read the header (k, n, m, q) of F, start from the n labels of X, evaluate the gates in order, and return the labels of the last m wires.

Half-gates garbling as a garbling scheme over XOR–AND conventional circuits, with the hash family hash.

The typed garbling #

The tweaks of the slots of a circuit at parameter k: slot s of gate g gets tweakWord k g s.

The offset key read from the coins: their first k + 1 bits.

The input zero labels read from the coins.

def Cslib.Crypto.Garbling.HalfGates.encodeGate {n m : ℕ} (k w : ℕ) (C : Circuits.Circuit signature n m) (table : Slot C → BitString (k + 1) × Bool) (g : Fin C.size) :

The block of gate g of a garbled table over C at parameter k: the numbers of its argument wires, from 1, as w-bit numbers, its AND bit, and for an AND gate its two ciphertexts, the generator half first.

The garbled function of a table over C at parameter k: the header (k, n, m, s), then the blocks of the gates.

The words (F, e, d) of a typed garbling of toCircuit f at parameter k.

@[simp]

A tweak word has k bits.

theorem Cslib.Crypto.Garbling.HalfGates.ofFn_slotTweak {n m : ℕ} (C : Circuits.Circuit signature n m) (k : ℕ) (g : Fin C.size) (h : op C g = Op.and) (s : Bool) :
List.ofFn (slotTweak C k (⟨g, h⟩, s)) = tweakWord k (↑g) s

The tweak of a slot, as a word, is tweakWord.

@[simp]
theorem Cslib.Crypto.Garbling.HalfGates.length_hashWord (hash : List Bool → List Bool → List Bool) (k : ℕ) (x t : List Bool) :
(hashWord hash k x t).length = k + 2

A hash word has k + 2 bits.

The hash on words is CCR.atLevel.

bitOffset on words is maskWord.

The colour of a label word is the label's colour.

theorem Cslib.Crypto.Garbling.HalfGates.labelBits_genCt (hash : List Bool → List Bool → List Bool) (k g : ℕ) {t : BitString k} (ht : List.ofFn t = tweakWord k g false) (Δ a b : BitString (k + 1) × Bool) :
labelBits (genCt (CCR.atLevel hash k) Δ t a b) = genWord hash k g (labelBits Δ) (labelBits a) (labelBits b)

The generator half on words is genCt.

theorem Cslib.Crypto.Garbling.HalfGates.labelBits_evCt (hash : List Bool → List Bool → List Bool) (k g : ℕ) {t : BitString k} (ht : List.ofFn t = tweakWord k g true) (Δ a b : BitString (k + 1) × Bool) :
labelBits (evCt (CCR.atLevel hash k) Δ t a b) = evWord hash k g (labelBits Δ) (labelBits a) (labelBits b)

The evaluator half on words is evCt.

theorem Cslib.Crypto.Garbling.HalfGates.labelBits_andEval (hash : List Bool → List Bool → List Bool) (k g : ℕ) {t t' : BitString k} (ht : List.ofFn t = tweakWord k g false) (ht' : List.ofFn t' = tweakWord k g true) (TG TE a b : BitString (k + 1) × Bool) :
labelBits (andEval (CCR.atLevel hash k) t t' TG TE a b) = andWord hash k g (labelBits TG) (labelBits TE) (labelBits a) (labelBits b)

The evaluator's AND gate on words is andEval.

The offset read from the coins, as a word, is offsetWord.

theorem Cslib.Crypto.Garbling.HalfGates.labelBits_inputLabels {n : ℕ} (k : ℕ) (coins : List Bool) (i : Fin n) :
labelBits (inputLabels k coins i) = inputWord k coins ↑i

An input zero label read from the coins, as a word, is inputWord.

theorem Cslib.Crypto.Garbling.HalfGates.getD_take_labels {n s k : ℕ} (A : Circuits.Wire n s → BitString (k + 1) × Bool) {j i : ℕ} (hij : i < j) (hj : j ≤ n + s) :
(List.take j (List.ofFn fun (v : Fin (n + s)) => labelBits (A (Circuits.Wire.ofNat ↑v ⋯)))).getD i [] = labelBits (A (Circuits.Wire.ofNat i ⋯))

An entry of a prefix of the label words of a labelling.

theorem Cslib.Crypto.Garbling.HalfGates.getD_ofFn_labels {n s k : ℕ} (A : Circuits.Wire n s → BitString (k + 1) × Bool) {i : ℕ} (hi : i < n + s) :
(List.ofFn fun (v : Fin (n + s)) => labelBits (A (Circuits.Wire.ofNat ↑v ⋯))).getD i [] = labelBits (A (Circuits.Wire.ofNat i hi))

An entry of the label words of a labelling.

theorem Cslib.Crypto.Garbling.HalfGates.zeroWords_eq (hash : List Bool → List Bool → List Bool) (k : ℕ) (f : XorAndCircuit) (coins : List Bool) {s : ℕ} (hs : s ≤ f.circuit.q) :
zeroWords hash k f.circuit coins s = List.take (f.circuit.n + s) (List.ofFn fun (v : Fin (f.circuit.n + (toCircuit f).size)) => labelBits (zeroLabels (toCircuit f) (CCR.atLevel hash k) (slotTweak (toCircuit f) k) (CCR.offset (offsetKey k coins)) (inputLabels k coins) (Circuits.Wire.ofNat ↑v ⋯)))

The garbler's zero labels are the typed zero labels. The first n + s zero label words that Gb computes are the words of the zero labels of the typed garbling of toCircuit f, with the offset key and input zero labels read from the coins.

Gate g of a typed garbled table over toCircuit f, as a word: the argument wires A g and B g of f as w-bit numbers, w the bit length of n + q, the AND bit G g 1 1, and for an AND gate the words of its two ciphertexts, the generator half first.

theorem Cslib.Crypto.Garbling.HalfGates.gb_eq_encodeGarbled (hash : List Bool → List Bool → List Bool) (k : ℕ) (f : XorAndCircuit) (coins : List Bool) :
(scheme hash).gb k f coins = encodeGarbled k f (garbleWith (toCircuit f) (CCR.atLevel hash k) (slotTweak (toCircuit f) k) (offsetKey k coins) (inputLabels k coins))

The garbler computes the typed garbling. At parameter k, Gb on any coins writes the words of the typed half-gates garbling garbleWith of toCircuit f, with the hash CCR.atLevel hash k, the tweaks slotTweak and the offset key and input zero labels read from the coins.

Evaluation #

theorem Cslib.Crypto.Garbling.HalfGates.block_parts {w : ℕ} {a b cts more : List Bool} (d : Bool) (ha : a.length = w) (hb : b.length = w) :
List.take w (a ++ b ++ [d] ++ cts ++ more) = a ∧ List.take w (List.drop w (a ++ b ++ [d] ++ cts ++ more)) = b ∧ (a ++ b ++ [d] ++ cts ++ more).getD (2 * w) false = d ∧ List.drop (2 * w + 1) (a ++ b ++ [d] ++ cts ++ more) = cts ++ more

The parts of a gate block followed by more of the body: its two wire numbers, its flag bit, and its ciphertexts with the rest.

theorem Cslib.Crypto.Garbling.HalfGates.evalWord_encodeFn (hash : List Bool → List Bool → List Bool) (k : ℕ) (f : XorAndCircuit) (table : Slot (toCircuit f) → BitString (k + 1) × Bool) (X : Fin f.circuit.n → BitString (k + 1) × Bool) (A : Circuits.Wire f.circuit.n (toCircuit f).size → BitString (k + 1) × Bool) (hA : ∀ (w : Circuits.Wire f.circuit.n (toCircuit f).size), evalStep (toCircuit f) (CCR.atLevel hash k) (slotTweak (toCircuit f) k) table X A w = A w) :
evalWord hash (encodeFn k (toCircuit f) table) (List.ofFn fun (i : Fin f.circuit.n) => labelBits (X i)).flatten = (List.ofFn fun (o : Fin f.circuit.m) => labelBits (A ((toCircuit f).outputs o))).flatten

Ev follows a fixed point of an evaluation round. If the labelling A of the wires of toCircuit f is left unchanged by one round of the typed evaluation of table on the input labels X, then Ev on the garbled function of table and the words of X returns the labels A of the output wires.

Correctness #

Correctness: decoding the evaluation of an encoded input gives the circuit's output, for every hash family.