Review: Yao's Protocol

In the last lecture, we learned most parts of Yao's protocol.

The above picture shows what's going on when Yao's protocol is run. The garbled circuit and the key are not sanitized, but as we learned in the last lecture, they can be sanitized as follows:

Oblivious Transfer (OT)

What is left to cover the protocol for Oblivious Transfer. As is shown in the picture, the input and output of OT are as follows:
  • Input of Alice: Two messages \(m_0, m_1\).
  • Input of Bob: A selection bit \(\sigma\).
  • Output of Alice: None
  • Output of Bob: \(m_\sigma\), that is, the message chosen according to the selection bit \(\sigma\),

Security property of OT

An OT Protocol Extending the Diffie-Hellman Key Exchange

Review: Diffie-Hellman Key Exhange

Then the protocol proceeds as follows:

  1. Alice chooses a random exponent \(a\) from \(\{1, ..., p-1\}\), and computes \(A = g^a \bmod p\). Alice sends \(A\) to Bob.
  2. Bob also chooses a random exponent \(b\) from \(\{1, ..., p-1\}\), and computes \(B = g^b \bmod p\). Bob sends \(B\) to Alice.
The common secret key is computed as follows: Note that \(B^a = (g^b)^a = g^{ab}\), and \(A^b = (g^a)^b = g^{ab}\). Therefore, Alice and Bob will share the same key.

Extension Step 1: Prepare two different keys for sending \(m_0, m_1\)

We first extend the DH key exchange as follows:

Extension Step 2: Change \(B\) to consider Bob's selection bit \(\sigma\)

Overall, the protocol proceeds as follows:

Note:

Review Questions

TRUE/FALSE

  1. Bob creates a fresh random garbled circuit and evaluates it for privacy.
  2. For each bit of Bob's input, Alice must send a pair of wire keys so that Bob can evaluate the garbled circuit correctly.
  3. For each output wire of the circuit, two wire keys must be sent.

Inverse

  1. \(5^{-1} \bmod 13 = \)?

Oblivious Transfer

Use the following encryption scheme: \(Enc_k(m) = k \cdot m \bmod p\). For example, with p = 23, we have \(Enc_4(7) = 5\). Fill out the numbers. Note: Fill the space with actual numbers. If you use a symbol, you will get 0 point.
                                       p = 23, g = 2
Alice: [input m0 = 7, m1 = 8]                                     Bob: [input sel_bit = 1]                                        
(random) a = 3                                                    (random) b = 2
                                            ____
                                 -------------------------->      

                                            ____
                                 <-------------------------

 K0 = (   )^(   ) mod 23 = ____
                                     _____       _____
 K1 = (   )^(   ) mod 23 = ____  ------------------------->       K_ = (    )^(    ) mod 23 = ____
                                                                  m_ = ____
Refer to the following table for inverse values:
1^(-1) mod 23 =  1
2^(-1) mod 23 =  12
3^(-1) mod 23 =  8
4^(-1) mod 23 =  6
5^(-1) mod 23 =  14
6^(-1) mod 23 =  4
7^(-1) mod 23 =  10
8^(-1) mod 23 =  3
9^(-1) mod 23 =  18
10^(-1) mod 23 =  7
11^(-1) mod 23 =  21
12^(-1) mod 23 =  2
13^(-1) mod 23 =  16
14^(-1) mod 23 =  5
15^(-1) mod 23 =  20
16^(-1) mod 23 =  13
17^(-1) mod 23 =  19
18^(-1) mod 23 =  9
19^(-1) mod 23 =  17
20^(-1) mod 23 =  15
21^(-1) mod 23 =  11
22^(-1) mod 23 =  22
Answer: ans.txt

Activity

Download the starter code: ot_py.txt.

>>> from ot import *
>>> g = 2
>>> p = prime()
## Alice: sample key pair (as two input messages), send A
>>> keys = sample_wirekey_pair()
>>> (a, A) = sendA(g, p)

## Bob: Suppose input selection bit is 1. send B.
>>> sel_bit = 1
>>> (b, B) = sendB(g, p, A, sel_bit)

## Alice: Send two ciphertext c0 and c1 encrypting m0 and m1 respectively
>>> (c0, c1) = send_enc_messages(g, p, a, A, B, keys[0], keys[1])

## Bob: Decrypt two ciphertext. Since sel_bit is 1, the second decryption works.
>>> ot_output(g, p, A, b, c0, c1)
(b'm\x82\xac^\xd4Em\x90\t\xc82\xfe\x9a<\x1dh\xf7T\x08j\x04&\x83{l\xa9<}\x91\xec\x04\x8d', 
 b'wire key:  \x9fX\x84\x1a9\xb5\x9f\x9dH;\x88m\x9e\x06\xa5s\x01]\x0f\xb0\xcb')

## The decrytion indeed matches the second wirekey
>>> keys
[b'wire key:  \xca~\x16\x11\x00$\x9f\x0c\xac\xc2\xe5\xa5\x07\xeb]-\x9ce\xff\xd3\x96', 
 b'wire key:  \x9fX\x84\x1a9\xb5\x9f\x9dH;\x88m\x9e\x06\xa5s\x01]\x0f\xb0\xcb']