2
0

speed.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532
  1. /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
  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. /* ====================================================================
  59. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  60. *
  61. * Portions of the attached software ("Contribution") are developed by
  62. * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
  63. *
  64. * The Contribution is licensed pursuant to the OpenSSL open source
  65. * license provided above.
  66. *
  67. * The ECDH and ECDSA speed test software is originally written by
  68. * Sumit Gupta of Sun Microsystems Laboratories.
  69. *
  70. */
  71. /* most of this code has been pilfered from my libdes speed.c program */
  72. #ifndef OPENSSL_NO_SPEED
  73. #undef SECONDS
  74. #define SECONDS 3
  75. #define RSA_SECONDS 10
  76. #define DSA_SECONDS 10
  77. #define ECDSA_SECONDS 10
  78. #define ECDH_SECONDS 10
  79. /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
  80. /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
  81. #undef PROG
  82. #define PROG speed_main
  83. #include <stdio.h>
  84. #include <stdlib.h>
  85. #include <string.h>
  86. #include <math.h>
  87. #include "apps.h"
  88. #ifdef OPENSSL_NO_STDIO
  89. #define APPS_WIN16
  90. #endif
  91. #include <openssl/crypto.h>
  92. #include <openssl/rand.h>
  93. #include <openssl/err.h>
  94. #include <openssl/evp.h>
  95. #include <openssl/objects.h>
  96. #if !defined(OPENSSL_SYS_MSDOS)
  97. #include OPENSSL_UNISTD
  98. #endif
  99. #ifndef OPENSSL_SYS_NETWARE
  100. #include <signal.h>
  101. #endif
  102. #ifdef _WIN32
  103. #include <windows.h>
  104. #endif
  105. #include <openssl/bn.h>
  106. #ifndef OPENSSL_NO_DES
  107. #include <openssl/des.h>
  108. #endif
  109. #ifndef OPENSSL_NO_AES
  110. #include <openssl/aes.h>
  111. #endif
  112. #ifndef OPENSSL_NO_MD2
  113. #include <openssl/md2.h>
  114. #endif
  115. #ifndef OPENSSL_NO_MDC2
  116. #include <openssl/mdc2.h>
  117. #endif
  118. #ifndef OPENSSL_NO_MD4
  119. #include <openssl/md4.h>
  120. #endif
  121. #ifndef OPENSSL_NO_MD5
  122. #include <openssl/md5.h>
  123. #endif
  124. #ifndef OPENSSL_NO_HMAC
  125. #include <openssl/hmac.h>
  126. #endif
  127. #include <openssl/evp.h>
  128. #ifndef OPENSSL_NO_SHA
  129. #include <openssl/sha.h>
  130. #endif
  131. #ifndef OPENSSL_NO_RIPEMD
  132. #include <openssl/ripemd.h>
  133. #endif
  134. #ifndef OPENSSL_NO_RC4
  135. #include <openssl/rc4.h>
  136. #endif
  137. #ifndef OPENSSL_NO_RC5
  138. #include <openssl/rc5.h>
  139. #endif
  140. #ifndef OPENSSL_NO_RC2
  141. #include <openssl/rc2.h>
  142. #endif
  143. #ifndef OPENSSL_NO_IDEA
  144. #include <openssl/idea.h>
  145. #endif
  146. #ifndef OPENSSL_NO_BF
  147. #include <openssl/blowfish.h>
  148. #endif
  149. #ifndef OPENSSL_NO_CAST
  150. #include <openssl/cast.h>
  151. #endif
  152. #ifndef OPENSSL_NO_RSA
  153. #include <openssl/rsa.h>
  154. #include "./testrsa.h"
  155. #endif
  156. #include <openssl/x509.h>
  157. #ifndef OPENSSL_NO_DSA
  158. #include <openssl/dsa.h>
  159. #include "./testdsa.h"
  160. #endif
  161. #ifndef OPENSSL_NO_ECDSA
  162. #include <openssl/ecdsa.h>
  163. #endif
  164. #ifndef OPENSSL_NO_ECDH
  165. #include <openssl/ecdh.h>
  166. #endif
  167. #if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) && !defined(OPENSSL_SYS_NETWARE)
  168. # define HAVE_FORK 1
  169. #endif
  170. #undef BUFSIZE
  171. #define BUFSIZE ((long)1024*8+1)
  172. int run=0;
  173. static int mr=0;
  174. static int usertime=1;
  175. static double Time_F(int s);
  176. static void print_message(const char *s,long num,int length);
  177. static void pkey_print_message(const char *str, const char *str2,
  178. long num, int bits, int sec);
  179. static void print_result(int alg,int run_no,int count,double time_used);
  180. #ifdef HAVE_FORK
  181. static int do_multi(int multi);
  182. #endif
  183. #define ALGOR_NUM 21
  184. #define SIZE_NUM 5
  185. #define RSA_NUM 4
  186. #define DSA_NUM 3
  187. #define EC_NUM 16
  188. #define MAX_ECDH_SIZE 256
  189. static const char *names[ALGOR_NUM]={
  190. "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
  191. "des cbc","des ede3","idea cbc",
  192. "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
  193. "aes-128 cbc","aes-192 cbc","aes-256 cbc","evp","sha256","sha512"};
  194. static double results[ALGOR_NUM][SIZE_NUM];
  195. static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
  196. static double rsa_results[RSA_NUM][2];
  197. static double dsa_results[DSA_NUM][2];
  198. #ifndef OPENSSL_NO_ECDSA
  199. static double ecdsa_results[EC_NUM][2];
  200. #endif
  201. #ifndef OPENSSL_NO_ECDH
  202. static double ecdh_results[EC_NUM][1];
  203. #endif
  204. #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
  205. static const char rnd_seed[] = "string to make the random number generator think it has entropy";
  206. static int rnd_fake = 0;
  207. #endif
  208. #ifdef SIGALRM
  209. #if defined(__STDC__) || defined(sgi) || defined(_AIX)
  210. #define SIGRETTYPE void
  211. #else
  212. #define SIGRETTYPE int
  213. #endif
  214. static SIGRETTYPE sig_done(int sig);
  215. static SIGRETTYPE sig_done(int sig)
  216. {
  217. signal(SIGALRM,sig_done);
  218. run=0;
  219. #ifdef LINT
  220. sig=sig;
  221. #endif
  222. }
  223. #endif
  224. #define START 0
  225. #define STOP 1
  226. #if defined(_WIN32)
  227. #define SIGALRM
  228. static unsigned int lapse,schlock;
  229. static void alarm(unsigned int secs) { lapse = secs*1000; }
  230. static DWORD WINAPI sleepy(VOID *arg)
  231. {
  232. schlock = 1;
  233. Sleep(lapse);
  234. run = 0;
  235. return 0;
  236. }
  237. static double Time_F(int s)
  238. {
  239. if (s == START)
  240. {
  241. HANDLE thr;
  242. schlock = 0;
  243. thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
  244. if (thr==NULL)
  245. {
  246. DWORD ret=GetLastError();
  247. BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
  248. ExitProcess(ret);
  249. }
  250. CloseHandle(thr); /* detach the thread */
  251. while (!schlock) Sleep(0); /* scheduler spinlock */
  252. }
  253. return app_tminterval(s,usertime);
  254. }
  255. #else
  256. static double Time_F(int s)
  257. {
  258. return app_tminterval(s,usertime);
  259. }
  260. #endif
  261. #ifndef OPENSSL_NO_ECDH
  262. static const int KDF1_SHA1_len = 20;
  263. static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
  264. {
  265. #ifndef OPENSSL_NO_SHA
  266. if (*outlen < SHA_DIGEST_LENGTH)
  267. return NULL;
  268. else
  269. *outlen = SHA_DIGEST_LENGTH;
  270. return SHA1(in, inlen, out);
  271. #else
  272. return NULL;
  273. #endif /* OPENSSL_NO_SHA */
  274. }
  275. #endif /* OPENSSL_NO_ECDH */
  276. int MAIN(int, char **);
  277. int MAIN(int argc, char **argv)
  278. {
  279. #ifndef OPENSSL_NO_ENGINE
  280. ENGINE *e = NULL;
  281. #endif
  282. unsigned char *buf=NULL,*buf2=NULL;
  283. int mret=1;
  284. long count=0,save_count=0;
  285. int i,j,k;
  286. #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
  287. long rsa_count;
  288. #endif
  289. #ifndef OPENSSL_NO_RSA
  290. unsigned rsa_num;
  291. #endif
  292. unsigned char md[EVP_MAX_MD_SIZE];
  293. #ifndef OPENSSL_NO_MD2
  294. unsigned char md2[MD2_DIGEST_LENGTH];
  295. #endif
  296. #ifndef OPENSSL_NO_MDC2
  297. unsigned char mdc2[MDC2_DIGEST_LENGTH];
  298. #endif
  299. #ifndef OPENSSL_NO_MD4
  300. unsigned char md4[MD4_DIGEST_LENGTH];
  301. #endif
  302. #ifndef OPENSSL_NO_MD5
  303. unsigned char md5[MD5_DIGEST_LENGTH];
  304. unsigned char hmac[MD5_DIGEST_LENGTH];
  305. #endif
  306. #ifndef OPENSSL_NO_SHA
  307. unsigned char sha[SHA_DIGEST_LENGTH];
  308. #ifndef OPENSSL_NO_SHA256
  309. unsigned char sha256[SHA256_DIGEST_LENGTH];
  310. #endif
  311. #ifndef OPENSSL_NO_SHA512
  312. unsigned char sha512[SHA512_DIGEST_LENGTH];
  313. #endif
  314. #endif
  315. #ifndef OPENSSL_NO_RIPEMD
  316. unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
  317. #endif
  318. #ifndef OPENSSL_NO_RC4
  319. RC4_KEY rc4_ks;
  320. #endif
  321. #ifndef OPENSSL_NO_RC5
  322. RC5_32_KEY rc5_ks;
  323. #endif
  324. #ifndef OPENSSL_NO_RC2
  325. RC2_KEY rc2_ks;
  326. #endif
  327. #ifndef OPENSSL_NO_IDEA
  328. IDEA_KEY_SCHEDULE idea_ks;
  329. #endif
  330. #ifndef OPENSSL_NO_BF
  331. BF_KEY bf_ks;
  332. #endif
  333. #ifndef OPENSSL_NO_CAST
  334. CAST_KEY cast_ks;
  335. #endif
  336. static const unsigned char key16[16]=
  337. {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
  338. 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
  339. #ifndef OPENSSL_NO_AES
  340. static const unsigned char key24[24]=
  341. {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
  342. 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
  343. 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
  344. static const unsigned char key32[32]=
  345. {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
  346. 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
  347. 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
  348. 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
  349. #endif
  350. #ifndef OPENSSL_NO_AES
  351. #define MAX_BLOCK_SIZE 128
  352. #else
  353. #define MAX_BLOCK_SIZE 64
  354. #endif
  355. unsigned char DES_iv[8];
  356. unsigned char iv[MAX_BLOCK_SIZE/8];
  357. #ifndef OPENSSL_NO_DES
  358. DES_cblock *buf_as_des_cblock = NULL;
  359. static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
  360. static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
  361. static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
  362. DES_key_schedule sch;
  363. DES_key_schedule sch2;
  364. DES_key_schedule sch3;
  365. #endif
  366. #ifndef OPENSSL_NO_AES
  367. AES_KEY aes_ks1, aes_ks2, aes_ks3;
  368. #endif
  369. #define D_MD2 0
  370. #define D_MDC2 1
  371. #define D_MD4 2
  372. #define D_MD5 3
  373. #define D_HMAC 4
  374. #define D_SHA1 5
  375. #define D_RMD160 6
  376. #define D_RC4 7
  377. #define D_CBC_DES 8
  378. #define D_EDE3_DES 9
  379. #define D_CBC_IDEA 10
  380. #define D_CBC_RC2 11
  381. #define D_CBC_RC5 12
  382. #define D_CBC_BF 13
  383. #define D_CBC_CAST 14
  384. #define D_CBC_128_AES 15
  385. #define D_CBC_192_AES 16
  386. #define D_CBC_256_AES 17
  387. #define D_EVP 18
  388. #define D_SHA256 19
  389. #define D_SHA512 20
  390. double d=0.0;
  391. long c[ALGOR_NUM][SIZE_NUM];
  392. #define R_DSA_512 0
  393. #define R_DSA_1024 1
  394. #define R_DSA_2048 2
  395. #define R_RSA_512 0
  396. #define R_RSA_1024 1
  397. #define R_RSA_2048 2
  398. #define R_RSA_4096 3
  399. #define R_EC_P160 0
  400. #define R_EC_P192 1
  401. #define R_EC_P224 2
  402. #define R_EC_P256 3
  403. #define R_EC_P384 4
  404. #define R_EC_P521 5
  405. #define R_EC_K163 6
  406. #define R_EC_K233 7
  407. #define R_EC_K283 8
  408. #define R_EC_K409 9
  409. #define R_EC_K571 10
  410. #define R_EC_B163 11
  411. #define R_EC_B233 12
  412. #define R_EC_B283 13
  413. #define R_EC_B409 14
  414. #define R_EC_B571 15
  415. #ifndef OPENSSL_NO_RSA
  416. RSA *rsa_key[RSA_NUM];
  417. long rsa_c[RSA_NUM][2];
  418. static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
  419. static unsigned char *rsa_data[RSA_NUM]=
  420. {test512,test1024,test2048,test4096};
  421. static int rsa_data_length[RSA_NUM]={
  422. sizeof(test512),sizeof(test1024),
  423. sizeof(test2048),sizeof(test4096)};
  424. #endif
  425. #ifndef OPENSSL_NO_DSA
  426. DSA *dsa_key[DSA_NUM];
  427. long dsa_c[DSA_NUM][2];
  428. static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
  429. #endif
  430. #ifndef OPENSSL_NO_EC
  431. /* We only test over the following curves as they are representative,
  432. * To add tests over more curves, simply add the curve NID
  433. * and curve name to the following arrays and increase the
  434. * EC_NUM value accordingly.
  435. */
  436. static unsigned int test_curves[EC_NUM] =
  437. {
  438. /* Prime Curves */
  439. NID_secp160r1,
  440. NID_X9_62_prime192v1,
  441. NID_secp224r1,
  442. NID_X9_62_prime256v1,
  443. NID_secp384r1,
  444. NID_secp521r1,
  445. /* Binary Curves */
  446. NID_sect163k1,
  447. NID_sect233k1,
  448. NID_sect283k1,
  449. NID_sect409k1,
  450. NID_sect571k1,
  451. NID_sect163r2,
  452. NID_sect233r1,
  453. NID_sect283r1,
  454. NID_sect409r1,
  455. NID_sect571r1
  456. };
  457. static const char * test_curves_names[EC_NUM] =
  458. {
  459. /* Prime Curves */
  460. "secp160r1",
  461. "nistp192",
  462. "nistp224",
  463. "nistp256",
  464. "nistp384",
  465. "nistp521",
  466. /* Binary Curves */
  467. "nistk163",
  468. "nistk233",
  469. "nistk283",
  470. "nistk409",
  471. "nistk571",
  472. "nistb163",
  473. "nistb233",
  474. "nistb283",
  475. "nistb409",
  476. "nistb571"
  477. };
  478. static int test_curves_bits[EC_NUM] =
  479. {
  480. 160, 192, 224, 256, 384, 521,
  481. 163, 233, 283, 409, 571,
  482. 163, 233, 283, 409, 571
  483. };
  484. #endif
  485. #ifndef OPENSSL_NO_ECDSA
  486. unsigned char ecdsasig[256];
  487. unsigned int ecdsasiglen;
  488. EC_KEY *ecdsa[EC_NUM];
  489. long ecdsa_c[EC_NUM][2];
  490. #endif
  491. #ifndef OPENSSL_NO_ECDH
  492. EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
  493. unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
  494. int secret_size_a, secret_size_b;
  495. int ecdh_checks = 0;
  496. int secret_idx = 0;
  497. long ecdh_c[EC_NUM][2];
  498. #endif
  499. int rsa_doit[RSA_NUM];
  500. int dsa_doit[DSA_NUM];
  501. #ifndef OPENSSL_NO_ECDSA
  502. int ecdsa_doit[EC_NUM];
  503. #endif
  504. #ifndef OPENSSL_NO_ECDH
  505. int ecdh_doit[EC_NUM];
  506. #endif
  507. int doit[ALGOR_NUM];
  508. int pr_header=0;
  509. const EVP_CIPHER *evp_cipher=NULL;
  510. const EVP_MD *evp_md=NULL;
  511. int decrypt=0;
  512. #ifdef HAVE_FORK
  513. int multi=0;
  514. #endif
  515. #ifndef TIMES
  516. usertime=-1;
  517. #endif
  518. apps_startup();
  519. memset(results, 0, sizeof(results));
  520. #ifndef OPENSSL_NO_DSA
  521. memset(dsa_key,0,sizeof(dsa_key));
  522. #endif
  523. #ifndef OPENSSL_NO_ECDSA
  524. for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
  525. #endif
  526. #ifndef OPENSSL_NO_ECDH
  527. for (i=0; i<EC_NUM; i++)
  528. {
  529. ecdh_a[i] = NULL;
  530. ecdh_b[i] = NULL;
  531. }
  532. #endif
  533. if (bio_err == NULL)
  534. if ((bio_err=BIO_new(BIO_s_file())) != NULL)
  535. BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
  536. if (!load_config(bio_err, NULL))
  537. goto end;
  538. #ifndef OPENSSL_NO_RSA
  539. memset(rsa_key,0,sizeof(rsa_key));
  540. for (i=0; i<RSA_NUM; i++)
  541. rsa_key[i]=NULL;
  542. #endif
  543. if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
  544. {
  545. BIO_printf(bio_err,"out of memory\n");
  546. goto end;
  547. }
  548. #ifndef OPENSSL_NO_DES
  549. buf_as_des_cblock = (DES_cblock *)buf;
  550. #endif
  551. if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
  552. {
  553. BIO_printf(bio_err,"out of memory\n");
  554. goto end;
  555. }
  556. memset(c,0,sizeof(c));
  557. memset(DES_iv,0,sizeof(DES_iv));
  558. memset(iv,0,sizeof(iv));
  559. for (i=0; i<ALGOR_NUM; i++)
  560. doit[i]=0;
  561. for (i=0; i<RSA_NUM; i++)
  562. rsa_doit[i]=0;
  563. for (i=0; i<DSA_NUM; i++)
  564. dsa_doit[i]=0;
  565. #ifndef OPENSSL_NO_ECDSA
  566. for (i=0; i<EC_NUM; i++)
  567. ecdsa_doit[i]=0;
  568. #endif
  569. #ifndef OPENSSL_NO_ECDH
  570. for (i=0; i<EC_NUM; i++)
  571. ecdh_doit[i]=0;
  572. #endif
  573. j=0;
  574. argc--;
  575. argv++;
  576. while (argc)
  577. {
  578. if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
  579. {
  580. usertime = 0;
  581. j--; /* Otherwise, -elapsed gets confused with
  582. an algorithm. */
  583. }
  584. else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
  585. {
  586. argc--;
  587. argv++;
  588. if(argc == 0)
  589. {
  590. BIO_printf(bio_err,"no EVP given\n");
  591. goto end;
  592. }
  593. evp_cipher=EVP_get_cipherbyname(*argv);
  594. if(!evp_cipher)
  595. {
  596. evp_md=EVP_get_digestbyname(*argv);
  597. }
  598. if(!evp_cipher && !evp_md)
  599. {
  600. BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
  601. goto end;
  602. }
  603. doit[D_EVP]=1;
  604. }
  605. else if (argc > 0 && !strcmp(*argv,"-decrypt"))
  606. {
  607. decrypt=1;
  608. j--; /* Otherwise, -elapsed gets confused with
  609. an algorithm. */
  610. }
  611. #ifndef OPENSSL_NO_ENGINE
  612. else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
  613. {
  614. argc--;
  615. argv++;
  616. if(argc == 0)
  617. {
  618. BIO_printf(bio_err,"no engine given\n");
  619. goto end;
  620. }
  621. e = setup_engine(bio_err, *argv, 0);
  622. /* j will be increased again further down. We just
  623. don't want speed to confuse an engine with an
  624. algorithm, especially when none is given (which
  625. means all of them should be run) */
  626. j--;
  627. }
  628. #endif
  629. #ifdef HAVE_FORK
  630. else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
  631. {
  632. argc--;
  633. argv++;
  634. if(argc == 0)
  635. {
  636. BIO_printf(bio_err,"no multi count given\n");
  637. goto end;
  638. }
  639. multi=atoi(argv[0]);
  640. if(multi <= 0)
  641. {
  642. BIO_printf(bio_err,"bad multi count\n");
  643. goto end;
  644. }
  645. j--; /* Otherwise, -mr gets confused with
  646. an algorithm. */
  647. }
  648. #endif
  649. else if (argc > 0 && !strcmp(*argv,"-mr"))
  650. {
  651. mr=1;
  652. j--; /* Otherwise, -mr gets confused with
  653. an algorithm. */
  654. }
  655. else
  656. #ifndef OPENSSL_NO_MD2
  657. if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
  658. else
  659. #endif
  660. #ifndef OPENSSL_NO_MDC2
  661. if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
  662. else
  663. #endif
  664. #ifndef OPENSSL_NO_MD4
  665. if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
  666. else
  667. #endif
  668. #ifndef OPENSSL_NO_MD5
  669. if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
  670. else
  671. #endif
  672. #ifndef OPENSSL_NO_MD5
  673. if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
  674. else
  675. #endif
  676. #ifndef OPENSSL_NO_SHA
  677. if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
  678. else
  679. if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
  680. doit[D_SHA256]=1,
  681. doit[D_SHA512]=1;
  682. else
  683. #ifndef OPENSSL_NO_SHA256
  684. if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
  685. else
  686. #endif
  687. #ifndef OPENSSL_NO_SHA512
  688. if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
  689. else
  690. #endif
  691. #endif
  692. #ifndef OPENSSL_NO_RIPEMD
  693. if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
  694. else
  695. if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
  696. else
  697. if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
  698. else
  699. #endif
  700. #ifndef OPENSSL_NO_RC4
  701. if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
  702. else
  703. #endif
  704. #ifndef OPENSSL_NO_DES
  705. if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
  706. else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
  707. else
  708. #endif
  709. #ifndef OPENSSL_NO_AES
  710. if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
  711. else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
  712. else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
  713. else
  714. #endif
  715. #ifndef OPENSSL_NO_RSA
  716. #if 0 /* was: #ifdef RSAref */
  717. if (strcmp(*argv,"rsaref") == 0)
  718. {
  719. RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
  720. j--;
  721. }
  722. else
  723. #endif
  724. #ifndef RSA_NULL
  725. if (strcmp(*argv,"openssl") == 0)
  726. {
  727. RSA_set_default_method(RSA_PKCS1_SSLeay());
  728. j--;
  729. }
  730. else
  731. #endif
  732. #endif /* !OPENSSL_NO_RSA */
  733. if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
  734. else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
  735. else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
  736. else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
  737. else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
  738. else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
  739. else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
  740. else
  741. #ifndef OPENSSL_NO_RC2
  742. if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
  743. else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
  744. else
  745. #endif
  746. #ifndef OPENSSL_NO_RC5
  747. if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
  748. else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
  749. else
  750. #endif
  751. #ifndef OPENSSL_NO_IDEA
  752. if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
  753. else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
  754. else
  755. #endif
  756. #ifndef OPENSSL_NO_BF
  757. if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
  758. else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
  759. else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
  760. else
  761. #endif
  762. #ifndef OPENSSL_NO_CAST
  763. if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
  764. else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
  765. else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
  766. else
  767. #endif
  768. #ifndef OPENSSL_NO_DES
  769. if (strcmp(*argv,"des") == 0)
  770. {
  771. doit[D_CBC_DES]=1;
  772. doit[D_EDE3_DES]=1;
  773. }
  774. else
  775. #endif
  776. #ifndef OPENSSL_NO_AES
  777. if (strcmp(*argv,"aes") == 0)
  778. {
  779. doit[D_CBC_128_AES]=1;
  780. doit[D_CBC_192_AES]=1;
  781. doit[D_CBC_256_AES]=1;
  782. }
  783. else
  784. #endif
  785. #ifndef OPENSSL_NO_RSA
  786. if (strcmp(*argv,"rsa") == 0)
  787. {
  788. rsa_doit[R_RSA_512]=1;
  789. rsa_doit[R_RSA_1024]=1;
  790. rsa_doit[R_RSA_2048]=1;
  791. rsa_doit[R_RSA_4096]=1;
  792. }
  793. else
  794. #endif
  795. #ifndef OPENSSL_NO_DSA
  796. if (strcmp(*argv,"dsa") == 0)
  797. {
  798. dsa_doit[R_DSA_512]=1;
  799. dsa_doit[R_DSA_1024]=1;
  800. dsa_doit[R_DSA_2048]=1;
  801. }
  802. else
  803. #endif
  804. #ifndef OPENSSL_NO_ECDSA
  805. if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
  806. else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
  807. else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
  808. else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
  809. else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
  810. else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
  811. else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
  812. else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
  813. else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
  814. else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
  815. else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
  816. else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
  817. else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
  818. else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
  819. else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
  820. else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
  821. else if (strcmp(*argv,"ecdsa") == 0)
  822. {
  823. for (i=0; i < EC_NUM; i++)
  824. ecdsa_doit[i]=1;
  825. }
  826. else
  827. #endif
  828. #ifndef OPENSSL_NO_ECDH
  829. if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
  830. else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
  831. else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
  832. else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
  833. else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
  834. else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
  835. else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
  836. else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
  837. else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
  838. else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
  839. else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
  840. else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
  841. else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
  842. else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
  843. else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
  844. else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
  845. else if (strcmp(*argv,"ecdh") == 0)
  846. {
  847. for (i=0; i < EC_NUM; i++)
  848. ecdh_doit[i]=1;
  849. }
  850. else
  851. #endif
  852. {
  853. BIO_printf(bio_err,"Error: bad option or value\n");
  854. BIO_printf(bio_err,"\n");
  855. BIO_printf(bio_err,"Available values:\n");
  856. #ifndef OPENSSL_NO_MD2
  857. BIO_printf(bio_err,"md2 ");
  858. #endif
  859. #ifndef OPENSSL_NO_MDC2
  860. BIO_printf(bio_err,"mdc2 ");
  861. #endif
  862. #ifndef OPENSSL_NO_MD4
  863. BIO_printf(bio_err,"md4 ");
  864. #endif
  865. #ifndef OPENSSL_NO_MD5
  866. BIO_printf(bio_err,"md5 ");
  867. #ifndef OPENSSL_NO_HMAC
  868. BIO_printf(bio_err,"hmac ");
  869. #endif
  870. #endif
  871. #ifndef OPENSSL_NO_SHA1
  872. BIO_printf(bio_err,"sha1 ");
  873. #endif
  874. #ifndef OPENSSL_NO_SHA256
  875. BIO_printf(bio_err,"sha256 ");
  876. #endif
  877. #ifndef OPENSSL_NO_SHA512
  878. BIO_printf(bio_err,"sha512 ");
  879. #endif
  880. #ifndef OPENSSL_NO_RIPEMD160
  881. BIO_printf(bio_err,"rmd160");
  882. #endif
  883. #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
  884. !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
  885. !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
  886. BIO_printf(bio_err,"\n");
  887. #endif
  888. #ifndef OPENSSL_NO_IDEA
  889. BIO_printf(bio_err,"idea-cbc ");
  890. #endif
  891. #ifndef OPENSSL_NO_RC2
  892. BIO_printf(bio_err,"rc2-cbc ");
  893. #endif
  894. #ifndef OPENSSL_NO_RC5
  895. BIO_printf(bio_err,"rc5-cbc ");
  896. #endif
  897. #ifndef OPENSSL_NO_BF
  898. BIO_printf(bio_err,"bf-cbc");
  899. #endif
  900. #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
  901. !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
  902. BIO_printf(bio_err,"\n");
  903. #endif
  904. #ifndef OPENSSL_NO_DES
  905. BIO_printf(bio_err,"des-cbc des-ede3 ");
  906. #endif
  907. #ifndef OPENSSL_NO_AES
  908. BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
  909. #endif
  910. #ifndef OPENSSL_NO_RC4
  911. BIO_printf(bio_err,"rc4");
  912. #endif
  913. BIO_printf(bio_err,"\n");
  914. #ifndef OPENSSL_NO_RSA
  915. BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
  916. #endif
  917. #ifndef OPENSSL_NO_DSA
  918. BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
  919. #endif
  920. #ifndef OPENSSL_NO_ECDSA
  921. BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
  922. BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
  923. BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
  924. BIO_printf(bio_err,"ecdsa\n");
  925. #endif
  926. #ifndef OPENSSL_NO_ECDH
  927. BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
  928. BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
  929. BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
  930. BIO_printf(bio_err,"ecdh\n");
  931. #endif
  932. #ifndef OPENSSL_NO_IDEA
  933. BIO_printf(bio_err,"idea ");
  934. #endif
  935. #ifndef OPENSSL_NO_RC2
  936. BIO_printf(bio_err,"rc2 ");
  937. #endif
  938. #ifndef OPENSSL_NO_DES
  939. BIO_printf(bio_err,"des ");
  940. #endif
  941. #ifndef OPENSSL_NO_AES
  942. BIO_printf(bio_err,"aes ");
  943. #endif
  944. #ifndef OPENSSL_NO_RSA
  945. BIO_printf(bio_err,"rsa ");
  946. #endif
  947. #ifndef OPENSSL_NO_BF
  948. BIO_printf(bio_err,"blowfish");
  949. #endif
  950. #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
  951. !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \
  952. !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES)
  953. BIO_printf(bio_err,"\n");
  954. #endif
  955. BIO_printf(bio_err,"\n");
  956. BIO_printf(bio_err,"Available options:\n");
  957. #if defined(TIMES) || defined(USE_TOD)
  958. BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
  959. #endif
  960. #ifndef OPENSSL_NO_ENGINE
  961. BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
  962. #endif
  963. BIO_printf(bio_err,"-evp e use EVP e.\n");
  964. BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
  965. BIO_printf(bio_err,"-mr produce machine readable output.\n");
  966. #ifdef HAVE_FORK
  967. BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
  968. #endif
  969. goto end;
  970. }
  971. argc--;
  972. argv++;
  973. j++;
  974. }
  975. #ifdef HAVE_FORK
  976. if(multi && do_multi(multi))
  977. goto show_res;
  978. #endif
  979. if (j == 0)
  980. {
  981. for (i=0; i<ALGOR_NUM; i++)
  982. {
  983. if (i != D_EVP)
  984. doit[i]=1;
  985. }
  986. for (i=0; i<RSA_NUM; i++)
  987. rsa_doit[i]=1;
  988. for (i=0; i<DSA_NUM; i++)
  989. dsa_doit[i]=1;
  990. }
  991. for (i=0; i<ALGOR_NUM; i++)
  992. if (doit[i]) pr_header++;
  993. if (usertime == 0 && !mr)
  994. BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
  995. #ifndef OPENSSL_NO_RSA
  996. for (i=0; i<RSA_NUM; i++)
  997. {
  998. const unsigned char *p;
  999. p=rsa_data[i];
  1000. rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
  1001. if (rsa_key[i] == NULL)
  1002. {
  1003. BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
  1004. goto end;
  1005. }
  1006. #if 0
  1007. else
  1008. {
  1009. BIO_printf(bio_err,mr ? "+RK:%d:"
  1010. : "Loaded RSA key, %d bit modulus and e= 0x",
  1011. BN_num_bits(rsa_key[i]->n));
  1012. BN_print(bio_err,rsa_key[i]->e);
  1013. BIO_printf(bio_err,"\n");
  1014. }
  1015. #endif
  1016. }
  1017. #endif
  1018. #ifndef OPENSSL_NO_DSA
  1019. dsa_key[0]=get_dsa512();
  1020. dsa_key[1]=get_dsa1024();
  1021. dsa_key[2]=get_dsa2048();
  1022. #endif
  1023. #ifndef OPENSSL_NO_DES
  1024. DES_set_key_unchecked(&key,&sch);
  1025. DES_set_key_unchecked(&key2,&sch2);
  1026. DES_set_key_unchecked(&key3,&sch3);
  1027. #endif
  1028. #ifndef OPENSSL_NO_AES
  1029. AES_set_encrypt_key(key16,128,&aes_ks1);
  1030. AES_set_encrypt_key(key24,192,&aes_ks2);
  1031. AES_set_encrypt_key(key32,256,&aes_ks3);
  1032. #endif
  1033. #ifndef OPENSSL_NO_IDEA
  1034. idea_set_encrypt_key(key16,&idea_ks);
  1035. #endif
  1036. #ifndef OPENSSL_NO_RC4
  1037. RC4_set_key(&rc4_ks,16,key16);
  1038. #endif
  1039. #ifndef OPENSSL_NO_RC2
  1040. RC2_set_key(&rc2_ks,16,key16,128);
  1041. #endif
  1042. #ifndef OPENSSL_NO_RC5
  1043. RC5_32_set_key(&rc5_ks,16,key16,12);
  1044. #endif
  1045. #ifndef OPENSSL_NO_BF
  1046. BF_set_key(&bf_ks,16,key16);
  1047. #endif
  1048. #ifndef OPENSSL_NO_CAST
  1049. CAST_set_key(&cast_ks,16,key16);
  1050. #endif
  1051. #ifndef OPENSSL_NO_RSA
  1052. memset(rsa_c,0,sizeof(rsa_c));
  1053. #endif
  1054. #ifndef SIGALRM
  1055. #ifndef OPENSSL_NO_DES
  1056. BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
  1057. count=10;
  1058. do {
  1059. long it;
  1060. count*=2;
  1061. Time_F(START);
  1062. for (it=count; it; it--)
  1063. DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
  1064. &sch,DES_ENCRYPT);
  1065. d=Time_F(STOP);
  1066. } while (d <3);
  1067. save_count=count;
  1068. c[D_MD2][0]=count/10;
  1069. c[D_MDC2][0]=count/10;
  1070. c[D_MD4][0]=count;
  1071. c[D_MD5][0]=count;
  1072. c[D_HMAC][0]=count;
  1073. c[D_SHA1][0]=count;
  1074. c[D_RMD160][0]=count;
  1075. c[D_RC4][0]=count*5;
  1076. c[D_CBC_DES][0]=count;
  1077. c[D_EDE3_DES][0]=count/3;
  1078. c[D_CBC_IDEA][0]=count;
  1079. c[D_CBC_RC2][0]=count;
  1080. c[D_CBC_RC5][0]=count;
  1081. c[D_CBC_BF][0]=count;
  1082. c[D_CBC_CAST][0]=count;
  1083. c[D_CBC_128_AES][0]=count;
  1084. c[D_CBC_192_AES][0]=count;
  1085. c[D_CBC_256_AES][0]=count;
  1086. c[D_SHA256][0]=count;
  1087. c[D_SHA512][0]=count;
  1088. for (i=1; i<SIZE_NUM; i++)
  1089. {
  1090. c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
  1091. c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
  1092. c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
  1093. c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
  1094. c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
  1095. c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
  1096. c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
  1097. c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
  1098. c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
  1099. }
  1100. for (i=1; i<SIZE_NUM; i++)
  1101. {
  1102. long l0,l1;
  1103. l0=(long)lengths[i-1];
  1104. l1=(long)lengths[i];
  1105. c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
  1106. c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
  1107. c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
  1108. c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
  1109. c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
  1110. c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
  1111. c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
  1112. c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
  1113. c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
  1114. c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
  1115. c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
  1116. }
  1117. #ifndef OPENSSL_NO_RSA
  1118. rsa_c[R_RSA_512][0]=count/2000;
  1119. rsa_c[R_RSA_512][1]=count/400;
  1120. for (i=1; i<RSA_NUM; i++)
  1121. {
  1122. rsa_c[i][0]=rsa_c[i-1][0]/8;
  1123. rsa_c[i][1]=rsa_c[i-1][1]/4;
  1124. if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
  1125. rsa_doit[i]=0;
  1126. else
  1127. {
  1128. if (rsa_c[i][0] == 0)
  1129. {
  1130. rsa_c[i][0]=1;
  1131. rsa_c[i][1]=20;
  1132. }
  1133. }
  1134. }
  1135. #endif
  1136. #ifndef OPENSSL_NO_DSA
  1137. dsa_c[R_DSA_512][0]=count/1000;
  1138. dsa_c[R_DSA_512][1]=count/1000/2;
  1139. for (i=1; i<DSA_NUM; i++)
  1140. {
  1141. dsa_c[i][0]=dsa_c[i-1][0]/4;
  1142. dsa_c[i][1]=dsa_c[i-1][1]/4;
  1143. if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
  1144. dsa_doit[i]=0;
  1145. else
  1146. {
  1147. if (dsa_c[i] == 0)
  1148. {
  1149. dsa_c[i][0]=1;
  1150. dsa_c[i][1]=1;
  1151. }
  1152. }
  1153. }
  1154. #endif
  1155. #ifndef OPENSSL_NO_ECDSA
  1156. ecdsa_c[R_EC_P160][0]=count/1000;
  1157. ecdsa_c[R_EC_P160][1]=count/1000/2;
  1158. for (i=R_EC_P192; i<=R_EC_P521; i++)
  1159. {
  1160. ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
  1161. ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
  1162. if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
  1163. ecdsa_doit[i]=0;
  1164. else
  1165. {
  1166. if (ecdsa_c[i] == 0)
  1167. {
  1168. ecdsa_c[i][0]=1;
  1169. ecdsa_c[i][1]=1;
  1170. }
  1171. }
  1172. }
  1173. ecdsa_c[R_EC_K163][0]=count/1000;
  1174. ecdsa_c[R_EC_K163][1]=count/1000/2;
  1175. for (i=R_EC_K233; i<=R_EC_K571; i++)
  1176. {
  1177. ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
  1178. ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
  1179. if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
  1180. ecdsa_doit[i]=0;
  1181. else
  1182. {
  1183. if (ecdsa_c[i] == 0)
  1184. {
  1185. ecdsa_c[i][0]=1;
  1186. ecdsa_c[i][1]=1;
  1187. }
  1188. }
  1189. }
  1190. ecdsa_c[R_EC_B163][0]=count/1000;
  1191. ecdsa_c[R_EC_B163][1]=count/1000/2;
  1192. for (i=R_EC_B233; i<=R_EC_B571; i++)
  1193. {
  1194. ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
  1195. ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
  1196. if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
  1197. ecdsa_doit[i]=0;
  1198. else
  1199. {
  1200. if (ecdsa_c[i] == 0)
  1201. {
  1202. ecdsa_c[i][0]=1;
  1203. ecdsa_c[i][1]=1;
  1204. }
  1205. }
  1206. }
  1207. #endif
  1208. #ifndef OPENSSL_NO_ECDH
  1209. ecdh_c[R_EC_P160][0]=count/1000;
  1210. ecdh_c[R_EC_P160][1]=count/1000;
  1211. for (i=R_EC_P192; i<=R_EC_P521; i++)
  1212. {
  1213. ecdh_c[i][0]=ecdh_c[i-1][0]/2;
  1214. ecdh_c[i][1]=ecdh_c[i-1][1]/2;
  1215. if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
  1216. ecdh_doit[i]=0;
  1217. else
  1218. {
  1219. if (ecdh_c[i] == 0)
  1220. {
  1221. ecdh_c[i][0]=1;
  1222. ecdh_c[i][1]=1;
  1223. }
  1224. }
  1225. }
  1226. ecdh_c[R_EC_K163][0]=count/1000;
  1227. ecdh_c[R_EC_K163][1]=count/1000;
  1228. for (i=R_EC_K233; i<=R_EC_K571; i++)
  1229. {
  1230. ecdh_c[i][0]=ecdh_c[i-1][0]/2;
  1231. ecdh_c[i][1]=ecdh_c[i-1][1]/2;
  1232. if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
  1233. ecdh_doit[i]=0;
  1234. else
  1235. {
  1236. if (ecdh_c[i] == 0)
  1237. {
  1238. ecdh_c[i][0]=1;
  1239. ecdh_c[i][1]=1;
  1240. }
  1241. }
  1242. }
  1243. ecdh_c[R_EC_B163][0]=count/1000;
  1244. ecdh_c[R_EC_B163][1]=count/1000;
  1245. for (i=R_EC_B233; i<=R_EC_B571; i++)
  1246. {
  1247. ecdh_c[i][0]=ecdh_c[i-1][0]/2;
  1248. ecdh_c[i][1]=ecdh_c[i-1][1]/2;
  1249. if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
  1250. ecdh_doit[i]=0;
  1251. else
  1252. {
  1253. if (ecdh_c[i] == 0)
  1254. {
  1255. ecdh_c[i][0]=1;
  1256. ecdh_c[i][1]=1;
  1257. }
  1258. }
  1259. }
  1260. #endif
  1261. #define COND(d) (count < (d))
  1262. #define COUNT(d) (d)
  1263. #else
  1264. /* not worth fixing */
  1265. # error "You cannot disable DES on systems without SIGALRM."
  1266. #endif /* OPENSSL_NO_DES */
  1267. #else
  1268. #define COND(c) (run)
  1269. #define COUNT(d) (count)
  1270. #ifndef _WIN32
  1271. signal(SIGALRM,sig_done);
  1272. #endif
  1273. #endif /* SIGALRM */
  1274. #ifndef OPENSSL_NO_MD2
  1275. if (doit[D_MD2])
  1276. {
  1277. for (j=0; j<SIZE_NUM; j++)
  1278. {
  1279. print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
  1280. Time_F(START);
  1281. for (count=0,run=1; COND(c[D_MD2][j]); count++)
  1282. EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
  1283. d=Time_F(STOP);
  1284. print_result(D_MD2,j,count,d);
  1285. }
  1286. }
  1287. #endif
  1288. #ifndef OPENSSL_NO_MDC2
  1289. if (doit[D_MDC2])
  1290. {
  1291. for (j=0; j<SIZE_NUM; j++)
  1292. {
  1293. print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
  1294. Time_F(START);
  1295. for (count=0,run=1; COND(c[D_MDC2][j]); count++)
  1296. EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
  1297. d=Time_F(STOP);
  1298. print_result(D_MDC2,j,count,d);
  1299. }
  1300. }
  1301. #endif
  1302. #ifndef OPENSSL_NO_MD4
  1303. if (doit[D_MD4])
  1304. {
  1305. for (j=0; j<SIZE_NUM; j++)
  1306. {
  1307. print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
  1308. Time_F(START);
  1309. for (count=0,run=1; COND(c[D_MD4][j]); count++)
  1310. EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
  1311. d=Time_F(STOP);
  1312. print_result(D_MD4,j,count,d);
  1313. }
  1314. }
  1315. #endif
  1316. #ifndef OPENSSL_NO_MD5
  1317. if (doit[D_MD5])
  1318. {
  1319. for (j=0; j<SIZE_NUM; j++)
  1320. {
  1321. print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
  1322. Time_F(START);
  1323. for (count=0,run=1; COND(c[D_MD5][j]); count++)
  1324. EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
  1325. d=Time_F(STOP);
  1326. print_result(D_MD5,j,count,d);
  1327. }
  1328. }
  1329. #endif
  1330. #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
  1331. if (doit[D_HMAC])
  1332. {
  1333. HMAC_CTX hctx;
  1334. HMAC_CTX_init(&hctx);
  1335. HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
  1336. 16,EVP_md5(), NULL);
  1337. for (j=0; j<SIZE_NUM; j++)
  1338. {
  1339. print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
  1340. Time_F(START);
  1341. for (count=0,run=1; COND(c[D_HMAC][j]); count++)
  1342. {
  1343. HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
  1344. HMAC_Update(&hctx,buf,lengths[j]);
  1345. HMAC_Final(&hctx,&(hmac[0]),NULL);
  1346. }
  1347. d=Time_F(STOP);
  1348. print_result(D_HMAC,j,count,d);
  1349. }
  1350. HMAC_CTX_cleanup(&hctx);
  1351. }
  1352. #endif
  1353. #ifndef OPENSSL_NO_SHA
  1354. if (doit[D_SHA1])
  1355. {
  1356. for (j=0; j<SIZE_NUM; j++)
  1357. {
  1358. print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
  1359. Time_F(START);
  1360. for (count=0,run=1; COND(c[D_SHA1][j]); count++)
  1361. EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
  1362. d=Time_F(STOP);
  1363. print_result(D_SHA1,j,count,d);
  1364. }
  1365. }
  1366. #ifndef OPENSSL_NO_SHA256
  1367. if (doit[D_SHA256])
  1368. {
  1369. for (j=0; j<SIZE_NUM; j++)
  1370. {
  1371. print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
  1372. Time_F(START);
  1373. for (count=0,run=1; COND(c[D_SHA256][j]); count++)
  1374. SHA256(buf,lengths[j],sha256);
  1375. d=Time_F(STOP);
  1376. print_result(D_SHA256,j,count,d);
  1377. }
  1378. }
  1379. #endif
  1380. #ifndef OPENSSL_NO_SHA512
  1381. if (doit[D_SHA512])
  1382. {
  1383. for (j=0; j<SIZE_NUM; j++)
  1384. {
  1385. print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
  1386. Time_F(START);
  1387. for (count=0,run=1; COND(c[D_SHA512][j]); count++)
  1388. SHA512(buf,lengths[j],sha512);
  1389. d=Time_F(STOP);
  1390. print_result(D_SHA512,j,count,d);
  1391. }
  1392. }
  1393. #endif
  1394. #endif
  1395. #ifndef OPENSSL_NO_RIPEMD
  1396. if (doit[D_RMD160])
  1397. {
  1398. for (j=0; j<SIZE_NUM; j++)
  1399. {
  1400. print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
  1401. Time_F(START);
  1402. for (count=0,run=1; COND(c[D_RMD160][j]); count++)
  1403. EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
  1404. d=Time_F(STOP);
  1405. print_result(D_RMD160,j,count,d);
  1406. }
  1407. }
  1408. #endif
  1409. #ifndef OPENSSL_NO_RC4
  1410. if (doit[D_RC4])
  1411. {
  1412. for (j=0; j<SIZE_NUM; j++)
  1413. {
  1414. print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
  1415. Time_F(START);
  1416. for (count=0,run=1; COND(c[D_RC4][j]); count++)
  1417. RC4(&rc4_ks,(unsigned int)lengths[j],
  1418. buf,buf);
  1419. d=Time_F(STOP);
  1420. print_result(D_RC4,j,count,d);
  1421. }
  1422. }
  1423. #endif
  1424. #ifndef OPENSSL_NO_DES
  1425. if (doit[D_CBC_DES])
  1426. {
  1427. for (j=0; j<SIZE_NUM; j++)
  1428. {
  1429. print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
  1430. Time_F(START);
  1431. for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
  1432. DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
  1433. &DES_iv,DES_ENCRYPT);
  1434. d=Time_F(STOP);
  1435. print_result(D_CBC_DES,j,count,d);
  1436. }
  1437. }
  1438. if (doit[D_EDE3_DES])
  1439. {
  1440. for (j=0; j<SIZE_NUM; j++)
  1441. {
  1442. print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
  1443. Time_F(START);
  1444. for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
  1445. DES_ede3_cbc_encrypt(buf,buf,lengths[j],
  1446. &sch,&sch2,&sch3,
  1447. &DES_iv,DES_ENCRYPT);
  1448. d=Time_F(STOP);
  1449. print_result(D_EDE3_DES,j,count,d);
  1450. }
  1451. }
  1452. #endif
  1453. #ifndef OPENSSL_NO_AES
  1454. if (doit[D_CBC_128_AES])
  1455. {
  1456. for (j=0; j<SIZE_NUM; j++)
  1457. {
  1458. print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
  1459. Time_F(START);
  1460. for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
  1461. AES_cbc_encrypt(buf,buf,
  1462. (unsigned long)lengths[j],&aes_ks1,
  1463. iv,AES_ENCRYPT);
  1464. d=Time_F(STOP);
  1465. print_result(D_CBC_128_AES,j,count,d);
  1466. }
  1467. }
  1468. if (doit[D_CBC_192_AES])
  1469. {
  1470. for (j=0; j<SIZE_NUM; j++)
  1471. {
  1472. print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
  1473. Time_F(START);
  1474. for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
  1475. AES_cbc_encrypt(buf,buf,
  1476. (unsigned long)lengths[j],&aes_ks2,
  1477. iv,AES_ENCRYPT);
  1478. d=Time_F(STOP);
  1479. print_result(D_CBC_192_AES,j,count,d);
  1480. }
  1481. }
  1482. if (doit[D_CBC_256_AES])
  1483. {
  1484. for (j=0; j<SIZE_NUM; j++)
  1485. {
  1486. print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
  1487. Time_F(START);
  1488. for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
  1489. AES_cbc_encrypt(buf,buf,
  1490. (unsigned long)lengths[j],&aes_ks3,
  1491. iv,AES_ENCRYPT);
  1492. d=Time_F(STOP);
  1493. print_result(D_CBC_256_AES,j,count,d);
  1494. }
  1495. }
  1496. #endif
  1497. #ifndef OPENSSL_NO_IDEA
  1498. if (doit[D_CBC_IDEA])
  1499. {
  1500. for (j=0; j<SIZE_NUM; j++)
  1501. {
  1502. print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
  1503. Time_F(START);
  1504. for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
  1505. idea_cbc_encrypt(buf,buf,
  1506. (unsigned long)lengths[j],&idea_ks,
  1507. iv,IDEA_ENCRYPT);
  1508. d=Time_F(STOP);
  1509. print_result(D_CBC_IDEA,j,count,d);
  1510. }
  1511. }
  1512. #endif
  1513. #ifndef OPENSSL_NO_RC2
  1514. if (doit[D_CBC_RC2])
  1515. {
  1516. for (j=0; j<SIZE_NUM; j++)
  1517. {
  1518. print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
  1519. Time_F(START);
  1520. for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
  1521. RC2_cbc_encrypt(buf,buf,
  1522. (unsigned long)lengths[j],&rc2_ks,
  1523. iv,RC2_ENCRYPT);
  1524. d=Time_F(STOP);
  1525. print_result(D_CBC_RC2,j,count,d);
  1526. }
  1527. }
  1528. #endif
  1529. #ifndef OPENSSL_NO_RC5
  1530. if (doit[D_CBC_RC5])
  1531. {
  1532. for (j=0; j<SIZE_NUM; j++)
  1533. {
  1534. print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
  1535. Time_F(START);
  1536. for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
  1537. RC5_32_cbc_encrypt(buf,buf,
  1538. (unsigned long)lengths[j],&rc5_ks,
  1539. iv,RC5_ENCRYPT);
  1540. d=Time_F(STOP);
  1541. print_result(D_CBC_RC5,j,count,d);
  1542. }
  1543. }
  1544. #endif
  1545. #ifndef OPENSSL_NO_BF
  1546. if (doit[D_CBC_BF])
  1547. {
  1548. for (j=0; j<SIZE_NUM; j++)
  1549. {
  1550. print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
  1551. Time_F(START);
  1552. for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
  1553. BF_cbc_encrypt(buf,buf,
  1554. (unsigned long)lengths[j],&bf_ks,
  1555. iv,BF_ENCRYPT);
  1556. d=Time_F(STOP);
  1557. print_result(D_CBC_BF,j,count,d);
  1558. }
  1559. }
  1560. #endif
  1561. #ifndef OPENSSL_NO_CAST
  1562. if (doit[D_CBC_CAST])
  1563. {
  1564. for (j=0; j<SIZE_NUM; j++)
  1565. {
  1566. print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
  1567. Time_F(START);
  1568. for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
  1569. CAST_cbc_encrypt(buf,buf,
  1570. (unsigned long)lengths[j],&cast_ks,
  1571. iv,CAST_ENCRYPT);
  1572. d=Time_F(STOP);
  1573. print_result(D_CBC_CAST,j,count,d);
  1574. }
  1575. }
  1576. #endif
  1577. if (doit[D_EVP])
  1578. {
  1579. for (j=0; j<SIZE_NUM; j++)
  1580. {
  1581. if (evp_cipher)
  1582. {
  1583. EVP_CIPHER_CTX ctx;
  1584. int outl;
  1585. names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
  1586. /* -O3 -fschedule-insns messes up an
  1587. * optimization here! names[D_EVP]
  1588. * somehow becomes NULL */
  1589. print_message(names[D_EVP],save_count,
  1590. lengths[j]);
  1591. EVP_CIPHER_CTX_init(&ctx);
  1592. if(decrypt)
  1593. EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
  1594. else
  1595. EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
  1596. EVP_CIPHER_CTX_set_padding(&ctx, 0);
  1597. Time_F(START);
  1598. if(decrypt)
  1599. for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
  1600. EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
  1601. else
  1602. for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
  1603. EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
  1604. if(decrypt)
  1605. EVP_DecryptFinal_ex(&ctx,buf,&outl);
  1606. else
  1607. EVP_EncryptFinal_ex(&ctx,buf,&outl);
  1608. d=Time_F(STOP);
  1609. EVP_CIPHER_CTX_cleanup(&ctx);
  1610. }
  1611. if (evp_md)
  1612. {
  1613. names[D_EVP]=OBJ_nid2ln(evp_md->type);
  1614. print_message(names[D_EVP],save_count,
  1615. lengths[j]);
  1616. Time_F(START);
  1617. for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
  1618. EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
  1619. d=Time_F(STOP);
  1620. }
  1621. print_result(D_EVP,j,count,d);
  1622. }
  1623. }
  1624. RAND_pseudo_bytes(buf,36);
  1625. #ifndef OPENSSL_NO_RSA
  1626. for (j=0; j<RSA_NUM; j++)
  1627. {
  1628. int ret;
  1629. if (!rsa_doit[j]) continue;
  1630. ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
  1631. if (ret == 0)
  1632. {
  1633. BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
  1634. ERR_print_errors(bio_err);
  1635. rsa_count=1;
  1636. }
  1637. else
  1638. {
  1639. pkey_print_message("private","rsa",
  1640. rsa_c[j][0],rsa_bits[j],
  1641. RSA_SECONDS);
  1642. /* RSA_blinding_on(rsa_key[j],NULL); */
  1643. Time_F(START);
  1644. for (count=0,run=1; COND(rsa_c[j][0]); count++)
  1645. {
  1646. ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
  1647. &rsa_num, rsa_key[j]);
  1648. if (ret == 0)
  1649. {
  1650. BIO_printf(bio_err,
  1651. "RSA sign failure\n");
  1652. ERR_print_errors(bio_err);
  1653. count=1;
  1654. break;
  1655. }
  1656. }
  1657. d=Time_F(STOP);
  1658. BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
  1659. : "%ld %d bit private RSA's in %.2fs\n",
  1660. count,rsa_bits[j],d);
  1661. rsa_results[j][0]=d/(double)count;
  1662. rsa_count=count;
  1663. }
  1664. #if 1
  1665. ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
  1666. if (ret <= 0)
  1667. {
  1668. BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
  1669. ERR_print_errors(bio_err);
  1670. rsa_doit[j] = 0;
  1671. }
  1672. else
  1673. {
  1674. pkey_print_message("public","rsa",
  1675. rsa_c[j][1],rsa_bits[j],
  1676. RSA_SECONDS);
  1677. Time_F(START);
  1678. for (count=0,run=1; COND(rsa_c[j][1]); count++)
  1679. {
  1680. ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
  1681. rsa_num, rsa_key[j]);
  1682. if (ret == 0)
  1683. {
  1684. BIO_printf(bio_err,
  1685. "RSA verify failure\n");
  1686. ERR_print_errors(bio_err);
  1687. count=1;
  1688. break;
  1689. }
  1690. }
  1691. d=Time_F(STOP);
  1692. BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
  1693. : "%ld %d bit public RSA's in %.2fs\n",
  1694. count,rsa_bits[j],d);
  1695. rsa_results[j][1]=d/(double)count;
  1696. }
  1697. #endif
  1698. if (rsa_count <= 1)
  1699. {
  1700. /* if longer than 10s, don't do any more */
  1701. for (j++; j<RSA_NUM; j++)
  1702. rsa_doit[j]=0;
  1703. }
  1704. }
  1705. #endif
  1706. RAND_pseudo_bytes(buf,20);
  1707. #ifndef OPENSSL_NO_DSA
  1708. if (RAND_status() != 1)
  1709. {
  1710. RAND_seed(rnd_seed, sizeof rnd_seed);
  1711. rnd_fake = 1;
  1712. }
  1713. for (j=0; j<DSA_NUM; j++)
  1714. {
  1715. unsigned int kk;
  1716. int ret;
  1717. if (!dsa_doit[j]) continue;
  1718. /* DSA_generate_key(dsa_key[j]); */
  1719. /* DSA_sign_setup(dsa_key[j],NULL); */
  1720. ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
  1721. &kk,dsa_key[j]);
  1722. if (ret == 0)
  1723. {
  1724. BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
  1725. ERR_print_errors(bio_err);
  1726. rsa_count=1;
  1727. }
  1728. else
  1729. {
  1730. pkey_print_message("sign","dsa",
  1731. dsa_c[j][0],dsa_bits[j],
  1732. DSA_SECONDS);
  1733. Time_F(START);
  1734. for (count=0,run=1; COND(dsa_c[j][0]); count++)
  1735. {
  1736. ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
  1737. &kk,dsa_key[j]);
  1738. if (ret == 0)
  1739. {
  1740. BIO_printf(bio_err,
  1741. "DSA sign failure\n");
  1742. ERR_print_errors(bio_err);
  1743. count=1;
  1744. break;
  1745. }
  1746. }
  1747. d=Time_F(STOP);
  1748. BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
  1749. : "%ld %d bit DSA signs in %.2fs\n",
  1750. count,dsa_bits[j],d);
  1751. dsa_results[j][0]=d/(double)count;
  1752. rsa_count=count;
  1753. }
  1754. ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
  1755. kk,dsa_key[j]);
  1756. if (ret <= 0)
  1757. {
  1758. BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
  1759. ERR_print_errors(bio_err);
  1760. dsa_doit[j] = 0;
  1761. }
  1762. else
  1763. {
  1764. pkey_print_message("verify","dsa",
  1765. dsa_c[j][1],dsa_bits[j],
  1766. DSA_SECONDS);
  1767. Time_F(START);
  1768. for (count=0,run=1; COND(dsa_c[j][1]); count++)
  1769. {
  1770. ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
  1771. kk,dsa_key[j]);
  1772. if (ret <= 0)
  1773. {
  1774. BIO_printf(bio_err,
  1775. "DSA verify failure\n");
  1776. ERR_print_errors(bio_err);
  1777. count=1;
  1778. break;
  1779. }
  1780. }
  1781. d=Time_F(STOP);
  1782. BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
  1783. : "%ld %d bit DSA verify in %.2fs\n",
  1784. count,dsa_bits[j],d);
  1785. dsa_results[j][1]=d/(double)count;
  1786. }
  1787. if (rsa_count <= 1)
  1788. {
  1789. /* if longer than 10s, don't do any more */
  1790. for (j++; j<DSA_NUM; j++)
  1791. dsa_doit[j]=0;
  1792. }
  1793. }
  1794. if (rnd_fake) RAND_cleanup();
  1795. #endif
  1796. #ifndef OPENSSL_NO_ECDSA
  1797. if (RAND_status() != 1)
  1798. {
  1799. RAND_seed(rnd_seed, sizeof rnd_seed);
  1800. rnd_fake = 1;
  1801. }
  1802. for (j=0; j<EC_NUM; j++)
  1803. {
  1804. int ret;
  1805. if (!ecdsa_doit[j]) continue; /* Ignore Curve */
  1806. ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
  1807. if (ecdsa[j] == NULL)
  1808. {
  1809. BIO_printf(bio_err,"ECDSA failure.\n");
  1810. ERR_print_errors(bio_err);
  1811. rsa_count=1;
  1812. }
  1813. else
  1814. {
  1815. #if 1
  1816. EC_KEY_precompute_mult(ecdsa[j], NULL);
  1817. #endif
  1818. /* Perform ECDSA signature test */
  1819. EC_KEY_generate_key(ecdsa[j]);
  1820. ret = ECDSA_sign(0, buf, 20, ecdsasig,
  1821. &ecdsasiglen, ecdsa[j]);
  1822. if (ret == 0)
  1823. {
  1824. BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
  1825. ERR_print_errors(bio_err);
  1826. rsa_count=1;
  1827. }
  1828. else
  1829. {
  1830. pkey_print_message("sign","ecdsa",
  1831. ecdsa_c[j][0],
  1832. test_curves_bits[j],
  1833. ECDSA_SECONDS);
  1834. Time_F(START);
  1835. for (count=0,run=1; COND(ecdsa_c[j][0]);
  1836. count++)
  1837. {
  1838. ret=ECDSA_sign(0, buf, 20,
  1839. ecdsasig, &ecdsasiglen,
  1840. ecdsa[j]);
  1841. if (ret == 0)
  1842. {
  1843. BIO_printf(bio_err, "ECDSA sign failure\n");
  1844. ERR_print_errors(bio_err);
  1845. count=1;
  1846. break;
  1847. }
  1848. }
  1849. d=Time_F(STOP);
  1850. BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
  1851. "%ld %d bit ECDSA signs in %.2fs \n",
  1852. count, test_curves_bits[j], d);
  1853. ecdsa_results[j][0]=d/(double)count;
  1854. rsa_count=count;
  1855. }
  1856. /* Perform ECDSA verification test */
  1857. ret=ECDSA_verify(0, buf, 20, ecdsasig,
  1858. ecdsasiglen, ecdsa[j]);
  1859. if (ret != 1)
  1860. {
  1861. BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
  1862. ERR_print_errors(bio_err);
  1863. ecdsa_doit[j] = 0;
  1864. }
  1865. else
  1866. {
  1867. pkey_print_message("verify","ecdsa",
  1868. ecdsa_c[j][1],
  1869. test_curves_bits[j],
  1870. ECDSA_SECONDS);
  1871. Time_F(START);
  1872. for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
  1873. {
  1874. ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
  1875. if (ret != 1)
  1876. {
  1877. BIO_printf(bio_err, "ECDSA verify failure\n");
  1878. ERR_print_errors(bio_err);
  1879. count=1;
  1880. break;
  1881. }
  1882. }
  1883. d=Time_F(STOP);
  1884. BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
  1885. : "%ld %d bit ECDSA verify in %.2fs\n",
  1886. count, test_curves_bits[j], d);
  1887. ecdsa_results[j][1]=d/(double)count;
  1888. }
  1889. if (rsa_count <= 1)
  1890. {
  1891. /* if longer than 10s, don't do any more */
  1892. for (j++; j<EC_NUM; j++)
  1893. ecdsa_doit[j]=0;
  1894. }
  1895. }
  1896. }
  1897. if (rnd_fake) RAND_cleanup();
  1898. #endif
  1899. #ifndef OPENSSL_NO_ECDH
  1900. if (RAND_status() != 1)
  1901. {
  1902. RAND_seed(rnd_seed, sizeof rnd_seed);
  1903. rnd_fake = 1;
  1904. }
  1905. for (j=0; j<EC_NUM; j++)
  1906. {
  1907. if (!ecdh_doit[j]) continue;
  1908. ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
  1909. ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
  1910. if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
  1911. {
  1912. BIO_printf(bio_err,"ECDH failure.\n");
  1913. ERR_print_errors(bio_err);
  1914. rsa_count=1;
  1915. }
  1916. else
  1917. {
  1918. /* generate two ECDH key pairs */
  1919. if (!EC_KEY_generate_key(ecdh_a[j]) ||
  1920. !EC_KEY_generate_key(ecdh_b[j]))
  1921. {
  1922. BIO_printf(bio_err,"ECDH key generation failure.\n");
  1923. ERR_print_errors(bio_err);
  1924. rsa_count=1;
  1925. }
  1926. else
  1927. {
  1928. /* If field size is not more than 24 octets, then use SHA-1 hash of result;
  1929. * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
  1930. */
  1931. int field_size, outlen;
  1932. void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
  1933. field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
  1934. if (field_size <= 24 * 8)
  1935. {
  1936. outlen = KDF1_SHA1_len;
  1937. kdf = KDF1_SHA1;
  1938. }
  1939. else
  1940. {
  1941. outlen = (field_size+7)/8;
  1942. kdf = NULL;
  1943. }
  1944. secret_size_a = ECDH_compute_key(secret_a, outlen,
  1945. EC_KEY_get0_public_key(ecdh_b[j]),
  1946. ecdh_a[j], kdf);
  1947. secret_size_b = ECDH_compute_key(secret_b, outlen,
  1948. EC_KEY_get0_public_key(ecdh_a[j]),
  1949. ecdh_b[j], kdf);
  1950. if (secret_size_a != secret_size_b)
  1951. ecdh_checks = 0;
  1952. else
  1953. ecdh_checks = 1;
  1954. for (secret_idx = 0;
  1955. (secret_idx < secret_size_a)
  1956. && (ecdh_checks == 1);
  1957. secret_idx++)
  1958. {
  1959. if (secret_a[secret_idx] != secret_b[secret_idx])
  1960. ecdh_checks = 0;
  1961. }
  1962. if (ecdh_checks == 0)
  1963. {
  1964. BIO_printf(bio_err,"ECDH computations don't match.\n");
  1965. ERR_print_errors(bio_err);
  1966. rsa_count=1;
  1967. }
  1968. pkey_print_message("","ecdh",
  1969. ecdh_c[j][0],
  1970. test_curves_bits[j],
  1971. ECDH_SECONDS);
  1972. Time_F(START);
  1973. for (count=0,run=1; COND(ecdh_c[j][0]); count++)
  1974. {
  1975. ECDH_compute_key(secret_a, outlen,
  1976. EC_KEY_get0_public_key(ecdh_b[j]),
  1977. ecdh_a[j], kdf);
  1978. }
  1979. d=Time_F(STOP);
  1980. BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
  1981. count, test_curves_bits[j], d);
  1982. ecdh_results[j][0]=d/(double)count;
  1983. rsa_count=count;
  1984. }
  1985. }
  1986. if (rsa_count <= 1)
  1987. {
  1988. /* if longer than 10s, don't do any more */
  1989. for (j++; j<EC_NUM; j++)
  1990. ecdh_doit[j]=0;
  1991. }
  1992. }
  1993. if (rnd_fake) RAND_cleanup();
  1994. #endif
  1995. #ifdef HAVE_FORK
  1996. show_res:
  1997. #endif
  1998. if(!mr)
  1999. {
  2000. fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
  2001. fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
  2002. printf("options:");
  2003. printf("%s ",BN_options());
  2004. #ifndef OPENSSL_NO_MD2
  2005. printf("%s ",MD2_options());
  2006. #endif
  2007. #ifndef OPENSSL_NO_RC4
  2008. printf("%s ",RC4_options());
  2009. #endif
  2010. #ifndef OPENSSL_NO_DES
  2011. printf("%s ",DES_options());
  2012. #endif
  2013. #ifndef OPENSSL_NO_AES
  2014. printf("%s ",AES_options());
  2015. #endif
  2016. #ifndef OPENSSL_NO_IDEA
  2017. printf("%s ",idea_options());
  2018. #endif
  2019. #ifndef OPENSSL_NO_BF
  2020. printf("%s ",BF_options());
  2021. #endif
  2022. fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
  2023. }
  2024. if (pr_header)
  2025. {
  2026. if(mr)
  2027. fprintf(stdout,"+H");
  2028. else
  2029. {
  2030. fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
  2031. fprintf(stdout,"type ");
  2032. }
  2033. for (j=0; j<SIZE_NUM; j++)
  2034. fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
  2035. fprintf(stdout,"\n");
  2036. }
  2037. for (k=0; k<ALGOR_NUM; k++)
  2038. {
  2039. if (!doit[k]) continue;
  2040. if(mr)
  2041. fprintf(stdout,"+F:%d:%s",k,names[k]);
  2042. else
  2043. fprintf(stdout,"%-13s",names[k]);
  2044. for (j=0; j<SIZE_NUM; j++)
  2045. {
  2046. if (results[k][j] > 10000 && !mr)
  2047. fprintf(stdout," %11.2fk",results[k][j]/1e3);
  2048. else
  2049. fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
  2050. }
  2051. fprintf(stdout,"\n");
  2052. }
  2053. #ifndef OPENSSL_NO_RSA
  2054. j=1;
  2055. for (k=0; k<RSA_NUM; k++)
  2056. {
  2057. if (!rsa_doit[k]) continue;
  2058. if (j && !mr)
  2059. {
  2060. printf("%18ssign verify sign/s verify/s\n"," ");
  2061. j=0;
  2062. }
  2063. if(mr)
  2064. fprintf(stdout,"+F2:%u:%u:%f:%f\n",
  2065. k,rsa_bits[k],rsa_results[k][0],
  2066. rsa_results[k][1]);
  2067. else
  2068. fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
  2069. rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
  2070. 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
  2071. }
  2072. #endif
  2073. #ifndef OPENSSL_NO_DSA
  2074. j=1;
  2075. for (k=0; k<DSA_NUM; k++)
  2076. {
  2077. if (!dsa_doit[k]) continue;
  2078. if (j && !mr)
  2079. {
  2080. printf("%18ssign verify sign/s verify/s\n"," ");
  2081. j=0;
  2082. }
  2083. if(mr)
  2084. fprintf(stdout,"+F3:%u:%u:%f:%f\n",
  2085. k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
  2086. else
  2087. fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
  2088. dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
  2089. 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
  2090. }
  2091. #endif
  2092. #ifndef OPENSSL_NO_ECDSA
  2093. j=1;
  2094. for (k=0; k<EC_NUM; k++)
  2095. {
  2096. if (!ecdsa_doit[k]) continue;
  2097. if (j && !mr)
  2098. {
  2099. printf("%30ssign verify sign/s verify/s\n"," ");
  2100. j=0;
  2101. }
  2102. if (mr)
  2103. fprintf(stdout,"+F4:%u:%u:%f:%f\n",
  2104. k, test_curves_bits[k],
  2105. ecdsa_results[k][0],ecdsa_results[k][1]);
  2106. else
  2107. fprintf(stdout,
  2108. "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
  2109. test_curves_bits[k],
  2110. test_curves_names[k],
  2111. ecdsa_results[k][0],ecdsa_results[k][1],
  2112. 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
  2113. }
  2114. #endif
  2115. #ifndef OPENSSL_NO_ECDH
  2116. j=1;
  2117. for (k=0; k<EC_NUM; k++)
  2118. {
  2119. if (!ecdh_doit[k]) continue;
  2120. if (j && !mr)
  2121. {
  2122. printf("%30sop op/s\n"," ");
  2123. j=0;
  2124. }
  2125. if (mr)
  2126. fprintf(stdout,"+F5:%u:%u:%f:%f\n",
  2127. k, test_curves_bits[k],
  2128. ecdh_results[k][0], 1.0/ecdh_results[k][0]);
  2129. else
  2130. fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
  2131. test_curves_bits[k],
  2132. test_curves_names[k],
  2133. ecdh_results[k][0], 1.0/ecdh_results[k][0]);
  2134. }
  2135. #endif
  2136. mret=0;
  2137. end:
  2138. ERR_print_errors(bio_err);
  2139. if (buf != NULL) OPENSSL_free(buf);
  2140. if (buf2 != NULL) OPENSSL_free(buf2);
  2141. #ifndef OPENSSL_NO_RSA
  2142. for (i=0; i<RSA_NUM; i++)
  2143. if (rsa_key[i] != NULL)
  2144. RSA_free(rsa_key[i]);
  2145. #endif
  2146. #ifndef OPENSSL_NO_DSA
  2147. for (i=0; i<DSA_NUM; i++)
  2148. if (dsa_key[i] != NULL)
  2149. DSA_free(dsa_key[i]);
  2150. #endif
  2151. #ifndef OPENSSL_NO_ECDSA
  2152. for (i=0; i<EC_NUM; i++)
  2153. if (ecdsa[i] != NULL)
  2154. EC_KEY_free(ecdsa[i]);
  2155. #endif
  2156. #ifndef OPENSSL_NO_ECDH
  2157. for (i=0; i<EC_NUM; i++)
  2158. {
  2159. if (ecdh_a[i] != NULL)
  2160. EC_KEY_free(ecdh_a[i]);
  2161. if (ecdh_b[i] != NULL)
  2162. EC_KEY_free(ecdh_b[i]);
  2163. }
  2164. #endif
  2165. apps_shutdown();
  2166. OPENSSL_EXIT(mret);
  2167. }
  2168. static void print_message(const char *s, long num, int length)
  2169. {
  2170. #ifdef SIGALRM
  2171. BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
  2172. : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
  2173. (void)BIO_flush(bio_err);
  2174. alarm(SECONDS);
  2175. #else
  2176. BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
  2177. : "Doing %s %ld times on %d size blocks: ",s,num,length);
  2178. (void)BIO_flush(bio_err);
  2179. #endif
  2180. #ifdef LINT
  2181. num=num;
  2182. #endif
  2183. }
  2184. static void pkey_print_message(const char *str, const char *str2, long num,
  2185. int bits, int tm)
  2186. {
  2187. #ifdef SIGALRM
  2188. BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
  2189. : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
  2190. (void)BIO_flush(bio_err);
  2191. alarm(RSA_SECONDS);
  2192. #else
  2193. BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
  2194. : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
  2195. (void)BIO_flush(bio_err);
  2196. #endif
  2197. #ifdef LINT
  2198. num=num;
  2199. #endif
  2200. }
  2201. static void print_result(int alg,int run_no,int count,double time_used)
  2202. {
  2203. BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
  2204. : "%d %s's in %.2fs\n",count,names[alg],time_used);
  2205. results[alg][run_no]=((double)count)/time_used*lengths[run_no];
  2206. }
  2207. #ifdef HAVE_FORK
  2208. static char *sstrsep(char **string, const char *delim)
  2209. {
  2210. char isdelim[256];
  2211. char *token = *string;
  2212. if (**string == 0)
  2213. return NULL;
  2214. memset(isdelim, 0, sizeof isdelim);
  2215. isdelim[0] = 1;
  2216. while (*delim)
  2217. {
  2218. isdelim[(unsigned char)(*delim)] = 1;
  2219. delim++;
  2220. }
  2221. while (!isdelim[(unsigned char)(**string)])
  2222. {
  2223. (*string)++;
  2224. }
  2225. if (**string)
  2226. {
  2227. **string = 0;
  2228. (*string)++;
  2229. }
  2230. return token;
  2231. }
  2232. static int do_multi(int multi)
  2233. {
  2234. int n;
  2235. int fd[2];
  2236. int *fds;
  2237. static char sep[]=":";
  2238. fds=malloc(multi*sizeof *fds);
  2239. for(n=0 ; n < multi ; ++n)
  2240. {
  2241. pipe(fd);
  2242. if(fork())
  2243. {
  2244. close(fd[1]);
  2245. fds[n]=fd[0];
  2246. }
  2247. else
  2248. {
  2249. close(fd[0]);
  2250. close(1);
  2251. dup(fd[1]);
  2252. close(fd[1]);
  2253. mr=1;
  2254. usertime=0;
  2255. return 0;
  2256. }
  2257. printf("Forked child %d\n",n);
  2258. }
  2259. /* for now, assume the pipe is long enough to take all the output */
  2260. for(n=0 ; n < multi ; ++n)
  2261. {
  2262. FILE *f;
  2263. char buf[1024];
  2264. char *p;
  2265. f=fdopen(fds[n],"r");
  2266. while(fgets(buf,sizeof buf,f))
  2267. {
  2268. p=strchr(buf,'\n');
  2269. if(p)
  2270. *p='\0';
  2271. if(buf[0] != '+')
  2272. {
  2273. fprintf(stderr,"Don't understand line '%s' from child %d\n",
  2274. buf,n);
  2275. continue;
  2276. }
  2277. printf("Got: %s from %d\n",buf,n);
  2278. if(!strncmp(buf,"+F:",3))
  2279. {
  2280. int alg;
  2281. int j;
  2282. p=buf+3;
  2283. alg=atoi(sstrsep(&p,sep));
  2284. sstrsep(&p,sep);
  2285. for(j=0 ; j < SIZE_NUM ; ++j)
  2286. results[alg][j]+=atof(sstrsep(&p,sep));
  2287. }
  2288. else if(!strncmp(buf,"+F2:",4))
  2289. {
  2290. int k;
  2291. double d;
  2292. p=buf+4;
  2293. k=atoi(sstrsep(&p,sep));
  2294. sstrsep(&p,sep);
  2295. d=atof(sstrsep(&p,sep));
  2296. if(n)
  2297. rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
  2298. else
  2299. rsa_results[k][0]=d;
  2300. d=atof(sstrsep(&p,sep));
  2301. if(n)
  2302. rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
  2303. else
  2304. rsa_results[k][1]=d;
  2305. }
  2306. else if(!strncmp(buf,"+F2:",4))
  2307. {
  2308. int k;
  2309. double d;
  2310. p=buf+4;
  2311. k=atoi(sstrsep(&p,sep));
  2312. sstrsep(&p,sep);
  2313. d=atof(sstrsep(&p,sep));
  2314. if(n)
  2315. rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
  2316. else
  2317. rsa_results[k][0]=d;
  2318. d=atof(sstrsep(&p,sep));
  2319. if(n)
  2320. rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
  2321. else
  2322. rsa_results[k][1]=d;
  2323. }
  2324. else if(!strncmp(buf,"+F3:",4))
  2325. {
  2326. int k;
  2327. double d;
  2328. p=buf+4;
  2329. k=atoi(sstrsep(&p,sep));
  2330. sstrsep(&p,sep);
  2331. d=atof(sstrsep(&p,sep));
  2332. if(n)
  2333. dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
  2334. else
  2335. dsa_results[k][0]=d;
  2336. d=atof(sstrsep(&p,sep));
  2337. if(n)
  2338. dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
  2339. else
  2340. dsa_results[k][1]=d;
  2341. }
  2342. #ifndef OPENSSL_NO_ECDSA
  2343. else if(!strncmp(buf,"+F4:",4))
  2344. {
  2345. int k;
  2346. double d;
  2347. p=buf+4;
  2348. k=atoi(sstrsep(&p,sep));
  2349. sstrsep(&p,sep);
  2350. d=atof(sstrsep(&p,sep));
  2351. if(n)
  2352. ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
  2353. else
  2354. ecdsa_results[k][0]=d;
  2355. d=atof(sstrsep(&p,sep));
  2356. if(n)
  2357. ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
  2358. else
  2359. ecdsa_results[k][1]=d;
  2360. }
  2361. #endif
  2362. #ifndef OPENSSL_NO_ECDH
  2363. else if(!strncmp(buf,"+F5:",4))
  2364. {
  2365. int k;
  2366. double d;
  2367. p=buf+4;
  2368. k=atoi(sstrsep(&p,sep));
  2369. sstrsep(&p,sep);
  2370. d=atof(sstrsep(&p,sep));
  2371. if(n)
  2372. ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
  2373. else
  2374. ecdh_results[k][0]=d;
  2375. }
  2376. #endif
  2377. else if(!strncmp(buf,"+H:",3))
  2378. {
  2379. }
  2380. else
  2381. fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
  2382. }
  2383. }
  2384. return 1;
  2385. }
  2386. #endif
  2387. #endif