speed.c 66 KB

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