int main(int argc, char* argv[]){ struct global_s global; int retcode; miracl *mr_mip; int retsock=0; mr_mip=mirsys(100, 0); global_init((char *)&global); //parse_cmd_lines(_MIPP_ argc, argv, (char *)&global); retcode=parse_cmd_lines(argc, argv, (char *)&global); if (retcode==-1){ printf("argv error\n"); return -1; }; //retcode=main_skypeclient_tcpconnect(_MIPP_ (char *)&global ); retcode=main_skypeclient_tcpconnect( (char *)&global ); if (retcode==0){ if(DEBUG_LEVEL>=1) printf("message delivered\n"); }; mirexit(); return 0; };
PFC::~PFC() { int i,j; delete B; delete x; delete mod; delete ord; delete cof; delete npoints; delete trace; for (i=0;i<4;i++) { delete WB[i]; for (j=0;j<4;j++) delete BB[i][j]; } for (i=0;i<2;i++) { delete W[i]; for (j=0;j<2;j++) delete SB[i][j]; } delete Beta; delete frob; mirexit(); }
int main() { big p,q,dp,dq,m,c,m1; int i,romptr; miracl instance; /* sizeof(miracl)= 2124 bytes from the stack */ #ifndef MR_STATIC miracl *mr_mip=mirsys(&instance,WORDS*8,16); char *mem=memalloc(_MIPP_ ,7); #else miracl *mr_mip=mirsys(&instance,MR_STATIC*8,16); /* size of bigs is fixed */ char mem[MR_BIG_RESERVE(7)]; /* reserve space on the stack for 7 bigs */ memset(mem,0,MR_BIG_RESERVE(7)); /* clear this memory */ #endif /* Initialise bigs */ p=mirvar_mem(_MIPP_ mem,0); q=mirvar_mem(_MIPP_ mem,1); dp=mirvar_mem(_MIPP_ mem,2); dq=mirvar_mem(_MIPP_ mem,3); m=mirvar_mem(_MIPP_ mem,4); c=mirvar_mem(_MIPP_ mem,5); m1=mirvar_mem(_MIPP_ mem,6); romptr=0; init_big_from_rom(p,WORDS,rom,256,&romptr); init_big_from_rom(q,WORDS,rom,256,&romptr); init_big_from_rom(dp,WORDS,rom,256,&romptr); init_big_from_rom(dq,WORDS,rom,256,&romptr); bigbits(_MIPP_ 512,c); /* count clocks, instructions and CPI from here.. */ //for (i=0;i<100000;i++) //{ powmod(_MIPP_ c,dp,p,m); powmod(_MIPP_ c,dq,q,m1); //} /* to here... */ #ifndef MR_NO_STANDARD_IO otnum(_MIPP_ m,stdout); otnum(_MIPP_ m1,stdout); #endif #ifndef MR_STATIC memkill(_MIPP_ mem,7); #else memset(mem,0,MR_BIG_RESERVE(6)); /* clear this stack memory */ #endif mirexit(_MIPPO_ ); /* clears workspace memory */ return 0; }
void DH1080_DeInit() { if(mip) { mirkill(b_1); mirkill(b_prime1080); mirexit(); } }
PFC::~PFC() { delete B; delete mod; delete ord; delete cof; delete npoints; delete trace; mirexit(); }
int main() { FILE *fp; big p,q,g,x,y; long seed; int bits; miracl *mip; /* get common data */ fp=fopen("common.dss","rt"); if (fp==NULL) { printf("file common.dss does not exist\n"); return 0; } fscanf(fp,"%d\n",&bits); mip=mirsys(bits/4,16); /* use Hex internally */ p=mirvar(0); q=mirvar(0); g=mirvar(0); x=mirvar(0); y=mirvar(0); innum(p,fp); innum(q,fp); innum(g,fp); fclose(fp); /* randomise */ printf("Enter 9 digit random number seed = "); scanf("%ld",&seed); getchar(); irand(seed); powmod(g,q,p,y); if (size(y)!=1) { printf("Problem - generator g is not of order q\n"); return 0; } /* generate public/private keys */ bigrand(q,x); powmod(g,x,p,y); printf("public key = "); otnum(y,stdout); fp=fopen("public.dss","wt"); otnum(y,fp); fclose(fp); fp=fopen("private.dss","wt"); otnum(x,fp); fclose(fp); mirexit(); return 0; }
BOOL BaseOT::Miracl_Cleanup() { delete m_Y; delete m_X; delete m_BA; delete m_BB; delete m_BP; mirexit(); return TRUE; }
BOOL MiraclCleanup(fparams* params) { delete params->eccparams.Y; delete params->eccparams.X; delete params->eccparams.BA; delete params->eccparams.BB; delete params->eccparams.BP; mirexit(); return TRUE; }
int main(int argc, char* argv[]){ struct global_s global; int retcode; miracl *mr_mip; int retsock=0; //char our_public_ip[0x100]; //mr_mip=mirsys(_MIPP_ 100, 0); mr_mip=mirsys(100, 0); global_init((char *)&global); //parse_cmd_lines(_MIPP_ argc, argv, (char *)&global); retcode=parse_cmd_lines(argc, argv, (char *)&global); if (retcode==-1){ printf("argv error\n"); return -1; }; ///////////// // new code /////////// // relay retcode=skyrel_main((char *)&global, &retsock); if (retcode==-1){ printf("Not found good relays\n"); return -1; }; printf("retsock main: 0x%08X\n",retsock); printf("Relay node ip: %s:%d\n",global.relayip,global.relayport); printf("Got connid: 0x%08X\n",global.connid); //strcpy(our_public_ip,"95.52.137.99"); // push retcode=skypush_main((char *)&global,global.user_snodeip,global.user_snodeport,global.our_public_ip); if (retcode==-1){ printf("Bad answer from user snode\n"); return -1; }; // recv retcode=skyrel_answer((char *)&global, &retsock); if (retcode==-1){ printf("Remote peer fail relay\n"); //return -1; }; //Sleep(1000); ///////////////// // end new code ///////////////// //retcode=main_skypeclient_tcpconnect(_MIPP_ (char *)&global ); retcode=main_skypeclient_tcpconnect( (char *)&global ); if (retcode==0){ if(DEBUG_LEVEL>=1) printf("message delivered\n"); }; mirexit(); return 0; };
void mcl_ecpbs_test(char *data) { /* timing the experiment */ struct timespec bank_start, bank_end, verify_start, verify_end; long bank_nanos = 0; long verify_nanos = 0; int i = 0; int result = 0; /* simulate client and bank interaction */ mcl_ecpbs_bank_state bstate; mcl_ecpbs_state cstate; mcl_ecpbs_init_bank(&bstate); mcl_ecpbs_init(&cstate); int date1 = time(NULL) / 86400; int date2 = date1 + 7; int date3 = date1 + 28; int infolen = 3 * sizeof(date1) + 6; /* 3 ints, 2 commas, null byte */ char info[infolen]; snprintf(info, infolen, "%d,%d,%d", date1, date2, date3); /* do a bunch of signatures and verifies */ char *pos = data; for (i = 0; i < NUM_LOOPS_PER_RUN; ++i) { /* bank computes a,b */ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &bank_start); mcl_ecpbs_sign_start_bank(&bstate, info); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &bank_end); bank_nanos = get_timer_nanos(&bank_start, &bank_end); /* bank 'sends' a,b,info to client */ epoint_copy(bstate.a, cstate.a); epoint_copy(bstate.b, cstate.b); /* client computes e */ mcl_ecpbs_sign_start(&cstate, info, pos); /* client 'sends' e to bank */ copy(cstate.e, bstate.e); /* bank produces r,c,s,d for client */ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &bank_start); mcl_ecpbs_sign_finish_bank(&bstate); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &bank_end); bank_nanos += get_timer_nanos(&bank_start, &bank_end); /* bank 'sends' r,c,s,d to client */ copy(bstate.r, cstate.r); copy(bstate.c, cstate.c); copy(bstate.s, cstate.s); copy(bstate.d, cstate.d); /* client finishes signature */ if (!mcl_ecpbs_sign_finish(&cstate)) { printf("Signature consistency check failed\n"); } /* now verify */ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &verify_start); result = mcl_ecpbs_verify(&cstate.signature, info, pos, &cstate.parameters, &cstate.pk, &cstate.workspace); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &verify_end); verify_nanos = get_timer_nanos(&verify_start, &verify_end); if (result != 0) { printf("Signature incorrect\n"); mcl_ecpbs_print_bank(&bstate, stdout); mcl_ecpbs_print(&cstate, stdout); } pos += CELL_NETWORK_SIZE + 1; mcl_ecpbs_reset_bank(&bstate); mcl_ecpbs_reset(&cstate); printf("mcl_ecpbs Bank effort: 1 signature %ld nanoseconds (%d/%d)\n", bank_nanos, i+1, NUM_LOOPS_PER_RUN); printf("mcl_ecpbs Signature verification: 1 verify %ld nanoseconds (%d/%d)\n", verify_nanos, i+1, NUM_LOOPS_PER_RUN); } /* free state and miracl */ mcl_ecpbs_free_bank(&bstate); mcl_ecpbs_free(&cstate); mirexit(); }
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() { FILE *fp; char ifname[13],ofname[13]; big p,q,g,x,r,s,k,hash; long seed; int bits; miracl *mip; /* get public data */ fp=fopen("common.dss","r"); if (fp==NULL) { printf("file common.dss does not exist\n"); return 0; } fscanf(fp,"%d\n",&bits); mip=mirsys(3+bits/MIRACL,0); p=mirvar(0); q=mirvar(0); g=mirvar(0); x=mirvar(0); r=mirvar(0); s=mirvar(0); k=mirvar(0); hash=mirvar(0); mip->IOBASE=16; cinnum(p,fp); cinnum(q,fp); cinnum(g,fp); mip->IOBASE=10; fclose(fp); /* randomise */ printf("Enter 9 digit random number seed = "); scanf("%ld",&seed); getchar(); irand(seed); /* calculate r - this can be done offline, and hence amortized to almost nothing */ bigrand(q,k); powmod(g,k,p,r); /* see brick.c for method to speed this up */ divide(r,q,q); /* get private key of signer */ fp=fopen("private.dss","r"); if (fp==NULL) { printf("file private.dss does not exist\n"); return 0; } cinnum(x,fp); fclose(fp); /* calculate message digest */ printf("file to be signed = "); gets(ifname); strcpy(ofname,ifname); strip(ofname); strcat(ofname,".dss"); if ((fp=fopen(ifname,"rb"))==NULL) { printf("Unable to open file %s\n",ifname); return 0; } hashing(fp,hash); fclose(fp); /* calculate s */ xgcd(k,q,k,k,k); mad(x,r,hash,q,q,s); mad(s,k,k,q,q,s); fp=fopen(ofname,"w"); cotnum(r,fp); cotnum(s,fp); fclose(fp); mirexit(); return 0; }
int crypto_dh(unsigned char *s,const unsigned char* pk,const unsigned char *sk) { int i,promptr; ecn2 P; big A,B,p,a[2]; zzn2 x,y,psi[2]; 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*16,16); /* size of bigs is fixed */ char mem_big[MR_BIG_RESERVE(17)]; /* we need 17 bigs... */ memset(mem_big, 0, MR_BIG_RESERVE(17)); /* clear the memory */ A=mirvar_mem(mip, mem_big, 0); /* Initialise big numbers */ B=mirvar_mem(mip, mem_big, 1); x.a=mirvar_mem(mip, mem_big, 2); x.b=mirvar_mem(mip, mem_big, 3); #ifndef COMPRESSED y.a=mirvar_mem(mip, mem_big, 4); y.b=mirvar_mem(mip, mem_big, 5); #endif a[0]=mirvar_mem(mip, mem_big, 6); a[1]=mirvar_mem(mip, mem_big, 7); p=mirvar_mem(mip, mem_big, 8); P.x.a=mirvar_mem(mip, mem_big, 9); P.x.b=mirvar_mem(mip, mem_big, 10); P.y.a=mirvar_mem(mip, mem_big, 11); P.y.b=mirvar_mem(mip, mem_big, 12); P.z.a=mirvar_mem(mip, mem_big, 13); P.z.b=mirvar_mem(mip, mem_big, 14); P.marker=MR_EPOINT_INFINITY; psi[0].a=mirvar_mem(mip, mem_big, 15); psi[0].b=mirvar_mem(mip, mem_big, 16); promptr=0; init_big_from_rom(p,WORDS,rom,16,&promptr); /* Read in prime modulus p from ROM */ init_big_from_rom(B,WORDS,rom,16,&promptr); /* Read in curve parameter B from ROM */ init_big_from_rom(psi[0].a,WORDS,rom,16,&promptr); init_big_from_rom(psi[0].b,WORDS,rom,16,&promptr); init_big_from_rom(x.a,WORDS,rom,16,&promptr); init_big_from_rom(x.b,WORDS,rom,16,&promptr); #ifndef COMPRESSED init_big_from_rom(y.a,WORDS,rom,16,&promptr); init_big_from_rom(y.b,WORDS,rom,16,&promptr); #endif convert(mip,1,A); /* Fix A=1 */ /* offline calculations */ ecurve_init(mip,A,B,p,MR_PROJECTIVE); mip->TWIST=TRUE; /* Alice calculates secret key */ bytes_to_big(mip,16,pk,x.a); bytes_to_big(mip,16,&pk[16],x.b); bytes_to_big(mip,16,sk,a[0]); bytes_to_big(mip,16,&sk[16],a[1]); #ifndef COMPRESSED bytes_to_big(mip,16,&pk[32],y.a); bytes_to_big(mip,16,&pk[48],y.b); if (!ecn2_set(mip,&x,&y,&P)) { memset(mem_big, 0, MR_BIG_RESERVE(17)); mirexit(mip); return -1; } #else if (!ecn2_setx(mip,&x,&P)) { memset(mem_big, 0, MR_BIG_RESERVE(17)); mirexit(mip); return -1; } #endif ecn2_mul2_gls(mip,a,&P,psi,&P); ecn2_getx(&P,&x); #ifdef COMPRESSED zzn2_sqr(mip,&x,&x); /* I tossed y, so I might have wrong sign.. */ #endif big_to_bytes(mip,16,x.a,s,TRUE); big_to_bytes(mip,16,x.b,&s[16],TRUE); memset(mem_big, 0, MR_BIG_RESERVE(17)); mirexit(mip); return 0; }
int crypto_dh_keypair(unsigned char* pk,unsigned char *sk) { int i,promptr; big A,B,p,a[2]; zzn2 x,y,psi[2]; miracl instance; /* create miracl workspace on the stack */ ebrick binst; /* Specify base 16 here so that HEX can be read in directly without a base-change */ miracl *mip=mirsys(&instance,WORDS*16,16); /* size of bigs is fixed */ char mem_big[MR_BIG_RESERVE(11)]; /* we need 10 bigs... */ memset(mem_big, 0, MR_BIG_RESERVE(11)); /* clear the memory */ A=mirvar_mem(mip, mem_big, 0); /* Initialise big numbers */ B=mirvar_mem(mip, mem_big, 1); x.a=mirvar_mem(mip, mem_big, 2); x.b=mirvar_mem(mip, mem_big, 3); y.a=mirvar_mem(mip, mem_big, 4); y.b=mirvar_mem(mip, mem_big, 5); a[0]=mirvar_mem(mip, mem_big, 6); a[1]=mirvar_mem(mip, mem_big, 7); p=mirvar_mem(mip, mem_big, 8); psi[0].a=mirvar_mem(mip, mem_big, 9); psi[0].b=mirvar_mem(mip, mem_big, 10); promptr=0; init_big_from_rom(p,WORDS,rom,16,&promptr); /* Read in prime modulus p from ROM */ init_big_from_rom(B,WORDS,rom,16,&promptr); /* Read in curve parameter B from ROM */ init_big_from_rom(psi[0].a,WORDS,rom,16,&promptr); init_big_from_rom(psi[0].b,WORDS,rom,16,&promptr); convert(mip,1,A); /* Fix A=1 */ ecn2_brick_init(&binst,prom,A,B,p,6,128); /* Alices key gen calculation */ #ifdef HAVE_MAIN for (i=0;i<32;i++) sk[i]=rand(); #else randombytes(sk,32); #endif sk[15]&=0x3f; sk[31]&=0x3f; bytes_to_big(mip,16,sk,a[0]); bytes_to_big(mip,16,&sk[16],a[1]); ecn2_mul_brick_gls(mip,&binst,a,psi,&x,&y); big_to_bytes(mip,16,x.a,pk,TRUE); big_to_bytes(mip,16,x.b,&pk[16],TRUE); #ifndef COMPRESSED big_to_bytes(mip,16,y.a,&pk[32],TRUE); big_to_bytes(mip,16,y.b,&pk[48],TRUE); #endif memset(mem_big, 0, MR_BIG_RESERVE(11)); mirexit(mip); return 0; }
JNIEXPORT void JNICALL Java_edu_biu_scapi_primitives_dlog_miracl_MiraclAdapterDlogEC_deleteMip (JNIEnv *env, jobject obj, jlong mip){ mirexit((miracl*)mip); }