BLS签名简介
BLS 签名方案最初是由斯坦福大学教授 DanBoneh 等人于 2001 年就提出的一种签名方案(原论文地址[1]),而在 2018 年,Boneh 教授还与 IBM 研究机构的 ManuDrijvers 等人更新了这种签名方案(原论文地址[2])。
双线性映射e函数
BLS签名算法就是基于双线性映射构造的,在给出具体的签名算法之前,我们需要了解一下什么是双线性映射。
对于一个质数双线性群可以由五元组
- 双线性(Bilinearity):对于任意的
,有;
- 非退化性(Non-degeneracy):至少存在元素
,满足;
- 可计算性(Efficiency):对于任意的
,存在有效算法高效地计算。
双线性映射,即利用一个特殊地函数,把一条或两条不同曲线上地两个点
此外,该函数还具有以下两个特性:
有关双线性映射的知识,可参考论文"ON THE IMPLEMENTATION OF PAIRING-BASED CRYPTOSYSTEMS"[3]。
Java实现双线性映射
(1)曲线初始化[4]
PairingParameters pairingParameters = PairingFactory.getPairingParameters("params/a1_2_128.properties");
Pairing pairing = PairingFactory.getPairing(pairingParameters);
Element g2 = pairing.getG2().newRandomElement();
(2)产生公私钥
byte[] privateKey = pairing.getZr().newRandomElement().toBytes();
Element secretKey = pairing.getZr().newElementFromBytes(privateKey);
Element publicKey = g2.powZn(secretKey);
(3)将两个点映射为一个数
Element n = pairing.pairing(p, q);
// the type of Q and P is Element.
如何将指定的元素哈希到双线性群中,可参考[4]。
Element h = pairing.getG1().newElementFromHash(byte[] var1, int var2, int var3);
Element h = pairing.getG1().newElementFromBytes(byte[] var1);
BLS签名
BLS签名包括:初始化、密钥生成、签名、验证四个部分,具体构造如下:
(1)初始化
G1, G2 是阶为 p 的乘法循环群,生成元分别是 g1,g2,e 是双线性映射:G1 * G2
这里示例哈希函数H:{0,1}*
byte[] msg = "message".getBytes();
byte[] hash = hash(msg, publicKey);
Element h = pairing.getG1().newElementFromHash(hash, 0, hash.length);
(2)密钥生成
选择随机数
(3)签名
对于消息“message”,首先映射到循环群中的一点,记为
public Signature signDemo(byte[] message){
// 随机生成私钥
byte[] privateKey = pairing.getZr().newRandomElement().toBytes();
Element secretKey = pairing.getZr().newElementFromBytes(privateKey);
// 生成公钥
Element publicKey = systemParameters.powZn(secretKey);
// hash映射
byte[] hash = hash(message, publicKey);
Element h = pairing.getG1().newElementFromHash(hash, 0, hash.length);
// 签名
Element signatureElement = h.powZn(secretKey);
return new Signature(message,publicKey,signatureElement);
}
(4)验签
公钥验证签名,即验证等式
证明过程如下:
Element p = pairing.pairing(g2,signatureElement);
Element duplicate = pairing.pairing(publicKey,h);
if (duplicate.isEqual(p)) {
System.out.println("验签成功");
}
本文首发公众号VenusBlockChain,VenusBlockChain致力于区块链技术研究,传播区块链技术和解决方案、区块链应用落地、区块链行业动态等。有兴趣的小伙伴们,欢迎关注。
http://weixin.qq.com/r/hEk_JgPEdF4LrUdF9xyW (二维码自动识别)
参考资料
[1]https://www.iacr.org/archive/asiacrypt2001/22480516.pdf
[2]https://eprint.iacr.org/2018/483.pdf
[3]https://crypto.stanford.edu/pbc/thesis.pdf
[4]https://blog.csdn.net/jingzi123456789/article/details/104944935