Пример #1
0
def gen_key():
    """Example naive RSA key generation"""
    p = Bn.get_prime(512)
    q = Bn.get_prime(512)
    m = p * q
    phi = (p - 1) * (q - 1)
    e = Bn(2**16 + 1)
    d = e.mod_inverse(phi)
    pub = (e, m)
    priv = (d,)
    return pub, priv
Пример #2
0
                    "m is out of range, please ensure m to be an integer in [0,p)"
                )
        except ValueError:
            print("m is not an int, please ensure m to be an integer in [0,p)")
        # 把这个整数类型的信息m转化为字符串类型,便于使用hashG1函数
        m = str(m)
        self.h = self.G.hashG1(m.encode("utf8"))
        theta = self.x * self.h
        return theta

    def verify(self, vk, m, theta):
        return self.G.pair(theta, self.g2) == self.G.pair(self.h, self.X)


if __name__ == "__main__":
    p = Bn.get_prime(100)
    m = p.random()
    bls = BLS(p)
    # 测试产生公钥私钥函数正确性
    (sk, vk) = bls.keygen()
    print(sk, vk)
    # 测试生成签名函数正确性
    theta = bls.sign(sk, m)
    print(theta)
    # 测量生成签名函数执行时间
    total_time = 0
    for i in range(10000):
        start = time.clock()
        bls.sign(sk, m)
        total_time += time.clock() - start
    print("BLS生成签名时间为", total_time / 10000)