Ejemplo n.º 1
0
double mult2_precomp(int eb,big x,big y,big a2,big a6,int M,int A,int B,int C)
{
    big e,c,d;
    int iterations=0;
    ebrick2 binst;
    clock_t start;
    double elapsed;
    char *mem;

    mem=(char *)memalloc(3);
    e=mirvar_mem(mem,0);
    c=mirvar_mem(mem,1);
    d=mirvar_mem(mem,2);
    ebrick2_init(&binst,x,y,a2,a6,M,A,B,C,WINDOW,eb);
    bigbits(eb,e);
    start=clock();

    do {
       mul2_brick(&binst,e,c,d);
       iterations++;
       elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
    } while (elapsed<MIN_TIME || iterations<MIN_ITERS);

    elapsed=1000.0*elapsed/iterations;
    printf("EP - %8d iterations             ",iterations);
    printf(" %8.2lf ms per iteration\n",elapsed);

    ebrick2_end(&binst);
    memkill(mem,3);
   
    return elapsed;
}
Ejemplo n.º 2
0
void BaseOT::Miracl_brickend(ebrick2* bg)
{
	ebrick2_end(bg);
}
Ejemplo n.º 3
0
int main()
{
    FILE *fp;
    int m,a,b,c;
    big e,a2,a6,x,y,r;
    epoint *g;
    ebrick2 binst;
    int i,d,ndig,nb,best,time,store,base;
    miracl *mip=mirsys(50,0);
    e=mirvar(0);
    a2=mirvar(0);
    a6=mirvar(0);
    x=mirvar(0);
    y=mirvar(0);
    r=mirvar(0);

    fp=fopen("common2.ecs","r");
    fscanf(fp,"%d\n",&m);
    mip->IOBASE=16;
    cinnum(a2,fp);
    cinnum(a6,fp);
    cinnum(r,fp);
    cinnum(x,fp);
    cinnum(y,fp);
    mip->IOBASE=10;

    fscanf(fp,"%d\n",&a);
    fscanf(fp,"%d\n",&b);
    fscanf(fp,"%d\n",&c);
    
    printf("modulus is %d bits in length\n",m);
    printf("Enter size of exponent in bits = ");
    scanf("%d",&nb);
    getchar();

    ebrick2_init(&binst,x,y,a2,a6,m,a,b,c,nb);

    printf("%d big numbers have been precomputed and stored\n",binst.store);

    bigdig(nb,2,e);  /* random exponent */  

    printf("naive method\n");
    ecurve2_init(m,a,b,c,a2,a6,FALSE,MR_PROJECTIVE);
    g=epoint2_init();
    epoint2_set(x,y,0,g);
    ecurve2_mult(e,g,g);
    epoint2_get(g,x,y);
    cotnum(x,stdout);
    cotnum(y,stdout);

    zero(x); zero(y);
    printf("Brickel et al method\n");
    mul2_brick(&binst,e,x,y);

    ebrick2_end(&binst);
    
    cotnum(x,stdout);
    cotnum(y,stdout);

    return 0;
}
Ejemplo n.º 4
0
void Miraclbrickend(ebrick2* bg)
{
	ebrick2_end(bg);
}
Ejemplo n.º 5
0
int main()
{
    FILE *fp;
    int m,a,b,c;
    big e,a2,a6,x,y,r,t;
    epoint *g;
    ebrick2 binst;
    char fname[100];
    BOOL last;
    int i,j,len,bptr,nb,window,wsize,words,winsize;
    miracl *mip=mirsys(50,0);
    e=mirvar(0);
    a2=mirvar(0);
    a6=mirvar(0);
    x=mirvar(0);
    y=mirvar(0);
    r=mirvar(0);
    t=mirvar(0);

    printf("Enter name of .ecs file= ");
    gets(fname);
    strip(fname);
    strcat(fname,".ecs");

    if ((fp=fopen(fname,"rt"))==NULL)
    {
        printf("Unable to open file %s\n",fname);
        return 0;
    }
    fscanf(fp,"%d\n",&m);

    mip->IOBASE=16;
    cinnum(a2,fp);
    cinnum(a6,fp);
    cinnum(r,fp);
    cinnum(x,fp);
    cinnum(y,fp);
    mip->IOBASE=10;

    fscanf(fp,"%d\n",&a);
    fscanf(fp,"%d\n",&b);
    fscanf(fp,"%d\n",&c);
    
    printf("modulus is %d bits in length\n",m);
    nb=m;
    printf("Enter window size in bits (1-10)= ");
    scanf("%d",&window);
    getchar();
    printf("Enter word size of application processor (8, 16, 32 or 64 bit)= ");
    scanf("%d",&wsize);
    getchar();

    if (wsize!=8 && wsize!=16 && wsize!=32 && wsize!=64 || wsize>MIRACL)
    {
        printf("Error - Unsupported word size\n");
        exit(0);
    }


    if (!ebrick2_init(&binst,x,y,a2,a6,m,a,b,c,window,nb))
    {
        printf("Failed to Initialize\n");
        return 0;
    }

    len=MR_ROUNDUP(m,MIRACL);
    words=MR_ROUNDUP(m,wsize);
    printf("\n--------------------CUT HERE----------------------\n\n");
    printf("#define CURVE_M %d\n",m);
    printf("#define CURVE_A %d\n",a);
    printf("#define CURVE_B %d\n",b);
    printf("#define CURVE_C %d\n",c);
    printf("#define WINDOW %d\n",window);
    printf("#define WORDS %d\n",words);

    printf("\nstatic const mr_small rom[]={\n");

    bprint(a6->w,len,words,wsize,FALSE);
    bprint(r->w,len,words,wsize,FALSE);
    bprint(x->w,len,words,wsize,FALSE);
    bprint(y->w,len,words,wsize,TRUE);

    printf("\nstatic const mr_small prom[]={\n");
    bptr=0;
    last=FALSE;
    winsize=2*(1<<window);
    for (i=0;i<winsize;i++)
    {
        zero(t);
        t->len=len;
        for (j=0;j<len;j++)
            t->w[j]=binst.table[bptr++];
       
        if (i==winsize-1) last=TRUE;
        bprint(t->w,len,words,wsize,last);
    }


    ebrick2_end(&binst);
    
    return 0;
}
Ejemplo n.º 6
0
/*
 * Class:     edu_biu_scapi_primitives_dlog_miracl_MiraclDlogECF2m
 * Method:    endF2mExponentiateWithPreComputedValues
 * Signature: (J)V
 *
 * This function cleans up used resources after performing exponentiation with precomputed values for a certain base.
 * It should be used if the calling application has finished working with the specified base.
 */
JNIEXPORT void JNICALL Java_edu_biu_scapi_primitives_dlog_miracl_MiraclDlogECF2m_endF2mExponentiateWithPreComputedValues
  (JNIEnv * env, jobject, jlong base){
	  //Call Miracl's function that cleans up after an application of the Comb method for GF(2m) elliptic curves.
	  ebrick2_end((ebrick2 *)base);
}