예제 #1
0
    def ot_alice(socket, msgs):
        """Oblivious transfer, Alice's side.

        Keyword arguments:
        socket -- socket for exchanges between A and B
        msgs   -- a pair (msg1, msg2) to suggest to Bob
        """
        # Create the prime group and send it to Bob
        G = util.PrimeGroup()
        socket.send_wait(G)

        # OT protocol based on
        # Nigel Smart’s "Cryptography Made Simple" implementation
        c = G.gen_pow(G.rand_int())
        h0 = socket.send_wait(c)
        h1 = G.mul(c, G.inv(h0))
        k = G.rand_int()
        c1 = G.gen_pow(k)
        e0 = util.xor_bytes(msgs[0], util.ot_hash(G.pow(h0, k), len(msgs[0])))
        e1 = util.xor_bytes(msgs[1], util.ot_hash(G.pow(h1, k), len(msgs[1])))
        socket.send((c1, e0, e1))
예제 #2
0
    def ot_garbler(self, msgs):
        """Oblivious transfer, Alice's side.

        Args:
            msgs: A pair (msg1, msg2) to suggest to Bob.
        """
        logging.debug("OT protocol started")
        G = util.PrimeGroup()
        self.socket.send_wait(G)

        # OT protocol based on Nigel Smart’s "Cryptography Made Simple"
        c = G.gen_pow(G.rand_int())
        h0 = self.socket.send_wait(c)
        h1 = G.mul(c, G.inv(h0))
        k = G.rand_int()
        c1 = G.gen_pow(k)
        e0 = util.xor_bytes(msgs[0], self.ot_hash(G.pow(h0, k), len(msgs[0])))
        e1 = util.xor_bytes(msgs[1], self.ot_hash(G.pow(h1, k), len(msgs[1])))

        self.socket.send((c1, e0, e1))
        logging.debug("OT protocol ended")
예제 #3
0
 def __init__(self,msg1,msg2):
     # sender generate a prime Group
     self.G_sender = util.PrimeGroup()
     # two message that needs to be sent
     self.msg1 = msg1
     self.msg2 = msg2
예제 #4
0
 def __init__(self, choice):
     # initialise the bob with his choice 
     self.G_rece = util.PrimeGroup()
     self.x = self.G_rece.primeM1
     self.choice = choice
예제 #5
0
class Alice:

    # message is the message that alice send to bob, t is the number of message that bob can learn
    def __init__(self):
        self.ClientSocket = util.ClientSocket

    def send(self, msg):
        self.ClientSocket.send(msg)

    def receive(self):
        self.ClientSocket.receive()


port = "5556"
context = zmq.Context()
socket = context.socket(zmq.PAIR)
socket.connect("tcp://localhost:%s" % port)
print('client alice connected')

while True:
    G_sender = util.PrimeGroup()
    c = G_sender.rand_int()
    print(type(c))
    print('c is ', c)
    socket.send(str(c).encode('utf8'))

    msg = socket.recv()
    print(msg.decode())

    time.sleep(1)
예제 #6
0
import time

port = "5556"
context = zmq.Context()
socket = context.socket(zmq.PAIR)
print('bob listening')
socket.bind("tcp://*:%s" % port)
print('server bob connected')

while True:

    msg = socket.recv()
    print(msg.decode())
    c = int(msg.decode())

    G_rece = util.PrimeGroup()
    x = G_rece.primeM1
    print(type(x))
    print('x is ', x)

    g = G_rece.find_generator()
    print(type(g))
    print('g is ', g)

    h_b = pow(g, x, 2)
    h_1b = c // h_b
    print(type(h_b), type(h_1b))
    print('h_b is ', h_b, 'h_1b is ', h_1b)
    # h0 (h_1b) is send to sender
    socket.send(str(h_1b).encode('utf8'))
예제 #7
0
 def __init__(self, b):   # b refers to which Bob selects
     self.b = b
     self.G = util.PrimeGroup()
     self.x = self.G.rand_int()
예제 #8
0
 def __init__(self, M):
     #  M responds to kb0 kb1   including m0,m1
     self.M = M
     self.G = util.PrimeGroup()
     k = self.G.rand_int()
     self.c = self.G.primeM1