Sync usage with man page.
[netbsd-mini2440.git] / crypto / external / bsd / openssl / dist / apps / speed.c
blob5b6450393db77be7938bcceb52e4329ac5ccfe1a
1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
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).
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.
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)"
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.
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.]
58 /* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
67 * The ECDH and ECDSA speed test software is originally written by
68 * Sumit Gupta of Sun Microsystems Laboratories.
72 /* most of this code has been pilfered from my libdes speed.c program */
74 #ifndef OPENSSL_NO_SPEED
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
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 */
86 #undef PROG
87 #define PROG speed_main
89 #include <stdio.h>
90 #include <stdlib.h>
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 <unistd.h>
105 #endif
107 #ifndef OPENSSL_SYS_NETWARE
108 #include <signal.h>
109 #endif
111 #ifdef _WIN32
112 #include <windows.h>
113 #endif
115 #include <openssl/bn.h>
116 #ifndef OPENSSL_NO_DES
117 #include <openssl/des.h>
118 #endif
119 #ifndef OPENSSL_NO_AES
120 #include <openssl/aes.h>
121 #endif
122 #ifndef OPENSSL_NO_CAMELLIA
123 #include <openssl/camellia.h>
124 #endif
125 #ifndef OPENSSL_NO_MD2
126 #include <openssl/md2.h>
127 #endif
128 #ifndef OPENSSL_NO_MDC2
129 #include <openssl/mdc2.h>
130 #endif
131 #ifndef OPENSSL_NO_MD4
132 #include <openssl/md4.h>
133 #endif
134 #ifndef OPENSSL_NO_MD5
135 #include <openssl/md5.h>
136 #endif
137 #ifndef OPENSSL_NO_HMAC
138 #include <openssl/hmac.h>
139 #endif
140 #include <openssl/evp.h>
141 #ifndef OPENSSL_NO_SHA
142 #include <openssl/sha.h>
143 #endif
144 #ifndef OPENSSL_NO_RIPEMD
145 #include <openssl/ripemd.h>
146 #endif
147 #ifndef OPENSSL_NO_WHIRLPOOL
148 #include <openssl/whrlpool.h>
149 #endif
150 #ifndef OPENSSL_NO_RC4
151 #include <openssl/rc4.h>
152 #endif
153 #ifndef OPENSSL_NO_RC5
154 #include <openssl/rc5.h>
155 #endif
156 #ifndef OPENSSL_NO_RC2
157 #include <openssl/rc2.h>
158 #endif
159 #ifndef OPENSSL_NO_IDEA
160 #include <openssl/idea.h>
161 #endif
162 #ifndef OPENSSL_NO_SEED
163 #include <openssl/seed.h>
164 #endif
165 #ifndef OPENSSL_NO_BF
166 #include <openssl/blowfish.h>
167 #endif
168 #ifndef OPENSSL_NO_CAST
169 #include <openssl/cast.h>
170 #endif
171 #ifndef OPENSSL_NO_RSA
172 #include <openssl/rsa.h>
173 #include "./testrsa.h"
174 #endif
175 #include <openssl/x509.h>
176 #ifndef OPENSSL_NO_DSA
177 #include <openssl/dsa.h>
178 #include "./testdsa.h"
179 #endif
180 #ifndef OPENSSL_NO_ECDSA
181 #include <openssl/ecdsa.h>
182 #endif
183 #ifndef OPENSSL_NO_ECDH
184 #include <openssl/ecdh.h>
185 #endif
187 #if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
188 # define NO_FORK 1
189 #elif HAVE_FORK
190 # undef NO_FORK
191 #else
192 # define NO_FORK 1
193 #endif
195 #undef BUFSIZE
196 #define BUFSIZE ((long)1024*8+1)
197 int run=0;
199 static int mr=0;
200 static int usertime=1;
202 static double Time_F(int s);
203 static void print_message(const char *s,long num,int length);
204 static void pkey_print_message(const char *str, const char *str2,
205 long num, int bits, int sec);
206 static void print_result(int alg,int run_no,int count,double time_used);
207 #ifndef NO_FORK
208 static int do_multi(int multi);
209 #endif
211 #define ALGOR_NUM 29
212 #define SIZE_NUM 5
213 #define RSA_NUM 4
214 #define DSA_NUM 3
216 #define EC_NUM 16
217 #define MAX_ECDH_SIZE 256
219 static const char *names[ALGOR_NUM]={
220 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
221 "des cbc","des ede3","idea cbc","seed cbc",
222 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
223 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
224 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
225 "evp","sha256","sha512","whirlpool",
226 "aes-128 ige","aes-192 ige","aes-256 ige"};
227 static double results[ALGOR_NUM][SIZE_NUM];
228 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
229 static double rsa_results[RSA_NUM][2];
230 static double dsa_results[DSA_NUM][2];
231 #ifndef OPENSSL_NO_ECDSA
232 static double ecdsa_results[EC_NUM][2];
233 #endif
234 #ifndef OPENSSL_NO_ECDH
235 static double ecdh_results[EC_NUM][1];
236 #endif
238 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
239 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
240 static int rnd_fake = 0;
241 #endif
243 #ifdef SIGALRM
244 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
245 #define SIGRETTYPE void
246 #else
247 #define SIGRETTYPE int
248 #endif
250 static SIGRETTYPE sig_done(int sig);
251 static SIGRETTYPE sig_done(int sig)
253 signal(SIGALRM,sig_done);
254 run=0;
255 #ifdef LINT
256 sig=sig;
257 #endif
259 #endif
261 #define START 0
262 #define STOP 1
264 #if defined(_WIN32)
266 #define SIGALRM
267 static unsigned int lapse,schlock;
268 static void alarm(unsigned int secs) { lapse = secs*1000; }
270 static DWORD WINAPI sleepy(VOID *arg)
272 schlock = 1;
273 Sleep(lapse);
274 run = 0;
275 return 0;
278 static double Time_F(int s)
280 if (s == START)
282 HANDLE thr;
283 schlock = 0;
284 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
285 if (thr==NULL)
287 DWORD ret=GetLastError();
288 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
289 ExitProcess(ret);
291 CloseHandle(thr); /* detach the thread */
292 while (!schlock) Sleep(0); /* scheduler spinlock */
295 return app_tminterval(s,usertime);
297 #else
299 static double Time_F(int s)
301 return app_tminterval(s,usertime);
303 #endif
306 #ifndef OPENSSL_NO_ECDH
307 static const int KDF1_SHA1_len = 20;
308 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
310 #ifndef OPENSSL_NO_SHA
311 if (*outlen < SHA_DIGEST_LENGTH)
312 return NULL;
313 else
314 *outlen = SHA_DIGEST_LENGTH;
315 return SHA1(in, inlen, out);
316 #else
317 return NULL;
318 #endif /* OPENSSL_NO_SHA */
320 #endif /* OPENSSL_NO_ECDH */
323 int MAIN(int, char **);
325 int MAIN(int argc, char **argv)
327 #ifndef OPENSSL_NO_ENGINE
328 ENGINE *e = NULL;
329 #endif
330 unsigned char *buf=NULL,*buf2=NULL;
331 int mret=1;
332 long count=0,save_count=0;
333 int i,j,k;
334 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
335 long rsa_count;
336 #endif
337 #ifndef OPENSSL_NO_RSA
338 unsigned rsa_num;
339 #endif
340 unsigned char md[EVP_MAX_MD_SIZE];
341 #ifndef OPENSSL_NO_MD2
342 unsigned char md2[MD2_DIGEST_LENGTH];
343 #endif
344 #ifndef OPENSSL_NO_MDC2
345 unsigned char mdc2[MDC2_DIGEST_LENGTH];
346 #endif
347 #ifndef OPENSSL_NO_MD4
348 unsigned char md4[MD4_DIGEST_LENGTH];
349 #endif
350 #ifndef OPENSSL_NO_MD5
351 unsigned char md5[MD5_DIGEST_LENGTH];
352 unsigned char hmac[MD5_DIGEST_LENGTH];
353 #endif
354 #ifndef OPENSSL_NO_SHA
355 unsigned char sha[SHA_DIGEST_LENGTH];
356 #ifndef OPENSSL_NO_SHA256
357 unsigned char sha256[SHA256_DIGEST_LENGTH];
358 #endif
359 #ifndef OPENSSL_NO_SHA512
360 unsigned char sha512[SHA512_DIGEST_LENGTH];
361 #endif
362 #endif
363 #ifndef OPENSSL_NO_WHIRLPOOL
364 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
365 #endif
366 #ifndef OPENSSL_NO_RIPEMD
367 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
368 #endif
369 #ifndef OPENSSL_NO_RC4
370 RC4_KEY rc4_ks;
371 #endif
372 #ifndef OPENSSL_NO_RC5
373 RC5_32_KEY rc5_ks;
374 #endif
375 #ifndef OPENSSL_NO_RC2
376 RC2_KEY rc2_ks;
377 #endif
378 #ifndef OPENSSL_NO_IDEA
379 IDEA_KEY_SCHEDULE idea_ks;
380 #endif
381 #ifndef OPENSSL_NO_SEED
382 SEED_KEY_SCHEDULE seed_ks;
383 #endif
384 #ifndef OPENSSL_NO_BF
385 BF_KEY bf_ks;
386 #endif
387 #ifndef OPENSSL_NO_CAST
388 CAST_KEY cast_ks;
389 #endif
390 static const unsigned char key16[16]=
391 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
392 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
393 #ifndef OPENSSL_NO_AES
394 static const unsigned char key24[24]=
395 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
396 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
397 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
398 static const unsigned char key32[32]=
399 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
400 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
401 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
402 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
403 #endif
404 #ifndef OPENSSL_NO_CAMELLIA
405 static const unsigned char ckey24[24]=
406 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
407 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
408 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
409 static const unsigned char ckey32[32]=
410 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
411 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
412 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
413 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
414 #endif
415 #ifndef OPENSSL_NO_AES
416 #define MAX_BLOCK_SIZE 128
417 #else
418 #define MAX_BLOCK_SIZE 64
419 #endif
420 unsigned char DES_iv[8];
421 unsigned char iv[2*MAX_BLOCK_SIZE/8];
422 #ifndef OPENSSL_NO_DES
423 DES_cblock *buf_as_des_cblock = NULL;
424 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
425 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
426 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
427 DES_key_schedule sch;
428 DES_key_schedule sch2;
429 DES_key_schedule sch3;
430 #endif
431 #ifndef OPENSSL_NO_AES
432 AES_KEY aes_ks1, aes_ks2, aes_ks3;
433 #endif
434 #ifndef OPENSSL_NO_CAMELLIA
435 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
436 #endif
437 #define D_MD2 0
438 #define D_MDC2 1
439 #define D_MD4 2
440 #define D_MD5 3
441 #define D_HMAC 4
442 #define D_SHA1 5
443 #define D_RMD160 6
444 #define D_RC4 7
445 #define D_CBC_DES 8
446 #define D_EDE3_DES 9
447 #define D_CBC_IDEA 10
448 #define D_CBC_SEED 11
449 #define D_CBC_RC2 12
450 #define D_CBC_RC5 13
451 #define D_CBC_BF 14
452 #define D_CBC_CAST 15
453 #define D_CBC_128_AES 16
454 #define D_CBC_192_AES 17
455 #define D_CBC_256_AES 18
456 #define D_CBC_128_CML 19
457 #define D_CBC_192_CML 20
458 #define D_CBC_256_CML 21
459 #define D_EVP 22
460 #define D_SHA256 23
461 #define D_SHA512 24
462 #define D_WHIRLPOOL 25
463 #define D_IGE_128_AES 26
464 #define D_IGE_192_AES 27
465 #define D_IGE_256_AES 28
466 double d=0.0;
467 long c[ALGOR_NUM][SIZE_NUM];
468 #define R_DSA_512 0
469 #define R_DSA_1024 1
470 #define R_DSA_2048 2
471 #define R_RSA_512 0
472 #define R_RSA_1024 1
473 #define R_RSA_2048 2
474 #define R_RSA_4096 3
476 #define R_EC_P160 0
477 #define R_EC_P192 1
478 #define R_EC_P224 2
479 #define R_EC_P256 3
480 #define R_EC_P384 4
481 #define R_EC_P521 5
482 #define R_EC_K163 6
483 #define R_EC_K233 7
484 #define R_EC_K283 8
485 #define R_EC_K409 9
486 #define R_EC_K571 10
487 #define R_EC_B163 11
488 #define R_EC_B233 12
489 #define R_EC_B283 13
490 #define R_EC_B409 14
491 #define R_EC_B571 15
493 #ifndef OPENSSL_NO_RSA
494 RSA *rsa_key[RSA_NUM];
495 long rsa_c[RSA_NUM][2];
496 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
497 static unsigned char *rsa_data[RSA_NUM]=
498 {test512,test1024,test2048,test4096};
499 static int rsa_data_length[RSA_NUM]={
500 sizeof(test512),sizeof(test1024),
501 sizeof(test2048),sizeof(test4096)};
502 #endif
503 #ifndef OPENSSL_NO_DSA
504 DSA *dsa_key[DSA_NUM];
505 long dsa_c[DSA_NUM][2];
506 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
507 #endif
508 #ifndef OPENSSL_NO_EC
509 /* We only test over the following curves as they are representative,
510 * To add tests over more curves, simply add the curve NID
511 * and curve name to the following arrays and increase the
512 * EC_NUM value accordingly.
514 static unsigned int test_curves[EC_NUM] =
516 /* Prime Curves */
517 NID_secp160r1,
518 NID_X9_62_prime192v1,
519 NID_secp224r1,
520 NID_X9_62_prime256v1,
521 NID_secp384r1,
522 NID_secp521r1,
523 /* Binary Curves */
524 NID_sect163k1,
525 NID_sect233k1,
526 NID_sect283k1,
527 NID_sect409k1,
528 NID_sect571k1,
529 NID_sect163r2,
530 NID_sect233r1,
531 NID_sect283r1,
532 NID_sect409r1,
533 NID_sect571r1
535 static const char * test_curves_names[EC_NUM] =
537 /* Prime Curves */
538 "secp160r1",
539 "nistp192",
540 "nistp224",
541 "nistp256",
542 "nistp384",
543 "nistp521",
544 /* Binary Curves */
545 "nistk163",
546 "nistk233",
547 "nistk283",
548 "nistk409",
549 "nistk571",
550 "nistb163",
551 "nistb233",
552 "nistb283",
553 "nistb409",
554 "nistb571"
556 static int test_curves_bits[EC_NUM] =
558 160, 192, 224, 256, 384, 521,
559 163, 233, 283, 409, 571,
560 163, 233, 283, 409, 571
563 #endif
565 #ifndef OPENSSL_NO_ECDSA
566 unsigned char ecdsasig[256];
567 unsigned int ecdsasiglen;
568 EC_KEY *ecdsa[EC_NUM];
569 long ecdsa_c[EC_NUM][2];
570 #endif
572 #ifndef OPENSSL_NO_ECDH
573 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
574 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
575 int secret_size_a, secret_size_b;
576 int ecdh_checks = 0;
577 int secret_idx = 0;
578 long ecdh_c[EC_NUM][2];
579 #endif
581 int rsa_doit[RSA_NUM];
582 int dsa_doit[DSA_NUM];
583 #ifndef OPENSSL_NO_ECDSA
584 int ecdsa_doit[EC_NUM];
585 #endif
586 #ifndef OPENSSL_NO_ECDH
587 int ecdh_doit[EC_NUM];
588 #endif
589 int doit[ALGOR_NUM];
590 int pr_header=0;
591 const EVP_CIPHER *evp_cipher=NULL;
592 const EVP_MD *evp_md=NULL;
593 int decrypt=0;
594 #ifndef NO_FORK
595 int multi=0;
596 #endif
598 #ifndef TIMES
599 usertime=-1;
600 #endif
602 apps_startup();
603 memset(results, 0, sizeof(results));
604 #ifndef OPENSSL_NO_DSA
605 memset(dsa_key,0,sizeof(dsa_key));
606 #endif
607 #ifndef OPENSSL_NO_ECDSA
608 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
609 #endif
610 #ifndef OPENSSL_NO_ECDH
611 for (i=0; i<EC_NUM; i++)
613 ecdh_a[i] = NULL;
614 ecdh_b[i] = NULL;
616 #endif
619 if (bio_err == NULL)
620 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
621 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
623 if (!load_config(bio_err, NULL))
624 goto end;
626 #ifndef OPENSSL_NO_RSA
627 memset(rsa_key,0,sizeof(rsa_key));
628 for (i=0; i<RSA_NUM; i++)
629 rsa_key[i]=NULL;
630 #endif
632 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
634 BIO_printf(bio_err,"out of memory\n");
635 goto end;
637 #ifndef OPENSSL_NO_DES
638 buf_as_des_cblock = (DES_cblock *)buf;
639 #endif
640 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
642 BIO_printf(bio_err,"out of memory\n");
643 goto end;
646 memset(c,0,sizeof(c));
647 memset(DES_iv,0,sizeof(DES_iv));
648 memset(iv,0,sizeof(iv));
650 for (i=0; i<ALGOR_NUM; i++)
651 doit[i]=0;
652 for (i=0; i<RSA_NUM; i++)
653 rsa_doit[i]=0;
654 for (i=0; i<DSA_NUM; i++)
655 dsa_doit[i]=0;
656 #ifndef OPENSSL_NO_ECDSA
657 for (i=0; i<EC_NUM; i++)
658 ecdsa_doit[i]=0;
659 #endif
660 #ifndef OPENSSL_NO_ECDH
661 for (i=0; i<EC_NUM; i++)
662 ecdh_doit[i]=0;
663 #endif
666 j=0;
667 argc--;
668 argv++;
669 while (argc)
671 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
673 usertime = 0;
674 j--; /* Otherwise, -elapsed gets confused with
675 an algorithm. */
677 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
679 argc--;
680 argv++;
681 if(argc == 0)
683 BIO_printf(bio_err,"no EVP given\n");
684 goto end;
686 evp_cipher=EVP_get_cipherbyname(*argv);
687 if(!evp_cipher)
689 evp_md=EVP_get_digestbyname(*argv);
691 if(!evp_cipher && !evp_md)
693 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
694 goto end;
696 doit[D_EVP]=1;
698 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
700 decrypt=1;
701 j--; /* Otherwise, -elapsed gets confused with
702 an algorithm. */
704 #ifndef OPENSSL_NO_ENGINE
705 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
707 argc--;
708 argv++;
709 if(argc == 0)
711 BIO_printf(bio_err,"no engine given\n");
712 goto end;
714 e = setup_engine(bio_err, *argv, 0);
715 /* j will be increased again further down. We just
716 don't want speed to confuse an engine with an
717 algorithm, especially when none is given (which
718 means all of them should be run) */
719 j--;
721 #endif
722 #ifndef NO_FORK
723 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
725 argc--;
726 argv++;
727 if(argc == 0)
729 BIO_printf(bio_err,"no multi count given\n");
730 goto end;
732 multi=atoi(argv[0]);
733 if(multi <= 0)
735 BIO_printf(bio_err,"bad multi count\n");
736 goto end;
738 j--; /* Otherwise, -mr gets confused with
739 an algorithm. */
741 #endif
742 else if (argc > 0 && !strcmp(*argv,"-mr"))
744 mr=1;
745 j--; /* Otherwise, -mr gets confused with
746 an algorithm. */
748 else
749 #ifndef OPENSSL_NO_MD2
750 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
751 else
752 #endif
753 #ifndef OPENSSL_NO_MDC2
754 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
755 else
756 #endif
757 #ifndef OPENSSL_NO_MD4
758 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
759 else
760 #endif
761 #ifndef OPENSSL_NO_MD5
762 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
763 else
764 #endif
765 #ifndef OPENSSL_NO_MD5
766 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
767 else
768 #endif
769 #ifndef OPENSSL_NO_SHA
770 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
771 else
772 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
773 doit[D_SHA256]=1,
774 doit[D_SHA512]=1;
775 else
776 #ifndef OPENSSL_NO_SHA256
777 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
778 else
779 #endif
780 #ifndef OPENSSL_NO_SHA512
781 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
782 else
783 #endif
784 #endif
785 #ifndef OPENSSL_NO_WHIRLPOOL
786 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
787 else
788 #endif
789 #ifndef OPENSSL_NO_RIPEMD
790 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
791 else
792 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
793 else
794 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
795 else
796 #endif
797 #ifndef OPENSSL_NO_RC4
798 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
799 else
800 #endif
801 #ifndef OPENSSL_NO_DES
802 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
803 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
804 else
805 #endif
806 #ifndef OPENSSL_NO_AES
807 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
808 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
809 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
810 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
811 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
812 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
813 else
814 #endif
815 #ifndef OPENSSL_NO_CAMELLIA
816 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
817 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
818 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
819 else
820 #endif
821 #ifndef OPENSSL_NO_RSA
822 #if 0 /* was: #ifdef RSAref */
823 if (strcmp(*argv,"rsaref") == 0)
825 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
826 j--;
828 else
829 #endif
830 #ifndef RSA_NULL
831 if (strcmp(*argv,"openssl") == 0)
833 RSA_set_default_method(RSA_PKCS1_SSLeay());
834 j--;
836 else
837 #endif
838 #endif /* !OPENSSL_NO_RSA */
839 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
840 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
841 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
842 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
843 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
844 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
845 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
846 else
847 #ifndef OPENSSL_NO_RC2
848 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
849 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
850 else
851 #endif
852 #ifndef OPENSSL_NO_RC5
853 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
854 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
855 else
856 #endif
857 #ifndef OPENSSL_NO_IDEA
858 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
859 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
860 else
861 #endif
862 #ifndef OPENSSL_NO_SEED
863 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
864 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
865 else
866 #endif
867 #ifndef OPENSSL_NO_BF
868 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
869 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
870 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
871 else
872 #endif
873 #ifndef OPENSSL_NO_CAST
874 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
875 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
876 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
877 else
878 #endif
879 #ifndef OPENSSL_NO_DES
880 if (strcmp(*argv,"des") == 0)
882 doit[D_CBC_DES]=1;
883 doit[D_EDE3_DES]=1;
885 else
886 #endif
887 #ifndef OPENSSL_NO_AES
888 if (strcmp(*argv,"aes") == 0)
890 doit[D_CBC_128_AES]=1;
891 doit[D_CBC_192_AES]=1;
892 doit[D_CBC_256_AES]=1;
894 else
895 #endif
896 #ifndef OPENSSL_NO_CAMELLIA
897 if (strcmp(*argv,"camellia") == 0)
899 doit[D_CBC_128_CML]=1;
900 doit[D_CBC_192_CML]=1;
901 doit[D_CBC_256_CML]=1;
903 else
904 #endif
905 #ifndef OPENSSL_NO_RSA
906 if (strcmp(*argv,"rsa") == 0)
908 rsa_doit[R_RSA_512]=1;
909 rsa_doit[R_RSA_1024]=1;
910 rsa_doit[R_RSA_2048]=1;
911 rsa_doit[R_RSA_4096]=1;
913 else
914 #endif
915 #ifndef OPENSSL_NO_DSA
916 if (strcmp(*argv,"dsa") == 0)
918 dsa_doit[R_DSA_512]=1;
919 dsa_doit[R_DSA_1024]=1;
920 dsa_doit[R_DSA_2048]=1;
922 else
923 #endif
924 #ifndef OPENSSL_NO_ECDSA
925 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
926 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
927 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
928 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
929 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
930 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
931 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
932 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
933 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
934 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
935 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
936 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
937 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
938 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
939 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
940 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
941 else if (strcmp(*argv,"ecdsa") == 0)
943 for (i=0; i < EC_NUM; i++)
944 ecdsa_doit[i]=1;
946 else
947 #endif
948 #ifndef OPENSSL_NO_ECDH
949 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
950 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
951 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
952 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
953 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
954 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
955 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
956 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
957 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
958 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
959 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
960 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
961 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
962 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
963 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
964 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
965 else if (strcmp(*argv,"ecdh") == 0)
967 for (i=0; i < EC_NUM; i++)
968 ecdh_doit[i]=1;
970 else
971 #endif
973 BIO_printf(bio_err,"Error: bad option or value\n");
974 BIO_printf(bio_err,"\n");
975 BIO_printf(bio_err,"Available values:\n");
976 #ifndef OPENSSL_NO_MD2
977 BIO_printf(bio_err,"md2 ");
978 #endif
979 #ifndef OPENSSL_NO_MDC2
980 BIO_printf(bio_err,"mdc2 ");
981 #endif
982 #ifndef OPENSSL_NO_MD4
983 BIO_printf(bio_err,"md4 ");
984 #endif
985 #ifndef OPENSSL_NO_MD5
986 BIO_printf(bio_err,"md5 ");
987 #ifndef OPENSSL_NO_HMAC
988 BIO_printf(bio_err,"hmac ");
989 #endif
990 #endif
991 #ifndef OPENSSL_NO_SHA1
992 BIO_printf(bio_err,"sha1 ");
993 #endif
994 #ifndef OPENSSL_NO_SHA256
995 BIO_printf(bio_err,"sha256 ");
996 #endif
997 #ifndef OPENSSL_NO_SHA512
998 BIO_printf(bio_err,"sha512 ");
999 #endif
1000 #ifndef OPENSSL_NO_WHIRLPOOL
1001 BIO_printf(bio_err,"whirlpool");
1002 #endif
1003 #ifndef OPENSSL_NO_RIPEMD160
1004 BIO_printf(bio_err,"rmd160");
1005 #endif
1006 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1007 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1008 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1009 !defined(OPENSSL_NO_WHIRLPOOL)
1010 BIO_printf(bio_err,"\n");
1011 #endif
1013 #ifndef OPENSSL_NO_IDEA
1014 BIO_printf(bio_err,"idea-cbc ");
1015 #endif
1016 #ifndef OPENSSL_NO_SEED
1017 BIO_printf(bio_err,"seed-cbc ");
1018 #endif
1019 #ifndef OPENSSL_NO_RC2
1020 BIO_printf(bio_err,"rc2-cbc ");
1021 #endif
1022 #ifndef OPENSSL_NO_RC5
1023 BIO_printf(bio_err,"rc5-cbc ");
1024 #endif
1025 #ifndef OPENSSL_NO_BF
1026 BIO_printf(bio_err,"bf-cbc");
1027 #endif
1028 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1029 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1030 BIO_printf(bio_err,"\n");
1031 #endif
1032 #ifndef OPENSSL_NO_DES
1033 BIO_printf(bio_err,"des-cbc des-ede3 ");
1034 #endif
1035 #ifndef OPENSSL_NO_AES
1036 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1037 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1038 #endif
1039 #ifndef OPENSSL_NO_CAMELLIA
1040 BIO_printf(bio_err,"\n");
1041 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1042 #endif
1043 #ifndef OPENSSL_NO_RC4
1044 BIO_printf(bio_err,"rc4");
1045 #endif
1046 BIO_printf(bio_err,"\n");
1048 #ifndef OPENSSL_NO_RSA
1049 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1050 #endif
1052 #ifndef OPENSSL_NO_DSA
1053 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1054 #endif
1055 #ifndef OPENSSL_NO_ECDSA
1056 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1057 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1058 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1059 BIO_printf(bio_err,"ecdsa\n");
1060 #endif
1061 #ifndef OPENSSL_NO_ECDH
1062 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1063 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1064 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1065 BIO_printf(bio_err,"ecdh\n");
1066 #endif
1068 #ifndef OPENSSL_NO_IDEA
1069 BIO_printf(bio_err,"idea ");
1070 #endif
1071 #ifndef OPENSSL_NO_SEED
1072 BIO_printf(bio_err,"seed ");
1073 #endif
1074 #ifndef OPENSSL_NO_RC2
1075 BIO_printf(bio_err,"rc2 ");
1076 #endif
1077 #ifndef OPENSSL_NO_DES
1078 BIO_printf(bio_err,"des ");
1079 #endif
1080 #ifndef OPENSSL_NO_AES
1081 BIO_printf(bio_err,"aes ");
1082 #endif
1083 #ifndef OPENSSL_NO_CAMELLIA
1084 BIO_printf(bio_err,"camellia ");
1085 #endif
1086 #ifndef OPENSSL_NO_RSA
1087 BIO_printf(bio_err,"rsa ");
1088 #endif
1089 #ifndef OPENSSL_NO_BF
1090 BIO_printf(bio_err,"blowfish");
1091 #endif
1092 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1093 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1094 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1095 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1096 BIO_printf(bio_err,"\n");
1097 #endif
1099 BIO_printf(bio_err,"\n");
1100 BIO_printf(bio_err,"Available options:\n");
1101 #if defined(TIMES) || defined(USE_TOD)
1102 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1103 #endif
1104 #ifndef OPENSSL_NO_ENGINE
1105 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1106 #endif
1107 BIO_printf(bio_err,"-evp e use EVP e.\n");
1108 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1109 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1110 #ifndef NO_FORK
1111 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1112 #endif
1113 goto end;
1115 argc--;
1116 argv++;
1117 j++;
1120 #ifndef NO_FORK
1121 if(multi && do_multi(multi))
1122 goto show_res;
1123 #endif
1125 if (j == 0)
1127 for (i=0; i<ALGOR_NUM; i++)
1129 if (i != D_EVP)
1130 doit[i]=1;
1132 for (i=0; i<RSA_NUM; i++)
1133 rsa_doit[i]=1;
1134 for (i=0; i<DSA_NUM; i++)
1135 dsa_doit[i]=1;
1136 #ifndef OPENSSL_NO_ECDSA
1137 for (i=0; i<EC_NUM; i++)
1138 ecdsa_doit[i]=1;
1139 #endif
1140 #ifndef OPENSSL_NO_ECDH
1141 for (i=0; i<EC_NUM; i++)
1142 ecdh_doit[i]=1;
1143 #endif
1145 for (i=0; i<ALGOR_NUM; i++)
1146 if (doit[i]) pr_header++;
1148 if (usertime == 0 && !mr)
1149 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1151 #ifndef OPENSSL_NO_RSA
1152 for (i=0; i<RSA_NUM; i++)
1154 const unsigned char *p;
1156 p=rsa_data[i];
1157 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1158 if (rsa_key[i] == NULL)
1160 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1161 goto end;
1163 #if 0
1164 else
1166 BIO_printf(bio_err,mr ? "+RK:%d:"
1167 : "Loaded RSA key, %d bit modulus and e= 0x",
1168 BN_num_bits(rsa_key[i]->n));
1169 BN_print(bio_err,rsa_key[i]->e);
1170 BIO_printf(bio_err,"\n");
1172 #endif
1174 #endif
1176 #ifndef OPENSSL_NO_DSA
1177 dsa_key[0]=get_dsa512();
1178 dsa_key[1]=get_dsa1024();
1179 dsa_key[2]=get_dsa2048();
1180 #endif
1182 #ifndef OPENSSL_NO_DES
1183 DES_set_key_unchecked(&key,&sch);
1184 DES_set_key_unchecked(&key2,&sch2);
1185 DES_set_key_unchecked(&key3,&sch3);
1186 #endif
1187 #ifndef OPENSSL_NO_AES
1188 AES_set_encrypt_key(key16,128,&aes_ks1);
1189 AES_set_encrypt_key(key24,192,&aes_ks2);
1190 AES_set_encrypt_key(key32,256,&aes_ks3);
1191 #endif
1192 #ifndef OPENSSL_NO_CAMELLIA
1193 Camellia_set_key(key16,128,&camellia_ks1);
1194 Camellia_set_key(ckey24,192,&camellia_ks2);
1195 Camellia_set_key(ckey32,256,&camellia_ks3);
1196 #endif
1197 #ifndef OPENSSL_NO_IDEA
1198 idea_set_encrypt_key(key16,&idea_ks);
1199 #endif
1200 #ifndef OPENSSL_NO_SEED
1201 SEED_set_key(key16,&seed_ks);
1202 #endif
1203 #ifndef OPENSSL_NO_RC4
1204 RC4_set_key(&rc4_ks,16,key16);
1205 #endif
1206 #ifndef OPENSSL_NO_RC2
1207 RC2_set_key(&rc2_ks,16,key16,128);
1208 #endif
1209 #ifndef OPENSSL_NO_RC5
1210 RC5_32_set_key(&rc5_ks,16,key16,12);
1211 #endif
1212 #ifndef OPENSSL_NO_BF
1213 BF_set_key(&bf_ks,16,key16);
1214 #endif
1215 #ifndef OPENSSL_NO_CAST
1216 CAST_set_key(&cast_ks,16,key16);
1217 #endif
1218 #ifndef OPENSSL_NO_RSA
1219 memset(rsa_c,0,sizeof(rsa_c));
1220 #endif
1221 #ifndef SIGALRM
1222 #ifndef OPENSSL_NO_DES
1223 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1224 count=10;
1225 do {
1226 long it;
1227 count*=2;
1228 Time_F(START);
1229 for (it=count; it; it--)
1230 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
1231 &sch,DES_ENCRYPT);
1232 d=Time_F(STOP);
1233 } while (d <3);
1234 save_count=count;
1235 c[D_MD2][0]=count/10;
1236 c[D_MDC2][0]=count/10;
1237 c[D_MD4][0]=count;
1238 c[D_MD5][0]=count;
1239 c[D_HMAC][0]=count;
1240 c[D_SHA1][0]=count;
1241 c[D_RMD160][0]=count;
1242 c[D_RC4][0]=count*5;
1243 c[D_CBC_DES][0]=count;
1244 c[D_EDE3_DES][0]=count/3;
1245 c[D_CBC_IDEA][0]=count;
1246 c[D_CBC_SEED][0]=count;
1247 c[D_CBC_RC2][0]=count;
1248 c[D_CBC_RC5][0]=count;
1249 c[D_CBC_BF][0]=count;
1250 c[D_CBC_CAST][0]=count;
1251 c[D_CBC_128_AES][0]=count;
1252 c[D_CBC_192_AES][0]=count;
1253 c[D_CBC_256_AES][0]=count;
1254 c[D_CBC_128_CML][0]=count;
1255 c[D_CBC_192_CML][0]=count;
1256 c[D_CBC_256_CML][0]=count;
1257 c[D_SHA256][0]=count;
1258 c[D_SHA512][0]=count;
1259 c[D_WHIRLPOOL][0]=count;
1260 c[D_IGE_128_AES][0]=count;
1261 c[D_IGE_192_AES][0]=count;
1262 c[D_IGE_256_AES][0]=count;
1264 for (i=1; i<SIZE_NUM; i++)
1266 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1267 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1268 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1269 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1270 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1271 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1272 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1273 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1274 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1275 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
1277 for (i=1; i<SIZE_NUM; i++)
1279 long l0,l1;
1281 l0=(long)lengths[i-1];
1282 l1=(long)lengths[i];
1283 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1284 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1285 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1286 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1287 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1288 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1289 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1290 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1291 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1292 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1293 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1294 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1295 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1296 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1297 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1298 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1299 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1300 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1302 #ifndef OPENSSL_NO_RSA
1303 rsa_c[R_RSA_512][0]=count/2000;
1304 rsa_c[R_RSA_512][1]=count/400;
1305 for (i=1; i<RSA_NUM; i++)
1307 rsa_c[i][0]=rsa_c[i-1][0]/8;
1308 rsa_c[i][1]=rsa_c[i-1][1]/4;
1309 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1310 rsa_doit[i]=0;
1311 else
1313 if (rsa_c[i][0] == 0)
1315 rsa_c[i][0]=1;
1316 rsa_c[i][1]=20;
1320 #endif
1322 #ifndef OPENSSL_NO_DSA
1323 dsa_c[R_DSA_512][0]=count/1000;
1324 dsa_c[R_DSA_512][1]=count/1000/2;
1325 for (i=1; i<DSA_NUM; i++)
1327 dsa_c[i][0]=dsa_c[i-1][0]/4;
1328 dsa_c[i][1]=dsa_c[i-1][1]/4;
1329 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1330 dsa_doit[i]=0;
1331 else
1333 if (dsa_c[i] == 0)
1335 dsa_c[i][0]=1;
1336 dsa_c[i][1]=1;
1340 #endif
1342 #ifndef OPENSSL_NO_ECDSA
1343 ecdsa_c[R_EC_P160][0]=count/1000;
1344 ecdsa_c[R_EC_P160][1]=count/1000/2;
1345 for (i=R_EC_P192; i<=R_EC_P521; i++)
1347 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1348 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1349 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1350 ecdsa_doit[i]=0;
1351 else
1353 if (ecdsa_c[i] == 0)
1355 ecdsa_c[i][0]=1;
1356 ecdsa_c[i][1]=1;
1360 ecdsa_c[R_EC_K163][0]=count/1000;
1361 ecdsa_c[R_EC_K163][1]=count/1000/2;
1362 for (i=R_EC_K233; i<=R_EC_K571; i++)
1364 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1365 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1366 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1367 ecdsa_doit[i]=0;
1368 else
1370 if (ecdsa_c[i] == 0)
1372 ecdsa_c[i][0]=1;
1373 ecdsa_c[i][1]=1;
1377 ecdsa_c[R_EC_B163][0]=count/1000;
1378 ecdsa_c[R_EC_B163][1]=count/1000/2;
1379 for (i=R_EC_B233; i<=R_EC_B571; i++)
1381 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1382 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1383 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1384 ecdsa_doit[i]=0;
1385 else
1387 if (ecdsa_c[i] == 0)
1389 ecdsa_c[i][0]=1;
1390 ecdsa_c[i][1]=1;
1394 #endif
1396 #ifndef OPENSSL_NO_ECDH
1397 ecdh_c[R_EC_P160][0]=count/1000;
1398 ecdh_c[R_EC_P160][1]=count/1000;
1399 for (i=R_EC_P192; i<=R_EC_P521; i++)
1401 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1402 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1403 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1404 ecdh_doit[i]=0;
1405 else
1407 if (ecdh_c[i] == 0)
1409 ecdh_c[i][0]=1;
1410 ecdh_c[i][1]=1;
1414 ecdh_c[R_EC_K163][0]=count/1000;
1415 ecdh_c[R_EC_K163][1]=count/1000;
1416 for (i=R_EC_K233; i<=R_EC_K571; i++)
1418 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1419 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1420 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1421 ecdh_doit[i]=0;
1422 else
1424 if (ecdh_c[i] == 0)
1426 ecdh_c[i][0]=1;
1427 ecdh_c[i][1]=1;
1431 ecdh_c[R_EC_B163][0]=count/1000;
1432 ecdh_c[R_EC_B163][1]=count/1000;
1433 for (i=R_EC_B233; i<=R_EC_B571; i++)
1435 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1436 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1437 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1438 ecdh_doit[i]=0;
1439 else
1441 if (ecdh_c[i] == 0)
1443 ecdh_c[i][0]=1;
1444 ecdh_c[i][1]=1;
1448 #endif
1450 #define COND(d) (count < (d))
1451 #define COUNT(d) (d)
1452 #else
1453 /* not worth fixing */
1454 # error "You cannot disable DES on systems without SIGALRM."
1455 #endif /* OPENSSL_NO_DES */
1456 #else
1457 #define COND(c) (run)
1458 #define COUNT(d) (count)
1459 #ifndef _WIN32
1460 signal(SIGALRM,sig_done);
1461 #endif
1462 #endif /* SIGALRM */
1464 #ifndef OPENSSL_NO_MD2
1465 if (doit[D_MD2])
1467 for (j=0; j<SIZE_NUM; j++)
1469 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1470 Time_F(START);
1471 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1472 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1473 d=Time_F(STOP);
1474 print_result(D_MD2,j,count,d);
1477 #endif
1478 #ifndef OPENSSL_NO_MDC2
1479 if (doit[D_MDC2])
1481 for (j=0; j<SIZE_NUM; j++)
1483 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1484 Time_F(START);
1485 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1486 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1487 d=Time_F(STOP);
1488 print_result(D_MDC2,j,count,d);
1491 #endif
1493 #ifndef OPENSSL_NO_MD4
1494 if (doit[D_MD4])
1496 for (j=0; j<SIZE_NUM; j++)
1498 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1499 Time_F(START);
1500 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1501 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1502 d=Time_F(STOP);
1503 print_result(D_MD4,j,count,d);
1506 #endif
1508 #ifndef OPENSSL_NO_MD5
1509 if (doit[D_MD5])
1511 for (j=0; j<SIZE_NUM; j++)
1513 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1514 Time_F(START);
1515 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1516 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1517 d=Time_F(STOP);
1518 print_result(D_MD5,j,count,d);
1521 #endif
1523 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1524 if (doit[D_HMAC])
1526 HMAC_CTX hctx;
1528 HMAC_CTX_init(&hctx);
1529 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1530 16,EVP_md5(), NULL);
1532 for (j=0; j<SIZE_NUM; j++)
1534 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1535 Time_F(START);
1536 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1538 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1539 HMAC_Update(&hctx,buf,lengths[j]);
1540 HMAC_Final(&hctx,&(hmac[0]),NULL);
1542 d=Time_F(STOP);
1543 print_result(D_HMAC,j,count,d);
1545 HMAC_CTX_cleanup(&hctx);
1547 #endif
1548 #ifndef OPENSSL_NO_SHA
1549 if (doit[D_SHA1])
1551 for (j=0; j<SIZE_NUM; j++)
1553 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1554 Time_F(START);
1555 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1556 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1557 d=Time_F(STOP);
1558 print_result(D_SHA1,j,count,d);
1562 #ifndef OPENSSL_NO_SHA256
1563 if (doit[D_SHA256])
1565 for (j=0; j<SIZE_NUM; j++)
1567 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1568 Time_F(START);
1569 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1570 SHA256(buf,lengths[j],sha256);
1571 d=Time_F(STOP);
1572 print_result(D_SHA256,j,count,d);
1575 #endif
1577 #ifndef OPENSSL_NO_SHA512
1578 if (doit[D_SHA512])
1580 for (j=0; j<SIZE_NUM; j++)
1582 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1583 Time_F(START);
1584 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1585 SHA512(buf,lengths[j],sha512);
1586 d=Time_F(STOP);
1587 print_result(D_SHA512,j,count,d);
1590 #endif
1591 #endif
1593 #ifndef OPENSSL_NO_WHIRLPOOL
1594 if (doit[D_WHIRLPOOL])
1596 for (j=0; j<SIZE_NUM; j++)
1598 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1599 Time_F(START);
1600 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1601 WHIRLPOOL(buf,lengths[j],whirlpool);
1602 d=Time_F(STOP);
1603 print_result(D_WHIRLPOOL,j,count,d);
1606 #endif
1608 #ifndef OPENSSL_NO_RIPEMD
1609 if (doit[D_RMD160])
1611 for (j=0; j<SIZE_NUM; j++)
1613 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1614 Time_F(START);
1615 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1616 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1617 d=Time_F(STOP);
1618 print_result(D_RMD160,j,count,d);
1621 #endif
1622 #ifndef OPENSSL_NO_RC4
1623 if (doit[D_RC4])
1625 for (j=0; j<SIZE_NUM; j++)
1627 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1628 Time_F(START);
1629 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1630 RC4(&rc4_ks,(unsigned int)lengths[j],
1631 buf,buf);
1632 d=Time_F(STOP);
1633 print_result(D_RC4,j,count,d);
1636 #endif
1637 #ifndef OPENSSL_NO_DES
1638 if (doit[D_CBC_DES])
1640 for (j=0; j<SIZE_NUM; j++)
1642 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1643 Time_F(START);
1644 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1645 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1646 &DES_iv,DES_ENCRYPT);
1647 d=Time_F(STOP);
1648 print_result(D_CBC_DES,j,count,d);
1652 if (doit[D_EDE3_DES])
1654 for (j=0; j<SIZE_NUM; j++)
1656 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1657 Time_F(START);
1658 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1659 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1660 &sch,&sch2,&sch3,
1661 &DES_iv,DES_ENCRYPT);
1662 d=Time_F(STOP);
1663 print_result(D_EDE3_DES,j,count,d);
1666 #endif
1667 #ifndef OPENSSL_NO_AES
1668 if (doit[D_CBC_128_AES])
1670 for (j=0; j<SIZE_NUM; j++)
1672 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1673 Time_F(START);
1674 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1675 AES_cbc_encrypt(buf,buf,
1676 (unsigned long)lengths[j],&aes_ks1,
1677 iv,AES_ENCRYPT);
1678 d=Time_F(STOP);
1679 print_result(D_CBC_128_AES,j,count,d);
1682 if (doit[D_CBC_192_AES])
1684 for (j=0; j<SIZE_NUM; j++)
1686 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1687 Time_F(START);
1688 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1689 AES_cbc_encrypt(buf,buf,
1690 (unsigned long)lengths[j],&aes_ks2,
1691 iv,AES_ENCRYPT);
1692 d=Time_F(STOP);
1693 print_result(D_CBC_192_AES,j,count,d);
1696 if (doit[D_CBC_256_AES])
1698 for (j=0; j<SIZE_NUM; j++)
1700 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1701 Time_F(START);
1702 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1703 AES_cbc_encrypt(buf,buf,
1704 (unsigned long)lengths[j],&aes_ks3,
1705 iv,AES_ENCRYPT);
1706 d=Time_F(STOP);
1707 print_result(D_CBC_256_AES,j,count,d);
1711 if (doit[D_IGE_128_AES])
1713 for (j=0; j<SIZE_NUM; j++)
1715 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1716 Time_F(START);
1717 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1718 AES_ige_encrypt(buf,buf2,
1719 (unsigned long)lengths[j],&aes_ks1,
1720 iv,AES_ENCRYPT);
1721 d=Time_F(STOP);
1722 print_result(D_IGE_128_AES,j,count,d);
1725 if (doit[D_IGE_192_AES])
1727 for (j=0; j<SIZE_NUM; j++)
1729 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1730 Time_F(START);
1731 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1732 AES_ige_encrypt(buf,buf2,
1733 (unsigned long)lengths[j],&aes_ks2,
1734 iv,AES_ENCRYPT);
1735 d=Time_F(STOP);
1736 print_result(D_IGE_192_AES,j,count,d);
1739 if (doit[D_IGE_256_AES])
1741 for (j=0; j<SIZE_NUM; j++)
1743 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1744 Time_F(START);
1745 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1746 AES_ige_encrypt(buf,buf2,
1747 (unsigned long)lengths[j],&aes_ks3,
1748 iv,AES_ENCRYPT);
1749 d=Time_F(STOP);
1750 print_result(D_IGE_256_AES,j,count,d);
1755 #endif
1756 #ifndef OPENSSL_NO_CAMELLIA
1757 if (doit[D_CBC_128_CML])
1759 for (j=0; j<SIZE_NUM; j++)
1761 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1762 Time_F(START);
1763 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1764 Camellia_cbc_encrypt(buf,buf,
1765 (unsigned long)lengths[j],&camellia_ks1,
1766 iv,CAMELLIA_ENCRYPT);
1767 d=Time_F(STOP);
1768 print_result(D_CBC_128_CML,j,count,d);
1771 if (doit[D_CBC_192_CML])
1773 for (j=0; j<SIZE_NUM; j++)
1775 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1776 Time_F(START);
1777 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1778 Camellia_cbc_encrypt(buf,buf,
1779 (unsigned long)lengths[j],&camellia_ks2,
1780 iv,CAMELLIA_ENCRYPT);
1781 d=Time_F(STOP);
1782 print_result(D_CBC_192_CML,j,count,d);
1785 if (doit[D_CBC_256_CML])
1787 for (j=0; j<SIZE_NUM; j++)
1789 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1790 Time_F(START);
1791 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1792 Camellia_cbc_encrypt(buf,buf,
1793 (unsigned long)lengths[j],&camellia_ks3,
1794 iv,CAMELLIA_ENCRYPT);
1795 d=Time_F(STOP);
1796 print_result(D_CBC_256_CML,j,count,d);
1800 #endif
1801 #ifndef OPENSSL_NO_IDEA
1802 if (doit[D_CBC_IDEA])
1804 for (j=0; j<SIZE_NUM; j++)
1806 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1807 Time_F(START);
1808 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1809 idea_cbc_encrypt(buf,buf,
1810 (unsigned long)lengths[j],&idea_ks,
1811 iv,IDEA_ENCRYPT);
1812 d=Time_F(STOP);
1813 print_result(D_CBC_IDEA,j,count,d);
1816 #endif
1817 #ifndef OPENSSL_NO_SEED
1818 if (doit[D_CBC_SEED])
1820 for (j=0; j<SIZE_NUM; j++)
1822 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1823 Time_F(START);
1824 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1825 SEED_cbc_encrypt(buf,buf,
1826 (unsigned long)lengths[j],&seed_ks,iv,1);
1827 d=Time_F(STOP);
1828 print_result(D_CBC_SEED,j,count,d);
1831 #endif
1832 #ifndef OPENSSL_NO_RC2
1833 if (doit[D_CBC_RC2])
1835 for (j=0; j<SIZE_NUM; j++)
1837 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1838 Time_F(START);
1839 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1840 RC2_cbc_encrypt(buf,buf,
1841 (unsigned long)lengths[j],&rc2_ks,
1842 iv,RC2_ENCRYPT);
1843 d=Time_F(STOP);
1844 print_result(D_CBC_RC2,j,count,d);
1847 #endif
1848 #ifndef OPENSSL_NO_RC5
1849 if (doit[D_CBC_RC5])
1851 for (j=0; j<SIZE_NUM; j++)
1853 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1854 Time_F(START);
1855 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1856 RC5_32_cbc_encrypt(buf,buf,
1857 (unsigned long)lengths[j],&rc5_ks,
1858 iv,RC5_ENCRYPT);
1859 d=Time_F(STOP);
1860 print_result(D_CBC_RC5,j,count,d);
1863 #endif
1864 #ifndef OPENSSL_NO_BF
1865 if (doit[D_CBC_BF])
1867 for (j=0; j<SIZE_NUM; j++)
1869 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1870 Time_F(START);
1871 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1872 BF_cbc_encrypt(buf,buf,
1873 (unsigned long)lengths[j],&bf_ks,
1874 iv,BF_ENCRYPT);
1875 d=Time_F(STOP);
1876 print_result(D_CBC_BF,j,count,d);
1879 #endif
1880 #ifndef OPENSSL_NO_CAST
1881 if (doit[D_CBC_CAST])
1883 for (j=0; j<SIZE_NUM; j++)
1885 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1886 Time_F(START);
1887 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1888 CAST_cbc_encrypt(buf,buf,
1889 (unsigned long)lengths[j],&cast_ks,
1890 iv,CAST_ENCRYPT);
1891 d=Time_F(STOP);
1892 print_result(D_CBC_CAST,j,count,d);
1895 #endif
1897 if (doit[D_EVP])
1899 for (j=0; j<SIZE_NUM; j++)
1901 if (evp_cipher)
1903 EVP_CIPHER_CTX ctx;
1904 int outl;
1906 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1907 /* -O3 -fschedule-insns messes up an
1908 * optimization here! names[D_EVP]
1909 * somehow becomes NULL */
1910 print_message(names[D_EVP],save_count,
1911 lengths[j]);
1913 EVP_CIPHER_CTX_init(&ctx);
1914 if(decrypt)
1915 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1916 else
1917 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1918 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1920 Time_F(START);
1921 if(decrypt)
1922 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1923 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1924 else
1925 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1926 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1927 if(decrypt)
1928 EVP_DecryptFinal_ex(&ctx,buf,&outl);
1929 else
1930 EVP_EncryptFinal_ex(&ctx,buf,&outl);
1931 d=Time_F(STOP);
1932 EVP_CIPHER_CTX_cleanup(&ctx);
1934 if (evp_md)
1936 names[D_EVP]=OBJ_nid2ln(evp_md->type);
1937 print_message(names[D_EVP],save_count,
1938 lengths[j]);
1940 Time_F(START);
1941 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1942 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
1944 d=Time_F(STOP);
1946 print_result(D_EVP,j,count,d);
1950 RAND_pseudo_bytes(buf,36);
1951 #ifndef OPENSSL_NO_RSA
1952 for (j=0; j<RSA_NUM; j++)
1954 int ret;
1955 if (!rsa_doit[j]) continue;
1956 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
1957 if (ret == 0)
1959 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
1960 ERR_print_errors(bio_err);
1961 rsa_count=1;
1963 else
1965 pkey_print_message("private","rsa",
1966 rsa_c[j][0],rsa_bits[j],
1967 RSA_SECONDS);
1968 /* RSA_blinding_on(rsa_key[j],NULL); */
1969 Time_F(START);
1970 for (count=0,run=1; COND(rsa_c[j][0]); count++)
1972 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
1973 &rsa_num, rsa_key[j]);
1974 if (ret == 0)
1976 BIO_printf(bio_err,
1977 "RSA sign failure\n");
1978 ERR_print_errors(bio_err);
1979 count=1;
1980 break;
1983 d=Time_F(STOP);
1984 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
1985 : "%ld %d bit private RSA's in %.2fs\n",
1986 count,rsa_bits[j],d);
1987 rsa_results[j][0]=d/(double)count;
1988 rsa_count=count;
1991 #if 1
1992 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
1993 if (ret <= 0)
1995 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
1996 ERR_print_errors(bio_err);
1997 rsa_doit[j] = 0;
1999 else
2001 pkey_print_message("public","rsa",
2002 rsa_c[j][1],rsa_bits[j],
2003 RSA_SECONDS);
2004 Time_F(START);
2005 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2007 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2008 rsa_num, rsa_key[j]);
2009 if (ret <= 0)
2011 BIO_printf(bio_err,
2012 "RSA verify failure\n");
2013 ERR_print_errors(bio_err);
2014 count=1;
2015 break;
2018 d=Time_F(STOP);
2019 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2020 : "%ld %d bit public RSA's in %.2fs\n",
2021 count,rsa_bits[j],d);
2022 rsa_results[j][1]=d/(double)count;
2024 #endif
2026 if (rsa_count <= 1)
2028 /* if longer than 10s, don't do any more */
2029 for (j++; j<RSA_NUM; j++)
2030 rsa_doit[j]=0;
2033 #endif
2035 RAND_pseudo_bytes(buf,20);
2036 #ifndef OPENSSL_NO_DSA
2037 if (RAND_status() != 1)
2039 RAND_seed(rnd_seed, sizeof rnd_seed);
2040 rnd_fake = 1;
2042 for (j=0; j<DSA_NUM; j++)
2044 unsigned int kk;
2045 int ret;
2047 if (!dsa_doit[j]) continue;
2048 /* DSA_generate_key(dsa_key[j]); */
2049 /* DSA_sign_setup(dsa_key[j],NULL); */
2050 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2051 &kk,dsa_key[j]);
2052 if (ret == 0)
2054 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2055 ERR_print_errors(bio_err);
2056 rsa_count=1;
2058 else
2060 pkey_print_message("sign","dsa",
2061 dsa_c[j][0],dsa_bits[j],
2062 DSA_SECONDS);
2063 Time_F(START);
2064 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2066 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2067 &kk,dsa_key[j]);
2068 if (ret == 0)
2070 BIO_printf(bio_err,
2071 "DSA sign failure\n");
2072 ERR_print_errors(bio_err);
2073 count=1;
2074 break;
2077 d=Time_F(STOP);
2078 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2079 : "%ld %d bit DSA signs in %.2fs\n",
2080 count,dsa_bits[j],d);
2081 dsa_results[j][0]=d/(double)count;
2082 rsa_count=count;
2085 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2086 kk,dsa_key[j]);
2087 if (ret <= 0)
2089 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2090 ERR_print_errors(bio_err);
2091 dsa_doit[j] = 0;
2093 else
2095 pkey_print_message("verify","dsa",
2096 dsa_c[j][1],dsa_bits[j],
2097 DSA_SECONDS);
2098 Time_F(START);
2099 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2101 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2102 kk,dsa_key[j]);
2103 if (ret <= 0)
2105 BIO_printf(bio_err,
2106 "DSA verify failure\n");
2107 ERR_print_errors(bio_err);
2108 count=1;
2109 break;
2112 d=Time_F(STOP);
2113 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2114 : "%ld %d bit DSA verify in %.2fs\n",
2115 count,dsa_bits[j],d);
2116 dsa_results[j][1]=d/(double)count;
2119 if (rsa_count <= 1)
2121 /* if longer than 10s, don't do any more */
2122 for (j++; j<DSA_NUM; j++)
2123 dsa_doit[j]=0;
2126 if (rnd_fake) RAND_cleanup();
2127 #endif
2129 #ifndef OPENSSL_NO_ECDSA
2130 if (RAND_status() != 1)
2132 RAND_seed(rnd_seed, sizeof rnd_seed);
2133 rnd_fake = 1;
2135 for (j=0; j<EC_NUM; j++)
2137 int ret;
2139 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2140 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2141 if (ecdsa[j] == NULL)
2143 BIO_printf(bio_err,"ECDSA failure.\n");
2144 ERR_print_errors(bio_err);
2145 rsa_count=1;
2147 else
2149 #if 1
2150 EC_KEY_precompute_mult(ecdsa[j], NULL);
2151 #endif
2152 /* Perform ECDSA signature test */
2153 EC_KEY_generate_key(ecdsa[j]);
2154 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2155 &ecdsasiglen, ecdsa[j]);
2156 if (ret == 0)
2158 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2159 ERR_print_errors(bio_err);
2160 rsa_count=1;
2162 else
2164 pkey_print_message("sign","ecdsa",
2165 ecdsa_c[j][0],
2166 test_curves_bits[j],
2167 ECDSA_SECONDS);
2169 Time_F(START);
2170 for (count=0,run=1; COND(ecdsa_c[j][0]);
2171 count++)
2173 ret=ECDSA_sign(0, buf, 20,
2174 ecdsasig, &ecdsasiglen,
2175 ecdsa[j]);
2176 if (ret == 0)
2178 BIO_printf(bio_err, "ECDSA sign failure\n");
2179 ERR_print_errors(bio_err);
2180 count=1;
2181 break;
2184 d=Time_F(STOP);
2186 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2187 "%ld %d bit ECDSA signs in %.2fs \n",
2188 count, test_curves_bits[j], d);
2189 ecdsa_results[j][0]=d/(double)count;
2190 rsa_count=count;
2193 /* Perform ECDSA verification test */
2194 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2195 ecdsasiglen, ecdsa[j]);
2196 if (ret != 1)
2198 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2199 ERR_print_errors(bio_err);
2200 ecdsa_doit[j] = 0;
2202 else
2204 pkey_print_message("verify","ecdsa",
2205 ecdsa_c[j][1],
2206 test_curves_bits[j],
2207 ECDSA_SECONDS);
2208 Time_F(START);
2209 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2211 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2212 if (ret != 1)
2214 BIO_printf(bio_err, "ECDSA verify failure\n");
2215 ERR_print_errors(bio_err);
2216 count=1;
2217 break;
2220 d=Time_F(STOP);
2221 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2222 : "%ld %d bit ECDSA verify in %.2fs\n",
2223 count, test_curves_bits[j], d);
2224 ecdsa_results[j][1]=d/(double)count;
2227 if (rsa_count <= 1)
2229 /* if longer than 10s, don't do any more */
2230 for (j++; j<EC_NUM; j++)
2231 ecdsa_doit[j]=0;
2235 if (rnd_fake) RAND_cleanup();
2236 #endif
2238 #ifndef OPENSSL_NO_ECDH
2239 if (RAND_status() != 1)
2241 RAND_seed(rnd_seed, sizeof rnd_seed);
2242 rnd_fake = 1;
2244 for (j=0; j<EC_NUM; j++)
2246 if (!ecdh_doit[j]) continue;
2247 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2248 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2249 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2251 BIO_printf(bio_err,"ECDH failure.\n");
2252 ERR_print_errors(bio_err);
2253 rsa_count=1;
2255 else
2257 /* generate two ECDH key pairs */
2258 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2259 !EC_KEY_generate_key(ecdh_b[j]))
2261 BIO_printf(bio_err,"ECDH key generation failure.\n");
2262 ERR_print_errors(bio_err);
2263 rsa_count=1;
2265 else
2267 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2268 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2270 int field_size, outlen;
2271 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2272 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2273 if (field_size <= 24 * 8)
2275 outlen = KDF1_SHA1_len;
2276 kdf = KDF1_SHA1;
2278 else
2280 outlen = (field_size+7)/8;
2281 kdf = NULL;
2283 secret_size_a = ECDH_compute_key(secret_a, outlen,
2284 EC_KEY_get0_public_key(ecdh_b[j]),
2285 ecdh_a[j], kdf);
2286 secret_size_b = ECDH_compute_key(secret_b, outlen,
2287 EC_KEY_get0_public_key(ecdh_a[j]),
2288 ecdh_b[j], kdf);
2289 if (secret_size_a != secret_size_b)
2290 ecdh_checks = 0;
2291 else
2292 ecdh_checks = 1;
2294 for (secret_idx = 0;
2295 (secret_idx < secret_size_a)
2296 && (ecdh_checks == 1);
2297 secret_idx++)
2299 if (secret_a[secret_idx] != secret_b[secret_idx])
2300 ecdh_checks = 0;
2303 if (ecdh_checks == 0)
2305 BIO_printf(bio_err,"ECDH computations don't match.\n");
2306 ERR_print_errors(bio_err);
2307 rsa_count=1;
2310 pkey_print_message("","ecdh",
2311 ecdh_c[j][0],
2312 test_curves_bits[j],
2313 ECDH_SECONDS);
2314 Time_F(START);
2315 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2317 ECDH_compute_key(secret_a, outlen,
2318 EC_KEY_get0_public_key(ecdh_b[j]),
2319 ecdh_a[j], kdf);
2321 d=Time_F(STOP);
2322 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2323 count, test_curves_bits[j], d);
2324 ecdh_results[j][0]=d/(double)count;
2325 rsa_count=count;
2330 if (rsa_count <= 1)
2332 /* if longer than 10s, don't do any more */
2333 for (j++; j<EC_NUM; j++)
2334 ecdh_doit[j]=0;
2337 if (rnd_fake) RAND_cleanup();
2338 #endif
2339 #ifndef NO_FORK
2340 show_res:
2341 #endif
2342 if(!mr)
2344 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2345 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2346 printf("options:");
2347 printf("%s ",BN_options());
2348 #ifndef OPENSSL_NO_MD2
2349 printf("%s ",MD2_options());
2350 #endif
2351 #ifndef OPENSSL_NO_RC4
2352 printf("%s ",RC4_options());
2353 #endif
2354 #ifndef OPENSSL_NO_DES
2355 printf("%s ",DES_options());
2356 #endif
2357 #ifndef OPENSSL_NO_AES
2358 printf("%s ",AES_options());
2359 #endif
2360 #ifndef OPENSSL_NO_IDEA
2361 printf("%s ",idea_options());
2362 #endif
2363 #ifndef OPENSSL_NO_BF
2364 printf("%s ",BF_options());
2365 #endif
2366 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2369 if (pr_header)
2371 if(mr)
2372 fprintf(stdout,"+H");
2373 else
2375 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2376 fprintf(stdout,"type ");
2378 for (j=0; j<SIZE_NUM; j++)
2379 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2380 fprintf(stdout,"\n");
2383 for (k=0; k<ALGOR_NUM; k++)
2385 if (!doit[k]) continue;
2386 if(mr)
2387 fprintf(stdout,"+F:%d:%s",k,names[k]);
2388 else
2389 fprintf(stdout,"%-13s",names[k]);
2390 for (j=0; j<SIZE_NUM; j++)
2392 if (results[k][j] > 10000 && !mr)
2393 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2394 else
2395 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2397 fprintf(stdout,"\n");
2399 #ifndef OPENSSL_NO_RSA
2400 j=1;
2401 for (k=0; k<RSA_NUM; k++)
2403 if (!rsa_doit[k]) continue;
2404 if (j && !mr)
2406 printf("%18ssign verify sign/s verify/s\n"," ");
2407 j=0;
2409 if(mr)
2410 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2411 k,rsa_bits[k],rsa_results[k][0],
2412 rsa_results[k][1]);
2413 else
2414 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2415 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2416 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2418 #endif
2419 #ifndef OPENSSL_NO_DSA
2420 j=1;
2421 for (k=0; k<DSA_NUM; k++)
2423 if (!dsa_doit[k]) continue;
2424 if (j && !mr)
2426 printf("%18ssign verify sign/s verify/s\n"," ");
2427 j=0;
2429 if(mr)
2430 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2431 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2432 else
2433 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2434 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2435 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2437 #endif
2438 #ifndef OPENSSL_NO_ECDSA
2439 j=1;
2440 for (k=0; k<EC_NUM; k++)
2442 if (!ecdsa_doit[k]) continue;
2443 if (j && !mr)
2445 printf("%30ssign verify sign/s verify/s\n"," ");
2446 j=0;
2449 if (mr)
2450 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2451 k, test_curves_bits[k],
2452 ecdsa_results[k][0],ecdsa_results[k][1]);
2453 else
2454 fprintf(stdout,
2455 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2456 test_curves_bits[k],
2457 test_curves_names[k],
2458 ecdsa_results[k][0],ecdsa_results[k][1],
2459 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2461 #endif
2464 #ifndef OPENSSL_NO_ECDH
2465 j=1;
2466 for (k=0; k<EC_NUM; k++)
2468 if (!ecdh_doit[k]) continue;
2469 if (j && !mr)
2471 printf("%30sop op/s\n"," ");
2472 j=0;
2474 if (mr)
2475 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2476 k, test_curves_bits[k],
2477 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2479 else
2480 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2481 test_curves_bits[k],
2482 test_curves_names[k],
2483 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2485 #endif
2487 mret=0;
2489 end:
2490 ERR_print_errors(bio_err);
2491 if (buf != NULL) OPENSSL_free(buf);
2492 if (buf2 != NULL) OPENSSL_free(buf2);
2493 #ifndef OPENSSL_NO_RSA
2494 for (i=0; i<RSA_NUM; i++)
2495 if (rsa_key[i] != NULL)
2496 RSA_free(rsa_key[i]);
2497 #endif
2498 #ifndef OPENSSL_NO_DSA
2499 for (i=0; i<DSA_NUM; i++)
2500 if (dsa_key[i] != NULL)
2501 DSA_free(dsa_key[i]);
2502 #endif
2504 #ifndef OPENSSL_NO_ECDSA
2505 for (i=0; i<EC_NUM; i++)
2506 if (ecdsa[i] != NULL)
2507 EC_KEY_free(ecdsa[i]);
2508 #endif
2509 #ifndef OPENSSL_NO_ECDH
2510 for (i=0; i<EC_NUM; i++)
2512 if (ecdh_a[i] != NULL)
2513 EC_KEY_free(ecdh_a[i]);
2514 if (ecdh_b[i] != NULL)
2515 EC_KEY_free(ecdh_b[i]);
2517 #endif
2519 apps_shutdown();
2520 OPENSSL_EXIT(mret);
2523 static void print_message(const char *s, long num, int length)
2525 #ifdef SIGALRM
2526 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2527 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2528 (void)BIO_flush(bio_err);
2529 alarm(SECONDS);
2530 #else
2531 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2532 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2533 (void)BIO_flush(bio_err);
2534 #endif
2535 #ifdef LINT
2536 num=num;
2537 #endif
2540 static void pkey_print_message(const char *str, const char *str2, long num,
2541 int bits, int tm)
2543 #ifdef SIGALRM
2544 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2545 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2546 (void)BIO_flush(bio_err);
2547 alarm(RSA_SECONDS);
2548 #else
2549 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2550 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2551 (void)BIO_flush(bio_err);
2552 #endif
2553 #ifdef LINT
2554 num=num;
2555 #endif
2558 static void print_result(int alg,int run_no,int count,double time_used)
2560 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2561 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2562 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2565 #ifndef NO_FORK
2566 static char *sstrsep(char **string, const char *delim)
2568 char isdelim[256];
2569 char *token = *string;
2571 if (**string == 0)
2572 return NULL;
2574 memset(isdelim, 0, sizeof isdelim);
2575 isdelim[0] = 1;
2577 while (*delim)
2579 isdelim[(unsigned char)(*delim)] = 1;
2580 delim++;
2583 while (!isdelim[(unsigned char)(**string)])
2585 (*string)++;
2588 if (**string)
2590 **string = 0;
2591 (*string)++;
2594 return token;
2597 static int do_multi(int multi)
2599 int n;
2600 int fd[2];
2601 int *fds;
2602 static char sep[]=":";
2604 fds=malloc(multi*sizeof *fds);
2605 for(n=0 ; n < multi ; ++n)
2607 pipe(fd);
2608 fflush(stdout);
2609 fflush(stderr);
2610 if(fork())
2612 close(fd[1]);
2613 fds[n]=fd[0];
2615 else
2617 close(fd[0]);
2618 close(1);
2619 dup(fd[1]);
2620 close(fd[1]);
2621 mr=1;
2622 usertime=0;
2623 free(fds);
2624 return 0;
2626 printf("Forked child %d\n",n);
2629 /* for now, assume the pipe is long enough to take all the output */
2630 for(n=0 ; n < multi ; ++n)
2632 FILE *f;
2633 char buf[1024];
2634 char *p;
2636 f=fdopen(fds[n],"r");
2637 while(fgets(buf,sizeof buf,f))
2639 p=strchr(buf,'\n');
2640 if(p)
2641 *p='\0';
2642 if(buf[0] != '+')
2644 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2645 buf,n);
2646 continue;
2648 printf("Got: %s from %d\n",buf,n);
2649 if(!strncmp(buf,"+F:",3))
2651 int alg;
2652 int j;
2654 p=buf+3;
2655 alg=atoi(sstrsep(&p,sep));
2656 sstrsep(&p,sep);
2657 for(j=0 ; j < SIZE_NUM ; ++j)
2658 results[alg][j]+=atof(sstrsep(&p,sep));
2660 else if(!strncmp(buf,"+F2:",4))
2662 int k;
2663 double d;
2665 p=buf+4;
2666 k=atoi(sstrsep(&p,sep));
2667 sstrsep(&p,sep);
2669 d=atof(sstrsep(&p,sep));
2670 if(n)
2671 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2672 else
2673 rsa_results[k][0]=d;
2675 d=atof(sstrsep(&p,sep));
2676 if(n)
2677 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2678 else
2679 rsa_results[k][1]=d;
2681 else if(!strncmp(buf,"+F2:",4))
2683 int k;
2684 double d;
2686 p=buf+4;
2687 k=atoi(sstrsep(&p,sep));
2688 sstrsep(&p,sep);
2690 d=atof(sstrsep(&p,sep));
2691 if(n)
2692 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2693 else
2694 rsa_results[k][0]=d;
2696 d=atof(sstrsep(&p,sep));
2697 if(n)
2698 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2699 else
2700 rsa_results[k][1]=d;
2702 else if(!strncmp(buf,"+F3:",4))
2704 int k;
2705 double d;
2707 p=buf+4;
2708 k=atoi(sstrsep(&p,sep));
2709 sstrsep(&p,sep);
2711 d=atof(sstrsep(&p,sep));
2712 if(n)
2713 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2714 else
2715 dsa_results[k][0]=d;
2717 d=atof(sstrsep(&p,sep));
2718 if(n)
2719 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2720 else
2721 dsa_results[k][1]=d;
2723 #ifndef OPENSSL_NO_ECDSA
2724 else if(!strncmp(buf,"+F4:",4))
2726 int k;
2727 double d;
2729 p=buf+4;
2730 k=atoi(sstrsep(&p,sep));
2731 sstrsep(&p,sep);
2733 d=atof(sstrsep(&p,sep));
2734 if(n)
2735 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2736 else
2737 ecdsa_results[k][0]=d;
2739 d=atof(sstrsep(&p,sep));
2740 if(n)
2741 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2742 else
2743 ecdsa_results[k][1]=d;
2745 #endif
2747 #ifndef OPENSSL_NO_ECDH
2748 else if(!strncmp(buf,"+F5:",4))
2750 int k;
2751 double d;
2753 p=buf+4;
2754 k=atoi(sstrsep(&p,sep));
2755 sstrsep(&p,sep);
2757 d=atof(sstrsep(&p,sep));
2758 if(n)
2759 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2760 else
2761 ecdh_results[k][0]=d;
2764 #endif
2766 else if(!strncmp(buf,"+H:",3))
2769 else
2770 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
2773 fclose(f);
2775 free(fds);
2776 return 1;
2778 #endif
2779 #endif