示例#1
0
def main():
    global group
    group = PairingGroup(secparam)

    userFuncs2.groupObj = group
    builtInFuncs.util = SecretUtil(group, verbose=False)

    attrs = ['ONE', 'TWO', 'THREE']
    access_policy = '((four or three) and (two or one))'
    print("Attributes =>", attrs)
    print("Policy =>", access_policy)

    (mk, pk) = setup()

    sk = keygen(pk, mk, attrs)
    print("sk :=>", sk)

    rand_msg = group.random(GT)
    print("msg =>", rand_msg)
    ct = encrypt(pk, rand_msg, access_policy)
    print("\nCiphertext...\n")
    group.debug(ct)

    rec_msg = decrypt(pk, sk, ct)
    print("\nDecrypt...\n")
    print("Rec msg =>", rec_msg)

    assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
    print("Successful Decryption!!!")
示例#2
0
def main():
    #Get the eliptic curve with the bilinear mapping feature needed.
    groupObj = PairingGroup('SS512')

    cpabe = CPabe09(groupObj)
    (msk, pk) = cpabe.setup()
    pol = '((ONE or THREE) and (TWO or FOUR))'
    attr_list = ['THREE', 'ONE', 'TWO']

    if debug: print('Acces Policy: %s' % pol)
    if debug: print('User credential list: %s' % attr_list)
    m = groupObj.random(GT)

    cpkey = cpabe.keygen(pk, msk, attr_list)
    if debug: print("\nSecret key: %s" % attr_list)
    if debug:groupObj.debug(cpkey)
    cipher = cpabe.encrypt(pk, m, pol)

    if debug: print("\nCiphertext...")
    if debug:groupObj.debug(cipher)
    orig_m = cpabe.decrypt(pk, cpkey, cipher)

    assert m == orig_m, 'FAILED Decryption!!!'
    if debug: print('Successful Decryption!')
    del groupObj
示例#3
0
def main():
    groupObj = PairingGroup('SS512')

    dabe = Dabe(groupObj)
    GP = dabe.setup()

    #Setup an authority
    auth_attrs= ['ONE', 'TWO', 'THREE', 'FOUR']
    (SK, PK) = dabe.authsetup(GP, auth_attrs)
    if debug: print("Authority SK")
    if debug: print(SK)

    #Setup a user and give him some keys
    gid, K = "bob", {}
    usr_attrs = ['THREE', 'ONE', 'TWO']
    for i in usr_attrs: dabe.keygen(GP, SK, i, gid, K)
    if debug: print('User credential list: %s' % usr_attrs)
    if debug: print("\nSecret key:")
    if debug: groupObj.debug(K)

    #Encrypt a random element in GT
    m = groupObj.random(GT)
    policy = '((one or three) and (TWO or FOUR))'
    if debug: print('Acces Policy: %s' % policy)
    CT = dabe.encrypt(PK, GP, m, policy)
    if debug: print("\nCiphertext...")
    if debug: groupObj.debug(CT)

    orig_m = dabe.decrypt(GP, K, CT)

    assert m == orig_m, 'FAILED Decryption!!!'
    if debug: print('Successful Decryption!')
def main():
    #Get the eliptic curve with the bilinear mapping feature needed.
    groupObj = PairingGroup('SS512')

    cpabe = CPabe09(groupObj)
    (msk, pk) = cpabe.setup()
    pol = '((ONE or THREE) and (TWO or FOUR))'
    attr_list = ['THREE', 'ONE', 'TWO']

    if debug: print('Acces Policy: %s' % pol)
    if debug: print('User credential list: %s' % attr_list)
    m = groupObj.random(GT)

    print('message:%s' % m)
    # individual's secret key (cpkey) is generated for each individual by AA using the individual's attribute list (attr_list)
    cpkey = cpabe.keygen(pk, msk, attr_list)
    if debug: print("\nSecret key: %s" % attr_list)
    if debug: groupObj.debug(cpkey)
    cipher = cpabe.encrypt(pk, m, pol)

    if debug: print("\nCiphertext...")
    if debug: groupObj.debug(cipher)
    orig_m = cpabe.decrypt(pk, cpkey, cipher)

    assert m == orig_m, 'FAILED Decryption!!!'
    if debug: print('Successful Decryption!')
    del groupObj
示例#5
0
def main():   
    groupObj = PairingGroup('SS512')

    cpabe = CPabe_BSW07(groupObj)
    attrs = ['ONE', 'TWO', 'THREE']
    access_policy = '((four or three) and (three or one))'
    if debug:
        print("Attributes =>", attrs); print("Policy =>", access_policy)

    (pk, mk) = cpabe.setup()

    sk = cpabe.keygen(pk, mk, attrs)
    print("sk :=>", sk)

    rand_msg = groupObj.random(GT)
    if debug: print("msg =>", rand_msg)
    ct = cpabe.encrypt(pk, rand_msg, access_policy)
    if debug: print("\n\nCiphertext...\n")
    groupObj.debug(ct)

    rec_msg = cpabe.decrypt(pk, sk, ct)
    if debug: print("\n\nDecrypt...\n")
    if debug: print("Rec msg =>", rec_msg)

    assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
    if debug: print("Successful Decryption!!!")
示例#6
0
def main(num=5):
	pol = generatePolicy(num)
	attr_list = generateAttrList(num)

	#Get the eliptic curve with the bilinear mapping feature needed.
	groupObj = PairingGroup('SS512')
	
	cpabe = RW13(groupObj)
	(msk, pk) = cpabe.setup()
	
	if debug: print('Acces Policy: %s' % pol)
	if debug: print('User credential list: %s' % attr_list)
	m = groupObj.random(GT)
	
	cpkey = cpabe.keygen(pk, msk, attr_list)
	if debug: print("\nSecret key: %s" % attr_list)
	if debug:groupObj.debug(cpkey)
	cipher = cpabe.encrypt(pk, m, pol)
	
	if debug: print("\nCiphertext...")
	if debug:groupObj.debug(cipher)
	orig_m = cpabe.decrypt(pk, cpkey, cipher)
	
	assert m == orig_m, 'FAILED Decryption!!!'
	if debug: print('Successful Decryption!')
	del groupObj
    def testCPabe_BSW07(self):
        groupObj = PairingGroup('SS512')

        cpabe = CPabe_BSW07(groupObj)
        attrs = ['ONE', 'TWO', 'THREE']
        access_policy = '((four or three) and (three or one))'
        if debug:
            print("Attributes =>", attrs)
            print("Policy =>", access_policy)

        (pk, mk) = cpabe.setup()

        sk = cpabe.keygen(pk, mk, attrs)

        rand_msg = groupObj.random(GT)
        if debug: print("msg =>", rand_msg)
        ct = cpabe.encrypt(pk, rand_msg, access_policy)
        if debug: print("\n\nCiphertext...\n")
        groupObj.debug(ct)

        rec_msg = cpabe.decrypt(pk, sk, ct)
        if debug: print("\n\nDecrypt...\n")
        if debug: print("Rec msg =>", rec_msg)

        assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
        if debug: print("Successful Decryption!!!")
示例#8
0
def main():
    groupObj = PairingGroup('SS512')

    cpabe = TrapAC(groupObj)
    attrs = ['ONE', 'TWO', 'THREE']
    access_policy = '((four AND two) OR (three AND one))'
    valid_attr = ['ONE', 'THREE']  # attribute in period time
    if debug:
        print("Attributes =>", attrs)
        print("Policy =>", access_policy)

    (pk, mk) = cpabe.setup()

    sk = cpabe.keygen(pk, mk, attrs)
    # print("sk :=>", sk)

    rand_msg = groupObj.random(GT)
    if debug: print("msg =>", rand_msg)
    ct = cpabe.encrypt(pk, rand_msg, access_policy)
    if debug: print("\n\nCiphertext...\n")
    groupObj.debug(ct)
    rect = cpabe.proxy_decrypt(pk, sk, ct, valid_attr)
    if debug: print("\n\nproxy_decrypt...\n")

    rec_msg = cpabe.decrypt(pk, sk, rect)
    if debug: print("\n\nDecrypt...\n")
    if debug: print("Rec msg =>", rec_msg)

    assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
    if debug: print("Successful Decryption!!!")
示例#9
0
def main():
    global group
    group = PairingGroup('SS512')

    attrs = ['ONE', 'TWO', 'THREE']
    access_policy = '((four or three) and (two or one))'
    #print("Attributes =>", attrs); print("Policy =>", access_policy)

    (mk, pk) = setup()

    sk = keygen(pk, mk, attrs)
    #print("sk :=>", sk)

    rand_msg = group.random(GT)
    print("msg =>", rand_msg)
    ct = encrypt(pk, rand_msg, access_policy)
    #print("\n\nCiphertext...\n")
    group.debug(ct)

    rec_msg = decrypt(pk, sk, ct)
    #print("\n\nDecrypt...\n")
    print("Rec msg =>", rec_msg)

    assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
    print("Successful Decryption!!!")
示例#10
0
    def testDabe(self):
        groupObj = PairingGroup('SS512')

        dabe = Dabe(groupObj)
        GP = dabe.setup()

        #Setup an authority
        auth_attrs = ['ONE', 'TWO', 'THREE', 'FOUR']
        (SK, PK) = dabe.authsetup(GP, auth_attrs)
        if debug: print("Authority SK")
        if debug: print(SK)

        #Setup a user and give him some keys
        gid, K = "bob", {}
        usr_attrs = ['THREE', 'ONE', 'TWO']
        for i in usr_attrs:
            dabe.keygen(GP, SK, i, gid, K)
        if debug: print('User credential list: %s' % usr_attrs)
        if debug: print("\nSecret key:")
        if debug: groupObj.debug(K)

        #Encrypt a random element in GT
        m = groupObj.random(GT)
        policy = '((one or three) and (TWO or FOUR))'
        if debug: print('Acces Policy: %s' % policy)
        CT = dabe.encrypt(PK, GP, m, policy)
        if debug: print("\nCiphertext...")
        if debug: groupObj.debug(CT)

        orig_m = dabe.decrypt(GP, K, CT)

        assert m == orig_m, 'FAILED Decryption!!!'
        if debug: print('Successful Decryption!')
示例#11
0
def main():
    global group
    group = PairingGroup(secparam)
    
    userFuncs2.groupObj = group
    builtInFuncs.util = SecretUtil(group, verbose=False)

    attrs = ['ONE', 'TWO', 'THREE']
    access_policy = '((four or three) and (two or one))'
    print("Attributes =>", attrs); print("Policy =>", access_policy)

    (mk, pk) = setup()

    sk = keygen(pk, mk, attrs)
    print("sk :=>", sk)

    rand_msg = group.random(GT)
    print("msg =>", rand_msg)
    ct = encrypt(pk, rand_msg, access_policy)
    print("\nCiphertext...\n")
    group.debug(ct)

    rec_msg = decrypt(pk, sk, ct)
    print("\nDecrypt...\n")
    print("Rec msg =>", rec_msg)

    assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
    print("Successful Decryption!!!")
示例#12
0
文件: bsw.py 项目: JHUISI/auto-tools
def main():
    global group
    group = PairingGroup("SS512")

    attrs = ["ONE", "TWO", "THREE"]
    access_policy = "((four or three) and (two or one))"
    # print("Attributes =>", attrs); print("Policy =>", access_policy)

    (mk, pk) = setup()

    sk = keygen(pk, mk, attrs)
    # print("sk :=>", sk)

    rand_msg = group.random(GT)
    print("msg =>", rand_msg)
    ct = encrypt(pk, rand_msg, access_policy)
    # print("\n\nCiphertext...\n")
    group.debug(ct)

    rec_msg = decrypt(pk, sk, ct)
    # print("\n\nDecrypt...\n")
    print("Rec msg =>", rec_msg)

    assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
    print("Successful Decryption!!!")
示例#13
0
def main():
    #Get the eliptic curve with the bilinear mapping feature needed.
    groupObj = PairingGroup('SS512')

    cpabe = CPabe_zjz(groupObj)
    (msk, pk) = cpabe.setup()
    pol = '(ONE or THREE) and (TWO or FOUR)'
    attr_list = ['THREE', 'ONE', 'TWO']

    if debug:
        print('Acces Policy: %s' % pol)
    if debug:
        print('User credential list: %s' % attr_list)
    m = groupObj.random(GT)
    m_ = groupObj.random(GT)

    if debug:
        print('message:>>', m)
        print('message for verification:>>', m_)

    cpkey = cpabe.keygen(pk, msk, attr_list)

    if debug:
        print("\nSecret key: %s" % attr_list)
    if debug:
        groupObj.debug(cpkey)

    cipher = cpabe.encrypt(pk, m, m_, pol)

    if debug:
        print("\nCiphertext...")
    if debug:
        groupObj.debug(cipher)

    orig_m = cpabe.decrypt(pk, cpkey, cipher)
    #assert m == orig_m, 'FAILED Decryption!!!'

    if debug:
        print('Successful Decryption!')

    tk, rk = cpabe.gen_tk_out(pk, cpkey)
    orig_m = cpabe.outsource(pk, cipher, tk, rk)
    assert m == orig_m, 'FAILED Decryption!!!'

    del groupObj
## START KEY GEN FOR USER & CS
pk_cs, sk_cs = cpabe.keygen_user(pk)
print("\ncloud key pair =>", (pk_cs, sk_cs))

pk_u, sk_u = cpabe.keygen_user(pk)
print("\nuser key pair =>", (pk_u, sk_u))

pxy_k_u = cpabe.keygen_proxy(pk, mk, pk_u, pk_cs, attrs)
print("\nproxy key =>", pxy_k_u)

rand_msg = groupObj.random(GT)
print("\nmsg =>", rand_msg)
ct = cpabe.encrypt(pk, rand_msg, access_policy)
print("\nEncrypt...\n", ct)
groupObj.debug(ct)

intmed_value = cpabe.proxy_decrypt(pk, sk_cs, pxy_k_u, ct)
print("\nPxy Decrypt...\n")
print("\nIntm msg =>", intmed_value)

rec_msg = cpabe.user_decrypt(pk, sk_u, intmed_value)
print("\nUser Decrypt...\n")
print("\nRec msg =>", rec_msg)

result = (rand_msg == rec_msg)

if result:
    print("\nSuccessful Decryption!!!")
else:
    print("\nFAILED Decryption: message is incorrect")
示例#15
0
    file_ct = symcrypt.encrypt(file_pt)

    print("Encryption finished...")
    print("LENGTH OF ENC FILE", len(file_ct))

    print("\n============ Encrypted Key =============\n")

    # ENCRYPT THE SYMM KEY BY USING CPABE PAIRING-BASED ALGO
    aes_key_pt = r
    print("AES key to be encrypted =>", aes_key_pt)

    aes_key_ct = cpabe.encrypt(cloud_pk, aes_key_pt, access_policy)
    print("\nEncrypt...\n", aes_key_ct)

    # DEBUG & VALIDATE THE CIPHER TEXT
    group.debug(aes_key_ct)

    print("\n=========== Pack Cipher File ============\n")

    print("Enc. Key", aes_key_ct)
    print("Enc. File", file_ct)

    # SERIALIZE ALL PAIRING ELEMENTS INTO STRINGS AND WRITE TO FILE
    aes_key_ct_serialized = ct_to_dict(aes_key_ct, group)
    aes_key_ct_printable = json.dumps(aes_key_ct_serialized)

    print(aes_key_ct_printable)

    outputFileObj = open(cipherFilename, 'w')
    outputFileObj.write(file_ct)
    outputFileObj.write("\n")
示例#16
0
def main():
    groupObj = PairingGroup('SS512')

    maabe = MAABE.MaabeRW15(groupObj)
    attrs1 = ['ONE', 'TWO']
    attrs2 = ['THREE', 'FOUR']

    access_policy = '((STUDENT@UT or PROFESSOR@OU) and (STUDENT@UT or MASTERS@OU))'
    if debug:
        print("attrs1 =>", attrs1)
        print("attrs2 =>", attrs2)
        print("Policy =>", access_policy)

    # setup
    public_parameters = maabe.setup()

    # authsetup 2AA
    (pk1, sk1) = maabe.authsetup(public_parameters, 'UT')
    (pk2, sk2) = maabe.authsetup(public_parameters, 'OU')
    maabepk = {'UT': pk1, 'OU': pk2}

    # keygen
    chamHash = chamwithemp.Chamwithemp()
    (pk, sk) = chamHash.keygen(1024)

    # keygen Bob
    gid = "bob"
    user_attr1 = ['STUDENT@UT']
    user_attr2 = ['STUDENT@OU']

    user_sk1 = maabe.multiple_attributes_keygen(public_parameters, sk1, gid,
                                                user_attr1)
    user_sk2 = maabe.multiple_attributes_keygen(public_parameters, sk2, gid,
                                                user_attr2)

    user_sk = {'GID': gid, 'keys': merge_dicts(user_sk1, user_sk2)}

    # hash
    msg = "Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for t"
    xi = chamHash.hash(pk, msg)
    etd = [xi['p1'], xi['q1']]
    if debug: print("Hash...")
    if debug: print("hash result =>", xi)

    # encrypt
    rand_key = groupObj.random(GT)
    if debug: print("msg =>", rand_key)
    #encrypt rand_key
    maabect = maabe.encrypt(public_parameters, maabepk, rand_key,
                            access_policy)
    #rand_key->symkey AE
    symcrypt = AuthenticatedCryptoAbstraction(extractor(rand_key))
    #symcrypt msg(etd=(p1,q1))
    etdtostr = [str(i) for i in etd]
    etdsumstr = etdtostr[0] + etdtostr[1]
    symct = symcrypt.encrypt(etdsumstr)

    ct = {'rkc': maabect, 'ec': symct}

    if debug: print("\n\nCiphertext...\n")
    groupObj.debug(ct)
    print("ciphertext:=>", ct)

    # decrypt
    #decrypt rand_key
    rec_key = maabe.decrypt(public_parameters, user_sk, maabect)
    assert rand_key == rec_key, "FAILED Decryption: random key is incorrect"
    #rec_key->symkey AE
    rec_symcrypt = AuthenticatedCryptoAbstraction(extractor(rec_key))
    #symdecrypt rec_etdsumstr
    rec_etdsumbytes = rec_symcrypt.decrypt(ct['ec'])
    rec_etdsumstr = str(rec_etdsumbytes, encoding="utf8")
    print("etdsumstr type=>", type(rec_etdsumstr))
    #sumstr->etd str list
    rec_etdtolist = cut_text(rec_etdsumstr, len(etdtostr[0]))
    print("rec_etdtolist=>", rec_etdtolist)
    #etd str list->etd integer list
    rec_etdint = [
        integer(int(rec_etdtolist[0])),
        integer(int(rec_etdtolist[1]))
    ]
    print("rec_etdint=>", rec_etdint)

    if debug: print("\n\nDecrypt...\n")
    if debug: print("Successful Decryption!!!")

    # collision
    msg1 = "Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for p"
    assert xi['p1'] == rec_etdint[
        0], "FAILED Decryption: etd key p1 is incorrect"
    assert xi['q1'] == rec_etdint[
        1], "FAILED Decryption: etd key q1 is incorrect"
    r1 = chamHash.collision(msg, msg1, xi, sk, pk)
    if debug: print("new randomness =>", r1)

    if debug: print("collision generated correctly!!!")