📄 speed.c
字号:
#ifndef NO_MDC2 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1; else#endif#ifndef NO_MD4 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1; else#endif#ifndef NO_MD5 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1; else#endif#ifndef NO_MD5 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1; else#endif#ifndef NO_SHA if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1; else if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1; else#endif#ifndef NO_RIPEMD if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1; else if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1; else if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1; else#endif#ifndef NO_RC4 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1; else #endif#ifndef NO_DES if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1; else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1; else#endif#ifndef NO_RSA#ifdef RSAref if (strcmp(*argv,"rsaref") == 0) { RSA_set_default_method(RSA_PKCS1_RSAref()); j--; } else#endif#ifndef RSA_NULL if (strcmp(*argv,"openssl") == 0) { RSA_set_default_method(RSA_PKCS1_SSLeay()); j--; } else#endif#endif /* !NO_RSA */ if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2; else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2; else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2; else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2; else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2; else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2; else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2; else#ifndef NO_RC2 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1; else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1; else#endif#ifndef NO_RC5 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1; else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1; else#endif#ifndef NO_IDEA if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1; else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1; else#endif#ifndef NO_BF if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1; else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1; else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1; else#endif#ifndef NO_CAST if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1; else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1; else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1; else#endif#ifndef NO_DES if (strcmp(*argv,"des") == 0) { doit[D_CBC_DES]=1; doit[D_EDE3_DES]=1; } else#endif#ifndef NO_RSA if (strcmp(*argv,"rsa") == 0) { rsa_doit[R_RSA_512]=1; rsa_doit[R_RSA_1024]=1; rsa_doit[R_RSA_2048]=1; rsa_doit[R_RSA_4096]=1; } else#endif#ifndef NO_DSA if (strcmp(*argv,"dsa") == 0) { dsa_doit[R_DSA_512]=1; dsa_doit[R_DSA_1024]=1; } else#endif { BIO_printf(bio_err,"Error: bad option or value\n"); BIO_printf(bio_err,"\n"); BIO_printf(bio_err,"Available values:\n");#ifndef NO_MD2 BIO_printf(bio_err,"md2 ");#endif#ifndef NO_MDC2 BIO_printf(bio_err,"mdc2 ");#endif#ifndef NO_MD4 BIO_printf(bio_err,"md4 ");#endif#ifndef NO_MD5 BIO_printf(bio_err,"md5 ");#ifndef NO_HMAC BIO_printf(bio_err,"hmac ");#endif#endif#ifndef NO_SHA1 BIO_printf(bio_err,"sha1 ");#endif#ifndef NO_RIPEMD160 BIO_printf(bio_err,"rmd160");#endif#if !defined(NO_MD2) || !defined(NO_MDC2) || !defined(NO_MD4) || !defined(NO_MD5) || !defined(NO_SHA1) || !defined(NO_RIPEMD160) BIO_printf(bio_err,"\n");#endif#ifndef NO_IDEA BIO_printf(bio_err,"idea-cbc ");#endif#ifndef NO_RC2 BIO_printf(bio_err,"rc2-cbc ");#endif#ifndef NO_RC5 BIO_printf(bio_err,"rc5-cbc ");#endif#ifndef NO_BF BIO_printf(bio_err,"bf-cbc");#endif#if !defined(NO_IDEA) || !defined(NO_RC2) || !defined(NO_BF) || !defined(NO_RC5) BIO_printf(bio_err,"\n");#endif BIO_printf(bio_err,"des-cbc des-ede3 ");#ifndef NO_RC4 BIO_printf(bio_err,"rc4");#endif BIO_printf(bio_err,"\n");#ifndef NO_RSA BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");#endif#ifndef NO_DSA BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");#endif#ifndef NO_IDEA BIO_printf(bio_err,"idea ");#endif#ifndef NO_RC2 BIO_printf(bio_err,"rc2 ");#endif#ifndef NO_DES BIO_printf(bio_err,"des ");#endif#ifndef NO_RSA BIO_printf(bio_err,"rsa ");#endif#ifndef NO_BF BIO_printf(bio_err,"blowfish");#endif#if !defined(NO_IDEA) || !defined(NO_RC2) || !defined(NO_DES) || !defined(NO_RSA) || !defined(NO_BF) BIO_printf(bio_err,"\n");#endif#ifdef TIMES BIO_printf(bio_err,"\n"); BIO_printf(bio_err,"Available options:\n"); BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");#endif goto end; } argc--; argv++; j++; } if (j == 0) { for (i=0; i<ALGOR_NUM; i++) doit[i]=1; for (i=0; i<RSA_NUM; i++) rsa_doit[i]=1; for (i=0; i<DSA_NUM; i++) dsa_doit[i]=1; } for (i=0; i<ALGOR_NUM; i++) if (doit[i]) pr_header++; if (usertime == 0) BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n"); if (usertime <= 0) { BIO_printf(bio_err,"To get the most accurate results, try to run this\n"); BIO_printf(bio_err,"program when this computer is idle.\n"); }#ifndef NO_RSA for (i=0; i<RSA_NUM; i++) { unsigned char *p; p=rsa_data[i]; rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]); if (rsa_key[i] == NULL) { BIO_printf(bio_err,"internal error loading RSA key number %d\n",i); goto end; }#if 0 else { BIO_printf(bio_err,"Loaded RSA key, %d bit modulus and e= 0x",BN_num_bits(rsa_key[i]->n)); BN_print(bio_err,rsa_key[i]->e); BIO_printf(bio_err,"\n"); }#endif }#endif#ifndef NO_DSA dsa_key[0]=get_dsa512(); dsa_key[1]=get_dsa1024(); dsa_key[2]=get_dsa2048();#endif#ifndef NO_DES des_set_key_unchecked(&key,sch); des_set_key_unchecked(&key2,sch2); des_set_key_unchecked(&key3,sch3);#endif#ifndef NO_IDEA idea_set_encrypt_key(key16,&idea_ks);#endif#ifndef NO_RC4 RC4_set_key(&rc4_ks,16,key16);#endif#ifndef NO_RC2 RC2_set_key(&rc2_ks,16,key16,128);#endif#ifndef NO_RC5 RC5_32_set_key(&rc5_ks,16,key16,12);#endif#ifndef NO_BF BF_set_key(&bf_ks,16,key16);#endif#ifndef NO_CAST CAST_set_key(&cast_ks,16,key16);#endif#ifndef NO_RSA memset(rsa_c,0,sizeof(rsa_c));#endif#ifndef SIGALRM#ifndef NO_DES BIO_printf(bio_err,"First we calculate the approximate speed ...\n"); count=10; do { long i; count*=2; Time_F(START,usertime); for (i=count; i; i--) des_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock, &(sch[0]),DES_ENCRYPT); d=Time_F(STOP,usertime); } while (d <3); c[D_MD2][0]=count/10; c[D_MDC2][0]=count/10; c[D_MD4][0]=count; c[D_MD5][0]=count; c[D_HMAC][0]=count; c[D_SHA1][0]=count; c[D_RMD160][0]=count; c[D_RC4][0]=count*5; c[D_CBC_DES][0]=count; c[D_EDE3_DES][0]=count/3; c[D_CBC_IDEA][0]=count; c[D_CBC_RC2][0]=count; c[D_CBC_RC5][0]=count; c[D_CBC_BF][0]=count; c[D_CBC_CAST][0]=count; for (i=1; i<SIZE_NUM; i++) { c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i]; c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i]; c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i]; c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i]; c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i]; c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i]; c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i]; } for (i=1; i<SIZE_NUM; i++) { long l0,l1; l0=(long)lengths[i-1]; l1=(long)lengths[i]; c[D_RC4][i]=c[D_RC4][i-1]*l0/l1; c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1; c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1; c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1; c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1; c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1; c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1; c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1; }#ifndef NO_RSA rsa_c[R_RSA_512][0]=count/2000; rsa_c[R_RSA_512][1]=count/400; for (i=1; i<RSA_NUM; i++) { rsa_c[i][0]=rsa_c[i-1][0]/8; rsa_c[i][1]=rsa_c[i-1][1]/4; if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0)) rsa_doit[i]=0; else { if (rsa_c[i][0] == 0) { rsa_c[i][0]=1; rsa_c[i][1]=20; } } }#endif dsa_c[R_DSA_512][0]=count/1000; dsa_c[R_DSA_512][1]=count/1000/2; for (i=1; i<DSA_NUM; i++) { dsa_c[i][0]=dsa_c[i-1][0]/4; dsa_c[i][1]=dsa_c[i-1][1]/4; if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0)) dsa_doit[i]=0; else { if (dsa_c[i] == 0) { dsa_c[i][0]=1; dsa_c[i][1]=1; } } }#define COND(d) (count < (d))#define COUNT(d) (d)#else/* not worth fixing */# error "You cannot disable DES on systems without SIGALRM."#endif /* NO_DES */#else#define COND(c) (run)#define COUNT(d) (count) signal(SIGALRM,sig_done);#endif /* SIGALRM */#ifndef NO_MD2 if (doit[D_MD2]) { for (j=0; j<SIZE_NUM; j++) { print_message(names[D_MD2],c[D_MD2][j],lengths[j]); Time_F(START,usertime); for (count=0,run=1; COND(c[D_MD2][j]); count++) MD2(buf,(unsigned long)lengths[j],&(md2[0])); d=Time_F(STOP,usertime); BIO_printf(bio_err,"%ld %s's in %.2fs\n", count,names[D_MD2],d); results[D_MD2][j]=((double)count)/d*lengths[j]; } }#endif#ifndef NO_MDC2 if (doit[D_MDC2]) { for (j=0; j<SIZE_NUM; j++) { print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]); Time_F(START,usertime); for (count=0,run=1; COND(c[D_MDC2][j]); count++) MDC2(buf,(unsigned long)lengths[j],&(mdc2[0])); d=Time_F(STOP,usertime); BIO_printf(bio_err,"%ld %s's in %.2fs\n", count,names[D_MDC2],d); results[D_MDC2][j]=((double)count)/d*lengths[j]; } }#endif#ifndef NO_MD4 if (doit[D_MD4]) { for (j=0; j<SIZE_NUM; j++) { print_message(names[D_MD4],c[D_MD4][j],lengths[j]); Time_F(START,usertime); for (count=0,run=1; COND(c[D_MD4][j]); count++) MD4(&(buf[0]),(unsigned long)lengths[j],&(md4[0])); d=Time_F(STOP,usertime); BIO_printf(bio_err,"%ld %s's in %.2fs\n", count,names[D_MD4],d); results[D_MD4][j]=((double)count)/d*lengths[j]; } }#endif#ifndef NO_MD5 if (doit[D_MD5]) { for (j=0; j<SIZE_NUM; j++) { print_message(names[D_MD5],c[D_MD5][j],lengths[j]); Time_F(START,usertime); for (count=0,run=1; COND(c[D_MD5][j]); count++) MD5(&(buf[0]),(unsigned long)lengths[j],&(md5[0])); d=Time_F(STOP,usertime); BIO_printf(bio_err,"%ld %s's in %.2fs\n", count,names[D_MD5],d); results[D_MD5][j]=((double)count)/d*lengths[j]; } }#endif#if !defined(NO_MD5) && !defined(NO_HMAC) if (doit[D_HMAC]) { HMAC_CTX hctx; HMAC_Init(&hctx,(unsigned char *)"This is a key...", 16,EVP_md5()); for (j=0; j<SIZE_NUM; j++) { print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]); Time_F(START,usertime); for (count=0,run=1; COND(c[D_HMAC][j]); count++) { HMAC_Init(&hctx,NULL,0,NULL); HMAC_Update(&hctx,buf,lengths[j]); HMAC_Final(&hctx,&(hmac[0]),NULL); } d=Time_F(STOP,usertime); BIO_printf(bio_err,"%ld %s's in %.2fs\n", count,names[D_HMAC],d); results[D_HMAC][j]=((double)count)/d*lengths[j]; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -