-
bls
签名方案(
A
签名,
B
验证)
:
A:
生成一个随机数
x
作为私钥,生成随机的群生成元
g
,公钥
y=g^x
;
被签名的消息
m
,计算
m
的哈希值
h
:
h=hash
(
m
)
;
对
h
进行签名:
sig=h^x;
B:
B
收到的签名消息为
sig';
p>
验证双线性映射
e(sig',g)
与
p>
e(h,y)
是否相等;
其中
e(h,y)=e(h,g^x)=e(h,g)^x;
若
e(sig',g)=e(sig,g)=e(h^x,g)
=e(h,g)^x=e(h,y)
,则说明
B
收到的签名是
A
的真实
签名<
/p>
;
*/
#include
#include
int main(int
argc, char **argv) {
//
定义需要用到的变量;
pairing_t pairing;
element_t g, h;
element_t public_key, sig;
element_t secret_key;
element_t
temp1, temp2;
//
初始化群
< br>G1,G2,GT
;
pbc_demo_pairing_init(pairing, argc,
argv);
element_init_G2(g, pairing);
element_init_G2(public_key, pairing);
element_init_G1(h, pairing);
element_init_G1(sig, pairing);
element_init_GT(temp1, pairing);
element_init_GT(temp2, pairing);
element_init_Zr(secret_key, pairing);
printf(
//generate system
parameters
element_random(g);
//
生成一个随机数作为生成元
element_printf(
//generate private key
element_random(secret_key);
//
生成一个随机数作为私钥
element_printf(
//compute corresponding
public key
element_pow_zn(public_key, g,
secret_key);
//
计算公钥
=g^(
私钥
)
;
element_printf(
//generate
element from a hash
//for toy pairings, should check that
pairing(g, h) != 1
element_from_hash(h,
//
计算消息的
hash
值
element_printf(
//h^secret_key
is the signature
//in real life: only output the first
coordinate
element_pow_zn(sig, h, secret_key);
//
对消息哈希值
< br>h
签名
sig=h^(
私钥
p>
)
;
element_printf(
{
int
n =
pairing_length_in_bytes_compressed_G1(pairing);
//int n =
element_length_in_bytes_compressed(sig);
int i;
unsigned char
*data = pbc_malloc(n);
element_to_bytes_compressed(data, sig);
printf(
for (i = 0; i <
n; i++) {
printf(
}
printf(
element_from_bytes_compressed(sig,
data);
element_printf(
pbc_free(data);
}
//verification part 1
element_pairing(temp1, sig,
g);
//
计算双线性映射
temp1=e(h^(
私钥
),g);
element_printf(
//verification part 2
//should match
above
element_pairing(temp2,
h,
public_key);
//
计算双线性映射
temp2=e(h,g^(
私
钥
));
element_printf(
-
-
-
-
-
-
-
-
-
上一篇:紫砂壶的嘴、孔、把、钮、底,都有哪些学问?
下一篇:茶壶的部件