libbswabe-0.9.tar.gz

  • 我是小肉包
    了解作者
  • C/C++
    开发工具
  • 67KB
    文件大小
  • gz
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-04-24 15:38
    上传日期
实现cp-abe算法的必备包之一,在Linux上使用,在安装pbc库之前的必备库,安装pbc库还需安装m4,gmp等库,在Linux中使用tar zxvf libbswabe-0.9.tar.gz命令解压。
libbswabe-0.9.tar.gz
  • libbswabe-0.9
  • missing
    10.3KB
  • COPYING
    14.8KB
  • aclocal.m4
    8.7KB
  • INSTALL
    8.8KB
  • mkinstalldirs
    3.3KB
  • private.h
    1.4KB
  • configure
    156.6KB
  • acinclude.m4
    3.7KB
  • install-sh
    9KB
  • Makefile.in
    1.7KB
  • core.c
    16.4KB
  • bswabe.h
    3.7KB
  • AUTHORS
    82B
  • configure.ac
    1.3KB
  • README
    337B
  • NEWS
    791B
  • misc.c
    6.8KB
内容介绍
#include <stdlib.h> #include <string.h> #ifndef BSWABE_DEBUG #define NDEBUG #endif #include <assert.h rel='nofollow' onclick='return false;'> #include <openssl/sha.h> #include <glib.h> #include <pbc.h> #include "bswabe.h" #include "private.h" #define TYPE_A_PARAMS \ "type a\n" \ "q 87807107996633125224377819847540498158068831994142082" \ "1102865339926647563088022295707862517942266222142315585" \ "8769582317459277713367317481324925129998224791\n" \ "h 12016012264891146079388821366740534204802954401251311" \ "822919615131047207289359704531102844802183906537786776\n" \ "r 730750818665451621361119245571504901405976559617\n" \ "exp2 159\n" \ "exp1 107\n" \ "sign1 1\n" \ "sign0 1\n" char last_error[256]; char* bswabe_error() { return last_error; } void raise_error(char* fmt, ...) { va_list args; #ifdef BSWABE_DEBUG va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); exit(1); #else va_start(args, fmt); vsnprintf(last_error, 256, fmt, args); va_end(args); #endif } void element_from_string( element_t h, char* s ) { unsigned char* r; r = malloc(SHA_DIGEST_LENGTH); SHA1((unsigned char*) s, strlen(s), r); element_from_hash(h, r, SHA_DIGEST_LENGTH); free(r); } void bswabe_setup( bswabe_pub_t** pub, bswabe_msk_t** msk ) { element_t alpha; /* initialize */ *pub = malloc(sizeof(bswabe_pub_t)); *msk = malloc(sizeof(bswabe_msk_t)); (*pub)->pairing_desc = strdup(TYPE_A_PARAMS); pairing_init_set_buf((*pub)->p, (*pub)->pairing_desc, strlen((*pub)->pairing_desc)); element_init_G1((*pub)->g, (*pub)->p); element_init_G1((*pub)->h, (*pub)->p); element_init_G2((*pub)->gp, (*pub)->p); element_init_GT((*pub)->g_hat_alpha, (*pub)->p); element_init_Zr(alpha, (*pub)->p); element_init_Zr((*msk)->beta, (*pub)->p); element_init_G2((*msk)->g_alpha, (*pub)->p); /* compute */ element_random(alpha); element_random((*msk)->beta); element_random((*pub)->g); element_random((*pub)->gp); element_pow_zn((*msk)->g_alpha, (*pub)->gp, alpha); element_pow_zn((*pub)->h, (*pub)->g, (*msk)->beta); pairing_apply((*pub)->g_hat_alpha, (*pub)->g, (*msk)->g_alpha, (*pub)->p); } bswabe_prv_t* bswabe_keygen( bswabe_pub_t* pub, bswabe_msk_t* msk, char** attributes ) { bswabe_prv_t* prv; element_t g_r; element_t r; element_t beta_inv; /* initialize */ prv = malloc(sizeof(bswabe_prv_t)); element_init_G2(prv->d, pub->p); element_init_G2(g_r, pub->p); element_init_Zr(r, pub->p); element_init_Zr(beta_inv, pub->p); prv->comps = g_array_new(0, 1, sizeof(bswabe_prv_comp_t)); /* compute */ element_random(r); element_pow_zn(g_r, pub->gp, r); element_mul(prv->d, msk->g_alpha, g_r); element_invert(beta_inv, msk->beta); element_pow_zn(prv->d, prv->d, beta_inv); while( *attributes ) { bswabe_prv_comp_t c; element_t h_rp; element_t rp; c.attr = *(attributes++); element_init_G2(c.d, pub->p); element_init_G1(c.dp, pub->p); element_init_G2(h_rp, pub->p); element_init_Zr(rp, pub->p); element_from_string(h_rp, c.attr); element_random(rp); element_pow_zn(h_rp, h_rp, rp); element_mul(c.d, g_r, h_rp); element_pow_zn(c.dp, pub->g, rp); element_clear(h_rp); element_clear(rp); g_array_append_val(prv->comps, c); } return prv; } bswabe_policy_t* base_node( int k, char* s ) { bswabe_policy_t* p; p = (bswabe_policy_t*) malloc(sizeof(bswabe_policy_t)); p->k = k; p->attr = s ? strdup(s) : 0; p->children = g_ptr_array_new(); p->q = 0; return p; } /* TODO convert this to use a GScanner and handle quotes and / or escapes to allow attributes with whitespace or = signs in them */ bswabe_policy_t* parse_policy_postfix( char* s ) { char** toks; char** cur_toks; char* tok; GPtrArray* stack; /* pointers to bswabe_policy_t's */ bswabe_policy_t* root; toks = g_strsplit(s, " ", 0); cur_toks = toks; stack = g_ptr_array_new(); while( *cur_toks ) { int i, k, n; tok = *(cur_toks++); if( !*tok ) continue; if( sscanf(tok, "%dof%d", &k, &n) != 2 ) /* push leaf token */ g_ptr_array_add(stack, base_node(1, tok)); else { bswabe_policy_t* node; /* parse "kofn" operator */ if( k < 1 ) { raise_error("error parsing \"%s\": trivially satisfied operator \"%s\"\n", s, tok); return 0; } else if( k > n ) { raise_error("error parsing \"%s\": unsatisfiable operator \"%s\"\n", s, tok); return 0; } else if( n == 1 ) { raise_error("error parsing \"%s\": identity operator \"%s\"\n", s, tok); return 0; } else if( n > stack->len ) { raise_error("error parsing \"%s\": stack underflow at \"%s\"\n", s, tok); return 0; } /* pop n things and fill in children */ node = base_node(k, 0); g_ptr_array_set_size(node->children, n); for( i = n - 1; i >= 0; i-- ) node->children->pdata[i] = g_ptr_array_remove_index(stack, stack->len - 1); /* push result */ g_ptr_array_add(stack, node); } } if( stack->len > 1 ) { raise_error("error parsing \"%s\": extra tokens left on stack\n", s); return 0; } else if( stack->len < 1 ) { raise_error("error parsing \"%s\": empty policy\n", s); return 0; } root = g_ptr_array_index(stack, 0); g_strfreev(toks); g_ptr_array_free(stack, 0); return root; } bswabe_polynomial_t* rand_poly( int deg, element_t zero_val ) { int i; bswabe_polynomial_t* q; q = (bswabe_polynomial_t*) malloc(sizeof(bswabe_polynomial_t)); q->deg = deg; q->coef = (element_t*) malloc(sizeof(element_t) * (deg + 1)); for( i = 0; i < q->deg + 1; i++ ) element_init_same_as(q->coef[i], zero_val); element_set(q->coef[0], zero_val); for( i = 1; i < q->deg + 1; i++ ) element_random(q->coef[i]); return q; } void eval_poly( element_t r, bswabe_polynomial_t* q, element_t x ) { int i; element_t s, t; element_init_same_as(s, r); element_init_same_as(t, r); element_set0(r); element_set1(t); for( i = 0; i < q->deg + 1; i++ ) { /* r += q->coef[i] * t */ element_mul(s, q->coef[i], t); element_add(r, r, s); /* t *= x */ element_mul(t, t, x); } element_clear(s); element_clear(t); } void fill_policy( bswabe_policy_t* p, bswabe_pub_t* pub, element_t e ) { int i; element_t r; element_t t; element_t h; element_init_Zr(r, pub->p); element_init_Zr(t, pub->p); element_init_G2(h, pub->p); p->q = rand_poly(p->k - 1, e); if( p->children->len == 0 ) { element_init_G1(p->c, pub->p); element_init_G2(p->cp, pub->p); element_from_string(h, p->attr); element_pow_zn(p->c, pub->g, p->q->coef[0]); element_pow_zn(p->cp, h, p->q->coef[0]); } else for( i = 0; i < p->children->len; i++ ) { element_set_si(r, i + 1); eval_poly(t, p->q, r); fill_policy(g_ptr_array_index(p->children, i), pub, t); } element_clear(r); element_clear(t); element_clear(h); } bswabe_cph_t* bswabe_enc( bswabe_pub_t* pub, element_t m, char* policy ) { bswabe_cph_t* cph; element_t s; /* initialize */ cph = malloc(sizeof(bswabe_cph_t)); element_init_Zr(s, pub->p); element_init_GT(m, pub->p); element_init_GT(cph->cs, pub->p); element_init_G1(cph->c, pub->p); cph->p = parse_policy_postfix(policy); /* compute */ element_random(m); element_random(s); element_pow_zn(cph->cs, pub->g_hat_alpha, s); element_mul(cph->cs, cph->cs, m); element_pow_zn(cph->c, pub->h, s); fill_policy(cph->p, pub, s); return cph; } void check_sat( bswabe_policy_t* p, bswabe_prv_t* prv ) { int i, l; p->satisfiable = 0; if( p->children->len == 0 ) { for( i = 0; i < prv->comps->len; i++ ) if( !strcmp(g_array_index(prv->comps, bswabe_prv_comp_t, i).attr, p->attr) ) { p->satisfiable = 1; p->attri = i; break; } } else { for( i = 0; i < p->children->len; i++ ) check_sat(g_ptr_array_index(p->children, i), prv); l = 0; for( i = 0; i < p->children->len; i++ ) if( ((bswabe_policy_t*) g_ptr_array_index(p->children, i))->satisfiable ) l++; if( l
评论
    相关推荐
    • NS2example.rar
      在ns2下实现无线传感器网络仿真,多个节点进行网络活动
    • tor-0.2.1.20.tar.gz
      The Onion Router 洋葱路由。具体不用解释了。
    • IPMessage.zip
      局域网内聊天和文件传送工具飞鸽传书 传送文件时可以选择一个目录,速度非常快
    • some-ns2-trace-awk.rar
      ns2中的trace分析脚本,用于网络仿真,吞吐量,延时,抖动率的分析
    • WiMAX_Protocol_Code.rar
      This documentation is based on the following versions:- pre-release of the wimax model developed by NIST (file patch-wimax-prerelease-092206)- ns-2.29 此程序是NS2下用C、C++编写的,主要对Wimax 802.16d和802.16e的MAC层协议的仿真,压缩文件内部有详细的说明。 由于NS2运行在Linux下而且是对网络的模拟,因此把它归在Linux/网络类中
    • linux-socket-program.rar
      全套Socket简单编程实例,很适合于初学网络编程者!
    • WSN-node-location-demo2.rar
      无线传感器网络模拟整个流程演示视频demo
    • ns-cbrp.tar.gz
      CBRP协议(移动adhoc中基于分簇的路由协议)ns2下的源码
    • sscom32.rar
      这是一个串口调试功能的工具,可以回显烧入的驱动程序
    • rtsp.rar
      linux\UNIX下跑的一套服务端程序,支持RTSP、RTCP、RTP等各种协议,对做音视频传输挺有参考意义