speed.c 91 KB

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