speed.c 91 KB

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