示例#1
0
    def issuecred(self, usk, uvk, m, ask, avk):
        n = len(m)
        # 得到s
        s = p.random()
        print("s为", s)
        # 得到{Qi},i=[1,n],其中Qi都是G2上的元素
        G = bp.BpGroup()
        g2 = G.gen2()
        Q = []
        for _ in range(n):
            rand = p.random()
            Q.append(rand * g2)
        # (user) ObtainCommit
        # 得到pi_1和pi_2

        pi_1 = self.nizk.proveK(m, s, uvk, Q)
        # 由于proveDL的接口,只能传入list形式的参数,这里需要用[usk],[self.g2],而不能用usk,self.g2
        pi_2 = self.nizk.proveDL([usk], [self.g2])
        # (auth)sigma_cred_ <-Issue(uvk,ask,pi)
        # 同样DL的接口,只能传入list形式的参数,这里需要用pi_2(pi_2本身就是三个元素的list),[self.g2]
        if (self.nizk.verifyK(pi_1, uvk, Q) == 1
                and self.nizk.verifyDL(pi_2, [self.g2]) == 1):
            w = p.random()
            sigma_cred_ = (w * uvk, w * (avk[1] + pi_1[0]))
        else:
            print("auth验证失败")
        #(user)delta_cred<-Unblind(delta_cred_,s)
        sigma_cred = (self.g1, self.g1, sigma_cred_[0],
                      sigma_cred_[1] - s * sigma_cred_[0])
        return sigma_cred
示例#2
0
def mk_gk():
    G = bp.BpGroup()
    q = G.order()
    g1 = G.gen1()
    g2 = G.gen2()
    gt = G.pair(g1, g2)
    return gk_T(G, q, g1, g2, gt, G.pair)
示例#3
0
def H(otsvk):
    # 这里要确保这里生成的G和BLCred的self.G是一样的才行
    G = bp.BpGroup()
    X_ = otsvk[0].export()
    Y_ = otsvk[1].export()
    bytestr = X_ + Y_
    str0 = str(bytestr)
    return G.hashG1(str0.encode("utf8"))
示例#4
0
 def __init__(self, p):
     self.G = bp.BpGroup()
     # g1, g2 is the generator of G1, G2
     self.g1, self.g2 = self.G.gen1(), self.G.gen2()
     self.x = 0
     self.X = 0
     self.p = p
     self.h = 0
     print("G的order为", self.G.order())
示例#5
0
 def __init__(self, p, m):
     self.G = bp.BpGroup()
     # g1, g2 分别是G1,G2的生成元
     self.g1, self.g2 = self.G.gen1(), self.G.gen2()
     # x,X 分别是私钥和公钥
     self.x = 0
     self.X = 0
     # p,m是传入的参数,p为传入的大质数,G1,G2,GT的阶为另一个给定的大质数,m是传入的消息,属于Zp
     self.p = p
     self.m = m
示例#6
0
 def __init__(self, p):
     self.G = bp.BpGroup()
     # g1, g2 分别是G1,G2的生成元
     self.g1, self.g2 = self.G.gen1(), self.G.gen2()
     # x,y,X,Y 分别是私钥和公钥中的元素
     self.x = 0
     self.y = 0
     self.X = 0
     self.Y = 0
     # p,m是传入的参数,p为传入的大质数,使得G1,G2,GT的阶为质数p,m是传入的消息,属于Zp
     self.p = p
     # r是theta中的一个元素,从消息空间Zp中随机获得(这里暂且先生成一个candidate,之后在sign函数中会进行筛选
     self.r = Bn().from_decimal(str(self.p)).random()
     self.theta_prime = 0
     print("G的order为", self.G.order())
示例#7
0
 def setup(self):
     # Choose a bilinear group
     self.G = bp.BpGroup()
     self.g1, self.g2 = self.G.gen1(), self.G.gen2()
示例#8
0
import random
from petlib.bn import Bn
from petlib.ec import EcGroup, EcPt
from bplib import bp

# 在FBB和WBB中遇到的一个Bug
G = bp.BpGroup()
p = 19
m = 16
x = Bn(p).random()
print(x)
# 这种情况会报错:TypeError: bad operand type for abs(): 'Bn'
num = Bn(x + m).mod_inverse(G.order())
print(num)
# 解决方案:改为如下写法
num = Bn(int(x + m)).mod_inverse(G.order())
print(num)

# 在BLS,FBB,WBB中会遇到另外一个Bug
# 无法使用大整数问题:如果是Bn(x),x不能超过2^32,而且必须是int类型,即最好写成Bn(int(x)),否则可能报错(上述
# 因此我们可以用别的方法来避免这种调用
Bn.from_decimal(str(x + m))
示例#9
0
 def __init__(self):
     self.G = bp.BpGroup()
     self.p = int(self.G.order())
     self.n = -1