双线性映射 pbc

pbc的官方网站是在

https://crypto.stanford.edu/pbc/

pbc是做双线性映射密码学的库


下载了pbc的库,然后在/pbc-0.5.14/example 文件夹下输入: 

./bls < ../param/a.param


pbc 简单编程

以下程序是用pbc的库来验证e(ab,cd) = e(ac,bd)


#include <pbc.h>
#include <pbc_test.h>


int main(int argc, char **argv) {
  pairing_t pairing;
  element_t a, b, c, d;
  element_t A, B, C, D;
  element_t temp1, temp2;


  pbc_demo_pairing_init(pairing, argc, argv);
  
  element_init_G1(a, pairing); //初始化群G1的a 
  element_init_G2(b, pairing); //初始化群G1的b
  element_init_G1(c, pairing); //初始化群G1的c 
  element_init_G2(d, pairing); //初始化群G1的d 


  element_init_G1(A, pairing);
  element_init_G2(B, pairing);
  element_init_G1(C, pairing);
  element_init_G2(D, pairing);


  
  element_init_GT(temp1, pairing);
  element_init_GT(temp2, pairing);


  element_random(a);
  element_random(b);
  element_random(c);
  element_random(d);




  element_mul(A, a, b);// A = ab a乘以b
  element_mul(B, c, d);// B = cd 
  element_mul(C, a, c);// C = ac
  element_mul(D, d, b);// D = bd


  element_pairing(temp1, A, B);
  element_pairing(temp2, C, D);


  if(element_cmp(temp1,temp2))
  {
printf("hello\n");
  }
  
  return 0;
}


test.c 

./test < ../param/a.param
hello


pbc的编译方式是gcc test.c -L. -lpbc -lgmp -o test

运行 

 ./test < ../param/a.param

true



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值