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
877 # if 0 /* was: #ifdef RSAref */
878 if (strcmp(*argv, "rsaref") == 0) {
879 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
884 if (strcmp(*argv, "openssl") == 0) {
885 RSA_set_default_method(RSA_PKCS1_SSLeay());
889 #endif /* !OPENSSL_NO_RSA */
890 if (strcmp(*argv, "dsa512") == 0)
891 dsa_doit[R_DSA_512] = 2;
892 else if (strcmp(*argv, "dsa1024") == 0)
893 dsa_doit[R_DSA_1024] = 2;
894 else if (strcmp(*argv, "dsa2048") == 0)
895 dsa_doit[R_DSA_2048] = 2;
896 else if (strcmp(*argv, "rsa512") == 0)
897 rsa_doit[R_RSA_512] = 2;
898 else if (strcmp(*argv, "rsa1024") == 0)
899 rsa_doit[R_RSA_1024] = 2;
900 else if (strcmp(*argv, "rsa2048") == 0)
901 rsa_doit[R_RSA_2048] = 2;
902 else if (strcmp(*argv, "rsa3072") == 0)
903 rsa_doit[R_RSA_3072] = 2;
904 else if (strcmp(*argv, "rsa4096") == 0)
905 rsa_doit[R_RSA_4096] = 2;
906 else if (strcmp(*argv, "rsa7680") == 0)
907 rsa_doit[R_RSA_7680] = 2;
908 else if (strcmp(*argv, "rsa15360") == 0)
909 rsa_doit[R_RSA_15360] = 2;
911 #ifndef OPENSSL_NO_RC2
912 if (strcmp(*argv, "rc2-cbc") == 0)
914 else if (strcmp(*argv, "rc2") == 0)
918 #ifndef OPENSSL_NO_RC5
919 if (strcmp(*argv, "rc5-cbc") == 0)
921 else if (strcmp(*argv, "rc5") == 0)
925 #ifndef OPENSSL_NO_IDEA
926 if (strcmp(*argv, "idea-cbc") == 0)
927 doit[D_CBC_IDEA] = 1;
928 else if (strcmp(*argv, "idea") == 0)
929 doit[D_CBC_IDEA] = 1;
932 #ifndef OPENSSL_NO_SEED
933 if (strcmp(*argv, "seed-cbc") == 0)
934 doit[D_CBC_SEED] = 1;
935 else if (strcmp(*argv, "seed") == 0)
936 doit[D_CBC_SEED] = 1;
939 #ifndef OPENSSL_NO_BF
940 if (strcmp(*argv, "bf-cbc") == 0)
942 else if (strcmp(*argv, "blowfish") == 0)
944 else if (strcmp(*argv, "bf") == 0)
948 #ifndef OPENSSL_NO_CAST
949 if (strcmp(*argv, "cast-cbc") == 0)
950 doit[D_CBC_CAST] = 1;
951 else if (strcmp(*argv, "cast") == 0)
952 doit[D_CBC_CAST] = 1;
953 else if (strcmp(*argv, "cast5") == 0)
954 doit[D_CBC_CAST] = 1;
957 #ifndef OPENSSL_NO_DES
958 if (strcmp(*argv, "des") == 0) {
960 doit[D_EDE3_DES] = 1;
963 #ifndef OPENSSL_NO_AES
964 if (strcmp(*argv, "aes") == 0) {
965 doit[D_CBC_128_AES] = 1;
966 doit[D_CBC_192_AES] = 1;
967 doit[D_CBC_256_AES] = 1;
968 } else if (strcmp(*argv, "ghash") == 0) {
972 #ifndef OPENSSL_NO_CAMELLIA
973 if (strcmp(*argv, "camellia") == 0) {
974 doit[D_CBC_128_CML] = 1;
975 doit[D_CBC_192_CML] = 1;
976 doit[D_CBC_256_CML] = 1;
979 #ifndef OPENSSL_NO_RSA
980 if (strcmp(*argv, "rsa") == 0) {
981 rsa_doit[R_RSA_512] = 1;
982 rsa_doit[R_RSA_1024] = 1;
983 rsa_doit[R_RSA_2048] = 1;
984 rsa_doit[R_RSA_3072] = 1;
985 rsa_doit[R_RSA_4096] = 1;
986 rsa_doit[R_RSA_7680] = 1;
987 rsa_doit[R_RSA_15360] = 1;
990 #ifndef OPENSSL_NO_DSA
991 if (strcmp(*argv, "dsa") == 0) {
992 dsa_doit[R_DSA_512] = 1;
993 dsa_doit[R_DSA_1024] = 1;
994 dsa_doit[R_DSA_2048] = 1;
997 #ifndef OPENSSL_NO_ECDSA
998 if (strcmp(*argv, "ecdsap160") == 0)
999 ecdsa_doit[R_EC_P160] = 2;
1000 else if (strcmp(*argv, "ecdsap192") == 0)
1001 ecdsa_doit[R_EC_P192] = 2;
1002 else if (strcmp(*argv, "ecdsap224") == 0)
1003 ecdsa_doit[R_EC_P224] = 2;
1004 else if (strcmp(*argv, "ecdsap256") == 0)
1005 ecdsa_doit[R_EC_P256] = 2;
1006 else if (strcmp(*argv, "ecdsap384") == 0)
1007 ecdsa_doit[R_EC_P384] = 2;
1008 else if (strcmp(*argv, "ecdsap521") == 0)
1009 ecdsa_doit[R_EC_P521] = 2;
1010 else if (strcmp(*argv, "ecdsak163") == 0)
1011 ecdsa_doit[R_EC_K163] = 2;
1012 else if (strcmp(*argv, "ecdsak233") == 0)
1013 ecdsa_doit[R_EC_K233] = 2;
1014 else if (strcmp(*argv, "ecdsak283") == 0)
1015 ecdsa_doit[R_EC_K283] = 2;
1016 else if (strcmp(*argv, "ecdsak409") == 0)
1017 ecdsa_doit[R_EC_K409] = 2;
1018 else if (strcmp(*argv, "ecdsak571") == 0)
1019 ecdsa_doit[R_EC_K571] = 2;
1020 else if (strcmp(*argv, "ecdsab163") == 0)
1021 ecdsa_doit[R_EC_B163] = 2;
1022 else if (strcmp(*argv, "ecdsab233") == 0)
1023 ecdsa_doit[R_EC_B233] = 2;
1024 else if (strcmp(*argv, "ecdsab283") == 0)
1025 ecdsa_doit[R_EC_B283] = 2;
1026 else if (strcmp(*argv, "ecdsab409") == 0)
1027 ecdsa_doit[R_EC_B409] = 2;
1028 else if (strcmp(*argv, "ecdsab571") == 0)
1029 ecdsa_doit[R_EC_B571] = 2;
1030 else if (strcmp(*argv, "ecdsa") == 0) {
1031 for (i = 0; i < EC_NUM; i++)
1035 #ifndef OPENSSL_NO_ECDH
1036 if (strcmp(*argv, "ecdhp160") == 0)
1037 ecdh_doit[R_EC_P160] = 2;
1038 else if (strcmp(*argv, "ecdhp192") == 0)
1039 ecdh_doit[R_EC_P192] = 2;
1040 else if (strcmp(*argv, "ecdhp224") == 0)
1041 ecdh_doit[R_EC_P224] = 2;
1042 else if (strcmp(*argv, "ecdhp256") == 0)
1043 ecdh_doit[R_EC_P256] = 2;
1044 else if (strcmp(*argv, "ecdhp384") == 0)
1045 ecdh_doit[R_EC_P384] = 2;
1046 else if (strcmp(*argv, "ecdhp521") == 0)
1047 ecdh_doit[R_EC_P521] = 2;
1048 else if (strcmp(*argv, "ecdhk163") == 0)
1049 ecdh_doit[R_EC_K163] = 2;
1050 else if (strcmp(*argv, "ecdhk233") == 0)
1051 ecdh_doit[R_EC_K233] = 2;
1052 else if (strcmp(*argv, "ecdhk283") == 0)
1053 ecdh_doit[R_EC_K283] = 2;
1054 else if (strcmp(*argv, "ecdhk409") == 0)
1055 ecdh_doit[R_EC_K409] = 2;
1056 else if (strcmp(*argv, "ecdhk571") == 0)
1057 ecdh_doit[R_EC_K571] = 2;
1058 else if (strcmp(*argv, "ecdhb163") == 0)
1059 ecdh_doit[R_EC_B163] = 2;
1060 else if (strcmp(*argv, "ecdhb233") == 0)
1061 ecdh_doit[R_EC_B233] = 2;
1062 else if (strcmp(*argv, "ecdhb283") == 0)
1063 ecdh_doit[R_EC_B283] = 2;
1064 else if (strcmp(*argv, "ecdhb409") == 0)
1065 ecdh_doit[R_EC_B409] = 2;
1066 else if (strcmp(*argv, "ecdhb571") == 0)
1067 ecdh_doit[R_EC_B571] = 2;
1068 else if (strcmp(*argv, "ecdh") == 0) {
1069 for (i = 0; i < EC_NUM; i++)
1074 BIO_printf(bio_err, "Error: bad option or value\n");
1075 BIO_printf(bio_err, "\n");
1076 BIO_printf(bio_err, "Available values:\n");
1077 #ifndef OPENSSL_NO_MD2
1078 BIO_printf(bio_err, "md2 ");
1080 #ifndef OPENSSL_NO_MDC2
1081 BIO_printf(bio_err, "mdc2 ");
1083 #ifndef OPENSSL_NO_MD4
1084 BIO_printf(bio_err, "md4 ");
1086 #ifndef OPENSSL_NO_MD5
1087 BIO_printf(bio_err, "md5 ");
1088 # ifndef OPENSSL_NO_HMAC
1089 BIO_printf(bio_err, "hmac ");
1092 BIO_printf(bio_err, "sha1 ");
1093 BIO_printf(bio_err, "sha256 ");
1094 BIO_printf(bio_err, "sha512 ");
1095 #ifndef OPENSSL_NO_WHIRLPOOL
1096 BIO_printf(bio_err, "whirlpool");
1098 #ifndef OPENSSL_NO_RMD160
1099 BIO_printf(bio_err, "rmd160");
1101 BIO_printf(bio_err, "\n");
1103 #ifndef OPENSSL_NO_IDEA
1104 BIO_printf(bio_err, "idea-cbc ");
1106 #ifndef OPENSSL_NO_SEED
1107 BIO_printf(bio_err, "seed-cbc ");
1109 #ifndef OPENSSL_NO_RC2
1110 BIO_printf(bio_err, "rc2-cbc ");
1112 #ifndef OPENSSL_NO_RC5
1113 BIO_printf(bio_err, "rc5-cbc ");
1115 #ifndef OPENSSL_NO_BF
1116 BIO_printf(bio_err, "bf-cbc");
1118 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1119 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1120 BIO_printf(bio_err, "\n");
1122 #ifndef OPENSSL_NO_DES
1123 BIO_printf(bio_err, "des-cbc des-ede3 ");
1125 #ifndef OPENSSL_NO_AES
1126 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1127 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1129 #ifndef OPENSSL_NO_CAMELLIA
1130 BIO_printf(bio_err, "\n");
1132 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1134 #ifndef OPENSSL_NO_RC4
1135 BIO_printf(bio_err, "rc4");
1137 BIO_printf(bio_err, "\n");
1139 #ifndef OPENSSL_NO_RSA
1141 "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1142 BIO_printf(bio_err, "rsa7680 rsa15360\n");
1145 #ifndef OPENSSL_NO_DSA
1146 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1148 #ifndef OPENSSL_NO_ECDSA
1149 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1150 "ecdsap256 ecdsap384 ecdsap521\n");
1152 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1154 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1155 BIO_printf(bio_err, "ecdsa\n");
1157 #ifndef OPENSSL_NO_ECDH
1158 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1159 "ecdhp256 ecdhp384 ecdhp521\n");
1161 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1163 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1164 BIO_printf(bio_err, "ecdh\n");
1167 #ifndef OPENSSL_NO_IDEA
1168 BIO_printf(bio_err, "idea ");
1170 #ifndef OPENSSL_NO_SEED
1171 BIO_printf(bio_err, "seed ");
1173 #ifndef OPENSSL_NO_RC2
1174 BIO_printf(bio_err, "rc2 ");
1176 #ifndef OPENSSL_NO_DES
1177 BIO_printf(bio_err, "des ");
1179 #ifndef OPENSSL_NO_AES
1180 BIO_printf(bio_err, "aes ");
1182 #ifndef OPENSSL_NO_CAMELLIA
1183 BIO_printf(bio_err, "camellia ");
1185 #ifndef OPENSSL_NO_RSA
1186 BIO_printf(bio_err, "rsa ");
1188 #ifndef OPENSSL_NO_BF
1189 BIO_printf(bio_err, "blowfish");
1191 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1192 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1193 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1194 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1195 BIO_printf(bio_err, "\n");
1198 BIO_printf(bio_err, "\n");
1199 BIO_printf(bio_err, "Available options:\n");
1200 #if defined(TIMES) || defined(USE_TOD)
1201 BIO_printf(bio_err, "-elapsed "
1202 "measure time in real time instead of CPU user time.\n");
1204 #ifndef OPENSSL_NO_ENGINE
1207 "use engine e, possibly a hardware device.\n");
1209 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1212 "time decryption instead of encryption (only EVP).\n");
1215 "produce machine readable output.\n");
1218 "perform multi-block benchmark (for specific ciphers)\n");
1221 "perform benchmark with misaligned data\n");
1224 "-multi n " "run n benchmarks in parallel.\n");
1234 if (multi && do_multi(multi))
1239 for (i = 0; i < ALGOR_NUM; i++) {
1243 for (i = 0; i < RSA_NUM; i++)
1245 for (i = 0; i < DSA_NUM; i++)
1247 #ifndef OPENSSL_NO_ECDSA
1248 for (i = 0; i < EC_NUM; i++)
1251 #ifndef OPENSSL_NO_ECDH
1252 for (i = 0; i < EC_NUM; i++)
1256 for (i = 0; i < ALGOR_NUM; i++)
1260 if (usertime == 0 && !mr)
1262 "You have chosen to measure elapsed time "
1263 "instead of user CPU time.\n");
1265 #ifndef OPENSSL_NO_RSA
1266 for (i = 0; i < RSA_NUM; i++) {
1267 const unsigned char *p;
1270 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1271 if (rsa_key[i] == NULL) {
1272 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1280 : "Loaded RSA key, %d bit modulus and e= 0x",
1281 BN_num_bits(rsa_key[i]->n));
1282 BN_print(bio_err, rsa_key[i]->e);
1283 BIO_printf(bio_err, "\n");
1289 #ifndef OPENSSL_NO_DSA
1290 dsa_key[0] = get_dsa512();
1291 dsa_key[1] = get_dsa1024();
1292 dsa_key[2] = get_dsa2048();
1295 #ifndef OPENSSL_NO_DES
1296 DES_set_key_unchecked(&key, &sch);
1297 DES_set_key_unchecked(&key2, &sch2);
1298 DES_set_key_unchecked(&key3, &sch3);
1300 #ifndef OPENSSL_NO_AES
1301 AES_set_encrypt_key(key16, 128, &aes_ks1);
1302 AES_set_encrypt_key(key24, 192, &aes_ks2);
1303 AES_set_encrypt_key(key32, 256, &aes_ks3);
1305 #ifndef OPENSSL_NO_CAMELLIA
1306 Camellia_set_key(key16, 128, &camellia_ks1);
1307 Camellia_set_key(ckey24, 192, &camellia_ks2);
1308 Camellia_set_key(ckey32, 256, &camellia_ks3);
1310 #ifndef OPENSSL_NO_IDEA
1311 idea_set_encrypt_key(key16, &idea_ks);
1313 #ifndef OPENSSL_NO_SEED
1314 SEED_set_key(key16, &seed_ks);
1316 #ifndef OPENSSL_NO_RC4
1317 RC4_set_key(&rc4_ks, 16, key16);
1319 #ifndef OPENSSL_NO_RC2
1320 RC2_set_key(&rc2_ks, 16, key16, 128);
1322 #ifndef OPENSSL_NO_RC5
1323 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1325 #ifndef OPENSSL_NO_BF
1326 BF_set_key(&bf_ks, 16, key16);
1328 #ifndef OPENSSL_NO_CAST
1329 CAST_set_key(&cast_ks, 16, key16);
1331 #ifndef OPENSSL_NO_RSA
1332 memset(rsa_c, 0, sizeof(rsa_c));
1335 # ifndef OPENSSL_NO_DES
1336 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1342 for (it = count; it; it--)
1343 DES_ecb_encrypt((DES_cblock *)buf,
1344 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1348 c[D_MD2][0] = count / 10;
1349 c[D_MDC2][0] = count / 10;
1350 c[D_MD4][0] = count;
1351 c[D_MD5][0] = count;
1352 c[D_HMAC][0] = count;
1353 c[D_SHA1][0] = count;
1354 c[D_RMD160][0] = count;
1355 c[D_RC4][0] = count * 5;
1356 c[D_CBC_DES][0] = count;
1357 c[D_EDE3_DES][0] = count / 3;
1358 c[D_CBC_IDEA][0] = count;
1359 c[D_CBC_SEED][0] = count;
1360 c[D_CBC_RC2][0] = count;
1361 c[D_CBC_RC5][0] = count;
1362 c[D_CBC_BF][0] = count;
1363 c[D_CBC_CAST][0] = count;
1364 c[D_CBC_128_AES][0] = count;
1365 c[D_CBC_192_AES][0] = count;
1366 c[D_CBC_256_AES][0] = count;
1367 c[D_CBC_128_CML][0] = count;
1368 c[D_CBC_192_CML][0] = count;
1369 c[D_CBC_256_CML][0] = count;
1370 c[D_SHA256][0] = count;
1371 c[D_SHA512][0] = count;
1372 c[D_WHIRLPOOL][0] = count;
1373 c[D_IGE_128_AES][0] = count;
1374 c[D_IGE_192_AES][0] = count;
1375 c[D_IGE_256_AES][0] = count;
1376 c[D_GHASH][0] = count;
1378 for (i = 1; i < SIZE_NUM; i++) {
1381 l0 = (long)lengths[0];
1382 l1 = (long)lengths[i];
1384 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1385 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1386 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1387 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1388 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1389 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1390 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1391 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1392 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1393 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1395 l0 = (long)lengths[i - 1];
1397 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1398 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1399 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1400 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1401 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1402 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1403 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1404 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1405 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1406 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1407 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1408 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1409 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1410 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1411 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1412 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1413 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1414 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1417 # ifndef OPENSSL_NO_RSA
1418 rsa_c[R_RSA_512][0] = count / 2000;
1419 rsa_c[R_RSA_512][1] = count / 400;
1420 for (i = 1; i < RSA_NUM; i++) {
1421 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1422 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1423 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1426 if (rsa_c[i][0] == 0) {
1434 # ifndef OPENSSL_NO_DSA
1435 dsa_c[R_DSA_512][0] = count / 1000;
1436 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1437 for (i = 1; i < DSA_NUM; i++) {
1438 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1439 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1440 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1443 if (dsa_c[i] == 0) {
1451 # ifndef OPENSSL_NO_ECDSA
1452 ecdsa_c[R_EC_P160][0] = count / 1000;
1453 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1454 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1455 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1456 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1457 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1460 if (ecdsa_c[i] == 0) {
1466 ecdsa_c[R_EC_K163][0] = count / 1000;
1467 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1468 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1469 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1470 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1471 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1474 if (ecdsa_c[i] == 0) {
1480 ecdsa_c[R_EC_B163][0] = count / 1000;
1481 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1482 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1483 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1484 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1485 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1488 if (ecdsa_c[i] == 0) {
1496 # ifndef OPENSSL_NO_ECDH
1497 ecdh_c[R_EC_P160][0] = count / 1000;
1498 ecdh_c[R_EC_P160][1] = count / 1000;
1499 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1500 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1501 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1502 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1505 if (ecdh_c[i] == 0) {
1511 ecdh_c[R_EC_K163][0] = count / 1000;
1512 ecdh_c[R_EC_K163][1] = count / 1000;
1513 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1514 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1515 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1516 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1519 if (ecdh_c[i] == 0) {
1525 ecdh_c[R_EC_B163][0] = count / 1000;
1526 ecdh_c[R_EC_B163][1] = count / 1000;
1527 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1528 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1529 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1530 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1533 if (ecdh_c[i] == 0) {
1541 # define COND(d) (count < (d))
1542 # define COUNT(d) (d)
1544 /* not worth fixing */
1545 # error "You cannot disable DES on systems without SIGALRM."
1546 # endif /* OPENSSL_NO_DES */
1548 # define COND(c) (run && count<0x7fffffff)
1549 # define COUNT(d) (count)
1551 signal(SIGALRM, sig_done);
1553 #endif /* SIGALRM */
1555 #ifndef OPENSSL_NO_MD2
1557 for (j = 0; j < SIZE_NUM; j++) {
1558 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1560 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1561 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1564 print_result(D_MD2, j, count, d);
1568 #ifndef OPENSSL_NO_MDC2
1570 for (j = 0; j < SIZE_NUM; j++) {
1571 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1573 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1574 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1577 print_result(D_MDC2, j, count, d);
1582 #ifndef OPENSSL_NO_MD4
1584 for (j = 0; j < SIZE_NUM; j++) {
1585 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1587 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1588 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1589 NULL, EVP_md4(), NULL);
1591 print_result(D_MD4, j, count, d);
1596 #ifndef OPENSSL_NO_MD5
1598 for (j = 0; j < SIZE_NUM; j++) {
1599 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1601 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1602 MD5(buf, lengths[j], md5);
1604 print_result(D_MD5, j, count, d);
1609 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1613 HMAC_CTX_init(&hctx);
1614 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1615 16, EVP_md5(), NULL);
1617 for (j = 0; j < SIZE_NUM; j++) {
1618 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1620 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1621 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1622 HMAC_Update(&hctx, buf, lengths[j]);
1623 HMAC_Final(&hctx, &(hmac[0]), NULL);
1626 print_result(D_HMAC, j, count, d);
1628 HMAC_CTX_cleanup(&hctx);
1632 for (j = 0; j < SIZE_NUM; j++) {
1633 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1635 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1636 SHA1(buf, lengths[j], sha);
1638 print_result(D_SHA1, j, count, d);
1641 if (doit[D_SHA256]) {
1642 for (j = 0; j < SIZE_NUM; j++) {
1643 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1645 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1646 SHA256(buf, lengths[j], sha256);
1648 print_result(D_SHA256, j, count, d);
1651 if (doit[D_SHA512]) {
1652 for (j = 0; j < SIZE_NUM; j++) {
1653 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1655 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1656 SHA512(buf, lengths[j], sha512);
1658 print_result(D_SHA512, j, count, d);
1662 #ifndef OPENSSL_NO_WHIRLPOOL
1663 if (doit[D_WHIRLPOOL]) {
1664 for (j = 0; j < SIZE_NUM; j++) {
1665 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1667 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1668 WHIRLPOOL(buf, lengths[j], whirlpool);
1670 print_result(D_WHIRLPOOL, j, count, d);
1675 #ifndef OPENSSL_NO_RMD160
1676 if (doit[D_RMD160]) {
1677 for (j = 0; j < SIZE_NUM; j++) {
1678 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1680 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1681 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1682 EVP_ripemd160(), NULL);
1684 print_result(D_RMD160, j, count, d);
1688 #ifndef OPENSSL_NO_RC4
1690 for (j = 0; j < SIZE_NUM; j++) {
1691 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1693 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1694 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1696 print_result(D_RC4, j, count, d);
1700 #ifndef OPENSSL_NO_DES
1701 if (doit[D_CBC_DES]) {
1702 for (j = 0; j < SIZE_NUM; j++) {
1703 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1705 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1706 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1707 &DES_iv, DES_ENCRYPT);
1709 print_result(D_CBC_DES, j, count, d);
1713 if (doit[D_EDE3_DES]) {
1714 for (j = 0; j < SIZE_NUM; j++) {
1715 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1717 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1718 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1720 &DES_iv, DES_ENCRYPT);
1722 print_result(D_EDE3_DES, j, count, d);
1726 #ifndef OPENSSL_NO_AES
1727 if (doit[D_CBC_128_AES]) {
1728 for (j = 0; j < SIZE_NUM; j++) {
1729 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1732 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1733 AES_cbc_encrypt(buf, buf,
1734 (unsigned long)lengths[j], &aes_ks1,
1737 print_result(D_CBC_128_AES, j, count, d);
1740 if (doit[D_CBC_192_AES]) {
1741 for (j = 0; j < SIZE_NUM; j++) {
1742 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1745 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1746 AES_cbc_encrypt(buf, buf,
1747 (unsigned long)lengths[j], &aes_ks2,
1750 print_result(D_CBC_192_AES, j, count, d);
1753 if (doit[D_CBC_256_AES]) {
1754 for (j = 0; j < SIZE_NUM; j++) {
1755 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1758 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1759 AES_cbc_encrypt(buf, buf,
1760 (unsigned long)lengths[j], &aes_ks3,
1763 print_result(D_CBC_256_AES, j, count, d);
1767 if (doit[D_IGE_128_AES]) {
1768 for (j = 0; j < SIZE_NUM; j++) {
1769 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1772 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1773 AES_ige_encrypt(buf, buf2,
1774 (unsigned long)lengths[j], &aes_ks1,
1777 print_result(D_IGE_128_AES, j, count, d);
1780 if (doit[D_IGE_192_AES]) {
1781 for (j = 0; j < SIZE_NUM; j++) {
1782 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1785 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1786 AES_ige_encrypt(buf, buf2,
1787 (unsigned long)lengths[j], &aes_ks2,
1790 print_result(D_IGE_192_AES, j, count, d);
1793 if (doit[D_IGE_256_AES]) {
1794 for (j = 0; j < SIZE_NUM; j++) {
1795 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1798 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1799 AES_ige_encrypt(buf, buf2,
1800 (unsigned long)lengths[j], &aes_ks3,
1803 print_result(D_IGE_256_AES, j, count, d);
1806 if (doit[D_GHASH]) {
1807 GCM128_CONTEXT *ctx =
1808 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1809 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1811 for (j = 0; j < SIZE_NUM; j++) {
1812 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1814 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1815 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1817 print_result(D_GHASH, j, count, d);
1819 CRYPTO_gcm128_release(ctx);
1822 #ifndef OPENSSL_NO_CAMELLIA
1823 if (doit[D_CBC_128_CML]) {
1824 for (j = 0; j < SIZE_NUM; j++) {
1825 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1828 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1829 Camellia_cbc_encrypt(buf, buf,
1830 (unsigned long)lengths[j], &camellia_ks1,
1831 iv, CAMELLIA_ENCRYPT);
1833 print_result(D_CBC_128_CML, j, count, d);
1836 if (doit[D_CBC_192_CML]) {
1837 for (j = 0; j < SIZE_NUM; j++) {
1838 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1841 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1842 Camellia_cbc_encrypt(buf, buf,
1843 (unsigned long)lengths[j], &camellia_ks2,
1844 iv, CAMELLIA_ENCRYPT);
1846 print_result(D_CBC_192_CML, j, count, d);
1849 if (doit[D_CBC_256_CML]) {
1850 for (j = 0; j < SIZE_NUM; j++) {
1851 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1854 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1855 Camellia_cbc_encrypt(buf, buf,
1856 (unsigned long)lengths[j], &camellia_ks3,
1857 iv, CAMELLIA_ENCRYPT);
1859 print_result(D_CBC_256_CML, j, count, d);
1863 #ifndef OPENSSL_NO_IDEA
1864 if (doit[D_CBC_IDEA]) {
1865 for (j = 0; j < SIZE_NUM; j++) {
1866 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1868 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1869 idea_cbc_encrypt(buf, buf,
1870 (unsigned long)lengths[j], &idea_ks,
1873 print_result(D_CBC_IDEA, j, count, d);
1877 #ifndef OPENSSL_NO_SEED
1878 if (doit[D_CBC_SEED]) {
1879 for (j = 0; j < SIZE_NUM; j++) {
1880 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1882 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1883 SEED_cbc_encrypt(buf, buf,
1884 (unsigned long)lengths[j], &seed_ks, iv, 1);
1886 print_result(D_CBC_SEED, j, count, d);
1890 #ifndef OPENSSL_NO_RC2
1891 if (doit[D_CBC_RC2]) {
1892 for (j = 0; j < SIZE_NUM; j++) {
1893 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1895 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1896 RC2_cbc_encrypt(buf, buf,
1897 (unsigned long)lengths[j], &rc2_ks,
1900 print_result(D_CBC_RC2, j, count, d);
1904 #ifndef OPENSSL_NO_RC5
1905 if (doit[D_CBC_RC5]) {
1906 for (j = 0; j < SIZE_NUM; j++) {
1907 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1909 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1910 RC5_32_cbc_encrypt(buf, buf,
1911 (unsigned long)lengths[j], &rc5_ks,
1914 print_result(D_CBC_RC5, j, count, d);
1918 #ifndef OPENSSL_NO_BF
1919 if (doit[D_CBC_BF]) {
1920 for (j = 0; j < SIZE_NUM; j++) {
1921 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1923 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1924 BF_cbc_encrypt(buf, buf,
1925 (unsigned long)lengths[j], &bf_ks,
1928 print_result(D_CBC_BF, j, count, d);
1932 #ifndef OPENSSL_NO_CAST
1933 if (doit[D_CBC_CAST]) {
1934 for (j = 0; j < SIZE_NUM; j++) {
1935 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1937 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1938 CAST_cbc_encrypt(buf, buf,
1939 (unsigned long)lengths[j], &cast_ks,
1942 print_result(D_CBC_CAST, j, count, d);
1948 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1949 if (multiblock && evp_cipher) {
1951 (EVP_CIPHER_flags(evp_cipher) &
1952 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1953 fprintf(stderr, "%s is not multi-block capable\n",
1954 OBJ_nid2ln(evp_cipher->nid));
1957 multiblock_speed(evp_cipher);
1962 for (j = 0; j < SIZE_NUM; j++) {
1967 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1969 * -O3 -fschedule-insns messes up an optimization here!
1970 * names[D_EVP] somehow becomes NULL
1972 print_message(names[D_EVP], save_count, lengths[j]);
1974 EVP_CIPHER_CTX_init(&ctx);
1976 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1978 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1979 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1983 for (count = 0, run = 1;
1984 COND(save_count * 4 * lengths[0] / lengths[j]);
1986 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1988 for (count = 0, run = 1;
1989 COND(save_count * 4 * lengths[0] / lengths[j]);
1991 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1993 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1995 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1997 EVP_CIPHER_CTX_cleanup(&ctx);
2000 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2001 print_message(names[D_EVP], save_count, lengths[j]);
2004 for (count = 0, run = 1;
2005 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2006 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2010 print_result(D_EVP, j, count, d);
2013 #ifndef OPENSSL_SYS_WIN32
2015 RAND_pseudo_bytes(buf, 36);
2016 #ifndef OPENSSL_NO_RSA
2017 for (j = 0; j < RSA_NUM; j++) {
2021 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2024 "RSA sign failure. No RSA sign will be done.\n");
2025 ERR_print_errors(bio_err);
2028 pkey_print_message("private", "rsa",
2029 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2030 /* RSA_blinding_on(rsa_key[j],NULL); */
2032 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2033 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2034 &rsa_num, rsa_key[j]);
2036 BIO_printf(bio_err, "RSA sign failure\n");
2037 ERR_print_errors(bio_err);
2044 mr ? "+R1:%ld:%d:%.2f\n"
2045 : "%ld %d bit private RSA's in %.2fs\n",
2046 count, rsa_bits[j], d);
2047 rsa_results[j][0] = d / (double)count;
2052 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2055 "RSA verify failure. No RSA verify will be done.\n");
2056 ERR_print_errors(bio_err);
2059 pkey_print_message("public", "rsa",
2060 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2062 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2063 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2064 rsa_num, rsa_key[j]);
2066 BIO_printf(bio_err, "RSA verify failure\n");
2067 ERR_print_errors(bio_err);
2074 mr ? "+R2:%ld:%d:%.2f\n"
2075 : "%ld %d bit public RSA's in %.2fs\n",
2076 count, rsa_bits[j], d);
2077 rsa_results[j][1] = d / (double)count;
2081 if (rsa_count <= 1) {
2082 /* if longer than 10s, don't do any more */
2083 for (j++; j < RSA_NUM; j++)
2089 RAND_pseudo_bytes(buf, 20);
2090 #ifndef OPENSSL_NO_DSA
2091 if (RAND_status() != 1) {
2092 RAND_seed(rnd_seed, sizeof rnd_seed);
2095 for (j = 0; j < DSA_NUM; j++) {
2102 /* DSA_generate_key(dsa_key[j]); */
2103 /* DSA_sign_setup(dsa_key[j],NULL); */
2104 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2107 "DSA sign failure. No DSA sign will be done.\n");
2108 ERR_print_errors(bio_err);
2111 pkey_print_message("sign", "dsa",
2112 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2114 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2115 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2117 BIO_printf(bio_err, "DSA sign failure\n");
2118 ERR_print_errors(bio_err);
2125 mr ? "+R3:%ld:%d:%.2f\n"
2126 : "%ld %d bit DSA signs in %.2fs\n",
2127 count, dsa_bits[j], d);
2128 dsa_results[j][0] = d / (double)count;
2132 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2135 "DSA verify failure. No DSA verify will be done.\n");
2136 ERR_print_errors(bio_err);
2139 pkey_print_message("verify", "dsa",
2140 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2142 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2143 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2145 BIO_printf(bio_err, "DSA verify failure\n");
2146 ERR_print_errors(bio_err);
2153 mr ? "+R4:%ld:%d:%.2f\n"
2154 : "%ld %d bit DSA verify in %.2fs\n",
2155 count, dsa_bits[j], d);
2156 dsa_results[j][1] = d / (double)count;
2159 if (rsa_count <= 1) {
2160 /* if longer than 10s, don't do any more */
2161 for (j++; j < DSA_NUM; j++)
2169 #ifndef OPENSSL_NO_ECDSA
2170 if (RAND_status() != 1) {
2171 RAND_seed(rnd_seed, sizeof rnd_seed);
2174 for (j = 0; j < EC_NUM; j++) {
2178 continue; /* Ignore Curve */
2179 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2180 if (ecdsa[j] == NULL) {
2181 BIO_printf(bio_err, "ECDSA failure.\n");
2182 ERR_print_errors(bio_err);
2186 EC_KEY_precompute_mult(ecdsa[j], NULL);
2188 /* Perform ECDSA signature test */
2189 EC_KEY_generate_key(ecdsa[j]);
2190 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2193 "ECDSA sign failure. No ECDSA sign will be done.\n");
2194 ERR_print_errors(bio_err);
2197 pkey_print_message("sign", "ecdsa",
2199 test_curves_bits[j], ECDSA_SECONDS);
2202 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2203 ret = ECDSA_sign(0, buf, 20,
2204 ecdsasig, &ecdsasiglen, ecdsa[j]);
2206 BIO_printf(bio_err, "ECDSA sign failure\n");
2207 ERR_print_errors(bio_err);
2215 mr ? "+R5:%ld:%d:%.2f\n" :
2216 "%ld %d bit ECDSA signs in %.2fs \n",
2217 count, test_curves_bits[j], d);
2218 ecdsa_results[j][0] = d / (double)count;
2222 /* Perform ECDSA verification test */
2223 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2226 "ECDSA verify failure. No ECDSA verify will be done.\n");
2227 ERR_print_errors(bio_err);
2230 pkey_print_message("verify", "ecdsa",
2232 test_curves_bits[j], ECDSA_SECONDS);
2234 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2236 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2239 BIO_printf(bio_err, "ECDSA verify failure\n");
2240 ERR_print_errors(bio_err);
2247 mr ? "+R6:%ld:%d:%.2f\n"
2248 : "%ld %d bit ECDSA verify in %.2fs\n",
2249 count, test_curves_bits[j], d);
2250 ecdsa_results[j][1] = d / (double)count;
2253 if (rsa_count <= 1) {
2254 /* if longer than 10s, don't do any more */
2255 for (j++; j < EC_NUM; j++)
2264 #ifndef OPENSSL_NO_ECDH
2265 if (RAND_status() != 1) {
2266 RAND_seed(rnd_seed, sizeof rnd_seed);
2269 for (j = 0; j < EC_NUM; j++) {
2272 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2273 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2274 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2275 BIO_printf(bio_err, "ECDH failure.\n");
2276 ERR_print_errors(bio_err);
2279 /* generate two ECDH key pairs */
2280 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2281 !EC_KEY_generate_key(ecdh_b[j])) {
2282 BIO_printf(bio_err, "ECDH key generation failure.\n");
2283 ERR_print_errors(bio_err);
2287 * If field size is not more than 24 octets, then use SHA-1
2288 * hash of result; otherwise, use result (see section 4.8 of
2289 * draft-ietf-tls-ecc-03.txt).
2291 int field_size, outlen;
2292 void *(*kdf) (const void *in, size_t inlen, void *out,
2295 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2296 if (field_size <= 24 * 8) {
2297 outlen = KDF1_SHA1_len;
2300 outlen = (field_size + 7) / 8;
2304 ECDH_compute_key(secret_a, outlen,
2305 EC_KEY_get0_public_key(ecdh_b[j]),
2308 ECDH_compute_key(secret_b, outlen,
2309 EC_KEY_get0_public_key(ecdh_a[j]),
2311 if (secret_size_a != secret_size_b)
2316 for (secret_idx = 0; (secret_idx < secret_size_a)
2317 && (ecdh_checks == 1); secret_idx++) {
2318 if (secret_a[secret_idx] != secret_b[secret_idx])
2322 if (ecdh_checks == 0) {
2323 BIO_printf(bio_err, "ECDH computations don't match.\n");
2324 ERR_print_errors(bio_err);
2328 pkey_print_message("", "ecdh",
2330 test_curves_bits[j], ECDH_SECONDS);
2332 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2333 ECDH_compute_key(secret_a, outlen,
2334 EC_KEY_get0_public_key(ecdh_b[j]),
2339 mr ? "+R7:%ld:%d:%.2f\n" :
2340 "%ld %d-bit ECDH ops in %.2fs\n", count,
2341 test_curves_bits[j], d);
2342 ecdh_results[j][0] = d / (double)count;
2347 if (rsa_count <= 1) {
2348 /* if longer than 10s, don't do any more */
2349 for (j++; j < EC_NUM; j++)
2360 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2361 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2363 printf("%s ", BN_options());
2364 #ifndef OPENSSL_NO_MD2
2365 printf("%s ", MD2_options());
2367 #ifndef OPENSSL_NO_RC4
2368 printf("%s ", RC4_options());
2370 #ifndef OPENSSL_NO_DES
2371 printf("%s ", DES_options());
2373 #ifndef OPENSSL_NO_AES
2374 printf("%s ", AES_options());
2376 #ifndef OPENSSL_NO_IDEA
2377 printf("%s ", idea_options());
2379 #ifndef OPENSSL_NO_BF
2380 printf("%s ", BF_options());
2382 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2387 fprintf(stdout, "+H");
2390 "The 'numbers' are in 1000s of bytes per second processed.\n");
2391 fprintf(stdout, "type ");
2393 for (j = 0; j < SIZE_NUM; j++)
2394 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2395 fprintf(stdout, "\n");
2398 for (k = 0; k < ALGOR_NUM; k++) {
2402 fprintf(stdout, "+F:%d:%s", k, names[k]);
2404 fprintf(stdout, "%-13s", names[k]);
2405 for (j = 0; j < SIZE_NUM; j++) {
2406 if (results[k][j] > 10000 && !mr)
2407 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2409 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2411 fprintf(stdout, "\n");
2413 #ifndef OPENSSL_NO_RSA
2415 for (k = 0; k < RSA_NUM; k++) {
2419 printf("%18ssign verify sign/s verify/s\n", " ");
2423 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2424 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2426 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2427 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2428 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2431 #ifndef OPENSSL_NO_DSA
2433 for (k = 0; k < DSA_NUM; k++) {
2437 printf("%18ssign verify sign/s verify/s\n", " ");
2441 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2442 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2444 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2445 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2446 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2449 #ifndef OPENSSL_NO_ECDSA
2451 for (k = 0; k < EC_NUM; k++) {
2455 printf("%30ssign verify sign/s verify/s\n", " ");
2460 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2461 k, test_curves_bits[k],
2462 ecdsa_results[k][0], ecdsa_results[k][1]);
2465 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2466 test_curves_bits[k],
2467 test_curves_names[k],
2468 ecdsa_results[k][0], ecdsa_results[k][1],
2469 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2473 #ifndef OPENSSL_NO_ECDH
2475 for (k = 0; k < EC_NUM; k++) {
2479 printf("%30sop op/s\n", " ");
2483 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2484 k, test_curves_bits[k],
2485 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2488 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2489 test_curves_bits[k],
2490 test_curves_names[k],
2491 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2498 ERR_print_errors(bio_err);
2499 if (buf_malloc != NULL)
2500 OPENSSL_free(buf_malloc);
2501 if (buf2_malloc != NULL)
2502 OPENSSL_free(buf2_malloc);
2503 #ifndef OPENSSL_NO_RSA
2504 for (i = 0; i < RSA_NUM; i++)
2505 if (rsa_key[i] != NULL)
2506 RSA_free(rsa_key[i]);
2508 #ifndef OPENSSL_NO_DSA
2509 for (i = 0; i < DSA_NUM; i++)
2510 if (dsa_key[i] != NULL)
2511 DSA_free(dsa_key[i]);
2514 #ifndef OPENSSL_NO_ECDSA
2515 for (i = 0; i < EC_NUM; i++)
2516 if (ecdsa[i] != NULL)
2517 EC_KEY_free(ecdsa[i]);
2519 #ifndef OPENSSL_NO_ECDH
2520 for (i = 0; i < EC_NUM; i++) {
2521 if (ecdh_a[i] != NULL)
2522 EC_KEY_free(ecdh_a[i]);
2523 if (ecdh_b[i] != NULL)
2524 EC_KEY_free(ecdh_b[i]);
2532 static void print_message(const char *s, long num, int length)
2536 mr ? "+DT:%s:%d:%d\n"
2537 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2538 (void)BIO_flush(bio_err);
2542 mr ? "+DN:%s:%ld:%d\n"
2543 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2544 (void)BIO_flush(bio_err);
2548 static void pkey_print_message(const char *str, const char *str2, long num,
2553 mr ? "+DTP:%d:%s:%s:%d\n"
2554 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2555 (void)BIO_flush(bio_err);
2559 mr ? "+DNP:%ld:%d:%s:%s\n"
2560 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2561 (void)BIO_flush(bio_err);
2565 static void print_result(int alg, int run_no, int count, double time_used)
2568 mr ? "+R:%d:%s:%f\n"
2569 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2570 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2574 static char *sstrsep(char **string, const char *delim)
2577 char *token = *string;
2582 memset(isdelim, 0, sizeof isdelim);
2586 isdelim[(unsigned char)(*delim)] = 1;
2590 while (!isdelim[(unsigned char)(**string)]) {
2602 static int do_multi(int multi)
2607 static char sep[] = ":";
2609 fds = malloc(multi * sizeof *fds);
2610 for (n = 0; n < multi; ++n) {
2611 if (pipe(fd) == -1) {
2612 fprintf(stderr, "pipe failure\n");
2623 if (dup(fd[1]) == -1) {
2624 fprintf(stderr, "dup failed\n");
2633 printf("Forked child %d\n", n);
2636 /* for now, assume the pipe is long enough to take all the output */
2637 for (n = 0; n < multi; ++n) {
2642 f = fdopen(fds[n], "r");
2643 while (fgets(buf, sizeof buf, f)) {
2644 p = strchr(buf, '\n');
2647 if (buf[0] != '+') {
2648 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2652 printf("Got: %s from %d\n", buf, n);
2653 if (!strncmp(buf, "+F:", 3)) {
2658 alg = atoi(sstrsep(&p, sep));
2660 for (j = 0; j < SIZE_NUM; ++j)
2661 results[alg][j] += atof(sstrsep(&p, sep));
2662 } else if (!strncmp(buf, "+F2:", 4)) {
2667 k = atoi(sstrsep(&p, sep));
2670 d = atof(sstrsep(&p, sep));
2672 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2674 rsa_results[k][0] = d;
2676 d = atof(sstrsep(&p, sep));
2678 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2680 rsa_results[k][1] = d;
2681 } else if (!strncmp(buf, "+F2:", 4)) {
2686 k = atoi(sstrsep(&p, sep));
2689 d = atof(sstrsep(&p, sep));
2691 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2693 rsa_results[k][0] = d;
2695 d = atof(sstrsep(&p, sep));
2697 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2699 rsa_results[k][1] = d;
2701 # ifndef OPENSSL_NO_DSA
2702 else if (!strncmp(buf, "+F3:", 4)) {
2707 k = atoi(sstrsep(&p, sep));
2710 d = atof(sstrsep(&p, sep));
2712 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2714 dsa_results[k][0] = d;
2716 d = atof(sstrsep(&p, sep));
2718 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2720 dsa_results[k][1] = d;
2723 # ifndef OPENSSL_NO_ECDSA
2724 else if (!strncmp(buf, "+F4:", 4)) {
2729 k = atoi(sstrsep(&p, sep));
2732 d = atof(sstrsep(&p, sep));
2734 ecdsa_results[k][0] =
2735 1 / (1 / ecdsa_results[k][0] + 1 / d);
2737 ecdsa_results[k][0] = d;
2739 d = atof(sstrsep(&p, sep));
2741 ecdsa_results[k][1] =
2742 1 / (1 / ecdsa_results[k][1] + 1 / d);
2744 ecdsa_results[k][1] = d;
2748 # ifndef OPENSSL_NO_ECDH
2749 else if (!strncmp(buf, "+F5:", 4)) {
2754 k = atoi(sstrsep(&p, sep));
2757 d = atof(sstrsep(&p, sep));
2759 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2761 ecdh_results[k][0] = d;
2766 else if (!strncmp(buf, "+H:", 3)) {
2768 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2778 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2780 static int mblengths[] =
2781 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2782 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2783 const char *alg_name;
2784 unsigned char *inp, *out, no_key[32], no_iv[16];
2788 inp = OPENSSL_malloc(mblengths[num - 1]);
2789 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2791 EVP_CIPHER_CTX_init(&ctx);
2792 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2793 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2795 alg_name = OBJ_nid2ln(evp_cipher->nid);
2797 for (j = 0; j < num; j++) {
2798 print_message(alg_name, 0, mblengths[j]);
2800 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2801 unsigned char aad[13];
2802 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2803 size_t len = mblengths[j];
2806 memset(aad, 0, 8); /* avoid uninitialized values */
2807 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2808 aad[9] = 3; /* version */
2810 aad[11] = 0; /* length */
2812 mb_param.out = NULL;
2815 mb_param.interleave = 8;
2817 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2818 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2819 sizeof(mb_param), &mb_param);
2825 EVP_CIPHER_CTX_ctrl(&ctx,
2826 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2827 sizeof(mb_param), &mb_param);
2831 RAND_bytes(out, 16);
2835 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2836 EVP_CTRL_AEAD_TLS1_AAD, 13, aad);
2837 EVP_Cipher(&ctx, out, inp, len + pad);
2842 mr ? "+R:%d:%s:%f\n"
2843 : "%d %s's in %.2fs\n", count, "evp", d);
2844 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2848 fprintf(stdout, "+H");
2849 for (j = 0; j < num; j++)
2850 fprintf(stdout, ":%d", mblengths[j]);
2851 fprintf(stdout, "\n");
2852 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2853 for (j = 0; j < num; j++)
2854 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2855 fprintf(stdout, "\n");
2858 "The 'numbers' are in 1000s of bytes per second processed.\n");
2859 fprintf(stdout, "type ");
2860 for (j = 0; j < num; j++)
2861 fprintf(stdout, "%7d bytes", mblengths[j]);
2862 fprintf(stdout, "\n");
2863 fprintf(stdout, "%-24s", alg_name);
2865 for (j = 0; j < num; j++) {
2866 if (results[D_EVP][j] > 10000)
2867 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2869 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2871 fprintf(stdout, "\n");