Ejemplo n.º 1
0
double mult_precomp(int eb,big x,big y,big a,big b,big p)
{
    big e,c,d;
    int iterations=0;
    ebrick 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);
    ebrick_init(&binst,x,y,a,b,p,WINDOW,eb);
    bigbits(eb,e);
    start=clock();

    do {
       mul_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);

    ebrick_end(&binst);
    memkill(mem,3);
   
    return elapsed;
}
Ejemplo n.º 2
0
BOOL MiraclInitBrick(ebrick* brick, ECn point, fparams* param)
{
	Big x, y;
	point.getxy(x, y);
	return ebrick_init(brick, x.getbig(), y.getbig(), param->eccparams.BA->getbig(), param->eccparams.BB->getbig(),
			param->eccparams.BP->getbig(), 8, param->secparam);
}
Ejemplo n.º 3
0
/*
 * Class:     edu_biu_scapi_primitives_dlog_miracl_MiraclDlogECFp
 * Method:    initFpExponentiateWithPrecomputedValues
 * Signature: (J[B[B[BJ[BII)J
 *
 * This function wraps the creation of an ebrick structure used to precompute exponentiations for a certain base for Dlog groups over Fp. It returns
 * a pointer to the ebrick structure which will be kept by the calling application (edu.biu.scapi...) in some data structure and will
 * be used for further calls to exponentiations with the same base.
 */
JNIEXPORT jlong JNICALL Java_edu_biu_scapi_primitives_dlog_miracl_MiraclDlogECFp_initFpExponentiateWithPrecomputedValues
  (JNIEnv *env, jobject, jlong m, jbyteArray p, jbyteArray a, jbyteArray b, jlong base, jbyteArray exponent, jint window, jint maxBits){



    //translate parameters  to miracl notation
	miracl* mip = (miracl*)m;
	big exponentB = byteArrayToMiraclBig(env, mip, exponent);
	big pB = byteArrayToMiraclBig(env, mip, p);
	big aB = byteArrayToMiraclBig(env, mip, a);
	big bB = byteArrayToMiraclBig(env, mip, b);

	//Create a new structure to hold the precomputed values for given base and exponent
	ebrick* exponentiations = new ebrick();
	
	//Get the coordinates (x,y) from the requested base point: 
	big x, y;
	x = mirvar(mip, 0);
	y = mirvar(mip, 0);
	epoint_get(mip, (epoint*)base, x, y);

	//Perform precomputation
	ebrick_init(mip, exponentiations, x, y, aB, bB, pB, window, maxBits);
	
	//clean up
	mirkill(exponentB);
	mirkill(pB);
	mirkill(aB);
	mirkill(bB);

	//Return the pointer to the structure where the precomputed values are held
	return (jlong)exponentiations;
}
Ejemplo n.º 4
0
int main()
{
    FILE *fp;
    big e,n,a,b,x,y,r;
    epoint *g;
    ebrick binst;
    int i,d,ndig,nb,best,time,store,base,bits;
    miracl *mip=mirsys(50,0);
    n=mirvar(0);
    e=mirvar(0);
    a=mirvar(0);
    b=mirvar(0);
    x=mirvar(0);
    y=mirvar(0);
    r=mirvar(0);

    fp=fopen("common.ecs","r");
    fscanf(fp,"%d\n",&bits);

    mip->IOBASE=16;
    cinnum(n,fp);
    cinnum(a,fp);
    cinnum(b,fp);
    cinnum(r,fp);
    cinnum(x,fp);
    cinnum(y,fp);
    mip->IOBASE=10;

    printf("modulus is %d bits in length\n",logb2(n));
    printf("Enter size of exponent in bits = ");
    scanf("%d",&nb);
    getchar();

    ebrick_init(&binst,x,y,a,b,n,nb);

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

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

    printf("naive method\n");
    ecurve_init(a,b,n,MR_PROJECTIVE);
    g=epoint_init();
    epoint_set(x,y,0,g);
    ecurve_mult(e,g,g);
    epoint_get(g,x,y);
    cotnum(x,stdout);
    cotnum(y,stdout);

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

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

    return 0;
}
Ejemplo n.º 5
0
BOOL BaseOT::Miracl_InitBrick(ebrick* brick, ECn* point)
{
	Big x, y;
	point->getxy(x, y);
	return ebrick_init(brick, x.getbig(), y.getbig(), m_BA->getbig(), m_BB->getbig(), m_BP->getbig(), 8, m_SecParam);
}
Ejemplo n.º 6
0
int main()
{
    FILE *fp;
    big e,n,a,b,x,y,r;
    epoint *g;
    ebrick binst;
    int nb,bits,window,len,bptr,m,i,j;
    miracl *mip=mirsys(50,0);
    n=mirvar(0);
    e=mirvar(0);
    a=mirvar(0);
    b=mirvar(0);
    x=mirvar(0);
    y=mirvar(0);
    r=mirvar(0);
#ifndef MR_EDWARDS
    fp=fopen("common.ecs","rt");
#else
    fp=fopen("edwards.ecs","rt");
#endif
	fscanf(fp,"%d\n",&bits);
    mip->IOBASE=16;
    cinnum(n,fp);
    cinnum(a,fp);
    cinnum(b,fp);
    cinnum(r,fp);
    cinnum(x,fp);
    cinnum(y,fp);
    mip->IOBASE=10;

    printf("modulus is %d bits in length\n",logb2(n));
    printf("Enter max. size of exponent in bits = ");
    scanf("%d",&nb);
    getchar();
    printf("Enter window size in bits (1-10)= ");
    scanf("%d",&window);
    getchar();

    ebrick_init(&binst,x,y,a,b,n,window,nb);

/* Print out the precomputed table (for use in ecdhp.c ?) 
   In which case make sure that MR_SPECIAL is defined and 
   active in the build of this program, so MR_COMBA must
   also be defined as the number of words in the modulus *

len=MR_ROUNDUP(bits,MIRACL);
bptr=0;
for (i=0;i<2*(1<<window);i++)
{
    for (j=0;j<len;j++)
    {
        printf("0x%x,",binst.table[bptr++]);
    }
    printf("\n");
}

*/

    printf("%d elliptic curve points have been precomputed and stored\n",(1<< window));

    bigbits(nb,e);  /* random exponent */  

    printf("naive method\n");
    ecurve_init(a,b,n,MR_PROJECTIVE);
    g=epoint_init();
    epoint_set(x,y,0,g);
    ecurve_mult(e,g,g);
    epoint_get(g,x,y);
    cotnum(x,stdout);
    cotnum(y,stdout);

    printf("Comb method\n");
    mul_brick(&binst,e,x,y);

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

    return 0;
}
Ejemplo n.º 7
0
int main()
{
    int promptr;
    epoint *PB;
    big A,B,p,a,b,pa,pb,key;
    ebrick binst;
    miracl instance;      /* create miracl workspace on the stack */

/* Specify base 16 here so that HEX can be read in directly without a base-change */

    miracl *mip=mirsys(&instance,WORDS*HEXDIGS,16); /* size of bigs is fixed */
    char mem_big[MR_BIG_RESERVE(8)];          /* we need 8 bigs... */
    char mem_ecp[MR_ECP_RESERVE(1)];          /* ..and 1 elliptic curve points */
 	memset(mem_big, 0, MR_BIG_RESERVE(8));    /* clear the memory */
	memset(mem_ecp, 0, MR_ECP_RESERVE(1));

    A=mirvar_mem(mip, mem_big, 0);       /* Initialise big numbers */
    B=mirvar_mem(mip, mem_big, 1);
    pa=mirvar_mem(mip, mem_big, 2);
    pb=mirvar_mem(mip, mem_big, 3);
    key=mirvar_mem(mip, mem_big, 4);
    a=mirvar_mem(mip, mem_big, 5);
    b=mirvar_mem(mip, mem_big, 6);
    p=mirvar_mem(mip, mem_big, 7);

    PB=epoint_init_mem(mip, mem_ecp, 0); /* initialise Elliptic Curve points */

    irand(mip, 3L);                      /* change parameter for different random numbers */

    promptr=0;
    init_big_from_rom(p,WORDS,rom,WORDS*5,&promptr);  /* Read in prime modulus p from ROM   */
    init_big_from_rom(B,WORDS,rom,WORDS*5,&promptr);  /* Read in curve parameter B from ROM */
                                                 /* don't need q or G(x,y) (we have precomputed table from it) */

    convert(mip,-3,A);                           /* set A=-3 */

/* Create precomputation instance from precomputed table in ROM */

    ebrick_init(&binst,prom,A,B,p,WINDOW,CURVE_BITS);

/* offline calculations */

    bigbits(mip,CURVE_BITS,a);  /* A's random number */
    mul_brick(mip,&binst,a,pa,pa);    /* a*G =(pa,ya) */

    bigbits(mip,CURVE_BITS,b);  /* B's random number */
    mul_brick(mip,&binst,b,pb,pb);    /* b*G =(pb,yb) */

/* swap X values of point */

/* online calculations */
    ecurve_init(mip,A,B,p,MR_PROJECTIVE);
    epoint_set(mip,pb,pb,0,PB); /* decompress PB */
    ecurve_mult(mip,a,PB,PB);
    epoint_get(mip,PB,key,key);

/* since internal base is HEX, can use otnum instead of cotnum - avoiding a base change */
#ifndef MR_NO_STANDARD_IO
printf("Alice's Key= ");
otnum(mip,key,stdout);
#endif

    epoint_set(mip,pa,pa,0,PB); /* decompress PA */
    ecurve_mult(mip,b,PB,PB);
    epoint_get(mip,PB,key,key);

#ifndef MR_NO_STANDARD_IO
printf("Bob's Key=   ");
otnum(mip,key,stdout);
#endif

/* clear the memory */

	memset(mem_big, 0, MR_BIG_RESERVE(8));
	memset(mem_ecp, 0, MR_ECP_RESERVE(1));

	return 0;
}