CP-ABE环境配置

本文密码学专业,论文仿真需要CP-ABE,现将配置过程作个记录

cpabe依赖pbc,pbc依赖gmp,gmp依赖M4、bison、flex,所以。。

  1. sudo apt-get install M4
  2. sudo apt-get install flex
  3. sudo apt-get install bison

1  安装gmp

下载https://gmplib.org/

  1. lzip -d gmp-6.1.0.tar.lz
  2. tar -zxvf gmp-6.1.0.tar
  3. cd gmp-6.1.0
  4. ./configure
  5. make
  6. make check
  7. sudo make install

2  安装pbc

下载https://crypto.stanford.edu/pbc/download.html

  1. tar -zxvf pbc-0.5.14.tar.gz
  2. cd pbc-0.5.14
  1. </pre><pre code_snippet_id="1719527" snippet_file_name="blog_20160616_14_9454922" name="code" class="plain">./configure
  2. make
  3. sudo make install

3 安装openSSL

下载https://www.openssl.org/source/

  1. tar -zxvf openssl-1.0.1t.tar.gz
  2. cd openssl-1.0.1
  3. ./configure
  4. make
  5. sudo make install

4 安装libbswcpabe

下载http://acsc.cs.utexas.edu/cpabe/

  1. tar -zxvf libbswabe-0.9.tar.gz
  2. cd libbswabe-0.9

  1. ./configure
  2. make
  3. sudo make install

make出现问题

  1. core.c:9:18: fatal error: glib.h: 没有那个文件或目录
  2. #include <glib.h>
  3. ^
  4. compilation terminated.
  5. make: *** [core.o] 错误 1

运行

  1. sudo apt-get install libglib2.0-dev

重新编译

  1. ./configure
  2. make
  3. sudo make install

5 安装cpabe

下载http://acsc.cs.utexas.edu/cpabe/

  1. tar -zxvf cpabe-0.11.tar.gz
  2. cd  cpabe-0.11/
  1. </pre><pre code_snippet_id="1719527" snippet_file_name="blog_20160616_14_9454922" name="code" class="plain">./configure
  2. make
  3. sudo make install

make 出现问题

  1. //usr/local/lib/libgmp.so: error adding symbols: DSO missing from command line
  2. collect2: error: ld returned 1 exit status
  3. make: *** [cpabe-setup] 错误 1

解决:修改Makefile,LDFLAGS最后加入-lgmp

  1. make

出现以下问题

  1. policy_lang.y: In function ‘yyparse’:
  2. policy_lang.y:67:38: error: expected ‘;’ before ‘}’ token
  3. result: policy { final_policy = $1 }
  4. ^
  5. make: *** [policy_lang.o] 错误 1<pre name="code" class="plain">cpabe-setup -h

解决:67行 } 前加 ;j即可

64位操作系统还有一些worning

  1. policy_lang.y: In function ‘eq_policy’:
  2. policy_lang.y:212:4: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat=]
  3. (g_strdup_printf("%s_flexint_%llu", attr, n->value));
  4. ^
  5. policy_lang.y:215:4: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ [-Wformat=]
  6. (g_strdup_printf("%s_expint%02d_%llu", attr, n->bits, n->value));
  7. ^
  8. policy_lang.y: In function ‘yylex’:
  9. policy_lang.y:391:3: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 3 has type ‘uint64_t *’ [-Wformat=]
  10. sscanf(s->str, "%llu", &(yylval.nat));
  11. ^
  12. policy_lang.y: In function ‘parse_attribute’:
  13. policy_lang.y:577:3: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 4 has type ‘uint64_t *’ [-Wformat=]
  14. if( sscanf(a, " %s = %llu # %u ", s, &value, &bits) == 3 )
  15. ^
  16. policy_lang.y:596:5: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ [-Wformat=]
  17. (*l, g_strdup_printf("%s_expint%02d_%llu", s, bits, value));
  18. ^
  19. policy_lang.y:598:3: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 4 has type ‘uint64_t *’ [-Wformat=]
  20. else if( sscanf(a, " %s = %llu ", s, &value) == 2 )
  21. ^
  22. policy_lang.y:612:5: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat=]
  23. (*l, g_strdup_printf("%s_flexint_%llu", s, value));

解决:%llu都改为 %lu 即可

  1. make
  2. sudo make install

编译成功

测试

  1. cpabe-setup -h

显示

  1. Usage: cpabe-setup [OPTION ...]
  2. Generate system parameters, a public key, and a master secret key
  3. for use with cpabe-keygen, cpabe-enc, and cpabe-dec.
  4. Output will be written to the files "pub_key" and "master_key"
  5. unless the --output-public-key or --output-master-key options are
  6. used.
  7. Mandatory arguments to long options are mandatory for short options too.
  8. -h, --help                    print this message
  9. -v, --version                 print version information
  10. -p, --output-public-key FILE  write public key to FILE
  11. -m, --output-master-key FILE  write master secret key to FILE
  12. -d, --deterministic           use deterministic "random" numbers
  13. (only for debugging)

没问题,,成功

还有一个abe更具体的实现 libfenc

6 安装 libenc

下载https://code.google.com/archive/p/libfenc/downloads

  1. cd  libfenc
  2. ./configure
  3. make
  4. sudo make install

测试

  1. cd tools/

初始化

  1. ./abe-setup -m CP
  2. Generating Waters CP scheme parameters...
  3. Initializing library...
  4. No error (0)
  5. Generating master ABE system parameters...
  6. Loading global parameters...
  7. No error (0)
  8. Generating scheme parameters and secret key...
  9. No error (0)
  10. Exporting public parameters...
  11. No error (0)
  12. Base-64 encoding public parameters...
  13. 'fwORsUPDOdb0etEQ8nXgM765TneErDKp9OTFiAAHNIBqwsy/UypT+5vWuhH2FGu4cwQ3iNS1qdvrYjzsBQk+x4KLtba/3ZLRnYM7ijf8L7YaztDneg5D4PA/udUYRZWIJT9WlvTzCQ5DP8ojilwkzL4BaflrVeWMYZfs5J/gFngIO0lOoG89fQmCG6vYzQAzEW/X1mgwTaZGy9gNTsi7AgQag6xUBBdFu+eAOgxhVS0AnPwLzokgVLTNyQA38GT2JPrpIuQsy3kh6rWk1u4MEa6Zp7KlbiZd+B9vd+HyIBX2ulABimVKLbNzyJuqVOtvG2xzttidrgAGlOP+n5aIiUant8+P+fwgil0PaQ4s6bleTf6BS6bAzdwoTZZSA04Hx7lQq6Wz0NE6Ee+5OnB+0osja71kMjWWJFcc6cUIACOk6lgJiCRXmbsW/1KSqTjOytbTujUAgnsR2DP1HyG9alJAhbgMFoJmPlXKdLYLIaxgvZfuyu3FH9DMHMqXj/HpRmSh9+rA944VxmkYAAAAAA=='
  14. Exporting secret parameters...
  15. No error (0)
  16. Base-64 encoding secret parameters...
  17. 'fiK5Eh1+z4jtsBMARFx9yheRmfLWPlS8M0bBHw=='
  18. Destroying context...
  19. No error (0)
  20. Shutting down library...
  21. No error (0)

加密

  1. #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
  2. Encrypting for Waters CP scheme...
  3. Loading global parameters...
  4. No error (0)
  5. Generating scheme parameters and secret key...
  6. No error (0)
  7. Reading the public parameters file = public.param.cp
  8. DEBUG: Policy -- '((Attr1 and Attr2) or Attr3)'
  9. Hashed Attr1 to 9330343389436777432774806010838379822496920567713207609639801066414
  10. share 0 is 6856445857519078318242964707612121029817614998351926048095706106450
  11. Hashed Attr2 to 12897582061484440647626205166858515037561919287927948242788041630532
  12. share 1 is 2195387252221824496104266554794551033371798688446347486142373906698
  13. Hashed Attr3 to 3456098104092453560102604953110158625385794332821633597398365174053
  14. share 2 is 11517504462816332140381662860429691026263431308257504610049038306202
  15. Generated session key: 28 36 ee 34 df b9 e1 88 c5 f1 0b 05 d2 d3 11 11
  16. IV: 1a eb ec 09 69 09 3b 9d 6b e8 f5 52 38 f1 4b f4
  17. Encrypting data...
  18. Plaintext is => 'haha'.
  19. Ciphertext stored in 'cipertext.cpabe'.
  20. ABE Ciphertex size is: '826'.
  21. AES Ciphertext size is: '16'.
  22. Shutting down library...
  23. No error (0)

生成密钥

  1. #38#^_^@bruvelv-Lenovo-Y430P:~/ABE/libfenc/tools$ ./abe-keygen -m CP -a Attr1,Attr2,Attr3 -p Attr3 -o key_file
  2. Generating private key for Waters CP scheme...
  3. Generating your private key...
  4. Loading global parameters...
  5. No error (0)
  6. Generating scheme parameters and secret key...
  7. No error (0)
  8. Reading the public parameters file = public.param.cp
  9. Reading the secret parameters file = secret.param.cp
  10. public params input = 'fwORsUPDOdb0etEQ8nXgM765TneErDKp9OTFiAAHNIBqwsy/UypT+5vWuhH2FGu4cwQ3iNS1qdvrYjzsBQk+x4KLtba/3ZLRnYM7ijf8L7YaztDneg5D4PA/udUYRZWIJT9WlvTzCQ5DP8ojilwkzL4BaflrVeWMYZfs5J/gFngIO0lOoG89fQmCG6vYzQAzEW/X1mgwTaZGy9gNTsi7AgQag6xUBBdFu+eAOgxhVS0AnPwLzokgVLTNyQA38GT2JPrpIuQsy3kh6rWk1u4MEa6Zp7KlbiZd+B9vd+HyIBX2ulABimVKLbNzyJuqVOtvG2xzttidrgAGlOP+n5aIiUant8+P+fwgil0PaQ4s6bleTf6BS6bAzdwoTZZSA04Hx7lQq6Wz0NE6Ee+5OnB+0osja71kMjWWJFcc6cUIACOk6lgJiCRXmbsW/1KSqTjOytbTujUAgnsR2DP1HyG9alJAhbgMFoJmPlXKdLYLIaxgvZfuyu3FH9DMHMqXj/HpRmSh9+rA944VxmkYAAAAAA=='
  11. secret params input = 'fiK5Eh1+z4jtsBMARFx9yheRmfLWPlS8M0bBHw=='
  12. Importing public parameters...
  13. No error (0)
  14. Importing secret parameters...
  15. No error (0)
  16. DEBUG: Attribute list -- '(Attr1,Attr2,Attr3)'
  17. Hashed Attr1 to 9330343389436777432774806010838379822496920567713207609639801066414
  18. Hashed Attr2 to 12897582061484440647626205166858515037561919287927948242788041630532
  19. Hashed Attr3 to 3456098104092453560102604953110158625385794332821633597398365174053
  20. Extracting a decryption key...
  21. No error (0)
  22. Exporting key...
  23. No error (0)
  24. Destroying context...
  25. No error (0)
  26. Shutting down library...
  27. No error (0)

解密

  1. #39#^_^@bruvelv-Lenovo-Y430P:~/ABE/libfenc/tools$ ./abe-dec -m CP -k key_file -f cipertext.cpabe
  2. Decrypting under Waters CP scheme...
  3. Private-key file = 'key_file'
  4. Encrypted file = 'cipertext.cpabe'
  5. out_len: 1194
  6. abe ciphertext = 'AgAAABAAAAADAAAAKChBdHRyMSBhb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ZugfGsbwLWpFkb+Q=='
  7. init vector = 'GuvsCWkJO51r6PVSOPFL9A=='
  8. aes ciphertext = 'M6u9Cck2j4Lg4wFwRHDGIQ=='
  9. Loading global parameters...
  10. No error (0)
  11. Generating scheme parameters and secret key...
  12. No error (0)
  13. public params input = 'fwORsUPDOdb0etEQ8nXgM765TneErDKp9OTFiAAHNIBqwsy/UypT+5vWuhH2FGu4cwQ3iNS1qdvrYjzsBQk+x4KLtba/3ZLRnYM7ijf8L7YaztDneg5D4PA/udUYRZWIJT9WlvTzCQ5DP8ojilwkzL4BaflrVeWMYZfs5J/gFngIO0lOoG89fQmCG6vYzQAzEW/X1mgwTaZGy9gNTsi7AgQag6xUBBdFu+eAOgxhVS0AnPwLzokgVLTNyQA38GT2JPrpIuQsy3kh6rWk1u4MEa6Zp7KlbiZd+B9vd+HyIBX2ulABimVKLbNzyJuqVOtvG2xzttidrgAGlOP+n5aIiUant8+P+fwgil0PaQ4s6bleTf6BS6bAzdwoTZZSA04Hx7lQq6Wz0NE6Ee+5OnB+0osja71kMjWWJFcc6cUIACOk6lgJiCRXmbsW/1KSqTjOytbTujUAgnsR2DP1HyG9alJAhbgMFoJmPlXKdLYLIaxgvZfuyu3FH9DMHMqXj/HpRmSh9+rA944VxmkYAAAAAA==�'@'
  14. Importing public parameters...
  15. No error (0)
  16. keyfile => 'key_file'
  17. out_len: 376
  18. 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
  19. Importing secret key...
  20. No error (0)
  21. running libfenc_get_attribute_index_in_list
  22. found: 9330343389436777432774806010838379822496920567713207609639801066414
  23. found: 12897582061484440647626205166858515037561919287927948242788041630532
  24. found: 3456098104092453560102604953110158625385794332821633597398365174053
  25. Decrypting the ciphertext...
  26. No error (0)
  27. Decrypted session key is: 28 36 ee 34 df b9 e1 88 c5 f1 0b 05 d2 d3 11 11
  28. IV: 1a eb ec 09 69 09 3b 9d 6b e8 f5 52 38 f1 4b f4
  29. Recovered magic: 'ABE|'
  30. <span style="color:#ff0000;"><strong>Plaintext: haha</strong></span>
  31. Destroying the encryption context...
  32. No error (0)
  33. Shutting down library...
  34. No error (0)

成功解密

参阅

http://blog.csdn.net/novostary/article/details/21883537

http://www.cnblogs.com/rockorange/p/3757805.html

64位Ubuntu下配置CP-ABE环境的更多相关文章

  1. 64位ubuntu下重新编译hadoop2.2流水账

    hadoop官方网站中只提供了32位的hadoop-2.2.0.tar.gz,如果要在64位ubuntu下部署hadoop-2.2.0,就需要重新编译源码包,生成64位的部署包.建议以下操作使用roo ...

  2. 64位ubuntu下Android开发环境的配置

    本文介绍如何在64位ubuntu上搭建android的开发环境. 系统:ubuntu12.04LTS 使用的是ADT Bundle for Linux和jdk1.7(open jdk也可) 一共分为3 ...

  3. 64位ubuntu下安装微博客户端的方法

    最近安装了12.04的ubuntu系统,在unbutu提供的软件中心找不到微博客户端的应用,但在新浪的http://sinatair.sinaapp.com/下找到了官方的客户端. 于是下载了linu ...

  4. 64位Ubuntu下的Eclipse、ADT终于可以生成R.java了,虚机也可以正常建立

    64位Ubuntu12下的Eclipse总也不能自动生成R.java,导致无法正常编译程序,建虚拟器的时候总是提示少文件....三天下班机器没关(无奈公司网络不给力)来安装lib包. 各种加载,总结一 ...

  5. 用 xampp 在ubuntu 下配置php 运行环境 lampp

      在linux下搭建php的运行环境,可以分别安装apache.mysql .php .phpmyadmin,也可以安装xampp(apache.mysql .php .phpmyadmin)集成包 ...

  6. Ubuntu下配置Hyperledger Fabric环境

    在win10系统的台式机上安装配置Hyperledger Fabric环境 安装Ubuntu 16.04 双系统 镜像下载地址:https://www.ubuntu.com/download/desk ...

  7. 64位ubuntu下用code::blocks IDE配置opengl开发环境

    http://jingyan.baidu.com/article/c74d60007d104f0f6b595d6d.html 样例程序: #include <GL/glut.h> #inc ...

  8. 在ubuntu下配置android开发环境

    http://developer.android.com/sdk/installing/index.html 基本上上面官网的链接可以解决所有问题,但是具体在安装过程中还是有一些坑. 说说具体流程 1 ...

  9. Ubuntu下配置Scheme开发环境

    MIT-Scheme环境 http://www.gnu.org/software/mit-scheme/ 在官网下载安装包,编译安装即可,期间会提示找不到m4这个库,安装即可 Scheme自带的交互环 ...

随机推荐

  1. Android之使用传感器获取相应数据

    Android的大部分手机中都有传感器,传感器类型有方向.加速度(重力).光线.磁场.距离(临近性).温度等. 方向传感器:   Sensor.TYPE_ORIENTATION 加速度(重力)传感器: ...

  2. 把一个List拆分为几个大小一样的List

    static void Main(string[] args) { List<String> tarArr = new List<String>(); tarArr.Add(& ...

  3. 基于 Python 和 Pandas 的数据分析(2) --- Pandas 基础

    在这个用 Python 和 Pandas 实现数据分析的教程中, 我们将明确一些 Pandas 基础知识. 加载到 Pandas Dataframe 的数据形式可以很多, 但是通常需要能形成行和列的数 ...

  4. 转csdn某位同学的 感谢bmfont

    UGUI 使用BMFont 首先要知道 Custom Font 的原理,不知道的同学可以先看这篇[Custom Font 原理](http://blog.csdn.net/liqiangeastsun ...

  5. codeforces gym 100971 K Palindromization 思路

    题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...

  6. jquery.js 3.0报错, Uncaught TypeError: url.indexOf is not a function

    转载自:http://majing.io/questions/432   问题描述 jQuery升级到3.0.0后类型错误 jquery.js:9612 Uncaught TypeError: url ...

  7. eclipse导入项目文件以及 import项目文件后有个红色感叹号

    eclipse导入项目文件 步骤:File —>Import—>General—>Existing Projects into Workspace 然后进去选择项目文件的具体路径即可 ...

  8. python中socket模块详解

    socket模块简介 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.socket通常被叫做"套接字",用于描述IP地址和端口,是一个通信 ...

  9. selenium+Page Objects(第二话)

    前面介绍了什么是po模式,并且简单分析了一下使用po模式编写脚本的思路,接下来开始正式编写 1.先编写一个页面基类BasePage.py,里面封装每个页面常用的一些方法 # coding: utf-8 ...

  10. FreeRTOS

    一.内核配置 1.configUSE_PREEMPTION 设置为1,使用抢先式内核:设置为0,为合作轮转内核. 2.configCPU_CLOCK_HZ 内部处理器执行的频率.这个值需要正确配置外围 ...