def bench_ipe(n, group_name, iter = 10, simulated = False, M = 1): setup_a = time.time() (pp, sk) = ipe.setup(n, group_name, simulated) setup_b = time.time() L = [] for index in range(iter): x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] keygen_a = time.time() skx = ipe.keygen(sk, x) keygen_b = time.time() encrypt_a = time.time() cty = ipe.encrypt(sk, y) encrypt_b = time.time() ctsize = get_ct_size(cty) decrypt_a = time.time() prod = ipe.decrypt(pp, skx, cty, M*M*n) decrypt_b = time.time() L.append((keygen_b - keygen_a, encrypt_b - encrypt_a, decrypt_b - decrypt_a, ctsize)) print("raw runtimes for each iteration: ", L) return (setup_b - setup_a, list_tuple_mean(L))
def bench_ipe(n, group_name, iter=10, simulated=False, M=1): setup_a = time.time() (pp, sk) = ipe.setup(n, group_name, simulated) setup_b = time.time() L = [] for index in range(iter): x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] keygen_a = time.time() skx = ipe.keygen(sk, x) keygen_b = time.time() encrypt_a = time.time() cty = ipe.encrypt(sk, y) encrypt_b = time.time() ctsize = get_ct_size(cty) decrypt_a = time.time() prod = ipe.decrypt(pp, skx, cty, M * M * n) decrypt_b = time.time() L.append((keygen_b - keygen_a, encrypt_b - encrypt_a, decrypt_b - decrypt_a, ctsize)) print("raw runtimes for each iteration: ", L) return (setup_b - setup_a, list_tuple_mean(L))
def ipe_decry_m(xvec,yvec,dev): (pp, sk) = ipe.setup(len(xvec)) skx = ipe.keygen(sk, xvec) cty = ipe.encrypt(sk, yvec) prod = ipe.decrypt(pp, skx, cty, M*M*n) m=prod/(len(xvec)*dev*dev) return m
def ipe_hamming(x, y): (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) print("the skx is:", skx) cty = ipe.encrypt(sk, y) print("the cty is:", cty) prod = ipe.decrypt(pp, skx, cty, M * M * n) print("<X',Y'> :", prod) return prod
def encryptR(sk, y): """ Performs the right-encrypt algorithm, where sk is the secret key and y is an integer in the range [0,n-1]. """ (n, f, sk_ipe) = sk assert y in range(n), "Input is outside of range" v = [f(i,y) for i in range(n)] cty = ipe.encrypt(sk_ipe, v) return cty
def test_ipe(): """ Runs a test on IPE for toy parameters. """ n = 10 M = 20 x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] checkprod = sum(map(lambda i: x[i] * y[i], range(n))) (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) cty = ipe.encrypt(sk, y) prod = ipe.decrypt(pp, skx, cty, M * M * n) assert prod == checkprod, "Failed test_ipe"
def test_ipe(): """ Runs a test on IPE for toy parameters. """ n = 10 M = 20 x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] checkprod = sum(map(lambda i: x[i] * y[i], range(n))) (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) cty = ipe.encrypt(sk, y) prod = ipe.decrypt(pp, skx, cty, M*M*n) assert prod == checkprod, "Failed test_ipe"
def test_ipe(): """ Runs a test on IPE for toy parameters. """ n = 10 M = 10 x = [random.randint(-M, M) for i in range(n)] print(x) y = [random.randint(-M, M) for i in range(n)] # checkprod = sum(map(lambda i: x[i] * y[i], range(n))) print(y) (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) cty = ipe.encrypt(sk, y) prod = ipe.decrypt(pp, skx, cty, M * M * n) print(prod)
def ipe_hamming(x,y): (pp, sk) = ipe.setup(n) keya=datetime.datetime.now() skx = ipe.keygen(sk, x) keyb=datetime.datetime.now() f.write(str(keyb-keya)+"---") #time 3 ena=datetime.datetime.now() cty = ipe.encrypt(sk, y) enb=datetime.datetime.now() f.write(str(enb-ena)+"---") dea=datetime.datetime.now() prod = ipe.decrypt(pp, skx, cty, M*M*n) deb=datetime.datetime.now() f.write(str(deb-dea)+"---") return prod
def ipe_decry_m(xvec, yvec, dev): (pp, sk) = ipe.setup(len(xvec)) kea = datetime.datetime.now() skx = ipe.keygen(sk, xvec) keb = datetime.datetime.now() f.write(str(keb - kea) + "---") # time ena = datetime.datetime.now() cty = ipe.encrypt(sk, yvec) enb = datetime.datetime.now() f.write(str(enb - ena) + "---") # time dea = datetime.datetime.now() prod = ipe.decrypt(pp, skx, cty, M * M * n) deb = datetime.datetime.now() f.write(str(deb - dea) + "---") # time m = prod / (len(xvec) * dev * dev) return m
def encrypt_polycoeffs(self, coeffs): return ipe.encrypt(self.sk, coeffs)
for j in i: des.append(j) print("x vectory is ", des) if select == 1: xarr = [] x = xvectory(des) for i in x: xarr.append(int(i)) skx = ipe.keygen(sk, xarr) ll = 0 tt = [] for i in xarr: ll += 1 tt.append(i) if ll / 10 == 0: print(tt) tt = [] print("x' vectory is ", xarr) if select == 2: yarr = [] y = yvectory(des) for i in y: yarr.append(int(i)) cty = ipe.encrypt(sk, yarr) print("y' vectory is ", yarr) prod = ipe.decrypt(pp, skx, cty, 10 * M * M * n) print(prod) print("--------------") print("the distance is :", math.sqrt(prod))