ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/src/vendor-crypto/openssl/dist/apps/speed.c
Revision: 6976
Committed: Fri Mar 20 00:01:13 2015 UTC (9 years, 1 month ago) by laffer1
Content type: text/plain
File size: 91877 byte(s)
Log Message:
openssl-0.9.8zf

File Contents

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