def next_data_in(self): self.params = {"dim": 3, "lenX": 32, "lenY": 32} self.client_inputs = {"X": (1, 2, 3)} self.server_inputs = {"Y": (2, 3, 4)} self.result = 2 yield for i in xrange(10): self.params = { "dim": rand.randint(0, 100), "lenX": rand.randint(0, 512), "lenY": rand.randint(0, 512) } self.client_inputs = { "X": nogen( get_random(0, 2**self.params['lenX'] - 1, self.params["dim"])) } self.server_inputs = { "Y": nogen( get_random(0, 2**self.params['lenY'] - 1, self.params["dim"])) } self.result = min( map(lambda x: x[0] * x[1], zip(self.client_inputs["X"], self.server_inputs["Y"]))) yield
def __init__(self, party, num): self.party = party if __debug__: state.active_party.socket().sendobj(num) assert num == state.active_party.socket().recvobj( ), "number of ots not equal on server and client" if not num: self.__precomputed_b = self.__precomputed_m = utils.mdeque() return OT = state.config.ot_chain.pop(0) ot = OT(party) state.config.ot_chain.insert(0, OT) if party.role == party.CLIENT: self.__precomputed_b = b = utils.mdeque(utils.get_random( 0, 1, num)) ot(b) self.__precomputed_m = utils.mdeque(ot.get_results()) if len(self.__precomputed_b) != len(self.__precomputed_m): raise InternalError( "The partys do not agree on the number of ots to precompute" ) else: self.__precomputed_m = m = utils.mdeque( tuple( utils.get_random(0, ( 2**state.config.symmetric_security_parameter) - 1, 2)) for i in xrange(num)) ot(m) protocol.Protocol.run()
def next_data_in(self): self.params = {"SETSIZE_C": 3, "SETSIZE_S": 3} self.client_inputs = {"X": (1, 2, 3)} self.server_inputs = {"Y": (2, 3, 4)} self.intersection = set((2, 3)) yield for i in xrange(10): randset = nogen( get_random(1, 2**state.config.asymmetric_security_parameter - 1, 100)) self.count_C = rand.randint(1, 50) self.count_S = rand.randint(1, 50) self.params = { "SETSIZE_C": self.count_C, "SETSIZE_S": self.count_S } client_inputs = set(rand.sample(randset, self.count_C)) server_inputs = set(rand.sample(randset, self.count_S)) self.client_inputs = {"X": client_inputs} self.server_inputs = {"Y": server_inputs} self.intersection = client_inputs.intersection(server_inputs) yield
def test_garbled_primitives(self): for i in xrange(1,32): v = tuple(utils.get_random(0,1,i)) gzv = tuple(generate_garbled_value(i)) gv = tuple(plain2garbled(v, gzv, state.R)) nv = tuple(garbled2plain(gv, gzv, state.R)) self.assertEqual(v, nv)
def test_polynomialInterpolation(self): numberOfRoots = 20 roots = get_random(0, 2**1022 - 1, numberOfRoots) rootsM = [Modular(val=root) for root in roots] coeff = getPolyCoefficients(rootsM) # make sure, that we get the right number of coefficients self.assertEqual(len(coeff), numberOfRoots + 1) # if we evaluate the polynomial at the roots the results have to be 0 for rootM in rootsM: self.assertEqual(evalPoly(coeff, rootM), Modular(val=0)) # and if we chose other points than the roots, the evaluations mustn't be 0 notRoots = get_random(0, 2**1022 - 1, numberOfRoots) notRoots = [notRoot for notRoot in notRoots if notRoot not in roots] for notRoot in notRoots: self.assertNotEqual(evalPoly(coeff, Modular(val=notRoot)), Modular(val=0))
def server_1(self, args): gc.disable() s = list(utils.get_random(0, 1, self.k)) m = len(self.args) if m <= state.config.symmetric_security_parameter: # IKNP03 does not make sense if m <= symmetric_security_parameter # Use the subot directly then. self.subot.forward() self.subot(self.args) return None self.subot(s) tmp = [utils.value2bits(res, m) for res in self.subot.get_results()] Q = zip(*tmp) # transpose tmp del tmp si = utils.bits2value(s) q = [utils.bits2value(j) for j in Q] cost_results.CostSystem.costs["theoretical"]["setup"]["accumulated"]( Send=2 * utils.bit2byte(state.config.symmetric_security_parameter) * m) gc.enable() return (((xj0 ^ self.H(j, qj)).binary(), (xj1 ^ self.H(j, qj ^ si)).binary()) for (j, qj), (xj0, xj1) in zip(enumerate(q), self.args))
def generate_test_data_for_iteration(self): if self.iterations: self.client_inputs = nogen(get_random(1, 2**32 - 1, 2)) self.server_inputs = tuple() self.params = {} self.iterations -= 1 else: self.params = None
def random(self, bitlen, signed, num=1): if signed: start, end = -(2**(bitlen - 1)), 2**(bitlen - 1) - 1 else: start, end = 0, 2**bitlen - 1 if num > 1: return list(get_random(start, end, num)) else: return rand.randint(start, end)
def next_data_in(self): self.params = {"la": 32, "lb": 32, "da": 8, "db": 8} self.inputs = {"a": 8 * (0, ), "b": rand.randint(1, 2**31 - 1)} yield self.inputs = {"b": 0, "a": nogen(get_random(1, 2**31 - 1, 8))} yield self.inputs = {"a": 8 * (0, ), "b": 0} yield self.inputs = {"a": 8 * (2**31 - 1, ), "b": 2**31 - 1} yield for i in xrange(self.COUNT): da = rand.randint(1, self.MAXDIM) db = rand.randint(1, self.MAXDIM) la = rand.randint(2, self.MAXBITLEN) lb = rand.randint(2, self.MAXBITLEN) self.params = {'la': la, 'lb': lb, 'da': da, 'db': db} self.inputs = { 'a': tuple(get_random(1, max(1, (2**(la - 1)) - 1), da)), 'b': rand.randint(1, max(1, (2**(lb - 1)) - 1)) } yield
def test_tastyot(self): """ testing the global TastyOT """ # state.config.ot_chain = [paillierot.PaillierOT] n = 128 # must be even self.ot = t = OTTest(n) x = tuple(utils.get_random(0, 1, n / 2)) y = tuple(utils.get_random(0, 1, n / 2)) xc = [tuple(utils.get_random(0, 2**80 - 1, 2)) for i in xrange(n / 2)] yc = [tuple(utils.get_random(0, 2**80 - 1, 2)) for i in xrange(n / 2)] resultx = tuple(map(lambda x: mpz(x[0][x[1]]), zip(xc, x))) resulty = tuple(map(lambda x: mpz(x[0][x[1]]), zip(yc, y))) res = t.next_ots(x, xc)[1] self.assertEqual(res, resultx) res2 = t.next_ots(y, yc)[1] self.assertEqual(res2, resulty)
def next_data_in(self): for i in xrange(self.COUNT): da = rand.randint(1, self.MAXDIM) db = rand.randint(1, self.MAXDIM) la = rand.randint(1, self.MAXBITLEN) lb = rand.randint(1, self.MAXBITLEN) self.params = {'la': la, 'lb': lb, 'da': da, 'db': db} self.inputs = { 'a': tuple(get_random(1, (2**la) - 1, da)), 'b': rand.randint(1, (2**lb) - 1) } yield
def test_ot_protocol_performance(self): """ testing available OT protocols """ # for security_level, ot_type in product(("short","medium","long"), ("Paillier","EC_c","EC")): for security_level, ot_type in product(("short", "medium", "long"), ("EC_c", "EC")): print security_level, ot_type, start_time = time.clock() #protocols = [ECNaorPinkasOT.NP_EC_OT_secp192r1, ECNaorPinkasOT.NP_EC_OT_secp192r1_c, \ # ECNaorPinkasOT.NP_EC_OT_secp224r1, ECNaorPinkasOT.NP_EC_OT_secp224r1_c, \ # ECNaorPinkasOT.NP_EC_OT_secp256r1, ECNaorPinkasOT.NP_EC_OT_secp256r1_c] #protocols = state.config.ot_chain n = state.config.symmetric_security_parameter # for prot in protocols: # print prot.__name__ # state.config.ot_chain = [prot] self.ot = t = OTTest(n) x = tuple(utils.get_random(0, 1, n / 2)) y = tuple(utils.get_random(0, 1, n / 2)) xc = [ tuple(utils.get_random(0, 2**n - 1, 2)) for i in xrange(n / 2) ] # n-bit messages yc = [ tuple(utils.get_random(0, 2**n - 1, 2)) for i in xrange(n / 2) ] # n-bit messages resultx = tuple(map(lambda x: mpz(x[0][x[1]]), zip(xc, x))) resulty = tuple(map(lambda x: mpz(x[0][x[1]]), zip(yc, y))) res = t.next_ots(x, xc)[1] self.assertEqual(res, resultx) res2 = t.next_ots(y, yc)[1] self.assertEqual(res2, resulty) print "%fs" % (time.clock() - start_time)
def get_random(self, maxbits, num, innum=0): if self.SIGNED[innum]: return nogen( get_random(-2**(maxbit - 1) - 1, 2**(maxbit - 1) - 1, num)) else: return nogen(get_random(0, 2**(maxbit) - 1, num))
def generate_garbled_value(length): return imap( mpz, utils.get_random( 0, 2**(state.config.symmetric_security_parameter + 1) - 1, length))