def protocol(c, s, params): M = params['SETSIZE_C'] N = params['SETSIZE_S'] c.X = ModularVec(dim=M).input(src=driver, desc='X') s.Y = ModularVec(dim=N).input(src=driver, desc='Y') c.a = getPolyCoefficients()(c.X) c.ha = HomomorphicVec(val=c.a) s.ha <<= c.ha s.hbarY = HomomorphicVec(bitlen=1776, dim=N) for i in xrange(N): s.p = s.ha[M] for j in xrange(M - 1, -1, -1): s.p = s.p * s.Y[i] + s.ha[j] s.hbarY[i] = s.p * Modular().rand() + Homomorphic(val=s.Y[i]) c.hbarY <<= s.hbarY c.barY = ModularVec(val=c.hbarY) for e in xrange(M): if c.X[e] in c.barY: c.output(c.X[e], dest=driver, desc='X%d' % e)
def protocol(c, s): M = 100 # size of client's set N = 100 # size of server's set c.X = ModularVec(dim=M).input(desc="X") s.Y = ModularVec(dim=N).input(desc="Y") # interpolate coeffs of poly with roots c.X c.a = getPolyCoefficients()(c.X) # encrypt and send coefficients to server c.ha = HomomorphicVec(val=c.a) s.ha <<= c.ha # evaluate and rerandomize p(y_i) under enc s.hbarY = HomomorphicVec(dim=N) for i in xrange(N): # 0, ..., N-1 # eval poly using Horner scheme s.p = s.ha[M] for j in xrange(M-1,-1,-1): s.p = (s.p * s.Y[i]) + s.ha[j] s.hbarY[i] = s.p * Modular().rand() + \ Homomorphic(val=s.Y[i]) # send hbarY to client and decrypt c.hbarY <<= s.hbarY c.barY = ModularVec(val=c.hbarY) # compute intersection of c.X and c.barY for e in c.X: if e in c.barY: c.output(e, desc="in output set")
def protocol(c, s, params): M = params["SETSIZE_C"] N = params["SETSIZE_S"] c.X = ModularVec(dim=M).input(src=driver, desc="X") s.Y = ModularVec(dim=N).input(src=driver, desc="Y") # interpolate coefficients of poly with roots c.X c.a = getPolyCoefficients()(c.X) # encrypt and send coefficients to server c.ha = HomomorphicVec(val=c.a) s.ha <<= c.ha # evaluate and rerandomize p(y_i) under enc s.hbarY = HomomorphicVec(bitlen=1776, dim=N) for i in xrange(N): # 0, ..., N-1 # evaluate poly p under enc using Horner scheme s.p = s.ha[M] for j in xrange(M - 1, -1, -1): s.p = (s.p * s.Y[i]) + s.ha[j] s.hbarY[i] = s.p * Modular().rand() \ + Homomorphic(val=s.Y[i]) # send hbarY to client and decrypt c.hbarY <<= s.hbarY c.barY = ModularVec(val=c.hbarY) # compute intersection of c.X and c.barY for e in xrange(M): if c.X[e] in c.barY: c.output(c.X[e], dest=driver, desc="X%d" % e)
def protocol(c, s, params): c.X = ModularVec(dim=34, empty=True, signed=False, bitlen=1776).input(src=driver, desc='X') c.a = getPolyCoefficients()(c.X) c.ha = HomomorphicVec(val=c.a, signed=False, bitlen=1776, dim=[35]) conversions.PaillierVec_PaillierVec_send(c.ha, s.ha, 1776, [35], False) s.hbarY = HomomorphicVec(bitlen=1776, dim=20, signed=False, passive=True) conversions.PaillierVec_PaillierVec_receive(s.hbarY, c.hbarY, 1776, [20], False) c.barY = ModularVec(val=c.hbarY, signed=False, bitlen=1776, dim=[20]) for e in xrange(34): if c.X[e] in c.barY: c.output(c.X[e], dest=driver, desc='X%d' % e)
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))