The Pairing-Based Cryptography Library的学习

这个库由stanford大学开发,库的地址为http://crypto.stanford.edu/pbc/


总介绍:

1,功能足够的丰富:

The PBC library is designed to be the backbone of implementations of pairing-based cryptosystems, thus speed and portability are important goals. It provides routines such as elliptic curve generation, elliptic curve arithmetic and pairing computation.

2,接口足够的抽象:

The API is abstract enough that the PBC library can be used even if the programmer possesses only an elementary understanding of pairings. There is no need to learn about elliptic curves or much of number theory. (The minimum requirement is some knowledge of cyclic groups and properties of the pairing.)


安装:

1,如果直接按其教程安装./configure会提示缺少一些东西:

tatostar@junjieshi:~/G2/Waters Encryption/pbc-0.5.14$ sudo ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
configure: WARNING: Libtool does not cope well with whitespace in `pwd`
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking whether gcc and cc understand -c and -o together... yes
checking how to run the C preprocessor... gcc -E
checking whether ln -s works... yes
checking whether make sets $(MAKE)... (cached) yes
checking for flex... no
checking for lex... no
************************
flex not found
************************


2,我们按照提示分别下载安装这些就好了:

tatostar@junjieshi:~/G2/Waters Encryption/pbc-0.5.14$ sudo apt-get install flex

tatostar@junjieshi:~/G2/Waters Encryption/pbc-0.5.14$ sudo apt-get install bison byacc


************************
gmp library not found
add its path to LDFLAGS
see ./configure --help
************************

3,由于PBC是基于GMP开发的,根据提示我们需要先安装GMP:从https://gmplib.org/下载gmp-5.1.3.tar.bz2

GNU MP is a portable library written in C for arbitrary precision arithmetic on integers, rational numbers, and floating-point numbers. It aims to provide the fastest possible arithmetic for all applications that need higher precision than is directly supported by the basic C types.

按要求:

  • tatostar@junjieshi:~/G2/Waters Encryption/gmp-5.1.3$ sudo ./configure 
  • 最终得到:configure: summary of build options:


      Version:           GNU MP 5.1.3
      Host type:         coreisbr-unknown-linux-gnu
      ABI:               64
      Install prefix:    /usr/local
      Compiler:          gcc -std=gnu99
      Static libraries:  yes
      Shared libraries:  yes
  • tatostar@junjieshi:~/G2/Waters Encryption/gmp-5.1.3$ make install
  • 最终得到:make[2]: Leaving directory `/home/tatostar/G2/Waters Encryption/gmp-5.1.3'
    make[1]: Leaving directory `/home/tatostar/G2/Waters Encryption/gmp-5.1.3'
  • Libraries have been installed in:
       /usr/local/lib


    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'


    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
     /bin/mkdir -p '/usr/local/include'
     /usr/bin/install -c -m 644 gmp.h '/usr/local/include'
    make  install-data-hook
    make[4]: Entering directory `/home/tatostar/G2/Waters_Encryption/gmp-5.1.3'


    +-------------------------------------------------------------+
    | CAUTION:                                                    |
    |                                                             |
    | If you have not already run "make check", then we strongly  |
    | recommend you do so.                                        |
    |                                                             |
    | GMP has been carefully tested by its authors, but compilers |
    | are all too often released with serious bugs.  GMP tends to |
    | explore interesting corners in compilers and has hit bugs   |
    | on quite a few occasions.                                   |
    |                                                             |
    +-------------------------------------------------------------+
  • 虽然make check会报一些错,但我们接下来会看到这并不影响PBC的安装。
4,再次tatostar@junjieshi:~/G2/Waters_Encryption/pbc-0.5.14$ sudo ./configure 

checking whether make sets $(MAKE)... (cached) yes
checking for flex... flex
checking lex output file root... lex.yy
checking lex library... -lfl
checking whether yytext is a pointer... yes
checking for bison... bison -y
checking for pow in -lm... yes
checking for __gmpz_init in -lgmp... yes
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for ANSI C header files... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for size_t... (cached) yes
checking whether time.h and sys/time.h may both be included... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... yes
checking for floor... no
checking for gettimeofday... yes
checking for memmove... yes
checking for memset... yes
checking for pow... no
checking for sqrt... no
checking for strchr... yes
checking for strdup... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating example/Makefile
config.status: creating gen/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands


global build variables
-----------------------------------------
Wed Dec 4 10:55:21 CST 2013
host info:        x86_64-unknown-linux-gnu
optimized build:  no
compiler (CC):    gcc
LDFLAGS:          
CPPFLAGS:         
CFLAGS:            -Wall -W -Wfloat-equal -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wredundant-decls -Wendif-labels -Wshadow -pipe -ffast-math -U__STRICT_ANSI__ -std=gnu99 -fomit-frame-pointer -O3
LEX:              flex
AM_LFLAGS:        
LFLAGS:           
YACC:             bison -y
AM_YFLAGS:        
YFLAGS:           
-----------------------------------------

接下来我们来测试一下是否已经安装成功:



从这些示例中我们可以看出,默认情况下,系统已经设定好了pairing的一些参数,包括G1、G2以及它们的order、generator等。

关于这个小解释程序的一些介绍可以参见http://crypto.stanford.edu/pbc/manual/ch07s01.html


Initially, the variables G1, G2, GT and Zr are represent groups associated with a particular A pairing.

Assignments such as variable := expression; return the value of the variable.

The arithmetic operators +, -, /, *, ^ have the standard precedence. The C comparison operators and ternary operator are available.

Each statement should be terminated by a semicolon.

//****************************************************************SEPARATION LINE***********************************************************************************\\


具体使用

(manual笔记)

由于我们最终需要的十一个bilinear map e,之前首先想到的是Dan boneh使用的weil pairing。但似乎一直没有直接的在这个library中找到显式说是weil pairing的函数。但有一个例子是介绍BLS signature的,看原始的论文,好像其使用的pairing就是weil pairing或者实现中的Tate pairing。


Programs using the PBC library should include the file pbc.h:

#include <pbc.h>

and linked against the PBC library and the GMP library, e.g.

$ gcc program.c -L. -lpbc -lgmp

PBC follows GMP in several respects:

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值