speed.c 86 KB

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