当前位置: 首页>>代码示例>>C++>>正文


C++ element_random函数代码示例

本文整理汇总了C++中element_random函数的典型用法代码示例。如果您正苦于以下问题:C++ element_random函数的具体用法?C++ element_random怎么用?C++ element_random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了element_random函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: xsgs_gm_gen

// 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;
}
开发者ID:RUB-SysSec,项目名称:libXSGS,代码行数:27,代码来源:xsgs_gen.c

示例2: GT_random

static void GT_random(element_ptr e) {
    element_t a, b;
    element_init(a, e->field->pairing->G1);
    element_init(b, e->field->pairing->G1);
    element_random(a);
    element_random(b);
    element_pairing(e, a, b);
    element_clear(a);
    element_clear(b);
}
开发者ID:JasonSome,项目名称:pbc,代码行数:10,代码来源:eta_T_3.c

示例3: main

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;
}
开发者ID:TzuPingWu,项目名称:ECC,代码行数:55,代码来源:curve.c

示例4: main

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);
  }
}
开发者ID:stefano81,项目名称:cryptoquery,代码行数:55,代码来源:benchmark_pairing.c

示例5: weil

void weil(element_t w, element_t g, element_t h)
{
    element_t gr;
    element_t hs;
    element_t r;
    element_t s;
    element_t z, z0, z1;

    element_init(z, Fq2);
    element_init(z0, Fq2);
    element_init(z1, Fq2);

    element_init_same_as(gr, g);
    element_init_same_as(hs, h);
    element_init_same_as(r, g);
    element_init_same_as(s, h);

    element_random(r);
    element_random(s);
    //point_random always takes the same square root
    //why not take the other one for once?
    element_neg(r, r);
    element_set_str(r, "[[40,0],[54,0]]", 0);
    element_set_str(s, "[[48,55],[28,51]]", 0);

    element_printf("chose R = %B\n", r);
    element_printf("chose S = %B\n", s);
    element_add(gr, g, r);
    element_add(hs, h, s);

    element_printf("P+R = %B\n", gr);
    element_printf("Q+S = %B\n", hs);
    miller(z, gr, r, g, hs);
    miller(z0, gr, r, g, s);
    element_div(z1, z, z0);
    element_printf("num: %B\n", z1);

    miller(z, hs, s, h, gr);
    miller(z0, hs, s, h, r);
    element_div(w, z, z0);
    element_printf("denom: %B\n", w);

    element_div(w, z1, w);

    element_clear(gr);
    element_clear(r);
    element_clear(hs);
    element_clear(s);
    element_clear(z);
    element_clear(z0);
    element_clear(z1);
}
开发者ID:Russ36363,项目名称:pbc-thesis,代码行数:52,代码来源:59.c

示例6: test_gf3m_mult

static void test_gf3m_mult(void) {
    element_random(a);
    element_mul(a, a, e0);
    EXPECT(!element_cmp(a, e0));

    element_random(a);
    element_mul(b, a, e1);
    EXPECT(!element_cmp(a, b));

    element_random(a);
    element_mul(b, a, e2);
    element_add(a, a, b);
    EXPECT(!element_cmp(a, e0));
}
开发者ID:blynn,项目名称:pbc,代码行数:14,代码来源:ternary_extension_field_test.c

示例7: do_multi

    // 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]);
        }
    }
开发者ID:dscharles,项目名称:impluniversidad,代码行数:50,代码来源:main.c

示例8: bb_sign

void bb_sign(unsigned char *sig, unsigned int hashlen, unsigned char *hash, bb_public_key_t pk, bb_private_key_t sk)
{
	int len;
	element_t sigma;
	element_t r, z, m;
	bb_sys_param_ptr param = pk->param;
	pairing_ptr pairing = param->pairing;

	element_init(r, pairing->Zr);
	element_init(z, pairing->Zr);
	element_init(m, pairing->Zr);

	element_random(r);
	element_from_hash(m, hash, hashlen);
	element_mul(z, sk->y, r);
	element_add(z, z, sk->x);
	element_add(z, z, m);
	element_invert(z, z);
	element_init(sigma, pairing->G1);
	element_pow_zn(sigma, pk->g1, z);

	len = element_to_bytes_x_only(sig, sigma);
	element_to_bytes(&sig[len], r);

	element_clear(sigma);
	element_clear(r);
	element_clear(z);
	element_clear(m);
}
开发者ID:Gp2mv3,项目名称:ThesisPOC,代码行数:29,代码来源:bb.c

示例9: test_gf33m_cubic

static void test_gf33m_cubic(void) {
    element_random(a3);
    element_mul(b3, a3, a3);
    element_mul(b3, b3, a3);
    element_cubic(a3, a3);
    EXPECT(!element_cmp(a3, b3));
}
开发者ID:blynn,项目名称:pbc,代码行数:7,代码来源:ternary_extension_field_test.c

示例10: tate

void tate(element_t z, element_t P, element_t Q)
{
    mpz_t q1r;

    mpz_init(q1r);
    mpz_set_ui(q1r, 696);

    /*
    millertate(z, P, Q);
    element_printf("prepow: z = %B\n", z);
    element_pow_mpz(z, z, q1r);
    */
    {
	element_t R, QR;
	element_t z0;

	element_init_same_as(R, P);
	element_init_same_as(QR, P);
	element_init_same_as(z0, z);

	element_random(R);
	element_add(QR, Q, R);

	millertate(z, P, QR);
	millertate(z0, P, R);
	element_div(z, z, z0);
	element_pow_mpz(z, z, q1r);
	element_clear(R);
	element_clear(QR);
    }

    mpz_clear(q1r);
}
开发者ID:Russ36363,项目名称:pbc-thesis,代码行数:33,代码来源:59.c

示例11: test_gf33m_inverse

static void test_gf33m_inverse(void) {
    element_random(a3);
    element_invert(b3, a3);
    element_mul(a3, a3, b3);
    element_ptr a0 = element_item(a3, 0);
    EXPECT(!element_cmp(a0, e1));
}
开发者ID:blynn,项目名称:pbc,代码行数:7,代码来源:ternary_extension_field_test.c

示例12: point_random

static void point_random(element_t a) {
    point_ptr p = DATA(a);
    element_ptr x = p->x, y = p->y;
    field_ptr f = x->field;
    p->isinf = 0;
    element_t t, t2, e1;
    element_init(t, f);
    element_init(e1, f);
    element_set1(e1);
    element_init(t2, f);
    do {
        element_random(x);
        if (element_is0(x))
            continue;
        element_cubic(t, x); // t == x^3
        element_sub(t, t, x); // t == x^3 - x
        element_add(t, t, e1); // t == x^3 - x + 1
        element_sqrt(y, t);  // y == sqrt(x^3 - x + 1)
        element_mul(t2, y, y); // t2 == x^3 - x + 1
    } while (element_cmp(t2, t)); // t2 != t

    // make sure order of $a$ is order of $G_1$
    pairing_ptr pairing = FIELD(a)->pairing;
    pairing_data_ptr dp = pairing->data;
    element_pow_mpz(a, a, dp->n2);

    element_clear(t);
    element_clear(t2);
    element_clear(e1);
}
开发者ID:JasonSome,项目名称:pbc,代码行数:30,代码来源:eta_T_3.c

示例13: test_gf36m_cubic

static void test_gf36m_cubic(void) {
    element_random(a6);
    element_mul(b6, a6, a6);
    element_mul(b6, b6, a6);
    element_cubic(a6, a6);
    EXPECT(!element_cmp(a6, b6));
}
开发者ID:blynn,项目名称:pbc,代码行数:7,代码来源:ternary_extension_field_test.c

示例14: test_gf3m_cubic

static void test_gf3m_cubic(void) {
    element_random(a);
    element_mul(b, a, a);
    element_mul(b, a, b);
    element_cubic(a, a);
    EXPECT(!element_cmp(a, b));
}
开发者ID:blynn,项目名称:pbc,代码行数:7,代码来源:ternary_extension_field_test.c

示例15: test_frob

//============================================
//   Frobenius Map \phi_p
//============================================
void test_frob(Field f)
{
    int i;
    unsigned long long int t1, t2;
    mpz_t p;
    Element a, b, c;

    mpz_init_set(p, *field_get_char(f));

    element_init(a, f);
    element_init(b, f);
    element_init(c, f);

    for (i = 0; i < 100; i++)
    {
        element_random(a);
        element_pow(b, a, p);

        bn254_fp2_frob_p(c, a);

        assert(element_cmp(b, c) == 0);
    }

    t1 = rdtsc();
    for (i = 0; i < N; i++) { bn254_fp2_frob_p(c, a); }
    t2 = rdtsc();

    printf("element frob: %.2lf [clock]\n", (double)(t2 - t1) / N);

    mpz_clear(p);

    element_clear(a);
    element_clear(b);
    element_clear(c);
}
开发者ID:ysk-knbr,项目名称:tepla-1,代码行数:38,代码来源:test_bn254_fp2.c


注:本文中的element_random函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。