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.
74 #define PRIME_SECONDS 10
75 #define RSA_SECONDS 10
76 #define DSA_SECONDS 10
77 #define ECDSA_SECONDS 10
78 #define ECDH_SECONDS 10
81 #define PROG speed_main
89 #include <openssl/crypto.h>
90 #include <openssl/rand.h>
91 #include <openssl/err.h>
92 #include <openssl/evp.h>
93 #include <openssl/objects.h>
94 #if !defined(OPENSSL_SYS_MSDOS)
95 # include OPENSSL_UNISTD
98 #ifndef OPENSSL_SYS_NETWARE
102 #if defined(_WIN32) || defined(__CYGWIN__)
103 # include <windows.h>
104 # if defined(__CYGWIN__) && !defined(_WIN32)
106 * <windows.h> should define _WIN32, which normally is mutually exclusive
107 * with __CYGWIN__, but if it didn't...
110 /* this is done because Cygwin alarm() fails sometimes. */
114 #include <openssl/bn.h>
115 #ifndef OPENSSL_NO_DES
116 # include <openssl/des.h>
118 #ifndef OPENSSL_NO_AES
119 # include <openssl/aes.h>
121 #ifndef OPENSSL_NO_CAMELLIA
122 # include <openssl/camellia.h>
124 #ifndef OPENSSL_NO_MD2
125 # include <openssl/md2.h>
127 #ifndef OPENSSL_NO_MDC2
128 # include <openssl/mdc2.h>
130 #ifndef OPENSSL_NO_MD4
131 # include <openssl/md4.h>
133 #ifndef OPENSSL_NO_MD5
134 # include <openssl/md5.h>
136 #ifndef OPENSSL_NO_HMAC
137 # include <openssl/hmac.h>
139 #include <openssl/evp.h>
140 # include <openssl/sha.h>
141 #ifndef OPENSSL_NO_RMD160
142 # include <openssl/ripemd.h>
144 #ifndef OPENSSL_NO_WHIRLPOOL
145 # include <openssl/whrlpool.h>
147 #ifndef OPENSSL_NO_RC4
148 # include <openssl/rc4.h>
150 #ifndef OPENSSL_NO_RC5
151 # include <openssl/rc5.h>
153 #ifndef OPENSSL_NO_RC2
154 # include <openssl/rc2.h>
156 #ifndef OPENSSL_NO_IDEA
157 # include <openssl/idea.h>
159 #ifndef OPENSSL_NO_SEED
160 # include <openssl/seed.h>
162 #ifndef OPENSSL_NO_BF
163 # include <openssl/blowfish.h>
165 #ifndef OPENSSL_NO_CAST
166 # include <openssl/cast.h>
168 #ifndef OPENSSL_NO_RSA
169 # include <openssl/rsa.h>
170 # include "./testrsa.h"
172 #include <openssl/x509.h>
173 #ifndef OPENSSL_NO_DSA
174 # include <openssl/dsa.h>
175 # include "./testdsa.h"
177 #ifndef OPENSSL_NO_ECDSA
178 # include <openssl/ecdsa.h>
180 #ifndef OPENSSL_NO_ECDH
181 # include <openssl/ecdh.h>
183 #include <openssl/modes.h>
185 #include <openssl/bn.h>
188 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
202 #define BUFSIZE (1024*8+1)
203 #define MAX_MISALIGNMENT 63
205 static volatile int run = 0;
208 static int usertime = 1;
210 static double Time_F(int s);
211 static void print_message(const char *s, long num, int length);
212 static void pkey_print_message(const char *str, const char *str2,
213 long num, int bits, int sec);
214 static void print_result(int alg, int run_no, int count, double time_used);
216 static int do_multi(int multi);
226 #define MAX_ECDH_SIZE 256
228 static const char *names[ALGOR_NUM] = {
229 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
230 "des cbc", "des ede3", "idea cbc", "seed cbc",
231 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
232 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
233 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
234 "evp", "sha256", "sha512", "whirlpool",
235 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
238 static double results[ALGOR_NUM][SIZE_NUM];
239 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
241 #ifndef OPENSSL_NO_RSA
242 static double rsa_results[RSA_NUM][2];
244 #ifndef OPENSSL_NO_DSA
245 static double dsa_results[DSA_NUM][2];
247 #ifndef OPENSSL_NO_ECDSA
248 static double ecdsa_results[EC_NUM][2];
250 #ifndef OPENSSL_NO_ECDH
251 static double ecdh_results[EC_NUM][1];
254 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
255 static const char rnd_seed[] =
256 "string to make the random number generator think it has entropy";
257 static int rnd_fake = 0;
261 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
262 # define SIGRETTYPE void
264 # define SIGRETTYPE int
267 static SIGRETTYPE sig_done(int sig);
268 static SIGRETTYPE sig_done(int sig)
270 signal(SIGALRM, sig_done);
280 # if !defined(SIGALRM)
283 static unsigned int lapse, schlock;
284 static void alarm_win32(unsigned int secs)
289 # define alarm alarm_win32
291 static DWORD WINAPI sleepy(VOID * arg)
299 static double Time_F(int s)
306 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
308 DWORD ret = GetLastError();
309 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
313 Sleep(0); /* scheduler spinlock */
314 ret = app_tminterval(s, usertime);
316 ret = app_tminterval(s, usertime);
318 TerminateThread(thr, 0);
326 static double Time_F(int s)
328 double ret = app_tminterval(s, usertime);
335 #ifndef OPENSSL_NO_ECDH
336 static const int KDF1_SHA1_len = 20;
337 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
340 if (*outlen < SHA_DIGEST_LENGTH)
342 *outlen = SHA_DIGEST_LENGTH;
343 return SHA1(in, inlen, out);
345 #endif /* OPENSSL_NO_ECDH */
347 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
349 int MAIN(int, char **);
351 int MAIN(int argc, char **argv)
353 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
354 unsigned char *buf = NULL, *buf2 = NULL;
356 long count = 0, save_count = 0;
358 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
361 #ifndef OPENSSL_NO_RSA
364 unsigned char md[EVP_MAX_MD_SIZE];
365 #ifndef OPENSSL_NO_MD2
366 unsigned char md2[MD2_DIGEST_LENGTH];
368 #ifndef OPENSSL_NO_MDC2
369 unsigned char mdc2[MDC2_DIGEST_LENGTH];
371 #ifndef OPENSSL_NO_MD4
372 unsigned char md4[MD4_DIGEST_LENGTH];
374 #ifndef OPENSSL_NO_MD5
375 unsigned char md5[MD5_DIGEST_LENGTH];
376 unsigned char hmac[MD5_DIGEST_LENGTH];
378 unsigned char sha[SHA_DIGEST_LENGTH];
379 unsigned char sha256[SHA256_DIGEST_LENGTH];
380 unsigned char sha512[SHA512_DIGEST_LENGTH];
381 #ifndef OPENSSL_NO_WHIRLPOOL
382 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
384 #ifndef OPENSSL_NO_RMD160
385 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
387 #ifndef OPENSSL_NO_RC4
390 #ifndef OPENSSL_NO_RC5
393 #ifndef OPENSSL_NO_RC2
396 #ifndef OPENSSL_NO_IDEA
397 IDEA_KEY_SCHEDULE idea_ks;
399 #ifndef OPENSSL_NO_SEED
400 SEED_KEY_SCHEDULE seed_ks;
402 #ifndef OPENSSL_NO_BF
405 #ifndef OPENSSL_NO_CAST
408 static const unsigned char key16[16] = {
409 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
410 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
412 #ifndef OPENSSL_NO_AES
413 static const unsigned char key24[24] = {
414 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
415 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
416 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
418 static const unsigned char key32[32] = {
419 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
420 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
421 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
422 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
425 #ifndef OPENSSL_NO_CAMELLIA
426 static const unsigned char ckey24[24] = {
427 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
428 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
429 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
431 static const unsigned char ckey32[32] = {
432 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
433 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
434 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
435 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
438 #ifndef OPENSSL_NO_AES
439 # define MAX_BLOCK_SIZE 128
441 # define MAX_BLOCK_SIZE 64
443 unsigned char DES_iv[8];
444 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
445 #ifndef OPENSSL_NO_DES
446 static DES_cblock key =
447 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
448 static DES_cblock key2 =
449 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
450 static DES_cblock key3 =
451 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
452 DES_key_schedule sch;
453 DES_key_schedule sch2;
454 DES_key_schedule sch3;
456 #ifndef OPENSSL_NO_AES
457 AES_KEY aes_ks1, aes_ks2, aes_ks3;
459 #ifndef OPENSSL_NO_CAMELLIA
460 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
472 #define D_CBC_IDEA 10
473 #define D_CBC_SEED 11
477 #define D_CBC_CAST 15
478 #define D_CBC_128_AES 16
479 #define D_CBC_192_AES 17
480 #define D_CBC_256_AES 18
481 #define D_CBC_128_CML 19
482 #define D_CBC_192_CML 20
483 #define D_CBC_256_CML 21
487 #define D_WHIRLPOOL 25
488 #define D_IGE_128_AES 26
489 #define D_IGE_192_AES 27
490 #define D_IGE_256_AES 28
493 long c[ALGOR_NUM][SIZE_NUM];
495 #ifndef OPENSSL_SYS_WIN32
506 #define R_RSA_15360 6
525 #ifndef OPENSSL_NO_RSA
526 RSA *rsa_key[RSA_NUM];
527 long rsa_c[RSA_NUM][2];
528 static unsigned int rsa_bits[RSA_NUM] = {
529 512, 1024, 2048, 3072, 4096, 7680, 15360
531 static unsigned char *rsa_data[RSA_NUM] = {
532 test512, test1024, test2048, test3072, test4096, test7680, test15360
534 static int rsa_data_length[RSA_NUM] = {
535 sizeof(test512), sizeof(test1024),
536 sizeof(test2048), sizeof(test3072),
537 sizeof(test4096), sizeof(test7680),
541 #ifndef OPENSSL_NO_DSA
542 DSA *dsa_key[DSA_NUM];
543 long dsa_c[DSA_NUM][2];
544 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
546 #ifndef OPENSSL_NO_EC
548 * We only test over the following curves as they are representative, To
549 * add tests over more curves, simply add the curve NID and curve name to
550 * the following arrays and increase the EC_NUM value accordingly.
552 static unsigned int test_curves[EC_NUM] = {
555 NID_X9_62_prime192v1,
557 NID_X9_62_prime256v1,
572 static const char *test_curves_names[EC_NUM] = {
592 static int test_curves_bits[EC_NUM] = {
593 160, 192, 224, 256, 384, 521,
594 163, 233, 283, 409, 571,
595 163, 233, 283, 409, 571
600 #ifndef OPENSSL_NO_ECDSA
601 unsigned char ecdsasig[256];
602 unsigned int ecdsasiglen;
603 EC_KEY *ecdsa[EC_NUM];
604 long ecdsa_c[EC_NUM][2];
607 #ifndef OPENSSL_NO_ECDH
608 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
609 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
610 int secret_size_a, secret_size_b;
613 long ecdh_c[EC_NUM][2];
616 int rsa_doit[RSA_NUM];
617 int dsa_doit[DSA_NUM];
618 #ifndef OPENSSL_NO_ECDSA
619 int ecdsa_doit[EC_NUM];
621 #ifndef OPENSSL_NO_ECDH
622 int ecdh_doit[EC_NUM];
626 const EVP_CIPHER *evp_cipher = NULL;
627 const EVP_MD *evp_md = NULL;
633 int misalign = MAX_MISALIGNMENT + 1;
640 memset(results, 0, sizeof(results));
641 #ifndef OPENSSL_NO_DSA
642 memset(dsa_key, 0, sizeof(dsa_key));
644 #ifndef OPENSSL_NO_ECDSA
645 for (i = 0; i < EC_NUM; i++)
648 #ifndef OPENSSL_NO_ECDH
649 for (i = 0; i < EC_NUM; i++) {
656 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
657 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
659 if (!load_config(bio_err, NULL))
662 #ifndef OPENSSL_NO_RSA
663 memset(rsa_key, 0, sizeof(rsa_key));
664 for (i = 0; i < RSA_NUM; i++)
669 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
670 BIO_printf(bio_err, "out of memory\n");
674 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
675 BIO_printf(bio_err, "out of memory\n");
679 misalign = 0; /* set later and buf/buf2 are adjusted
684 memset(c, 0, sizeof(c));
685 memset(DES_iv, 0, sizeof(DES_iv));
686 memset(iv, 0, sizeof(iv));
688 for (i = 0; i < ALGOR_NUM; i++)
690 for (i = 0; i < RSA_NUM; i++)
692 for (i = 0; i < DSA_NUM; i++)
694 #ifndef OPENSSL_NO_ECDSA
695 for (i = 0; i < EC_NUM; i++)
698 #ifndef OPENSSL_NO_ECDH
699 for (i = 0; i < EC_NUM; i++)
707 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
709 j--; /* Otherwise, -elapsed gets confused with an
711 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
715 BIO_printf(bio_err, "no EVP given\n");
718 evp_cipher = EVP_get_cipherbyname(*argv);
720 evp_md = EVP_get_digestbyname(*argv);
722 if (!evp_cipher && !evp_md) {
723 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
728 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
730 j--; /* Otherwise, -elapsed gets confused with an
733 #ifndef OPENSSL_NO_ENGINE
734 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
738 BIO_printf(bio_err, "no engine given\n");
741 setup_engine(bio_err, *argv, 0);
743 * j will be increased again further down. We just don't want
744 * speed to confuse an engine with an algorithm, especially when
745 * none is given (which means all of them should be run)
751 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
755 BIO_printf(bio_err, "no multi count given\n");
758 multi = atoi(argv[0]);
760 BIO_printf(bio_err, "bad multi count\n");
763 j--; /* Otherwise, -mr gets confused with an
767 else if (argc > 0 && !strcmp(*argv, "-mr")) {
769 j--; /* Otherwise, -mr gets confused with an
771 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
774 } else if (argc > 0 && !strcmp(*argv, "-misalign")) {
778 BIO_printf(bio_err, "no misalignment given\n");
781 misalign = atoi(argv[0]);
782 if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
784 "misalignment is outsize permitted range 0-%d\n",
788 buf = buf_malloc + misalign;
789 buf2 = buf2_malloc + misalign;
792 #ifndef OPENSSL_NO_MD2
793 if (strcmp(*argv, "md2") == 0)
797 #ifndef OPENSSL_NO_MDC2
798 if (strcmp(*argv, "mdc2") == 0)
802 #ifndef OPENSSL_NO_MD4
803 if (strcmp(*argv, "md4") == 0)
807 #ifndef OPENSSL_NO_MD5
808 if (strcmp(*argv, "md5") == 0)
812 #ifndef OPENSSL_NO_MD5
813 if (strcmp(*argv, "hmac") == 0)
817 if (strcmp(*argv, "sha1") == 0)
819 else if (strcmp(*argv, "sha") == 0)
820 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
821 else if (strcmp(*argv, "sha256") == 0)
823 else if (strcmp(*argv, "sha512") == 0)
826 #ifndef OPENSSL_NO_WHIRLPOOL
827 if (strcmp(*argv, "whirlpool") == 0)
828 doit[D_WHIRLPOOL] = 1;
831 #ifndef OPENSSL_NO_RMD160
832 if (strcmp(*argv, "ripemd") == 0)
834 else if (strcmp(*argv, "rmd160") == 0)
836 else if (strcmp(*argv, "ripemd160") == 0)
840 #ifndef OPENSSL_NO_RC4
841 if (strcmp(*argv, "rc4") == 0)
845 #ifndef OPENSSL_NO_DES
846 if (strcmp(*argv, "des-cbc") == 0)
848 else if (strcmp(*argv, "des-ede3") == 0)
849 doit[D_EDE3_DES] = 1;
852 #ifndef OPENSSL_NO_AES
853 if (strcmp(*argv, "aes-128-cbc") == 0)
854 doit[D_CBC_128_AES] = 1;
855 else if (strcmp(*argv, "aes-192-cbc") == 0)
856 doit[D_CBC_192_AES] = 1;
857 else if (strcmp(*argv, "aes-256-cbc") == 0)
858 doit[D_CBC_256_AES] = 1;
859 else if (strcmp(*argv, "aes-128-ige") == 0)
860 doit[D_IGE_128_AES] = 1;
861 else if (strcmp(*argv, "aes-192-ige") == 0)
862 doit[D_IGE_192_AES] = 1;
863 else if (strcmp(*argv, "aes-256-ige") == 0)
864 doit[D_IGE_256_AES] = 1;
867 #ifndef OPENSSL_NO_CAMELLIA
868 if (strcmp(*argv, "camellia-128-cbc") == 0)
869 doit[D_CBC_128_CML] = 1;
870 else if (strcmp(*argv, "camellia-192-cbc") == 0)
871 doit[D_CBC_192_CML] = 1;
872 else if (strcmp(*argv, "camellia-256-cbc") == 0)
873 doit[D_CBC_256_CML] = 1;
876 #ifndef OPENSSL_NO_RSA
878 if (strcmp(*argv, "openssl") == 0) {
879 RSA_set_default_method(RSA_PKCS1_SSLeay());
883 #endif /* !OPENSSL_NO_RSA */
884 if (strcmp(*argv, "dsa512") == 0)
885 dsa_doit[R_DSA_512] = 2;
886 else if (strcmp(*argv, "dsa1024") == 0)
887 dsa_doit[R_DSA_1024] = 2;
888 else if (strcmp(*argv, "dsa2048") == 0)
889 dsa_doit[R_DSA_2048] = 2;
890 else if (strcmp(*argv, "rsa512") == 0)
891 rsa_doit[R_RSA_512] = 2;
892 else if (strcmp(*argv, "rsa1024") == 0)
893 rsa_doit[R_RSA_1024] = 2;
894 else if (strcmp(*argv, "rsa2048") == 0)
895 rsa_doit[R_RSA_2048] = 2;
896 else if (strcmp(*argv, "rsa3072") == 0)
897 rsa_doit[R_RSA_3072] = 2;
898 else if (strcmp(*argv, "rsa4096") == 0)
899 rsa_doit[R_RSA_4096] = 2;
900 else if (strcmp(*argv, "rsa7680") == 0)
901 rsa_doit[R_RSA_7680] = 2;
902 else if (strcmp(*argv, "rsa15360") == 0)
903 rsa_doit[R_RSA_15360] = 2;
905 #ifndef OPENSSL_NO_RC2
906 if (strcmp(*argv, "rc2-cbc") == 0)
908 else if (strcmp(*argv, "rc2") == 0)
912 #ifndef OPENSSL_NO_RC5
913 if (strcmp(*argv, "rc5-cbc") == 0)
915 else if (strcmp(*argv, "rc5") == 0)
919 #ifndef OPENSSL_NO_IDEA
920 if (strcmp(*argv, "idea-cbc") == 0)
921 doit[D_CBC_IDEA] = 1;
922 else if (strcmp(*argv, "idea") == 0)
923 doit[D_CBC_IDEA] = 1;
926 #ifndef OPENSSL_NO_SEED
927 if (strcmp(*argv, "seed-cbc") == 0)
928 doit[D_CBC_SEED] = 1;
929 else if (strcmp(*argv, "seed") == 0)
930 doit[D_CBC_SEED] = 1;
933 #ifndef OPENSSL_NO_BF
934 if (strcmp(*argv, "bf-cbc") == 0)
936 else if (strcmp(*argv, "blowfish") == 0)
938 else if (strcmp(*argv, "bf") == 0)
942 #ifndef OPENSSL_NO_CAST
943 if (strcmp(*argv, "cast-cbc") == 0)
944 doit[D_CBC_CAST] = 1;
945 else if (strcmp(*argv, "cast") == 0)
946 doit[D_CBC_CAST] = 1;
947 else if (strcmp(*argv, "cast5") == 0)
948 doit[D_CBC_CAST] = 1;
951 #ifndef OPENSSL_NO_DES
952 if (strcmp(*argv, "des") == 0) {
954 doit[D_EDE3_DES] = 1;
957 #ifndef OPENSSL_NO_AES
958 if (strcmp(*argv, "aes") == 0) {
959 doit[D_CBC_128_AES] = 1;
960 doit[D_CBC_192_AES] = 1;
961 doit[D_CBC_256_AES] = 1;
962 } else if (strcmp(*argv, "ghash") == 0) {
966 #ifndef OPENSSL_NO_CAMELLIA
967 if (strcmp(*argv, "camellia") == 0) {
968 doit[D_CBC_128_CML] = 1;
969 doit[D_CBC_192_CML] = 1;
970 doit[D_CBC_256_CML] = 1;
973 #ifndef OPENSSL_NO_RSA
974 if (strcmp(*argv, "rsa") == 0) {
975 rsa_doit[R_RSA_512] = 1;
976 rsa_doit[R_RSA_1024] = 1;
977 rsa_doit[R_RSA_2048] = 1;
978 rsa_doit[R_RSA_3072] = 1;
979 rsa_doit[R_RSA_4096] = 1;
980 rsa_doit[R_RSA_7680] = 1;
981 rsa_doit[R_RSA_15360] = 1;
984 #ifndef OPENSSL_NO_DSA
985 if (strcmp(*argv, "dsa") == 0) {
986 dsa_doit[R_DSA_512] = 1;
987 dsa_doit[R_DSA_1024] = 1;
988 dsa_doit[R_DSA_2048] = 1;
991 #ifndef OPENSSL_NO_ECDSA
992 if (strcmp(*argv, "ecdsap160") == 0)
993 ecdsa_doit[R_EC_P160] = 2;
994 else if (strcmp(*argv, "ecdsap192") == 0)
995 ecdsa_doit[R_EC_P192] = 2;
996 else if (strcmp(*argv, "ecdsap224") == 0)
997 ecdsa_doit[R_EC_P224] = 2;
998 else if (strcmp(*argv, "ecdsap256") == 0)
999 ecdsa_doit[R_EC_P256] = 2;
1000 else if (strcmp(*argv, "ecdsap384") == 0)
1001 ecdsa_doit[R_EC_P384] = 2;
1002 else if (strcmp(*argv, "ecdsap521") == 0)
1003 ecdsa_doit[R_EC_P521] = 2;
1004 else if (strcmp(*argv, "ecdsak163") == 0)
1005 ecdsa_doit[R_EC_K163] = 2;
1006 else if (strcmp(*argv, "ecdsak233") == 0)
1007 ecdsa_doit[R_EC_K233] = 2;
1008 else if (strcmp(*argv, "ecdsak283") == 0)
1009 ecdsa_doit[R_EC_K283] = 2;
1010 else if (strcmp(*argv, "ecdsak409") == 0)
1011 ecdsa_doit[R_EC_K409] = 2;
1012 else if (strcmp(*argv, "ecdsak571") == 0)
1013 ecdsa_doit[R_EC_K571] = 2;
1014 else if (strcmp(*argv, "ecdsab163") == 0)
1015 ecdsa_doit[R_EC_B163] = 2;
1016 else if (strcmp(*argv, "ecdsab233") == 0)
1017 ecdsa_doit[R_EC_B233] = 2;
1018 else if (strcmp(*argv, "ecdsab283") == 0)
1019 ecdsa_doit[R_EC_B283] = 2;
1020 else if (strcmp(*argv, "ecdsab409") == 0)
1021 ecdsa_doit[R_EC_B409] = 2;
1022 else if (strcmp(*argv, "ecdsab571") == 0)
1023 ecdsa_doit[R_EC_B571] = 2;
1024 else if (strcmp(*argv, "ecdsa") == 0) {
1025 for (i = 0; i < EC_NUM; i++)
1029 #ifndef OPENSSL_NO_ECDH
1030 if (strcmp(*argv, "ecdhp160") == 0)
1031 ecdh_doit[R_EC_P160] = 2;
1032 else if (strcmp(*argv, "ecdhp192") == 0)
1033 ecdh_doit[R_EC_P192] = 2;
1034 else if (strcmp(*argv, "ecdhp224") == 0)
1035 ecdh_doit[R_EC_P224] = 2;
1036 else if (strcmp(*argv, "ecdhp256") == 0)
1037 ecdh_doit[R_EC_P256] = 2;
1038 else if (strcmp(*argv, "ecdhp384") == 0)
1039 ecdh_doit[R_EC_P384] = 2;
1040 else if (strcmp(*argv, "ecdhp521") == 0)
1041 ecdh_doit[R_EC_P521] = 2;
1042 else if (strcmp(*argv, "ecdhk163") == 0)
1043 ecdh_doit[R_EC_K163] = 2;
1044 else if (strcmp(*argv, "ecdhk233") == 0)
1045 ecdh_doit[R_EC_K233] = 2;
1046 else if (strcmp(*argv, "ecdhk283") == 0)
1047 ecdh_doit[R_EC_K283] = 2;
1048 else if (strcmp(*argv, "ecdhk409") == 0)
1049 ecdh_doit[R_EC_K409] = 2;
1050 else if (strcmp(*argv, "ecdhk571") == 0)
1051 ecdh_doit[R_EC_K571] = 2;
1052 else if (strcmp(*argv, "ecdhb163") == 0)
1053 ecdh_doit[R_EC_B163] = 2;
1054 else if (strcmp(*argv, "ecdhb233") == 0)
1055 ecdh_doit[R_EC_B233] = 2;
1056 else if (strcmp(*argv, "ecdhb283") == 0)
1057 ecdh_doit[R_EC_B283] = 2;
1058 else if (strcmp(*argv, "ecdhb409") == 0)
1059 ecdh_doit[R_EC_B409] = 2;
1060 else if (strcmp(*argv, "ecdhb571") == 0)
1061 ecdh_doit[R_EC_B571] = 2;
1062 else if (strcmp(*argv, "ecdh") == 0) {
1063 for (i = 0; i < EC_NUM; i++)
1068 BIO_printf(bio_err, "Error: bad option or value\n");
1069 BIO_printf(bio_err, "\n");
1070 BIO_printf(bio_err, "Available values:\n");
1071 #ifndef OPENSSL_NO_MD2
1072 BIO_printf(bio_err, "md2 ");
1074 #ifndef OPENSSL_NO_MDC2
1075 BIO_printf(bio_err, "mdc2 ");
1077 #ifndef OPENSSL_NO_MD4
1078 BIO_printf(bio_err, "md4 ");
1080 #ifndef OPENSSL_NO_MD5
1081 BIO_printf(bio_err, "md5 ");
1082 # ifndef OPENSSL_NO_HMAC
1083 BIO_printf(bio_err, "hmac ");
1086 BIO_printf(bio_err, "sha1 ");
1087 BIO_printf(bio_err, "sha256 ");
1088 BIO_printf(bio_err, "sha512 ");
1089 #ifndef OPENSSL_NO_WHIRLPOOL
1090 BIO_printf(bio_err, "whirlpool");
1092 #ifndef OPENSSL_NO_RMD160
1093 BIO_printf(bio_err, "rmd160");
1095 BIO_printf(bio_err, "\n");
1097 #ifndef OPENSSL_NO_IDEA
1098 BIO_printf(bio_err, "idea-cbc ");
1100 #ifndef OPENSSL_NO_SEED
1101 BIO_printf(bio_err, "seed-cbc ");
1103 #ifndef OPENSSL_NO_RC2
1104 BIO_printf(bio_err, "rc2-cbc ");
1106 #ifndef OPENSSL_NO_RC5
1107 BIO_printf(bio_err, "rc5-cbc ");
1109 #ifndef OPENSSL_NO_BF
1110 BIO_printf(bio_err, "bf-cbc");
1112 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1113 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1114 BIO_printf(bio_err, "\n");
1116 #ifndef OPENSSL_NO_DES
1117 BIO_printf(bio_err, "des-cbc des-ede3 ");
1119 #ifndef OPENSSL_NO_AES
1120 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1121 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1123 #ifndef OPENSSL_NO_CAMELLIA
1124 BIO_printf(bio_err, "\n");
1126 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1128 #ifndef OPENSSL_NO_RC4
1129 BIO_printf(bio_err, "rc4");
1131 BIO_printf(bio_err, "\n");
1133 #ifndef OPENSSL_NO_RSA
1135 "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1136 BIO_printf(bio_err, "rsa7680 rsa15360\n");
1139 #ifndef OPENSSL_NO_DSA
1140 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1142 #ifndef OPENSSL_NO_ECDSA
1143 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1144 "ecdsap256 ecdsap384 ecdsap521\n");
1146 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1148 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1149 BIO_printf(bio_err, "ecdsa\n");
1151 #ifndef OPENSSL_NO_ECDH
1152 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1153 "ecdhp256 ecdhp384 ecdhp521\n");
1155 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1157 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1158 BIO_printf(bio_err, "ecdh\n");
1161 #ifndef OPENSSL_NO_IDEA
1162 BIO_printf(bio_err, "idea ");
1164 #ifndef OPENSSL_NO_SEED
1165 BIO_printf(bio_err, "seed ");
1167 #ifndef OPENSSL_NO_RC2
1168 BIO_printf(bio_err, "rc2 ");
1170 #ifndef OPENSSL_NO_DES
1171 BIO_printf(bio_err, "des ");
1173 #ifndef OPENSSL_NO_AES
1174 BIO_printf(bio_err, "aes ");
1176 #ifndef OPENSSL_NO_CAMELLIA
1177 BIO_printf(bio_err, "camellia ");
1179 #ifndef OPENSSL_NO_RSA
1180 BIO_printf(bio_err, "rsa ");
1182 #ifndef OPENSSL_NO_BF
1183 BIO_printf(bio_err, "blowfish");
1185 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1186 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1187 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1188 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1189 BIO_printf(bio_err, "\n");
1192 BIO_printf(bio_err, "\n");
1193 BIO_printf(bio_err, "Available options:\n");
1194 #if defined(TIMES) || defined(USE_TOD)
1195 BIO_printf(bio_err, "-elapsed "
1196 "measure time in real time instead of CPU user time.\n");
1198 #ifndef OPENSSL_NO_ENGINE
1201 "use engine e, possibly a hardware device.\n");
1203 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1206 "time decryption instead of encryption (only EVP).\n");
1209 "produce machine readable output.\n");
1212 "perform multi-block benchmark (for specific ciphers)\n");
1215 "perform benchmark with misaligned data\n");
1218 "-multi n " "run n benchmarks in parallel.\n");
1228 if (multi && do_multi(multi))
1233 for (i = 0; i < ALGOR_NUM; i++) {
1237 for (i = 0; i < RSA_NUM; i++)
1239 for (i = 0; i < DSA_NUM; i++)
1241 #ifndef OPENSSL_NO_ECDSA
1242 for (i = 0; i < EC_NUM; i++)
1245 #ifndef OPENSSL_NO_ECDH
1246 for (i = 0; i < EC_NUM; i++)
1250 for (i = 0; i < ALGOR_NUM; i++)
1254 if (usertime == 0 && !mr)
1256 "You have chosen to measure elapsed time "
1257 "instead of user CPU time.\n");
1259 #ifndef OPENSSL_NO_RSA
1260 for (i = 0; i < RSA_NUM; i++) {
1261 const unsigned char *p;
1264 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1265 if (rsa_key[i] == NULL) {
1266 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1273 #ifndef OPENSSL_NO_DSA
1274 dsa_key[0] = get_dsa512();
1275 dsa_key[1] = get_dsa1024();
1276 dsa_key[2] = get_dsa2048();
1279 #ifndef OPENSSL_NO_DES
1280 DES_set_key_unchecked(&key, &sch);
1281 DES_set_key_unchecked(&key2, &sch2);
1282 DES_set_key_unchecked(&key3, &sch3);
1284 #ifndef OPENSSL_NO_AES
1285 AES_set_encrypt_key(key16, 128, &aes_ks1);
1286 AES_set_encrypt_key(key24, 192, &aes_ks2);
1287 AES_set_encrypt_key(key32, 256, &aes_ks3);
1289 #ifndef OPENSSL_NO_CAMELLIA
1290 Camellia_set_key(key16, 128, &camellia_ks1);
1291 Camellia_set_key(ckey24, 192, &camellia_ks2);
1292 Camellia_set_key(ckey32, 256, &camellia_ks3);
1294 #ifndef OPENSSL_NO_IDEA
1295 idea_set_encrypt_key(key16, &idea_ks);
1297 #ifndef OPENSSL_NO_SEED
1298 SEED_set_key(key16, &seed_ks);
1300 #ifndef OPENSSL_NO_RC4
1301 RC4_set_key(&rc4_ks, 16, key16);
1303 #ifndef OPENSSL_NO_RC2
1304 RC2_set_key(&rc2_ks, 16, key16, 128);
1306 #ifndef OPENSSL_NO_RC5
1307 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1309 #ifndef OPENSSL_NO_BF
1310 BF_set_key(&bf_ks, 16, key16);
1312 #ifndef OPENSSL_NO_CAST
1313 CAST_set_key(&cast_ks, 16, key16);
1315 #ifndef OPENSSL_NO_RSA
1316 memset(rsa_c, 0, sizeof(rsa_c));
1319 # ifndef OPENSSL_NO_DES
1320 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1326 for (it = count; it; it--)
1327 DES_ecb_encrypt((DES_cblock *)buf,
1328 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1332 c[D_MD2][0] = count / 10;
1333 c[D_MDC2][0] = count / 10;
1334 c[D_MD4][0] = count;
1335 c[D_MD5][0] = count;
1336 c[D_HMAC][0] = count;
1337 c[D_SHA1][0] = count;
1338 c[D_RMD160][0] = count;
1339 c[D_RC4][0] = count * 5;
1340 c[D_CBC_DES][0] = count;
1341 c[D_EDE3_DES][0] = count / 3;
1342 c[D_CBC_IDEA][0] = count;
1343 c[D_CBC_SEED][0] = count;
1344 c[D_CBC_RC2][0] = count;
1345 c[D_CBC_RC5][0] = count;
1346 c[D_CBC_BF][0] = count;
1347 c[D_CBC_CAST][0] = count;
1348 c[D_CBC_128_AES][0] = count;
1349 c[D_CBC_192_AES][0] = count;
1350 c[D_CBC_256_AES][0] = count;
1351 c[D_CBC_128_CML][0] = count;
1352 c[D_CBC_192_CML][0] = count;
1353 c[D_CBC_256_CML][0] = count;
1354 c[D_SHA256][0] = count;
1355 c[D_SHA512][0] = count;
1356 c[D_WHIRLPOOL][0] = count;
1357 c[D_IGE_128_AES][0] = count;
1358 c[D_IGE_192_AES][0] = count;
1359 c[D_IGE_256_AES][0] = count;
1360 c[D_GHASH][0] = count;
1362 for (i = 1; i < SIZE_NUM; i++) {
1365 l0 = (long)lengths[0];
1366 l1 = (long)lengths[i];
1368 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1369 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1370 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1371 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1372 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1373 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1374 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1375 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1376 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1377 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1379 l0 = (long)lengths[i - 1];
1381 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1382 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1383 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1384 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1385 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1386 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1387 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1388 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1389 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1390 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1391 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1392 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1393 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1394 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1395 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1396 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1397 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1398 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1401 # ifndef OPENSSL_NO_RSA
1402 rsa_c[R_RSA_512][0] = count / 2000;
1403 rsa_c[R_RSA_512][1] = count / 400;
1404 for (i = 1; i < RSA_NUM; i++) {
1405 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1406 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1407 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1410 if (rsa_c[i][0] == 0) {
1418 # ifndef OPENSSL_NO_DSA
1419 dsa_c[R_DSA_512][0] = count / 1000;
1420 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1421 for (i = 1; i < DSA_NUM; i++) {
1422 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1423 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1424 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1427 if (dsa_c[i] == 0) {
1435 # ifndef OPENSSL_NO_ECDSA
1436 ecdsa_c[R_EC_P160][0] = count / 1000;
1437 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1438 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1439 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1440 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1441 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1444 if (ecdsa_c[i] == 0) {
1450 ecdsa_c[R_EC_K163][0] = count / 1000;
1451 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1452 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1453 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1454 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1455 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1458 if (ecdsa_c[i] == 0) {
1464 ecdsa_c[R_EC_B163][0] = count / 1000;
1465 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1466 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1467 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1468 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1469 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1472 if (ecdsa_c[i] == 0) {
1480 # ifndef OPENSSL_NO_ECDH
1481 ecdh_c[R_EC_P160][0] = count / 1000;
1482 ecdh_c[R_EC_P160][1] = count / 1000;
1483 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1484 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1485 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1486 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1489 if (ecdh_c[i] == 0) {
1495 ecdh_c[R_EC_K163][0] = count / 1000;
1496 ecdh_c[R_EC_K163][1] = count / 1000;
1497 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1498 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1499 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1500 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1503 if (ecdh_c[i] == 0) {
1509 ecdh_c[R_EC_B163][0] = count / 1000;
1510 ecdh_c[R_EC_B163][1] = count / 1000;
1511 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1512 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1513 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1514 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1517 if (ecdh_c[i] == 0) {
1525 # define COND(d) (count < (d))
1526 # define COUNT(d) (d)
1528 /* not worth fixing */
1529 # error "You cannot disable DES on systems without SIGALRM."
1530 # endif /* OPENSSL_NO_DES */
1532 # define COND(c) (run && count<0x7fffffff)
1533 # define COUNT(d) (count)
1535 signal(SIGALRM, sig_done);
1537 #endif /* SIGALRM */
1539 #ifndef OPENSSL_NO_MD2
1541 for (j = 0; j < SIZE_NUM; j++) {
1542 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1544 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1545 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1548 print_result(D_MD2, j, count, d);
1552 #ifndef OPENSSL_NO_MDC2
1554 for (j = 0; j < SIZE_NUM; j++) {
1555 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1557 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1558 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1561 print_result(D_MDC2, j, count, d);
1566 #ifndef OPENSSL_NO_MD4
1568 for (j = 0; j < SIZE_NUM; j++) {
1569 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1571 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1572 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1573 NULL, EVP_md4(), NULL);
1575 print_result(D_MD4, j, count, d);
1580 #ifndef OPENSSL_NO_MD5
1582 for (j = 0; j < SIZE_NUM; j++) {
1583 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1585 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1586 MD5(buf, lengths[j], md5);
1588 print_result(D_MD5, j, count, d);
1593 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1597 HMAC_CTX_init(&hctx);
1598 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1599 16, EVP_md5(), NULL);
1601 for (j = 0; j < SIZE_NUM; j++) {
1602 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1604 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1605 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1606 HMAC_Update(&hctx, buf, lengths[j]);
1607 HMAC_Final(&hctx, &(hmac[0]), NULL);
1610 print_result(D_HMAC, j, count, d);
1612 HMAC_CTX_cleanup(&hctx);
1616 for (j = 0; j < SIZE_NUM; j++) {
1617 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1619 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1620 SHA1(buf, lengths[j], sha);
1622 print_result(D_SHA1, j, count, d);
1625 if (doit[D_SHA256]) {
1626 for (j = 0; j < SIZE_NUM; j++) {
1627 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1629 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1630 SHA256(buf, lengths[j], sha256);
1632 print_result(D_SHA256, j, count, d);
1635 if (doit[D_SHA512]) {
1636 for (j = 0; j < SIZE_NUM; j++) {
1637 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1639 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1640 SHA512(buf, lengths[j], sha512);
1642 print_result(D_SHA512, j, count, d);
1646 #ifndef OPENSSL_NO_WHIRLPOOL
1647 if (doit[D_WHIRLPOOL]) {
1648 for (j = 0; j < SIZE_NUM; j++) {
1649 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1651 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1652 WHIRLPOOL(buf, lengths[j], whirlpool);
1654 print_result(D_WHIRLPOOL, j, count, d);
1659 #ifndef OPENSSL_NO_RMD160
1660 if (doit[D_RMD160]) {
1661 for (j = 0; j < SIZE_NUM; j++) {
1662 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1664 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1665 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1666 EVP_ripemd160(), NULL);
1668 print_result(D_RMD160, j, count, d);
1672 #ifndef OPENSSL_NO_RC4
1674 for (j = 0; j < SIZE_NUM; j++) {
1675 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1677 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1678 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1680 print_result(D_RC4, j, count, d);
1684 #ifndef OPENSSL_NO_DES
1685 if (doit[D_CBC_DES]) {
1686 for (j = 0; j < SIZE_NUM; j++) {
1687 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1689 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1690 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1691 &DES_iv, DES_ENCRYPT);
1693 print_result(D_CBC_DES, j, count, d);
1697 if (doit[D_EDE3_DES]) {
1698 for (j = 0; j < SIZE_NUM; j++) {
1699 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1701 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1702 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1704 &DES_iv, DES_ENCRYPT);
1706 print_result(D_EDE3_DES, j, count, d);
1710 #ifndef OPENSSL_NO_AES
1711 if (doit[D_CBC_128_AES]) {
1712 for (j = 0; j < SIZE_NUM; j++) {
1713 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1716 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1717 AES_cbc_encrypt(buf, buf,
1718 (unsigned long)lengths[j], &aes_ks1,
1721 print_result(D_CBC_128_AES, j, count, d);
1724 if (doit[D_CBC_192_AES]) {
1725 for (j = 0; j < SIZE_NUM; j++) {
1726 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1729 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1730 AES_cbc_encrypt(buf, buf,
1731 (unsigned long)lengths[j], &aes_ks2,
1734 print_result(D_CBC_192_AES, j, count, d);
1737 if (doit[D_CBC_256_AES]) {
1738 for (j = 0; j < SIZE_NUM; j++) {
1739 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1742 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1743 AES_cbc_encrypt(buf, buf,
1744 (unsigned long)lengths[j], &aes_ks3,
1747 print_result(D_CBC_256_AES, j, count, d);
1751 if (doit[D_IGE_128_AES]) {
1752 for (j = 0; j < SIZE_NUM; j++) {
1753 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1756 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1757 AES_ige_encrypt(buf, buf2,
1758 (unsigned long)lengths[j], &aes_ks1,
1761 print_result(D_IGE_128_AES, j, count, d);
1764 if (doit[D_IGE_192_AES]) {
1765 for (j = 0; j < SIZE_NUM; j++) {
1766 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1769 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1770 AES_ige_encrypt(buf, buf2,
1771 (unsigned long)lengths[j], &aes_ks2,
1774 print_result(D_IGE_192_AES, j, count, d);
1777 if (doit[D_IGE_256_AES]) {
1778 for (j = 0; j < SIZE_NUM; j++) {
1779 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1782 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1783 AES_ige_encrypt(buf, buf2,
1784 (unsigned long)lengths[j], &aes_ks3,
1787 print_result(D_IGE_256_AES, j, count, d);
1790 if (doit[D_GHASH]) {
1791 GCM128_CONTEXT *ctx =
1792 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1793 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1795 for (j = 0; j < SIZE_NUM; j++) {
1796 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1798 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1799 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1801 print_result(D_GHASH, j, count, d);
1803 CRYPTO_gcm128_release(ctx);
1806 #ifndef OPENSSL_NO_CAMELLIA
1807 if (doit[D_CBC_128_CML]) {
1808 for (j = 0; j < SIZE_NUM; j++) {
1809 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1812 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1813 Camellia_cbc_encrypt(buf, buf,
1814 (unsigned long)lengths[j], &camellia_ks1,
1815 iv, CAMELLIA_ENCRYPT);
1817 print_result(D_CBC_128_CML, j, count, d);
1820 if (doit[D_CBC_192_CML]) {
1821 for (j = 0; j < SIZE_NUM; j++) {
1822 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1825 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1826 Camellia_cbc_encrypt(buf, buf,
1827 (unsigned long)lengths[j], &camellia_ks2,
1828 iv, CAMELLIA_ENCRYPT);
1830 print_result(D_CBC_192_CML, j, count, d);
1833 if (doit[D_CBC_256_CML]) {
1834 for (j = 0; j < SIZE_NUM; j++) {
1835 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1838 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1839 Camellia_cbc_encrypt(buf, buf,
1840 (unsigned long)lengths[j], &camellia_ks3,
1841 iv, CAMELLIA_ENCRYPT);
1843 print_result(D_CBC_256_CML, j, count, d);
1847 #ifndef OPENSSL_NO_IDEA
1848 if (doit[D_CBC_IDEA]) {
1849 for (j = 0; j < SIZE_NUM; j++) {
1850 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1852 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1853 idea_cbc_encrypt(buf, buf,
1854 (unsigned long)lengths[j], &idea_ks,
1857 print_result(D_CBC_IDEA, j, count, d);
1861 #ifndef OPENSSL_NO_SEED
1862 if (doit[D_CBC_SEED]) {
1863 for (j = 0; j < SIZE_NUM; j++) {
1864 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1866 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1867 SEED_cbc_encrypt(buf, buf,
1868 (unsigned long)lengths[j], &seed_ks, iv, 1);
1870 print_result(D_CBC_SEED, j, count, d);
1874 #ifndef OPENSSL_NO_RC2
1875 if (doit[D_CBC_RC2]) {
1876 for (j = 0; j < SIZE_NUM; j++) {
1877 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1879 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1880 RC2_cbc_encrypt(buf, buf,
1881 (unsigned long)lengths[j], &rc2_ks,
1884 print_result(D_CBC_RC2, j, count, d);
1888 #ifndef OPENSSL_NO_RC5
1889 if (doit[D_CBC_RC5]) {
1890 for (j = 0; j < SIZE_NUM; j++) {
1891 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1893 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1894 RC5_32_cbc_encrypt(buf, buf,
1895 (unsigned long)lengths[j], &rc5_ks,
1898 print_result(D_CBC_RC5, j, count, d);
1902 #ifndef OPENSSL_NO_BF
1903 if (doit[D_CBC_BF]) {
1904 for (j = 0; j < SIZE_NUM; j++) {
1905 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1907 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1908 BF_cbc_encrypt(buf, buf,
1909 (unsigned long)lengths[j], &bf_ks,
1912 print_result(D_CBC_BF, j, count, d);
1916 #ifndef OPENSSL_NO_CAST
1917 if (doit[D_CBC_CAST]) {
1918 for (j = 0; j < SIZE_NUM; j++) {
1919 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1921 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1922 CAST_cbc_encrypt(buf, buf,
1923 (unsigned long)lengths[j], &cast_ks,
1926 print_result(D_CBC_CAST, j, count, d);
1932 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1933 if (multiblock && evp_cipher) {
1935 (EVP_CIPHER_flags(evp_cipher) &
1936 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1937 fprintf(stderr, "%s is not multi-block capable\n",
1938 OBJ_nid2ln(evp_cipher->nid));
1941 multiblock_speed(evp_cipher);
1946 for (j = 0; j < SIZE_NUM; j++) {
1951 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1953 * -O3 -fschedule-insns messes up an optimization here!
1954 * names[D_EVP] somehow becomes NULL
1956 print_message(names[D_EVP], save_count, lengths[j]);
1958 EVP_CIPHER_CTX_init(&ctx);
1960 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1962 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1963 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1967 for (count = 0, run = 1;
1968 COND(save_count * 4 * lengths[0] / lengths[j]);
1970 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1972 for (count = 0, run = 1;
1973 COND(save_count * 4 * lengths[0] / lengths[j]);
1975 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1977 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1979 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1981 EVP_CIPHER_CTX_cleanup(&ctx);
1984 names[D_EVP] = OBJ_nid2ln(evp_md->type);
1985 print_message(names[D_EVP], save_count, lengths[j]);
1988 for (count = 0, run = 1;
1989 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1990 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1994 print_result(D_EVP, j, count, d);
1997 #ifndef OPENSSL_SYS_WIN32
1999 RAND_pseudo_bytes(buf, 36);
2000 #ifndef OPENSSL_NO_RSA
2001 for (j = 0; j < RSA_NUM; j++) {
2005 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2008 "RSA sign failure. No RSA sign will be done.\n");
2009 ERR_print_errors(bio_err);
2012 pkey_print_message("private", "rsa",
2013 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2014 /* RSA_blinding_on(rsa_key[j],NULL); */
2016 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2017 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2018 &rsa_num, rsa_key[j]);
2020 BIO_printf(bio_err, "RSA sign failure\n");
2021 ERR_print_errors(bio_err);
2028 mr ? "+R1:%ld:%d:%.2f\n"
2029 : "%ld %d bit private RSA's in %.2fs\n",
2030 count, rsa_bits[j], d);
2031 rsa_results[j][0] = d / (double)count;
2036 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2039 "RSA verify failure. No RSA verify will be done.\n");
2040 ERR_print_errors(bio_err);
2043 pkey_print_message("public", "rsa",
2044 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2046 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2047 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2048 rsa_num, rsa_key[j]);
2050 BIO_printf(bio_err, "RSA verify failure\n");
2051 ERR_print_errors(bio_err);
2058 mr ? "+R2:%ld:%d:%.2f\n"
2059 : "%ld %d bit public RSA's in %.2fs\n",
2060 count, rsa_bits[j], d);
2061 rsa_results[j][1] = d / (double)count;
2065 if (rsa_count <= 1) {
2066 /* if longer than 10s, don't do any more */
2067 for (j++; j < RSA_NUM; j++)
2073 RAND_pseudo_bytes(buf, 20);
2074 #ifndef OPENSSL_NO_DSA
2075 if (RAND_status() != 1) {
2076 RAND_seed(rnd_seed, sizeof rnd_seed);
2079 for (j = 0; j < DSA_NUM; j++) {
2086 /* DSA_generate_key(dsa_key[j]); */
2087 /* DSA_sign_setup(dsa_key[j],NULL); */
2088 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2091 "DSA sign failure. No DSA sign will be done.\n");
2092 ERR_print_errors(bio_err);
2095 pkey_print_message("sign", "dsa",
2096 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2098 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2099 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2101 BIO_printf(bio_err, "DSA sign failure\n");
2102 ERR_print_errors(bio_err);
2109 mr ? "+R3:%ld:%d:%.2f\n"
2110 : "%ld %d bit DSA signs in %.2fs\n",
2111 count, dsa_bits[j], d);
2112 dsa_results[j][0] = d / (double)count;
2116 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2119 "DSA verify failure. No DSA verify will be done.\n");
2120 ERR_print_errors(bio_err);
2123 pkey_print_message("verify", "dsa",
2124 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2126 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2127 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2129 BIO_printf(bio_err, "DSA verify failure\n");
2130 ERR_print_errors(bio_err);
2137 mr ? "+R4:%ld:%d:%.2f\n"
2138 : "%ld %d bit DSA verify in %.2fs\n",
2139 count, dsa_bits[j], d);
2140 dsa_results[j][1] = d / (double)count;
2143 if (rsa_count <= 1) {
2144 /* if longer than 10s, don't do any more */
2145 for (j++; j < DSA_NUM; j++)
2153 #ifndef OPENSSL_NO_ECDSA
2154 if (RAND_status() != 1) {
2155 RAND_seed(rnd_seed, sizeof rnd_seed);
2158 for (j = 0; j < EC_NUM; j++) {
2162 continue; /* Ignore Curve */
2163 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2164 if (ecdsa[j] == NULL) {
2165 BIO_printf(bio_err, "ECDSA failure.\n");
2166 ERR_print_errors(bio_err);
2170 EC_KEY_precompute_mult(ecdsa[j], NULL);
2172 /* Perform ECDSA signature test */
2173 EC_KEY_generate_key(ecdsa[j]);
2174 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2177 "ECDSA sign failure. No ECDSA sign will be done.\n");
2178 ERR_print_errors(bio_err);
2181 pkey_print_message("sign", "ecdsa",
2183 test_curves_bits[j], ECDSA_SECONDS);
2186 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2187 ret = ECDSA_sign(0, buf, 20,
2188 ecdsasig, &ecdsasiglen, ecdsa[j]);
2190 BIO_printf(bio_err, "ECDSA sign failure\n");
2191 ERR_print_errors(bio_err);
2199 mr ? "+R5:%ld:%d:%.2f\n" :
2200 "%ld %d bit ECDSA signs in %.2fs \n",
2201 count, test_curves_bits[j], d);
2202 ecdsa_results[j][0] = d / (double)count;
2206 /* Perform ECDSA verification test */
2207 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2210 "ECDSA verify failure. No ECDSA verify will be done.\n");
2211 ERR_print_errors(bio_err);
2214 pkey_print_message("verify", "ecdsa",
2216 test_curves_bits[j], ECDSA_SECONDS);
2218 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2220 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2223 BIO_printf(bio_err, "ECDSA verify failure\n");
2224 ERR_print_errors(bio_err);
2231 mr ? "+R6:%ld:%d:%.2f\n"
2232 : "%ld %d bit ECDSA verify in %.2fs\n",
2233 count, test_curves_bits[j], d);
2234 ecdsa_results[j][1] = d / (double)count;
2237 if (rsa_count <= 1) {
2238 /* if longer than 10s, don't do any more */
2239 for (j++; j < EC_NUM; j++)
2248 #ifndef OPENSSL_NO_ECDH
2249 if (RAND_status() != 1) {
2250 RAND_seed(rnd_seed, sizeof rnd_seed);
2253 for (j = 0; j < EC_NUM; j++) {
2256 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2257 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2258 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2259 BIO_printf(bio_err, "ECDH failure.\n");
2260 ERR_print_errors(bio_err);
2263 /* generate two ECDH key pairs */
2264 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2265 !EC_KEY_generate_key(ecdh_b[j])) {
2266 BIO_printf(bio_err, "ECDH key generation failure.\n");
2267 ERR_print_errors(bio_err);
2271 * If field size is not more than 24 octets, then use SHA-1
2272 * hash of result; otherwise, use result (see section 4.8 of
2273 * draft-ietf-tls-ecc-03.txt).
2275 int field_size, outlen;
2276 void *(*kdf) (const void *in, size_t inlen, void *out,
2279 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2280 if (field_size <= 24 * 8) {
2281 outlen = KDF1_SHA1_len;
2284 outlen = (field_size + 7) / 8;
2288 ECDH_compute_key(secret_a, outlen,
2289 EC_KEY_get0_public_key(ecdh_b[j]),
2292 ECDH_compute_key(secret_b, outlen,
2293 EC_KEY_get0_public_key(ecdh_a[j]),
2295 if (secret_size_a != secret_size_b)
2300 for (secret_idx = 0; (secret_idx < secret_size_a)
2301 && (ecdh_checks == 1); secret_idx++) {
2302 if (secret_a[secret_idx] != secret_b[secret_idx])
2306 if (ecdh_checks == 0) {
2307 BIO_printf(bio_err, "ECDH computations don't match.\n");
2308 ERR_print_errors(bio_err);
2312 pkey_print_message("", "ecdh",
2314 test_curves_bits[j], ECDH_SECONDS);
2316 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]),
2323 mr ? "+R7:%ld:%d:%.2f\n" :
2324 "%ld %d-bit ECDH ops in %.2fs\n", count,
2325 test_curves_bits[j], d);
2326 ecdh_results[j][0] = d / (double)count;
2331 if (rsa_count <= 1) {
2332 /* if longer than 10s, don't do any more */
2333 for (j++; j < EC_NUM; j++)
2344 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2345 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2347 printf("%s ", BN_options());
2348 #ifndef OPENSSL_NO_MD2
2349 printf("%s ", MD2_options());
2351 #ifndef OPENSSL_NO_RC4
2352 printf("%s ", RC4_options());
2354 #ifndef OPENSSL_NO_DES
2355 printf("%s ", DES_options());
2357 #ifndef OPENSSL_NO_AES
2358 printf("%s ", AES_options());
2360 #ifndef OPENSSL_NO_IDEA
2361 printf("%s ", idea_options());
2363 #ifndef OPENSSL_NO_BF
2364 printf("%s ", BF_options());
2366 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2371 fprintf(stdout, "+H");
2374 "The 'numbers' are in 1000s of bytes per second processed.\n");
2375 fprintf(stdout, "type ");
2377 for (j = 0; j < SIZE_NUM; j++)
2378 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2379 fprintf(stdout, "\n");
2382 for (k = 0; k < ALGOR_NUM; k++) {
2386 fprintf(stdout, "+F:%d:%s", k, names[k]);
2388 fprintf(stdout, "%-13s", names[k]);
2389 for (j = 0; j < SIZE_NUM; j++) {
2390 if (results[k][j] > 10000 && !mr)
2391 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2393 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2395 fprintf(stdout, "\n");
2397 #ifndef OPENSSL_NO_RSA
2399 for (k = 0; k < RSA_NUM; k++) {
2403 printf("%18ssign verify sign/s verify/s\n", " ");
2407 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2408 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2410 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2411 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2412 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2415 #ifndef OPENSSL_NO_DSA
2417 for (k = 0; k < DSA_NUM; k++) {
2421 printf("%18ssign verify sign/s verify/s\n", " ");
2425 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2426 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2428 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2429 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2430 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2433 #ifndef OPENSSL_NO_ECDSA
2435 for (k = 0; k < EC_NUM; k++) {
2439 printf("%30ssign verify sign/s verify/s\n", " ");
2444 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2445 k, test_curves_bits[k],
2446 ecdsa_results[k][0], ecdsa_results[k][1]);
2449 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2450 test_curves_bits[k],
2451 test_curves_names[k],
2452 ecdsa_results[k][0], ecdsa_results[k][1],
2453 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2457 #ifndef OPENSSL_NO_ECDH
2459 for (k = 0; k < EC_NUM; k++) {
2463 printf("%30sop op/s\n", " ");
2467 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2468 k, test_curves_bits[k],
2469 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2472 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2473 test_curves_bits[k],
2474 test_curves_names[k],
2475 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2482 ERR_print_errors(bio_err);
2483 if (buf_malloc != NULL)
2484 OPENSSL_free(buf_malloc);
2485 if (buf2_malloc != NULL)
2486 OPENSSL_free(buf2_malloc);
2487 #ifndef OPENSSL_NO_RSA
2488 for (i = 0; i < RSA_NUM; i++)
2489 if (rsa_key[i] != NULL)
2490 RSA_free(rsa_key[i]);
2492 #ifndef OPENSSL_NO_DSA
2493 for (i = 0; i < DSA_NUM; i++)
2494 if (dsa_key[i] != NULL)
2495 DSA_free(dsa_key[i]);
2498 #ifndef OPENSSL_NO_ECDSA
2499 for (i = 0; i < EC_NUM; i++)
2500 if (ecdsa[i] != NULL)
2501 EC_KEY_free(ecdsa[i]);
2503 #ifndef OPENSSL_NO_ECDH
2504 for (i = 0; i < EC_NUM; i++) {
2505 if (ecdh_a[i] != NULL)
2506 EC_KEY_free(ecdh_a[i]);
2507 if (ecdh_b[i] != NULL)
2508 EC_KEY_free(ecdh_b[i]);
2516 static void print_message(const char *s, long num, int length)
2520 mr ? "+DT:%s:%d:%d\n"
2521 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2522 (void)BIO_flush(bio_err);
2526 mr ? "+DN:%s:%ld:%d\n"
2527 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2528 (void)BIO_flush(bio_err);
2532 static void pkey_print_message(const char *str, const char *str2, long num,
2537 mr ? "+DTP:%d:%s:%s:%d\n"
2538 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2539 (void)BIO_flush(bio_err);
2543 mr ? "+DNP:%ld:%d:%s:%s\n"
2544 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2545 (void)BIO_flush(bio_err);
2549 static void print_result(int alg, int run_no, int count, double time_used)
2552 mr ? "+R:%d:%s:%f\n"
2553 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2554 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2558 static char *sstrsep(char **string, const char *delim)
2561 char *token = *string;
2566 memset(isdelim, 0, sizeof isdelim);
2570 isdelim[(unsigned char)(*delim)] = 1;
2574 while (!isdelim[(unsigned char)(**string)]) {
2586 static int do_multi(int multi)
2591 static char sep[] = ":";
2593 fds = malloc(multi * sizeof *fds);
2594 for (n = 0; n < multi; ++n) {
2595 if (pipe(fd) == -1) {
2596 fprintf(stderr, "pipe failure\n");
2607 if (dup(fd[1]) == -1) {
2608 fprintf(stderr, "dup failed\n");
2617 printf("Forked child %d\n", n);
2620 /* for now, assume the pipe is long enough to take all the output */
2621 for (n = 0; n < multi; ++n) {
2626 f = fdopen(fds[n], "r");
2627 while (fgets(buf, sizeof buf, f)) {
2628 p = strchr(buf, '\n');
2631 if (buf[0] != '+') {
2632 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2636 printf("Got: %s from %d\n", buf, n);
2637 if (!strncmp(buf, "+F:", 3)) {
2642 alg = atoi(sstrsep(&p, sep));
2644 for (j = 0; j < SIZE_NUM; ++j)
2645 results[alg][j] += atof(sstrsep(&p, sep));
2646 } else if (!strncmp(buf, "+F2:", 4)) {
2651 k = atoi(sstrsep(&p, sep));
2654 d = atof(sstrsep(&p, sep));
2656 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2658 rsa_results[k][0] = d;
2660 d = atof(sstrsep(&p, sep));
2662 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2664 rsa_results[k][1] = d;
2665 } else if (!strncmp(buf, "+F2:", 4)) {
2670 k = atoi(sstrsep(&p, sep));
2673 d = atof(sstrsep(&p, sep));
2675 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2677 rsa_results[k][0] = d;
2679 d = atof(sstrsep(&p, sep));
2681 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2683 rsa_results[k][1] = d;
2685 # ifndef OPENSSL_NO_DSA
2686 else if (!strncmp(buf, "+F3:", 4)) {
2691 k = atoi(sstrsep(&p, sep));
2694 d = atof(sstrsep(&p, sep));
2696 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2698 dsa_results[k][0] = d;
2700 d = atof(sstrsep(&p, sep));
2702 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2704 dsa_results[k][1] = d;
2707 # ifndef OPENSSL_NO_ECDSA
2708 else if (!strncmp(buf, "+F4:", 4)) {
2713 k = atoi(sstrsep(&p, sep));
2716 d = atof(sstrsep(&p, sep));
2718 ecdsa_results[k][0] =
2719 1 / (1 / ecdsa_results[k][0] + 1 / d);
2721 ecdsa_results[k][0] = d;
2723 d = atof(sstrsep(&p, sep));
2725 ecdsa_results[k][1] =
2726 1 / (1 / ecdsa_results[k][1] + 1 / d);
2728 ecdsa_results[k][1] = d;
2732 # ifndef OPENSSL_NO_ECDH
2733 else if (!strncmp(buf, "+F5:", 4)) {
2738 k = atoi(sstrsep(&p, sep));
2741 d = atof(sstrsep(&p, sep));
2743 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2745 ecdh_results[k][0] = d;
2750 else if (!strncmp(buf, "+H:", 3)) {
2752 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2762 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2764 static int mblengths[] =
2765 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2766 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2767 const char *alg_name;
2768 unsigned char *inp, *out, no_key[32], no_iv[16];
2772 inp = OPENSSL_malloc(mblengths[num - 1]);
2773 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2775 EVP_CIPHER_CTX_init(&ctx);
2776 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2777 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2779 alg_name = OBJ_nid2ln(evp_cipher->nid);
2781 for (j = 0; j < num; j++) {
2782 print_message(alg_name, 0, mblengths[j]);
2784 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2785 unsigned char aad[13];
2786 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2787 size_t len = mblengths[j];
2790 memset(aad, 0, 8); /* avoid uninitialized values */
2791 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2792 aad[9] = 3; /* version */
2794 aad[11] = 0; /* length */
2796 mb_param.out = NULL;
2799 mb_param.interleave = 8;
2801 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2802 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2803 sizeof(mb_param), &mb_param);
2809 EVP_CIPHER_CTX_ctrl(&ctx,
2810 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2811 sizeof(mb_param), &mb_param);
2815 RAND_bytes(out, 16);
2819 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2820 EVP_CTRL_AEAD_TLS1_AAD, 13, aad);
2821 EVP_Cipher(&ctx, out, inp, len + pad);
2826 mr ? "+R:%d:%s:%f\n"
2827 : "%d %s's in %.2fs\n", count, "evp", d);
2828 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2832 fprintf(stdout, "+H");
2833 for (j = 0; j < num; j++)
2834 fprintf(stdout, ":%d", mblengths[j]);
2835 fprintf(stdout, "\n");
2836 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2837 for (j = 0; j < num; j++)
2838 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2839 fprintf(stdout, "\n");
2842 "The 'numbers' are in 1000s of bytes per second processed.\n");
2843 fprintf(stdout, "type ");
2844 for (j = 0; j < num; j++)
2845 fprintf(stdout, "%7d bytes", mblengths[j]);
2846 fprintf(stdout, "\n");
2847 fprintf(stdout, "%-24s", alg_name);
2849 for (j = 0; j < num; j++) {
2850 if (results[D_EVP][j] > 10000)
2851 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2853 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2855 fprintf(stdout, "\n");