int main() { big a2,a6,bx,r; big res[4]; epoint *P,*Q; int i,romptr; miracl instance; /* sizeof(miracl)= 2000 bytes from the stack */ #ifndef MR_STATIC #ifdef MR_GENERIC_MT miracl *mr_mip=mirsys(WORDS*NPW,16); #else miracl *mr_mip=mirsys(WORDS*NPW,16); #endif char *mem=(char *)memalloc(_MIPP_ 8); char *mem1=(char *)ecp_memalloc(_MIPP_ 2); #else #ifdef MR_GENERIC_MT miracl *mr_mip=mirsys(&instance,MR_STATIC*NPW,16); /* size of bigs is fixed */ #else miracl *mr_mip=mirsys(&instance,MR_STATIC*NPW,16); #endif char mem[MR_BIG_RESERVE(8)]; /* reserve space on the stack for 8 bigs */ char mem1[MR_ECP_RESERVE(2)]; /* reserve space on stack for 2 curve points */ memset(mem,0,MR_BIG_RESERVE(8)); /* clear this memory */ memset(mem1,0,MR_ECP_RESERVE(2)); /* ~668 bytes in all */ #endif /* Initialise bigs */ a2=mirvar_mem(_MIPP_ mem,0); a6=mirvar_mem(_MIPP_ mem,1); bx=mirvar_mem(_MIPP_ mem,2); for (i=0;i<4;i++) res[i]=mirvar_mem(_MIPP_ mem,3+i); r=mirvar_mem(_MIPP_ mem,7); /* printf("ROM size= %d\n",sizeof(rom)+sizeof(prom)); */ #ifndef MR_NO_STANDARD_IO #ifdef MR_STATIC printf("n Bigs require n*%d+%d bytes\n",MR_SIZE,MR_SL); printf("n Points require n*%d+%d bytes\n",MR_ESIZE,MR_SL); printf("sizeof(miracl)= %d\n",sizeof(miracl)); #endif #endif /* Initialise Elliptic curve points */ P=epoint_init_mem(_MIPP_ mem1,0); Q=epoint_init_mem(_MIPP_ mem1,1); /* Initialise supersingular curve */ convert(_MIPP_ 1,a2); convert(_MIPP_ B,a6); /* The -M tells MIRACL that this is a supersingular curve */ if (!ecurve2_init(_MIPP_ -M,T,U,V,a2,a6,FALSE,MR_PROJECTIVE)) { #ifndef MR_NO_STANDARD_IO printf("Problem with the curve\n"); #endif return 0; } /* Get P and Q from ROM */ /* These should have been multiplied by the cofactor 487805 = 5*97561 */ /* 487805 is a cofactor of the group order 2^271+2^136+1 */ romptr=0; init_point_from_rom(P,WORDS,rom,ROMSZ,&romptr); init_point_from_rom(Q,WORDS,rom,ROMSZ,&romptr); #ifndef MR_NO_STANDARD_IO printf( "P= \n"); otnum(_MIPP_ P->X,stdout); otnum(_MIPP_ P->Y,stdout); printf( "Q= \n"); otnum(_MIPP_ Q->X,stdout); otnum(_MIPP_ Q->Y,stdout); #endif bigbits(_MIPP_ 160,r); /* Simple bilinearity test */ tate(_MIPP_ P,Q,res); /* this could break the 4k stack, 2060+668+2996 >4K */ /* so we cannot afford much precomputation in power4 */ power4(_MIPP_ res,r,res); /* res=res^{sr} */ #ifndef MR_NO_STANDARD_IO printf( "\ne(P,Q)^r= \n"); for (i=0;i<4;i++) { otnum(_MIPP_ res[i],stdout); zero(res[i]); } #endif ecurve2_mult(_MIPP_ r,Q,Q); /* Q=rQ */ epoint2_norm(_MIPP_ Q); tate(_MIPP_ P,Q,res); /* Now invert is taken out of Tate, and the stack should be OK */ #ifndef MR_NO_STANDARD_IO printf( "\ne(P,rQ)= \n"); for (i=0;i<4;i++) otnum(_MIPP_ res[i],stdout); #endif /* all done */ #ifndef MR_STATIC memkill(_MIPP_ mem,8); ecp_memkill(_MIPP_ mem1,2); #else memset(mem,0,MR_BIG_RESERVE(8)); /* clear this stack memory */ memset(mem1,0,MR_ECP_RESERVE(2)); #endif mirexit(_MIPPO_ ); /* clears workspace memory */ return 0; }
int main(void) { int i; element_t g, h; element_t w0, w1; element_t a, b; mpz_t prime, cofac; mpz_init(prime); mpz_init(order); mpz_init(cofac); mpz_set_ui(prime, 59); field_init_fp(Fq, prime); element_init(a, Fq); element_init(b, Fq); field_init_fi(Fq2, Fq); element_set1(a); element_set0(b); mpz_set_ui(order, 5); mpz_set_ui(cofac, 12); field_init_curve_ab(E, a, b, order, cofac); element_clear(a); element_clear(b); element_init(a, Fq2); element_init(b, Fq2); element_set1(a); element_set0(b); mpz_mul(cofac, cofac, cofac); field_init_curve_ab(E2, a, b, order, NULL); element_init(g, E2); element_init(h, E2); element_init(w0, Fq2); element_init(w1, Fq2); /* do { element_random(g); } while (element_is1(g)); for (i=1; i<5; i++) { element_mul(h, h, g); element_printf("%d: %B\n", i, h); element_printf("tangent = "); do_tangent(h); } */ element_set_str(g, "[[25,0],[30,0]", 0); element_set_str(h, "[[34,0],[0,30]", 0); weil(w0, g, h); element_printf("weil: %B\n", w0); element_set1(w1); for (i=1; i<6; i++) { element_mul(w1, w1, w0); element_printf("%d: %B\n", i, w1); } fasterweil(w0, g, h); element_printf("fasterweil: %B\n", w0); element_set1(w1); for (i=1; i<6; i++) { element_mul(w1, w1, w0); element_printf("%d: %B\n", i, w1); } fasterweil2(w0, g, h); element_printf("fasterweil2: %B\n", w0); tate(w0, g, h); element_printf("tate: %B\n", w0); element_set1(w1); for (i=1; i<6; i++) { element_mul(w1, w1, w0); element_printf("%d: %B\n", i, w1); } shipseystange(w0, g, h); element_printf("ss-tate: %B\n", w0); element_set1(w1); for (i=1; i<6; i++) { element_mul(w1, w1, w0); element_printf("%d: %B\n", i, w1); } return 0; }