CP-ABE环境配置
本文密码学专业,论文仿真需要CP-ABE,现将配置过程作个记录
cpabe依赖pbc,pbc依赖gmp,gmp依赖M4、bison、flex,所以。。
- sudo apt-get install M4
- sudo apt-get install flex
- sudo apt-get install bison
1 安装gmp
- lzip -d gmp-6.1.0.tar.lz
- tar -zxvf gmp-6.1.0.tar
- cd gmp-6.1.0
- ./configure
- make
- make check
- sudo make install
2 安装pbc
下载https://crypto.stanford.edu/pbc/download.html
- tar -zxvf pbc-0.5.14.tar.gz
- cd pbc-0.5.14
- </pre><pre code_snippet_id="1719527" snippet_file_name="blog_20160616_14_9454922" name="code" class="plain">./configure
- make
- sudo make install
3 安装openSSL
下载https://www.openssl.org/source/
- tar -zxvf openssl-1.0.1t.tar.gz
- cd openssl-1.0.1
- ./configure
- make
- sudo make install
4 安装libbswcpabe
下载http://acsc.cs.utexas.edu/cpabe/
- tar -zxvf libbswabe-0.9.tar.gz
- cd libbswabe-0.9
- ./configure
- make
- sudo make install
make出现问题
- core.c:9:18: fatal error: glib.h: 没有那个文件或目录
- #include <glib.h>
- ^
- compilation terminated.
- make: *** [core.o] 错误 1
运行
- sudo apt-get install libglib2.0-dev
重新编译
- ./configure
- make
- sudo make install
5 安装cpabe
下载http://acsc.cs.utexas.edu/cpabe/
- tar -zxvf cpabe-0.11.tar.gz
- cd cpabe-0.11/
- </pre><pre code_snippet_id="1719527" snippet_file_name="blog_20160616_14_9454922" name="code" class="plain">./configure
- make
- sudo make install
make 出现问题
- //usr/local/lib/libgmp.so: error adding symbols: DSO missing from command line
- collect2: error: ld returned 1 exit status
- make: *** [cpabe-setup] 错误 1
解决:修改Makefile,LDFLAGS最后加入-lgmp
- make
出现以下问题
- policy_lang.y: In function ‘yyparse’:
- policy_lang.y:67:38: error: expected ‘;’ before ‘}’ token
- result: policy { final_policy = $1 }
- ^
- make: *** [policy_lang.o] 错误 1<pre name="code" class="plain">cpabe-setup -h
解决:67行 } 前加 ;j即可
64位操作系统还有一些worning
- policy_lang.y: In function ‘eq_policy’:
- policy_lang.y:212:4: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat=]
- (g_strdup_printf("%s_flexint_%llu", attr, n->value));
- ^
- policy_lang.y:215:4: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ [-Wformat=]
- (g_strdup_printf("%s_expint%02d_%llu", attr, n->bits, n->value));
- ^
- policy_lang.y: In function ‘yylex’:
- policy_lang.y:391:3: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 3 has type ‘uint64_t *’ [-Wformat=]
- sscanf(s->str, "%llu", &(yylval.nat));
- ^
- policy_lang.y: In function ‘parse_attribute’:
- policy_lang.y:577:3: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 4 has type ‘uint64_t *’ [-Wformat=]
- if( sscanf(a, " %s = %llu # %u ", s, &value, &bits) == 3 )
- ^
- policy_lang.y:596:5: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ [-Wformat=]
- (*l, g_strdup_printf("%s_expint%02d_%llu", s, bits, value));
- ^
- policy_lang.y:598:3: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 4 has type ‘uint64_t *’ [-Wformat=]
- else if( sscanf(a, " %s = %llu ", s, &value) == 2 )
- ^
- policy_lang.y:612:5: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat=]
- (*l, g_strdup_printf("%s_flexint_%llu", s, value));
解决:%llu都改为 %lu 即可
- make
- sudo make install
编译成功
测试
- cpabe-setup -h
显示
- Usage: cpabe-setup [OPTION ...]
- Generate system parameters, a public key, and a master secret key
- for use with cpabe-keygen, cpabe-enc, and cpabe-dec.
- Output will be written to the files "pub_key" and "master_key"
- unless the --output-public-key or --output-master-key options are
- used.
- Mandatory arguments to long options are mandatory for short options too.
- -h, --help print this message
- -v, --version print version information
- -p, --output-public-key FILE write public key to FILE
- -m, --output-master-key FILE write master secret key to FILE
- -d, --deterministic use deterministic "random" numbers
- (only for debugging)
没问题,,成功
还有一个abe更具体的实现 libfenc
6 安装 libenc
下载https://code.google.com/archive/p/libfenc/downloads
- cd libfenc
- ./configure
- make
- sudo make install
测试
- cd tools/
初始化
- ./abe-setup -m CP
- Generating Waters CP scheme parameters...
- Initializing library...
- No error (0)
- Generating master ABE system parameters...
- Loading global parameters...
- No error (0)
- Generating scheme parameters and secret key...
- No error (0)
- Exporting public parameters...
- No error (0)
- Base-64 encoding public parameters...
- 'fwORsUPDOdb0etEQ8nXgM765TneErDKp9OTFiAAHNIBqwsy/UypT+5vWuhH2FGu4cwQ3iNS1qdvrYjzsBQk+x4KLtba/3ZLRnYM7ijf8L7YaztDneg5D4PA/udUYRZWIJT9WlvTzCQ5DP8ojilwkzL4BaflrVeWMYZfs5J/gFngIO0lOoG89fQmCG6vYzQAzEW/X1mgwTaZGy9gNTsi7AgQag6xUBBdFu+eAOgxhVS0AnPwLzokgVLTNyQA38GT2JPrpIuQsy3kh6rWk1u4MEa6Zp7KlbiZd+B9vd+HyIBX2ulABimVKLbNzyJuqVOtvG2xzttidrgAGlOP+n5aIiUant8+P+fwgil0PaQ4s6bleTf6BS6bAzdwoTZZSA04Hx7lQq6Wz0NE6Ee+5OnB+0osja71kMjWWJFcc6cUIACOk6lgJiCRXmbsW/1KSqTjOytbTujUAgnsR2DP1HyG9alJAhbgMFoJmPlXKdLYLIaxgvZfuyu3FH9DMHMqXj/HpRmSh9+rA944VxmkYAAAAAA=='
- Exporting secret parameters...
- No error (0)
- Base-64 encoding secret parameters...
- 'fiK5Eh1+z4jtsBMARFx9yheRmfLWPlS8M0bBHw=='
- Destroying context...
- No error (0)
- Shutting down library...
- No error (0)
加密
- #37#^_^@bruvelv-Lenovo-Y430P:~/ABE/libfenc/tools$ ./abe-enc -m CP -d "<span style="color:#ff0000;"><strong>haha</strong></span>" -i plaintext.txt -a Attr1,Attr2,Attr3 -p '((Attr1 and Attr2) or Attr3)' -o cipertext
- Encrypting for Waters CP scheme...
- Loading global parameters...
- No error (0)
- Generating scheme parameters and secret key...
- No error (0)
- Reading the public parameters file = public.param.cp
- DEBUG: Policy -- '((Attr1 and Attr2) or Attr3)'
- Hashed Attr1 to 9330343389436777432774806010838379822496920567713207609639801066414
- share 0 is 6856445857519078318242964707612121029817614998351926048095706106450
- Hashed Attr2 to 12897582061484440647626205166858515037561919287927948242788041630532
- share 1 is 2195387252221824496104266554794551033371798688446347486142373906698
- Hashed Attr3 to 3456098104092453560102604953110158625385794332821633597398365174053
- share 2 is 11517504462816332140381662860429691026263431308257504610049038306202
- Generated session key: 28 36 ee 34 df b9 e1 88 c5 f1 0b 05 d2 d3 11 11
- IV: 1a eb ec 09 69 09 3b 9d 6b e8 f5 52 38 f1 4b f4
- Encrypting data...
- Plaintext is => 'haha'.
- Ciphertext stored in 'cipertext.cpabe'.
- ABE Ciphertex size is: '826'.
- AES Ciphertext size is: '16'.
- Shutting down library...
- No error (0)
生成密钥
- #38#^_^@bruvelv-Lenovo-Y430P:~/ABE/libfenc/tools$ ./abe-keygen -m CP -a Attr1,Attr2,Attr3 -p Attr3 -o key_file
- Generating private key for Waters CP scheme...
- Generating your private key...
- Loading global parameters...
- No error (0)
- Generating scheme parameters and secret key...
- No error (0)
- Reading the public parameters file = public.param.cp
- Reading the secret parameters file = secret.param.cp
- public params input = 'fwORsUPDOdb0etEQ8nXgM765TneErDKp9OTFiAAHNIBqwsy/UypT+5vWuhH2FGu4cwQ3iNS1qdvrYjzsBQk+x4KLtba/3ZLRnYM7ijf8L7YaztDneg5D4PA/udUYRZWIJT9WlvTzCQ5DP8ojilwkzL4BaflrVeWMYZfs5J/gFngIO0lOoG89fQmCG6vYzQAzEW/X1mgwTaZGy9gNTsi7AgQag6xUBBdFu+eAOgxhVS0AnPwLzokgVLTNyQA38GT2JPrpIuQsy3kh6rWk1u4MEa6Zp7KlbiZd+B9vd+HyIBX2ulABimVKLbNzyJuqVOtvG2xzttidrgAGlOP+n5aIiUant8+P+fwgil0PaQ4s6bleTf6BS6bAzdwoTZZSA04Hx7lQq6Wz0NE6Ee+5OnB+0osja71kMjWWJFcc6cUIACOk6lgJiCRXmbsW/1KSqTjOytbTujUAgnsR2DP1HyG9alJAhbgMFoJmPlXKdLYLIaxgvZfuyu3FH9DMHMqXj/HpRmSh9+rA944VxmkYAAAAAA=='
- secret params input = 'fiK5Eh1+z4jtsBMARFx9yheRmfLWPlS8M0bBHw=='
- Importing public parameters...
- No error (0)
- Importing secret parameters...
- No error (0)
- DEBUG: Attribute list -- '(Attr1,Attr2,Attr3)'
- Hashed Attr1 to 9330343389436777432774806010838379822496920567713207609639801066414
- Hashed Attr2 to 12897582061484440647626205166858515037561919287927948242788041630532
- Hashed Attr3 to 3456098104092453560102604953110158625385794332821633597398365174053
- Extracting a decryption key...
- No error (0)
- Exporting key...
- No error (0)
- Destroying context...
- No error (0)
- Shutting down library...
- No error (0)
解密
- #39#^_^@bruvelv-Lenovo-Y430P:~/ABE/libfenc/tools$ ./abe-dec -m CP -k key_file -f cipertext.cpabe
- Decrypting under Waters CP scheme...
- Private-key file = 'key_file'
- Encrypted file = 'cipertext.cpabe'
- out_len: 1194
- abe ciphertext = 'AgAAABAAAAADAAAAKChBdHRyMSBhbmQgQXR0cjIpIG9yIEF0dHIzKQBNmxMgdHM5vlR5AoXrZfvntyiuiBdSQ5h+MVfNAFiYzvIuE66JM9RbKO+Hctw8pgs7AFiYzvIuE65tDgJFX30JTMtn3Ugywbcl/OXub/Lurx3YcLx+YwZb9T1zLM8CH/B8nHtGHkooZlZyS8RJFXPlPUBs/cMbfzN0TrGsiB4cNdcT6e3xW+tnFZUtsQcxajFtx8TqIIcfvX5hq/jWSWRAFxTStWco/YtgCwjRTYc8/h0vg+5oR50n/lQIv3VYSl07BCG/SHpbSCGzL+GJwjukNIWfLhlxjV6539VHvK9Cy/Ywit6gRovYoI/bN0DsZyNgLhFrfDJ+1Sll9r/hcRLzB/cxcCm5ZFqoGp4Xa5xsQMupTS0DlESSmnp4SQWII0QWwHKTjHpeGtdSwzTrgHp4SQWII0QpRvZ90+pPpxFZ6lKg6AyZez9+8aPC7b5n/UkEYTXz8UKKjR8DGiG040Nm2qJQpdGHMiX1t1GiQnMipZq30WZIq3w5u3ox0V2gaI6S+DdZomaTweBzUs+WVG/+FXTH8jxI6ylAYwrzP8Ivxm4RlL1JBmwb9LLoFnhKOi5aMBiJl0zHMi/aLZ+nB2bTHzFY/lJkKnTe6+2y1DiBMHBz3WY98gnpJfjRFEYtIciCgKDZY5kV5Ofzg0mx6AirPlyMVvNBf3RoShflOXwKP2kIMVCITGwlpqZV/z2bpDiijS/acCDRTyFe+SWmjO9KdW4LS3q+Ib3EACDRTyFe+SUaJeXWy8cxUl/j116dpVagPjeXst3p5yRFSxLzd2Wx2MubzAdwAENvSOXevn2RQQdRkV0SaIFx0zwCjO4QdJMkQ8nyInDDDSHx91mgkMc1GgUhPNpfEkuvaYXc9oLILN38g1fD9TfA/Q9xfIEf0AVuNsQMWJyhBaYupZq8z2PpKCYdVW2EbUuCWdyVEyzRzbNEe8k0+8RPsw7uO9Ap0XFaoDUzRoirmxM8906CXbM2mYXKyG0V6GwrIMWRm2PkMiH4AS2gZEtcsMs0CTEJUXZ2jtmeT9ZugfGsbwLWpFkb+Q=='
- init vector = 'GuvsCWkJO51r6PVSOPFL9A=='
- aes ciphertext = 'M6u9Cck2j4Lg4wFwRHDGIQ=='
- Loading global parameters...
- No error (0)
- Generating scheme parameters and secret key...
- No error (0)
- public params input = 'fwORsUPDOdb0etEQ8nXgM765TneErDKp9OTFiAAHNIBqwsy/UypT+5vWuhH2FGu4cwQ3iNS1qdvrYjzsBQk+x4KLtba/3ZLRnYM7ijf8L7YaztDneg5D4PA/udUYRZWIJT9WlvTzCQ5DP8ojilwkzL4BaflrVeWMYZfs5J/gFngIO0lOoG89fQmCG6vYzQAzEW/X1mgwTaZGy9gNTsi7AgQag6xUBBdFu+eAOgxhVS0AnPwLzokgVLTNyQA38GT2JPrpIuQsy3kh6rWk1u4MEa6Zp7KlbiZd+B9vd+HyIBX2ulABimVKLbNzyJuqVOtvG2xzttidrgAGlOP+n5aIiUant8+P+fwgil0PaQ4s6bleTf6BS6bAzdwoTZZSA04Hx7lQq6Wz0NE6Ee+5OnB+0osja71kMjWWJFcc6cUIACOk6lgJiCRXmbsW/1KSqTjOytbTujUAgnsR2DP1HyG9alJAhbgMFoJmPlXKdLYLIaxgvZfuyu3FH9DMHMqXj/HpRmSh9+rA944VxmkYAAAAAA==�'@'
- Importing public parameters...
- No error (0)
- keyfile => 'key_file'
- out_len: 376
- Base-64 decoded buffer: 28 41 74 74 72 31 2c 41 74 74 72 32 2c 41 74 74 72 33 29 00 03 00 00 00 4d ae 4e a9 92 ed f3 42 5e fb f5 9e d7 20 83 14 93 1f 06 ac 33 40 72 2e b1 bf 5d 18 81 ad 94 5f 4a 07 71 f2 66 16 92 68 6b fd be 86 a1 c6 c9 5b 0a 45 56 79 c6 cc 83 a7 75 5b 4c 08 7e 3c 8e 18 95 18 41 38 c1 a5 03 01 fe b0 03 84 e1 1e 4a ca 65 c9 d0 a6 00 6f 16 90 42 f1 fe c1 ea 9c 83 3f ec bc cd 74 90 b2 b2 c7 a1 98 f0 38 9e 61 f5 bf 4c 4c ae ba e4 0b 00 8f 60 fb ae d6 a5 6d 44 8d 53 08 af 80 e1 8a da 51 a3 21 2f f7 85 04 44 46 ce 8d ec 48 b6 91 a5 c1 7e 28 0b 3e d6 12 46 df eb 22 d1 71 e3 cf 9e c7 31 00 81 a4 22 7a 47 32 fd 22 19 68 37 7c 28 cb 1b 42 af 7f 3e ac 2a 2a 7b 45 76 b4 5d 2e 00 82 9b 12 dd b4 1d 74 8c ec 3d 95 fa 76 82 62 30 09 92 8a 4d eb bd 5e d0 be 62 64 51 01 47 61 93 26 ec 3e 43 c0 3c 03 38 e8 0b bd 6c 08 28 f0 95 17 68 0f ec cf e1 ae 48 41 01
- Importing secret key...
- No error (0)
- running libfenc_get_attribute_index_in_list
- found: 9330343389436777432774806010838379822496920567713207609639801066414
- found: 12897582061484440647626205166858515037561919287927948242788041630532
- found: 3456098104092453560102604953110158625385794332821633597398365174053
- Decrypting the ciphertext...
- No error (0)
- Decrypted session key is: 28 36 ee 34 df b9 e1 88 c5 f1 0b 05 d2 d3 11 11
- IV: 1a eb ec 09 69 09 3b 9d 6b e8 f5 52 38 f1 4b f4
- Recovered magic: 'ABE|'
- <span style="color:#ff0000;"><strong>Plaintext: haha</strong></span>
- Destroying the encryption context...
- No error (0)
- Shutting down library...
- No error (0)
成功解密
参阅
http://blog.csdn.net/novostary/article/details/21883537
http://www.cnblogs.com/rockorange/p/3757805.html