Garbling. The garbling algorithm Garble(C) is described as
follows.
-
Let CircuitInputs(C), CircuitOutputs(C) be the set
of input and output wires of C, respectively. Given a non-input wire i,
let (a,b)←InputWires(C,i) denote the two input wires
a,b of i associated to an AND or XOR gate. Let
a←InputsWires(C,i) denote the input wire a of i
associated to an INV gate. The garbler maintains three sets E,D and
T. The garbler also maintains a counter initiated as 0.
-
Choose a secret global 128-bit string Δ uniformly, and set
LSB(Δ)=1. Let P=X⊕Δ be the label of public bit 1,
where X is chosen uniformly at random. Note that P will be sent to the
evaluator.
-
For i∈CircuitInputs(C), do the following.
- Choose 128-bit Xi0 uniformly at random, and set
Xi1=Xi0⊕Δ.
- Let ei=Xi0 and insert it to E.
-
For any non-input wire i, do the following.
- If the gate associated to i is a XOR gate.
- Let (a,b)←GateInputs(C,i).
- Compute Xi0=Xa0⊕Xb0 and Xi1=Xi0⊕Δ.
- If the gate associated to i is an INV gate.
- Let a←GateInputs(C,i),
- Compute Xi0=Xa0⊕P and Xi1=Xi0⊕Δ.
- If the gate associated to i is an AND gate.
- let (a,b)←GateInputs(C,i),
- Let pa=LSB(Xa0), pb=LSB(Xb0).
- Compute the first half gate:
- Let
TG=H(counter,Xa0)⊕H(counter,Xa1)⊕(pb⋅Δ).
- Let XG0=H(counter,Xa0)⊕(pa⋅TG).
- counter=counter+1.
- Compute the second half gate:
- Let TE=H(counter,Xb0)⊕H(counter,Xb1)⊕Xa0.
- Let XE0=H(counter,Xb0)⊕pb⋅(TE⊕Xa0)
- Let Xi0=XG0⊕XE0, Xi1=Xi0⊕Δ and insert
the garbled gate (TG,TE) to T.
- counter=counter+1.
-
For i∈CircuitOutputs(C), do the following.
- Compute di=LSB(Xi0).
- Insert di into D.
-
The garbler outputs (G,E,D).
Input Encoding. Given E=(e1,...,eℓ), the garbler encodes the input
(x1,...,xℓ)∈{0,1}ℓ as follows.
- For all 1≤i≤ℓ, compute Xi=ei⊕xiΔ
- Outputs X=(X1,...,Xℓ).
Evaluating. The evaluating algorithm Eval(C) is described as
follows.
-
The evaluator takes as input the garbled circuit T and the encoded inputs
X.
-
The evaluator obtains the input labels (X1,...,Xℓ) from X and
initiates counter=0.
-
For any non-input wire i, do the following.
- If the gate associated to i is a XOR gate.
- Let (a,b)←GateInputs(C,i).
- Compute Xi=Xa⊕Xb.
- If the gate associated to i is an INV gate.
- Let a←GateInputs(C,i),
- Compute Xi=Xa⊕P.
- If the gate associated to i is an AND gate.
- Let (a,b)←GateInputs(C,i),
- Let sa=LSB(Xa), sb=LSB(Xb).
- Parse Ti as (TG,TE).
- Compute XG=H(counter,Xa)⊕sa⋅TG.
- counter=counter+1.
- Compute XE=H(counter,Xb)⊕sb(TE⊕Xa).
- Let Xi=XG⊕XE.
-
For i∈CircuitOutputs(C), do the following.
- Let Yi=Xi.
- Outputs Y, the set of Yi.
Output Decoding. Given Y and D, the evaluator decodes the labels into
outputs as follows.
- For any i, compute yi=di⊕LSB(Yi).
- Outputs all yi.