当前位置: 首页>>代码示例>>Python>>正文


Python PairingGroup.random方法代码示例

本文整理汇总了Python中charm.toolbox.pairinggroup.PairingGroup.random方法的典型用法代码示例。如果您正苦于以下问题:Python PairingGroup.random方法的具体用法?Python PairingGroup.random怎么用?Python PairingGroup.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在charm.toolbox.pairinggroup.PairingGroup的用法示例。


在下文中一共展示了PairingGroup.random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testPairing

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
    def testPairing(self):    
        trials = 10
        trials2 = trials * 3 
        group = PairingGroup("SS512")
        g = group.random(G1)
        h = group.random(G1)
        i = group.random(G2)

        self.assertTrue(group.InitBenchmark())
        group.StartBenchmark(["RealTime", "Exp", "Pair"])
        for a in range(trials):
            j = g * h 
            k = i ** group.random(ZR)
            t = (j ** group.random(ZR)) / h 
            n = pair(h, i)
        group.EndBenchmark()
       
        msmtDict = group.GetGeneralBenchmarks()
        self.assertTrue(isSaneBenchmark(msmtDict))        

        self.assertTrue(group.InitBenchmark())
        
        group.StartBenchmark(["CpuTime", "Mul", "Pair"])
        for a in range(trials2):
            j = g * h 
            k = i ** group.random(ZR)
            n = pair(h, i)
        group.EndBenchmark()
        
        msmtDict = group.GetGeneralBenchmarks()
        del group
        self.assertTrue(isSaneBenchmark(msmtDict))        
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:34,代码来源:benchmark_test.py

示例2: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
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!!!")
开发者ID:JHUISI,项目名称:auto-tools,代码行数:27,代码来源:bsw.py

示例3: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
def main():
    global group
    group = PairingGroup("SS512")

    alphabet = {'a', 'b'}
    dfa = DFA("ab*a", alphabet)
    dfaM = dfa.constructDFA()

    fe = FE_DFA(group, dfa)

    (mpk, msk) = fe.setup(alphabet)
    if debug: print("mpk :=>", mpk, "\n\n")

    sk = fe.keygen(mpk, msk, dfaM)
    if debug: print("sk :=>", sk)

    w = dfa.getSymbols("abba")
    w1 = dfa.getSymbols("aba")
    M = group.random(GT)
    ct = fe.encrypt(mpk, w, M)

    # Explicitly override the string with another valid string
    ct[1] = w1
    print w1 == w

    origM = fe.decrypt(sk, ct)
    assert M == origM, "failed decryption!"
    if debug: print("Successful Decryption!!!!!")
开发者ID:chris-wood,项目名称:dfa-fe,代码行数:30,代码来源:dfa_fe12.py

示例4: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
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!!!")
开发者ID:JHUISI,项目名称:auto-tools,代码行数:30,代码来源:bsw07_asym_ky.py

示例5: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
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!')
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:34,代码来源:dabe_aw11.py

示例6: testIBE_BB04

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
    def testIBE_BB04(self):
        # initialize the element object so that object references have global scope
        groupObj = PairingGroup('MNT224')
        ibe = IBE_BB04(groupObj)
        (params, mk) = ibe.setup()

        # represents public identity
        kID = groupObj.random(ZR)
        key = ibe.extract(mk, kID)

        M = groupObj.random(GT)
        cipher = ibe.encrypt(params, kID, M)
        m = ibe.decrypt(params, key, cipher)

        assert m == M, "FAILED Decryption!"
        if debug: print("Successful Decryption!! M => '%s'" % m)
开发者ID:FinalF,项目名称:charm,代码行数:18,代码来源:ibenc_test.py

示例7: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
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
开发者ID:CryptoStore,项目名称:charm-example,代码行数:28,代码来源:abenc_rw13.py

示例8: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
def main():
    global group
    group = PairingGroup(secparam)

    alphabet = ['a', 'b']
    dfa = DFA("ab*a", alphabet)
    builtinFuncs_dfa.DFAObj = dfa
    dfaM = dfa.constructDFA()

    (mpk, msk) = setup(alphabet)

    (blindingFactor0Blinded, skBlinded) = keygen(mpk, msk, dfaM)
    w = dfa.getSymbols("abba")
    M = group.random(GT)
    print("M :", M)
    ct = encrypt(mpk, w, M)

    transformOutputList = transform(skBlinded, ct)
    origM = decout(skBlinded, ct, transformOutputList, blindingFactor0Blinded, blindingFactorKendList1Blinded)



    print("rec M :", origM)
    assert M == origM, "failed decryption"
    print("SUCCESSFUL DECRYPTION!!!") 
开发者ID:JHUISI,项目名称:auto-tools,代码行数:27,代码来源:dfa.py

示例9: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
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!!!")
开发者ID:FinalF,项目名称:charm,代码行数:28,代码来源:abenc_bsw07.py

示例10: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
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
开发者ID:FinalF,项目名称:charm,代码行数:27,代码来源:abenc_waters09.py

示例11: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
def main():
    global group
    #group = PairingGroup(secparam)
    group = PairingGroup("SS512")

    alphabet = ['a', 'b']
    dfa = DFA("ab*a", alphabet)
    builtinFuncs_dfa.DFAObj = dfa
    dfaM = dfa.constructDFA()

    (mpk, msk) = setup(alphabet)

    Q, S, T, q0, F = dfaM

    (blindingFactor0Blinded, skBlinded) = keygen(mpk, msk, Q, T, F)
    w = dfa.getSymbols("abbba")
    M = group.random(GT)
    print("M :", M)
    ct = encrypt(mpk, w, M)

    (transformOutputList, l, Ti, transformOutputListForLoop) = transform(skBlinded, ct, dfaM)
    origM = decout(dfaM, transformOutputList, blindingFactor0Blinded, l, Ti, transformOutputListForLoop)


    print("rec M :", origM)
    assert M == origM, "failed decryption"
    print("SUCCESSFUL DECRYPTION!!!") 
开发者ID:JHUISI,项目名称:auto-tools,代码行数:29,代码来源:forAyoDFA.py

示例12: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
def main():
	global benchmarkResult, options

	options=parse_args()

	# SS512 : a symmertic curve with a 512-bit base field
	# MNT159 : an asymmetric curve with a 159-bit based field
	groupObj = PairingGroup ('SS512')
	generator = groupObj.random(G1)
	# for optimization 
	assert generator.initPP(), "failed to init pre-computation table"

	# initialize key server and user objects
	ks = KS (groupObj, generator)
	user = User (groupObj, generator)

	# set up key server
	pk=ks.setup()

	if options.output_file is not None:
		rf=open(options.output_file, "w")
	else:
		rf=sys.stdout
	rf.write ("#KB\tN.KS\tN.kss\tD1\tD2\tHash\tSE\tGroup\tKS\tTo.\tTo.(CR)\tTo.(SE)\n")

	sys.stderr.write ("Run experiment...\n")

	if options.file_size > 0:
		file_size=[options.file_size]

	for fsize in file_size:
		# generate sample file
		create_file (sample_file, fsize)

		benchmarkResult={}
		for count in range (0,options.trials, 1):
			# compute a hash for a file
			h=user.computeHash(sample_file)

			# generate tag and decryption key
			t_F, dk_F = user.generate_key_and_tag(pk, h, ks)
		
			# encrypt a file
			C1,C2,C3=user.encrypt (t_F,pk,sample_file,h)


		delay_Hash=round(benchmarkResult['Hash']*1000/options.trials,2)
		delay_SE=round(benchmarkResult['SE']*1000/options.trials,2)
		delay_Group=round(benchmarkResult['Group']*1000/options.trials,2)
		delay_KS=round(benchmarkResult['KS']*1000/options.trials,2)
		delay_total=round(delay_Hash+delay_SE+delay_Group+delay_KS,2)
		delay_total_cr=round(delay_Hash+delay_Group+delay_KS,2)
		delay_total_SE=delay_SE

		rf.write("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}\n".format(\
			int(fsize/1024), options.num_of_KS, options.num_of_kss, options.KS_delay1, options.KS_delay2,\
			delay_Hash, delay_SE, delay_Group, delay_KS,delay_total,delay_total_cr,delay_total_SE))
			
	rf.close()
开发者ID:syoungjoo,项目名称:fogpaper,代码行数:61,代码来源:proposed.py

示例13: MsgTestAESCBCSeperate

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
 def MsgTestAESCBCSeperate(self,msg):
     groupObj = PairingGroup('SS512')
     ran = groupObj.random(GT)
     a =  AuthenticatedCryptoAbstraction(sha1(ran))
     ct = a.encrypt(msg)        
     b =  AuthenticatedCryptoAbstraction(sha1(ran))
     dmsg = b.decrypt(ct);
     assert msg == dmsg , 'o: =>%s\nm: =>%s' % (msg, dmsg)
开发者ID:FinalF,项目名称:charm,代码行数:10,代码来源:symcrypto_test.py

示例14: main

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
def main(argv):
    HOST, PORT = "", 8090
    party_info = {}
    if argv[1] == '-p':
        print("Operating as prover...")
        prover_sock = socket(AF_INET, SOCK_STREAM)
        prover_sock.connect((HOST, PORT))
        prover_sock.settimeout(15)
        user = 'prover'
        party_info['socket'] = prover_sock
    elif argv[1] == '-v':
        print("Operating as verifier...")
        svr = socket(AF_INET, SOCK_STREAM)
        svr.bind((HOST, PORT))
        svr.listen(1)
        verifier_sock, addr = svr.accept()
        print("Connected by ", addr)
        user = 'verifier'
        party_info['socket'] = verifier_sock
    else:
        print("ERROR!")
        exit(-1)

    group = PairingGroup('a.param')
    party_info['party'] = user
    party_info['setting'] = group
    # statement: '(h = g^x) and (j = g^y)'

    if(user == 'prover'):
        g = group.random(G1)
        x,y = group.random(ZR), group.random(ZR)
        pk = {'h':g ** x, 'g':g, 'j':g**y}
        sk = {'x':x, 'y':y}
    #    pk = {'h':g**x, 'g':g}
    #    sk = {'x':x, 'y':y}
        result = executeIntZKProof(pk, sk, '(h = g^x) and (j = g^y)', party_info)
        print("Results for PROVER =>", result)

    elif(user == 'verifier'):
        # verifier shouldn't have this information
    #    pk = {'h':1, 'g':1, 'j':1}
    #    sk = {'x':1, 'y':1} 
        pk = {'h':1, 'g':1, 'j':1}
        sk = {'x':1}
        result = executeIntZKProof(pk, sk, '(h = g^x) and (j = g^y)', party_info)
        print("Results for VERIFIER =>", result)
开发者ID:FinalF,项目名称:charm,代码行数:48,代码来源:zk_demo.py

示例15: testPairingGroup

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import random [as 别名]
    def testPairingGroup(self):    
        groupobj = PairingGroup('SS512')
        p=groupobj.random()
        data={'p':p,'String':"foo",'list':[p,{},1,1.7, b'dfa',]}

        x=objectToBytes(data,groupobj)
        data2=bytesToObject(x,groupobj)
        self.assertEqual(data,data2)
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:10,代码来源:serialize_test.py


注:本文中的charm.toolbox.pairinggroup.PairingGroup.random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。