函数加密库fenc - abe-pchr.docx_第1页
函数加密库fenc - abe-pchr.docx_第2页
函数加密库fenc - abe-pchr.docx_第3页
函数加密库fenc - abe-pchr.docx_第4页
函数加密库fenc - abe-pchr.docx_第5页
免费预览已结束,剩余11页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

函数加密库libfenc项目简介Libfenc为开源项目,源码托管于/p/libfenc/,使用c语言编写,使用SVN作版本管理,使用Autotools作项目源码管理,可编译运行于多种系统平台。Libfenc支持两类属性加密方案:CP-ABE, KP-ABE具体实现三种方案:l FENC_SCHEME_LSWa KP-ABE scheme over non-monotonic access structure, based on Section 6.1 of the following paper.“Lewko, Sahai and Waters: Revocation Systems with Very Small Private Keys.”l FENC_SCHEME_WATERSCPa CP-ABE scheme, based on the relatively recent scheme described in Appendix C of the following paper.“Waters: Ciphertext-Policy Attribute-Based Encryption: An Expressive, Effcient, and Provably Secure Realization.”l FENC_SCHEME_WATERSSIMPLECPa variant of the CP-ABE scheme above. Its based on the scheme in Appendix D of that paper, but employs a random oracle for efficiencly.“Waters: Ciphertext-Policy Attribute-Based Encryption: An Expressive, Effcient, and Provably Secure Realization.”项目结构l Libfenc库提供两类属性加密方案的相关函数实现l Toolkit基于libfenc库实现的可用的属性加密程序工具集l Benchmark测试用例程序集安装指南Libfenc库及相关套件需从源码编译,Linux环境下使用gcc编译器,Windows环境下使用MinGW编译器。编译前需安装依赖库:gmp: 高精度运算库(/)pbc: 配对加密库(/pbc/)openssl: 密码学库(/)bison: 语法解析器生成器Linux下编译安装使用包管理软件安装相关依赖库(openssl, gmp),编译安装pbc依赖库Ubuntu下,使用apt-get install如下软件包:bisonbuild-essentiallibgmp3-devlibssl-dev以下包也建议安装(修改项目源码有用):autoconfautomakelibtool下载pbc源码,解压,进入源码目录执行./configuremakemake install进入libfenc源码目录执行./configuremakemake install默认安装目录为/usr/local下的bin, lib, include等Windows下编译安装Windows下使用MinGW + Msys编译1. 安装mingw-get到/projects/mingw/files/下载mingw-get-inst在线安装包安装2. 安装gmp库打开msys执行:mingw-get install gmp3. 源码编译pbc库到/pbc/download.html下载pbc源码,解压到临时目录,打开Msys终端,进入pbc源码目录执行:./configure LDFLAGS=-L/mingw/lib CPPFLAGS=-I/mingw/include -enable-shared -disable-staticmake & make install安装后的文件中/usr/local4. 安装配置openssl库n 法1(推荐)到/source/下载最新源码,解压到临时目录,使用Msys执行以下命令编译openssl库shared版:./Configure mingw sharedmake & make install_sw安装后的文件在/usr/local/ssl使用该方法无需修改libfenc源码配置,但编译libfenc后的程序要带上libeay32.dll动态链接库n 法2openssl库使用官方Windows开发版(这里下载:/products/Win32OpenSSL.html)安装后将相关的lib和include目录复制到Msys的/usr/local/ssl下openssl库在Windows上名为libeay32(crypto)和ssleay32(ssl),需要对libfenc编译脚本做修改:configure.ac:将crypto替换为libeay32tool/Makefile.am:将crypto替换为libeay32执行autoreconf运行编译后的libfenc程序要带上libeay32.dlln 法3:openssl库使用MinGW编译版(静态编译: Configure mingw)openssl库名称和linux版一样,但需要额外链接gdi32库:libfenc项目源码的配置文件configure.ac加入:#ifdef WIN32_LEAN_AND_MEAN LIBS=$LIBS -lgdi32#endif 5. 解决源代码宏定义错误Windows下使用MinGW编译libfenc可能出现宏定义冲突,具体要对libfenc进行修改,在n tool/common.h里SIZE宏与windows系统定义冲突,改SIZE为BUFSIZE(或其他名字,之前修改成KEYSIZE)n tool目录下相应的mgabe-keygen.c, mgabe-enc.c, mgabe-dec.c里宏定义区加入:#define SIZE BUFSIZE6. 编译libfenc打开MSys进入libfenc源码目录执行以下命令编译:./configure LDFLAGS=-L/mingw/lib -L/usr/local/lib -L/usr/local/ssl/lib CPPFLAGS=-I/mingw/include -I/usr/local/include -I/usr/local/ssl/include -enable-shared -disable-staticmake & make install安装后的文件中/usr/local注:fenc-0.2.0-mod是修改过的源码(法2,mod2结尾的是按法3修改),用于windows下编译fenc_dist_mingw_ssl_shared.7z等是windows下的可执行文件(使用mingw shared版openssl库)编译的清理指令有make clean、make distclean、make uninstall等autotools管理指令有autoreconf等用户手册libfenc库的使用libfenc库文件为libfenc.a,基于其开发的程序源码使用gcc的-lfenc参数编译,使用-Lxxx指定库路径,使用-Ixxx指定头文件路径。Tookit的使用abe-setup, abe-keygen, abe-enc, abe-dec, policy-test等程序,前四个分别完成ABE加密方案的Setup, KeyGen, Encrypt, Decrypt的功能,policy-test用于测试访问策略。简单使用如下(见libfenc项目Wiki: /p/libfenc/wiki/FENCToolkitHelp):The following sample commands apply to the ciphertext-policy CP-ABE scheme: n Create master secret and public parameters abe-setup -m CP n Generate key for users attributes abe-keygen -m CP -a ONE,TWO,THREE,FOUR,FIVE -o userCP.key n Encrypt an input file under a given policy abe-enc -m CP -i filename.txt -p (ONE and TWO) or THREE) -o outfile n Decrypt a file given the users secret key abe-dec -m CP -k userCP.key -f outfile.cpabe The following sample commands apply to the key-policy KP-ABE scheme: n Create master secret and public parameters abe-setup -m KP n Generate a key with a given policy abe-keygen -m KP -p (ONE and TWO) or THREE) -o userKP.key n Encrypt an input file under a set of attributes abe-enc -m KP -i filename.txt -a ONE,TWO,THREE,FOUR,FIVE -o outfile n Decrypt a file given the users secret key abe-dec -m KP -k userKP.key -f outfile.kpabe 注:1. CP-ABE密钥生成时输入属性,加密时输入访问策略;KP-ABE相反,密钥生成时输入访问策略,加密时输入属性。2. SCP方案尚未完成。3. 执行前需要在当前目录准备一个待加密文件(如filename.txt, 文本文件)和配对(pairing)参数文件(如d224.param, 可由pbc程序生成)。4. 访问策略支持与(and)、或(or)和门限(, , =, =,相应的属性形式为Att=xx,不完善,需要修改源代码)。示例l CP-ABE以下各步骤均隐含输入配对(pairing)参数文件d224.paramn Setup执行命令:abe-setup -m CP 输入:方案名称CP输出:主私钥参数文件secret.param.cp,公共参数文件public.param.cp截图:n Key-Gen执行命令:abe-keygen -m CP -a ONE,TWO,THREE,FOUR,FIVE -o userCP.key 输入:方案名称CP,属性列表ONE,TWO,THREE,FOUR,FIVE,主私钥参数文件secret.param.cp,公共参数文件public.param.cp输出:用户私钥文件userCP.key截图:n Encrypt执行命令:abe-enc -m CP -i filename.txt -p (ONE and TWO) or THREE) -o outfile 输入:方案名称CP,公共参数文件public.param.cp,待加密文件filename.txt,访问策略(ONE and TWO) or THREE)输出:密文文件outfile.cpabe截图:n Decrypt执行命令:abe-dec -m CP -k userCP.key -f outfile.cpabe 输入:方案名称CP,待解密文件outfile.cpabe,用户私钥文件userCP.key,公共参数文件public.param.cp输出:明文消息截图:开发指南gmp库相关gmp库文档在/manual/。gmp库是c语言开发的开源高精度数值运算库,是pbc库和libfenc库的依赖。Libfenc库主要应用其大整数运算的一些函数,部分相关介绍如下:l 数据类型mpz_t高精度整数类型l 整数运算相关函数void mpz_init (mpz_t x)初始化void mpz_clear (mpz_t x)清理void mpz_add (mpz_t rop, mpz_t op1, mpz_t op2)加法op1 + op2void mpz_sub (mpz_t rop, mpz_t op1, mpz_t op2)减法op1 op2void mpz_mul (mpz_t rop, mpz_t op1, mpz_t op2)乘法op1 * op2void mpz_powm (mpz_t rop, mpz_t base, mpz_t exp, mpz_t mod)模指数void mpz_nextprime (mpz_t rop, mpz_t op)下一素数int mpz_invert (mpz_t rop, mpz_t op1, mpz_t op2)求逆元Compute the inverse of op1 modulo op2 and put the result in rop.void mpz_random (mpz_t rop, mp_size_t max_size)产生随机数l 输入输出函数size_t mpz_out_str (FILE *stream, int base, mpz_t op)字符串输出size_t mpz_inp_str (mpz_t rop, FILE *stream, int base)字符串输入pbc库相关pbc库文档在/pbc/manual/。pbc库在gmp库之上开发,提供了椭圆曲线群上的配对运算(pairing)支持。l 编程约定PBC follows GMP in several respects:n Output arguments generally precede input arguments.n The same variable can be used as input and output in one call.n Before a variable may be used it must be initialized exactly once. When no longer needed it must be cleared. For efficiency, unnecessary initializating and clearing should be avoided.n PBC variables ending with _t behave the same as GMP variables in function calls: effectively as call-by references. In other words, as in GMP, if a function that modifies an input variable, that variable remains modified when control return is returned to the caller.n Like GMP, variables automatically allocate memory when needed. By default, malloc() and friends are called but this can be changed.n PBC functions are mostly reentrant.l 数据类型n element_t: elements of an algebraic structure.n pairing_t: pairings where elements belong; can initialize from sample pairing parameters bundled with PBC in the param subdirectory.n pbc_param_t: used to generate pairing parameters.n pbc_cm_t: parameters for constructing curves via the CM method; sometimes required by pbc_param_t.n field_t: algebraic structures: groups, rings and fields; used internally by pairing_t.n a few miscellaneous functions, such as ones controlling how random bits are generated.l 相关函数n 初始化void element_init_G1(element_t e, pairing_t pairing)void element_init_G2(element_t e, pairing_t pairing)void element_init_GT(element_t e, pairing_t pairing)Initialize e to be an element of the group G1, G2 or GT of pairing.void element_init_Zr(element_t e, pairing_t pairing)void element_clear(element_t e)清理n 赋值void element_set0(element_t e)void element_set1(element_t e)void element_set_si(element_t e, signed long int i)void element_set_mpz(element_t e, mpz_t z)void element_set(element_t e, element_t a)n 转换void element_to_mpz(mpz_t z, element_t e)到mpz_t格式void element_from_hash(element_t e, void *data, int len)从hash值映射n 群元素运算void element_add(element_t n, element_t a, element_t b)Set n to a + b.void element_sub(element_t n, element_t a, element_t b)Set n to a - b.void element_mul(element_t n, element_t a, element_t b)Set n = a b.void element_invert(element_t n, element_t a)Set n to the inverse of a.void element_pow_mpz(element_t x, element_t a, mpz_t n)void element_pow_zn(element_t x, element_t a, element_t n)模指数运算Set x = an, that is a times a times times a where there are n element_cmp(element_t a, element_t b)比较运算Returns 0 if a and b are the same, nonzero otherwise.void element_random(element_t e)随机生成元素n 配对运算int pairing_init_set_str(pairing_t pairing, const char *s)int pairing_init_set_buf(pairing_t pairing, const char *s, size_t len)void pairing_init_pbc_param(struct pairing_s *pairing, pbc_param_t p)void pairing_clear(pairing_t pairing)初始化和清理void element_pairing(element_t out, element_t in1, element_t in2)双线性映射Computes a pairing: out = e(in1, in2), where in1, in2, out must be in the groups G1, G2, GT.n 配对参数相关int pbc_param_init_set_str(pbc_param_t par, const char *s)从字符串初始化void pbc_param_clear(pbc_param_t p)清理void pbc_param_init_a_gen(pbc_param_t par, int rbits, int qbits)生成type a参数l 配对参数类型pbc库支持的配对类型指标见/pbc/times.html。 openssl库相关openssl库文档在/docs/。openssl的密码学库(crypto)提供了AES等对称加密算法,SHA1等散列算法和安全随机数生成函数。l 对称加密(aes.h)AES_KEY密钥类型int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key);int AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key);设置加/解密密钥void AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key);void AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key);加/解密void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,size_t length, const AES_KEY *key,unsigned char *ivec, const int enc);CBC模式加/解密l 随机数相关(rand.h)int RAND_bytes(unsigned char *buf, int num);生成不可预测的强伪随机数libfenc库开发l 文件简介|- Makefile.amMakefile脚本配置文件,Autotools的输入文件之一|- abe_policy.h|- abe_policy.tab.c|- abe_policy.y访问策略解析器源文件|- benchmark测试用例源文件|- configure配置脚本,由Autotools生成|- configure.acconfigure脚本配置文件,Autotools的输入文件之一|- libfenc.c|- libfenc.hLibfenc库主头文件和实现|- libfenc_ABE_common.c|- libfenc_ABE_common.h属性加密公共函数,处理属性列表和访问控制树|- libfenc_LSSS.c|- libfenc_LSSS.h线性密秘分享的相关运算|- libfenc_LSW.c|- libfenc_LSW.hLSW方案:KP-ABE方案|- libfenc_WatersCP.c|- libfenc_WatersCP.hWatersCP方案:CP-ABE方案|- libfenc_WatersSimpleCP.c|- libfenc_WatersSimpleCP.hWatersSimpleCP方案:CP-ABE方案|- libfenc_group_params.c|- libfenc_group_params.h配对(群)参数处理函数|- libfenc_utils.c|- libfenc_utils.hLibfenc库相关函数,主要处理一些参数的转换|- param| |- a.param| - d224.param配对(群)参数,可由pbc库生成|- sha1.c|- sha1.hHash函数库- toolsToolkit(工具集)代码 |- Makefile.am |- base64.c |- base64.hBase64编码库 |- common.c |- common.h公共头文件 |- mgabe-dec.c解密 |- mgabe-enc.c加密 |- mgabe-keygen.c密钥生成 |- mgabe-setup.c参数设置 - policy-tool.c访问策略检测程序l 访问策略修改1Libfenc函数库的访问策略实现不完善,对于数值型属性和门限策略处理可能出问题,如属性ONE=3,TWO=2,策略ONE=2 and ONEattributei.attribute_str, 0, MAX_ATTRIBUTE_STR); sprintf(char *)attribute_list-attributei.attribute_str, %s_flexint_uint, attr); i+;作以下添加+ memset(attribute_list-attributei.attribute_str, 0, MAX_ATTRIBUTE_STR);+printf(char *)attribute_list-attributei.attribute_str, %s_flexint_%s, attr, value);+i+;l 开发步骤1. 初始化err_code = libfenc_init();2. 创建加密上下文fenc_context co

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论