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 #ifndef OPENSSL_NO_SHA
141 # include <openssl/sha.h>
143 #ifndef OPENSSL_NO_RMD160
144 # include <openssl/ripemd.h>
146 #ifndef OPENSSL_NO_WHIRLPOOL
147 # include <openssl/whrlpool.h>
149 #ifndef OPENSSL_NO_RC4
150 # include <openssl/rc4.h>
152 #ifndef OPENSSL_NO_RC5
153 # include <openssl/rc5.h>
155 #ifndef OPENSSL_NO_RC2
156 # include <openssl/rc2.h>
158 #ifndef OPENSSL_NO_IDEA
159 # include <openssl/idea.h>
161 #ifndef OPENSSL_NO_SEED
162 # include <openssl/seed.h>
164 #ifndef OPENSSL_NO_BF
165 # include <openssl/blowfish.h>
167 #ifndef OPENSSL_NO_CAST
168 # include <openssl/cast.h>
170 #ifndef OPENSSL_NO_RSA
171 # include <openssl/rsa.h>
172 # include "./testrsa.h"
174 #include <openssl/x509.h>
175 #ifndef OPENSSL_NO_DSA
176 # include <openssl/dsa.h>
177 # include "./testdsa.h"
179 #ifndef OPENSSL_NO_ECDSA
180 # include <openssl/ecdsa.h>
182 #ifndef OPENSSL_NO_ECDH
183 # include <openssl/ecdh.h>
185 #include <openssl/modes.h>
187 #include <openssl/bn.h>
190 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
204 #define BUFSIZE (1024*8+1)
205 #define MAX_MISALIGNMENT 63
207 static volatile int run = 0;
210 static int usertime = 1;
212 static double Time_F(int s);
213 static void print_message(const char *s, long num, int length);
214 static void pkey_print_message(const char *str, const char *str2,
215 long num, int bits, int sec);
216 static void print_result(int alg, int run_no, int count, double time_used);
218 static int do_multi(int multi);
228 #define MAX_ECDH_SIZE 256
230 static const char *names[ALGOR_NUM] = {
231 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
232 "des cbc", "des ede3", "idea cbc", "seed cbc",
233 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
234 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
235 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
236 "evp", "sha256", "sha512", "whirlpool",
237 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
240 static double results[ALGOR_NUM][SIZE_NUM];
241 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
243 #ifndef OPENSSL_NO_RSA
244 static double rsa_results[RSA_NUM][2];
246 #ifndef OPENSSL_NO_DSA
247 static double dsa_results[DSA_NUM][2];
249 #ifndef OPENSSL_NO_ECDSA
250 static double ecdsa_results[EC_NUM][2];
252 #ifndef OPENSSL_NO_ECDH
253 static double ecdh_results[EC_NUM][1];
256 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
257 static const char rnd_seed[] =
258 "string to make the random number generator think it has entropy";
259 static int rnd_fake = 0;
263 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
264 # define SIGRETTYPE void
266 # define SIGRETTYPE int
269 static SIGRETTYPE sig_done(int sig);
270 static SIGRETTYPE sig_done(int sig)
272 signal(SIGALRM, sig_done);
282 # if !defined(SIGALRM)
285 static unsigned int lapse, schlock;
286 static void alarm_win32(unsigned int secs)
291 # define alarm alarm_win32
293 static DWORD WINAPI sleepy(VOID * arg)
301 static double Time_F(int s)
308 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
310 DWORD ret = GetLastError();
311 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
315 Sleep(0); /* scheduler spinlock */
316 ret = app_tminterval(s, usertime);
318 ret = app_tminterval(s, usertime);
320 TerminateThread(thr, 0);
328 static double Time_F(int s)
330 double ret = app_tminterval(s, usertime);
337 #ifndef OPENSSL_NO_ECDH
338 static const int KDF1_SHA1_len = 20;
339 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
342 # ifndef OPENSSL_NO_SHA
343 if (*outlen < SHA_DIGEST_LENGTH)
346 *outlen = SHA_DIGEST_LENGTH;
347 return SHA1(in, inlen, out);
350 # endif /* OPENSSL_NO_SHA */
352 #endif /* OPENSSL_NO_ECDH */
354 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
356 int MAIN(int, char **);
358 int MAIN(int argc, char **argv)
360 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
361 unsigned char *buf = NULL, *buf2 = NULL;
363 long count = 0, save_count = 0;
365 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
368 #ifndef OPENSSL_NO_RSA
371 unsigned char md[EVP_MAX_MD_SIZE];
372 #ifndef OPENSSL_NO_MD2
373 unsigned char md2[MD2_DIGEST_LENGTH];
375 #ifndef OPENSSL_NO_MDC2
376 unsigned char mdc2[MDC2_DIGEST_LENGTH];
378 #ifndef OPENSSL_NO_MD4
379 unsigned char md4[MD4_DIGEST_LENGTH];
381 #ifndef OPENSSL_NO_MD5
382 unsigned char md5[MD5_DIGEST_LENGTH];
383 unsigned char hmac[MD5_DIGEST_LENGTH];
385 #ifndef OPENSSL_NO_SHA
386 unsigned char sha[SHA_DIGEST_LENGTH];
387 # ifndef OPENSSL_NO_SHA256
388 unsigned char sha256[SHA256_DIGEST_LENGTH];
390 # ifndef OPENSSL_NO_SHA512
391 unsigned char sha512[SHA512_DIGEST_LENGTH];
394 #ifndef OPENSSL_NO_WHIRLPOOL
395 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
397 #ifndef OPENSSL_NO_RMD160
398 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
400 #ifndef OPENSSL_NO_RC4
403 #ifndef OPENSSL_NO_RC5
406 #ifndef OPENSSL_NO_RC2
409 #ifndef OPENSSL_NO_IDEA
410 IDEA_KEY_SCHEDULE idea_ks;
412 #ifndef OPENSSL_NO_SEED
413 SEED_KEY_SCHEDULE seed_ks;
415 #ifndef OPENSSL_NO_BF
418 #ifndef OPENSSL_NO_CAST
421 static const unsigned char key16[16] = {
422 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
423 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
425 #ifndef OPENSSL_NO_AES
426 static const unsigned char key24[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 key32[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_CAMELLIA
439 static const unsigned char ckey24[24] = {
440 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
441 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
442 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
444 static const unsigned char ckey32[32] = {
445 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
446 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
447 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
448 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
451 #ifndef OPENSSL_NO_AES
452 # define MAX_BLOCK_SIZE 128
454 # define MAX_BLOCK_SIZE 64
456 unsigned char DES_iv[8];
457 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
458 #ifndef OPENSSL_NO_DES
459 static DES_cblock key =
460 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
461 static DES_cblock key2 =
462 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
463 static DES_cblock key3 =
464 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
465 DES_key_schedule sch;
466 DES_key_schedule sch2;
467 DES_key_schedule sch3;
469 #ifndef OPENSSL_NO_AES
470 AES_KEY aes_ks1, aes_ks2, aes_ks3;
472 #ifndef OPENSSL_NO_CAMELLIA
473 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
485 #define D_CBC_IDEA 10
486 #define D_CBC_SEED 11
490 #define D_CBC_CAST 15
491 #define D_CBC_128_AES 16
492 #define D_CBC_192_AES 17
493 #define D_CBC_256_AES 18
494 #define D_CBC_128_CML 19
495 #define D_CBC_192_CML 20
496 #define D_CBC_256_CML 21
500 #define D_WHIRLPOOL 25
501 #define D_IGE_128_AES 26
502 #define D_IGE_192_AES 27
503 #define D_IGE_256_AES 28
506 long c[ALGOR_NUM][SIZE_NUM];
508 #ifndef OPENSSL_SYS_WIN32
519 #define R_RSA_15360 6
538 #ifndef OPENSSL_NO_RSA
539 RSA *rsa_key[RSA_NUM];
540 long rsa_c[RSA_NUM][2];
541 static unsigned int rsa_bits[RSA_NUM] = {
542 512, 1024, 2048, 3072, 4096, 7680, 15360
544 static unsigned char *rsa_data[RSA_NUM] = {
545 test512, test1024, test2048, test3072, test4096, test7680, test15360
547 static int rsa_data_length[RSA_NUM] = {
548 sizeof(test512), sizeof(test1024),
549 sizeof(test2048), sizeof(test3072),
550 sizeof(test4096), sizeof(test7680),
554 #ifndef OPENSSL_NO_DSA
555 DSA *dsa_key[DSA_NUM];
556 long dsa_c[DSA_NUM][2];
557 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
559 #ifndef OPENSSL_NO_EC
561 * We only test over the following curves as they are representative, To
562 * add tests over more curves, simply add the curve NID and curve name to
563 * the following arrays and increase the EC_NUM value accordingly.
565 static unsigned int test_curves[EC_NUM] = {
568 NID_X9_62_prime192v1,
570 NID_X9_62_prime256v1,
585 static const char *test_curves_names[EC_NUM] = {
605 static int test_curves_bits[EC_NUM] = {
606 160, 192, 224, 256, 384, 521,
607 163, 233, 283, 409, 571,
608 163, 233, 283, 409, 571
613 #ifndef OPENSSL_NO_ECDSA
614 unsigned char ecdsasig[256];
615 unsigned int ecdsasiglen;
616 EC_KEY *ecdsa[EC_NUM];
617 long ecdsa_c[EC_NUM][2];
620 #ifndef OPENSSL_NO_ECDH
621 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
622 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
623 int secret_size_a, secret_size_b;
626 long ecdh_c[EC_NUM][2];
629 int rsa_doit[RSA_NUM];
630 int dsa_doit[DSA_NUM];
631 #ifndef OPENSSL_NO_ECDSA
632 int ecdsa_doit[EC_NUM];
634 #ifndef OPENSSL_NO_ECDH
635 int ecdh_doit[EC_NUM];
639 const EVP_CIPHER *evp_cipher = NULL;
640 const EVP_MD *evp_md = NULL;
646 int misalign = MAX_MISALIGNMENT + 1;
653 memset(results, 0, sizeof(results));
654 #ifndef OPENSSL_NO_DSA
655 memset(dsa_key, 0, sizeof(dsa_key));
657 #ifndef OPENSSL_NO_ECDSA
658 for (i = 0; i < EC_NUM; i++)
661 #ifndef OPENSSL_NO_ECDH
662 for (i = 0; i < EC_NUM; i++) {
669 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
670 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
672 if (!load_config(bio_err, NULL))
675 #ifndef OPENSSL_NO_RSA
676 memset(rsa_key, 0, sizeof(rsa_key));
677 for (i = 0; i < RSA_NUM; i++)
682 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
683 BIO_printf(bio_err, "out of memory\n");
687 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
688 BIO_printf(bio_err, "out of memory\n");
692 misalign = 0; /* set later and buf/buf2 are adjusted
697 memset(c, 0, sizeof(c));
698 memset(DES_iv, 0, sizeof(DES_iv));
699 memset(iv, 0, sizeof(iv));
701 for (i = 0; i < ALGOR_NUM; i++)
703 for (i = 0; i < RSA_NUM; i++)
705 for (i = 0; i < DSA_NUM; i++)
707 #ifndef OPENSSL_NO_ECDSA
708 for (i = 0; i < EC_NUM; i++)
711 #ifndef OPENSSL_NO_ECDH
712 for (i = 0; i < EC_NUM; i++)
720 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
722 j--; /* Otherwise, -elapsed gets confused with an
724 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
728 BIO_printf(bio_err, "no EVP given\n");
731 evp_cipher = EVP_get_cipherbyname(*argv);
733 evp_md = EVP_get_digestbyname(*argv);
735 if (!evp_cipher && !evp_md) {
736 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
741 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
743 j--; /* Otherwise, -elapsed gets confused with an
746 #ifndef OPENSSL_NO_ENGINE
747 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
751 BIO_printf(bio_err, "no engine given\n");
754 setup_engine(bio_err, *argv, 0);
756 * j will be increased again further down. We just don't want
757 * speed to confuse an engine with an algorithm, especially when
758 * none is given (which means all of them should be run)
764 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
768 BIO_printf(bio_err, "no multi count given\n");
771 multi = atoi(argv[0]);
773 BIO_printf(bio_err, "bad multi count\n");
776 j--; /* Otherwise, -mr gets confused with an
780 else if (argc > 0 && !strcmp(*argv, "-mr")) {
782 j--; /* Otherwise, -mr gets confused with an
784 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
787 } else if (argc > 0 && !strcmp(*argv, "-misalign")) {
791 BIO_printf(bio_err, "no misalignment given\n");
794 misalign = atoi(argv[0]);
795 if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
797 "misalignment is outsize permitted range 0-%d\n",
801 buf = buf_malloc + misalign;
802 buf2 = buf2_malloc + misalign;
805 #ifndef OPENSSL_NO_MD2
806 if (strcmp(*argv, "md2") == 0)
810 #ifndef OPENSSL_NO_MDC2
811 if (strcmp(*argv, "mdc2") == 0)
815 #ifndef OPENSSL_NO_MD4
816 if (strcmp(*argv, "md4") == 0)
820 #ifndef OPENSSL_NO_MD5
821 if (strcmp(*argv, "md5") == 0)
825 #ifndef OPENSSL_NO_MD5
826 if (strcmp(*argv, "hmac") == 0)
830 #ifndef OPENSSL_NO_SHA
831 if (strcmp(*argv, "sha1") == 0)
833 else if (strcmp(*argv, "sha") == 0)
834 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
836 # ifndef OPENSSL_NO_SHA256
837 if (strcmp(*argv, "sha256") == 0)
841 # ifndef OPENSSL_NO_SHA512
842 if (strcmp(*argv, "sha512") == 0)
847 #ifndef OPENSSL_NO_WHIRLPOOL
848 if (strcmp(*argv, "whirlpool") == 0)
849 doit[D_WHIRLPOOL] = 1;
852 #ifndef OPENSSL_NO_RMD160
853 if (strcmp(*argv, "ripemd") == 0)
855 else if (strcmp(*argv, "rmd160") == 0)
857 else if (strcmp(*argv, "ripemd160") == 0)
861 #ifndef OPENSSL_NO_RC4
862 if (strcmp(*argv, "rc4") == 0)
866 #ifndef OPENSSL_NO_DES
867 if (strcmp(*argv, "des-cbc") == 0)
869 else if (strcmp(*argv, "des-ede3") == 0)
870 doit[D_EDE3_DES] = 1;
873 #ifndef OPENSSL_NO_AES
874 if (strcmp(*argv, "aes-128-cbc") == 0)
875 doit[D_CBC_128_AES] = 1;
876 else if (strcmp(*argv, "aes-192-cbc") == 0)
877 doit[D_CBC_192_AES] = 1;
878 else if (strcmp(*argv, "aes-256-cbc") == 0)
879 doit[D_CBC_256_AES] = 1;
880 else if (strcmp(*argv, "aes-128-ige") == 0)
881 doit[D_IGE_128_AES] = 1;
882 else if (strcmp(*argv, "aes-192-ige") == 0)
883 doit[D_IGE_192_AES] = 1;
884 else if (strcmp(*argv, "aes-256-ige") == 0)
885 doit[D_IGE_256_AES] = 1;
888 #ifndef OPENSSL_NO_CAMELLIA
889 if (strcmp(*argv, "camellia-128-cbc") == 0)
890 doit[D_CBC_128_CML] = 1;
891 else if (strcmp(*argv, "camellia-192-cbc") == 0)
892 doit[D_CBC_192_CML] = 1;
893 else if (strcmp(*argv, "camellia-256-cbc") == 0)
894 doit[D_CBC_256_CML] = 1;
897 #ifndef OPENSSL_NO_RSA
898 # if 0 /* was: #ifdef RSAref */
899 if (strcmp(*argv, "rsaref") == 0) {
900 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
905 if (strcmp(*argv, "openssl") == 0) {
906 RSA_set_default_method(RSA_PKCS1_SSLeay());
910 #endif /* !OPENSSL_NO_RSA */
911 if (strcmp(*argv, "dsa512") == 0)
912 dsa_doit[R_DSA_512] = 2;
913 else if (strcmp(*argv, "dsa1024") == 0)
914 dsa_doit[R_DSA_1024] = 2;
915 else if (strcmp(*argv, "dsa2048") == 0)
916 dsa_doit[R_DSA_2048] = 2;
917 else if (strcmp(*argv, "rsa512") == 0)
918 rsa_doit[R_RSA_512] = 2;
919 else if (strcmp(*argv, "rsa1024") == 0)
920 rsa_doit[R_RSA_1024] = 2;
921 else if (strcmp(*argv, "rsa2048") == 0)
922 rsa_doit[R_RSA_2048] = 2;
923 else if (strcmp(*argv, "rsa3072") == 0)
924 rsa_doit[R_RSA_3072] = 2;
925 else if (strcmp(*argv, "rsa4096") == 0)
926 rsa_doit[R_RSA_4096] = 2;
927 else if (strcmp(*argv, "rsa7680") == 0)
928 rsa_doit[R_RSA_7680] = 2;
929 else if (strcmp(*argv, "rsa15360") == 0)
930 rsa_doit[R_RSA_15360] = 2;
932 #ifndef OPENSSL_NO_RC2
933 if (strcmp(*argv, "rc2-cbc") == 0)
935 else if (strcmp(*argv, "rc2") == 0)
939 #ifndef OPENSSL_NO_RC5
940 if (strcmp(*argv, "rc5-cbc") == 0)
942 else if (strcmp(*argv, "rc5") == 0)
946 #ifndef OPENSSL_NO_IDEA
947 if (strcmp(*argv, "idea-cbc") == 0)
948 doit[D_CBC_IDEA] = 1;
949 else if (strcmp(*argv, "idea") == 0)
950 doit[D_CBC_IDEA] = 1;
953 #ifndef OPENSSL_NO_SEED
954 if (strcmp(*argv, "seed-cbc") == 0)
955 doit[D_CBC_SEED] = 1;
956 else if (strcmp(*argv, "seed") == 0)
957 doit[D_CBC_SEED] = 1;
960 #ifndef OPENSSL_NO_BF
961 if (strcmp(*argv, "bf-cbc") == 0)
963 else if (strcmp(*argv, "blowfish") == 0)
965 else if (strcmp(*argv, "bf") == 0)
969 #ifndef OPENSSL_NO_CAST
970 if (strcmp(*argv, "cast-cbc") == 0)
971 doit[D_CBC_CAST] = 1;
972 else if (strcmp(*argv, "cast") == 0)
973 doit[D_CBC_CAST] = 1;
974 else if (strcmp(*argv, "cast5") == 0)
975 doit[D_CBC_CAST] = 1;
978 #ifndef OPENSSL_NO_DES
979 if (strcmp(*argv, "des") == 0) {
981 doit[D_EDE3_DES] = 1;
984 #ifndef OPENSSL_NO_AES
985 if (strcmp(*argv, "aes") == 0) {
986 doit[D_CBC_128_AES] = 1;
987 doit[D_CBC_192_AES] = 1;
988 doit[D_CBC_256_AES] = 1;
989 } else if (strcmp(*argv, "ghash") == 0) {
993 #ifndef OPENSSL_NO_CAMELLIA
994 if (strcmp(*argv, "camellia") == 0) {
995 doit[D_CBC_128_CML] = 1;
996 doit[D_CBC_192_CML] = 1;
997 doit[D_CBC_256_CML] = 1;
1000 #ifndef OPENSSL_NO_RSA
1001 if (strcmp(*argv, "rsa") == 0) {
1002 rsa_doit[R_RSA_512] = 1;
1003 rsa_doit[R_RSA_1024] = 1;
1004 rsa_doit[R_RSA_2048] = 1;
1005 rsa_doit[R_RSA_3072] = 1;
1006 rsa_doit[R_RSA_4096] = 1;
1007 rsa_doit[R_RSA_7680] = 1;
1008 rsa_doit[R_RSA_15360] = 1;
1011 #ifndef OPENSSL_NO_DSA
1012 if (strcmp(*argv, "dsa") == 0) {
1013 dsa_doit[R_DSA_512] = 1;
1014 dsa_doit[R_DSA_1024] = 1;
1015 dsa_doit[R_DSA_2048] = 1;
1018 #ifndef OPENSSL_NO_ECDSA
1019 if (strcmp(*argv, "ecdsap160") == 0)
1020 ecdsa_doit[R_EC_P160] = 2;
1021 else if (strcmp(*argv, "ecdsap192") == 0)
1022 ecdsa_doit[R_EC_P192] = 2;
1023 else if (strcmp(*argv, "ecdsap224") == 0)
1024 ecdsa_doit[R_EC_P224] = 2;
1025 else if (strcmp(*argv, "ecdsap256") == 0)
1026 ecdsa_doit[R_EC_P256] = 2;
1027 else if (strcmp(*argv, "ecdsap384") == 0)
1028 ecdsa_doit[R_EC_P384] = 2;
1029 else if (strcmp(*argv, "ecdsap521") == 0)
1030 ecdsa_doit[R_EC_P521] = 2;
1031 else if (strcmp(*argv, "ecdsak163") == 0)
1032 ecdsa_doit[R_EC_K163] = 2;
1033 else if (strcmp(*argv, "ecdsak233") == 0)
1034 ecdsa_doit[R_EC_K233] = 2;
1035 else if (strcmp(*argv, "ecdsak283") == 0)
1036 ecdsa_doit[R_EC_K283] = 2;
1037 else if (strcmp(*argv, "ecdsak409") == 0)
1038 ecdsa_doit[R_EC_K409] = 2;
1039 else if (strcmp(*argv, "ecdsak571") == 0)
1040 ecdsa_doit[R_EC_K571] = 2;
1041 else if (strcmp(*argv, "ecdsab163") == 0)
1042 ecdsa_doit[R_EC_B163] = 2;
1043 else if (strcmp(*argv, "ecdsab233") == 0)
1044 ecdsa_doit[R_EC_B233] = 2;
1045 else if (strcmp(*argv, "ecdsab283") == 0)
1046 ecdsa_doit[R_EC_B283] = 2;
1047 else if (strcmp(*argv, "ecdsab409") == 0)
1048 ecdsa_doit[R_EC_B409] = 2;
1049 else if (strcmp(*argv, "ecdsab571") == 0)
1050 ecdsa_doit[R_EC_B571] = 2;
1051 else if (strcmp(*argv, "ecdsa") == 0) {
1052 for (i = 0; i < EC_NUM; i++)
1056 #ifndef OPENSSL_NO_ECDH
1057 if (strcmp(*argv, "ecdhp160") == 0)
1058 ecdh_doit[R_EC_P160] = 2;
1059 else if (strcmp(*argv, "ecdhp192") == 0)
1060 ecdh_doit[R_EC_P192] = 2;
1061 else if (strcmp(*argv, "ecdhp224") == 0)
1062 ecdh_doit[R_EC_P224] = 2;
1063 else if (strcmp(*argv, "ecdhp256") == 0)
1064 ecdh_doit[R_EC_P256] = 2;
1065 else if (strcmp(*argv, "ecdhp384") == 0)
1066 ecdh_doit[R_EC_P384] = 2;
1067 else if (strcmp(*argv, "ecdhp521") == 0)
1068 ecdh_doit[R_EC_P521] = 2;
1069 else if (strcmp(*argv, "ecdhk163") == 0)
1070 ecdh_doit[R_EC_K163] = 2;
1071 else if (strcmp(*argv, "ecdhk233") == 0)
1072 ecdh_doit[R_EC_K233] = 2;
1073 else if (strcmp(*argv, "ecdhk283") == 0)
1074 ecdh_doit[R_EC_K283] = 2;
1075 else if (strcmp(*argv, "ecdhk409") == 0)
1076 ecdh_doit[R_EC_K409] = 2;
1077 else if (strcmp(*argv, "ecdhk571") == 0)
1078 ecdh_doit[R_EC_K571] = 2;
1079 else if (strcmp(*argv, "ecdhb163") == 0)
1080 ecdh_doit[R_EC_B163] = 2;
1081 else if (strcmp(*argv, "ecdhb233") == 0)
1082 ecdh_doit[R_EC_B233] = 2;
1083 else if (strcmp(*argv, "ecdhb283") == 0)
1084 ecdh_doit[R_EC_B283] = 2;
1085 else if (strcmp(*argv, "ecdhb409") == 0)
1086 ecdh_doit[R_EC_B409] = 2;
1087 else if (strcmp(*argv, "ecdhb571") == 0)
1088 ecdh_doit[R_EC_B571] = 2;
1089 else if (strcmp(*argv, "ecdh") == 0) {
1090 for (i = 0; i < EC_NUM; i++)
1095 BIO_printf(bio_err, "Error: bad option or value\n");
1096 BIO_printf(bio_err, "\n");
1097 BIO_printf(bio_err, "Available values:\n");
1098 #ifndef OPENSSL_NO_MD2
1099 BIO_printf(bio_err, "md2 ");
1101 #ifndef OPENSSL_NO_MDC2
1102 BIO_printf(bio_err, "mdc2 ");
1104 #ifndef OPENSSL_NO_MD4
1105 BIO_printf(bio_err, "md4 ");
1107 #ifndef OPENSSL_NO_MD5
1108 BIO_printf(bio_err, "md5 ");
1109 # ifndef OPENSSL_NO_HMAC
1110 BIO_printf(bio_err, "hmac ");
1113 #ifndef OPENSSL_NO_SHA1
1114 BIO_printf(bio_err, "sha1 ");
1116 #ifndef OPENSSL_NO_SHA256
1117 BIO_printf(bio_err, "sha256 ");
1119 #ifndef OPENSSL_NO_SHA512
1120 BIO_printf(bio_err, "sha512 ");
1122 #ifndef OPENSSL_NO_WHIRLPOOL
1123 BIO_printf(bio_err, "whirlpool");
1125 #ifndef OPENSSL_NO_RMD160
1126 BIO_printf(bio_err, "rmd160");
1128 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1129 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1130 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \
1131 !defined(OPENSSL_NO_WHIRLPOOL)
1132 BIO_printf(bio_err, "\n");
1135 #ifndef OPENSSL_NO_IDEA
1136 BIO_printf(bio_err, "idea-cbc ");
1138 #ifndef OPENSSL_NO_SEED
1139 BIO_printf(bio_err, "seed-cbc ");
1141 #ifndef OPENSSL_NO_RC2
1142 BIO_printf(bio_err, "rc2-cbc ");
1144 #ifndef OPENSSL_NO_RC5
1145 BIO_printf(bio_err, "rc5-cbc ");
1147 #ifndef OPENSSL_NO_BF
1148 BIO_printf(bio_err, "bf-cbc");
1150 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1151 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1152 BIO_printf(bio_err, "\n");
1154 #ifndef OPENSSL_NO_DES
1155 BIO_printf(bio_err, "des-cbc des-ede3 ");
1157 #ifndef OPENSSL_NO_AES
1158 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1159 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1161 #ifndef OPENSSL_NO_CAMELLIA
1162 BIO_printf(bio_err, "\n");
1164 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1166 #ifndef OPENSSL_NO_RC4
1167 BIO_printf(bio_err, "rc4");
1169 BIO_printf(bio_err, "\n");
1171 #ifndef OPENSSL_NO_RSA
1173 "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1174 BIO_printf(bio_err, "rsa7680 rsa15360\n");
1177 #ifndef OPENSSL_NO_DSA
1178 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1180 #ifndef OPENSSL_NO_ECDSA
1181 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1182 "ecdsap256 ecdsap384 ecdsap521\n");
1184 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1186 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1187 BIO_printf(bio_err, "ecdsa\n");
1189 #ifndef OPENSSL_NO_ECDH
1190 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1191 "ecdhp256 ecdhp384 ecdhp521\n");
1193 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1195 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1196 BIO_printf(bio_err, "ecdh\n");
1199 #ifndef OPENSSL_NO_IDEA
1200 BIO_printf(bio_err, "idea ");
1202 #ifndef OPENSSL_NO_SEED
1203 BIO_printf(bio_err, "seed ");
1205 #ifndef OPENSSL_NO_RC2
1206 BIO_printf(bio_err, "rc2 ");
1208 #ifndef OPENSSL_NO_DES
1209 BIO_printf(bio_err, "des ");
1211 #ifndef OPENSSL_NO_AES
1212 BIO_printf(bio_err, "aes ");
1214 #ifndef OPENSSL_NO_CAMELLIA
1215 BIO_printf(bio_err, "camellia ");
1217 #ifndef OPENSSL_NO_RSA
1218 BIO_printf(bio_err, "rsa ");
1220 #ifndef OPENSSL_NO_BF
1221 BIO_printf(bio_err, "blowfish");
1223 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1224 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1225 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1226 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1227 BIO_printf(bio_err, "\n");
1230 BIO_printf(bio_err, "\n");
1231 BIO_printf(bio_err, "Available options:\n");
1232 #if defined(TIMES) || defined(USE_TOD)
1233 BIO_printf(bio_err, "-elapsed "
1234 "measure time in real time instead of CPU user time.\n");
1236 #ifndef OPENSSL_NO_ENGINE
1239 "use engine e, possibly a hardware device.\n");
1241 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1244 "time decryption instead of encryption (only EVP).\n");
1247 "produce machine readable output.\n");
1250 "perform multi-block benchmark (for specific ciphers)\n");
1253 "perform benchmark with misaligned data\n");
1256 "-multi n " "run n benchmarks in parallel.\n");
1266 if (multi && do_multi(multi))
1271 for (i = 0; i < ALGOR_NUM; i++) {
1275 for (i = 0; i < RSA_NUM; i++)
1277 for (i = 0; i < DSA_NUM; i++)
1279 #ifndef OPENSSL_NO_ECDSA
1280 for (i = 0; i < EC_NUM; i++)
1283 #ifndef OPENSSL_NO_ECDH
1284 for (i = 0; i < EC_NUM; i++)
1288 for (i = 0; i < ALGOR_NUM; i++)
1292 if (usertime == 0 && !mr)
1294 "You have chosen to measure elapsed time "
1295 "instead of user CPU time.\n");
1297 #ifndef OPENSSL_NO_RSA
1298 for (i = 0; i < RSA_NUM; i++) {
1299 const unsigned char *p;
1302 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1303 if (rsa_key[i] == NULL) {
1304 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1312 : "Loaded RSA key, %d bit modulus and e= 0x",
1313 BN_num_bits(rsa_key[i]->n));
1314 BN_print(bio_err, rsa_key[i]->e);
1315 BIO_printf(bio_err, "\n");
1321 #ifndef OPENSSL_NO_DSA
1322 dsa_key[0] = get_dsa512();
1323 dsa_key[1] = get_dsa1024();
1324 dsa_key[2] = get_dsa2048();
1327 #ifndef OPENSSL_NO_DES
1328 DES_set_key_unchecked(&key, &sch);
1329 DES_set_key_unchecked(&key2, &sch2);
1330 DES_set_key_unchecked(&key3, &sch3);
1332 #ifndef OPENSSL_NO_AES
1333 AES_set_encrypt_key(key16, 128, &aes_ks1);
1334 AES_set_encrypt_key(key24, 192, &aes_ks2);
1335 AES_set_encrypt_key(key32, 256, &aes_ks3);
1337 #ifndef OPENSSL_NO_CAMELLIA
1338 Camellia_set_key(key16, 128, &camellia_ks1);
1339 Camellia_set_key(ckey24, 192, &camellia_ks2);
1340 Camellia_set_key(ckey32, 256, &camellia_ks3);
1342 #ifndef OPENSSL_NO_IDEA
1343 idea_set_encrypt_key(key16, &idea_ks);
1345 #ifndef OPENSSL_NO_SEED
1346 SEED_set_key(key16, &seed_ks);
1348 #ifndef OPENSSL_NO_RC4
1349 RC4_set_key(&rc4_ks, 16, key16);
1351 #ifndef OPENSSL_NO_RC2
1352 RC2_set_key(&rc2_ks, 16, key16, 128);
1354 #ifndef OPENSSL_NO_RC5
1355 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1357 #ifndef OPENSSL_NO_BF
1358 BF_set_key(&bf_ks, 16, key16);
1360 #ifndef OPENSSL_NO_CAST
1361 CAST_set_key(&cast_ks, 16, key16);
1363 #ifndef OPENSSL_NO_RSA
1364 memset(rsa_c, 0, sizeof(rsa_c));
1367 # ifndef OPENSSL_NO_DES
1368 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1374 for (it = count; it; it--)
1375 DES_ecb_encrypt((DES_cblock *)buf,
1376 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1380 c[D_MD2][0] = count / 10;
1381 c[D_MDC2][0] = count / 10;
1382 c[D_MD4][0] = count;
1383 c[D_MD5][0] = count;
1384 c[D_HMAC][0] = count;
1385 c[D_SHA1][0] = count;
1386 c[D_RMD160][0] = count;
1387 c[D_RC4][0] = count * 5;
1388 c[D_CBC_DES][0] = count;
1389 c[D_EDE3_DES][0] = count / 3;
1390 c[D_CBC_IDEA][0] = count;
1391 c[D_CBC_SEED][0] = count;
1392 c[D_CBC_RC2][0] = count;
1393 c[D_CBC_RC5][0] = count;
1394 c[D_CBC_BF][0] = count;
1395 c[D_CBC_CAST][0] = count;
1396 c[D_CBC_128_AES][0] = count;
1397 c[D_CBC_192_AES][0] = count;
1398 c[D_CBC_256_AES][0] = count;
1399 c[D_CBC_128_CML][0] = count;
1400 c[D_CBC_192_CML][0] = count;
1401 c[D_CBC_256_CML][0] = count;
1402 c[D_SHA256][0] = count;
1403 c[D_SHA512][0] = count;
1404 c[D_WHIRLPOOL][0] = count;
1405 c[D_IGE_128_AES][0] = count;
1406 c[D_IGE_192_AES][0] = count;
1407 c[D_IGE_256_AES][0] = count;
1408 c[D_GHASH][0] = count;
1410 for (i = 1; i < SIZE_NUM; i++) {
1413 l0 = (long)lengths[0];
1414 l1 = (long)lengths[i];
1416 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1417 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1418 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1419 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1420 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1421 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1422 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1423 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1424 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1425 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1427 l0 = (long)lengths[i - 1];
1429 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1430 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1431 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1432 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1433 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1434 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1435 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1436 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1437 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1438 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1439 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1440 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1441 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1442 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1443 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1444 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1445 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1446 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1449 # ifndef OPENSSL_NO_RSA
1450 rsa_c[R_RSA_512][0] = count / 2000;
1451 rsa_c[R_RSA_512][1] = count / 400;
1452 for (i = 1; i < RSA_NUM; i++) {
1453 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1454 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1455 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1458 if (rsa_c[i][0] == 0) {
1466 # ifndef OPENSSL_NO_DSA
1467 dsa_c[R_DSA_512][0] = count / 1000;
1468 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1469 for (i = 1; i < DSA_NUM; i++) {
1470 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1471 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1472 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1475 if (dsa_c[i] == 0) {
1483 # ifndef OPENSSL_NO_ECDSA
1484 ecdsa_c[R_EC_P160][0] = count / 1000;
1485 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1486 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1487 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1488 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1489 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1492 if (ecdsa_c[i] == 0) {
1498 ecdsa_c[R_EC_K163][0] = count / 1000;
1499 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1500 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1501 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1502 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1503 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1506 if (ecdsa_c[i] == 0) {
1512 ecdsa_c[R_EC_B163][0] = count / 1000;
1513 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1514 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1515 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1516 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1517 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1520 if (ecdsa_c[i] == 0) {
1528 # ifndef OPENSSL_NO_ECDH
1529 ecdh_c[R_EC_P160][0] = count / 1000;
1530 ecdh_c[R_EC_P160][1] = count / 1000;
1531 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1532 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1533 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1534 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1537 if (ecdh_c[i] == 0) {
1543 ecdh_c[R_EC_K163][0] = count / 1000;
1544 ecdh_c[R_EC_K163][1] = count / 1000;
1545 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1546 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1547 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1548 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1551 if (ecdh_c[i] == 0) {
1557 ecdh_c[R_EC_B163][0] = count / 1000;
1558 ecdh_c[R_EC_B163][1] = count / 1000;
1559 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1560 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1561 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1562 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1565 if (ecdh_c[i] == 0) {
1573 # define COND(d) (count < (d))
1574 # define COUNT(d) (d)
1576 /* not worth fixing */
1577 # error "You cannot disable DES on systems without SIGALRM."
1578 # endif /* OPENSSL_NO_DES */
1580 # define COND(c) (run && count<0x7fffffff)
1581 # define COUNT(d) (count)
1583 signal(SIGALRM, sig_done);
1585 #endif /* SIGALRM */
1587 #ifndef OPENSSL_NO_MD2
1589 for (j = 0; j < SIZE_NUM; j++) {
1590 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1592 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1593 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1596 print_result(D_MD2, j, count, d);
1600 #ifndef OPENSSL_NO_MDC2
1602 for (j = 0; j < SIZE_NUM; j++) {
1603 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1605 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1606 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1609 print_result(D_MDC2, j, count, d);
1614 #ifndef OPENSSL_NO_MD4
1616 for (j = 0; j < SIZE_NUM; j++) {
1617 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1619 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1620 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1621 NULL, EVP_md4(), NULL);
1623 print_result(D_MD4, j, count, d);
1628 #ifndef OPENSSL_NO_MD5
1630 for (j = 0; j < SIZE_NUM; j++) {
1631 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1633 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1634 MD5(buf, lengths[j], md5);
1636 print_result(D_MD5, j, count, d);
1641 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1645 HMAC_CTX_init(&hctx);
1646 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1647 16, EVP_md5(), NULL);
1649 for (j = 0; j < SIZE_NUM; j++) {
1650 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1652 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1653 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1654 HMAC_Update(&hctx, buf, lengths[j]);
1655 HMAC_Final(&hctx, &(hmac[0]), NULL);
1658 print_result(D_HMAC, j, count, d);
1660 HMAC_CTX_cleanup(&hctx);
1663 #ifndef OPENSSL_NO_SHA
1665 for (j = 0; j < SIZE_NUM; j++) {
1666 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1668 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1670 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1673 SHA1(buf, lengths[j], sha);
1676 print_result(D_SHA1, j, count, d);
1679 # ifndef OPENSSL_NO_SHA256
1680 if (doit[D_SHA256]) {
1681 for (j = 0; j < SIZE_NUM; j++) {
1682 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1684 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1685 SHA256(buf, lengths[j], sha256);
1687 print_result(D_SHA256, j, count, d);
1692 # ifndef OPENSSL_NO_SHA512
1693 if (doit[D_SHA512]) {
1694 for (j = 0; j < SIZE_NUM; j++) {
1695 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1697 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1698 SHA512(buf, lengths[j], sha512);
1700 print_result(D_SHA512, j, count, d);
1706 #ifndef OPENSSL_NO_WHIRLPOOL
1707 if (doit[D_WHIRLPOOL]) {
1708 for (j = 0; j < SIZE_NUM; j++) {
1709 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1711 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1712 WHIRLPOOL(buf, lengths[j], whirlpool);
1714 print_result(D_WHIRLPOOL, j, count, d);
1719 #ifndef OPENSSL_NO_RMD160
1720 if (doit[D_RMD160]) {
1721 for (j = 0; j < SIZE_NUM; j++) {
1722 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1724 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1725 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1726 EVP_ripemd160(), NULL);
1728 print_result(D_RMD160, j, count, d);
1732 #ifndef OPENSSL_NO_RC4
1734 for (j = 0; j < SIZE_NUM; j++) {
1735 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1737 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1738 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1740 print_result(D_RC4, j, count, d);
1744 #ifndef OPENSSL_NO_DES
1745 if (doit[D_CBC_DES]) {
1746 for (j = 0; j < SIZE_NUM; j++) {
1747 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1749 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1750 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1751 &DES_iv, DES_ENCRYPT);
1753 print_result(D_CBC_DES, j, count, d);
1757 if (doit[D_EDE3_DES]) {
1758 for (j = 0; j < SIZE_NUM; j++) {
1759 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1761 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1762 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1764 &DES_iv, DES_ENCRYPT);
1766 print_result(D_EDE3_DES, j, count, d);
1770 #ifndef OPENSSL_NO_AES
1771 if (doit[D_CBC_128_AES]) {
1772 for (j = 0; j < SIZE_NUM; j++) {
1773 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1776 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1777 AES_cbc_encrypt(buf, buf,
1778 (unsigned long)lengths[j], &aes_ks1,
1781 print_result(D_CBC_128_AES, j, count, d);
1784 if (doit[D_CBC_192_AES]) {
1785 for (j = 0; j < SIZE_NUM; j++) {
1786 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1789 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1790 AES_cbc_encrypt(buf, buf,
1791 (unsigned long)lengths[j], &aes_ks2,
1794 print_result(D_CBC_192_AES, j, count, d);
1797 if (doit[D_CBC_256_AES]) {
1798 for (j = 0; j < SIZE_NUM; j++) {
1799 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1802 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1803 AES_cbc_encrypt(buf, buf,
1804 (unsigned long)lengths[j], &aes_ks3,
1807 print_result(D_CBC_256_AES, j, count, d);
1811 if (doit[D_IGE_128_AES]) {
1812 for (j = 0; j < SIZE_NUM; j++) {
1813 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1816 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1817 AES_ige_encrypt(buf, buf2,
1818 (unsigned long)lengths[j], &aes_ks1,
1821 print_result(D_IGE_128_AES, j, count, d);
1824 if (doit[D_IGE_192_AES]) {
1825 for (j = 0; j < SIZE_NUM; j++) {
1826 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1829 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1830 AES_ige_encrypt(buf, buf2,
1831 (unsigned long)lengths[j], &aes_ks2,
1834 print_result(D_IGE_192_AES, j, count, d);
1837 if (doit[D_IGE_256_AES]) {
1838 for (j = 0; j < SIZE_NUM; j++) {
1839 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1842 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1843 AES_ige_encrypt(buf, buf2,
1844 (unsigned long)lengths[j], &aes_ks3,
1847 print_result(D_IGE_256_AES, j, count, d);
1850 if (doit[D_GHASH]) {
1851 GCM128_CONTEXT *ctx =
1852 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1853 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1855 for (j = 0; j < SIZE_NUM; j++) {
1856 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1858 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1859 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1861 print_result(D_GHASH, j, count, d);
1863 CRYPTO_gcm128_release(ctx);
1866 #ifndef OPENSSL_NO_CAMELLIA
1867 if (doit[D_CBC_128_CML]) {
1868 for (j = 0; j < SIZE_NUM; j++) {
1869 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1872 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1873 Camellia_cbc_encrypt(buf, buf,
1874 (unsigned long)lengths[j], &camellia_ks1,
1875 iv, CAMELLIA_ENCRYPT);
1877 print_result(D_CBC_128_CML, j, count, d);
1880 if (doit[D_CBC_192_CML]) {
1881 for (j = 0; j < SIZE_NUM; j++) {
1882 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1885 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1886 Camellia_cbc_encrypt(buf, buf,
1887 (unsigned long)lengths[j], &camellia_ks2,
1888 iv, CAMELLIA_ENCRYPT);
1890 print_result(D_CBC_192_CML, j, count, d);
1893 if (doit[D_CBC_256_CML]) {
1894 for (j = 0; j < SIZE_NUM; j++) {
1895 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1898 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1899 Camellia_cbc_encrypt(buf, buf,
1900 (unsigned long)lengths[j], &camellia_ks3,
1901 iv, CAMELLIA_ENCRYPT);
1903 print_result(D_CBC_256_CML, j, count, d);
1907 #ifndef OPENSSL_NO_IDEA
1908 if (doit[D_CBC_IDEA]) {
1909 for (j = 0; j < SIZE_NUM; j++) {
1910 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1912 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1913 idea_cbc_encrypt(buf, buf,
1914 (unsigned long)lengths[j], &idea_ks,
1917 print_result(D_CBC_IDEA, j, count, d);
1921 #ifndef OPENSSL_NO_SEED
1922 if (doit[D_CBC_SEED]) {
1923 for (j = 0; j < SIZE_NUM; j++) {
1924 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1926 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1927 SEED_cbc_encrypt(buf, buf,
1928 (unsigned long)lengths[j], &seed_ks, iv, 1);
1930 print_result(D_CBC_SEED, j, count, d);
1934 #ifndef OPENSSL_NO_RC2
1935 if (doit[D_CBC_RC2]) {
1936 for (j = 0; j < SIZE_NUM; j++) {
1937 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1939 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1940 RC2_cbc_encrypt(buf, buf,
1941 (unsigned long)lengths[j], &rc2_ks,
1944 print_result(D_CBC_RC2, j, count, d);
1948 #ifndef OPENSSL_NO_RC5
1949 if (doit[D_CBC_RC5]) {
1950 for (j = 0; j < SIZE_NUM; j++) {
1951 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1953 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1954 RC5_32_cbc_encrypt(buf, buf,
1955 (unsigned long)lengths[j], &rc5_ks,
1958 print_result(D_CBC_RC5, j, count, d);
1962 #ifndef OPENSSL_NO_BF
1963 if (doit[D_CBC_BF]) {
1964 for (j = 0; j < SIZE_NUM; j++) {
1965 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1967 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1968 BF_cbc_encrypt(buf, buf,
1969 (unsigned long)lengths[j], &bf_ks,
1972 print_result(D_CBC_BF, j, count, d);
1976 #ifndef OPENSSL_NO_CAST
1977 if (doit[D_CBC_CAST]) {
1978 for (j = 0; j < SIZE_NUM; j++) {
1979 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1981 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1982 CAST_cbc_encrypt(buf, buf,
1983 (unsigned long)lengths[j], &cast_ks,
1986 print_result(D_CBC_CAST, j, count, d);
1992 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1993 if (multiblock && evp_cipher) {
1995 (EVP_CIPHER_flags(evp_cipher) &
1996 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1997 fprintf(stderr, "%s is not multi-block capable\n",
1998 OBJ_nid2ln(evp_cipher->nid));
2001 multiblock_speed(evp_cipher);
2006 for (j = 0; j < SIZE_NUM; j++) {
2011 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
2013 * -O3 -fschedule-insns messes up an optimization here!
2014 * names[D_EVP] somehow becomes NULL
2016 print_message(names[D_EVP], save_count, lengths[j]);
2018 EVP_CIPHER_CTX_init(&ctx);
2020 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
2022 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
2023 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2027 for (count = 0, run = 1;
2028 COND(save_count * 4 * lengths[0] / lengths[j]);
2030 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
2032 for (count = 0, run = 1;
2033 COND(save_count * 4 * lengths[0] / lengths[j]);
2035 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
2037 EVP_DecryptFinal_ex(&ctx, buf, &outl);
2039 EVP_EncryptFinal_ex(&ctx, buf, &outl);
2041 EVP_CIPHER_CTX_cleanup(&ctx);
2044 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2045 print_message(names[D_EVP], save_count, lengths[j]);
2048 for (count = 0, run = 1;
2049 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2050 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2054 print_result(D_EVP, j, count, d);
2057 #ifndef OPENSSL_SYS_WIN32
2059 RAND_pseudo_bytes(buf, 36);
2060 #ifndef OPENSSL_NO_RSA
2061 for (j = 0; j < RSA_NUM; j++) {
2065 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2068 "RSA sign failure. No RSA sign will be done.\n");
2069 ERR_print_errors(bio_err);
2072 pkey_print_message("private", "rsa",
2073 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2074 /* RSA_blinding_on(rsa_key[j],NULL); */
2076 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2077 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2078 &rsa_num, rsa_key[j]);
2080 BIO_printf(bio_err, "RSA sign failure\n");
2081 ERR_print_errors(bio_err);
2088 mr ? "+R1:%ld:%d:%.2f\n"
2089 : "%ld %d bit private RSA's in %.2fs\n",
2090 count, rsa_bits[j], d);
2091 rsa_results[j][0] = d / (double)count;
2096 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2099 "RSA verify failure. No RSA verify will be done.\n");
2100 ERR_print_errors(bio_err);
2103 pkey_print_message("public", "rsa",
2104 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2106 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2107 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2108 rsa_num, rsa_key[j]);
2110 BIO_printf(bio_err, "RSA verify failure\n");
2111 ERR_print_errors(bio_err);
2118 mr ? "+R2:%ld:%d:%.2f\n"
2119 : "%ld %d bit public RSA's in %.2fs\n",
2120 count, rsa_bits[j], d);
2121 rsa_results[j][1] = d / (double)count;
2125 if (rsa_count <= 1) {
2126 /* if longer than 10s, don't do any more */
2127 for (j++; j < RSA_NUM; j++)
2133 RAND_pseudo_bytes(buf, 20);
2134 #ifndef OPENSSL_NO_DSA
2135 if (RAND_status() != 1) {
2136 RAND_seed(rnd_seed, sizeof rnd_seed);
2139 for (j = 0; j < DSA_NUM; j++) {
2146 /* DSA_generate_key(dsa_key[j]); */
2147 /* DSA_sign_setup(dsa_key[j],NULL); */
2148 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2151 "DSA sign failure. No DSA sign will be done.\n");
2152 ERR_print_errors(bio_err);
2155 pkey_print_message("sign", "dsa",
2156 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2158 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2159 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2161 BIO_printf(bio_err, "DSA sign failure\n");
2162 ERR_print_errors(bio_err);
2169 mr ? "+R3:%ld:%d:%.2f\n"
2170 : "%ld %d bit DSA signs in %.2fs\n",
2171 count, dsa_bits[j], d);
2172 dsa_results[j][0] = d / (double)count;
2176 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2179 "DSA verify failure. No DSA verify will be done.\n");
2180 ERR_print_errors(bio_err);
2183 pkey_print_message("verify", "dsa",
2184 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2186 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2187 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2189 BIO_printf(bio_err, "DSA verify failure\n");
2190 ERR_print_errors(bio_err);
2197 mr ? "+R4:%ld:%d:%.2f\n"
2198 : "%ld %d bit DSA verify in %.2fs\n",
2199 count, dsa_bits[j], d);
2200 dsa_results[j][1] = d / (double)count;
2203 if (rsa_count <= 1) {
2204 /* if longer than 10s, don't do any more */
2205 for (j++; j < DSA_NUM; j++)
2213 #ifndef OPENSSL_NO_ECDSA
2214 if (RAND_status() != 1) {
2215 RAND_seed(rnd_seed, sizeof rnd_seed);
2218 for (j = 0; j < EC_NUM; j++) {
2222 continue; /* Ignore Curve */
2223 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2224 if (ecdsa[j] == NULL) {
2225 BIO_printf(bio_err, "ECDSA failure.\n");
2226 ERR_print_errors(bio_err);
2230 EC_KEY_precompute_mult(ecdsa[j], NULL);
2232 /* Perform ECDSA signature test */
2233 EC_KEY_generate_key(ecdsa[j]);
2234 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2237 "ECDSA sign failure. No ECDSA sign will be done.\n");
2238 ERR_print_errors(bio_err);
2241 pkey_print_message("sign", "ecdsa",
2243 test_curves_bits[j], ECDSA_SECONDS);
2246 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2247 ret = ECDSA_sign(0, buf, 20,
2248 ecdsasig, &ecdsasiglen, ecdsa[j]);
2250 BIO_printf(bio_err, "ECDSA sign failure\n");
2251 ERR_print_errors(bio_err);
2259 mr ? "+R5:%ld:%d:%.2f\n" :
2260 "%ld %d bit ECDSA signs in %.2fs \n",
2261 count, test_curves_bits[j], d);
2262 ecdsa_results[j][0] = d / (double)count;
2266 /* Perform ECDSA verification test */
2267 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2270 "ECDSA verify failure. No ECDSA verify will be done.\n");
2271 ERR_print_errors(bio_err);
2274 pkey_print_message("verify", "ecdsa",
2276 test_curves_bits[j], ECDSA_SECONDS);
2278 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2280 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2283 BIO_printf(bio_err, "ECDSA verify failure\n");
2284 ERR_print_errors(bio_err);
2291 mr ? "+R6:%ld:%d:%.2f\n"
2292 : "%ld %d bit ECDSA verify in %.2fs\n",
2293 count, test_curves_bits[j], d);
2294 ecdsa_results[j][1] = d / (double)count;
2297 if (rsa_count <= 1) {
2298 /* if longer than 10s, don't do any more */
2299 for (j++; j < EC_NUM; j++)
2308 #ifndef OPENSSL_NO_ECDH
2309 if (RAND_status() != 1) {
2310 RAND_seed(rnd_seed, sizeof rnd_seed);
2313 for (j = 0; j < EC_NUM; j++) {
2316 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2317 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2318 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2319 BIO_printf(bio_err, "ECDH failure.\n");
2320 ERR_print_errors(bio_err);
2323 /* generate two ECDH key pairs */
2324 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2325 !EC_KEY_generate_key(ecdh_b[j])) {
2326 BIO_printf(bio_err, "ECDH key generation failure.\n");
2327 ERR_print_errors(bio_err);
2331 * If field size is not more than 24 octets, then use SHA-1
2332 * hash of result; otherwise, use result (see section 4.8 of
2333 * draft-ietf-tls-ecc-03.txt).
2335 int field_size, outlen;
2336 void *(*kdf) (const void *in, size_t inlen, void *out,
2339 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2340 if (field_size <= 24 * 8) {
2341 outlen = KDF1_SHA1_len;
2344 outlen = (field_size + 7) / 8;
2348 ECDH_compute_key(secret_a, outlen,
2349 EC_KEY_get0_public_key(ecdh_b[j]),
2352 ECDH_compute_key(secret_b, outlen,
2353 EC_KEY_get0_public_key(ecdh_a[j]),
2355 if (secret_size_a != secret_size_b)
2360 for (secret_idx = 0; (secret_idx < secret_size_a)
2361 && (ecdh_checks == 1); secret_idx++) {
2362 if (secret_a[secret_idx] != secret_b[secret_idx])
2366 if (ecdh_checks == 0) {
2367 BIO_printf(bio_err, "ECDH computations don't match.\n");
2368 ERR_print_errors(bio_err);
2372 pkey_print_message("", "ecdh",
2374 test_curves_bits[j], ECDH_SECONDS);
2376 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2377 ECDH_compute_key(secret_a, outlen,
2378 EC_KEY_get0_public_key(ecdh_b[j]),
2383 mr ? "+R7:%ld:%d:%.2f\n" :
2384 "%ld %d-bit ECDH ops in %.2fs\n", count,
2385 test_curves_bits[j], d);
2386 ecdh_results[j][0] = d / (double)count;
2391 if (rsa_count <= 1) {
2392 /* if longer than 10s, don't do any more */
2393 for (j++; j < EC_NUM; j++)
2404 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2405 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2407 printf("%s ", BN_options());
2408 #ifndef OPENSSL_NO_MD2
2409 printf("%s ", MD2_options());
2411 #ifndef OPENSSL_NO_RC4
2412 printf("%s ", RC4_options());
2414 #ifndef OPENSSL_NO_DES
2415 printf("%s ", DES_options());
2417 #ifndef OPENSSL_NO_AES
2418 printf("%s ", AES_options());
2420 #ifndef OPENSSL_NO_IDEA
2421 printf("%s ", idea_options());
2423 #ifndef OPENSSL_NO_BF
2424 printf("%s ", BF_options());
2426 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2431 fprintf(stdout, "+H");
2434 "The 'numbers' are in 1000s of bytes per second processed.\n");
2435 fprintf(stdout, "type ");
2437 for (j = 0; j < SIZE_NUM; j++)
2438 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2439 fprintf(stdout, "\n");
2442 for (k = 0; k < ALGOR_NUM; k++) {
2446 fprintf(stdout, "+F:%d:%s", k, names[k]);
2448 fprintf(stdout, "%-13s", names[k]);
2449 for (j = 0; j < SIZE_NUM; j++) {
2450 if (results[k][j] > 10000 && !mr)
2451 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2453 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2455 fprintf(stdout, "\n");
2457 #ifndef OPENSSL_NO_RSA
2459 for (k = 0; k < RSA_NUM; k++) {
2463 printf("%18ssign verify sign/s verify/s\n", " ");
2467 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2468 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2470 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2471 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2472 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2475 #ifndef OPENSSL_NO_DSA
2477 for (k = 0; k < DSA_NUM; k++) {
2481 printf("%18ssign verify sign/s verify/s\n", " ");
2485 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2486 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2488 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2489 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2490 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2493 #ifndef OPENSSL_NO_ECDSA
2495 for (k = 0; k < EC_NUM; k++) {
2499 printf("%30ssign verify sign/s verify/s\n", " ");
2504 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2505 k, test_curves_bits[k],
2506 ecdsa_results[k][0], ecdsa_results[k][1]);
2509 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2510 test_curves_bits[k],
2511 test_curves_names[k],
2512 ecdsa_results[k][0], ecdsa_results[k][1],
2513 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2517 #ifndef OPENSSL_NO_ECDH
2519 for (k = 0; k < EC_NUM; k++) {
2523 printf("%30sop op/s\n", " ");
2527 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2528 k, test_curves_bits[k],
2529 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2532 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2533 test_curves_bits[k],
2534 test_curves_names[k],
2535 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2542 ERR_print_errors(bio_err);
2543 if (buf_malloc != NULL)
2544 OPENSSL_free(buf_malloc);
2545 if (buf2_malloc != NULL)
2546 OPENSSL_free(buf2_malloc);
2547 #ifndef OPENSSL_NO_RSA
2548 for (i = 0; i < RSA_NUM; i++)
2549 if (rsa_key[i] != NULL)
2550 RSA_free(rsa_key[i]);
2552 #ifndef OPENSSL_NO_DSA
2553 for (i = 0; i < DSA_NUM; i++)
2554 if (dsa_key[i] != NULL)
2555 DSA_free(dsa_key[i]);
2558 #ifndef OPENSSL_NO_ECDSA
2559 for (i = 0; i < EC_NUM; i++)
2560 if (ecdsa[i] != NULL)
2561 EC_KEY_free(ecdsa[i]);
2563 #ifndef OPENSSL_NO_ECDH
2564 for (i = 0; i < EC_NUM; i++) {
2565 if (ecdh_a[i] != NULL)
2566 EC_KEY_free(ecdh_a[i]);
2567 if (ecdh_b[i] != NULL)
2568 EC_KEY_free(ecdh_b[i]);
2576 static void print_message(const char *s, long num, int length)
2580 mr ? "+DT:%s:%d:%d\n"
2581 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2582 (void)BIO_flush(bio_err);
2586 mr ? "+DN:%s:%ld:%d\n"
2587 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2588 (void)BIO_flush(bio_err);
2592 static void pkey_print_message(const char *str, const char *str2, long num,
2597 mr ? "+DTP:%d:%s:%s:%d\n"
2598 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2599 (void)BIO_flush(bio_err);
2603 mr ? "+DNP:%ld:%d:%s:%s\n"
2604 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2605 (void)BIO_flush(bio_err);
2609 static void print_result(int alg, int run_no, int count, double time_used)
2612 mr ? "+R:%d:%s:%f\n"
2613 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2614 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2618 static char *sstrsep(char **string, const char *delim)
2621 char *token = *string;
2626 memset(isdelim, 0, sizeof isdelim);
2630 isdelim[(unsigned char)(*delim)] = 1;
2634 while (!isdelim[(unsigned char)(**string)]) {
2646 static int do_multi(int multi)
2651 static char sep[] = ":";
2653 fds = malloc(multi * sizeof *fds);
2654 for (n = 0; n < multi; ++n) {
2655 if (pipe(fd) == -1) {
2656 fprintf(stderr, "pipe failure\n");
2667 if (dup(fd[1]) == -1) {
2668 fprintf(stderr, "dup failed\n");
2677 printf("Forked child %d\n", n);
2680 /* for now, assume the pipe is long enough to take all the output */
2681 for (n = 0; n < multi; ++n) {
2686 f = fdopen(fds[n], "r");
2687 while (fgets(buf, sizeof buf, f)) {
2688 p = strchr(buf, '\n');
2691 if (buf[0] != '+') {
2692 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2696 printf("Got: %s from %d\n", buf, n);
2697 if (!strncmp(buf, "+F:", 3)) {
2702 alg = atoi(sstrsep(&p, sep));
2704 for (j = 0; j < SIZE_NUM; ++j)
2705 results[alg][j] += atof(sstrsep(&p, sep));
2706 } else if (!strncmp(buf, "+F2:", 4)) {
2711 k = atoi(sstrsep(&p, sep));
2714 d = atof(sstrsep(&p, sep));
2716 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2718 rsa_results[k][0] = d;
2720 d = atof(sstrsep(&p, sep));
2722 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2724 rsa_results[k][1] = d;
2725 } else if (!strncmp(buf, "+F2:", 4)) {
2730 k = atoi(sstrsep(&p, sep));
2733 d = atof(sstrsep(&p, sep));
2735 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2737 rsa_results[k][0] = d;
2739 d = atof(sstrsep(&p, sep));
2741 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2743 rsa_results[k][1] = d;
2745 # ifndef OPENSSL_NO_DSA
2746 else if (!strncmp(buf, "+F3:", 4)) {
2751 k = atoi(sstrsep(&p, sep));
2754 d = atof(sstrsep(&p, sep));
2756 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2758 dsa_results[k][0] = d;
2760 d = atof(sstrsep(&p, sep));
2762 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2764 dsa_results[k][1] = d;
2767 # ifndef OPENSSL_NO_ECDSA
2768 else if (!strncmp(buf, "+F4:", 4)) {
2773 k = atoi(sstrsep(&p, sep));
2776 d = atof(sstrsep(&p, sep));
2778 ecdsa_results[k][0] =
2779 1 / (1 / ecdsa_results[k][0] + 1 / d);
2781 ecdsa_results[k][0] = d;
2783 d = atof(sstrsep(&p, sep));
2785 ecdsa_results[k][1] =
2786 1 / (1 / ecdsa_results[k][1] + 1 / d);
2788 ecdsa_results[k][1] = d;
2792 # ifndef OPENSSL_NO_ECDH
2793 else if (!strncmp(buf, "+F5:", 4)) {
2798 k = atoi(sstrsep(&p, sep));
2801 d = atof(sstrsep(&p, sep));
2803 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2805 ecdh_results[k][0] = d;
2810 else if (!strncmp(buf, "+H:", 3)) {
2812 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2822 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2824 static int mblengths[] =
2825 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2826 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2827 const char *alg_name;
2828 unsigned char *inp, *out, no_key[32], no_iv[16];
2832 inp = OPENSSL_malloc(mblengths[num - 1]);
2833 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2835 EVP_CIPHER_CTX_init(&ctx);
2836 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2837 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2839 alg_name = OBJ_nid2ln(evp_cipher->nid);
2841 for (j = 0; j < num; j++) {
2842 print_message(alg_name, 0, mblengths[j]);
2844 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2845 unsigned char aad[13];
2846 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2847 size_t len = mblengths[j];
2850 memset(aad, 0, 8); /* avoid uninitialized values */
2851 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2852 aad[9] = 3; /* version */
2854 aad[11] = 0; /* length */
2856 mb_param.out = NULL;
2859 mb_param.interleave = 8;
2861 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2862 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2863 sizeof(mb_param), &mb_param);
2869 EVP_CIPHER_CTX_ctrl(&ctx,
2870 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2871 sizeof(mb_param), &mb_param);
2875 RAND_bytes(out, 16);
2879 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2880 EVP_CTRL_AEAD_TLS1_AAD, 13, aad);
2881 EVP_Cipher(&ctx, out, inp, len + pad);
2886 mr ? "+R:%d:%s:%f\n"
2887 : "%d %s's in %.2fs\n", count, "evp", d);
2888 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2892 fprintf(stdout, "+H");
2893 for (j = 0; j < num; j++)
2894 fprintf(stdout, ":%d", mblengths[j]);
2895 fprintf(stdout, "\n");
2896 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2897 for (j = 0; j < num; j++)
2898 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2899 fprintf(stdout, "\n");
2902 "The 'numbers' are in 1000s of bytes per second processed.\n");
2903 fprintf(stdout, "type ");
2904 for (j = 0; j < num; j++)
2905 fprintf(stdout, "%7d bytes", mblengths[j]);
2906 fprintf(stdout, "\n");
2907 fprintf(stdout, "%-24s", alg_name);
2909 for (j = 0; j < num; j++) {
2910 if (results[D_EVP][j] > 10000)
2911 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2913 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2915 fprintf(stdout, "\n");