void do_mul_exp(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx) { int i,k; double tm; long num; BN_MONT_CTX m; memset(&m,0,sizeof(m)); num=BASENUM; for (i=0; i<NUM_SIZES; i++) { BN_rand(a,sizes[i],1,0); BN_rand(b,sizes[i],1,0); BN_rand(c,sizes[i],1,1); BN_mod(a,a,c,ctx); BN_mod(b,b,c,ctx); BN_MONT_CTX_set(&m,c,ctx); Time_F(START); for (k=0; k<num; k++) BN_mod_exp_mont(r,a,b,c,ctx,&m); tm=Time_F(STOP); printf("mul %4d ^ %4d %% %d -> %8.3fms %5.1f\n",sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num); num/=7; if (num <= 0) num=1; } }
void do_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) { int i, j, k; double tm; long num; for (i = 0; i < NUM_SIZES; i++) { num = BASENUM; if (i) num /= (i * 3); BN_rand(a, sizes[i], 1, 0); for (j = i; j < NUM_SIZES; j++) { BN_rand(b, sizes[j], 1, 0); Time_F(START); for (k = 0; k < num; k++) BN_mul(r, b, a, ctx); tm = Time_F(STOP); /*printf("mul %4d x %4d -> %8.3fms\n", sizes[i], sizes[j], tm * 1000.0 / num);*//* LEVANCIO S10 comment delete R.Miura 2016/02/03 */ } } for (i = 0; i < NUM_SIZES; i++) { num = BASENUM; if (i) num /= (i * 3); BN_rand(a, sizes[i], 1, 0); Time_F(START); for (k = 0; k < num; k++) BN_sqr(r, a, ctx); tm = Time_F(STOP); /*printf("sqr %4d x %4d -> %8.3fms\n", sizes[i], sizes[i], tm * 1000.0 / num);*//* LEVANCIO S10 comment delete R.Miura 2016/02/03 */ } for (i = 0; i < NUM_SIZES; i++) { num = BASENUM / 10; if (i) num /= (i * 3); BN_rand(a, sizes[i] - 1, 1, 0); for (j = i; j < NUM_SIZES; j++) { BN_rand(b, sizes[j], 1, 0); Time_F(START); for (k = 0; k < 100000; k++) BN_div(r, NULL, b, a, ctx); tm = Time_F(STOP); /*printf("div %4d / %4d -> %8.3fms\n", sizes[j], sizes[i] - 1, tm * 1000.0 / num);*//* LEVANCIO S10 comment delete R.Miura 2016/02/03 */ } } }
void do_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) { int i,j,k; double tm; long num; for (i=0; i<NUM_SIZES; i++) { num=BASENUM; if (i) num/=(i*3); BN_rand(a,sizes[i],1,0); for (j=i; j<NUM_SIZES; j++) { BN_rand(b,sizes[j],1,0); Time_F(START); for (k=0; k<num; k++) BN_mul(r,b,a,ctx); tm=Time_F(STOP); TINYCLR_SSL_FPRINTF("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num); } } for (i=0; i<NUM_SIZES; i++) { num=BASENUM; if (i) num/=(i*3); BN_rand(a,sizes[i],1,0); Time_F(START); for (k=0; k<num; k++) BN_sqr(r,a,ctx); tm=Time_F(STOP); TINYCLR_SSL_FPRINTF("sqr %4d x %4d -> %8.3fms\n",sizes[i],sizes[i],tm*1000.0/num); } for (i=0; i<NUM_SIZES; i++) { num=BASENUM/10; if (i) num/=(i*3); BN_rand(a,sizes[i]-1,1,0); for (j=i; j<NUM_SIZES; j++) { BN_rand(b,sizes[j],1,0); Time_F(START); for (k=0; k<100000; k++) BN_div(r, NULL, b, a,ctx); tm=Time_F(STOP); TINYCLR_SSL_FPRINTF("div %4d / %4d -> %8.3fms\n",sizes[j],sizes[i]-1,tm*1000.0/num); } } }
int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; static unsigned char key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, }; RC5_32_KEY sch; double a, b, c, d; #ifndef SIGALRM long ca, cb, cc; #endif #ifndef TIMES printf("To get the most accurate results, try to run this\n"); printf("program when this computer is idle.\n"); #endif #ifndef SIGALRM printf("First we calculate the approximate speed ...\n"); RC5_32_set_key(&sch, 16, key, 12); count = 10; do { long i; RC5_32_INT data[2]; count *= 2; Time_F(START); for (i = count; i; i--) RC5_32_encrypt(data, &sch); d = Time_F(STOP); } while (d < 3.0); ca = count / 512; cb = count; cc = count * 8 / BUFSIZE + 1; printf("Doing RC5_32_set_key %ld times\n", ca); # define COND(d) (count != (d)) # define COUNT(d) (d) #else # define COND(c) (run) # define COUNT(d) (count) signal(SIGALRM, sig_done); printf("Doing RC5_32_set_key for 10 seconds\n"); alarm(10); #endif Time_F(START); for (count = 0, run = 1; COND(ca); count += 4) { RC5_32_set_key(&sch, 16, key, 12); RC5_32_set_key(&sch, 16, key, 12); RC5_32_set_key(&sch, 16, key, 12); RC5_32_set_key(&sch, 16, key, 12); } d = Time_F(STOP); printf("%ld RC5_32_set_key's in %.2f seconds\n", count, d); a = ((double)COUNT(ca)) / d; #ifdef SIGALRM printf("Doing RC5_32_encrypt's for 10 seconds\n"); alarm(10); #else printf("Doing RC5_32_encrypt %ld times\n", cb); #endif Time_F(START); for (count = 0, run = 1; COND(cb); count += 4) { RC5_32_INT data[2]; RC5_32_encrypt(data, &sch); RC5_32_encrypt(data, &sch); RC5_32_encrypt(data, &sch); RC5_32_encrypt(data, &sch); } d = Time_F(STOP); printf("%ld RC5_32_encrypt's in %.2f second\n", count, d); b = ((double)COUNT(cb) * 8) / d; #ifdef SIGALRM printf("Doing RC5_32_cbc_encrypt on %ld byte blocks for 10 seconds\n", BUFSIZE); alarm(10); #else printf("Doing RC5_32_cbc_encrypt %ld times on %ld byte blocks\n", cc, BUFSIZE); #endif Time_F(START); for (count = 0, run = 1; COND(cc); count++) RC5_32_cbc_encrypt(buf, buf, BUFSIZE, &sch, &(key[0]), RC5_ENCRYPT); d = Time_F(STOP); printf("%ld RC5_32_cbc_encrypt's of %ld byte blocks in %.2f second\n", count, BUFSIZE, d); c = ((double)COUNT(cc) * BUFSIZE) / d; printf("RC5_32/12/16 set_key per sec = %12.2f (%9.3fuS)\n", a, 1.0e6 / a); printf("RC5_32/12/16 raw ecb bytes per sec = %12.2f (%9.3fuS)\n", b, 8.0e6 / b); printf("RC5_32/12/16 cbc bytes per sec = %12.2f (%9.3fuS)\n", c, 8.0e6 / c); exit(0); #if defined(LINT) || defined(OPENSSL_SYS_MSDOS) return (0); #endif }
int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; BF_KEY sch; double d,tm[16],max=0; int rank[16]; char *str[16]; int max_idx=0,i,num=0,j; #ifndef SIGALARM long ca,cb,cc,cd,ce; #endif for (i=0; i<12; i++) { tm[i]=0.0; rank[i]=0; } #ifndef TIMES fprintf(stderr,"To get the most accurate results, try to run this\n"); fprintf(stderr,"program when this computer is idle.\n"); #endif BF_set_key(&sch,16,key); #ifndef SIGALRM fprintf(stderr,"First we calculate the approximate speed ...\n"); count=10; do { long i; unsigned long data[2]; count*=2; Time_F(START); for (i=count; i; i--) BF_encrypt(data,&sch); d=Time_F(STOP); } while (d < 3.0); ca=count; cb=count*3; cc=count*3*8/BUFSIZE+1; cd=count*8/BUFSIZE+1; ce=count/20+1; #define COND(d) (count != (d)) #define COUNT(d) (d) #else #define COND(c) (run) #define COUNT(d) (count) signal(SIGALRM,sig_done); alarm(10); #endif time_it(BF_encrypt_normal, "BF_encrypt_normal ", 0); time_it(BF_encrypt_ptr, "BF_encrypt_ptr ", 1); time_it(BF_encrypt_ptr2, "BF_encrypt_ptr2 ", 2); num+=3; str[0]="<nothing>"; print_it("BF_encrypt_normal ",0); max=tm[0]; max_idx=0; str[1]="ptr "; print_it("BF_encrypt_ptr ",1); if (max < tm[1]) { max=tm[1]; max_idx=1; } str[2]="ptr2 "; print_it("BF_encrypt_ptr2 ",2); if (max < tm[2]) { max=tm[2]; max_idx=2; } printf("options BF ecb/s\n"); printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]); d=tm[max_idx]; tm[max_idx]= -2.0; max= -1.0; for (;;) { for (i=0; i<3; i++) { if (max < tm[i]) { max=tm[i]; j=i; } } if (max < 0.0) break; printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0); tm[j]= -2.0; max= -1.0; } switch (max_idx) { case 0: printf("-DBF_DEFAULT_OPTIONS\n"); break; case 1: printf("-DBF_PTR\n"); break; case 2: printf("-DBF_PTR2\n"); break; } exit(0); #if defined(LINT) || defined(OPENSSL_SYS_MSDOS) return(0); #endif }
int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; DES_key_schedule sch,sch2,sch3; double a,b,c,d,e; #ifndef SIGALRM long ca,cb,cc,cd,ce; #endif #ifndef TIMES printf("To get the most accurate results, try to run this\n"); printf("program when this computer is idle.\n"); #endif DES_set_key_unchecked(&key2,&sch2); DES_set_key_unchecked(&key3,&sch3); #ifndef SIGALRM printf("First we calculate the approximate speed ...\n"); DES_set_key_unchecked(&key,&sch); count=10; do { long i; DES_LONG data[2]; count*=2; Time_F(START); for (i=count; i; i--) DES_encrypt1(data,&sch,DES_ENCRYPT); d=Time_F(STOP); } while (d < 3.0); ca=count; cb=count*3; cc=count*3*8/BUFSIZE+1; cd=count*8/BUFSIZE+1; ce=count/20+1; printf("Doing set_key %ld times\n",ca); #define COND(d) (count != (d)) #define COUNT(d) (d) #else #define COND(c) (run) #define COUNT(d) (count) signal(SIGALRM,sig_done); printf("Doing set_key for 10 seconds\n"); alarm(10); #endif Time_F(START); for (count=0,run=1; COND(ca); count++) DES_set_key_unchecked(&key,&sch); d=Time_F(STOP); printf("%ld set_key's in %.2f seconds\n",count,d); a=((double)COUNT(ca))/d; #ifdef SIGALRM printf("Doing DES_encrypt's for 10 seconds\n"); alarm(10); #else printf("Doing DES_encrypt %ld times\n",cb); #endif Time_F(START); for (count=0,run=1; COND(cb); count++) { DES_LONG data[2]; DES_encrypt1(data,&sch,DES_ENCRYPT); } d=Time_F(STOP); printf("%ld DES_encrypt's in %.2f second\n",count,d); b=((double)COUNT(cb)*8)/d; #ifdef SIGALRM printf("Doing DES_cbc_encrypt on %ld byte blocks for 10 seconds\n", BUFSIZE); alarm(10); #else printf("Doing DES_cbc_encrypt %ld times on %ld byte blocks\n",cc, BUFSIZE); #endif Time_F(START); for (count=0,run=1; COND(cc); count++) DES_ncbc_encrypt(buf,buf,BUFSIZE,&sch, &key,DES_ENCRYPT); d=Time_F(STOP); printf("%ld DES_cbc_encrypt's of %ld byte blocks in %.2f second\n", count,BUFSIZE,d); c=((double)COUNT(cc)*BUFSIZE)/d; #ifdef SIGALRM printf("Doing DES_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n", BUFSIZE); alarm(10); #else printf("Doing DES_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd, BUFSIZE); #endif Time_F(START); for (count=0,run=1; COND(cd); count++) DES_ede3_cbc_encrypt(buf,buf,BUFSIZE, &sch, &sch2, &sch3, &key, DES_ENCRYPT); d=Time_F(STOP); printf("%ld DES_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n", count,BUFSIZE,d); d=((double)COUNT(cd)*BUFSIZE)/d; #ifdef SIGALRM printf("Doing crypt for 10 seconds\n"); alarm(10); #else printf("Doing crypt %ld times\n",ce); #endif Time_F(START); for (count=0,run=1; COND(ce); count++) crypt("testing1","ef"); e=Time_F(STOP); printf("%ld crypts in %.2f second\n",count,e); e=((double)COUNT(ce))/e; printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d); printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e); exit(0); #if defined(LINT) || defined(OPENSSL_SYS_MSDOS) return(0); #endif }
jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env, jclass thiz, jstring algorithm, jint testnumber) { static const unsigned char key16[16] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }; const EVP_CIPHER *evp_cipher = NULL; const char* alg = (*env)->GetStringUTFChars( env, algorithm , NULL ) ; evp_cipher = EVP_get_cipherbyname(alg); if (evp_cipher == NULL) evp_md = EVP_get_digestbyname(alg); if (evp_cipher == NULL && evp_md == NULL) { // BIO_printf(bio_err, "%s: %s is an unknown cipher or digest\n", prog, opt_arg()); //jniThrowException(env, "java/security/NoSuchAlgorithmException", "Algorithm not found"); return NULL; } const char* name; loopargs_t *loopargs = NULL; int loopargs_len = 1; int async_jobs=0; loopargs = malloc(loopargs_len * sizeof(loopargs_t)); memset(loopargs, 0, loopargs_len * sizeof(loopargs_t)); jdoubleArray ret = (*env)->NewDoubleArray(env, 3); if (testnum < 0 || testnum >= SIZE_NUM) return NULL; testnum = testnumber; for (int i = 0; i < loopargs_len; i++) { int misalign=0; loopargs[i].buf_malloc = malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1); loopargs[i].buf2_malloc = malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1); /* Align the start of buffers on a 64 byte boundary */ loopargs[i].buf = loopargs[i].buf_malloc + misalign; loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign; } int count; float d; if (evp_cipher) { name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)); /* * -O3 -fschedule-insns messes up an optimization here! * names[D_EVP] somehow becomes NULL */ for (int k = 0; k < loopargs_len; k++) { loopargs[k].ctx = EVP_CIPHER_CTX_new(); if (decrypt) EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv); else EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv); EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0); } Time_F(START); pthread_t timer_thread; if (pthread_create(&timer_thread, NULL, stop_run, NULL)) return NULL; count = run_benchmark(async_jobs, EVP_Update_loop, loopargs); d = Time_F(STOP); for (int k = 0; k < loopargs_len; k++) { EVP_CIPHER_CTX_free(loopargs[k].ctx); } } if (evp_md) { name = OBJ_nid2ln(EVP_MD_type(evp_md)); // print_message(names[D_EVP], save_count, lengths[testnum]); pthread_t timer_thread; if (pthread_create(&timer_thread, NULL, stop_run, NULL)) return NULL; Time_F(START); count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs); d = Time_F(STOP); } // Save results in hacky way double results[] = {(double) lengths[testnum], (double) count, d}; (*env)->SetDoubleArrayRegion(env, ret, 0, 3, results); // print_result(D_EVP, testnum, count, d); return ret; }
int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; DES_key_schedule sch,sch2,sch3; double d,tm[16],max=0; int rank[16]; char *str[16]; int max_idx=0,i,num=0,j; #ifndef SIGALARM long ca,cb,cc,cd,ce; #endif for (i=0; i<12; i++) { tm[i]=0.0; rank[i]=0; } #ifndef TIMES TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"To get the most accurate results, try to run this\n"); TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"program when this computer is idle.\n"); #endif DES_set_key_unchecked(&key,&sch); DES_set_key_unchecked(&key2,&sch2); DES_set_key_unchecked(&key3,&sch3); #ifndef SIGALRM TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"First we calculate the approximate speed ...\n"); DES_set_key_unchecked(&key,sch); count=10; do { long i; unsigned long data[2]; count*=2; Time_F(START); for (i=count; i; i--) DES_encrypt1(data,&(sch[0]),DES_ENCRYPT); d=Time_F(STOP); } while (d < 3.0); ca=count; cb=count*3; cc=count*3*8/BUFSIZE+1; cd=count*8/BUFSIZE+1; ce=count/20+1; #define COND(d) (count != (d)) #define COUNT(d) (d) #else #define COND(c) (run) #define COUNT(d) (count) signal(SIGALRM,sig_done); alarm(10); #endif #ifdef PART1 time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0); time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1); time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2); num+=3; #endif #ifdef PART2 time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3); time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4); time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5); num+=3; #endif #ifdef PART3 time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6); time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7); time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8); num+=3; #endif #ifdef PART4 time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9); time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10); time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11); num+=3; #endif #ifdef PART1 str[0]=" 4 c i"; print_it("des_encrypt_u4_cisc_idx ",0); max=tm[0]; max_idx=0; str[1]="16 c i"; print_it("des_encrypt_u16_cisc_idx ",1); if (max < tm[1]) { max=tm[1]; max_idx=1; } str[2]=" 4 r1 i"; print_it("des_encrypt_u4_risc1_idx ",2); if (max < tm[2]) { max=tm[2]; max_idx=2; } #endif #ifdef PART2 str[3]="16 r1 i"; print_it("des_encrypt_u16_risc1_idx",3); if (max < tm[3]) { max=tm[3]; max_idx=3; } str[4]=" 4 r2 i"; print_it("des_encrypt_u4_risc2_idx ",4); if (max < tm[4]) { max=tm[4]; max_idx=4; } str[5]="16 r2 i"; print_it("des_encrypt_u16_risc2_idx",5); if (max < tm[5]) { max=tm[5]; max_idx=5; } #endif #ifdef PART3 str[6]=" 4 c p"; print_it("des_encrypt_u4_cisc_ptr ",6); if (max < tm[6]) { max=tm[6]; max_idx=6; } str[7]="16 c p"; print_it("des_encrypt_u16_cisc_ptr ",7); if (max < tm[7]) { max=tm[7]; max_idx=7; } str[8]=" 4 r1 p"; print_it("des_encrypt_u4_risc1_ptr ",8); if (max < tm[8]) { max=tm[8]; max_idx=8; } #endif #ifdef PART4 str[9]="16 r1 p"; print_it("des_encrypt_u16_risc1_ptr",9); if (max < tm[9]) { max=tm[9]; max_idx=9; } str[10]=" 4 r2 p"; print_it("des_encrypt_u4_risc2_ptr ",10); if (max < tm[10]) { max=tm[10]; max_idx=10; } str[11]="16 r2 p"; print_it("des_encrypt_u16_risc2_ptr",11); if (max < tm[11]) { max=tm[11]; max_idx=11; } #endif TINYCLR_SSL_PRINTF("options des ecb/s\n"); TINYCLR_SSL_PRINTF("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]); d=tm[max_idx]; tm[max_idx]= -2.0; max= -1.0; for (;;) { for (i=0; i<12; i++) { if (max < tm[i]) { max=tm[i]; j=i; } } if (max < 0.0) break; TINYCLR_SSL_PRINTF("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0); tm[j]= -2.0; max= -1.0; } switch (max_idx) { case 0: TINYCLR_SSL_PRINTF("-DDES_DEFAULT_OPTIONS\n"); break; case 1: TINYCLR_SSL_PRINTF("-DDES_UNROLL\n"); break; case 2: TINYCLR_SSL_PRINTF("-DDES_RISC1\n"); break; case 3: TINYCLR_SSL_PRINTF("-DDES_UNROLL -DDES_RISC1\n"); break; case 4: TINYCLR_SSL_PRINTF("-DDES_RISC2\n"); break; case 5: TINYCLR_SSL_PRINTF("-DDES_UNROLL -DDES_RISC2\n"); break; case 6: TINYCLR_SSL_PRINTF("-DDES_PTR\n"); break; case 7: TINYCLR_SSL_PRINTF("-DDES_UNROLL -DDES_PTR\n"); break; case 8: TINYCLR_SSL_PRINTF("-DDES_RISC1 -DDES_PTR\n"); break; case 9: TINYCLR_SSL_PRINTF("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n"); break; case 10: TINYCLR_SSL_PRINTF("-DDES_RISC2 -DDES_PTR\n"); break; case 11: TINYCLR_SSL_PRINTF("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n"); break; } TINYCLR_SSL_EXIT(0); #if defined(LINT) || defined(OPENSSL_SYS_MSDOS) return(0); #endif }
void do_mul_exp(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx) { int i,k; double tm; long num; num=BASENUM; for (i=NUM_START; i<NUM_SIZES; i++) { #ifdef C_PRIME # ifdef TEST_SQRT if (!BN_set_word(a, 64)) goto err; if (!BN_set_word(b, P_MOD_64)) goto err; # define ADD a # define REM b # else # define ADD NULL # define REM NULL # endif if (!BN_generate_prime(c,sizes[i],0,ADD,REM,genprime_cb,NULL)) goto err; putc('\n', stderr); fflush(stderr); #endif for (k=0; k<num; k++) { if (k%50 == 0) /* Average over num/50 different choices of random numbers. */ { if (!BN_pseudo_rand(a,sizes[i],1,0)) goto err; if (!BN_pseudo_rand(b,sizes[i],1,0)) goto err; #ifndef C_PRIME if (!BN_pseudo_rand(c,sizes[i],1,1)) goto err; #endif #ifdef TEST_SQRT if (!BN_mod_sqr(a,a,c,ctx)) goto err; if (!BN_mod_sqr(b,b,c,ctx)) goto err; #else if (!BN_nnmod(a,a,c,ctx)) goto err; if (!BN_nnmod(b,b,c,ctx)) goto err; #endif if (k == 0) Time_F(START); } #if defined(TEST_EXP) if (!BN_mod_exp(r,a,b,c,ctx)) goto err; #elif defined(TEST_MUL) { int i = 0; for (i = 0; i < 50; i++) if (!BN_mod_mul(r,a,b,c,ctx)) goto err; } #elif defined(TEST_SQR) { int i = 0; for (i = 0; i < 50; i++) { if (!BN_mod_sqr(r,a,c,ctx)) goto err; if (!BN_mod_sqr(r,b,c,ctx)) goto err; } } #elif defined(TEST_GCD) if (!BN_gcd(r,a,b,ctx)) goto err; if (!BN_gcd(r,b,c,ctx)) goto err; if (!BN_gcd(r,c,a,ctx)) goto err; #elif defined(TEST_KRON) if (-2 == BN_kronecker(a,b,ctx)) goto err; if (-2 == BN_kronecker(b,c,ctx)) goto err; if (-2 == BN_kronecker(c,a,ctx)) goto err; #elif defined(TEST_INV) if (!BN_mod_inverse(r,a,c,ctx)) goto err; if (!BN_mod_inverse(r,b,c,ctx)) goto err; #else /* TEST_SQRT */ if (!BN_mod_sqrt(r,a,c,ctx)) goto err; if (!BN_mod_sqrt(r,b,c,ctx)) goto err; #endif } tm=Time_F(STOP); printf( #if defined(TEST_EXP) "modexp %4d ^ %4d %% %4d" #elif defined(TEST_MUL) "50*modmul %4d %4d %4d" #elif defined(TEST_SQR) "100*modsqr %4d %4d %4d" #elif defined(TEST_GCD) "3*gcd %4d %4d %4d" #elif defined(TEST_KRON) "3*kronecker %4d %4d %4d" #elif defined(TEST_INV) "2*inv %4d %4d mod %4d" #else /* TEST_SQRT */ "2*sqrt [prime == %d (mod 64)] %4d %4d mod %4d" #endif " -> %8.3fms %5.1f (%ld)\n", #ifdef TEST_SQRT P_MOD_64, #endif sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num, num); num/=7; if (num <= 0) num=1; } return; err: ERR_print_errors_fp(stderr); }