speed.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. /* apps/speed.c */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. /* most of this code has been pilfered from my libdes speed.c program */
  59. #undef SECONDS
  60. #define SECONDS 3
  61. #define RSA_SECONDS 10
  62. #define DSA_SECONDS 10
  63. /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
  64. /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
  65. #undef PROG
  66. #define PROG speed_main
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <signal.h>
  70. #include <string.h>
  71. #include <math.h>
  72. #include "apps.h"
  73. #ifdef OPENSSL_NO_STDIO
  74. #define APPS_WIN16
  75. #endif
  76. #include <openssl/crypto.h>
  77. #include <openssl/rand.h>
  78. #include <openssl/err.h>
  79. #include <openssl/engine.h>
  80. #include <openssl/evp.h>
  81. #include <openssl/objects.h>
  82. #if defined(__FreeBSD__)
  83. # define USE_TOD
  84. #elif !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
  85. # define TIMES
  86. #endif
  87. #if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) /* FIXME */
  88. # define TIMEB
  89. #endif
  90. #ifndef _IRIX
  91. # include <time.h>
  92. #endif
  93. #ifdef TIMES
  94. # include <sys/types.h>
  95. # include <sys/times.h>
  96. #endif
  97. #ifdef USE_TOD
  98. # include <sys/time.h>
  99. # include <sys/resource.h>
  100. #endif
  101. /* Depending on the VMS version, the tms structure is perhaps defined.
  102. The __TMS macro will show if it was. If it wasn't defined, we should
  103. undefine TIMES, since that tells the rest of the program how things
  104. should be handled. -- Richard Levitte */
  105. #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
  106. #undef TIMES
  107. #endif
  108. #ifdef TIMEB
  109. #include <sys/timeb.h>
  110. #endif
  111. #if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD)
  112. #error "It seems neither struct tms nor struct timeb is supported in this platform!"
  113. #endif
  114. #if defined(sun) || defined(__ultrix)
  115. #define _POSIX_SOURCE
  116. #include <limits.h>
  117. #include <sys/param.h>
  118. #endif
  119. #ifndef OPENSSL_NO_DES
  120. #include <openssl/des.h>
  121. #endif
  122. #ifndef OPENSSL_NO_MD2
  123. #include <openssl/md2.h>
  124. #endif
  125. #ifndef OPENSSL_NO_MDC2
  126. #include <openssl/mdc2.h>
  127. #endif
  128. #ifndef OPENSSL_NO_MD4
  129. #include <openssl/md4.h>
  130. #endif
  131. #ifndef OPENSSL_NO_MD5
  132. #include <openssl/md5.h>
  133. #endif
  134. #ifndef OPENSSL_NO_HMAC
  135. #include <openssl/hmac.h>
  136. #endif
  137. #include <openssl/evp.h>
  138. #ifndef OPENSSL_NO_SHA
  139. #include <openssl/sha.h>
  140. #endif
  141. #ifndef OPENSSL_NO_RIPEMD
  142. #include <openssl/ripemd.h>
  143. #endif
  144. #ifndef OPENSSL_NO_RC4
  145. #include <openssl/rc4.h>
  146. #endif
  147. #ifndef OPENSSL_NO_RC5
  148. #include <openssl/rc5.h>
  149. #endif
  150. #ifndef OPENSSL_NO_RC2
  151. #include <openssl/rc2.h>
  152. #endif
  153. #ifndef OPENSSL_NO_IDEA
  154. #include <openssl/idea.h>
  155. #endif
  156. #ifndef OPENSSL_NO_BF
  157. #include <openssl/blowfish.h>
  158. #endif
  159. #ifndef OPENSSL_NO_CAST
  160. #include <openssl/cast.h>
  161. #endif
  162. #ifndef OPENSSL_NO_RSA
  163. #include <openssl/rsa.h>
  164. #include "./testrsa.h"
  165. #endif
  166. #include <openssl/x509.h>
  167. #ifndef OPENSSL_NO_DSA
  168. #include "./testdsa.h"
  169. #endif
  170. /* The following if from times(3) man page. It may need to be changed */
  171. #ifndef HZ
  172. # ifndef CLK_TCK
  173. # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
  174. # define HZ 100.0
  175. # else /* _BSD_CLK_TCK_ */
  176. # define HZ ((double)_BSD_CLK_TCK_)
  177. # endif
  178. # else /* CLK_TCK */
  179. # define HZ ((double)CLK_TCK)
  180. # endif
  181. #endif
  182. #undef BUFSIZE
  183. #define BUFSIZE ((long)1024*8+1)
  184. int run=0;
  185. static double Time_F(int s, int usertime);
  186. static void print_message(const char *s,long num,int length);
  187. static void pkey_print_message(char *str,char *str2,long num,int bits,int sec);
  188. #ifdef SIGALRM
  189. #if defined(__STDC__) || defined(sgi) || defined(_AIX)
  190. #define SIGRETTYPE void
  191. #else
  192. #define SIGRETTYPE int
  193. #endif
  194. static SIGRETTYPE sig_done(int sig);
  195. static SIGRETTYPE sig_done(int sig)
  196. {
  197. signal(SIGALRM,sig_done);
  198. run=0;
  199. #ifdef LINT
  200. sig=sig;
  201. #endif
  202. }
  203. #endif
  204. #define START 0
  205. #define STOP 1
  206. static double Time_F(int s, int usertime)
  207. {
  208. double ret;
  209. #ifdef USE_TOD
  210. if(usertime)
  211. {
  212. static struct rusage tstart,tend;
  213. if (s == START)
  214. {
  215. getrusage(RUSAGE_SELF,&tstart);
  216. return(0);
  217. }
  218. else
  219. {
  220. long i;
  221. getrusage(RUSAGE_SELF,&tend);
  222. i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
  223. ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
  224. +((double)i)/1000000.0;
  225. return((ret < 0.001)?0.001:ret);
  226. }
  227. }
  228. else
  229. {
  230. static struct timeval tstart,tend;
  231. long i;
  232. if (s == START)
  233. {
  234. gettimeofday(&tstart,NULL);
  235. return(0);
  236. }
  237. else
  238. {
  239. gettimeofday(&tend,NULL);
  240. i=(long)tend.tv_usec-(long)tstart.tv_usec;
  241. ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
  242. return((ret < 0.001)?0.001:ret);
  243. }
  244. }
  245. #else /* ndef USE_TOD */
  246. # ifdef TIMES
  247. if (usertime)
  248. {
  249. static struct tms tstart,tend;
  250. if (s == START)
  251. {
  252. times(&tstart);
  253. return(0);
  254. }
  255. else
  256. {
  257. times(&tend);
  258. ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
  259. return((ret < 1e-3)?1e-3:ret);
  260. }
  261. }
  262. # endif /* times() */
  263. # if defined(TIMES) && defined(TIMEB)
  264. else
  265. # endif
  266. # ifdef TIMEB
  267. {
  268. static struct timeb tstart,tend;
  269. long i;
  270. if (s == START)
  271. {
  272. ftime(&tstart);
  273. return(0);
  274. }
  275. else
  276. {
  277. ftime(&tend);
  278. i=(long)tend.millitm-(long)tstart.millitm;
  279. ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
  280. return((ret < 0.001)?0.001:ret);
  281. }
  282. }
  283. # endif
  284. #endif
  285. }
  286. int MAIN(int, char **);
  287. int MAIN(int argc, char **argv)
  288. {
  289. ENGINE *e;
  290. unsigned char *buf=NULL,*buf2=NULL;
  291. int mret=1;
  292. #define ALGOR_NUM 16
  293. #define SIZE_NUM 5
  294. #define RSA_NUM 4
  295. #define DSA_NUM 3
  296. long count,rsa_count,save_count=0;
  297. int i,j,k;
  298. #ifndef OPENSSL_NO_RSA
  299. unsigned rsa_num;
  300. #endif
  301. #ifndef OPENSSL_NO_MD2
  302. unsigned char md2[MD2_DIGEST_LENGTH];
  303. #endif
  304. #ifndef OPENSSL_NO_MDC2
  305. unsigned char mdc2[MDC2_DIGEST_LENGTH];
  306. #endif
  307. #ifndef OPENSSL_NO_MD4
  308. unsigned char md4[MD4_DIGEST_LENGTH];
  309. #endif
  310. #ifndef OPENSSL_NO_MD5
  311. unsigned char md5[MD5_DIGEST_LENGTH];
  312. unsigned char hmac[MD5_DIGEST_LENGTH];
  313. #endif
  314. #ifndef OPENSSL_NO_SHA
  315. unsigned char sha[SHA_DIGEST_LENGTH];
  316. #endif
  317. #ifndef OPENSSL_NO_RIPEMD
  318. unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
  319. #endif
  320. #ifndef OPENSSL_NO_RC4
  321. RC4_KEY rc4_ks;
  322. #endif
  323. #ifndef OPENSSL_NO_RC5
  324. RC5_32_KEY rc5_ks;
  325. #endif
  326. #ifndef OPENSSL_NO_RC2
  327. RC2_KEY rc2_ks;
  328. #endif
  329. #ifndef OPENSSL_NO_IDEA
  330. IDEA_KEY_SCHEDULE idea_ks;
  331. #endif
  332. #ifndef OPENSSL_NO_BF
  333. BF_KEY bf_ks;
  334. #endif
  335. #ifndef OPENSSL_NO_CAST
  336. CAST_KEY cast_ks;
  337. #endif
  338. static unsigned char key16[16]=
  339. {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
  340. 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
  341. unsigned char iv[8];
  342. #ifndef OPENSSL_NO_DES
  343. des_cblock *buf_as_des_cblock = NULL;
  344. static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
  345. static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
  346. static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
  347. des_key_schedule sch,sch2,sch3;
  348. #endif
  349. #define D_MD2 0
  350. #define D_MDC2 1
  351. #define D_MD4 2
  352. #define D_MD5 3
  353. #define D_HMAC 4
  354. #define D_SHA1 5
  355. #define D_RMD160 6
  356. #define D_RC4 7
  357. #define D_CBC_DES 8
  358. #define D_EDE3_DES 9
  359. #define D_CBC_IDEA 10
  360. #define D_CBC_RC2 11
  361. #define D_CBC_RC5 12
  362. #define D_CBC_BF 13
  363. #define D_CBC_CAST 14
  364. #define D_EVP 15
  365. double d,results[ALGOR_NUM][SIZE_NUM];
  366. static int lengths[SIZE_NUM]={8,64,256,1024,8*1024};
  367. long c[ALGOR_NUM][SIZE_NUM];
  368. static const char *names[ALGOR_NUM]={
  369. "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
  370. "des cbc","des ede3","idea cbc",
  371. "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc"};
  372. #define R_DSA_512 0
  373. #define R_DSA_1024 1
  374. #define R_DSA_2048 2
  375. #define R_RSA_512 0
  376. #define R_RSA_1024 1
  377. #define R_RSA_2048 2
  378. #define R_RSA_4096 3
  379. #ifndef OPENSSL_NO_RSA
  380. RSA *rsa_key[RSA_NUM];
  381. long rsa_c[RSA_NUM][2];
  382. double rsa_results[RSA_NUM][2];
  383. static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
  384. static unsigned char *rsa_data[RSA_NUM]=
  385. {test512,test1024,test2048,test4096};
  386. static int rsa_data_length[RSA_NUM]={
  387. sizeof(test512),sizeof(test1024),
  388. sizeof(test2048),sizeof(test4096)};
  389. #endif
  390. #ifndef OPENSSL_NO_DSA
  391. DSA *dsa_key[DSA_NUM];
  392. long dsa_c[DSA_NUM][2];
  393. double dsa_results[DSA_NUM][2];
  394. static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
  395. #endif
  396. int rsa_doit[RSA_NUM];
  397. int dsa_doit[DSA_NUM];
  398. int doit[ALGOR_NUM];
  399. int pr_header=0;
  400. int usertime=1;
  401. const EVP_CIPHER *evp=NULL;
  402. #ifndef TIMES
  403. usertime=-1;
  404. #endif
  405. apps_startup();
  406. memset(results, 0, sizeof(results));
  407. #ifndef OPENSSL_NO_DSA
  408. memset(dsa_key,0,sizeof(dsa_key));
  409. #endif
  410. if (bio_err == NULL)
  411. if ((bio_err=BIO_new(BIO_s_file())) != NULL)
  412. BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
  413. #ifndef OPENSSL_NO_RSA
  414. memset(rsa_key,0,sizeof(rsa_key));
  415. for (i=0; i<RSA_NUM; i++)
  416. rsa_key[i]=NULL;
  417. #endif
  418. if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
  419. {
  420. BIO_printf(bio_err,"out of memory\n");
  421. goto end;
  422. }
  423. #ifndef OPENSSL_NO_DES
  424. buf_as_des_cblock = (des_cblock *)buf;
  425. #endif
  426. if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
  427. {
  428. BIO_printf(bio_err,"out of memory\n");
  429. goto end;
  430. }
  431. memset(c,0,sizeof(c));
  432. memset(iv,0,sizeof(iv));
  433. for (i=0; i<ALGOR_NUM; i++)
  434. doit[i]=0;
  435. for (i=0; i<RSA_NUM; i++)
  436. rsa_doit[i]=0;
  437. for (i=0; i<DSA_NUM; i++)
  438. dsa_doit[i]=0;
  439. j=0;
  440. argc--;
  441. argv++;
  442. while (argc)
  443. {
  444. if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
  445. usertime = 0;
  446. else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
  447. {
  448. argc--;
  449. argv++;
  450. if(argc == 0)
  451. {
  452. BIO_printf(bio_err,"no EVP given\n");
  453. goto end;
  454. }
  455. evp=EVP_get_cipherbyname(*argv);
  456. if(!evp)
  457. {
  458. BIO_printf(bio_err,"%s is an unknown cipher\n",*argv);
  459. goto end;
  460. }
  461. doit[D_EVP]=1;
  462. }
  463. else
  464. if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
  465. {
  466. argc--;
  467. argv++;
  468. if(argc == 0)
  469. {
  470. BIO_printf(bio_err,"no engine given\n");
  471. goto end;
  472. }
  473. if((e = ENGINE_by_id(*argv)) == NULL)
  474. {
  475. BIO_printf(bio_err,"invalid engine \"%s\"\n",
  476. *argv);
  477. goto end;
  478. }
  479. if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
  480. {
  481. BIO_printf(bio_err,"can't use that engine\n");
  482. goto end;
  483. }
  484. BIO_printf(bio_err,"engine \"%s\" set.\n", *argv);
  485. /* Free our "structural" reference. */
  486. ENGINE_free(e);
  487. /* It will be increased again further down. We just
  488. don't want speed to confuse an engine with an
  489. algorithm, especially when none is given (which
  490. means all of them should be run) */
  491. j--;
  492. }
  493. else
  494. #ifndef OPENSSL_NO_MD2
  495. if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
  496. else
  497. #endif
  498. #ifndef OPENSSL_NO_MDC2
  499. if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
  500. else
  501. #endif
  502. #ifndef OPENSSL_NO_MD4
  503. if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
  504. else
  505. #endif
  506. #ifndef OPENSSL_NO_MD5
  507. if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
  508. else
  509. #endif
  510. #ifndef OPENSSL_NO_MD5
  511. if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
  512. else
  513. #endif
  514. #ifndef OPENSSL_NO_SHA
  515. if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
  516. else
  517. if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1;
  518. else
  519. #endif
  520. #ifndef OPENSSL_NO_RIPEMD
  521. if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
  522. else
  523. if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
  524. else
  525. if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
  526. else
  527. #endif
  528. #ifndef OPENSSL_NO_RC4
  529. if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
  530. else
  531. #endif
  532. #ifndef OPENSSL_NO_DES
  533. if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
  534. else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
  535. else
  536. #endif
  537. #ifndef OPENSSL_NO_RSA
  538. #if 0 /* was: #ifdef RSAref */
  539. if (strcmp(*argv,"rsaref") == 0)
  540. {
  541. RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
  542. j--;
  543. }
  544. else
  545. #endif
  546. #ifndef RSA_NULL
  547. if (strcmp(*argv,"openssl") == 0)
  548. {
  549. RSA_set_default_openssl_method(RSA_PKCS1_SSLeay());
  550. j--;
  551. }
  552. else
  553. #endif
  554. #endif /* !OPENSSL_NO_RSA */
  555. if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
  556. else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
  557. else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
  558. else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
  559. else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
  560. else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
  561. else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
  562. else
  563. #ifndef OPENSSL_NO_RC2
  564. if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
  565. else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
  566. else
  567. #endif
  568. #ifndef OPENSSL_NO_RC5
  569. if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
  570. else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
  571. else
  572. #endif
  573. #ifndef OPENSSL_NO_IDEA
  574. if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
  575. else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
  576. else
  577. #endif
  578. #ifndef OPENSSL_NO_BF
  579. if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
  580. else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
  581. else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
  582. else
  583. #endif
  584. #ifndef OPENSSL_NO_CAST
  585. if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
  586. else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
  587. else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
  588. else
  589. #endif
  590. #ifndef OPENSSL_NO_DES
  591. if (strcmp(*argv,"des") == 0)
  592. {
  593. doit[D_CBC_DES]=1;
  594. doit[D_EDE3_DES]=1;
  595. }
  596. else
  597. #endif
  598. #ifndef OPENSSL_NO_RSA
  599. if (strcmp(*argv,"rsa") == 0)
  600. {
  601. rsa_doit[R_RSA_512]=1;
  602. rsa_doit[R_RSA_1024]=1;
  603. rsa_doit[R_RSA_2048]=1;
  604. rsa_doit[R_RSA_4096]=1;
  605. }
  606. else
  607. #endif
  608. #ifndef OPENSSL_NO_DSA
  609. if (strcmp(*argv,"dsa") == 0)
  610. {
  611. dsa_doit[R_DSA_512]=1;
  612. dsa_doit[R_DSA_1024]=1;
  613. }
  614. else
  615. #endif
  616. {
  617. BIO_printf(bio_err,"Error: bad option or value\n");
  618. BIO_printf(bio_err,"\n");
  619. BIO_printf(bio_err,"Available values:\n");
  620. #ifndef OPENSSL_NO_MD2
  621. BIO_printf(bio_err,"md2 ");
  622. #endif
  623. #ifndef OPENSSL_NO_MDC2
  624. BIO_printf(bio_err,"mdc2 ");
  625. #endif
  626. #ifndef OPENSSL_NO_MD4
  627. BIO_printf(bio_err,"md4 ");
  628. #endif
  629. #ifndef OPENSSL_NO_MD5
  630. BIO_printf(bio_err,"md5 ");
  631. #ifndef OPENSSL_NO_HMAC
  632. BIO_printf(bio_err,"hmac ");
  633. #endif
  634. #endif
  635. #ifndef OPENSSL_NO_SHA1
  636. BIO_printf(bio_err,"sha1 ");
  637. #endif
  638. #ifndef OPENSSL_NO_RIPEMD160
  639. BIO_printf(bio_err,"rmd160");
  640. #endif
  641. #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
  642. !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
  643. !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
  644. BIO_printf(bio_err,"\n");
  645. #endif
  646. #ifndef OPENSSL_NO_IDEA
  647. BIO_printf(bio_err,"idea-cbc ");
  648. #endif
  649. #ifndef OPENSSL_NO_RC2
  650. BIO_printf(bio_err,"rc2-cbc ");
  651. #endif
  652. #ifndef OPENSSL_NO_RC5
  653. BIO_printf(bio_err,"rc5-cbc ");
  654. #endif
  655. #ifndef OPENSSL_NO_BF
  656. BIO_printf(bio_err,"bf-cbc");
  657. #endif
  658. #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
  659. !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
  660. BIO_printf(bio_err,"\n");
  661. #endif
  662. BIO_printf(bio_err,"des-cbc des-ede3 ");
  663. #ifndef OPENSSL_NO_RC4
  664. BIO_printf(bio_err,"rc4");
  665. #endif
  666. BIO_printf(bio_err,"\n");
  667. #ifndef OPENSSL_NO_RSA
  668. BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
  669. #endif
  670. #ifndef OPENSSL_NO_DSA
  671. BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
  672. #endif
  673. #ifndef OPENSSL_NO_IDEA
  674. BIO_printf(bio_err,"idea ");
  675. #endif
  676. #ifndef OPENSSL_NO_RC2
  677. BIO_printf(bio_err,"rc2 ");
  678. #endif
  679. #ifndef OPENSSL_NO_DES
  680. BIO_printf(bio_err,"des ");
  681. #endif
  682. #ifndef OPENSSL_NO_RSA
  683. BIO_printf(bio_err,"rsa ");
  684. #endif
  685. #ifndef OPENSSL_NO_BF
  686. BIO_printf(bio_err,"blowfish");
  687. #endif
  688. #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
  689. !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \
  690. !defined(OPENSSL_NO_BF)
  691. BIO_printf(bio_err,"\n");
  692. #endif
  693. BIO_printf(bio_err,"\n");
  694. BIO_printf(bio_err,"Available options:\n");
  695. #ifdef TIMES
  696. BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
  697. #endif
  698. BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
  699. goto end;
  700. }
  701. argc--;
  702. argv++;
  703. j++;
  704. }
  705. if (j == 0)
  706. {
  707. for (i=0; i<ALGOR_NUM; i++)
  708. {
  709. if (i != D_EVP)
  710. doit[i]=1;
  711. }
  712. for (i=0; i<RSA_NUM; i++)
  713. rsa_doit[i]=1;
  714. for (i=0; i<DSA_NUM; i++)
  715. dsa_doit[i]=1;
  716. }
  717. for (i=0; i<ALGOR_NUM; i++)
  718. if (doit[i]) pr_header++;
  719. if (usertime == 0)
  720. BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
  721. if (usertime <= 0)
  722. {
  723. BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
  724. BIO_printf(bio_err,"program when this computer is idle.\n");
  725. }
  726. #ifndef OPENSSL_NO_RSA
  727. for (i=0; i<RSA_NUM; i++)
  728. {
  729. const unsigned char *p;
  730. p=rsa_data[i];
  731. rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
  732. if (rsa_key[i] == NULL)
  733. {
  734. BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
  735. goto end;
  736. }
  737. #if 0
  738. else
  739. {
  740. BIO_printf(bio_err,"Loaded RSA key, %d bit modulus and e= 0x",BN_num_bits(rsa_key[i]->n));
  741. BN_print(bio_err,rsa_key[i]->e);
  742. BIO_printf(bio_err,"\n");
  743. }
  744. #endif
  745. }
  746. #endif
  747. #ifndef OPENSSL_NO_DSA
  748. dsa_key[0]=get_dsa512();
  749. dsa_key[1]=get_dsa1024();
  750. dsa_key[2]=get_dsa2048();
  751. #endif
  752. #ifndef OPENSSL_NO_DES
  753. des_set_key_unchecked(&key,sch);
  754. des_set_key_unchecked(&key2,sch2);
  755. des_set_key_unchecked(&key3,sch3);
  756. #endif
  757. #ifndef OPENSSL_NO_IDEA
  758. idea_set_encrypt_key(key16,&idea_ks);
  759. #endif
  760. #ifndef OPENSSL_NO_RC4
  761. RC4_set_key(&rc4_ks,16,key16);
  762. #endif
  763. #ifndef OPENSSL_NO_RC2
  764. RC2_set_key(&rc2_ks,16,key16,128);
  765. #endif
  766. #ifndef OPENSSL_NO_RC5
  767. RC5_32_set_key(&rc5_ks,16,key16,12);
  768. #endif
  769. #ifndef OPENSSL_NO_BF
  770. BF_set_key(&bf_ks,16,key16);
  771. #endif
  772. #ifndef OPENSSL_NO_CAST
  773. CAST_set_key(&cast_ks,16,key16);
  774. #endif
  775. #ifndef OPENSSL_NO_RSA
  776. memset(rsa_c,0,sizeof(rsa_c));
  777. #endif
  778. #ifndef SIGALRM
  779. #ifndef OPENSSL_NO_DES
  780. BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
  781. count=10;
  782. do {
  783. long i;
  784. count*=2;
  785. Time_F(START,usertime);
  786. for (i=count; i; i--)
  787. des_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
  788. &(sch[0]),DES_ENCRYPT);
  789. d=Time_F(STOP,usertime);
  790. } while (d <3);
  791. save_count=count;
  792. c[D_MD2][0]=count/10;
  793. c[D_MDC2][0]=count/10;
  794. c[D_MD4][0]=count;
  795. c[D_MD5][0]=count;
  796. c[D_HMAC][0]=count;
  797. c[D_SHA1][0]=count;
  798. c[D_RMD160][0]=count;
  799. c[D_RC4][0]=count*5;
  800. c[D_CBC_DES][0]=count;
  801. c[D_EDE3_DES][0]=count/3;
  802. c[D_CBC_IDEA][0]=count;
  803. c[D_CBC_RC2][0]=count;
  804. c[D_CBC_RC5][0]=count;
  805. c[D_CBC_BF][0]=count;
  806. c[D_CBC_CAST][0]=count;
  807. for (i=1; i<SIZE_NUM; i++)
  808. {
  809. c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
  810. c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
  811. c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
  812. c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
  813. c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
  814. c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
  815. c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
  816. }
  817. for (i=1; i<SIZE_NUM; i++)
  818. {
  819. long l0,l1;
  820. l0=(long)lengths[i-1];
  821. l1=(long)lengths[i];
  822. c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
  823. c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
  824. c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
  825. c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
  826. c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
  827. c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
  828. c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
  829. c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
  830. }
  831. #ifndef OPENSSL_NO_RSA
  832. rsa_c[R_RSA_512][0]=count/2000;
  833. rsa_c[R_RSA_512][1]=count/400;
  834. for (i=1; i<RSA_NUM; i++)
  835. {
  836. rsa_c[i][0]=rsa_c[i-1][0]/8;
  837. rsa_c[i][1]=rsa_c[i-1][1]/4;
  838. if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
  839. rsa_doit[i]=0;
  840. else
  841. {
  842. if (rsa_c[i][0] == 0)
  843. {
  844. rsa_c[i][0]=1;
  845. rsa_c[i][1]=20;
  846. }
  847. }
  848. }
  849. #endif
  850. dsa_c[R_DSA_512][0]=count/1000;
  851. dsa_c[R_DSA_512][1]=count/1000/2;
  852. for (i=1; i<DSA_NUM; i++)
  853. {
  854. dsa_c[i][0]=dsa_c[i-1][0]/4;
  855. dsa_c[i][1]=dsa_c[i-1][1]/4;
  856. if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
  857. dsa_doit[i]=0;
  858. else
  859. {
  860. if (dsa_c[i] == 0)
  861. {
  862. dsa_c[i][0]=1;
  863. dsa_c[i][1]=1;
  864. }
  865. }
  866. }
  867. #define COND(d) (count < (d))
  868. #define COUNT(d) (d)
  869. #else
  870. /* not worth fixing */
  871. # error "You cannot disable DES on systems without SIGALRM."
  872. #endif /* OPENSSL_NO_DES */
  873. #else
  874. #define COND(c) (run)
  875. #define COUNT(d) (count)
  876. signal(SIGALRM,sig_done);
  877. #endif /* SIGALRM */
  878. #ifndef OPENSSL_NO_MD2
  879. if (doit[D_MD2])
  880. {
  881. for (j=0; j<SIZE_NUM; j++)
  882. {
  883. print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
  884. Time_F(START,usertime);
  885. for (count=0,run=1; COND(c[D_MD2][j]); count++)
  886. MD2(buf,(unsigned long)lengths[j],&(md2[0]));
  887. d=Time_F(STOP,usertime);
  888. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  889. count,names[D_MD2],d);
  890. results[D_MD2][j]=((double)count)/d*lengths[j];
  891. }
  892. }
  893. #endif
  894. #ifndef OPENSSL_NO_MDC2
  895. if (doit[D_MDC2])
  896. {
  897. for (j=0; j<SIZE_NUM; j++)
  898. {
  899. print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
  900. Time_F(START,usertime);
  901. for (count=0,run=1; COND(c[D_MDC2][j]); count++)
  902. MDC2(buf,(unsigned long)lengths[j],&(mdc2[0]));
  903. d=Time_F(STOP,usertime);
  904. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  905. count,names[D_MDC2],d);
  906. results[D_MDC2][j]=((double)count)/d*lengths[j];
  907. }
  908. }
  909. #endif
  910. #ifndef OPENSSL_NO_MD4
  911. if (doit[D_MD4])
  912. {
  913. for (j=0; j<SIZE_NUM; j++)
  914. {
  915. print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
  916. Time_F(START,usertime);
  917. for (count=0,run=1; COND(c[D_MD4][j]); count++)
  918. MD4(&(buf[0]),(unsigned long)lengths[j],&(md4[0]));
  919. d=Time_F(STOP,usertime);
  920. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  921. count,names[D_MD4],d);
  922. results[D_MD4][j]=((double)count)/d*lengths[j];
  923. }
  924. }
  925. #endif
  926. #ifndef OPENSSL_NO_MD5
  927. if (doit[D_MD5])
  928. {
  929. for (j=0; j<SIZE_NUM; j++)
  930. {
  931. print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
  932. Time_F(START,usertime);
  933. for (count=0,run=1; COND(c[D_MD5][j]); count++)
  934. MD5(&(buf[0]),(unsigned long)lengths[j],&(md5[0]));
  935. d=Time_F(STOP,usertime);
  936. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  937. count,names[D_MD5],d);
  938. results[D_MD5][j]=((double)count)/d*lengths[j];
  939. }
  940. }
  941. #endif
  942. #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
  943. if (doit[D_HMAC])
  944. {
  945. HMAC_CTX hctx;
  946. HMAC_Init(&hctx,(unsigned char *)"This is a key...",
  947. 16,EVP_md5());
  948. for (j=0; j<SIZE_NUM; j++)
  949. {
  950. print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
  951. Time_F(START,usertime);
  952. for (count=0,run=1; COND(c[D_HMAC][j]); count++)
  953. {
  954. HMAC_Init(&hctx,NULL,0,NULL);
  955. HMAC_Update(&hctx,buf,lengths[j]);
  956. HMAC_Final(&hctx,&(hmac[0]),NULL);
  957. }
  958. d=Time_F(STOP,usertime);
  959. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  960. count,names[D_HMAC],d);
  961. results[D_HMAC][j]=((double)count)/d*lengths[j];
  962. }
  963. }
  964. #endif
  965. #ifndef OPENSSL_NO_SHA
  966. if (doit[D_SHA1])
  967. {
  968. for (j=0; j<SIZE_NUM; j++)
  969. {
  970. print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
  971. Time_F(START,usertime);
  972. for (count=0,run=1; COND(c[D_SHA1][j]); count++)
  973. SHA1(buf,(unsigned long)lengths[j],&(sha[0]));
  974. d=Time_F(STOP,usertime);
  975. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  976. count,names[D_SHA1],d);
  977. results[D_SHA1][j]=((double)count)/d*lengths[j];
  978. }
  979. }
  980. #endif
  981. #ifndef OPENSSL_NO_RIPEMD
  982. if (doit[D_RMD160])
  983. {
  984. for (j=0; j<SIZE_NUM; j++)
  985. {
  986. print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
  987. Time_F(START,usertime);
  988. for (count=0,run=1; COND(c[D_RMD160][j]); count++)
  989. RIPEMD160(buf,(unsigned long)lengths[j],&(rmd160[0]));
  990. d=Time_F(STOP,usertime);
  991. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  992. count,names[D_RMD160],d);
  993. results[D_RMD160][j]=((double)count)/d*lengths[j];
  994. }
  995. }
  996. #endif
  997. #ifndef OPENSSL_NO_RC4
  998. if (doit[D_RC4])
  999. {
  1000. for (j=0; j<SIZE_NUM; j++)
  1001. {
  1002. print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
  1003. Time_F(START,usertime);
  1004. for (count=0,run=1; COND(c[D_RC4][j]); count++)
  1005. RC4(&rc4_ks,(unsigned int)lengths[j],
  1006. buf,buf);
  1007. d=Time_F(STOP,usertime);
  1008. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1009. count,names[D_RC4],d);
  1010. results[D_RC4][j]=((double)count)/d*lengths[j];
  1011. }
  1012. }
  1013. #endif
  1014. #ifndef OPENSSL_NO_DES
  1015. if (doit[D_CBC_DES])
  1016. {
  1017. for (j=0; j<SIZE_NUM; j++)
  1018. {
  1019. print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
  1020. Time_F(START,usertime);
  1021. for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
  1022. des_ncbc_encrypt(buf,buf,lengths[j],sch,
  1023. &iv,DES_ENCRYPT);
  1024. d=Time_F(STOP,usertime);
  1025. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1026. count,names[D_CBC_DES],d);
  1027. results[D_CBC_DES][j]=((double)count)/d*lengths[j];
  1028. }
  1029. }
  1030. if (doit[D_EDE3_DES])
  1031. {
  1032. for (j=0; j<SIZE_NUM; j++)
  1033. {
  1034. print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
  1035. Time_F(START,usertime);
  1036. for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
  1037. des_ede3_cbc_encrypt(buf,buf,lengths[j],
  1038. sch,sch2,sch3,
  1039. &iv,DES_ENCRYPT);
  1040. d=Time_F(STOP,usertime);
  1041. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1042. count,names[D_EDE3_DES],d);
  1043. results[D_EDE3_DES][j]=((double)count)/d*lengths[j];
  1044. }
  1045. }
  1046. #endif
  1047. #ifndef OPENSSL_NO_IDEA
  1048. if (doit[D_CBC_IDEA])
  1049. {
  1050. for (j=0; j<SIZE_NUM; j++)
  1051. {
  1052. print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
  1053. Time_F(START,usertime);
  1054. for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
  1055. idea_cbc_encrypt(buf,buf,
  1056. (unsigned long)lengths[j],&idea_ks,
  1057. iv,IDEA_ENCRYPT);
  1058. d=Time_F(STOP,usertime);
  1059. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1060. count,names[D_CBC_IDEA],d);
  1061. results[D_CBC_IDEA][j]=((double)count)/d*lengths[j];
  1062. }
  1063. }
  1064. #endif
  1065. #ifndef OPENSSL_NO_RC2
  1066. if (doit[D_CBC_RC2])
  1067. {
  1068. for (j=0; j<SIZE_NUM; j++)
  1069. {
  1070. print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
  1071. Time_F(START,usertime);
  1072. for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
  1073. RC2_cbc_encrypt(buf,buf,
  1074. (unsigned long)lengths[j],&rc2_ks,
  1075. iv,RC2_ENCRYPT);
  1076. d=Time_F(STOP,usertime);
  1077. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1078. count,names[D_CBC_RC2],d);
  1079. results[D_CBC_RC2][j]=((double)count)/d*lengths[j];
  1080. }
  1081. }
  1082. #endif
  1083. #ifndef OPENSSL_NO_RC5
  1084. if (doit[D_CBC_RC5])
  1085. {
  1086. for (j=0; j<SIZE_NUM; j++)
  1087. {
  1088. print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
  1089. Time_F(START,usertime);
  1090. for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
  1091. RC5_32_cbc_encrypt(buf,buf,
  1092. (unsigned long)lengths[j],&rc5_ks,
  1093. iv,RC5_ENCRYPT);
  1094. d=Time_F(STOP,usertime);
  1095. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1096. count,names[D_CBC_RC5],d);
  1097. results[D_CBC_RC5][j]=((double)count)/d*lengths[j];
  1098. }
  1099. }
  1100. #endif
  1101. #ifndef OPENSSL_NO_BF
  1102. if (doit[D_CBC_BF])
  1103. {
  1104. for (j=0; j<SIZE_NUM; j++)
  1105. {
  1106. print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
  1107. Time_F(START,usertime);
  1108. for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
  1109. BF_cbc_encrypt(buf,buf,
  1110. (unsigned long)lengths[j],&bf_ks,
  1111. iv,BF_ENCRYPT);
  1112. d=Time_F(STOP,usertime);
  1113. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1114. count,names[D_CBC_BF],d);
  1115. results[D_CBC_BF][j]=((double)count)/d*lengths[j];
  1116. }
  1117. }
  1118. #endif
  1119. #ifndef OPENSSL_NO_CAST
  1120. if (doit[D_CBC_CAST])
  1121. {
  1122. for (j=0; j<SIZE_NUM; j++)
  1123. {
  1124. print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
  1125. Time_F(START,usertime);
  1126. for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
  1127. CAST_cbc_encrypt(buf,buf,
  1128. (unsigned long)lengths[j],&cast_ks,
  1129. iv,CAST_ENCRYPT);
  1130. d=Time_F(STOP,usertime);
  1131. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1132. count,names[D_CBC_CAST],d);
  1133. results[D_CBC_CAST][j]=((double)count)/d*lengths[j];
  1134. }
  1135. }
  1136. #endif
  1137. if (doit[D_EVP])
  1138. {
  1139. for (j=0; j<SIZE_NUM; j++)
  1140. {
  1141. EVP_CIPHER_CTX ctx;
  1142. int outl;
  1143. names[D_EVP]=OBJ_nid2ln(evp->nid);
  1144. print_message(names[D_EVP],save_count,
  1145. lengths[j]);
  1146. EVP_EncryptInit(&ctx,evp,key16,iv);
  1147. Time_F(START,usertime);
  1148. for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
  1149. EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
  1150. EVP_EncryptFinal(&ctx,buf,&outl);
  1151. d=Time_F(STOP,usertime);
  1152. BIO_printf(bio_err,"%ld %s's in %.2fs\n",
  1153. count,names[D_EVP],d);
  1154. results[D_EVP][j]=((double)count)/d*lengths[j];
  1155. }
  1156. }
  1157. RAND_pseudo_bytes(buf,36);
  1158. #ifndef OPENSSL_NO_RSA
  1159. for (j=0; j<RSA_NUM; j++)
  1160. {
  1161. int ret;
  1162. if (!rsa_doit[j]) continue;
  1163. ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
  1164. if (ret == 0)
  1165. {
  1166. BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
  1167. ERR_print_errors(bio_err);
  1168. rsa_count=1;
  1169. }
  1170. else
  1171. {
  1172. pkey_print_message("private","rsa",
  1173. rsa_c[j][0],rsa_bits[j],
  1174. RSA_SECONDS);
  1175. /* RSA_blinding_on(rsa_key[j],NULL); */
  1176. Time_F(START,usertime);
  1177. for (count=0,run=1; COND(rsa_c[j][0]); count++)
  1178. {
  1179. ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
  1180. &rsa_num, rsa_key[j]);
  1181. if (ret == 0)
  1182. {
  1183. BIO_printf(bio_err,
  1184. "RSA sign failure\n");
  1185. ERR_print_errors(bio_err);
  1186. count=1;
  1187. break;
  1188. }
  1189. }
  1190. d=Time_F(STOP,usertime);
  1191. BIO_printf(bio_err,
  1192. "%ld %d bit private RSA's in %.2fs\n",
  1193. count,rsa_bits[j],d);
  1194. rsa_results[j][0]=d/(double)count;
  1195. rsa_count=count;
  1196. }
  1197. #if 1
  1198. ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
  1199. if (ret <= 0)
  1200. {
  1201. BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
  1202. ERR_print_errors(bio_err);
  1203. dsa_doit[j] = 0;
  1204. }
  1205. else
  1206. {
  1207. pkey_print_message("public","rsa",
  1208. rsa_c[j][1],rsa_bits[j],
  1209. RSA_SECONDS);
  1210. Time_F(START,usertime);
  1211. for (count=0,run=1; COND(rsa_c[j][1]); count++)
  1212. {
  1213. ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
  1214. rsa_num, rsa_key[j]);
  1215. if (ret == 0)
  1216. {
  1217. BIO_printf(bio_err,
  1218. "RSA verify failure\n");
  1219. ERR_print_errors(bio_err);
  1220. count=1;
  1221. break;
  1222. }
  1223. }
  1224. d=Time_F(STOP,usertime);
  1225. BIO_printf(bio_err,
  1226. "%ld %d bit public RSA's in %.2fs\n",
  1227. count,rsa_bits[j],d);
  1228. rsa_results[j][1]=d/(double)count;
  1229. }
  1230. #endif
  1231. if (rsa_count <= 1)
  1232. {
  1233. /* if longer than 10s, don't do any more */
  1234. for (j++; j<RSA_NUM; j++)
  1235. rsa_doit[j]=0;
  1236. }
  1237. }
  1238. #endif
  1239. RAND_pseudo_bytes(buf,20);
  1240. #ifndef OPENSSL_NO_DSA
  1241. if (RAND_status() != 1)
  1242. {
  1243. RAND_seed(rnd_seed, sizeof rnd_seed);
  1244. rnd_fake = 1;
  1245. }
  1246. for (j=0; j<DSA_NUM; j++)
  1247. {
  1248. unsigned int kk;
  1249. int ret;
  1250. if (!dsa_doit[j]) continue;
  1251. DSA_generate_key(dsa_key[j]);
  1252. /* DSA_sign_setup(dsa_key[j],NULL); */
  1253. ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
  1254. &kk,dsa_key[j]);
  1255. if (ret == 0)
  1256. {
  1257. BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
  1258. ERR_print_errors(bio_err);
  1259. rsa_count=1;
  1260. }
  1261. else
  1262. {
  1263. pkey_print_message("sign","dsa",
  1264. dsa_c[j][0],dsa_bits[j],
  1265. DSA_SECONDS);
  1266. Time_F(START,usertime);
  1267. for (count=0,run=1; COND(dsa_c[j][0]); count++)
  1268. {
  1269. ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
  1270. &kk,dsa_key[j]);
  1271. if (ret == 0)
  1272. {
  1273. BIO_printf(bio_err,
  1274. "DSA sign failure\n");
  1275. ERR_print_errors(bio_err);
  1276. count=1;
  1277. break;
  1278. }
  1279. }
  1280. d=Time_F(STOP,usertime);
  1281. BIO_printf(bio_err,"%ld %d bit DSA signs in %.2fs\n",
  1282. count,dsa_bits[j],d);
  1283. dsa_results[j][0]=d/(double)count;
  1284. rsa_count=count;
  1285. }
  1286. ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
  1287. kk,dsa_key[j]);
  1288. if (ret <= 0)
  1289. {
  1290. BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
  1291. ERR_print_errors(bio_err);
  1292. dsa_doit[j] = 0;
  1293. }
  1294. else
  1295. {
  1296. pkey_print_message("verify","dsa",
  1297. dsa_c[j][1],dsa_bits[j],
  1298. DSA_SECONDS);
  1299. Time_F(START,usertime);
  1300. for (count=0,run=1; COND(dsa_c[j][1]); count++)
  1301. {
  1302. ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
  1303. kk,dsa_key[j]);
  1304. if (ret <= 0)
  1305. {
  1306. BIO_printf(bio_err,
  1307. "DSA verify failure\n");
  1308. ERR_print_errors(bio_err);
  1309. count=1;
  1310. break;
  1311. }
  1312. }
  1313. d=Time_F(STOP,usertime);
  1314. BIO_printf(bio_err,"%ld %d bit DSA verify in %.2fs\n",
  1315. count,dsa_bits[j],d);
  1316. dsa_results[j][1]=d/(double)count;
  1317. }
  1318. if (rsa_count <= 1)
  1319. {
  1320. /* if longer than 10s, don't do any more */
  1321. for (j++; j<DSA_NUM; j++)
  1322. dsa_doit[j]=0;
  1323. }
  1324. }
  1325. if (rnd_fake) RAND_cleanup();
  1326. #endif
  1327. fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
  1328. fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
  1329. printf("options:");
  1330. printf("%s ",BN_options());
  1331. #ifndef OPENSSL_NO_MD2
  1332. printf("%s ",MD2_options());
  1333. #endif
  1334. #ifndef OPENSSL_NO_RC4
  1335. printf("%s ",RC4_options());
  1336. #endif
  1337. #ifndef OPENSSL_NO_DES
  1338. printf("%s ",des_options());
  1339. #endif
  1340. #ifndef OPENSSL_NO_IDEA
  1341. printf("%s ",idea_options());
  1342. #endif
  1343. #ifndef OPENSSL_NO_BF
  1344. printf("%s ",BF_options());
  1345. #endif
  1346. fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
  1347. if (pr_header)
  1348. {
  1349. fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
  1350. fprintf(stdout,"type ");
  1351. for (j=0; j<SIZE_NUM; j++)
  1352. fprintf(stdout,"%7d bytes",lengths[j]);
  1353. fprintf(stdout,"\n");
  1354. }
  1355. for (k=0; k<ALGOR_NUM; k++)
  1356. {
  1357. if (!doit[k]) continue;
  1358. fprintf(stdout,"%-13s",names[k]);
  1359. for (j=0; j<SIZE_NUM; j++)
  1360. {
  1361. if (results[k][j] > 10000)
  1362. fprintf(stdout," %11.2fk",results[k][j]/1e3);
  1363. else
  1364. fprintf(stdout," %11.2f ",results[k][j]);
  1365. }
  1366. fprintf(stdout,"\n");
  1367. }
  1368. #ifndef OPENSSL_NO_RSA
  1369. j=1;
  1370. for (k=0; k<RSA_NUM; k++)
  1371. {
  1372. if (!rsa_doit[k]) continue;
  1373. if (j)
  1374. {
  1375. printf("%18ssign verify sign/s verify/s\n"," ");
  1376. j=0;
  1377. }
  1378. fprintf(stdout,"rsa %4u bits %8.4fs %8.4fs %8.1f %8.1f",
  1379. rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
  1380. 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
  1381. fprintf(stdout,"\n");
  1382. }
  1383. #endif
  1384. #ifndef OPENSSL_NO_DSA
  1385. j=1;
  1386. for (k=0; k<DSA_NUM; k++)
  1387. {
  1388. if (!dsa_doit[k]) continue;
  1389. if (j) {
  1390. printf("%18ssign verify sign/s verify/s\n"," ");
  1391. j=0;
  1392. }
  1393. fprintf(stdout,"dsa %4u bits %8.4fs %8.4fs %8.1f %8.1f",
  1394. dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
  1395. 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
  1396. fprintf(stdout,"\n");
  1397. }
  1398. #endif
  1399. mret=0;
  1400. end:
  1401. ERR_print_errors(bio_err);
  1402. if (buf != NULL) OPENSSL_free(buf);
  1403. if (buf2 != NULL) OPENSSL_free(buf2);
  1404. #ifndef OPENSSL_NO_RSA
  1405. for (i=0; i<RSA_NUM; i++)
  1406. if (rsa_key[i] != NULL)
  1407. RSA_free(rsa_key[i]);
  1408. #endif
  1409. #ifndef OPENSSL_NO_DSA
  1410. for (i=0; i<DSA_NUM; i++)
  1411. if (dsa_key[i] != NULL)
  1412. DSA_free(dsa_key[i]);
  1413. #endif
  1414. EXIT(mret);
  1415. }
  1416. static void print_message(const char *s, long num, int length)
  1417. {
  1418. #ifdef SIGALRM
  1419. BIO_printf(bio_err,"Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
  1420. (void)BIO_flush(bio_err);
  1421. alarm(SECONDS);
  1422. #else
  1423. BIO_printf(bio_err,"Doing %s %ld times on %d size blocks: ",s,num,length);
  1424. (void)BIO_flush(bio_err);
  1425. #endif
  1426. #ifdef LINT
  1427. num=num;
  1428. #endif
  1429. }
  1430. static void pkey_print_message(char *str, char *str2, long num, int bits,
  1431. int tm)
  1432. {
  1433. #ifdef SIGALRM
  1434. BIO_printf(bio_err,"Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
  1435. (void)BIO_flush(bio_err);
  1436. alarm(RSA_SECONDS);
  1437. #else
  1438. BIO_printf(bio_err,"Doing %ld %d bit %s %s's: ",num,bits,str,str2);
  1439. (void)BIO_flush(bio_err);
  1440. #endif
  1441. #ifdef LINT
  1442. num=num;
  1443. #endif
  1444. }