speed.c 90 KB

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