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