speed.c 66 KB

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