An important and recurring problem in cryptography is the problem of secure function evaluation (SFE). For simplicity, we just consider the 2-party setting. In the 2-party setting, the two agents, Alice and Bob, each have some private input and , respectively, and they want to compute some function of their inputs without revealing their inputs. The SFE problem was first introduced by Andrew Yao  in 1982 where he introduced what has come to be known as the millionaire problem.
Millionaire Problem. Alice and Bob are millionaires and are interested in knowing who is richer. However, they wish to do so without revealing their actual wealth.
If we view the above problem through the SFE lens, then and would coincide with Alice’s and Bob’s wealth, respectively. The function they want to compute would be the comparator function:
Note that denotes an indicator function that evaluates to 1 if the predicate is satisfied and 0 otherwise.
More generally, we can take , and at the conclusion of the protocol, Alice learns and Bob learns . Alice and Bob should not learn anything about the other’s input except what is explicitly leaked by the result. Observe that the millionaire problem described above is just a special case where
Moreover, observe that we can take , where denotes the null function. In other words, following the SFE protocol, Alice does not learn anything about Bob’s input, whereas Bob learns the value of .
One elegant construction of an SFE protocol is through garbled circuits. In this model, we will use a Boolean circuit to model the function . A Boolean circuit consists of a series of logic gates: AND, OR, NOT, and so on. In our setup, a logic gate takes several input bits (0s and 1s) and produces a single output bit. We can characterize the operation of a logic gate by writing down a truth table, that is, the gate’s output bit for each assignment to its inputs. As an example, consider an AND gate with two inputs. The output of an AND gate is 1 if both of its inputs is 1, and 0 otherwise. Thus, the truth table for an AND gate will look like the following:
|Input 1||Input 2||Output|
Similarly, we can write down truth tables for OR gates, NOT gates, and so on. Then, given a function , we can construct a Boolean circuit that evaluates . A Boolean circuit consists of a series of logic gates with wires connecting the inputs and outputs of the different gates. From complexity theory, we know that if there exists a polynomial-time algorithm for computing , then there exists a polynomial-sized circuit that evaluates . Thus, the circuit model is quite flexible and allow us to efficiently model many functions of interest.
Thus, given a function , we can construct a circuit that evaluates . The final ingredient we need to obtain SFE is a way of evaluating the circuit without revealing any information about the inputs. The idea here is to take a circuit for , and construct a garbled circuit that can be used to securely evaluate . In particular, we seek a circuit that may be evaluated without revealing any information about the input or intermediate bits. To do so, we transform the circuit as follows:
- Observe that each wire in the circuit will carry a single bit. Then, for each wire , we associate two random values and with the wire, depending on the bit carried by the wire. In other words, if the wire is carrying a 0, we assign it the value and if the wire is carrying the bit 1, we assign it the value . Note that because and are chosen uniformly at random, given for does not yield information on whether or .
- Having scrambled the values of each wire, we still need a way to evaluate each gate. Recall that the behavior of a logic gate is entirely specified by its truth table. Thus, we prescribe a method for constructing a garbled truth table for each gate in our circuit. Consider a logic gate with input wires and output wire . As before, let be the bits carried by the wires , respectively. Then, let denote the operation of the logic gate, that is, . For notational convenience, we will write to denote , that is, the value of the wire if it is carrying bit . Then, let denote the operation of our garbled gate. One candidate definition for is to simply yield , that is the value of the output wire carrying the corresponding output bit:
Thus, we can simply construct a table mapping each assignment to the corresponding value . However, in the SFE setting, the circuit evaluator should only learn the value of that corresponds to his particular set of inputs and nothing else about the circuit. Given a fixed set of input bits, the evaluator should only be able to extract one set of intermediate and output values from the circuit. If both possible values of a given wire was known, the evaluator can evaluate the circuit using different intermediate states, and in doing so, potentially learn additional information about the hidden inputs to the circuit. We want the evaluator to obtain one of or depending on the value of . To do this, we treat as encryption keys and encrypt the value of using :
In the above, refers to the encryption of a message using key . In words, we successively encrypt the value of with keys . Observe that in this case, if we are given the input values , then we can look up in the truth table to obtain an encryption of with respect to keys . Since we have the keys , we can now decrypt this ciphertext to obtain . Moreover, because we only have the keys , we can only decrypt the ciphertext encrypting , and in particular, we are not able to learn any information about the other value of the output wire .
- For the output wires of the circuit, we set . Specifically, the value of an output wire carrying a given bit is just the value of the bit itself. Thus, when the evaluator decrypts the output wires on the circuit, he obtains the bits corresponding to the output of the circuit.
The above description is a bit abstract, so let’s consider a concrete example and construct the garbled equivalent of the AND gate from before. First, we assign values for each of the input and output wires. Let and for be the values corresponding to the two input wires. Let be the value corresponding to the output wire. Then, using our construction above, the truth table for the garbled AND gate will be the following:
|Input 1||Input 2||Output|
Observe that given the inputs, we are able to compute just a single output bit. In practice, we randomly permute the entries in the table, so the table does not leak any information about the computation performed by a given gate. This concludes the construction of a garbled circuit. What remains is to show how we can use these garbled circuits to perform SFE. Recall our previous setup: Alice and Bob each have an input and and would like to securely evaluate some function without revealing their private input. We arbitrarily designate Alice as the sender and Bob as the receiver. The protocol then proceeds as follows:
- Alice generates some secret key and constructs a garbled circuit for the function . Alice sends the garbled circuit along with her garbled inputs to Bob.
- Next, in order to evaluate the circuit, Bob needs to obtain the values corresponding to his input. However, since Alice constructed the circuit, only she knows what which values correspond to which bits. Thus, Bob must obtain the keys corresponding to his input from Alice, but without revealing to Alice the value of his input. We can accomplish this using a 1-out-of-2 oblivious transfer (OT) protocol. In 1-out-of-2 OT, Alice holds two keys and , and Bob holds a bit . At the end of the OT protocol, Bob learns the value of and Alice learns nothing. I will defer the discussion of 1-out-of-2 oblivious transfer protocols to a future post. For now, it is sufficient to assume that such a protocol exists. Then, for each bit of his input, Bob engages in a 1-out-of-2 OT protocol withe Alice to learn the value corresponding to his particular bit. In this way, for each of his input wires , Bob learns the value where is the value of that particular input bit.
- Since Bob now has all of the garbled inputs to , he evaluates and obtains the result . Thus, Bob learns the value of . He sends to Alice.
- Alice decrypts to obtain the result .
At the end of the above protocol, observe that Alice learns the value of and Bob learns the value of . Alice does not have access to the internal state of the garbled circuit (she does not evaluate ), so she does not learn any information about Bob’s input. From Bob’s perspective, the circuit is garbled, so Bob does not learn any information regarding Alice’s input. Finally, we note that while Bob learns , this does not leak any information about by semantic security of the underlying encryption scheme.
Note that the above protocol is only secure against honest-but-curious adversaries. In particular, we assume that Alice and Bob follow the protocol as described but may inspect the messages that are sent between them in order to learn something about the other’s input or response. In particular, we do not protect against malicious adversaries that may send malformed or malicious messages. Naturally, there are constructions that are secure even against malicious adversaries, but that’s a topic for a later time.
 Andrew Yao. Protocols for Secure Computations. FOCS 1982.