暗号文ポリシー属性ベース暗号(CP-ABE)のライブラリ

属性ベース暗号のライブラリを使う機会があったのでまとめます。

 

何も開発環境を整えてないのでまずは、

$ sudo yum groupinstall "Development tools" -y

 

リンク先の以下のものをwgetなりでダウンロードし、解凍します。

 

PBC Libraryが必要らしいので以下からダウンロードして解凍します。バージョンは0.5.4以上がいいでしょう。

 

pbcディレクトリに入り、

$  ./configure

...

checking for pow in -lm... yes
checking for __gmpz_init in -lgmp... no
************************
gmp library not found
add its path to LDFLAGS
see ./configure --help
************************

gmpが無いと怒られました。pbcは一度中断しましょう。

 

ここからダウンロード・解凍しましょう。

gmpのディレクトリに入り、

$ ./configure

...

configure: summary of build options:

Version: GNU MP 6.1.1
Host type: core2-pc-linux-gnu
ABI: 64
Install prefix: /usr/local
Compiler: gcc -std=gnu99
Static libraries: yes
Shared libraries: yes

$ make

$ sudo make install

$ make clean

gmp入りました。

 

では一度中断していたpbcディレクトに入り、

$ ./configure

 ...

global build variables
-----------------------------------------
Mon Sep 5 15:28:18 JST 2016
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:
-----------------------------------------

環境によってはbisonとflexが無くて怒られる可能性があるので適宜導入してください。

$ make

$ sudo make install

$ make clean

これでpbcは入りました。

 

libbswabeを入れます。

$ ./configure 

...

checking for SHA1 in -lcrypto... no
configure: error: please install the OpenSSL crypto library, libcrypto.

怒られました。openssl-develを入れます。再チャレンジ。

$ sudo yum install openssl-devel -y

$ ./configure

checking for SHA1 in -lcrypto... yes
checking for strdup... yes
checking for pkg-config... /usr/bin/pkg-config
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.
checking for GMP version >= 4.0.0 or later... found
checking for the PBC library... found
configure: creating ./config.status
config.status: creating Makefile

また怒られました。GLIBが見つからないと言われました。入れましょう。

sudo yum install glib2-devel -y

$ ./configure

...

checking for GLIB - version >= 2.0.0... yes (version 2.42.2)
checking for GMP version >= 4.0.0 or later... found
checking for the PBC library... found
configure: creating ./config.status
config.status: creating Makefile

$ make

$ sudo make install

$ make clean

 

 やっとCP-ABE本体です。cpabeのディレクトリに入りましょう。

$ ./configure

 ...

checking for GLIB - version >= 2.0.0... yes (version 2.42.2)
checking for GMP version >= 4.0.0 or later... found
checking for the PBC library... found
checking for libbswabe... found
configure: creating ./config.status
config.status: creating Makefile
config.status: WARNING: 'Makefile.in' seems to ignore the --datarootdir setting

$ make

$ sudo make install

$ make clean

これで導入完了です。

 

 試しにcpabe-enc等のコマンドを叩くとhelpが出るはずです。