Exemple #1
0
void mcl_ecpbs_printpoint(epoint *p, char *msg) {
	epoint_norm(p);
	fprintf(stdout, "%s\t\t", msg);
	otnum(p->X, stdout);
	fprintf(stdout, "\t\t");
	otnum(p->Y, stdout);
}
Exemple #2
0
void mcl_ecpbs_hash_epsilon(big result, epoint *alpha, epoint *beta, epoint *z,
		char *message, mcl_ecpbs_parameters *parameters) {
	int buffer_len, num_bytes = 0;
	int big_size;
	char *buffer, *pos;

	/* miracl *mip = get_mip(); */
	/* FIXME do this dynamically: big_size_bits = mip->nib * 8; */
	big_size = 20;

	/* 6 bigs for X and Y of alpha,beta,and z */
	buffer_len = (6 * big_size) + strlen(message) + 1;

	epoint_norm(alpha);
	epoint_norm(beta);
	epoint_norm(z);

	/* compute: H(alpha->X|alpha->Y|beta->X|beta->Y|z->X|z->Y|msg) */
	buffer = calloc(1, buffer_len);
	pos = buffer;
	num_bytes = big_to_bytes(big_size, alpha->X, pos, FALSE);
	pos = pos + num_bytes;
	num_bytes = big_to_bytes(big_size, alpha->Y, pos, FALSE);
	pos = pos + num_bytes;
	num_bytes = big_to_bytes(big_size, beta->X, pos, FALSE);
	pos = pos + num_bytes;
	num_bytes = big_to_bytes(big_size, beta->Y, pos, FALSE);
	pos = pos + num_bytes;
	num_bytes = big_to_bytes(big_size, z->X, pos, FALSE);
	pos = pos + num_bytes;
	num_bytes = big_to_bytes(big_size, z->Y, pos, FALSE);
	pos = pos + num_bytes;
	memcpy(pos, message, strlen(message));

	mcl_ecpbs_Hhash(result, buffer, parameters->q);
	free(buffer);
}
void ecap(_MIPD_ zzn2 *Qx,zzn2 *Qy,epoint *P,big T,big fr,big delta,zzn2* r)
{
    zzn4 res,w;
#ifndef MR_STATIC
    char *mem=memalloc(_MIPP_ 8);
#else
    char mem[MR_BIG_RESERVE(8)];
    memset(mem,0,MR_BIG_RESERVE(8));
#endif
    res.x.a=mirvar_mem(_MIPP_ mem,0);
    res.x.b=mirvar_mem(_MIPP_ mem,1);
    res.y.a=mirvar_mem(_MIPP_ mem,2);
    res.y.b=mirvar_mem(_MIPP_ mem,3);
    w.x.a=mirvar_mem(_MIPP_ mem,4);
    w.x.b=mirvar_mem(_MIPP_ mem,5);
    w.y.a=mirvar_mem(_MIPP_ mem,6);
    w.y.b=mirvar_mem(_MIPP_ mem,7);

    res.unitary=FALSE;
    w.unitary=FALSE;

    epoint_norm(_MIPP_ P);

    fast_tate_pairing(_MIPP_ Qx,Qy,P,T,fr,delta,&w,&res);

    zzn4_copy(&res,&w);
    zzn4_powq(_MIPP_ fr,&res);

    zzn4_powu(_MIPP_ &w,delta,&w);
    zzn4_mul(_MIPP_ &res,&w,&res);

    zzn2_copy(&(res.x),r);

#ifdef MR_COUNT_OPS
    printf("Final Exponentiation cost\n");
    printf("fpc= %d\n",fpc);
    printf("fpa= %d\n",fpa);
    printf("fpx= %d\n",fpx);

    fpa=fpc=fpx=0;
#endif

#ifndef MR_STATIC
    memkill(_MIPP_ mem,8);
#else
    memset(mem,0,MR_BIG_RESERVE(8));
#endif
}
void ecap(_MIPD_ epoint *P,zzn3 *Qx,zzn3 *Qy,big q,big cf,zzn3* r)
{
    zzn6 res,w;
#ifndef MR_STATIC
    char *mem=memalloc(_MIPP_ 12);
#else
    char mem[MR_BIG_RESERVE(12)];        
    memset(mem,0,MR_BIG_RESERVE(12));
#endif
    res.x.a=mirvar_mem(_MIPP_ mem,0);
    res.x.b=mirvar_mem(_MIPP_ mem,1);
    res.x.c=mirvar_mem(_MIPP_ mem,2);
    res.y.a=mirvar_mem(_MIPP_ mem,3);
    res.y.b=mirvar_mem(_MIPP_ mem,4);
    res.y.c=mirvar_mem(_MIPP_ mem,5);
    w.x.a=mirvar_mem(_MIPP_ mem,6);
    w.x.b=mirvar_mem(_MIPP_ mem,7);
    w.x.c=mirvar_mem(_MIPP_ mem,8);
    w.y.a=mirvar_mem(_MIPP_ mem,9);
    w.y.b=mirvar_mem(_MIPP_ mem,10);
    w.y.c=mirvar_mem(_MIPP_ mem,11);
    res.unitary=FALSE;
    w.unitary=FALSE;

    epoint_norm(_MIPP_ P);
    fast_tate_pairing(_MIPP_ P,Qx,Qy,q,cf,&w,&res);

    zzn6_copy(&res,&w);
    zzn6_powq(_MIPP_ &res);
    zzn6_mul(_MIPP_ &res,&res,&res);

    zzn6_powu(_MIPP_ &w,cf,&w);
    zzn6_mul(_MIPP_ &res,&w,&res);

    zzn3_copy(&(res.x),r);        

#ifndef MR_STATIC      
    memkill(_MIPP_ mem,12);
#else
    memset(mem,0,MR_BIG_RESERVE(12)); 
#endif
}
void fast_tate_pairing(_MIPD_ epoint *P,zzn3 *Qx,zzn3 *Qy,big q,big cf,zzn6 *w,zzn6* res)
{
    int i,j,n,nb,nbw,nzs;
    epoint *t[4],*A,*P2;
    zzn6 zn[4];
    big work[4];

#ifndef MR_STATIC
    char *mem=memalloc(_MIPP_ 28);
	char *mem1=ecp_memalloc(_MIPP_ 6);
#else
    char mem[MR_BIG_RESERVE(28)];  
    char mem1[MR_ECP_RESERVE(6)]; 
    memset(mem,0,MR_BIG_RESERVE(28));
    memset(mem1,0,MR_ECP_RESERVE(6));
#endif

    for (i=0;i<4;i++)
        t[i]=epoint_init_mem(_MIPP_ mem1,i);
    A=epoint_init_mem(_MIPP_ mem1,4);
    P2=epoint_init_mem(_MIPP_ mem1,5);
  
    for (j=i=0;i<4;i++)
    {
        work[i]=mirvar_mem(_MIPP_ mem,j++);
        zn[i].x.a=mirvar_mem(_MIPP_ mem,j++);
        zn[i].x.b=mirvar_mem(_MIPP_ mem,j++);
        zn[i].x.c=mirvar_mem(_MIPP_ mem,j++);
        zn[i].y.a=mirvar_mem(_MIPP_ mem,j++);
        zn[i].y.b=mirvar_mem(_MIPP_ mem,j++);
        zn[i].y.c=mirvar_mem(_MIPP_ mem,j++);
        zn[i].unitary=FALSE;
    }

    zzn6_from_int(_MIPP_ 1,&zn[0]); 
    epoint_copy(P,A);
    epoint_copy(P,P2);
    epoint_copy(P,t[0]);

    g(_MIPP_ P2,P2,Qx,Qy,res);
    epoint_norm(_MIPP_ P2);

    for (i=1;i<4;i++)
    {
        g(_MIPP_ A,P2,Qx,Qy,w);
        epoint_copy(A,t[i]);
        zzn6_mul(_MIPP_ &zn[i-1],w,&zn[i]);
        zzn6_mul(_MIPP_ &zn[i],res,&zn[i]);
    }

    epoint_multi_norm(_MIPP_ 4,work,t);

    epoint_copy(P,A);
    zzn6_from_int(_MIPP_ 1,res);
 
    nb=logb2(_MIPP_ q);
    for (i=nb-2;i>=0;i-=(nbw+nzs))
    {
        n=mr_window(_MIPP_ q,i,&nbw,&nzs,3);
        for (j=0;j<nbw;j++)
        {
            zzn6_mul(_MIPP_ res,res,res);
            g(_MIPP_ A,A,Qx,Qy,w);
            zzn6_mul(_MIPP_ res,w,res);
        }
        if (n>0)
        {
            zzn6_mul(_MIPP_ res,&zn[n/2],res);
            g(_MIPP_ A,t[n/2],Qx,Qy,w);
            zzn6_mul(_MIPP_ res,w,res);
        }
        for (j=0;j<nzs;j++) 
        {
            zzn6_mul(_MIPP_ res,res,res);
            g(_MIPP_ A,A,Qx,Qy,w);
            zzn6_mul(_MIPP_ res,w,res);
        }
    }

    zzn6_copy(res,w);
    zzn6_powq(_MIPP_ w);
    zzn6_mul(_MIPP_ res,w,res);

    zzn6_copy(res,w);
    zzn6_powq(_MIPP_ w);
    zzn6_powq(_MIPP_ w);
    zzn6_powq(_MIPP_ w);

    zzn6_inv(_MIPP_ res);
    zzn6_mul(_MIPP_ res,w,res);

    res->unitary=TRUE;

#ifndef MR_STATIC      
    memkill(_MIPP_ mem,28);
    ecp_memkill(_MIPP_ mem1,6);
#else
    memset(mem,0,MR_BIG_RESERVE(28)); 
    memset(mem1,0,MR_ECP_RESERVE(6));
#endif
}