Path: blob/main/frontier/12-mpc/sage/12d-oblivious-transfer.ipynb
483 views
Notebook 12d: Oblivious Transfer
Module 12: Multi-Party Computation
Motivating Question. In Yao's garbled circuits, the evaluator (Bob) needs wire labels for his input bits, but the garbler (Alice) can't hand them over directly, because that would reveal both labels and thus the bit values. Can we design a protocol where Bob receives exactly one of two messages, Alice doesn't learn which one Bob chose, and Bob doesn't learn the other?
Prerequisites. You should be comfortable with:
Discrete logarithms and Diffie-Hellman (Module 05)
RSA encryption (Module 04)
Garbled circuits (Notebook 12c)
Learning objectives. By the end of this notebook you will be able to:
Define the ideal functionality of 1-of-2 Oblivious Transfer.
Implement a DH-based OT protocol from scratch.
Explain both sender privacy and receiver privacy.
Connect OT to Yao's garbled circuits as the missing building block.
Understand how OT extension makes millions of OTs practical.
1. The OT Ideal Functionality
Bridge from Notebook 12c. In garbled circuits, Alice garbles the circuit and sends it to Bob along with her input labels. But Bob still needs labels for his input wires. If Alice sends both labels for a wire, Bob learns both bit values. If Bob tells Alice which label he wants, Alice learns Bob's input. Oblivious Transfer solves this dilemma.
1-of-2 Oblivious Transfer involves two parties:
| Party | Holds | Learns |
|---|---|---|
| Sender | Two messages | Nothing about |
| Receiver | Choice bit | Only (nothing about ) |
With a trusted third party, this is trivial:
Checkpoint 1. Make sure you can state the two security properties: (1) sender privacy, the receiver learns nothing about ; (2) receiver privacy, the sender learns nothing about . Both must hold simultaneously.
2. Diffie-Hellman-Based OT
The key insight: in a Diffie-Hellman key exchange, two parties create a shared secret . We'll exploit this so the receiver can create a shared secret for one of two possible messages, but not both.
The Protocol
Public parameters: prime , generator of .
| Step | Who | Action |
|---|---|---|
| 1 | Sender | Pick random , publish |
| 2 | Receiver (bit ) | Pick random . If : send . If : send |
| 3 | Sender | Compute keys and . Encrypt |
| 4 | Receiver | Compute . Decrypt |
Why it works: Regardless of , the receiver can compute .
If : ✓
If : ✓
The receiver's key always matches exactly one of .
Step 1: Sender publishes
Step 2: Receiver's clever blinding trick
The receiver picks a random and sends either (if ) or (if ). Since is uniformly random, both cases produce a uniformly random group element, the sender cannot distinguish them.
Step 3: Sender computes both keys and encrypts
Step 4: Receiver decrypts the chosen message
Checkpoint 2. Trace through the case . Verify: and , so . Then verify (the receiver can't compute this without knowing ).
3. Complete OT Implementation
Let's package the protocol into clean functions and test exhaustively.
4. Security Analysis
Sender Privacy (Receiver learns only )
The receiver knows and their own . They can compute , which is the key for their chosen message.
To decrypt the other message, they would need:
If : need , which requires knowing
If : need , which requires knowing
Computing from is the discrete logarithm problem, hard by assumption.
Receiver Privacy (Sender learns nothing about )
The sender sees , which is either or . Since is uniformly random:
is uniformly distributed over the group
is also uniformly distributed (shifting by is a bijection)
Both distributions are identical, the sender gains zero information about .
Misconception alert. "The sender knows , so can't they check whether or ?" No! The sender doesn't know . They would have to try every possible , which is exhaustive search, equivalent to brute-forcing the discrete log.
5. RSA-Based OT
Bridge from Module 04. The first OT construction (Even, Goldreich, Lempel, 1985) used RSA rather than Diffie-Hellman. The RSA blinding trick hides the receiver's choice.
Protocol:
Sender generates RSA key and random values
Receiver picks random , computes
Sender computes for
Sender sends
Receiver recovers (since )
Checkpoint 3. In the RSA-based OT, why does ? Because by the RSA correctness property. The other key has no simple form without knowing .
6. OT Completes Yao's Protocol
Bridge from Notebook 12c. Remember Alice's garbled circuit: Bob needs one wire label per input wire, but Alice holds both labels. OT is exactly the right tool.
For each of Bob's input wires:
Alice (sender) offers for that wire
Bob (receiver) has his input bit
After OT: Bob gets , Alice doesn't learn
For a garbled circuit where Bob has input bits, we need independent OT executions.
| Application | Bob's input bits | OTs needed |
|---|---|---|
| 1-bit comparison | 1 | 1 |
| AES circuit | 128 | 128 |
| SHA-256 circuit | 256 | 256 |
| Millionaire's problem (32-bit) | 32 | 32 |
Public-key OT is expensive (~1 ms per instance). For large circuits, this becomes a bottleneck.
7. OT Extension
OT extension (Ishai, Kilian, Nissim, Petrank, 2003) is a remarkable result:
A small number of "base" OTs (using public-key crypto) can be extended to millions of OTs using only symmetric-key operations (hashing).
With base OTs (where is a security parameter, e.g., 128), we can perform an unlimited number of OTs:
| Base OT | Extended OT | |
|---|---|---|
| Crypto | Public-key (DH/RSA) | Symmetric (SHA-256) |
| Cost per OT | ~1 ms | ~1 μs |
| Number needed | (e.g., 128) | Unlimited |
This 1000× speedup is what makes garbled circuits practical for real-world secure computation.
Crypto foreshadowing. OT is not just for garbled circuits. In the next notebook, we'll see how the SPDZ protocol uses correlated OT to generate Beaver triples for multiplication, the same Beaver triples we met in Notebook 12b, but generated without any trusted dealer.
8. Exercises
Exercise 1 (Worked): Verify the Key Equations
Problem. Trace through the DH-based OT for both choice values. For each case, verify that exactly one of equals .
Solution:
Exercise 2 (Guided): String Transfer via OT
Problem. Use OT to transfer a multi-character string one character at a time. The sender holds two strings of equal length; the receiver picks one.
Hint: run one OT per character position, encoding each character as its ASCII value mod .
Exercise 3 (Independent): What if the Receiver Cheats?
Problem. What happens if a malicious receiver sends instead of the honest or ?
Compute what and become in this case.
Can the receiver decrypt either or ? Both? Neither?
What does this tell you about the security model of this OT protocol?
Summary
| Concept | Key Fact |
|---|---|
| OT ideal functionality | Receiver gets ; sender learns nothing about ; receiver learns nothing about |
| DH-based OT | Receiver sends or ; both are uniformly random |
| Sender privacy | Computing the other key requires solving the discrete log problem |
| Receiver privacy | is uniform regardless of choice, sender gains zero information |
| RSA-based OT | Blinding trick: hides the choice via RSA one-wayness |
| OT + garbled circuits | One OT per input wire gives Bob his labels without revealing his bits |
| OT extension | 128 base OTs → millions of OTs using only hashing |
Oblivious Transfer is one of the most fundamental primitives in cryptography. It is both necessary and sufficient for secure computation, any function can be computed securely given only OT as a building block.
Next: 12e: The SPDZ Protocol, achieving malicious security with MACs and Beaver triple preprocessing.