Shayan 4 rokov pred
rodič
commit
37f5ce2e5e

+ 69 - 69
oracle.py → OLD/oracle.py

@@ -1,70 +1,70 @@
-#!/usr/bin/python
-import socket
-import _thread
-import time
-import socket
-import os
-import random
-from padra import padra
-
-
-LenFunc = 4
-padra = padra(LenFunc)
-
-
-HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
-socketPort = int(random.random()*5000+1024)
-def broadcast():
-    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-    sock.bind(("", 6666))
-    while True:
-        msg, addr = sock.recvfrom(1024)
-        sock.sendto(bytes(str(socketPort),'utf-8'),addr)
-
-
-connectedUser = []
-
-def listen():
-    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
-        s.bind((HOST, socketPort))
-        s.listen()
-        while True:
-            conn, addr = s.accept()
-            u = _thread.start_new_thread( user, (conn, addr))
-            connectedUser.append((addr,u))
-
-
-
-
-class user():
-    def __init__(self,connection,address):
-        self.conn = connection
-        self.addr = address
-        self.history = []
-        _thread.start_new_thread( self.receive, ())
-        self.send("Connected")
-
-    def send(self,Message):
-        Message=bytes(Message,'utf-8')
-        self.conn.sendall(Message)
-        self.history.append(("send",Message))
-
-    def receive(self):
-        while True: 
-            len = self.conn.recv(LenFunc)
-            if not len:
-                break
-            data = self.conn.recv(int(len))
-            padra.parse(data.decode("utf-8"))
-            self.history.append(("receive",data))
-
-
-try:
-   _thread.start_new_thread( broadcast, ())
-   _thread.start_new_thread( listen, ())
-except:
-   print ("Error: unable to start thread")
-
-while 1:
+#!/usr/bin/python
+import socket
+import _thread
+import time
+import socket
+import os
+import random
+from padra import padra
+
+
+LenFunc = 4
+padra = padra(LenFunc)
+
+
+HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
+socketPort = int(random.random()*5000+1024)
+def broadcast():
+    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    sock.bind(("", 6666))
+    while True:
+        msg, addr = sock.recvfrom(1024)
+        sock.sendto(bytes(str(socketPort),'utf-8'),addr)
+
+
+connectedUser = []
+
+def listen():
+    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
+        s.bind((HOST, socketPort))
+        s.listen()
+        while True:
+            conn, addr = s.accept()
+            u = _thread.start_new_thread( user, (conn, addr))
+            connectedUser.append((addr,u))
+
+
+
+
+class user():
+    def __init__(self,connection,address):
+        self.conn = connection
+        self.addr = address
+        self.history = []
+        _thread.start_new_thread( self.receive, ())
+        self.send("Connected")
+
+    def send(self,Message):
+        Message=bytes(Message,'utf-8')
+        self.conn.sendall(Message)
+        self.history.append(("send",Message))
+
+    def receive(self):
+        while True: 
+            len = self.conn.recv(LenFunc)
+            if not len:
+                break
+            data = self.conn.recv(int(len))
+            padra.parse(data.decode("utf-8"))
+            self.history.append(("receive",data))
+
+
+try:
+   _thread.start_new_thread( broadcast, ())
+   _thread.start_new_thread( listen, ())
+except:
+   print ("Error: unable to start thread")
+
+while 1:
    pass

+ 140 - 140
padra.py → OLD/padra.py

@@ -1,140 +1,140 @@
-import json
-import os
-import time
-
-class padra():
-    def __init__(self,len):
-        self.len = len
-        print("added",self.len)
-
-    def toSend(self,x):
-        j = json.dumps(x)
-        l = self.len - len(str(len(j)))
-        return "0000"[0:l]+str(len(j))+j
-
-    def toJson(self,x):
-        print( x)
-        return json.loads(x)
-
-
-    # user
-
-
-    def xor(self,o,key,data):
-        print("startetd")
-        o0data= {
-            "function":"xor",
-            "players_number":"3",
-            "player":"0",
-            "ip":"192.168.178.105",
-            "data":"",
-
-        }
-        o[0].send(self.toSend(o0data))
-        o1data= {
-            "function":"xor",
-            "players_number":"3",
-            "player":"1",
-            "ip":"192.168.178.105",
-            "data":key,
-
-        }
-        o[1].send(self.toSend(o1data))
-        o2data= {
-            "function":"xor",
-            "players_number":"3",
-            "player":"2",
-            "ip":"192.168.178.105",
-            "data":data
-        }
-        o[2].send(self.toSend(o2data))
-
-    def aes(self,o,key,data):
-        print("startetd")
-        o0data= {
-            "function":"aes",
-            "players_number":"3",
-            "player":"0",
-            "ip":"192.168.178.105",
-            "data":"",
-
-        }
-        o[0].send(self.toSend(o0data))
-        o1data= {
-            "function":"aes",
-            "players_number":"3",
-            "player":"1",
-            "ip":"192.168.178.105",
-            "data":key,
-
-        }
-        o[1].send(self.toSend(o1data))
-        o2data= {
-            "function":"aes",
-            "players_number":"3",
-            "player":"2",
-            "ip":"192.168.178.105",
-            "data":data
-        }
-        o[2].send(self.toSend(o2data))
-        print("Data send from USER")
-    
-    # oracle
-    def parse(self,message):
-        data = json.loads(message)
-        print(data)
-        function = data["function"]
-        if(function == "aes"):
-            self.aesOracle(data["players_number"],data["player"],data["ip"],data["data"])
-        elif(function == "xor"):
-            self.xorOracle(data["players_number"],data["player"],data["ip"],data["data"])
-
-
-    def aesOracle(self,players_number,player,ip,data):
-        player=int(player)
-        players_number=int(players_number)
-        time.sleep(player*10)
-        line = " "
-        t1= "echo "+ data + " > gf2n_vals.in"
-        t2= "./gen_input_f2n.x"
-        t3= "mv ./gf2n_vals.out ./Player-Data/Private-Input-"+str(player)
-        t4= "./mascot-party.x "+str(player)+" aes_m -pn 12598 -h "+ip+" -N "+str(players_number)
-        handle = (os.system("ls"))
-        print (handle)
-        handle = (os.system("cd .."))
-        print (handle)
-        handle = (os.system("ls"))
-        print (handle)
-        handle = (os.system(t1))
-        print (line)
-        handle = (os.system(t2))
-        print (line)
-        handle = (os.system(t3))
-        print (line)
-        handle = (os.system(t4))
-        print (line)
-    
-    def xorOracle(self,players_number,player,ip,data):
-        player=int(player)
-        print(player)
-        players_number=int(players_number)
-        time.sleep(player*10)
-        line = " "
-        if player != 0:
-            t1= "echo 1 "+ data + " > gf2n_vals.in"
-            handle = (os.system(t1))
-            print (line)
-        if player != 0:
-            handle = (os.system("./gen_input_f2n.x"))
-            print (line)
-        if player != 0:
-            handle = (os.system("mv ./gf2n_vals.out ./Player-Data/Private-Input-"+str(player)))
-            print (line)
-
-
-        print("player " + str(player) )
-        t4= "./mascot-party.x "+str(player)+" xor -pn 12598 -h "+ip+" -N "+str(players_number)
-        
-        handle = (os.system(t4))
-        print (line)
-
+import json
+import os
+import time
+
+class padra():
+    def __init__(self,len):
+        self.len = len
+        print("added",self.len)
+
+    def toSend(self,x):
+        j = json.dumps(x)
+        l = self.len - len(str(len(j)))
+        return "0000"[0:l]+str(len(j))+j
+
+    def toJson(self,x):
+        print( x)
+        return json.loads(x)
+
+
+    # user
+
+
+    def xor(self,o,key,data):
+        print("startetd")
+        o0data= {
+            "function":"xor",
+            "players_number":"3",
+            "player":"0",
+            "ip":"192.168.178.105",
+            "data":"",
+
+        }
+        o[0].send(self.toSend(o0data))
+        o1data= {
+            "function":"xor",
+            "players_number":"3",
+            "player":"1",
+            "ip":"192.168.178.105",
+            "data":key,
+
+        }
+        o[1].send(self.toSend(o1data))
+        o2data= {
+            "function":"xor",
+            "players_number":"3",
+            "player":"2",
+            "ip":"192.168.178.105",
+            "data":data
+        }
+        o[2].send(self.toSend(o2data))
+
+    def aes(self,o,key,data):
+        print("startetd")
+        o0data= {
+            "function":"aes",
+            "players_number":"3",
+            "player":"0",
+            "ip":"192.168.178.105",
+            "data":"",
+
+        }
+        o[0].send(self.toSend(o0data))
+        o1data= {
+            "function":"aes",
+            "players_number":"3",
+            "player":"1",
+            "ip":"192.168.178.105",
+            "data":key,
+
+        }
+        o[1].send(self.toSend(o1data))
+        o2data= {
+            "function":"aes",
+            "players_number":"3",
+            "player":"2",
+            "ip":"192.168.178.105",
+            "data":data
+        }
+        o[2].send(self.toSend(o2data))
+        print("Data send from USER")
+    
+    # oracle
+    def parse(self,message):
+        data = json.loads(message)
+        print(data)
+        function = data["function"]
+        if(function == "aes"):
+            self.aesOracle(data["players_number"],data["player"],data["ip"],data["data"])
+        elif(function == "xor"):
+            self.xorOracle(data["players_number"],data["player"],data["ip"],data["data"])
+
+
+    def aesOracle(self,players_number,player,ip,data):
+        player=int(player)
+        players_number=int(players_number)
+        time.sleep(player*10)
+        line = " "
+        t1= "echo "+ data + " > gf2n_vals.in"
+        t2= "./gen_input_f2n.x"
+        t3= "mv ./gf2n_vals.out ./Player-Data/Private-Input-"+str(player)
+        t4= "./mascot-party.x "+str(player)+" aes_m -pn 12598 -h "+ip+" -N "+str(players_number)
+        handle = (os.system("ls"))
+        print (handle)
+        handle = (os.system("cd .."))
+        print (handle)
+        handle = (os.system("ls"))
+        print (handle)
+        handle = (os.system(t1))
+        print (line)
+        handle = (os.system(t2))
+        print (line)
+        handle = (os.system(t3))
+        print (line)
+        handle = (os.system(t4))
+        print (line)
+    
+    def xorOracle(self,players_number,player,ip,data):
+        player=int(player)
+        print(player)
+        players_number=int(players_number)
+        time.sleep(player*10)
+        line = " "
+        if player != 0:
+            t1= "echo 1 "+ data + " > gf2n_vals.in"
+            handle = (os.system(t1))
+            print (line)
+        if player != 0:
+            handle = (os.system("./gen_input_f2n.x"))
+            print (line)
+        if player != 0:
+            handle = (os.system("mv ./gf2n_vals.out ./Player-Data/Private-Input-"+str(player)))
+            print (line)
+
+
+        print("player " + str(player) )
+        t4= "./mascot-party.x "+str(player)+" xor -pn 12598 -h "+ip+" -N "+str(players_number)
+        
+        handle = (os.system(t4))
+        print (line)
+

+ 89 - 89
user.py → OLD/user.py

@@ -1,90 +1,90 @@
-#!/usr/bin/python
-import socket
-import _thread
-import time
-import json
-from padra import padra
-import threading
-
-LenFunc = 4
-
-padra = padra(LenFunc)
-NumberOfOracles = 3
-listOfAll = []
-def broadcast():
-    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-    msg = bytes("Message: ",'utf-8')
-    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
-    sock.sendto(msg, ("255.255.255.255", 6666))
-    while 1:
-        m = sock.recvfrom(1024)
-        listOfAll.append(((m[1][0]),str(int(m[0]))))
-        print(listOfAll)
-
-
-    
-
-connectedOracles = []
-def connection():
-    while len(listOfAll)<NumberOfOracles: pass
-    for _ in listOfAll: 
-        if len(connectedOracles) < NumberOfOracles:
-            o = oracle(None,None,None,None,"127.0.0.1",int(_[1]))
-            o.start()
-            connectedOracles.append(o)
-    print(connectedOracles)
-    time.sleep(2)
-    print(connectedOracles)
-    padra.xor(connectedOracles,"11111111111111111111111111223344",
-    "11111111111111111111111111223341")
-
-
-
-class oracle(threading.Thread):
-
-    def __init__(self, group, target, name,
-                 verbose,HOST,PORT):
-
-        super(oracle,self).__init__(group, target, 
-			              name, verbose)
-        print(HOST,PORT)
-        self.port = PORT
-        self.Host = HOST
-        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
-            s.connect((HOST, PORT))
-            data = s.recv(1024)
-        ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        print(ss)
-        ss.connect((HOST,PORT))
-        self.s = ss
-        self.history = []
-        _thread.start_new_thread( self.receive, ())
-
-        def run(self):
-            # logging.debug('running')
-            return
-
-# 4 char = len of data +  data
-    def send(self,Message):
-        Message=bytes(Message,'utf-8')
-        self.s.sendall(Message)
-        self.history.append(("send",Message))
-        print("Send",Message)
-
-    def receive(self):
-        while True:
-            data = self.s.recv(1024)
-            if not len:
-                break 
-            self.history.append(("receive",data))
-            print("receive",data)
-
-
-
-try:
-    _thread.start_new_thread( broadcast, ())
-    _thread.start_new_thread( connection, ())
-except:
-   print ("Error: unable to start thread")
-while 1:
+#!/usr/bin/python
+import socket
+import _thread
+import time
+import json
+from padra import padra
+import threading
+
+LenFunc = 4
+
+padra = padra(LenFunc)
+NumberOfOracles = 3
+listOfAll = []
+def broadcast():
+    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    msg = bytes("Message: ",'utf-8')
+    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+    sock.sendto(msg, ("255.255.255.255", 6666))
+    while 1:
+        m = sock.recvfrom(1024)
+        listOfAll.append(((m[1][0]),str(int(m[0]))))
+        print(listOfAll)
+
+
+    
+
+connectedOracles = []
+def connection():
+    while len(listOfAll)<NumberOfOracles: pass
+    for _ in listOfAll: 
+        if len(connectedOracles) < NumberOfOracles:
+            o = oracle(None,None,None,None,"127.0.0.1",int(_[1]))
+            o.start()
+            connectedOracles.append(o)
+    print(connectedOracles)
+    time.sleep(2)
+    print(connectedOracles)
+    padra.xor(connectedOracles,"11111111111111111111111111223344",
+    "11111111111111111111111111223341")
+
+
+
+class oracle(threading.Thread):
+
+    def __init__(self, group, target, name,
+                 verbose,HOST,PORT):
+
+        super(oracle,self).__init__(group, target, 
+			              name, verbose)
+        print(HOST,PORT)
+        self.port = PORT
+        self.Host = HOST
+        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
+            s.connect((HOST, PORT))
+            data = s.recv(1024)
+        ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        print(ss)
+        ss.connect((HOST,PORT))
+        self.s = ss
+        self.history = []
+        _thread.start_new_thread( self.receive, ())
+
+        def run(self):
+            # logging.debug('running')
+            return
+
+# 4 char = len of data +  data
+    def send(self,Message):
+        Message=bytes(Message,'utf-8')
+        self.s.sendall(Message)
+        self.history.append(("send",Message))
+        print("Send",Message)
+
+    def receive(self):
+        while True:
+            data = self.s.recv(1024)
+            if not len:
+                break 
+            self.history.append(("receive",data))
+            print("receive",data)
+
+
+
+try:
+    _thread.start_new_thread( broadcast, ())
+    _thread.start_new_thread( connection, ())
+except:
+   print ("Error: unable to start thread")
+while 1:
     pass

+ 0 - 0
connection/broadcastClient.py


+ 0 - 0
connection/broadcastServer.py


+ 0 - 0
socketClient.py → connection/socketClient.py


+ 0 - 0
connection/socketServer.py


+ 0 - 0
aes_m.mpc → mpc/aes_m.mpc


+ 7 - 7
xor.mpc → mpc/xor.mpc

@@ -1,8 +1,8 @@
-
-
-
-def init():
-	p1 = sgf2n.get_raw_input_from(1)
-	p2 = sgf2n.get_raw_input_from(2)
-	print_ln('%s',p1.__xor__(p2).reveal())
+
+
+
+def init():
+	p1 = sgf2n.get_raw_input_from(1)
+	p2 = sgf2n.get_raw_input_from(2)
+	print_ln('%s',p1.__xor__(p2).reveal())
 init()

+ 0 - 0
tls/aes_gcm.py