// GROUP MANAGER INIT - group key generation part1 void xsgs_gm_gen(XSGS_PUBLIC_KEY* gpk, XSGS_ISSUER_KEY* ik, pbc_param_ptr param) { // 1. generate prime p, pairing group G1, G2, GT, e and a hash function H: {0,1}* -> Zp gpk->param = param; gpk->pairing = (pairing_ptr) malloc(sizeof(pairing_t)); pairing_init_pbc_param(gpk->pairing, gpk->param); // 2. select a generator G2 e group 2 at random element_init_G2(gpk->G2, gpk->pairing); element_random(gpk->G2); // and select a generator G1 e group 1 at random (G1 <- psi(G2) not applicable) element_init_G1(gpk->G1, gpk->pairing); element_random(gpk->G1); // 3. choose gamma e Zp* at random and set ik = gamma element_init_Zr(ik->gamma, gpk->pairing); element_random(ik->gamma); // 4. select K e Group1 element_init_G1(gpk->K, gpk->pairing); element_random(gpk->K); // and W = G2^gamma (e Group2) element_init_G2(gpk->W, gpk->pairing); element_pow_naf(gpk->W, gpk->G2, ik->gamma); return; }
int main(int argc, char **argv) { pairing_t pairing; pbc_demo_pairing_init(pairing, argc, argv); char m[80]={0}; if (!pairing_is_symmetric(pairing)) pbc_die("pairing must be symmetric"); printf("Enter the message to be encrypted : "); gets(m); size_t len_m = sizeof(m); unsigned char hash[30]; SHA1(m, len_m, hash); printf("The hash is : %s", hash); element_t g, h; element_t public_key, secret_key; element_t sig; element_t temp1, temp2; element_init_G2(g, pairing); element_init_G2(public_key, pairing); element_init_G1(h, pairing); element_init_G1(sig, pairing); element_init_GT(temp1, pairing); element_init_GT(temp2, pairing); element_init_Zr(secret_key, pairing); element_random(g); element_random(secret_key); element_pow_zn(public_key, g, secret_key); element_printf("The public key is %B\n", public_key); element_from_hash(h, hash, 30); element_pow_zn(sig, h, secret_key); pairing_apply(temp1, sig, g, pairing); pairing_apply(temp2, h, public_key, pairing); if(!element_cmp(temp1, temp2)){ printf("\nVerified\n");} else{ printf("\nNot verified\n"); } }
int main(int argc, char ** argv) { pbc_param_t ec_params; pairing_t pairing; unsigned int rbits = 40, qbits = 128; element_t *g1, *g2, *gt; for (int s = 10; s <= 1000; s += 10) { while (qbits <= 4096) { fprintf(stderr, "%d", qbits); pbc_param_init_a_gen(ec_params, rbits, qbits); pairing_init_pbc_param(pairing, ec_params); element_init_G1(g1, pairing); element_init_G2(g2, pairing); element_init_GT(gt, pairing); struct timeval tv1, tv2; int bc = element_length_in_bytes(g1); for (int i = 0; i < 100; i++) { if (0 == i % 10) fprintf(stderr, "."); element_random(g1); element_random(g2); gettimeofday(&tv1, NULL); pairing_apply(gt, g1, g2, pairing); gettimeofday(&tv2, NULL); double time = tv2.tv_sec - tv1.tv_sec; time *= (1000 * 1000); time += tv2.tv_usec - tv1.tv_usec; fprintf(stdout, "%d %d %d %d %d\n", bc, rbits, qbits, i, ((int) time)); } for (int j = 0; j < s; j++) { element_clear(g1[j]); element_clear(g2[j]); element_clear(gt[j]); } rbits *= 2; qbits *= 2; fprintf(stderr, "\n"); } free(g1); free(g2); free(g3); } }
int main(int argc, char **argv) { if(argc < 3){ fprintf(stderr,"Wrong input arguments!"); fprintf(stderr,"Please input <./curve><supersinuglar><rbits><qbits> or <./curve><ordinary><bits>\n"); }else{ //initialization pairing_t pairing; element_t g,h,temp1; int rbits, qbits; if(!strcmp(argv[1],"supersingular")&&argc==4){//to generate supersingualr curve rbits = atoi(argv[2]); qbits = atoi(argv[3]); generateSupersingular(&pairing,rbits,qbits); printf("generate supersingular curve..."); }else if(!strcmp(argv[1],"ordinary")&&argc==3){//to generate ordinary curve rbits = atoi(argv[2]); generateOrdinary(&pairing,256); printf("generate ordinary curve..."); }else{ fprintf(stderr,"Wrong input arguments!"); fprintf(stderr,"Please input <./curve><supersinuglar><rbits><qbits> or <./curve><ordinary><bits>\n"); return 0; } if(pairing_is_symmetric(pairing)){ printf("pairing is symmetric\n"); }else{ printf("pairing is NOT symmetric\n"); } FILE *fTime = fopen("curve.txt","w+"); clock_t start,end;//start:the start of pairing, end:the end of pairing float difftime=0.0; int loopnum = 100;//the numbers for the while-loop int i;//the index for the for-loop element_init_G1(g, pairing); element_init_G2(h, pairing); element_init_GT(temp1, pairing); element_random(g); element_random(h); for(i = 0;i<100;i++){ while(loopnum--){ start = clock(); element_pairing(temp1, g, h); end = clock(); } difftime = (float)(end-start)/CLOCKS_PER_SEC; printf("The time of using pairing is %f\n",difftime); fprintf(fTime,"%f\r\n",difftime); difftime = 0.0; loopnum = 100; } }//end of main-else return 0; }
// Multipairing void do_multi(int m){ int i = 0; lpoly list[m]; lpoly *tmp_list; // prevalues element_t gg[m]; element_ptr ggg[m]; element_t hh[m]; for(i = 0; i < m; i++){ element_init_G2(gg[i], pairing); element_random(gg[i]); ggg[i] = malloc(sizeof(element_ptr)); element_init(ggg[i], gg[i]->field); element_set(ggg[i], gg[i]); element_init_G1(hh[i], pairing); element_random(hh[i]); } // precomputation gettimeofday(&tvBegin, NULL); for(i = 0; i < m; i++){ tmp_list = lpoly_init(); precompute(tmp_list, pairing->r, hh[i], gg[i]); list[i] = *tmp_list; } gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); // compute gettimeofday(&tvBegin, NULL); compute_millers(temp2, list, ggg, m, pairing); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); gettimeofday(&tvBegin, NULL); element_prod_pairing(temp1, hh, gg, m); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); for(i = 0; i < m; i++){ lpoly_free2(list[i]); } }
int main(int argc, char **argv) { FILE *fpairing, *ftag, *fdata, *fresult, *fplain, *fkey, *fcipher, *fpub; pairing_t pairing; paillier_pubkey_t *pub; paillier_prvkey_t *priv; element_t g, h, u, sig1, sig2, sig3, temp_pow, m, g1, g2; element_t public_key, tag, tag_prod; element_t secret_key; paillier_get_rand_t get_rand; paillier_ciphertext_t *cipher1, *cipher2; paillier_plaintext_t *plain1, *plain2; mpz_t pub_n, a, b, data2, nsquare; int count = 0, val=5; pairing_init_set_str(pairing, param_str); //mpz_init_set_str(data_sum, "0", 10); plain1 = (paillier_plaintext_t*) malloc(sizeof(paillier_plaintext_t)); plain2 = (paillier_plaintext_t*) malloc(sizeof(paillier_plaintext_t)); cipher1 = (paillier_ciphertext_t*) malloc(sizeof(paillier_ciphertext_t)); cipher2 = (paillier_ciphertext_t*) malloc(sizeof(paillier_ciphertext_t)); //pbc_demo_pairing_init(pairing, argc, argv); element_init_G1(g1, pairing); element_init_G1(g2, pairing); element_init_G2(g, pairing); element_init_G2(public_key, pairing); element_init_G1(u, pairing); element_init_G1(temp_pow, pairing); element_init_G2(public_key, pairing); element_init_G1(h, pairing); element_init_G1(m, pairing); element_init_G1(sig1, pairing); element_init_G1(sig2, pairing); element_init_G1(sig3, pairing); element_init_G1(tag, pairing); element_init_G1(tag_prod, pairing); element_init_Zr(secret_key, pairing); // mpz_init(pub_n); char *len; mpz_init(a); mpz_init(b); mpz_init(data2); printf("Short signature test\n"); len = (char *)malloc(2048*sizeof(char)); if((fpub = fopen("pub.txt", "r"))) { pub = (paillier_pubkey_t*) malloc(sizeof(paillier_pubkey_t)); priv = (paillier_prvkey_t*) malloc(sizeof(paillier_prvkey_t)); mpz_init(pub->n_squared); mpz_init(pub->n); fgets(len, 1000, fpub); mpz_init_set_str(pub->p, len, 10); fgets(len, 1000, fpub); mpz_init_set_str(pub->q, len, 10); fgets(len, 1000, fpub); mpz_init_set_str(pub->n_plusone, len, 10); //printf("value of nplusone : \n"); //mpz_out_str(stdout, 10, pub->n_plusone); paillier_keygen(&pub, &priv, get_rand, 0); pub->bits = mpz_sizeinbase(pub->n, 2); fclose(fpub); } //setting already known pairing parameters if((fpairing = fopen("pairing.txt", "r"))) { fgets(len, 1000, fpairing); //printf("\n %s\n", len); element_set_str(g, len, 10); //element_printf(" g = %B\n", g); fgets(len, 1000, fpairing); //printf("\n %s\n", len); element_set_str(u, len, 10); //element_printf("\n u= %B\n", u); fgets(len, 1000, fpairing); element_set_str(secret_key, len, 10); //element_printf(" secretkey %B\n",secret_key); fgets(len, 1000, fpairing); element_set_str(public_key, len, 10); //element_printf(" publickey %B\n", public_key); fgets(len, 1000, fpairing); element_set_str(h, len, 10); //element_printf(" \nh = %B\n", h); fgets(len, 1000, fpairing); mpz_init_set_str(pub_n, len, 10); //printf("\n n = "); //mpz_out_str(stdout, 10, pub_n); fclose(fpairing); } element_set1(tag_prod); ftag = fopen("./tag/output5.txt", "r"); fgets(len, 1000, ftag); element_set_str(g1, len, 10); element_printf("\ng1 = %B\n", g1); fclose(ftag); ftag = fopen("./tag/output6.txt", "r"); fgets(len, 1000, ftag); element_set_str(g2, len, 10); element_printf("\ng2 = %B\n", g2); fclose(ftag); fplain = fopen("./split/output5.txt", "r"); fgets(len, 1000, fplain); // printf("\nlen %s", len); mpz_set_str(a, len, 10); //element_printf("\na = %Zd\n", a); fclose(fplain); fplain = fopen("./split/output6.txt", "r"); fgets(len, 1000, fplain); mpz_set_str(b, len, 10); fcipher = fopen("./cipher/copy1/output5.txt", "r"); fgets(len, 1000, fcipher); mpz_init_set_str(cipher1->c, len, 10); fclose(fcipher); fcipher = fopen("./cipher/copy1/output6.txt", "r"); fgets(len, 1000, fcipher); mpz_init_set_str(cipher2->c, len, 10); fclose(fcipher); paillier_mul(pub, cipher2, cipher2, cipher1); plain1 = paillier_dec(plain1, pub, priv, cipher2); //tag mpz_t an; mpz_init(an); mpz_init(nsquare); // mpz_mul(an, a, pub_n); mpz_mul(nsquare, pub_n, pub_n); element_pow_mpz(temp_pow,u, plain1->m); element_mul(temp_pow, temp_pow, h); element_pow_zn(sig1, temp_pow, secret_key); element_printf("\n signature of plain = %B\n", sig1); //mpz_mul(an, b, pub_n); // mpz_mul(nsquare, pub_n, pub_n); element_pow_mpz(temp_pow,u, b); element_mul(temp_pow, temp_pow, h); element_pow_zn(sig2, temp_pow, secret_key); element_printf("\n signature of b = %B\n", sig2); //element_printf("\nb = %Zd\n", b); fclose(fplain); mpz_add(a, a, b); // mpz_mod(a, a, pub_n); // mpz_mul(a, a, pub_n); // mpz_mod(a, a, nsquare); count = 2; element_pow_mpz(temp_pow,u, a); mpz_set_ui(data2, count); // itoa(count, len, 10);+ //element_printf(" \nh = %B\n", h); element_pow_mpz(h, h, data2); element_mul(temp_pow, temp_pow, h); //element_printf("\n h. u^bN = %B\n", temp_pow); element_pow_zn(sig3, temp_pow, secret_key); element_printf("\n sig 3 %B\n", sig3); element_mul(g2, g2, g1); element_printf("\n Direct Product %B\n", g2); element_mul(sig2, sig1, sig2); element_printf("\n Direct Product %B\n", sig2); return 0; }
int main(void) { pairing_t pairing; char param[50000]; size_t count = fread(param, 1, 50000, stdin); if (!count) pbc_die("input error"); pairing_init_set_buf(pairing, param, count); // int cont = 0; struct timeval tvBegin, tvEnd; element_t g, h; element_t public_key, secret_key; element_t sig; element_t temp1, temp2; element_init_G2(g, pairing); element_init_G2(public_key, pairing); element_init_G1(h, pairing); element_init_G1(sig, pairing); element_init_GT(temp1, pairing); element_init_GT(temp2, pairing); element_init_Zr(secret_key, pairing); // Generating key element_random(g); element_random(secret_key); element_pow_zn(public_key, g, secret_key); // Generating message element_from_hash(h, "ABCDEF", 6); element_pow_zn(sig, h, secret_key); // RANDOM TESTS /* // Fp element_t p1, p2; element_init(p1, element_x(h)->field); element_init(p2, p1->field); element_random(p1); element_random(p2); // multiplication element_t puntos[2000]; for(cont = 0; cont < 1000; cont++){ element_init(puntos[cont], element_x(h)->field); element_init(puntos[2*cont], element_x(h)->field); element_random(puntos[cont]); element_random(puntos[2*cont]); } gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++){ element_mul(puntos[cont], puntos[cont], puntos[2*cont]); } gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); //square gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++) element_square(puntos[cont], puntos[2*cont]); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // add gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++) element_add(puntos[cont], puntos[cont], puntos[2*cont]); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // invers gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++) element_invert(puntos[cont], puntos[2*cont]); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // Fpk element_t q1, q2; element_init_GT(q1, pairing); element_init_GT(q2, pairing); element_random(q1); element_random(q2); // multiplication for(cont = 0; cont < 1000; cont++){ element_init_GT(puntos[cont], pairing); element_init_GT(puntos[2*cont], pairing); element_random(puntos[cont]); element_random(puntos[2*cont]); } gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++) { element_mul(puntos[cont], puntos[cont], puntos[2*cont]); } gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); //square gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++) element_square(puntos[cont], puntos[cont]); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // add gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++){ element_add(element_x(puntos[cont]), element_x(puntos[cont]), element_x(puntos[2*cont])); element_add(element_y(puntos[cont]), element_y(puntos[cont]), element_y(puntos[2*cont])); } gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // invers gettimeofday(&tvBegin, NULL); for(cont = 0; cont < 1000; cont++) element_invert(puntos[cont], puntos[2*cont]); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // CURVE OPERATIONS element_t punto, punto2; element_init(punto, h->field); element_random(punto); element_init(punto2, h->field); element_random(punto2); // add gettimeofday(&tvBegin, NULL); element_mul(punto, punto, punto2); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // double gettimeofday(&tvBegin, NULL); element_double(punto, punto2); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1); // SIZE GROUP int m = mpz_sizeinbase(pairing->r, 2) - 2; printf("%i\n", m); int contador = 0; for(;;){ if(!m) break; if(mpz_tstbit(pairing->r,m)) contador++; m--; } printf("%i\n", contador); */ // One pairing gettimeofday(&tvBegin, NULL); eval_miller(temp1, sig, g, pairing); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); //print_contador(); // One pairing (with precomputed values) // Original method pairing_pp_t pp; // Precomp gettimeofday(&tvBegin, NULL); pairing_pp_init(pp, sig, pairing); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); // Eval gettimeofday(&tvBegin, NULL); pairing_pp_apply(temp1, g, pp); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); pairing_pp_clear(pp); void do_precomp(){ lpoly *list; // precomputation gettimeofday(&tvBegin, NULL); list = lpoly_init(); precompute(list, pairing->r, sig, g); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); // DMAX printf("%i\n", list->MAXD); // eval gettimeofday(&tvBegin, NULL); compute_miller(temp2, list, g, pairing); gettimeofday(&tvEnd, NULL); timeval_subtract(&tvEnd, &tvBegin, 1000); lpoly_free(list); }
void wSetup(char *string,int attrNo,pairing_t *pairing, MSP *msp){ int count = 0;//the index of the attribute array /* if(!strcmp(string,"ordinary")){ setupOrdinaryPairing(pairing);//setup pairing first printf("Use ordinary curve...\n"); }else if(!strcmp(string,"singular")){ setupSingularPairing(pairing);//setup pairing first printf("Use singular curve...\n"); }else{ fprintf(stderr,"Wrong input arguments!"); fprintf(stderr,"Please input <./wAbe><sinuglar> or <./wAbe><ordinary>\n"); } */ element_t g;//the generator of G element_init_G2(g,*pairing);//initial the generator g element_random(g); /* initial the random group elements h_1...h_attrNo which belog to G and are associated with the attrNo attributes in the system. */ element_t h; element_init_G2(h,*pairing); //initial the h element_t alpha; element_t a; //initial the alpha and a in Z_p element_init_Zr(alpha,*pairing); element_init_Zr(a,*pairing); element_random(alpha); element_random(a); //public key e(g,g)^alpha element_t pubKey; element_t gAlpha; element_t gA; element_init_GT(pubKey,*pairing);//initial the publicKey element_init_G2(gAlpha,*pairing);//initial the gAlpha element_init_G2(gA,*pairing);//initial the gA element_pow_zn(gAlpha,g,alpha);//gAlpha=g^alpha element_pow_zn(gA,g,a);//gA=g^a weilPairing(&pubKey,g,gAlpha,*pairing);//publicKey = e(g,g^alpha) = e(g,g)^alpha //Master secret key element_t msk; element_init_G2(msk,*pairing); element_set(msk,gAlpha);//msk = g^alpha //write the master key and public key to file FILE* fG = fopen("publicKey/g.key","w");//file pointer to the public key g FILE* fGA = fopen("publicKey/gA.key","w");//file pointer to the public key gA FILE* fPub = fopen("publicKey/eGG.key","w");//file pointer to the public key e(g,gALPHA) FILE* fH;//file pointer the the attribute key FILE* fMsk = fopen("MSK/msk.key","w");//file pointer to the master key element_fprintf(fG,"%B\n",g); element_fprintf(fPub,"%B\n",pubKey); element_fprintf(fGA,"%B\n",gA); count = 0; char hCmd[100];//the command line for the pointer of FILE* fH char attrName[2];//the name of attribute memset(hCmd,'\0',100); memset(attrName,'\0',2); strcpy(hCmd,"publicKey/h"); while(count!=attrNo){ sprintf(attrName,"%c",msp->label[count]); strcat(hCmd,attrName); strcat(hCmd,".key"); fH = fopen(hCmd,"w"); element_random(h); element_fprintf(fH,"%B",h); memset(hCmd,'\0',100); strcpy(hCmd,"publicKey/h"); memset(attrName,'\0',2); fclose(fH); count++; } element_clear(h); element_fprintf(fMsk,"%B\n",msk); //close the file pointer and clear all the element fclose(fG); fclose(fGA); fclose(fPub); fclose(fMsk); element_clear(g); element_clear(a); element_clear(alpha); element_clear(gAlpha); element_clear(gA); element_clear(pubKey); element_clear(msk); }//end of setup
/* * Initializes a member element of G2 to no initial value. * MEMBER ELEMENT MEANS THIS ELEMENT WON'T BE USED AS AN EXPONENT * @param elem - the element to be initialized */ void BilinearMappingHandler::initEmptyMemberElementFromG2(memberElement& elem) { element_init_G2(elem, pairing); }//end of initEmptyMemberElementFromG2()
void pbc_decrypt(struct crypto *pbc, int tl, int *nse, int ts, int use_caching, int use_product) { /* e(C_0, K_0) -> pairing(C, K[i]) * e(C_{i1}, K_{i1}) -> pairing(Ci[i], Ki[i]) * e(C_{i2}, K_{i2}) -> pairing(Ci[i], Ki[i]) */ element_t C, K[ts], Ci[tl], Ki[tl], R, A, B, M, T; int num_mul=0, num_pair=0; struct timeval st, en; int i, j; /* -------------------- setup --------------------- */ gettimeofday(&st, NULL); element_init_G1(C, pbc->pairing); element_random(C); for (i = 0; i < ts; i++) { element_init_G2(K[i], pbc->pairing); element_random(K[i]); } for (i = 0; i < tl; i++) { element_init_G1(Ci[i], pbc->pairing); element_random(Ci[i]); } for (i = 0; i < tl; i++) { element_init_G2(Ki[i], pbc->pairing); element_random(Ki[i]); } element_init_GT(R, pbc->pairing); element_init_GT(A, pbc->pairing); element_init_GT(B, pbc->pairing); element_init_GT(M, pbc->pairing); element_init_GT(T, pbc->pairing); gettimeofday(&en, NULL); printf("Setup: %lu us\n", time_diff(&st, &en)); printf("tl=%d ts=%d|", tl, ts); for (i = 0; i < ts; i++) printf("%d ", nse[i]); printf("\n"); /* ------------------ decryption ------------------ */ gettimeofday(&st, NULL); /* e(C0, K0) across all tokens */ if (use_caching) { pairing_pp_t pp; pairing_pp_init(pp, C, pbc->pairing); for (i = 0; i < ts; i++) pairing_pp_apply(R, K[i], pp); pairing_pp_clear(pp); } else for (i = 0; i < ts; i++) { pairing_apply(R, C, K[i], pbc->pairing); num_pair++; } /* prod{e(Ci1, Ki1)}prod{e(Ci2, Ki2)} across all tokens */ if (use_product) { for (i = 0; i < ts; i++) { if (!nse[i])continue; element_prod_pairing(A, Ci, Ki, nse[i]); element_prod_pairing(B, Ci, Ki, nse[i]); element_mul(M, A, B); } } else for (i = 0; i < ts; i++) { element_set1(A); for (j = 0; j < nse[i]; j++) { element_pairing(T, Ci[j], Ki[j]); element_mul(A, A, T); num_pair++; num_mul++; } element_set1(B); for (j = 0; j < nse[i]; j++) { element_pairing(T, Ci[j], Ki[j]); element_mul(B, B, T); num_pair++; num_mul++; } element_mul(M, A, B); num_mul++; } gettimeofday(&en, NULL); printf("Decryption: %lu us\n", time_diff(&st, &en)); if (use_caching || use_product) { num_pair = -1; num_mul = -1; } printf("Used %d pairings and %d multiplications\n", num_pair, num_mul); /* ------------------- cleanup -------------------- */ gettimeofday(&st, NULL); element_clear(T); element_clear(M); element_clear(B); element_clear(A); element_clear(R); element_clear(C); for (i = 0; i < ts; i++) element_clear(K[i]); for (i = 0; i < tl; i++) element_clear(Ci[i]); for (i = 0; i < tl; i++) element_clear(Ki[i]); gettimeofday(&en, NULL); printf("Cleanup: %lu us\n", time_diff(&st, &en)); }
int bbs_verify(unsigned char *sig, int hashlen, void *hash, bbs_group_public_key_t gpk) { bbs_sys_param_ptr param = gpk->param; pairing_ptr pairing = param->pairing; field_ptr Fp = pairing->Zr; element_t T1, T2, T3; element_t R1, R2, R3, R4, R5; element_t c, salpha, sbeta, sx, sdelta1, sdelta2; element_t e10, e20, e21, et0, z0, z1; unsigned char *readptr = sig; element_init_G1(T1, pairing); element_init_G1(T2, pairing); element_init_G1(T3, pairing); element_init_G1(R1, pairing); element_init_G1(R2, pairing); element_init_GT(R3, pairing); element_init_G1(R4, pairing); element_init_G1(R5, pairing); element_init(c, Fp); element_init(salpha, Fp); element_init(sbeta, Fp); element_init(sx, Fp); element_init(sdelta1, Fp); element_init(sdelta2, Fp); element_init_G1(e10, pairing); element_init_G2(e20, pairing); element_init_G2(e21, pairing); element_init_GT(et0, pairing); element_init(z0, Fp); element_init(z1, Fp); readptr += element_from_bytes(T1, readptr); readptr += element_from_bytes(T2, readptr); readptr += element_from_bytes(T3, readptr); readptr += element_from_bytes(c, readptr); readptr += element_from_bytes(salpha, readptr); readptr += element_from_bytes(sbeta, readptr); readptr += element_from_bytes(sx, readptr); readptr += element_from_bytes(sdelta1, readptr); readptr += element_from_bytes(sdelta2, readptr); element_neg(z0, c); //element_pow_zn(R1, gpk->u, salpha); //element_pow_zn(e10, T1, z0); //element_mul(R1, R1, e10); element_pow2_zn(R1, gpk->u, salpha, T1, z0); //element_pow_zn(R2, gpk->v, sbeta); //element_pow_zn(e10, T2, z0); //element_mul(R2, R2, e10); element_pow2_zn(R2, gpk->v, sbeta, T2, z0); element_neg(z0, sdelta1); //element_pow_zn(R4, gpk->u, z0); //element_pow_zn(e10, T1, sx); //element_mul(R4, R4, e10); element_pow2_zn(R4, gpk->u, z0, T1, sx); element_neg(z0, sdelta2); //element_pow_zn(R5, gpk->v, z0); //element_pow_zn(e10, T2, sx); //element_mul(R5, R5, e10); element_pow2_zn(R5, gpk->v, z0, T2, sx); /* * compute R3 more efficiently. use precomputed e(g1,g2)^{-1}, * e(h,g2), and e(h,w). this leaves e(T3,g2)^sx and e(T3,w)^c; * compute these with one pairing as e(T3, g2^sx w^c). */ //element_pow_zn(e20, gpk->g2, sx); //element_pow_zn(e21, gpk->w, c); //element_mul(e20, e20, e21); element_pow2_zn(e20, gpk->g2, sx, gpk->w, c); pairing_apply(R3, T3, e20, pairing); //element_pow_zn(et0, gpk->pr_g1_g2_inv, c); //element_mul(R3, R3, et0); element_add(z0, salpha, sbeta); element_neg(z0, z0); //element_pow_zn(et0, gpk->pr_h_w, z0); //element_mul(R3, R3, et0); element_add(z1, sdelta1, sdelta2); element_neg(z1, z1); //element_pow_zn(et0, gpk->pr_h_g2, z1); element_pow3_zn(et0, gpk->pr_g1_g2_inv, c, gpk->pr_h_w, z0, gpk->pr_h_g2, z1); element_mul(R3, R3, et0); #ifdef DEBUG element_printf("T1: %B\n", T1); element_printf("T2: %B\n", T2); element_printf("T3: %B\n", T3); element_printf("R1: %B\n", R1); element_printf("R2: %B\n", R2); element_printf("R3: %B\n", R3); element_printf("R4: %B\n", R4); element_printf("R5: %B\n", R5); #endif int result = 0; element_t M; element_init_G1(M, pairing); element_from_hash(M, hash, hashlen); unsigned int hash_input_length = element_length_in_bytes(T1) + element_length_in_bytes(T2) + element_length_in_bytes(T3) + element_length_in_bytes(R1) + element_length_in_bytes(R2) + element_length_in_bytes(R3) + element_length_in_bytes(R4) + element_length_in_bytes(R5) + element_length_in_bytes(M); unsigned char *hash_input = malloc(hash_input_length); hash_input += element_to_bytes(hash_input, T1); hash_input += element_to_bytes(hash_input, T2); hash_input += element_to_bytes(hash_input, T3); hash_input += element_to_bytes(hash_input, R1); hash_input += element_to_bytes(hash_input, R2); hash_input += element_to_bytes(hash_input, R3); hash_input += element_to_bytes(hash_input, R4); hash_input += element_to_bytes(hash_input, R5); hash_input += element_to_bytes(hash_input, M); // Could avoid converting to bytes and from bytes hash_input -= hash_input_length; hash_ctx_t context; unsigned char digest[hash_length]; hash_init(context); hash_update(context, hash_input, hash_input_length); hash_final(digest, context); free(hash_input); element_t c1; element_init(c1, Fp); element_from_hash(c1, digest, sizeof(digest)); if (!element_cmp(c, c1)) { result = 1; } element_clear(M); element_clear(c1); element_clear(T1); element_clear(T2); element_clear(T3); element_clear(R1); element_clear(R2); element_clear(R3); element_clear(R4); element_clear(R5); element_clear(c); element_clear(salpha); element_clear(sbeta); element_clear(sx); element_clear(sdelta1); element_clear(sdelta2); element_clear(e10); element_clear(e20); element_clear(e21); element_clear(et0); element_clear(z0); element_clear(z1); return result; }
void bbs_gen(bbs_group_public_key_ptr gpk, bbs_manager_private_key_ptr gmsk, int n, bbs_group_private_key_t *gsk, bbs_sys_param_ptr param) { pairing_ptr pairing = param->pairing; element_t z0; element_t gamma; int i; gpk->param = param; gmsk->param = param; element_init_G1(gpk->g1, pairing); element_init_G2(gpk->g2, pairing); element_init_G1(gpk->h, pairing); element_init_G1(gpk->u, pairing); element_init_G1(gpk->v, pairing); element_init_G2(gpk->w, pairing); element_init_Zr(gmsk->xi1, pairing); element_init_Zr(gmsk->xi2, pairing); element_init_Zr(z0, pairing); element_init_Zr(gamma, pairing); element_random(gpk->g2); element_random(gpk->g1); element_random(gpk->h); element_random(gmsk->xi1); element_random(gmsk->xi2); element_invert(z0, gmsk->xi1); element_pow_zn(gpk->u, gpk->h, z0); element_invert(z0, gmsk->xi2); element_pow_zn(gpk->v, gpk->h, z0); element_random(gamma); element_pow_zn(gpk->w, gpk->g2, gamma); for (i=0; i<n; i++) { gsk[i]->param = param; element_init_G1(gsk[i]->A, pairing); element_init_Zr(gsk[i]->x, pairing); element_random(gsk[i]->x); element_add(z0, gamma, gsk[i]->x); element_invert(z0, z0); element_pow_zn(gsk[i]->A, gpk->g1, z0); /* do some precomputation */ /* TODO: could instead compute from e(g1,g2) ... */ element_init_GT(gsk[i]->pr_A_g2, pairing); pairing_apply(gsk[i]->pr_A_g2, gsk[i]->A, gpk->g2, pairing); } /* do some precomputation */ element_init_GT(gpk->pr_g1_g2, pairing); element_init_GT(gpk->pr_g1_g2_inv, pairing); element_init_GT(gpk->pr_h_g2, pairing); element_init_GT(gpk->pr_h_w, pairing); pairing_apply(gpk->pr_g1_g2, gpk->g1, gpk->g2, pairing); element_invert(gpk->pr_g1_g2_inv, gpk->pr_g1_g2); pairing_apply(gpk->pr_h_g2, gpk->h, gpk->g2, pairing); pairing_apply(gpk->pr_h_w, gpk->h, gpk->w, pairing); element_clear(z0); element_clear(gamma); }
int main(int argc, char *argv[]) { ///list all the files in the directory/// DIR *d; FILE *fpub, *fpriv, *fciph, *fplain, *ftag, *fpairing, *ftemp, *frand;//, *fp6, *fp7; paillier_pubkey_t *pub; paillier_prvkey_t *priv; paillier_get_rand_t get_rand; paillier_plaintext_t *plain; paillier_ciphertext_t *cipher, *cipher_copy; paillier_tag* tag; mpz_t tag_sig, *rand_prf; gmp_randstate_t rand; char *len; struct stat st= {0}; unsigned char *data; int count=0, count1=0, gbytes, n, no_copies=10; struct dirent *dir; ///pairing parameters pairing_t pairing; //pairing_t p; //printf("setting pairing parameters\n"); //pairing_init_set_str(pairing, param_str); // printf("after pairing setup\n"); element_t g, h, u, temp_pow, test1, test2; element_t public_key, sig; element_t secret_key; ///end of pairing parameters //initialize pairing parametrs pbc_demo_pairing_init(pairing, argc, argv); element_init_G2(g, pairing); element_init_G1(u, pairing); element_init_G1(test1, pairing); element_init_G2(test2, pairing); element_init_G1(temp_pow, pairing); element_init_G2(public_key, pairing); // element_from_hash(h, "hashofmessage", 13); element_init_G1(h, pairing); element_init_G1(sig, pairing); element_init_Zr(secret_key, pairing); //end of pairing parameters initialization //set up pairing parameters //generate system parameters element_random(g); // n = pairing_length_in_bytes_x_only_G1(pairing); // data = pbc_malloc(n); // gbytes = pairing_length_in_bytes_G2(pairing); // printf(" \n g in bytes %d \n", gbytes); // element_printf("system parameter g = %B\n", g); //generate private key element_random(secret_key); //generate u element_random(u); //calculating hash of a file name and mapping it to element in group G1 // element_from_hash(h, "FileName", 8); element_random(h); //element_printf("private key = %B\n", secret_key); //compute corresponding public key element_pow_zn(public_key, g, secret_key); //element_printf("public key = %B\n", public_key); //end of setup tag = (paillier_tag*) malloc(sizeof(paillier_tag)); plain = (paillier_plaintext_t*) malloc(sizeof(paillier_plaintext_t)); cipher = (paillier_ciphertext_t*) malloc(sizeof(paillier_ciphertext_t)); mpz_init(plain->m); mpz_init(tag->t); mpz_init(cipher->c); mpz_init(tag_sig); rand_prf = (mpz_t*) malloc(n*sizeof(mpz_t)); len = (char *)malloc(2048*sizeof(char)); //****paillier key generation**** if(!(fpub = fopen("pub.txt", "r"))) { //fputs("Not able to read public key file!\n", stderr); paillier_keygen(&pub, &priv, get_rand,450); //fclose(fpub); fpub = fopen("pub.txt", "w"); gmp_fprintf(fpub, "%Zd\n", pub->p); gmp_fprintf(fpub, "%Zd\n", pub->q); gmp_fprintf(fpub, "%Zd\n", pub->n_plusone); //***Writing private keys into a file*** fpriv = fopen("priv.txt", "w"); gmp_fprintf(fpriv, "%Zd\n", priv->lambda); gmp_fprintf(fpriv, "%Zd\n", priv->x); fclose(fpriv); //****End of writing private key in a file*** } else { printf("\n in else"); pub = (paillier_pubkey_t*) malloc(sizeof(paillier_pubkey_t)); priv = (paillier_prvkey_t*) malloc(sizeof(paillier_prvkey_t)); mpz_init(pub->n_squared); mpz_init(pub->n); fgets(len, 1000, fpub); mpz_init_set_str(pub->p, len, 10); fgets(len, 1000, fpub); mpz_init_set_str(pub->q, len, 10); fgets(len, 1000, fpub); mpz_init_set_str(pub->n_plusone, len, 10); //printf("value of nplusone : \n"); //mpz_out_str(stdout, 10, pub->n_plusone); paillier_keygen(&pub, &priv, get_rand, 0); pub->bits = mpz_sizeinbase(pub->n, 2); } fclose(fpub); //****end of paillier key generation**** //printf("writing pairing parameters to a file\n"); //writing pairing keys to file fpairing = fopen("pairing.txt", "w"); /* n = pairing_length_in_bytes_compressed_G2(pairing); data = pbc_malloc(n); element_to_bytes_compressed(data, g); element_printf(" decomp g %B\n", g); element_from_bytes_compressed(test2, data); element_printf(" decomp g %B\n", test2); */ //writing compressed g to file element_fprintf(fpairing, "%B\n", g); // element_printf(" g = %B\n", g); /*n = pairing_length_in_bytes_compressed_G1(pairing); data = pbc_malloc(n); element_to_bytes_compressed(data, u); element_printf(" decomp g %B\n", u); element_from_bytes_compressed(test1, data); element_printf(" decomp g %B\n", test1); //writing compressed u to file */ element_fprintf(fpairing, "%B\n", u); //element_printf(" u = %B\n", u); //writing secret key to file element_fprintf(fpairing, "%B\n", secret_key); //element_printf(" sk = %B\n", secret_key); // printf("secret key = %s\n",secret_key); /* n = pairing_length_in_bytes_compressed_G2(pairing); data = pbc_malloc(n); element_to_bytes_compressed(data, public_key); //writing compressed public key to file */ element_fprintf(fpairing, "%B\n", public_key); //element_printf("pk = %B\n", public_key); /* n = pairing_length_in_bytes_compressed_G1(pairing); data = pbc_malloc(n); element_to_bytes_compressed(data, h); element_printf(" decomp g %B\n", h); element_from_bytes_compressed(test1, data); element_printf(" decomp g %B\n", test1); //writing compressed h to file */ element_fprintf(fpairing, "%B\n", h); //element_printf("h = %B\n", h); //writing n to file gmp_fprintf(fpairing, "%Zd\n", pub->n); fclose(fpairing); //end of writing pairing keys to file cipher_copy = (paillier_ciphertext_t*)malloc(no_copies*sizeof(paillier_ciphertext_t)); frand = fopen("rand.txt","w"); int i; init_rand(rand, get_rand, pub->bits / 8 + 1); for(i = 0; i< no_copies; i++) { mpz_init(rand_prf[i]); do mpz_urandomb(rand_prf[i], rand, pub->bits); while( mpz_cmp(rand_prf[i], pub->n) >= 0 ); gmp_fprintf(frand, "%Zd\n", rand_prf[i]); //printf("\nrandom : \n"); //mpz_out_str(stdout, 10, rand_prf[i]); } fclose(frand); //****Opening files to read files and encrypt***** d = opendir("./split"); if (d) { while ((dir = readdir(d)) != NULL) { //printf("%s\n", dir->d_name); char fileName[1000], copy[1000]; strcpy(fileName, "./split/"); strcat(fileName,dir->d_name); //printf("\nfile name %s", fileName); if(!(fplain = fopen(fileName, "r"))) { printf("\n not able to read %s", fileName); // fputs("not possible to read file!\n", stderr); count1++; } else { //printf("\n able to read %s", fileName); fgets(len, 2048, fplain); mpz_init_set_str(plain->m, len, 10); // mpz_out_str(stdout, 10, plain->m); fclose(fplain); //Writing cipher text to files strcpy(fileName, "./cipher/"); //strcat(fileName,dir->d_name); //printf("\nfilename %s",fileName); paillier_enc(tag, cipher_copy, pub,plain, get_rand, no_copies, rand_prf); // mpz_out_str(stdout, 10, tag->t); int j; for(j=0;j < no_copies; j++) { char num[20]; strcpy(copy, fileName); sprintf(num, "copy%d/", (j+1)); // strcat(copy, ); strcat(copy, num); if(stat(copy, &st) == -1) mkdir(copy,0777); strcat(copy,dir->d_name); if(!(fciph = fopen(copy, "w"))) { printf("\nnot able to open file for writing cipher text %s", copy); } else { // printf("\nbefore enc"); gmp_fprintf(fciph, "%Zd\n", cipher_copy[j].c); fclose(fciph); } } //writing tags to files strcpy(fileName, "./tag/"); strcat(fileName,dir->d_name); //printf("\nfilename %s",fileName); if(!(ftag = fopen(fileName, "w"))) { printf("not able to open file for writing tag %s", fileName); } else { element_pow_mpz(temp_pow,u, tag->t); element_mul(temp_pow, temp_pow, h); element_pow_zn(sig, temp_pow, secret_key); element_fprintf(ftag, "%B", sig); fclose(ftag); } } count++; } closedir(d); } printf("\nTotal number of files : %d, unreadable files %d", count, count1); return 0; }
int main(int argc, char **argv) { verbose = 0; ifsize = 0; int canrun =0; clock_t start_t, end_t; float total_t; int user_num = 100; int k; int choose; char *para1, *para2; while ((choose = getopt (argc, argv, "vfn:hgs")) != -1) { switch (choose) { case 's': ifsize = 1; break; case 'h': usage(); exit(0); break; case 'v': verbose = 1; break; case 'n': user_num = atoi(optarg); break; case 'g': //printf("Initializing pairing parameters...\n"); if(canrun) { fprintf(stderr, "Pairing parameters have been set, \'-g\' should not set paring parameters again.\n"); break; } canrun = 1; k=0; for( ; optind<argc && !(*argv[optind] == '-'); optind++) k++; if(k==2) { int rbits = atoi(argv[optind-k]); int qbits = atoi(argv[optind-k+1]); pbc_param_t param; // printf("rbits=%d qbits=%d\n",rbits,qbits); pbc_param_init_a_gen(param, rbits, qbits); pairing_init_pbc_param(pairing, param); pairing_init_pbc_param(pairing2, param); pbc_param_clear(param); } else { fprintf(stderr, "Input invalid!\n"); usage(); exit(-1); } break; case 'f': //printf("Initializing pairing parameters...\n"); if(canrun) { fprintf(stderr, "Pairing parameters have been set, \'-f\' should not set paring parameters again.\n"); break; } canrun = 1; k=0; for( ; optind<argc && !(*argv[optind] == '-'); optind++) k++; if(k==2) { pbc_single_pairing_init(pairing, argc, argv[optind-k]); pbc_single_pairing_init(pairing2, argc, argv[optind-k+1]); } else { fprintf(stderr, "Input invalid!\n"); usage(); exit(-1); } break; case '?': fprintf(stderr, "Invalid parameters!\n"); usage(); exit(-1); break; default: abort(); } } if(!canrun) { printf("Please at least set \'-f\' or \'-g\'\n"); usage(); exit(-1); } //printf("Initializing system variable and public key....\n"); element_init_G2(g, pairing); element_init_G2(X, pairing); element_init_G2(Y, pairing); element_init_Zr(x, pairing2); element_init_Zr(y, pairing2); element_random(x); element_random(y); printf("g=%lu X=%lu Y=%lu x=%lu y=%lu\n",sizeof(g),sizeof(X),sizeof(Y),sizeof(x),sizeof(y)); //system variable & public key generation element_random(g); if(verbose) element_printf("system parameter g = %B\n", g); element_pow_zn(X, g, x); element_pow_zn(Y, g, y); // mpz_t mpz_g, mpz_X, mpz_Y; // mpz_inits(mpz_g, mpz_X, mpz_Y, mpz_x, mpz_y, NULL); // element_to_mpz(mpz_g, g); // element_to_mpz(mpz_x, x); // element_to_mpz(mpz_y, y); // mpz_powm(mpz_X, mpz_g, mpz_x, pairing->r); // element_set_mpz(X, mpz_X); // //element_pow_zn(X, g, x); // mpz_powm(mpz_Y, mpz_g, mpz_y, pairing->r); // element_set_mpz(Y, mpz_Y); // if(verbose) { // gmp_printf("pair order %zd\n", pairing->r); // gmp_printf("mpz g %zd\n", mpz_g); // element_printf("x = %B\n", x); // gmp_printf("mpz x %zd\n", mpz_x); // gmp_printf("mpz y %zd\n", mpz_y); // gmp_printf("mpz X %zd\n", mpz_X); // element_printf("public key X = %B\n", X); // element_printf("public key Y = %B\n", Y); // } // //element_pow_zn(Y, g, y); // mpz_clear(mpz_g);mpz_clear(mpz_X);mpz_clear(mpz_Y); unsigned char *a, *b, *c, *cu; /*******Working********/ start_t = clock(); clock_t tmp_start; clock_t bscurtotal = 0; float bstotal; clock_t tmp=0; clock_t max; clock_t min; for(int i=0; i<user_num; i++) { //printf("New user comes...\n"); UEActivity(&a, &b, &c, &cu); tmp_start = clock(); BSActivity(a, b, c, cu); tmp = clock() - tmp_start; if(i==0) {min = tmp; max = tmp;} else { if(tmp > max) max = tmp; if(tmp < min) min = tmp; } printf("Processing time for this user is %f ms \n",(float)tmp*1000 / CLOCKS_PER_SEC); bscurtotal += tmp; } clock_t avg = bscurtotal / user_num; printf("max single user time is %f ms \n",(float)max*1000 / CLOCKS_PER_SEC); printf("min single user time is %f ms \n",(float)min*1000 / CLOCKS_PER_SEC); printf("average single user time is %f ms \n",(float)avg*1000 / CLOCKS_PER_SEC); //printf("************************\n"); end_t = clock(); total_t = (float)(end_t - start_t) / CLOCKS_PER_SEC; bstotal = (float)bscurtotal / CLOCKS_PER_SEC; //printf("User number: %d. \nTotal Generation & verification time taken by CPU: %f seconds.\n", user_num, total_t); //printf("Total verification time at base station taken by CPU: %f seconds.\n", bstotal); //printf("Exiting of the program...\n"); element_clear(g); element_clear(X); element_clear(Y); element_clear(x); element_clear(y); return 0; }
void test_libfenc(char *policy) { FENC_ERROR result; fenc_context context; fenc_group_params group_params; fenc_global_params global_params; fenc_function_input policy_input; pairing_t pairing; FILE *fp; char *public_params_buf = NULL; size_t serialized_len; memset(&context, 0, sizeof(fenc_context)); memset(&group_params, 0, sizeof(fenc_group_params)); memset(&global_params, 0, sizeof(fenc_global_params)); /* Initialize the library. */ result = libfenc_init(); report_error("Initializing library", result); /* Create a Sahai-Waters context. */ result = libfenc_create_context(&context, FENC_SCHEME_WATERSCP); report_error("Creating context for Waters CP scheme", result); /* Load group parameters from a file. */ fp = fopen(PARAM, "r"); if (fp != NULL) { libfenc_load_group_params_from_file(&group_params, fp); libfenc_get_pbc_pairing(&group_params, pairing); } else { perror("Could not open type-d parameters file.\n"); return; } fclose(fp); /* Set up the global parameters. */ result = context.generate_global_params(&global_params, &group_params); result = libfenc_gen_params(&context, &global_params); /* Set up the publci parameters */ fp = fopen(PUBLIC_FILE".cp", "r"); if(fp != NULL) { size_t pub_len = read_file(fp, &public_params_buf); /* base-64 decode */ uint8 *bin_public_buf = NewBase64Decode((const char *) public_params_buf, pub_len, &serialized_len); /* Import the parameters from binary buffer: */ result = libfenc_import_public_params(&context, bin_public_buf, serialized_len); report_error("Importing public parameters", result); free(public_params_buf); free(bin_public_buf); } else { perror("Could not open public parameters\n"); return; } fclose(fp); /* encrypt under given policy */ // fenc_attribute_policy *parsed_policy = construct_test_policy(); fenc_attribute_policy *parsed_policy = (fenc_attribute_policy *) malloc(sizeof(fenc_attribute_policy)); memset(parsed_policy, 0, sizeof(fenc_attribute_policy)); fenc_policy_from_string(parsed_policy, policy); policy_input.input_type = FENC_INPUT_NM_ATTRIBUTE_POLICY; policy_input.scheme_input = (void *) parsed_policy; printf("START: test_secret_sharing\n"); test_secret_sharing(parsed_policy, pairing); printf("END: test_secret_sharing\n"); /* simple test */ element_t ONE, TWO, THREE, ONEG2, TWOG2, THREEG2, ONEGT, TWOGT, FinalGT; element_init_G1(ONE, pairing); element_init_G1(TWO, pairing); element_init_G1(THREE, pairing); element_init_G2(ONEG2, pairing); element_init_G2(TWOG2, pairing); element_init_G2(THREEG2, pairing); element_init_GT(ONEGT, pairing); element_init_GT(TWOGT, pairing); element_init_GT(FinalGT, pairing); clock_t start, stop; double timeG1, timeG2, timePairing; element_random(ONE); element_random(TWO); element_random(ONEG2); element_random(TWOG2); // element_random(ONEGT); // element_random(TWOGT); /* time G1 */ start = clock(); element_mul(THREE, ONE, TWO); stop = clock(); timeG1 = ((double)(stop - start))/CLOCKS_PER_SEC; element_printf("THREEG1: %B, ", THREE); printf("G1 mul time: %f secs\n", timeG1); /* time G2 */ start = clock(); element_mul(THREEG2, ONEG2, TWOG2); stop = clock(); timeG2 = ((double)(stop - start))/CLOCKS_PER_SEC; element_printf("THREEG2: %B, ", THREEG2); printf("G2 mul time: %f secs\n", timeG2); /* time GT start = clock(); element_mul(FinalGT, ONEGT, TWOGT); stop = clock(); timeGT = ((double)(stop - start))/CLOCKS_PER_SEC; element_printf("FinalGT: %B, ", FinalGT); printf("GT mul time: %f secs\n", timeGT); */ /* time pairings */ start = clock(); pairing_apply(FinalGT, THREE, THREEG2, pairing); stop = clock(); timePairing = ((double)(stop - start))/CLOCKS_PER_SEC; element_printf("Pairing: %B, ", FinalGT); printf("GT pairing time: %f secs\n", timePairing); free(parsed_policy); result = libfenc_shutdown(); report_error("Shutting down library", result); }