zoukankan      html  css  js  c++  java
  • 64位Ubuntu下配置CP-ABE环境

    CP-ABE环境配置

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

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

    [plain] view plain copy
     
    1. sudo apt-get install M4  
    2. sudo apt-get install flex  
    3. sudo apt-get install bison  

    1  安装gmp

    下载https://gmplib.org/

    [plain] view plain copy
     
    1. lzip -d gmp-6.1.0.tar.lz  
    2. tar -zxvf gmp-6.1.0.tar  
    3. cd gmp-6.1.0  
    4.   
    5. ./configure  
    6. make  
    7. make check  
    8. sudo make install  
    
    
    

    2  安装pbc

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

    [plain] view plain copy
     
    1. tar -zxvf pbc-0.5.14.tar.gz  
    2. cd pbc-0.5.14  
    [plain] view plain copy
     
    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/

    [plain] view plain copy
     
    1. tar -zxvf openssl-1.0.1t.tar.gz  
    2. cd openssl-1.0.1  
    3.   
    4. ./configure  
    5. make  
    6. sudo make install  

    4 安装libbswcpabe

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

    [plain] view plain copy
     
    1. tar -zxvf libbswabe-0.9.tar.gz  
    2. cd libbswabe-0.9  
    
    
    [plain] view plain copy
     
    1. ./configure  
    2. make  
    3. sudo make install  

    make出现问题

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

    运行

    [plain] view plain copy
     
    1. sudo apt-get install libglib2.0-dev  

    重新编译

    [plain] view plain copy
     
    1. ./configure  
    2. make  
    3. sudo make install  

    5 安装cpabe

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

    [plain] view plain copy
     
    1. tar -zxvf cpabe-0.11.tar.gz  
    2. cd  cpabe-0.11/  
    [plain] view plain copy
     
    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 出现问题

    [plain] view plain copy
     
    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

    [plain] view plain copy
     
    1. make  

    出现以下问题

    [plain] view plain copy
     
    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

    [plain] view plain copy
     
    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 即可

    [plain] view plain copy
     
    1. make  
    2. sudo make install  

    编译成功

    测试

    [plain] view plain copy
     
    1. cpabe-setup -h  

    显示

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

    没问题,,成功

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

    6 安装 libenc

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

    [plain] view plain copy
     
    1. cd  libfenc  
    2.   
    3. ./configure  
    4. make  
    5. sudo make install  

    测试

    [plain] view plain copy
     
    1. cd tools/  

    初始化

    [plain] view plain copy
     
    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)  

    加密

    [plain] view plain copy
     
    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.   
    18. Encrypting data...  
    19.     Plaintext is => 'haha'.  
    20.     Ciphertext stored in 'cipertext.cpabe'.  
    21.     ABE Ciphertex size is: '826'.  
    22.     AES Ciphertext size is: '16'.  
    23. Shutting down library...  
    24.     No error (0)  

    生成密钥

    [plain] view plain copy
     
    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)  

    解密

    [plain] view plain copy
     
    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 = '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=='  
    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



    Windy心梦无痕
  • 相关阅读:
    Velocity模版进行shiro验证
    freemarker中使用shiro标签
    freemarker中使用shiro标签
    freemarker中使用shiro标签
    Maven引入自定义jar包
    Maven引入自定义jar包
    Maven引入自定义jar包
    Spring MVC多个视图解析器及优先级
    (尚054)Vue_源码分析_模板解析_事件指令
    (尚052)+(尚053) Vue_源码分析_模板解析_大括号表达式
  • 原文地址:https://www.cnblogs.com/windy-xmwh/p/8119899.html
Copyright © 2011-2022 走看看