import garbled_circuit import ot import sys import socket lsock = socket.socket() lsock.bind(("0.0.0.0",8000)) lsock.listen() (sock, addr) = lsock.accept() # recv from Alice: GC, outkey pair, Alice keys gcdata = sock.recv(5*4*32, socket.MSG_WAITALL) outkey_pair = sock.recv(2*32, socket.MSG_WAITALL) alice_keys = sock.recv(2*32, socket.MSG_WAITALL) # Bob's input from argv x = [int(sys.argv[1]), int(sys.argv[2])] # OT: get bob_keys g = 2 p = ot.prime() # 2048bit prime = 256 byte numbers A = [None]*2; B = [None]*2; b = [None]*2; bob_keys = [None]*2 for i in range(2): # receive A A[i] = sock.recv(256, socket.MSG_WAITALL) A[i] = int.from_bytes(A[i], 'big') # send B b[i], B[i] = ot.sendB(g, p, A[i], x[i]) sock.send( B[i].to_bytes(256, 'big')) # receive ciphertexts c0 = sock.recv(32, socket.MSG_WAITALL) c1 = sock.recv(32, socket.MSG_WAITALL) # get output bob_keys[i] = ot.ot_output(g, p, A[i], b[i], c0, c1)[x[i]] sock.close() # GC evaluation fin = open("tmp-inkeys.bin", "wb") fin.write(alice_keys) fin.write(bob_keys[0]+bob_keys[1]) fin.close() fout = open("tmp-outkeys.bin", "wb") fout.write(outkey_pair) fout.close() fgc = open("tmp-gc.bin", "wb") fgc.write(gcdata) fgc.close() garbled_circuit.eval("tmp")