概述
CC签名
#include"pbc.h"
#include"pbc_time.h"
int main(void)
{
pairing_t pairing;
element_t P,Ppub,Qu,Su,V,W,temp;
element_t s,r,h,temp1;
element_t T1,T2;
double time1,time2;
int byte1,byte2;
a_param_input(pairing);
element_init_G1(P,pairing);
element_init_G1(Ppub,pairing);
element_init_G1(Qu,pairing);
element_init_G1(Su,pairing);
element_init_G1(V,pairing);
element_init_G1(W,pairing);
element_init_G1(temp,pairing);
element_init_Zr(s,pairing);
element_init_Zr(r,pairing);
element_init_Zr(h,pairing);
element_init_Zr(temp1,pairing);
element_init_GT(T1,pairing);
element_init_GT(T2,pairing);
if(!pairing_is_symmetric(pairing))
{
fprintf(stderr,"only works with symmetric pairingn");
exit(1);
}
printf("SetUpn");
time1=get_time();
element_random(s);
element_random(P);
element_mul_zn(Ppub,P,s);
time2=get_time();
element_printf("P=%Bn",P);
element_printf("Ppub=%Bn",Ppub);
printf("the time of setup phase = %fsb",time2-time1);
printf("Extractn");
time1=get_time();
element_from_hash(Qu,"IDu",3);
element_mul_zn(Su,Qu,s);
time2=get_time();
element_printf("Qu=%Bn",Qu);
element_printf("Su=%Bn",Su);
printf("the time of extract phase = %fsn",time2-time1);
printf("Signn");
time1=get_time();
element_random(r);
element_mul_zn(V,Qu,r);
element_random(h);
element_add(temp1,h,r);
element_mul_zn(W,Su,temp1);
time2=get_time();
printf("the signature of message is:n");
element_printf("V=%Bn",V);
element_printf("W=%Bn",W);
printf("the time of sign phase = %fsn",time2-time1);
printf("Verifyn");
time1=get_time();
pairing_apply(T1,P,W,pairing);
element_mul_zn(temp,Qu,h);
element_add(temp,temp,V);
pairing_apply(T2,Ppub,temp,pairing);
if(!element_cmp(T1,T2))
printf("the signature is valid!n");
else
printf("the signature is not valid!n");
time2=get_time();
element_printf("e(P,W)=%Bn",T1);
element_printf("the time of verify phase= %fsn",time2-time1);
byte1=element_length_in_bytes(W);
byte2=element_length_in_bytes(V);
printf("the bytes of signature = %dn",byte1+byte2);
/*释放*/
element_clear(P);
element_clear(Ppub);
element_clear(Qu);
element_clear(Su);
element_clear(W);
element_clear(V);
element_clear(temp);
element_clear(s);
element_clear(h);
element_clear(r);
element_clear(temp1);
element_clear(T1);
element_clear(T2);
pairing_clear(pairing);
return 0;
}
最后
以上就是魔幻棒球为你收集整理的PBC应用的全部内容,希望文章能够帮你解决PBC应用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复