speed.c 67 KB

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