Example #1
0
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))
Example #2
0
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))
Example #3
0
def decrypt(pp, ctx, cty):
  """
  Decrypts the two ciphertexts, which is equivalent to evaluating f(x,y), for 
  two ciphertexts ctx and cty.
  """
  
  pp_ipe = pp
  return ipe.decrypt(pp_ipe, ctx, cty)
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
Example #5
0
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
Example #6
0
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"
Example #7
0
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"
Example #8
0
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
Example #10
0
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
Example #11
0
    def search_enc(self, idx, token):
	    prod = ipe.decrypt(self.pp, token, idx, 1)
	    return True if prod == 0 else False
Example #12
0
            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))