示例#1
0
文件: bench.py 项目: kevinlewi/fhipe
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))
示例#2
0
文件: bench.py 项目: zpleefly/fhipe
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))
示例#3
0
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
示例#4
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
示例#5
0
文件: tife.py 项目: zpleefly/fhipe
def setup(n, f, group_name = 'MNT159', simulated = False):
  """
  Performs the two-input functional encryption setup algorithm, where n is the 
  plaintext space size, f is a function which takes two inputs, and group_name 
  is the name of the pairing group to use.
  """

  (pp_ipe, sk_ipe) = ipe.setup(n, group_name, simulated)
  pp = pp_ipe
  sk = (n, f, sk_ipe)
  return (pp, sk)
示例#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"
示例#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"
示例#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
示例#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
示例#11
0
文件: ipe_wrap.py 项目: z6shang/OSSE
    def init_para(self):
        # if the parameter already generated and stored
        # then return .
        if os.path.isfile(self.sk_dump_path): return 

        # the vector to be encrypted has length 303
        (self.pp, self.sk) = ipe.setup(self.vec_len, simulated = False)
        (detB, B, Bstar, group, g1, g2) = self.sk 
        self.group = group 

        def deparse_B(M):
            new_M = []
            for i in range(len(M)):
                new_M.append([])
                for j in range(len(M[i])):
                    new_M[i].append( self.group_serial( M[i][j]) )
            return new_M

        sk_dump = { 'detB':detB, 'B': deparse_B(B), 'Bstar': deparse_B(Bstar),\
            'group':'MNT159', 'g1': self.group_serial(g1), 'g2': self.group_serial(g2)	}
        
        with open(self.sk_dump_path, 'w') as fd:
            json.dump( sk_dump, fd )
示例#12
0
        at.append(-2 * i)
    at.append(1)
    return at


def yvectory(b):
    bn = 0
    for i in b:
        bn += i * i
    b.append(bn)
    b.insert(0, 1)
    return b


if __name__ == '__main__':
    (pp, sk) = ipe.setup(n + 2)
    inorout = 2  #int(input("please input the number of vertor:"))
    for i in range(inorout):
        des = []
        select = int(input("please input the data your want 1 or 2 :"))
        d = load(select)
        f = pca(d)
        lowdata = display(select)
        for i in lowdata.tolist():
            for j in i:
                des.append(j)
        print("x vectory is ", des)
        if select == 1:
            xarr = []
            x = xvectory(des)
            for i in x: