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