speed.c 67 KB

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