博主论文狗,很久没有来贴博客,最近作实验须要用到属性加密,了解了下CP-ABE,前来记录一下:php
网上相关的博文较多,博主看了大部分的,认为下面这两个看完了基本就能够成功安装。html
可参见博文:前端
http://blog.csdn.net/hlsdbd1990/article/details/48291359算法
http://blog.csdn.net/huifeideyema/article/details/51695231ubuntu
(一)相关概念ide
cp-abe须要用到许多算法库,像M四、bison、flex、gmp、pbc,且cpabe依赖pbc,pbc依赖gmp,gmp依赖M四、bison、flex函数
M4 :是一个宏处理器.将输入拷贝到输出,同时将宏展开. 宏能够是内嵌的也能够是用户定义的. 除了能够展开宏,m4还有一些内建的函数,用来引用文件,执行Unix命令,整数运算,文本操做,循环等. m4既能够做为编译器的前端也能够单独做为一个宏处理器.M4 依赖于: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, Perl, Sed等;工具
bison: Bison其实是使用最普遍的Yacc-like分析器生成器,使用它能够生成解释器,编译器,协议实现等多种程序. flex
flex:是一个产生扫描器的工具;能识别文本模式的词句的程序.flex读入给定的文件,或没有文件名给定时的标准输入,即要产生的扫描器的说明.说明按照正规表达式和C代码的格式,叫作规则.flex产生定义了例程'yylex()'的'lex.yy.c'C源码文件,该文件被编译和用'-lfl'标志连接库以产生可执行文件,当可执行文件被运行后,它分析以正规表达式出现的输入.不管什么时候它找到匹配,都将执行相应的C代码.(bison flex实际上就是用于实现属性加密中访问控制策略)ui
gmp:GMP是一个任意精度的开源算术库,可用于符号整数,有理数,浮点数计算。
pbc:基于对数运算的算法库
(二)安装
一、安装m4
sudo apt-get install m4
二、安装gmp
http://gmplib.org/ 下载gmplib
./configure
make
make check
sudo make install
三、安装pbc
http://crypto.stanford.edu/pbc/download.html 下载pbc
解压,安装
./configure
出现
flex not found
执行
sudo apt-get install flex
安装成功后继续执行
./configure
出现
bison not found
运行
sudo apt-get install bison
成功后执行
./configure
make
sudo make install
四、安装cpabe toolkit
http://hms.isi.jhu.edu/acsc/cpabe/ 或者 http://acsc.cs.utexas.edu/cpabe/ 下载cpabe-0.11和libbswabe-0.9
安装openSSL
sudo apt-get install libssl-dev
进入libbswabe-0.9解压目录
/configure
报错
checking for GLIB - version >= 2.0.0... no
*** Could not run GLIB test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GLIB is incorrectly installed.
执行
sudo apt-get install libglib2.0-dev
安装成功后,执行
./configure
make
sudo make install
进入cpabe-0.11解压目录
./configure
出错
/usr/bin/ld: note: '__gmpz_init' is defined in DSO /usr/local/lib/libgmp.so so try adding it to the linker command line
/usr/local/lib/libgmp.so: could not read symbols: 无效的操做
改成另外一种方式编译:
sudo apt-get install checkinstall
修改Makefile,LDFLAGS后加入-lgmp
sudo checkinstall
编译成功~
(三)报错
除了上述报错外,执行checkinstall之后也有可能出现这种错误
gcc -o cpabe-setup setup.o common.o -O3 -Wall -lglib-2.0 -Wl,-rpath /usr/local/lib -lgmp -Wl,-rpath /usr/local/lib -lpbc -lbswabe -lcrypto -lcrypto /usr/bin/ld: /usr/local/lib/libpbc.so: undefined reference to symbol '__gmpz_init' /usr/local/lib/libgmp.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status Makefile:34: recipe for target 'cpabe-setup' failed make: *** [cpabe-setup] Error 1</pre></code
或者出现这种错误
policy_lang.y: In function ‘yyparse’:
policy_lang.y:67:38: error: expected ‘;’ before ‘}’ token
result: policy { final_policy = $1 }
***解决方法***
https://ubuntuforums.org/showthread.php?t=2254939
或者http://stackoverflow.com/questions/17373306/error-in-linking-gmp-while-compiling-cpabe-package-from-its-source-code
安装成功之后出现以下界面
图片摘自http://blog.csdn.net/guomutian911/article/details/42558155