Beispiel #1
0
def main():
    group = PairingGroup('SS512')
    waters_hash = Waters(group)
    ibe = IBE_N04(group)
    (master_public_key, master_key) = ibe.setup()

    ID = "*****@*****.**"
    kID = waters_hash.hash(ID)
    secret_key = ibe.extract(master_key, kID)
    msg = group.random(GT)
    cipher_text = ibe.encrypt(master_public_key, kID, msg)
    decrypted_msg = ibe.decrypt(master_public_key, secret_key, cipher_text)
    assert msg == decrypted_msg, "invalid decryption"
    if debug: print("Successful Decryption!")
Beispiel #2
0
def main():
    group = PairingGroup('SS512')
    waters_hash = Waters(group)
    ibe = IBE_N04(group)
    (master_public_key, master_key) = ibe.setup()

    ID = "*****@*****.**"
    kID = waters_hash.hash(ID)
    secret_key = ibe.extract(master_key, kID)
    msg = group.random(GT)
    cipher_text = ibe.encrypt(master_public_key, kID, msg)
    decrypted_msg = ibe.decrypt(master_public_key, secret_key, cipher_text)
    assert msg == decrypted_msg, "invalid decryption"
    if debug: print("Successful Decryption!")
 def keygen(self, l=32):
     '''l is the security parameter
     with l = 32, and the hash function at 160 bits = n * l with n = 5'''
     global waters
     sha1_func, sha1_len = 'sha1', 20
     g = group.random(G2)      # generator for group G of prime order p
     
     hLen = sha1_len * 8
     n = int(math.floor(hLen / l))
     waters = Waters(group, n, l, sha1_func)
     
     alpha = group.random(ZR)  #from Zp
     g2    = g ** alpha      
     g1    = group.random(G1)   
     u = group.random(ZR)
     uprime = g ** u
     U_z = [group.random(ZR) for x in range(n)]
     U = [g ** x  for x in U_z]
     
     pk = {'g':g, 'g1':g1, 'g2': g2, 'uPrime':uprime, 'U': U,
           'n':n, 'l':l, 'egg': pair(g1, g2) }
     
     # mk = pk.copy()
     #mk = {'g':g, 'g1':g1, 'g2': g2, 'uPrime':uprime, 'U': U, 
     #      'n':n, 'l':l, 'egg': pair(g, g2) ** alpha }
     mk = {'g1^alpha':g1 ** alpha, 'U_z':U_z, 'u':u} #master secret
     if debug: 
         print(mk)
     
     return (pk, mk)
Beispiel #4
0
 def setup(self, n=5, l=32):
     """n integers with each size l"""
     global lam_func, waters
     lam_func = lambda i, x, y: x[i]**y[i]
     waters = Waters(group, n, l)
     alpha, t1, t2, t3, t4 = group.random(ZR, 5)
     z = list(group.random(ZR, n))
     g = group.random(G1)
     h = group.random(G2)
     omega = pair(g, h)**(t1 * t2 * alpha)
     g_l = [g**i for i in z]
     h_l = [h**i for i in z]
     v1, v2 = g**t1, g**t2
     v3, v4 = g**t3, g**t4
     msk = {'alpha': alpha, 't1': t1, 't2': t2, 't3': t3, 't4': t4}
     mpk = {
         'omega': omega,
         'g': g,
         'h': h,
         'g_l': g_l,
         'h_l': h_l,
         'v1': v1,
         'v2': v2,
         'v3': v3,
         'v4': v4,
         'n': n,
         'l': l
     }
     return (mpk, msk)
Beispiel #5
0
    def setup(self, l=32):
        """l is the security parameter
        with l = 32, and the hash function at 256 bits = n * l with n = 8"""
        global waters
        g = group.random(G1)      # generator for group G of prime order p

        sha2_byte_len = 32
        hLen = sha2_byte_len * 8
        n = int(math.floor(hLen / l))
        waters = Waters(group, n, l, 'sha256')
                
        alpha = group.random()  #from Zp
        g1    = g ** alpha      # G1
        g2    = group.random(G2)    #G2
        uprime = group.random(G2)
        U = [group.random() for x in range(n)]
        
        pk = {'g':g, 'g1':g1, 'g2': g2, 'uPrime':uprime, 'U': U, 
              'n':n, 'l':l}
        
        mk = pk.copy()
        mk['g2^alpha'] = g2 ** alpha #master secret
        if debug: 
            print(mk)
        
        return (pk, mk)
Beispiel #6
0
    def setup(self, z, l=32):
        global waters
        waters = Waters(group, z, l)
        alpha, h = group.random(ZR), group.random(G1)
        g1, g2 = group.random(G1), group.random(G2)
        A = pair(h, g2)**alpha
        y = [group.random(ZR) for i in range(z)]
        y1t, y2t = group.random(ZR), group.random(ZR)

        u1t = g1**y1t
        u2t = g1**y2t
        u = [g1**y[i] for i in range(z)]

        u1b = g2**y1t
        u2b = g2**y2t
        ub = [g2**y[i] for i in range(z)]

        msk = h**alpha
        mpk = {
            'g1': g1,
            'g2': g2,
            'A': A,
            'u1t': u1t,
            'u2t': u2t,
            'u': u,
            'u1b': u1b,
            'u2b': u2b,
            'ub': ub,
            'z': z,
            'l': l
        }
        return (mpk, msk)
def main():
    groupObj = PairingGroup('SS512')
    ibe = IBE_N04_Sig_z(groupObj)
    waters = Waters(group)
    (pk, sk) = ibe.keygen()

    # represents public identity
    M = "*****@*****.**"
    msg = waters.hash("This is a test.")    
    sig = ibe.sign(pk, sk, msg)
    if debug:
        print("original msg => '%s'" % M)
        print("msg => '%s'" % msg)
        print("sig => '%s'" % sig)

    assert ibe.verify(pk, msg, sig), "Failed verification!"
    if debug: print("Successful Verification!!! msg => '%s'" % msg)
Beispiel #8
0
 def __init__(self, groupObj):
     IBEnc.__init__(self)
     #IBEnc.setProperty(self, secdef='IND_ID_CPA', assumption='DBDH', secmodel='Standard')
     #, other={'id':ZR}
     #message_space=[GT, 'KEM']
     global group
     group = groupObj
     global waters_hash
     waters_hash = Waters(group)
Beispiel #9
0
 def extract(self, level, mpk, mk, ID):
     j = level
     assert j >= 1 and j <= mpk['l'], "invalid level: 1 - %d" % mpk['l']
     I = Waters(group, j, mpk['z']).hash(ID)
     r = [group.random(ZR) for i in range(j)]
     g_b = [mpk['gb']**r[i] for i in range(j)]
     hashID = mk['g0b'] * dotprod2(range(j), hash_func, mpk['g1b'], I,
                                   mpk['hb'], r)
     return {'ID': ID, 'j': j}, {'d0': hashID, 'dn': g_b}
Beispiel #10
0
    def encrypt(self, mpk, pk, M):
        I = Waters(group, pk['j'], mpk['z']).hash(pk['ID'])
        s = group.random(ZR)
        A = M * (mpk['v']**s)
        B = mpk['g']**s
        C = {}
        for i in range(pk['j']):
            C[i] = ((mpk['g1']**I[i]) * mpk['h'][i])**s

        return {'A': A, 'B': B, 'C': C, 'j': pk['j']}
Beispiel #11
0
    def testIBE_N04_Sig(self):
        # initialize the element object so that object references have global scope
        groupObj = PairingGroup('SS512')
        waters = Waters(groupObj)
        ibe = IBE_N04_Sig(groupObj)
        (pk, sk) = ibe.keygen()

        # represents public identity
        M = "*****@*****.**"

        msg = waters.hash(M)
        sig = ibe.sign(pk, sk, msg)
        if debug:
            print("original msg => '%s'" % M)
            print("msg => '%s'" % msg)
            print("sig => '%s'" % sig)

        assert ibe.verify(pk, msg, sig), "Failed verification!"
        if debug: print("Successful Verification!!! msg => '%s'" % msg)
Beispiel #12
0
    def derive(self, mpk, pk):
        j = pk['j']  # pk[j-1]
        assert pk['j'] + 1 <= mpk['l'], "invalid level: 1 - %d" % mpk['l']
        I = Waters(group, j, mpk['z']).hash(pk['ID'])

        r = [group.random(ZR) for i in range(j)]
        g_b = [pk['dn'][i] * (mpk['gb']**r[i]) for i in range(j)]  # j-1
        g_b.append(pk['gb']**r[j])  # represents j
        hashID = dID['d0'] * dotprod2(range(j + 1), hash_func, mpk['g1b'], I,
                                      mpk['hb'], r)
        return {'ID': ID, 'j': j}, {'d0': hashID, 'dn': g_b}
    def testIBE_N04(self):
        # initialize the element object so that object references have global scope
        groupObj = PairingGroup('SS512')
        waters = Waters(groupObj)
        ibe = IBE_N04(groupObj)
        (pk, mk) = ibe.setup()

        # represents public identity
        ID = "*****@*****.**"
        kID = waters.hash(ID)
        # if debug: print("Bob's key  =>", kID)
        key = ibe.extract(mk, kID)

        M = groupObj.random(GT)
        cipher = ibe.encrypt(pk, kID, M)
        m = ibe.decrypt(pk, key, cipher)
        # print('m    =>', m)

        assert m == M, "FAILED Decryption!"
        if debug: print("Successful Decryption!!! m => '%s'" % m)
        del groupObj
Beispiel #14
0
    def testIBE_N04(self):
        # initialize the element object so that object references have global scope
        groupObj = PairingGroup('SS512')
        waters = Waters(groupObj)
        ibe = IBE_N04(groupObj)
        (pk, mk) = ibe.setup()

        # represents public identity
        ID = "*****@*****.**"
        kID = waters.hash(ID)
        #if debug: print("Bob's key  =>", kID)
        key = ibe.extract(mk, kID)

        M = groupObj.random(GT)
        cipher = ibe.encrypt(pk, kID, M)
        m = ibe.decrypt(pk, key, cipher)
        #print('m    =>', m)

        assert m == M, "FAILED Decryption!"
        if debug: print("Successful Decryption!!! m => '%s'" % m)
        del groupObj
    def setup(self, l=32):
        '''l is the security parameter
        with l = 32, and the hash function at 160 bits = n * l with n = 5'''
        global waters
        sha1_func, sha1_len = 'sha1', 20
        g = group.random(G1)  # generator for group G of prime order p
        ##
        ##        timer = 0.0
        ##        startTime = time.time()
        ##        k = group.random(ZR)
        ##        timer += time.time() - startTime
        ##        print("average time %f ms" %(timer*1000))

        hLen = sha1_len * 8
        n = int(math.floor(hLen / l))
        waters = Waters(group, n, l, sha1_func)

        alpha = group.random(ZR)  #from Zp
        g1 = g**alpha  # G1
        g2 = group.random(G2)  #G2
        u = group.random(ZR)
        uprime = g**u
        U_z = [group.random(ZR) for x in range(n)]  # in Z_p
        U = [g**x for x in U_z]  # in G_1

        pk = {
            'g': g,
            'g1': g1,
            'g2': g2,
            'uPrime': uprime,
            'U': U,
            'n': n,
            'l': l,
            'eg1g2': pair(g1, g2)
        }
        #print("U[0]:",U[0])

        #mk = pk.copy()
        mk = {'g2^alpha': g2**alpha, 'U_z': U_z, 'u': u}  #master secret
        if debug:
            print(mk)

        return (pk, mk)
Beispiel #16
0
    def setup(self, l=32):
        '''l is the security parameter
        with l = 32, and the hash function at 160 bits = n * l with n = 5'''
        global waters
        g = group.random(G1)  # generator for group G of prime order p

        sha2_byte_len = 32
        hLen = sha2_byte_len * 8
        n = int(math.floor(hLen / l))
        waters = Waters(group, n, l, 'sha256')

        alpha = group.random(ZR)  #from Zp
        g1 = g**alpha  # G1
        g2 = group.random(G2)  #G2
        u = group.random(ZR)
        uprime = g**u
        U_z = [group.random(ZR) for x in range(n)]
        U = [g**x for x in U_z]

        pk = {
            'g': g,
            'g1': g1,
            'g2': g2,
            'uPrime': uprime,
            'U': U,
            'n': n,
            'l': l,
            'eg1g2': pair(g1, g2)
        }

        mk = {
            'g1': g1,
            'g2': g2,
            'n': n,
            'g2^alpha': g2**alpha,
            'U_z': U_z,
            'u': u
        }  #master secret
        if debug:
            print(mk)

        return (pk, mk)
Beispiel #17
0
        assert bls.verify(pk, sig, m), "Failure!!!"
        cllwwVerifyTime += time.time() - startTime
    print("Bls04: Keygen %d times, average time %f ms" %
          (n, cllwwKeyGenTime / n * 1000))
    print("Bls04: Sign random message %d times, average time %f ms" %
          (n, cllwwSignTime / n * 1000))
    print("Bls04: Verify %d times, average time %f ms" %
          (n, cllwwVerifyTime / n * 1000))
    print("&%.2f () &%.2f () &%.2f ()" %
          (cllwwKeyGenTime / n * 1000, cllwwSignTime / n * 1000,
           cllwwVerifyTime / n * 1000))
#groupObj = PairingGroup('MNT159')
#groupObj = PairingGroup('SS512')
if (1):
    ibe = IBE_N04_Sig(groupObj)
    waters = Waters(groupObj)
    msg = waters.hash("This is a test.")
    cllwwKeyGenTime = 0.0
    cllwwSignTime = 0.0
    cllwwVerifyTime = 0.0
    for i in range(0, n):
        startTime = time.time()
        (pk, sk) = ibe.keygen()
        cllwwKeyGenTime += time.time() - startTime

        msg = waters.hash(randomStringGen())
        startTime = time.time()
        sig = ibe.sign(pk, sk, msg)
        cllwwSignTime += time.time() - startTime

        startTime = time.time()
##    IBE_RevokeEncTime += time.time() - startTime
##    
##    startTime = time.time()
##    decrypted_msg = ibe.decrypt(S, cipher_text, secret_key)
##    IBE_RevokeDecTime += time.time() - startTime
##print("\nAllison Lewko, Amit Sahai and Brent Waters, Revocation Systems with Very Small Private Keys")
###print("Group: SS512")
##print("IBE_Revoke: Extract %d times, average time %f ms" %(n, IBE_RevokeExtTime/n*1000))
##print("IBE_Revoke: Enc random message %d times, average time %f ms" %(n, IBE_RevokeEncTime/n*1000))
##print("IBE_Revoke: Dec %d times, average time %f ms" %(n, IBE_RevokeDecTime/n*1000))


#group = PairingGroup('SS512')
#group = PairingGroup('MNT224')
if(1):
    waters_hash = Waters(group)
    ibe = IBE_N04(group)
    IBE_N04SetupTime = 0.0
    IBE_N04ExtTime = 0.0
    IBE_N04EncTime = 0.0
    IBE_N04DecTime = 0.0
    for i in range(0, n):
        startTime = time.time()
        (master_public_key, master_key) = ibe.setup()
        IBE_N04SetupTime += time.time() - startTime
        
        ID = randomStringGen() 
        kID = waters_hash.hash(ID)
        startTime = time.time()
        secret_key = ibe.extract(master_key, kID)
        IBE_N04ExtTime += time.time() - startTime
Beispiel #19
0
##    cipher_text = ibe.encrypt(master_public_key, msg, S)
##    IBE_RevokeEncTime += time.time() - startTime
##
##    startTime = time.time()
##    decrypted_msg = ibe.decrypt(S, cipher_text, secret_key)
##    IBE_RevokeDecTime += time.time() - startTime
##print("\nAllison Lewko, Amit Sahai and Brent Waters, Revocation Systems with Very Small Private Keys")
###print("Group: SS512")
##print("IBE_Revoke: Extract %d times, average time %f ms" %(n, IBE_RevokeExtTime/n*1000))
##print("IBE_Revoke: Enc random message %d times, average time %f ms" %(n, IBE_RevokeEncTime/n*1000))
##print("IBE_Revoke: Dec %d times, average time %f ms" %(n, IBE_RevokeDecTime/n*1000))

#group = PairingGroup('SS512')
#group = PairingGroup('MNT224')
if (1):
    waters_hash = Waters(group)
    ibe = IBE_N04(group)
    IBE_N04SetupTime = 0.0
    IBE_N04ExtTime = 0.0
    IBE_N04EncTime = 0.0
    IBE_N04DecTime = 0.0
    for i in range(0, n):
        startTime = time.time()
        (master_public_key, master_key) = ibe.setup()
        IBE_N04SetupTime += time.time() - startTime

        ID = randomStringGen()
        kID = waters_hash.hash(ID)
        startTime = time.time()
        secret_key = ibe.extract(master_key, kID)
        IBE_N04ExtTime += time.time() - startTime
Beispiel #20
0
from charm.core.crypto.cryptobase import *
from charm.toolbox.hash_module import Waters
from charm.schemes.ibenc.ibenc_waters09 import DSE09

import time
import string
import random

def randomStringGen(size=10, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for x in range(size))

b = 1000
group = PairingGroup('SS512')
#group = PairingGroup('/home/zfwise/Downloads/pbc-0.5.12/param/f.param', param_file=True)
global waters_hash
waters_hash = Waters(group)

za = group.random()
zb = group.random()
g = group.random(G1)
h = group.random(G1)
i = group.random(G1)
j = group.random(G2)
k = group.random(G2)
m = group.random(G2)
n = group.random(ZR)
o = group.random(GT)
x = group.random(GT)
y = group.random(GT)
G1add = 0.0
G1sub = 0.0
        cllwwSignTime += time.time() - startTime

        startTime = time.time()
        assert bls.verify(pk, sig, m), "Failure!!!"
        cllwwVerifyTime += time.time() - startTime
    print("Bls04: Keygen %d times, average time %f ms" %(n, cllwwKeyGenTime/n*1000))
    print("Bls04: Sign random message %d times, average time %f ms" %(n, cllwwSignTime/n*1000))
    print("Bls04: Verify %d times, average time %f ms" %(n, cllwwVerifyTime/n*1000))
    print("&%.2f () &%.2f () &%.2f ()" %(cllwwKeyGenTime/n*1000,
                                         cllwwSignTime/n*1000,
                                         cllwwVerifyTime/n*1000))
#groupObj = PairingGroup('MNT159')
#groupObj = PairingGroup('SS512')
if(1):
    ibe = IBE_N04_Sig(groupObj)
    waters = Waters(groupObj)
    msg = waters.hash("This is a test.")  
    cllwwKeyGenTime = 0.0
    cllwwSignTime = 0.0
    cllwwVerifyTime = 0.0
    for i in range(0, n):
        startTime = time.time()
        (pk, sk) = ibe.keygen()
        cllwwKeyGenTime += time.time() - startTime

        msg = waters.hash(randomStringGen()) 
        startTime = time.time()
        sig = ibe.sign(pk, sk, msg) 
        cllwwSignTime += time.time() - startTime

        startTime = time.time()
 def __init__(self, groupObj, z, l=32):
     global group, lam_func
     global waters
     group = groupObj
     waters = Waters(group, z, l)
     lam_func = lambda i, a, b: a[i]**b[i]