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


Python PairingGroup.hash方法代码示例

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


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

示例1: keygen

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import hash [as 别名]
def keygen(pk, msk, S):
    group = PairingGroup('SS512')

    attributes = [unicode(a) for a in S]
    z = group.random()
    r = group.random()
    alpha = msk['alpha']
    K0 = ((pk['g'] ** alpha) * (pk['w'] ** r)) ** (1/z)
    K1 = pk['g'] ** (r/z)
    K_x_2, K_x_3 = {},{}
    for attr in attributes:
        ri = group.random()
        K_x_2[attr] = pk['g'] ** (ri/z)
        K_x_2[attr] = objectToBytes(K_x_2[attr], group)
        K_x_3[attr] = ((((pk['u'] ** group.hash(unicode(attr),ZR))) * pk['h']) ** (ri/z)) * (pk['v'] ** (-r/z))
        K_x_3[attr] = objectToBytes(K_x_3[attr], group)
    ik = {'S':S,
          'K0':objectToBytes(K0, group),
          'K1':objectToBytes(K1, group),
          'Ki2':K_x_2,
          'Ki3':K_x_3}
    sk = objectToBytes(z, group)
    return {'ik':ik, 'sk':sk}
开发者ID:jiang2,项目名称:Trusted-Server,代码行数:25,代码来源:ABE_TS.py

示例2: encrypt

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import hash [as 别名]
def encrypt(policy_str, pool, group=None):
    print('policy_str in ABEnc=',policy_str)
    if group is None:
        group = PairingGroup('SS512')
    util = SecretUtil(group, False)
    policy = util.createPolicy(policy_str)
    secret = pool.pop('s')
    print('policy in ABEnc=',policy)
    sshares = util.calculateSharesList(secret, policy)
    sshares = dict([(x[0].getAttributeAndIndex(), x[1]) for x in sshares])
    print('sshares in ABEnc=',sshares)
    C0 = pool.pop('C0')
    C_x_1, C_x_2, C_x_3, C_x_4, C_x_5 = {},{},{},{},{}
    for attr, s_share in sshares.items():
        component = pool['components'].pop()
        C_x_1[attr] = component['C_j_1']
        C_x_2[attr] = component['C_j_2']
        C_x_3[attr] = component['C_j_3']
        C_x_4[attr] = s_share - component['lambda_prime_j']
        C_x_5[attr] = component['t_j'] * (group.hash(unicode(attr),ZR) - component['x_j'])
    ct = {'policy':policy_str, 'C0':C0,'C_j_1':C_x_1, 'C_j_2':C_x_2, 'C_j_3':C_x_3, 'C_j_4':C_x_4, 'C_j_5':C_x_5}
    print('ct in ABEnc=',ct)
    return (pool, ct)
开发者ID:jiang2,项目名称:ABEClient,代码行数:25,代码来源:ABE_Interface.py

示例3: hadamard_product

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import hash [as 别名]
    else:
        labeled_instance = [label] + instance[0]
        hashed_instance  =  group.hash(labeled_instance, ZR)

    c = hadamard_product(crs[3], basematrix_pow_exp(crs[4], hashed_instance))
    # pi=[PI]1, crs[5]=[(1,a)]2, y=[Y]1, c=[C]2
    # print(pairing_matrix(pi, crs[5]))
    # print(pairing_matrix(instance, c))
    return pairing_matrix(pi, crs[5]) == pairing_matrix(instance, c)


if __name__ == '__main__':
    # 'MNT159' represents an asymmetric curve with 159-bit base field
    group = PairingGroup('MNT159')
    g1 = group.random(G1)
    g2 = group.random(G2)
    t  = group.random(ZR)

    # Third-Party-Section
    crs   = generate_crs(group, g1, g2, t)

    # Certification-Section
    r     = group.random(ZR)
    y     = generate_instance(crs, r)
    alpha = group.hash(y[0], ZR)
    pi    = generate_pi(group, crs, y, r)

    # Verification-Section
    print("accept" if check_certificate(group, crs, pi, y) else "reject")

开发者ID:do030b,项目名称:cryptography,代码行数:31,代码来源:kiltz_and_wee_2.py

示例4: PairingGroup

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import hash [as 别名]
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
from charm.core.engine.util import objectToBytes,bytesToObject

import time, json, pickle, os, random, csv, copy
from sys import getsizeof
groupObj='SS512'
global group
group = PairingGroup(groupObj)


r = group.random(ZR)
i=0
for i in xrange(1,10):
	r_i = group.hash(str(r) + str(i), ZR)
	print r_i
开发者ID:dkhungme,项目名称:FastKAC,代码行数:17,代码来源:test.py

示例5: deserialize1

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import hash [as 别名]
    # Only work in G1 here
    return group.deserialize('0:'+encodestring(g))

def deserialize1(g):
    # Only work in G1 here
    return group.deserialize('1:'+encodestring(g))

def deserialize2(g):
    # Only work in G1 here
    return group.deserialize('2:'+encodestring(g))

def xor(x,y):
    assert len(x) == len(y) == 32
    return ''.join(chr(ord(x_)^ord(y_)) for x_,y_ in zip(x,y))

g1 = group.hash('geng1', G1)
g1.initPP()
g2 = g1
#g2 = group.hash('geng2', G2)
#g2.initPP()
ZERO = group.random(ZR)*0
ONE = group.random(ZR)*0+1

def hashG(g):
    return SHA256.new(serialize(g)).digest()

def hashH(g, x):
    assert len(x) == 32
    return group.hash(serialize(g) + x, G2)

class TPKEPublicKey(object):
开发者ID:amiller,项目名称:HoneyBadgerBFT,代码行数:33,代码来源:tpke.py


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