speed.c 91 KB

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