1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
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.
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
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
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
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 */
87 # define PROG speed_main
95 # ifdef OPENSSL_NO_STDIO
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
107 # ifndef OPENSSL_SYS_NETWARE
111 # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
113 # elif !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
117 # if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) && !defined(OPENSSL_SYS_VXWORKS)
121 # if defined(OPENSSL_SYS_NETWARE)
131 # include <sys/types.h>
132 # include <sys/times.h>
135 # include <sys/time.h>
136 # include <sys/resource.h>
140 * Depending on the VMS version, the tms structure is perhaps defined. The
141 * __TMS macro will show if it was. If it wasn't defined, we should undefine
142 * TIMES, since that tells the rest of the program how things should be
143 * handled. -- Richard Levitte
145 # if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
150 # include <sys/timeb.h>
153 # if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
154 # error "It seems neither struct tms nor struct timeb is supported in this platform!"
157 # if defined(sun) || defined(__ultrix)
158 # define _POSIX_SOURCE
160 # include <sys/param.h>
163 # include <openssl/bn.h>
164 # ifndef OPENSSL_NO_DES
165 # include <openssl/des.h>
167 # ifndef OPENSSL_NO_AES
168 # include <openssl/aes.h>
170 # ifndef OPENSSL_NO_CAMELLIA
171 # include <openssl/camellia.h>
173 # ifndef OPENSSL_NO_MD2
174 # include <openssl/md2.h>
176 # ifndef OPENSSL_NO_MDC2
177 # include <openssl/mdc2.h>
179 # ifndef OPENSSL_NO_MD4
180 # include <openssl/md4.h>
182 # ifndef OPENSSL_NO_MD5
183 # include <openssl/md5.h>
185 # ifndef OPENSSL_NO_HMAC
186 # include <openssl/hmac.h>
188 # include <openssl/evp.h>
189 # ifndef OPENSSL_NO_SHA
190 # include <openssl/sha.h>
192 # ifndef OPENSSL_NO_RIPEMD
193 # include <openssl/ripemd.h>
195 # ifndef OPENSSL_NO_RC4
196 # include <openssl/rc4.h>
198 # ifndef OPENSSL_NO_RC5
199 # include <openssl/rc5.h>
201 # ifndef OPENSSL_NO_RC2
202 # include <openssl/rc2.h>
204 # ifndef OPENSSL_NO_IDEA
205 # include <openssl/idea.h>
207 # ifndef OPENSSL_NO_SEED
208 # include <openssl/seed.h>
210 # ifndef OPENSSL_NO_BF
211 # include <openssl/blowfish.h>
213 # ifndef OPENSSL_NO_CAST
214 # include <openssl/cast.h>
216 # ifndef OPENSSL_NO_RSA
217 # include <openssl/rsa.h>
218 # include "./testrsa.h"
220 # include <openssl/x509.h>
221 # ifndef OPENSSL_NO_DSA
222 # include <openssl/dsa.h>
223 # include "./testdsa.h"
225 # ifndef OPENSSL_NO_ECDSA
226 # include <openssl/ecdsa.h>
228 # ifndef OPENSSL_NO_ECDH
229 # include <openssl/ecdh.h>
233 * The following "HZ" timing stuff should be sync'd up with the code in
234 * crypto/tmdiff.[ch]. That appears to try to do the same job, though I think
235 * this code is more up to date than libcrypto's so there may be features to
236 * migrate over first. This is used in two places further down AFAICS.
237 * The point is that nothing in openssl actually *uses* that tmdiff stuff, so
238 * either speed.c should be using it or it should go because it's obviously not
239 * useful enough. Anyone want to do a janitorial job on this?
242 /* The following if from times(3) man page. It may need to be changed */
244 # if defined(_SC_CLK_TCK) \
245 && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
246 # define HZ sysconf(_SC_CLK_TCK)
249 # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
251 # else /* _BSD_CLK_TCK_ */
252 # define HZ ((double)_BSD_CLK_TCK_)
255 # define HZ ((double)CLK_TCK)
261 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
275 # define BUFSIZE ((long)1024*8+1)
278 static char ftime_used = 0, times_used = 0, gettimeofday_used =
279 0, getrusage_used = 0;
281 static int usertime = 1;
283 static double Time_F(int s);
284 static void print_message(const char *s, long num, int length);
285 static void pkey_print_message(const char *str, const char *str2,
286 long num, int bits, int sec);
287 static void print_result(int alg, int run_no, int count, double time_used);
289 static int do_multi(int multi);
292 # define ALGOR_NUM 28
298 # define MAX_ECDH_SIZE 256
300 static const char *names[ALGOR_NUM] = {
301 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
302 "des cbc", "des ede3", "idea cbc", "seed cbc",
303 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
304 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
305 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
306 "evp", "sha256", "sha512",
307 "aes-128 ige", "aes-192 ige", "aes-256 ige"
310 static double results[ALGOR_NUM][SIZE_NUM];
311 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
313 # ifndef OPENSSL_NO_RSA
314 static double rsa_results[RSA_NUM][2];
316 # ifndef OPENSSL_NO_DSA
317 static double dsa_results[DSA_NUM][2];
319 # ifndef OPENSSL_NO_ECDSA
320 static double ecdsa_results[EC_NUM][2];
322 # ifndef OPENSSL_NO_ECDH
323 static double ecdh_results[EC_NUM][1];
326 # if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
327 static const char rnd_seed[] =
328 "string to make the random number generator think it has entropy";
329 static int rnd_fake = 0;
333 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
334 # define SIGRETTYPE void
336 # define SIGRETTYPE int
339 static SIGRETTYPE sig_done(int sig);
340 static SIGRETTYPE sig_done(int sig)
342 signal(SIGALRM, sig_done);
353 # if defined(OPENSSL_SYS_NETWARE)
356 * for NetWare the best we can do is use clock() which returns the time,
357 * in hundredths of a second, since the NLM began executing
359 static double Time_F(int s)
363 static clock_t tstart, tend;
370 ret = (double)((double)(tend) - (double)(tstart));
371 return ((ret < 0.001) ? 0.001 : ret);
377 static double Time_F(int s)
383 static struct rusage tstart, tend;
387 getrusage(RUSAGE_SELF, &tstart);
392 getrusage(RUSAGE_SELF, &tend);
393 i = (long)tend.ru_utime.tv_usec - (long)tstart.ru_utime.tv_usec;
394 ret = ((double)(tend.ru_utime.tv_sec - tstart.ru_utime.tv_sec))
395 + ((double)i) / 1000000.0;
396 return ((ret < 0.001) ? 0.001 : ret);
399 static struct timeval tstart, tend;
402 gettimeofday_used = 1;
404 gettimeofday(&tstart, NULL);
407 gettimeofday(&tend, NULL);
408 i = (long)tend.tv_usec - (long)tstart.tv_usec;
410 ((double)(tend.tv_sec - tstart.tv_sec)) +
411 ((double)i) / 1000000.0;
412 return ((ret < 0.001) ? 0.001 : ret);
415 # else /* ndef USE_TOD */
419 static struct tms tstart, tend;
428 ret = (double)(tend.tms_utime - tstart.tms_utime) / ret;
429 return ((ret < 1e-3) ? 1e-3 : ret);
432 # endif /* times() */
433 # if defined(TIMES) && defined(TIMEB)
436 # ifdef OPENSSL_SYS_VXWORKS
438 static unsigned long tick_start, tick_end;
441 tick_start = tickGet();
444 tick_end = tickGet();
445 ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
446 return ((ret < 0.001) ? 0.001 : ret);
449 # elif defined(TIMEB)
451 static struct timeb tstart, tend;
460 i = (long)tend.millitm - (long)tstart.millitm;
461 ret = ((double)(tend.time - tstart.time)) + ((double)i) / 1000.0;
462 return ((ret < 0.001) ? 0.001 : ret);
468 # endif /* if defined(OPENSSL_SYS_NETWARE) */
470 # ifndef OPENSSL_NO_ECDH
471 static const int KDF1_SHA1_len = 20;
472 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
475 # ifndef OPENSSL_NO_SHA
476 if (*outlen < SHA_DIGEST_LENGTH)
479 *outlen = SHA_DIGEST_LENGTH;
480 return SHA1(in, inlen, out);
483 # endif /* OPENSSL_NO_SHA */
485 # endif /* OPENSSL_NO_ECDH */
487 int MAIN(int, char **);
489 int MAIN(int argc, char **argv)
491 unsigned char *buf = NULL, *buf2 = NULL;
493 long count = 0, save_count = 0;
495 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
498 # ifndef OPENSSL_NO_RSA
501 unsigned char md[EVP_MAX_MD_SIZE];
502 # ifndef OPENSSL_NO_MD2
503 unsigned char md2[MD2_DIGEST_LENGTH];
505 # ifndef OPENSSL_NO_MDC2
506 unsigned char mdc2[MDC2_DIGEST_LENGTH];
508 # ifndef OPENSSL_NO_MD4
509 unsigned char md4[MD4_DIGEST_LENGTH];
511 # ifndef OPENSSL_NO_MD5
512 unsigned char md5[MD5_DIGEST_LENGTH];
513 unsigned char hmac[MD5_DIGEST_LENGTH];
515 # ifndef OPENSSL_NO_SHA
516 unsigned char sha[SHA_DIGEST_LENGTH];
517 # ifndef OPENSSL_NO_SHA256
518 unsigned char sha256[SHA256_DIGEST_LENGTH];
520 # ifndef OPENSSL_NO_SHA512
521 unsigned char sha512[SHA512_DIGEST_LENGTH];
524 # ifndef OPENSSL_NO_RIPEMD
525 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
527 # ifndef OPENSSL_NO_RC4
530 # ifndef OPENSSL_NO_RC5
533 # ifndef OPENSSL_NO_RC2
536 # ifndef OPENSSL_NO_IDEA
537 IDEA_KEY_SCHEDULE idea_ks;
539 # ifndef OPENSSL_NO_SEED
540 SEED_KEY_SCHEDULE seed_ks;
542 # ifndef OPENSSL_NO_BF
545 # ifndef OPENSSL_NO_CAST
548 static const unsigned char key16[16] = {
549 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
550 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
552 # ifndef OPENSSL_NO_AES
553 static const unsigned char key24[24] = {
554 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
555 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
556 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
558 static const unsigned char key32[32] = {
559 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
560 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
561 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
562 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
565 # ifndef OPENSSL_NO_CAMELLIA
566 static const unsigned char ckey24[24] = {
567 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
568 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
569 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
571 static const unsigned char ckey32[32] = {
572 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
573 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
574 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
575 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
578 # ifndef OPENSSL_NO_AES
579 # define MAX_BLOCK_SIZE 128
581 # define MAX_BLOCK_SIZE 64
583 unsigned char DES_iv[8];
584 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
585 # ifndef OPENSSL_NO_DES
586 static DES_cblock key =
587 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
588 static DES_cblock key2 =
589 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
590 static DES_cblock key3 =
591 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
592 DES_key_schedule sch;
593 DES_key_schedule sch2;
594 DES_key_schedule sch3;
596 # ifndef OPENSSL_NO_AES
597 AES_KEY aes_ks1, aes_ks2, aes_ks3;
599 # ifndef OPENSSL_NO_CAMELLIA
600 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
611 # define D_EDE3_DES 9
612 # define D_CBC_IDEA 10
613 # define D_CBC_SEED 11
614 # define D_CBC_RC2 12
615 # define D_CBC_RC5 13
617 # define D_CBC_CAST 15
618 # define D_CBC_128_AES 16
619 # define D_CBC_192_AES 17
620 # define D_CBC_256_AES 18
621 # define D_CBC_128_CML 19
622 # define D_CBC_192_CML 20
623 # define D_CBC_256_CML 21
627 # define D_IGE_128_AES 25
628 # define D_IGE_192_AES 26
629 # define D_IGE_256_AES 27
631 long c[ALGOR_NUM][SIZE_NUM];
633 # define R_DSA_1024 1
634 # define R_DSA_2048 2
636 # define R_RSA_1024 1
637 # define R_RSA_2048 2
638 # define R_RSA_4096 3
650 # define R_EC_K571 10
651 # define R_EC_B163 11
652 # define R_EC_B233 12
653 # define R_EC_B283 13
654 # define R_EC_B409 14
655 # define R_EC_B571 15
657 # ifndef OPENSSL_NO_RSA
658 RSA *rsa_key[RSA_NUM];
659 long rsa_c[RSA_NUM][2];
660 static unsigned int rsa_bits[RSA_NUM] = {
661 512, 1024, 2048, 4096
663 static unsigned char *rsa_data[RSA_NUM] = {
664 test512, test1024, test2048, test4096
666 static int rsa_data_length[RSA_NUM] = {
667 sizeof(test512), sizeof(test1024),
668 sizeof(test2048), sizeof(test4096)
671 # ifndef OPENSSL_NO_DSA
672 DSA *dsa_key[DSA_NUM];
673 long dsa_c[DSA_NUM][2];
674 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
676 # ifndef OPENSSL_NO_EC
678 * We only test over the following curves as they are representative, To
679 * add tests over more curves, simply add the curve NID and curve name to
680 * the following arrays and increase the EC_NUM value accordingly.
682 static unsigned int test_curves[EC_NUM] = {
685 NID_X9_62_prime192v1,
687 NID_X9_62_prime256v1,
702 static const char *test_curves_names[EC_NUM] = {
722 static int test_curves_bits[EC_NUM] = {
723 160, 192, 224, 256, 384, 521,
724 163, 233, 283, 409, 571,
725 163, 233, 283, 409, 571
730 # ifndef OPENSSL_NO_ECDSA
731 unsigned char ecdsasig[256];
732 unsigned int ecdsasiglen;
733 EC_KEY *ecdsa[EC_NUM];
734 long ecdsa_c[EC_NUM][2];
737 # ifndef OPENSSL_NO_ECDH
738 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
739 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
740 int secret_size_a, secret_size_b;
743 long ecdh_c[EC_NUM][2];
746 int rsa_doit[RSA_NUM];
747 int dsa_doit[DSA_NUM];
748 # ifndef OPENSSL_NO_ECDSA
749 int ecdsa_doit[EC_NUM];
751 # ifndef OPENSSL_NO_ECDH
752 int ecdh_doit[EC_NUM];
756 const EVP_CIPHER *evp_cipher = NULL;
757 const EVP_MD *evp_md = NULL;
768 memset(results, 0, sizeof(results));
769 # ifndef OPENSSL_NO_DSA
770 memset(dsa_key, 0, sizeof(dsa_key));
772 # ifndef OPENSSL_NO_ECDSA
773 for (i = 0; i < EC_NUM; i++)
776 # ifndef OPENSSL_NO_ECDH
777 for (i = 0; i < EC_NUM; i++) {
784 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
785 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
787 if (!load_config(bio_err, NULL))
790 # ifndef OPENSSL_NO_RSA
791 memset(rsa_key, 0, sizeof(rsa_key));
792 for (i = 0; i < RSA_NUM; i++)
796 if ((buf = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
797 BIO_printf(bio_err, "out of memory\n");
800 if ((buf2 = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
801 BIO_printf(bio_err, "out of memory\n");
805 memset(c, 0, sizeof(c));
806 memset(DES_iv, 0, sizeof(DES_iv));
807 memset(iv, 0, sizeof(iv));
809 for (i = 0; i < ALGOR_NUM; i++)
811 for (i = 0; i < RSA_NUM; i++)
813 for (i = 0; i < DSA_NUM; i++)
815 # ifndef OPENSSL_NO_ECDSA
816 for (i = 0; i < EC_NUM; i++)
819 # ifndef OPENSSL_NO_ECDH
820 for (i = 0; i < EC_NUM; i++)
828 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
830 j--; /* Otherwise, -elapsed gets confused with an
832 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
836 BIO_printf(bio_err, "no EVP given\n");
839 evp_cipher = EVP_get_cipherbyname(*argv);
841 evp_md = EVP_get_digestbyname(*argv);
843 if (!evp_cipher && !evp_md) {
844 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
849 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
851 j--; /* Otherwise, -elapsed gets confused with an
854 # ifndef OPENSSL_NO_ENGINE
855 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
859 BIO_printf(bio_err, "no engine given\n");
862 setup_engine(bio_err, *argv, 0);
864 * j will be increased again further down. We just don't want
865 * speed to confuse an engine with an algorithm, especially when
866 * none is given (which means all of them should be run)
872 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
876 BIO_printf(bio_err, "no multi count given\n");
879 multi = atoi(argv[0]);
881 BIO_printf(bio_err, "bad multi count\n");
884 j--; /* Otherwise, -mr gets confused with an
888 else if (argc > 0 && !strcmp(*argv, "-mr")) {
890 j--; /* Otherwise, -mr gets confused with an
893 # ifndef OPENSSL_NO_MD2
894 if (strcmp(*argv, "md2") == 0)
898 # ifndef OPENSSL_NO_MDC2
899 if (strcmp(*argv, "mdc2") == 0)
903 # ifndef OPENSSL_NO_MD4
904 if (strcmp(*argv, "md4") == 0)
908 # ifndef OPENSSL_NO_MD5
909 if (strcmp(*argv, "md5") == 0)
913 # ifndef OPENSSL_NO_MD5
914 if (strcmp(*argv, "hmac") == 0)
918 # ifndef OPENSSL_NO_SHA
919 if (strcmp(*argv, "sha1") == 0)
921 else if (strcmp(*argv, "sha") == 0)
922 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
924 # ifndef OPENSSL_NO_SHA256
925 if (strcmp(*argv, "sha256") == 0)
929 # ifndef OPENSSL_NO_SHA512
930 if (strcmp(*argv, "sha512") == 0)
935 # ifndef OPENSSL_NO_RIPEMD
936 if (strcmp(*argv, "ripemd") == 0)
938 else if (strcmp(*argv, "rmd160") == 0)
940 else if (strcmp(*argv, "ripemd160") == 0)
944 # ifndef OPENSSL_NO_RC4
945 if (strcmp(*argv, "rc4") == 0)
949 # ifndef OPENSSL_NO_DES
950 if (strcmp(*argv, "des-cbc") == 0)
952 else if (strcmp(*argv, "des-ede3") == 0)
953 doit[D_EDE3_DES] = 1;
956 # ifndef OPENSSL_NO_AES
957 if (strcmp(*argv, "aes-128-cbc") == 0)
958 doit[D_CBC_128_AES] = 1;
959 else if (strcmp(*argv, "aes-192-cbc") == 0)
960 doit[D_CBC_192_AES] = 1;
961 else if (strcmp(*argv, "aes-256-cbc") == 0)
962 doit[D_CBC_256_AES] = 1;
963 else if (strcmp(*argv, "aes-128-ige") == 0)
964 doit[D_IGE_128_AES] = 1;
965 else if (strcmp(*argv, "aes-192-ige") == 0)
966 doit[D_IGE_192_AES] = 1;
967 else if (strcmp(*argv, "aes-256-ige") == 0)
968 doit[D_IGE_256_AES] = 1;
971 # ifndef OPENSSL_NO_CAMELLIA
972 if (strcmp(*argv, "camellia-128-cbc") == 0)
973 doit[D_CBC_128_CML] = 1;
974 else if (strcmp(*argv, "camellia-192-cbc") == 0)
975 doit[D_CBC_192_CML] = 1;
976 else if (strcmp(*argv, "camellia-256-cbc") == 0)
977 doit[D_CBC_256_CML] = 1;
980 # ifndef OPENSSL_NO_RSA
981 # if 0 /* was: #ifdef RSAref */
982 if (strcmp(*argv, "rsaref") == 0) {
983 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
988 if (strcmp(*argv, "openssl") == 0) {
989 RSA_set_default_method(RSA_PKCS1_SSLeay());
993 # endif /* !OPENSSL_NO_RSA */
994 if (strcmp(*argv, "dsa512") == 0)
995 dsa_doit[R_DSA_512] = 2;
996 else if (strcmp(*argv, "dsa1024") == 0)
997 dsa_doit[R_DSA_1024] = 2;
998 else if (strcmp(*argv, "dsa2048") == 0)
999 dsa_doit[R_DSA_2048] = 2;
1000 else if (strcmp(*argv, "rsa512") == 0)
1001 rsa_doit[R_RSA_512] = 2;
1002 else if (strcmp(*argv, "rsa1024") == 0)
1003 rsa_doit[R_RSA_1024] = 2;
1004 else if (strcmp(*argv, "rsa2048") == 0)
1005 rsa_doit[R_RSA_2048] = 2;
1006 else if (strcmp(*argv, "rsa4096") == 0)
1007 rsa_doit[R_RSA_4096] = 2;
1009 # ifndef OPENSSL_NO_RC2
1010 if (strcmp(*argv, "rc2-cbc") == 0)
1011 doit[D_CBC_RC2] = 1;
1012 else if (strcmp(*argv, "rc2") == 0)
1013 doit[D_CBC_RC2] = 1;
1016 # ifndef OPENSSL_NO_RC5
1017 if (strcmp(*argv, "rc5-cbc") == 0)
1018 doit[D_CBC_RC5] = 1;
1019 else if (strcmp(*argv, "rc5") == 0)
1020 doit[D_CBC_RC5] = 1;
1023 # ifndef OPENSSL_NO_IDEA
1024 if (strcmp(*argv, "idea-cbc") == 0)
1025 doit[D_CBC_IDEA] = 1;
1026 else if (strcmp(*argv, "idea") == 0)
1027 doit[D_CBC_IDEA] = 1;
1030 # ifndef OPENSSL_NO_SEED
1031 if (strcmp(*argv, "seed-cbc") == 0)
1032 doit[D_CBC_SEED] = 1;
1033 else if (strcmp(*argv, "seed") == 0)
1034 doit[D_CBC_SEED] = 1;
1037 # ifndef OPENSSL_NO_BF
1038 if (strcmp(*argv, "bf-cbc") == 0)
1040 else if (strcmp(*argv, "blowfish") == 0)
1042 else if (strcmp(*argv, "bf") == 0)
1046 # ifndef OPENSSL_NO_CAST
1047 if (strcmp(*argv, "cast-cbc") == 0)
1048 doit[D_CBC_CAST] = 1;
1049 else if (strcmp(*argv, "cast") == 0)
1050 doit[D_CBC_CAST] = 1;
1051 else if (strcmp(*argv, "cast5") == 0)
1052 doit[D_CBC_CAST] = 1;
1055 # ifndef OPENSSL_NO_DES
1056 if (strcmp(*argv, "des") == 0) {
1057 doit[D_CBC_DES] = 1;
1058 doit[D_EDE3_DES] = 1;
1061 # ifndef OPENSSL_NO_AES
1062 if (strcmp(*argv, "aes") == 0) {
1063 doit[D_CBC_128_AES] = 1;
1064 doit[D_CBC_192_AES] = 1;
1065 doit[D_CBC_256_AES] = 1;
1068 # ifndef OPENSSL_NO_CAMELLIA
1069 if (strcmp(*argv, "camellia") == 0) {
1070 doit[D_CBC_128_CML] = 1;
1071 doit[D_CBC_192_CML] = 1;
1072 doit[D_CBC_256_CML] = 1;
1075 # ifndef OPENSSL_NO_RSA
1076 if (strcmp(*argv, "rsa") == 0) {
1077 rsa_doit[R_RSA_512] = 1;
1078 rsa_doit[R_RSA_1024] = 1;
1079 rsa_doit[R_RSA_2048] = 1;
1080 rsa_doit[R_RSA_4096] = 1;
1083 # ifndef OPENSSL_NO_DSA
1084 if (strcmp(*argv, "dsa") == 0) {
1085 dsa_doit[R_DSA_512] = 1;
1086 dsa_doit[R_DSA_1024] = 1;
1087 dsa_doit[R_DSA_2048] = 1;
1090 # ifndef OPENSSL_NO_ECDSA
1091 if (strcmp(*argv, "ecdsap160") == 0)
1092 ecdsa_doit[R_EC_P160] = 2;
1093 else if (strcmp(*argv, "ecdsap192") == 0)
1094 ecdsa_doit[R_EC_P192] = 2;
1095 else if (strcmp(*argv, "ecdsap224") == 0)
1096 ecdsa_doit[R_EC_P224] = 2;
1097 else if (strcmp(*argv, "ecdsap256") == 0)
1098 ecdsa_doit[R_EC_P256] = 2;
1099 else if (strcmp(*argv, "ecdsap384") == 0)
1100 ecdsa_doit[R_EC_P384] = 2;
1101 else if (strcmp(*argv, "ecdsap521") == 0)
1102 ecdsa_doit[R_EC_P521] = 2;
1103 else if (strcmp(*argv, "ecdsak163") == 0)
1104 ecdsa_doit[R_EC_K163] = 2;
1105 else if (strcmp(*argv, "ecdsak233") == 0)
1106 ecdsa_doit[R_EC_K233] = 2;
1107 else if (strcmp(*argv, "ecdsak283") == 0)
1108 ecdsa_doit[R_EC_K283] = 2;
1109 else if (strcmp(*argv, "ecdsak409") == 0)
1110 ecdsa_doit[R_EC_K409] = 2;
1111 else if (strcmp(*argv, "ecdsak571") == 0)
1112 ecdsa_doit[R_EC_K571] = 2;
1113 else if (strcmp(*argv, "ecdsab163") == 0)
1114 ecdsa_doit[R_EC_B163] = 2;
1115 else if (strcmp(*argv, "ecdsab233") == 0)
1116 ecdsa_doit[R_EC_B233] = 2;
1117 else if (strcmp(*argv, "ecdsab283") == 0)
1118 ecdsa_doit[R_EC_B283] = 2;
1119 else if (strcmp(*argv, "ecdsab409") == 0)
1120 ecdsa_doit[R_EC_B409] = 2;
1121 else if (strcmp(*argv, "ecdsab571") == 0)
1122 ecdsa_doit[R_EC_B571] = 2;
1123 else if (strcmp(*argv, "ecdsa") == 0) {
1124 for (i = 0; i < EC_NUM; i++)
1128 # ifndef OPENSSL_NO_ECDH
1129 if (strcmp(*argv, "ecdhp160") == 0)
1130 ecdh_doit[R_EC_P160] = 2;
1131 else if (strcmp(*argv, "ecdhp192") == 0)
1132 ecdh_doit[R_EC_P192] = 2;
1133 else if (strcmp(*argv, "ecdhp224") == 0)
1134 ecdh_doit[R_EC_P224] = 2;
1135 else if (strcmp(*argv, "ecdhp256") == 0)
1136 ecdh_doit[R_EC_P256] = 2;
1137 else if (strcmp(*argv, "ecdhp384") == 0)
1138 ecdh_doit[R_EC_P384] = 2;
1139 else if (strcmp(*argv, "ecdhp521") == 0)
1140 ecdh_doit[R_EC_P521] = 2;
1141 else if (strcmp(*argv, "ecdhk163") == 0)
1142 ecdh_doit[R_EC_K163] = 2;
1143 else if (strcmp(*argv, "ecdhk233") == 0)
1144 ecdh_doit[R_EC_K233] = 2;
1145 else if (strcmp(*argv, "ecdhk283") == 0)
1146 ecdh_doit[R_EC_K283] = 2;
1147 else if (strcmp(*argv, "ecdhk409") == 0)
1148 ecdh_doit[R_EC_K409] = 2;
1149 else if (strcmp(*argv, "ecdhk571") == 0)
1150 ecdh_doit[R_EC_K571] = 2;
1151 else if (strcmp(*argv, "ecdhb163") == 0)
1152 ecdh_doit[R_EC_B163] = 2;
1153 else if (strcmp(*argv, "ecdhb233") == 0)
1154 ecdh_doit[R_EC_B233] = 2;
1155 else if (strcmp(*argv, "ecdhb283") == 0)
1156 ecdh_doit[R_EC_B283] = 2;
1157 else if (strcmp(*argv, "ecdhb409") == 0)
1158 ecdh_doit[R_EC_B409] = 2;
1159 else if (strcmp(*argv, "ecdhb571") == 0)
1160 ecdh_doit[R_EC_B571] = 2;
1161 else if (strcmp(*argv, "ecdh") == 0) {
1162 for (i = 0; i < EC_NUM; i++)
1167 BIO_printf(bio_err, "Error: bad option or value\n");
1168 BIO_printf(bio_err, "\n");
1169 BIO_printf(bio_err, "Available values:\n");
1170 # ifndef OPENSSL_NO_MD2
1171 BIO_printf(bio_err, "md2 ");
1173 # ifndef OPENSSL_NO_MDC2
1174 BIO_printf(bio_err, "mdc2 ");
1176 # ifndef OPENSSL_NO_MD4
1177 BIO_printf(bio_err, "md4 ");
1179 # ifndef OPENSSL_NO_MD5
1180 BIO_printf(bio_err, "md5 ");
1181 # ifndef OPENSSL_NO_HMAC
1182 BIO_printf(bio_err, "hmac ");
1185 # ifndef OPENSSL_NO_SHA1
1186 BIO_printf(bio_err, "sha1 ");
1188 # ifndef OPENSSL_NO_SHA256
1189 BIO_printf(bio_err, "sha256 ");
1191 # ifndef OPENSSL_NO_SHA512
1192 BIO_printf(bio_err, "sha512 ");
1194 # ifndef OPENSSL_NO_RIPEMD160
1195 BIO_printf(bio_err, "rmd160");
1197 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1198 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1199 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
1200 BIO_printf(bio_err, "\n");
1203 # ifndef OPENSSL_NO_IDEA
1204 BIO_printf(bio_err, "idea-cbc ");
1206 # ifndef OPENSSL_NO_SEED
1207 BIO_printf(bio_err, "seed-cbc ");
1209 # ifndef OPENSSL_NO_RC2
1210 BIO_printf(bio_err, "rc2-cbc ");
1212 # ifndef OPENSSL_NO_RC5
1213 BIO_printf(bio_err, "rc5-cbc ");
1215 # ifndef OPENSSL_NO_BF
1216 BIO_printf(bio_err, "bf-cbc");
1218 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1219 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1220 BIO_printf(bio_err, "\n");
1222 # ifndef OPENSSL_NO_DES
1223 BIO_printf(bio_err, "des-cbc des-ede3 ");
1225 # ifndef OPENSSL_NO_AES
1226 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1227 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1229 # ifndef OPENSSL_NO_CAMELLIA
1230 BIO_printf(bio_err, "\n");
1232 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1234 # ifndef OPENSSL_NO_RC4
1235 BIO_printf(bio_err, "rc4");
1237 BIO_printf(bio_err, "\n");
1239 # ifndef OPENSSL_NO_RSA
1240 BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
1243 # ifndef OPENSSL_NO_DSA
1244 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1246 # ifndef OPENSSL_NO_ECDSA
1247 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1248 "ecdsap256 ecdsap384 ecdsap521\n");
1250 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1252 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1253 BIO_printf(bio_err, "ecdsa\n");
1255 # ifndef OPENSSL_NO_ECDH
1256 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1257 "ecdhp256 ecdhp384 ecdhp521\n");
1259 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1261 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1262 BIO_printf(bio_err, "ecdh\n");
1265 # ifndef OPENSSL_NO_IDEA
1266 BIO_printf(bio_err, "idea ");
1268 # ifndef OPENSSL_NO_SEED
1269 BIO_printf(bio_err, "seed ");
1271 # ifndef OPENSSL_NO_RC2
1272 BIO_printf(bio_err, "rc2 ");
1274 # ifndef OPENSSL_NO_DES
1275 BIO_printf(bio_err, "des ");
1277 # ifndef OPENSSL_NO_AES
1278 BIO_printf(bio_err, "aes ");
1280 # ifndef OPENSSL_NO_CAMELLIA
1281 BIO_printf(bio_err, "camellia ");
1283 # ifndef OPENSSL_NO_RSA
1284 BIO_printf(bio_err, "rsa ");
1286 # ifndef OPENSSL_NO_BF
1287 BIO_printf(bio_err, "blowfish");
1289 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1290 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1291 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1292 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1293 BIO_printf(bio_err, "\n");
1296 BIO_printf(bio_err, "\n");
1297 BIO_printf(bio_err, "Available options:\n");
1298 # if defined(TIMES) || defined(USE_TOD)
1299 BIO_printf(bio_err, "-elapsed "
1300 "measure time in real time instead of CPU user time.\n");
1302 # ifndef OPENSSL_NO_ENGINE
1305 "use engine e, possibly a hardware device.\n");
1307 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1310 "time decryption instead of encryption (only EVP).\n");
1313 "produce machine readable output.\n");
1316 "-multi n " "run n benchmarks in parallel.\n");
1326 if (multi && do_multi(multi))
1331 for (i = 0; i < ALGOR_NUM; i++) {
1335 for (i = 0; i < RSA_NUM; i++)
1337 for (i = 0; i < DSA_NUM; i++)
1340 for (i = 0; i < ALGOR_NUM; i++)
1344 if (usertime == 0 && !mr)
1346 "You have chosen to measure elapsed time "
1347 "instead of user CPU time.\n");
1348 if (usertime <= 0 && !mr) {
1350 "To get the most accurate results, try to run this\n");
1351 BIO_printf(bio_err, "program when this computer is idle.\n");
1353 # ifndef OPENSSL_NO_RSA
1354 for (i = 0; i < RSA_NUM; i++) {
1355 const unsigned char *p;
1358 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1359 if (rsa_key[i] == NULL) {
1360 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1368 : "Loaded RSA key, %d bit modulus and e= 0x",
1369 BN_num_bits(rsa_key[i]->n));
1370 BN_print(bio_err, rsa_key[i]->e);
1371 BIO_printf(bio_err, "\n");
1377 # ifndef OPENSSL_NO_DSA
1378 dsa_key[0] = get_dsa512();
1379 dsa_key[1] = get_dsa1024();
1380 dsa_key[2] = get_dsa2048();
1383 # ifndef OPENSSL_NO_DES
1384 DES_set_key_unchecked(&key, &sch);
1385 DES_set_key_unchecked(&key2, &sch2);
1386 DES_set_key_unchecked(&key3, &sch3);
1388 # ifndef OPENSSL_NO_AES
1389 AES_set_encrypt_key(key16, 128, &aes_ks1);
1390 AES_set_encrypt_key(key24, 192, &aes_ks2);
1391 AES_set_encrypt_key(key32, 256, &aes_ks3);
1393 # ifndef OPENSSL_NO_CAMELLIA
1394 Camellia_set_key(key16, 128, &camellia_ks1);
1395 Camellia_set_key(ckey24, 192, &camellia_ks2);
1396 Camellia_set_key(ckey32, 256, &camellia_ks3);
1398 # ifndef OPENSSL_NO_IDEA
1399 idea_set_encrypt_key(key16, &idea_ks);
1401 # ifndef OPENSSL_NO_SEED
1402 SEED_set_key(key16, &seed_ks);
1404 # ifndef OPENSSL_NO_RC4
1405 RC4_set_key(&rc4_ks, 16, key16);
1407 # ifndef OPENSSL_NO_RC2
1408 RC2_set_key(&rc2_ks, 16, key16, 128);
1410 # ifndef OPENSSL_NO_RC5
1411 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1413 # ifndef OPENSSL_NO_BF
1414 BF_set_key(&bf_ks, 16, key16);
1416 # ifndef OPENSSL_NO_CAST
1417 CAST_set_key(&cast_ks, 16, key16);
1419 # ifndef OPENSSL_NO_RSA
1420 memset(rsa_c, 0, sizeof(rsa_c));
1423 # ifndef OPENSSL_NO_DES
1424 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1430 for (it = count; it; it--)
1431 DES_ecb_encrypt((DES_cblock *)buf,
1432 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1436 c[D_MD2][0] = count / 10;
1437 c[D_MDC2][0] = count / 10;
1438 c[D_MD4][0] = count;
1439 c[D_MD5][0] = count;
1440 c[D_HMAC][0] = count;
1441 c[D_SHA1][0] = count;
1442 c[D_RMD160][0] = count;
1443 c[D_RC4][0] = count * 5;
1444 c[D_CBC_DES][0] = count;
1445 c[D_EDE3_DES][0] = count / 3;
1446 c[D_CBC_IDEA][0] = count;
1447 c[D_CBC_SEED][0] = count;
1448 c[D_CBC_RC2][0] = count;
1449 c[D_CBC_RC5][0] = count;
1450 c[D_CBC_BF][0] = count;
1451 c[D_CBC_CAST][0] = count;
1452 c[D_CBC_128_AES][0] = count;
1453 c[D_CBC_192_AES][0] = count;
1454 c[D_CBC_256_AES][0] = count;
1455 c[D_CBC_128_CML][0] = count;
1456 c[D_CBC_192_CML][0] = count;
1457 c[D_CBC_256_CML][0] = count;
1458 c[D_SHA256][0] = count;
1459 c[D_SHA512][0] = count;
1460 c[D_IGE_128_AES][0] = count;
1461 c[D_IGE_192_AES][0] = count;
1462 c[D_IGE_256_AES][0] = count;
1464 for (i = 1; i < SIZE_NUM; i++) {
1465 c[D_MD2][i] = c[D_MD2][0] * 4 * lengths[0] / lengths[i];
1466 c[D_MDC2][i] = c[D_MDC2][0] * 4 * lengths[0] / lengths[i];
1467 c[D_MD4][i] = c[D_MD4][0] * 4 * lengths[0] / lengths[i];
1468 c[D_MD5][i] = c[D_MD5][0] * 4 * lengths[0] / lengths[i];
1469 c[D_HMAC][i] = c[D_HMAC][0] * 4 * lengths[0] / lengths[i];
1470 c[D_SHA1][i] = c[D_SHA1][0] * 4 * lengths[0] / lengths[i];
1471 c[D_RMD160][i] = c[D_RMD160][0] * 4 * lengths[0] / lengths[i];
1472 c[D_SHA256][i] = c[D_SHA256][0] * 4 * lengths[0] / lengths[i];
1473 c[D_SHA512][i] = c[D_SHA512][0] * 4 * lengths[0] / lengths[i];
1475 for (i = 1; i < SIZE_NUM; i++) {
1478 l0 = (long)lengths[i - 1];
1479 l1 = (long)lengths[i];
1480 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1481 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1482 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1483 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1484 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1485 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1486 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1487 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1488 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1489 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1490 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1491 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1492 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1493 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1494 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1495 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1496 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1497 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1499 # ifndef OPENSSL_NO_RSA
1500 rsa_c[R_RSA_512][0] = count / 2000;
1501 rsa_c[R_RSA_512][1] = count / 400;
1502 for (i = 1; i < RSA_NUM; i++) {
1503 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1504 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1505 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1508 if (rsa_c[i][0] == 0) {
1516 # ifndef OPENSSL_NO_DSA
1517 dsa_c[R_DSA_512][0] = count / 1000;
1518 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1519 for (i = 1; i < DSA_NUM; i++) {
1520 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1521 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1522 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1525 if (dsa_c[i] == 0) {
1533 # ifndef OPENSSL_NO_ECDSA
1534 ecdsa_c[R_EC_P160][0] = count / 1000;
1535 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1536 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1537 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1538 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1539 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1542 if (ecdsa_c[i] == 0) {
1548 ecdsa_c[R_EC_K163][0] = count / 1000;
1549 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1550 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1551 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1552 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1553 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1556 if (ecdsa_c[i] == 0) {
1562 ecdsa_c[R_EC_B163][0] = count / 1000;
1563 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1564 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1565 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1566 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1567 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1570 if (ecdsa_c[i] == 0) {
1578 # ifndef OPENSSL_NO_ECDH
1579 ecdh_c[R_EC_P160][0] = count / 1000;
1580 ecdh_c[R_EC_P160][1] = count / 1000;
1581 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1582 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1583 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1584 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1587 if (ecdh_c[i] == 0) {
1593 ecdh_c[R_EC_K163][0] = count / 1000;
1594 ecdh_c[R_EC_K163][1] = count / 1000;
1595 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1596 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1597 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1598 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1601 if (ecdh_c[i] == 0) {
1607 ecdh_c[R_EC_B163][0] = count / 1000;
1608 ecdh_c[R_EC_B163][1] = count / 1000;
1609 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1610 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1611 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1612 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1615 if (ecdh_c[i] == 0) {
1623 # define COND(d) (count < (d))
1624 # define COUNT(d) (d)
1626 /* not worth fixing */
1627 # error "You cannot disable DES on systems without SIGALRM."
1628 # endif /* OPENSSL_NO_DES */
1630 # define COND(c) (run)
1631 # define COUNT(d) (count)
1632 signal(SIGALRM, sig_done);
1633 # endif /* SIGALRM */
1635 # ifndef OPENSSL_NO_MD2
1637 for (j = 0; j < SIZE_NUM; j++) {
1638 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1640 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1641 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1644 print_result(D_MD2, j, count, d);
1648 # ifndef OPENSSL_NO_MDC2
1650 for (j = 0; j < SIZE_NUM; j++) {
1651 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1653 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1654 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1657 print_result(D_MDC2, j, count, d);
1662 # ifndef OPENSSL_NO_MD4
1664 for (j = 0; j < SIZE_NUM; j++) {
1665 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1667 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1668 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1669 NULL, EVP_md4(), NULL);
1671 print_result(D_MD4, j, count, d);
1676 # ifndef OPENSSL_NO_MD5
1678 for (j = 0; j < SIZE_NUM; j++) {
1679 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1681 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1682 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md5[0]),
1683 NULL, EVP_get_digestbyname("md5"), NULL);
1685 print_result(D_MD5, j, count, d);
1690 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1694 HMAC_CTX_init(&hctx);
1695 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1696 16, EVP_md5(), NULL);
1698 for (j = 0; j < SIZE_NUM; j++) {
1699 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1701 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1702 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1703 HMAC_Update(&hctx, buf, lengths[j]);
1704 HMAC_Final(&hctx, &(hmac[0]), NULL);
1707 print_result(D_HMAC, j, count, d);
1709 HMAC_CTX_cleanup(&hctx);
1712 # ifndef OPENSSL_NO_SHA
1714 for (j = 0; j < SIZE_NUM; j++) {
1715 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1717 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1718 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1721 print_result(D_SHA1, j, count, d);
1724 # ifndef OPENSSL_NO_SHA256
1725 if (doit[D_SHA256]) {
1726 for (j = 0; j < SIZE_NUM; j++) {
1727 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1729 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1730 SHA256(buf, lengths[j], sha256);
1732 print_result(D_SHA256, j, count, d);
1737 # ifndef OPENSSL_NO_SHA512
1738 if (doit[D_SHA512]) {
1739 for (j = 0; j < SIZE_NUM; j++) {
1740 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1742 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1743 SHA512(buf, lengths[j], sha512);
1745 print_result(D_SHA512, j, count, d);
1751 # ifndef OPENSSL_NO_RIPEMD
1752 if (doit[D_RMD160]) {
1753 for (j = 0; j < SIZE_NUM; j++) {
1754 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1756 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1757 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1758 EVP_ripemd160(), NULL);
1760 print_result(D_RMD160, j, count, d);
1764 # ifndef OPENSSL_NO_RC4
1766 for (j = 0; j < SIZE_NUM; j++) {
1767 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1769 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1770 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1772 print_result(D_RC4, j, count, d);
1776 # ifndef OPENSSL_NO_DES
1777 if (doit[D_CBC_DES]) {
1778 for (j = 0; j < SIZE_NUM; j++) {
1779 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1781 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1782 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1783 &DES_iv, DES_ENCRYPT);
1785 print_result(D_CBC_DES, j, count, d);
1789 if (doit[D_EDE3_DES]) {
1790 for (j = 0; j < SIZE_NUM; j++) {
1791 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1793 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1794 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1796 &DES_iv, DES_ENCRYPT);
1798 print_result(D_EDE3_DES, j, count, d);
1802 # ifndef OPENSSL_NO_AES
1803 if (doit[D_CBC_128_AES]) {
1804 for (j = 0; j < SIZE_NUM; j++) {
1805 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1808 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1809 AES_cbc_encrypt(buf, buf,
1810 (unsigned long)lengths[j], &aes_ks1,
1813 print_result(D_CBC_128_AES, j, count, d);
1816 if (doit[D_CBC_192_AES]) {
1817 for (j = 0; j < SIZE_NUM; j++) {
1818 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1821 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1822 AES_cbc_encrypt(buf, buf,
1823 (unsigned long)lengths[j], &aes_ks2,
1826 print_result(D_CBC_192_AES, j, count, d);
1829 if (doit[D_CBC_256_AES]) {
1830 for (j = 0; j < SIZE_NUM; j++) {
1831 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1834 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1835 AES_cbc_encrypt(buf, buf,
1836 (unsigned long)lengths[j], &aes_ks3,
1839 print_result(D_CBC_256_AES, j, count, d);
1843 if (doit[D_IGE_128_AES]) {
1844 for (j = 0; j < SIZE_NUM; j++) {
1845 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1848 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1849 AES_ige_encrypt(buf, buf2,
1850 (unsigned long)lengths[j], &aes_ks1,
1853 print_result(D_IGE_128_AES, j, count, d);
1856 if (doit[D_IGE_192_AES]) {
1857 for (j = 0; j < SIZE_NUM; j++) {
1858 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1861 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1862 AES_ige_encrypt(buf, buf2,
1863 (unsigned long)lengths[j], &aes_ks2,
1866 print_result(D_IGE_192_AES, j, count, d);
1869 if (doit[D_IGE_256_AES]) {
1870 for (j = 0; j < SIZE_NUM; j++) {
1871 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1874 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1875 AES_ige_encrypt(buf, buf2,
1876 (unsigned long)lengths[j], &aes_ks3,
1879 print_result(D_IGE_256_AES, j, count, d);
1883 # ifndef OPENSSL_NO_CAMELLIA
1884 if (doit[D_CBC_128_CML]) {
1885 for (j = 0; j < SIZE_NUM; j++) {
1886 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1889 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1890 Camellia_cbc_encrypt(buf, buf,
1891 (unsigned long)lengths[j], &camellia_ks1,
1892 iv, CAMELLIA_ENCRYPT);
1894 print_result(D_CBC_128_CML, j, count, d);
1897 if (doit[D_CBC_192_CML]) {
1898 for (j = 0; j < SIZE_NUM; j++) {
1899 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1902 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1903 Camellia_cbc_encrypt(buf, buf,
1904 (unsigned long)lengths[j], &camellia_ks2,
1905 iv, CAMELLIA_ENCRYPT);
1907 print_result(D_CBC_192_CML, j, count, d);
1910 if (doit[D_CBC_256_CML]) {
1911 for (j = 0; j < SIZE_NUM; j++) {
1912 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1915 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1916 Camellia_cbc_encrypt(buf, buf,
1917 (unsigned long)lengths[j], &camellia_ks3,
1918 iv, CAMELLIA_ENCRYPT);
1920 print_result(D_CBC_256_CML, j, count, d);
1924 # ifndef OPENSSL_NO_IDEA
1925 if (doit[D_CBC_IDEA]) {
1926 for (j = 0; j < SIZE_NUM; j++) {
1927 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1929 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1930 idea_cbc_encrypt(buf, buf,
1931 (unsigned long)lengths[j], &idea_ks,
1934 print_result(D_CBC_IDEA, j, count, d);
1938 # ifndef OPENSSL_NO_SEED
1939 if (doit[D_CBC_SEED]) {
1940 for (j = 0; j < SIZE_NUM; j++) {
1941 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1943 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1944 SEED_cbc_encrypt(buf, buf,
1945 (unsigned long)lengths[j], &seed_ks, iv, 1);
1947 print_result(D_CBC_SEED, j, count, d);
1951 # ifndef OPENSSL_NO_RC2
1952 if (doit[D_CBC_RC2]) {
1953 for (j = 0; j < SIZE_NUM; j++) {
1954 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1956 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1957 RC2_cbc_encrypt(buf, buf,
1958 (unsigned long)lengths[j], &rc2_ks,
1961 print_result(D_CBC_RC2, j, count, d);
1965 # ifndef OPENSSL_NO_RC5
1966 if (doit[D_CBC_RC5]) {
1967 for (j = 0; j < SIZE_NUM; j++) {
1968 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1970 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1971 RC5_32_cbc_encrypt(buf, buf,
1972 (unsigned long)lengths[j], &rc5_ks,
1975 print_result(D_CBC_RC5, j, count, d);
1979 # ifndef OPENSSL_NO_BF
1980 if (doit[D_CBC_BF]) {
1981 for (j = 0; j < SIZE_NUM; j++) {
1982 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1984 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1985 BF_cbc_encrypt(buf, buf,
1986 (unsigned long)lengths[j], &bf_ks,
1989 print_result(D_CBC_BF, j, count, d);
1993 # ifndef OPENSSL_NO_CAST
1994 if (doit[D_CBC_CAST]) {
1995 for (j = 0; j < SIZE_NUM; j++) {
1996 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1998 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1999 CAST_cbc_encrypt(buf, buf,
2000 (unsigned long)lengths[j], &cast_ks,
2003 print_result(D_CBC_CAST, j, count, d);
2009 for (j = 0; j < SIZE_NUM; j++) {
2014 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
2016 * -O3 -fschedule-insns messes up an optimization here!
2017 * names[D_EVP] somehow becomes NULL
2019 print_message(names[D_EVP], save_count, lengths[j]);
2021 EVP_CIPHER_CTX_init(&ctx);
2023 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
2025 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
2026 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2030 for (count = 0, run = 1;
2031 COND(save_count * 4 * lengths[0] / lengths[j]);
2033 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
2035 for (count = 0, run = 1;
2036 COND(save_count * 4 * lengths[0] / lengths[j]);
2038 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
2040 EVP_DecryptFinal_ex(&ctx, buf, &outl);
2042 EVP_EncryptFinal_ex(&ctx, buf, &outl);
2044 EVP_CIPHER_CTX_cleanup(&ctx);
2047 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2048 print_message(names[D_EVP], save_count, lengths[j]);
2051 for (count = 0, run = 1;
2052 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2053 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2057 print_result(D_EVP, j, count, d);
2061 RAND_pseudo_bytes(buf, 36);
2062 # ifndef OPENSSL_NO_RSA
2063 for (j = 0; j < RSA_NUM; j++) {
2067 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2070 "RSA sign failure. No RSA sign will be done.\n");
2071 ERR_print_errors(bio_err);
2074 pkey_print_message("private", "rsa",
2075 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2076 /* RSA_blinding_on(rsa_key[j],NULL); */
2078 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2079 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2080 &rsa_num, rsa_key[j]);
2082 BIO_printf(bio_err, "RSA sign failure\n");
2083 ERR_print_errors(bio_err);
2090 mr ? "+R1:%ld:%d:%.2f\n"
2091 : "%ld %d bit private RSA's in %.2fs\n",
2092 count, rsa_bits[j], d);
2093 rsa_results[j][0] = d / (double)count;
2098 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2101 "RSA verify failure. No RSA verify will be done.\n");
2102 ERR_print_errors(bio_err);
2105 pkey_print_message("public", "rsa",
2106 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2108 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2109 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2110 rsa_num, rsa_key[j]);
2112 BIO_printf(bio_err, "RSA verify failure\n");
2113 ERR_print_errors(bio_err);
2120 mr ? "+R2:%ld:%d:%.2f\n"
2121 : "%ld %d bit public RSA's in %.2fs\n",
2122 count, rsa_bits[j], d);
2123 rsa_results[j][1] = d / (double)count;
2127 if (rsa_count <= 1) {
2128 /* if longer than 10s, don't do any more */
2129 for (j++; j < RSA_NUM; j++)
2135 RAND_pseudo_bytes(buf, 20);
2136 # ifndef OPENSSL_NO_DSA
2137 if (RAND_status() != 1) {
2138 RAND_seed(rnd_seed, sizeof rnd_seed);
2141 for (j = 0; j < DSA_NUM; j++) {
2148 /* DSA_generate_key(dsa_key[j]); */
2149 /* DSA_sign_setup(dsa_key[j],NULL); */
2150 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2153 "DSA sign failure. No DSA sign will be done.\n");
2154 ERR_print_errors(bio_err);
2157 pkey_print_message("sign", "dsa",
2158 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2160 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2161 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2163 BIO_printf(bio_err, "DSA sign failure\n");
2164 ERR_print_errors(bio_err);
2171 mr ? "+R3:%ld:%d:%.2f\n"
2172 : "%ld %d bit DSA signs in %.2fs\n",
2173 count, dsa_bits[j], d);
2174 dsa_results[j][0] = d / (double)count;
2178 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2181 "DSA verify failure. No DSA verify will be done.\n");
2182 ERR_print_errors(bio_err);
2185 pkey_print_message("verify", "dsa",
2186 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2188 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2189 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2191 BIO_printf(bio_err, "DSA verify failure\n");
2192 ERR_print_errors(bio_err);
2199 mr ? "+R4:%ld:%d:%.2f\n"
2200 : "%ld %d bit DSA verify in %.2fs\n",
2201 count, dsa_bits[j], d);
2202 dsa_results[j][1] = d / (double)count;
2205 if (rsa_count <= 1) {
2206 /* if longer than 10s, don't do any more */
2207 for (j++; j < DSA_NUM; j++)
2215 # ifndef OPENSSL_NO_ECDSA
2216 if (RAND_status() != 1) {
2217 RAND_seed(rnd_seed, sizeof rnd_seed);
2220 for (j = 0; j < EC_NUM; j++) {
2224 continue; /* Ignore Curve */
2225 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2226 if (ecdsa[j] == NULL) {
2227 BIO_printf(bio_err, "ECDSA failure.\n");
2228 ERR_print_errors(bio_err);
2232 EC_KEY_precompute_mult(ecdsa[j], NULL);
2234 /* Perform ECDSA signature test */
2235 EC_KEY_generate_key(ecdsa[j]);
2236 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2239 "ECDSA sign failure. No ECDSA sign will be done.\n");
2240 ERR_print_errors(bio_err);
2243 pkey_print_message("sign", "ecdsa",
2245 test_curves_bits[j], ECDSA_SECONDS);
2248 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2249 ret = ECDSA_sign(0, buf, 20,
2250 ecdsasig, &ecdsasiglen, ecdsa[j]);
2252 BIO_printf(bio_err, "ECDSA sign failure\n");
2253 ERR_print_errors(bio_err);
2261 mr ? "+R5:%ld:%d:%.2f\n" :
2262 "%ld %d bit ECDSA signs in %.2fs \n",
2263 count, test_curves_bits[j], d);
2264 ecdsa_results[j][0] = d / (double)count;
2268 /* Perform ECDSA verification test */
2269 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2272 "ECDSA verify failure. No ECDSA verify will be done.\n");
2273 ERR_print_errors(bio_err);
2276 pkey_print_message("verify", "ecdsa",
2278 test_curves_bits[j], ECDSA_SECONDS);
2280 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2282 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2285 BIO_printf(bio_err, "ECDSA verify failure\n");
2286 ERR_print_errors(bio_err);
2293 mr ? "+R6:%ld:%d:%.2f\n"
2294 : "%ld %d bit ECDSA verify in %.2fs\n",
2295 count, test_curves_bits[j], d);
2296 ecdsa_results[j][1] = d / (double)count;
2299 if (rsa_count <= 1) {
2300 /* if longer than 10s, don't do any more */
2301 for (j++; j < EC_NUM; j++)
2310 # ifndef OPENSSL_NO_ECDH
2311 if (RAND_status() != 1) {
2312 RAND_seed(rnd_seed, sizeof rnd_seed);
2315 for (j = 0; j < EC_NUM; j++) {
2318 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2319 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2320 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2321 BIO_printf(bio_err, "ECDH failure.\n");
2322 ERR_print_errors(bio_err);
2325 /* generate two ECDH key pairs */
2326 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2327 !EC_KEY_generate_key(ecdh_b[j])) {
2328 BIO_printf(bio_err, "ECDH key generation failure.\n");
2329 ERR_print_errors(bio_err);
2333 * If field size is not more than 24 octets, then use SHA-1
2334 * hash of result; otherwise, use result (see section 4.8 of
2335 * draft-ietf-tls-ecc-03.txt).
2337 int field_size, outlen;
2338 void *(*kdf) (const void *in, size_t inlen, void *out,
2341 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2342 if (field_size <= 24 * 8) {
2343 outlen = KDF1_SHA1_len;
2346 outlen = (field_size + 7) / 8;
2350 ECDH_compute_key(secret_a, outlen,
2351 EC_KEY_get0_public_key(ecdh_b[j]),
2354 ECDH_compute_key(secret_b, outlen,
2355 EC_KEY_get0_public_key(ecdh_a[j]),
2357 if (secret_size_a != secret_size_b)
2362 for (secret_idx = 0; (secret_idx < secret_size_a)
2363 && (ecdh_checks == 1); secret_idx++) {
2364 if (secret_a[secret_idx] != secret_b[secret_idx])
2368 if (ecdh_checks == 0) {
2369 BIO_printf(bio_err, "ECDH computations don't match.\n");
2370 ERR_print_errors(bio_err);
2374 pkey_print_message("", "ecdh",
2376 test_curves_bits[j], ECDH_SECONDS);
2378 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2379 ECDH_compute_key(secret_a, outlen,
2380 EC_KEY_get0_public_key(ecdh_b[j]),
2385 mr ? "+R7:%ld:%d:%.2f\n" :
2386 "%ld %d-bit ECDH ops in %.2fs\n", count,
2387 test_curves_bits[j], d);
2388 ecdh_results[j][0] = d / (double)count;
2393 if (rsa_count <= 1) {
2394 /* if longer than 10s, don't do any more */
2395 for (j++; j < EC_NUM; j++)
2406 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2407 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2409 printf("%s ", BN_options());
2410 # ifndef OPENSSL_NO_MD2
2411 printf("%s ", MD2_options());
2413 # ifndef OPENSSL_NO_RC4
2414 printf("%s ", RC4_options());
2416 # ifndef OPENSSL_NO_DES
2417 printf("%s ", DES_options());
2419 # ifndef OPENSSL_NO_AES
2420 printf("%s ", AES_options());
2422 # ifndef OPENSSL_NO_IDEA
2423 printf("%s ", idea_options());
2425 # ifndef OPENSSL_NO_BF
2426 printf("%s ", BF_options());
2428 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2429 printf("available timing options: ");
2440 # define as_string(s) (#s)
2443 printf("HZ=%g", dbl);
2446 printf(" [sysconf value]");
2450 printf("timing function used: %s%s%s%s%s%s%s\n",
2451 (ftime_used ? "ftime" : ""),
2452 (ftime_used + times_used > 1 ? "," : ""),
2453 (times_used ? "times" : ""),
2454 (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
2455 (gettimeofday_used ? "gettimeofday" : ""),
2456 (ftime_used + times_used + gettimeofday_used + getrusage_used >
2457 1 ? "," : ""), (getrusage_used ? "getrusage" : ""));
2462 fprintf(stdout, "+H");
2465 "The 'numbers' are in 1000s of bytes per second processed.\n");
2466 fprintf(stdout, "type ");
2468 for (j = 0; j < SIZE_NUM; j++)
2469 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2470 fprintf(stdout, "\n");
2473 for (k = 0; k < ALGOR_NUM; k++) {
2477 fprintf(stdout, "+F:%d:%s", k, names[k]);
2479 fprintf(stdout, "%-13s", names[k]);
2480 for (j = 0; j < SIZE_NUM; j++) {
2481 if (results[k][j] > 10000 && !mr)
2482 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2484 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2486 fprintf(stdout, "\n");
2488 # ifndef OPENSSL_NO_RSA
2490 for (k = 0; k < RSA_NUM; k++) {
2494 printf("%18ssign verify sign/s verify/s\n", " ");
2498 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2499 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2501 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2502 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2503 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2506 # ifndef OPENSSL_NO_DSA
2508 for (k = 0; k < DSA_NUM; k++) {
2512 printf("%18ssign verify sign/s verify/s\n", " ");
2516 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2517 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2519 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2520 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2521 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2524 # ifndef OPENSSL_NO_ECDSA
2526 for (k = 0; k < EC_NUM; k++) {
2530 printf("%30ssign verify sign/s verify/s\n", " ");
2535 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2536 k, test_curves_bits[k],
2537 ecdsa_results[k][0], ecdsa_results[k][1]);
2540 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2541 test_curves_bits[k],
2542 test_curves_names[k],
2543 ecdsa_results[k][0], ecdsa_results[k][1],
2544 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2548 # ifndef OPENSSL_NO_ECDH
2550 for (k = 0; k < EC_NUM; k++) {
2554 printf("%30sop op/s\n", " ");
2558 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2559 k, test_curves_bits[k],
2560 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2563 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2564 test_curves_bits[k],
2565 test_curves_names[k],
2566 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2573 ERR_print_errors(bio_err);
2578 # ifndef OPENSSL_NO_RSA
2579 for (i = 0; i < RSA_NUM; i++)
2580 if (rsa_key[i] != NULL)
2581 RSA_free(rsa_key[i]);
2583 # ifndef OPENSSL_NO_DSA
2584 for (i = 0; i < DSA_NUM; i++)
2585 if (dsa_key[i] != NULL)
2586 DSA_free(dsa_key[i]);
2589 # ifndef OPENSSL_NO_ECDSA
2590 for (i = 0; i < EC_NUM; i++)
2591 if (ecdsa[i] != NULL)
2592 EC_KEY_free(ecdsa[i]);
2594 # ifndef OPENSSL_NO_ECDH
2595 for (i = 0; i < EC_NUM; i++) {
2596 if (ecdh_a[i] != NULL)
2597 EC_KEY_free(ecdh_a[i]);
2598 if (ecdh_b[i] != NULL)
2599 EC_KEY_free(ecdh_b[i]);
2607 static void print_message(const char *s, long num, int length)
2611 mr ? "+DT:%s:%d:%d\n"
2612 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2613 (void)BIO_flush(bio_err);
2617 mr ? "+DN:%s:%ld:%d\n"
2618 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2619 (void)BIO_flush(bio_err);
2626 static void pkey_print_message(const char *str, const char *str2, long num,
2631 mr ? "+DTP:%d:%s:%s:%d\n"
2632 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2633 (void)BIO_flush(bio_err);
2637 mr ? "+DNP:%ld:%d:%s:%s\n"
2638 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2639 (void)BIO_flush(bio_err);
2646 static void print_result(int alg, int run_no, int count, double time_used)
2649 mr ? "+R:%d:%s:%f\n"
2650 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2651 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2655 static char *sstrsep(char **string, const char *delim)
2658 char *token = *string;
2663 memset(isdelim, 0, sizeof isdelim);
2667 isdelim[(unsigned char)(*delim)] = 1;
2671 while (!isdelim[(unsigned char)(**string)]) {
2683 static int do_multi(int multi)
2688 static char sep[] = ":";
2690 fds = malloc(multi * sizeof *fds);
2691 for (n = 0; n < multi; ++n) {
2692 if (pipe(fd) == -1) {
2693 fprintf(stderr, "pipe failure\n");
2704 if (dup(fd[1]) == -1) {
2705 fprintf(stderr, "dup failed\n");
2713 printf("Forked child %d\n", n);
2716 /* for now, assume the pipe is long enough to take all the output */
2717 for (n = 0; n < multi; ++n) {
2722 f = fdopen(fds[n], "r");
2723 while (fgets(buf, sizeof buf, f)) {
2724 p = strchr(buf, '\n');
2727 if (buf[0] != '+') {
2728 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2732 printf("Got: %s from %d\n", buf, n);
2733 if (!strncmp(buf, "+F:", 3)) {
2738 alg = atoi(sstrsep(&p, sep));
2740 for (j = 0; j < SIZE_NUM; ++j)
2741 results[alg][j] += atof(sstrsep(&p, sep));
2742 } else if (!strncmp(buf, "+F2:", 4)) {
2747 k = atoi(sstrsep(&p, sep));
2750 d = atof(sstrsep(&p, sep));
2752 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2754 rsa_results[k][0] = d;
2756 d = atof(sstrsep(&p, sep));
2758 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2760 rsa_results[k][1] = d;
2761 } else if (!strncmp(buf, "+F2:", 4)) {
2766 k = atoi(sstrsep(&p, sep));
2769 d = atof(sstrsep(&p, sep));
2771 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2773 rsa_results[k][0] = d;
2775 d = atof(sstrsep(&p, sep));
2777 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2779 rsa_results[k][1] = d;
2780 } else if (!strncmp(buf, "+F3:", 4)) {
2785 k = atoi(sstrsep(&p, sep));
2788 d = atof(sstrsep(&p, sep));
2790 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2792 dsa_results[k][0] = d;
2794 d = atof(sstrsep(&p, sep));
2796 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2798 dsa_results[k][1] = d;
2800 # ifndef OPENSSL_NO_ECDSA
2801 else if (!strncmp(buf, "+F4:", 4)) {
2806 k = atoi(sstrsep(&p, sep));
2809 d = atof(sstrsep(&p, sep));
2811 ecdsa_results[k][0] =
2812 1 / (1 / ecdsa_results[k][0] + 1 / d);
2814 ecdsa_results[k][0] = d;
2816 d = atof(sstrsep(&p, sep));
2818 ecdsa_results[k][1] =
2819 1 / (1 / ecdsa_results[k][1] + 1 / d);
2821 ecdsa_results[k][1] = d;
2825 # ifndef OPENSSL_NO_ECDH
2826 else if (!strncmp(buf, "+F5:", 4)) {
2831 k = atoi(sstrsep(&p, sep));
2834 d = atof(sstrsep(&p, sep));
2836 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2838 ecdh_results[k][0] = d;
2843 else if (!strncmp(buf, "+H:", 3)) {
2845 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);