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