speed.c 66 KB

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