呃呃呃
PBC库环境配置
依赖预安装
1 2 3 4 5 6
| sudo apt-get install m4 sudo apt-get install g++ sudo apt-get install flex sudo apt-get install bison sudo apt-get install libgmp-dev sudo apt-get install libpthread-stubs0-dev
|
下载GMP包
前往官网,我下载的是 gmp-6.1.2.tar.xz
版本
1
| tar xvJf gm--6.1.2.tar.xz
|
进入文件夹内,进行安装
1 2 3 4
| ./configure make make check sudo make install
|
安装PBC
PBC官网下载包并解压
1 2 3
| wget https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz
tar -xzvf pbc-0.5.14.tar.gz
|
下面进入PBC源码目录,进行编译和安装
1 2 3 4
| cd pbc-0.5.14 ./configure make sudo make install
|
管理库路径
1 2
| cd /etc/ld.so.conf.d sudo vi libpbc.conf
|
写入 /usr/local/lib
更新cache:sudo ldconfig
配置环境变量
1 2 3
| vim ~/.bashrc export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH source ~/.bashrc
|
实例测试
把pbc/param/a.param
移到工程目录
1
| cp a.param /your/project/location && ls
|
创建测试程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #include <stdio.h> #include "/usr/local/include/pbc/pbc.h" int main(int argc, char const *argv[]) { pairing_t pairing; char param[1024]; size_t count = fread(param, 1, 1024, stdin); if (!count) pbc_die("input error"); pairing_init_set_buf(pairing, param, count);
element_t x; element_init_Zr(x, pairing); element_random(x); element_printf("%B\n", x);
return 0; }
|
编译与运行
1 2
| gcc main.c -L. -lpbc -lgmp ./a.out < ./a.param
|
结果如下: