Esempio n. 1
0
/* Galbraith & Scott Method */
static void gs(BIG u[4],BIG e)
{
	int i,j;
	BIG v[4],t,q;
	DBIG d;
	BIG_rcopy(q,CURVE_Order);
	for (i=0;i<4;i++)
	{
		BIG_rcopy(t,CURVE_WB[i]);
		BIG_mul(d,t,e);
		BIG_ddiv(v[i],d,q);
		BIG_zero(u[i]);
	}

	BIG_copy(u[0],e);
	for (i=0;i<4;i++)
		for (j=0;j<4;j++)
		{
			BIG_rcopy(t,CURVE_BB[j][i]);
			BIG_modmul(t,v[j],t,q);
			BIG_add(u[i],u[i],q);
			BIG_sub(u[i],u[i],t);
			BIG_mod(u[i],q);
		}
	return;
}
Esempio n. 2
0
/* Galbraith & Scott Method */
static void gs(BIG u[4],BIG e)
{
    int i;
#if CHOICE<BLS_CURVES
    int j;
    BIG v[4],t,q;
    DBIG d;
    BIG_rcopy(q,CURVE_Order);
    for (i=0; i<4; i++)
    {
        BIG_rcopy(t,CURVE_WB[i]);
//BIG_norm(t); BIG_norm(e);
        BIG_mul(d,t,e);
        BIG_ddiv(v[i],d,q);
        BIG_zero(u[i]);
    }

    BIG_copy(u[0],e);
    for (i=0; i<4; i++)
        for (j=0; j<4; j++)
        {
            BIG_rcopy(t,CURVE_BB[j][i]);
            BIG_modmul(t,v[j],t,q);
            BIG_add(u[i],u[i],q);
            BIG_sub(u[i],u[i],t);
            BIG_mod(u[i],q);
        }

#else

    BIG x,w;
    BIG_rcopy(x,CURVE_Bnx);
    BIG_copy(w,e);

    for (i=0; i<4; i++)
    {
        BIG_copy(u[i],w);
        BIG_mod(u[i],x);
        BIG_sdiv(w,x);
    }

#endif
    return;
}
Esempio n. 3
0
/* GLV method */
static void glv(BIG u[2],BIG e)
{
#if CHOICE<BLS_CURVES
    int i,j;
    BIG v[2],t,q;
    DBIG d;
    BIG_rcopy(q,CURVE_Order);
    for (i=0; i<2; i++)
    {
        BIG_rcopy(t,CURVE_W[i]);
//BIG_norm(t); BIG_norm(e);
        BIG_mul(d,t,e);
        BIG_ddiv(v[i],d,q);
        BIG_zero(u[i]);
    }
    BIG_copy(u[0],e);
    for (i=0; i<2; i++)
        for (j=0; j<2; j++)
        {
            BIG_rcopy(t,CURVE_SB[j][i]);
            BIG_modmul(t,v[j],t,q);
            BIG_add(u[i],u[i],q);
            BIG_sub(u[i],u[i],t);
            BIG_mod(u[i],q);
        }

#else
// -(x^2).P = (Beta.x,y)

    BIG x,x2,q;
    BIG_rcopy(x,CURVE_Bnx);
    BIG_smul(x2,x,x);
    BIG_copy(u[0],e);
    BIG_mod(u[0],x2);
    BIG_copy(u[1],e);
    BIG_sdiv(u[1],x2);

    BIG_rcopy(q,CURVE_Order);
    BIG_sub(u[1],q,u[1]);

#endif

    return;
}
Esempio n. 4
0
void FP12_pow4(FP12 *p,FP12 *q,BIG u[4])
{
	int i,j,a[4],nb,m;
	FP12 g[8],c,s[2];
	BIG t[4],mt;
	sign8 w[NLEN*BASEBITS+1];

	for (i=0;i<4;i++)
		BIG_copy(t[i],u[i]);

	FP12_copy(&g[0],&q[0]); FP12_conj(&s[0],&q[1]); FP12_mul(&g[0],&s[0]);  /* P/Q */	
	FP12_copy(&g[1],&g[0]);
	FP12_copy(&g[2],&g[0]);
	FP12_copy(&g[3],&g[0]);
	FP12_copy(&g[4],&q[0]); FP12_mul(&g[4],&q[1]);  /* P*Q */
	FP12_copy(&g[5],&g[4]);
	FP12_copy(&g[6],&g[4]);
	FP12_copy(&g[7],&g[4]);

	FP12_copy(&s[1],&q[2]); FP12_conj(&s[0],&q[3]); FP12_mul(&s[1],&s[0]);       /* R/S */
	FP12_conj(&s[0],&s[1]); FP12_mul(&g[1],&s[0]); 
	FP12_mul(&g[2],&s[1]); 
	FP12_mul(&g[5],&s[0]);
	FP12_mul(&g[6],&s[1]);
	FP12_copy(&s[1],&q[2]); FP12_mul(&s[1],&q[3]);      /* R*S */
	FP12_conj(&s[0],&s[1]); FP12_mul(&g[0],&s[0]);
	FP12_mul(&g[3],&s[1]);
	FP12_mul(&g[4],&s[0]);
	FP12_mul(&g[7],&s[1]);

/* if power is even add 1 to power, and add q to correction */
	FP12_one(&c);

	BIG_zero(mt);
	for (i=0;i<4;i++)
	{
		if (BIG_parity(t[i])==0)
		{
			BIG_inc(t[i],1); BIG_norm(t[i]);
			FP12_mul(&c,&q[i]);
		}
		BIG_add(mt,mt,t[i]); BIG_norm(mt);
	}

	FP12_conj(&c,&c);
	nb=1+BIG_nbits(mt);

/* convert exponent to signed 1-bit window */
	for (j=0;j<nb;j++)
	{
		for (i=0;i<4;i++)
		{
			a[i]=BIG_lastbits(t[i],2)-2;
			BIG_dec(t[i],a[i]); BIG_norm(t[i]); 
			BIG_fshr(t[i],1);
		}
		w[j]=8*a[0]+4*a[1]+2*a[2]+a[3];
	}
	w[nb]=8*BIG_lastbits(t[0],2)+4*BIG_lastbits(t[1],2)+2*BIG_lastbits(t[2],2)+BIG_lastbits(t[3],2);
	FP12_copy(p,&g[(w[nb]-1)/2]);  

	for (i=nb-1;i>=0;i--)
	{
		m=w[i]>>7;
		j=(w[i]^m)-m;  /* j=abs(w[i]) */
		j=(j-1)/2;
		FP12_copy(&s[0],&g[j]);
		FP12_conj(&s[1],&g[j]);
		FP12_usqr(p,p);
		FP12_mul(p,&s[m&1]);
	}
	FP12_mul(p,&c); /* apply correction */
	FP12_reduce(p);
}