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 # include <openssl/hmac.h>
137 #include <openssl/evp.h>
138 # include <openssl/sha.h>
139 #ifndef OPENSSL_NO_RMD160
140 # include <openssl/ripemd.h>
142 #ifndef OPENSSL_NO_WHIRLPOOL
143 # include <openssl/whrlpool.h>
145 #ifndef OPENSSL_NO_RC4
146 # include <openssl/rc4.h>
148 #ifndef OPENSSL_NO_RC5
149 # include <openssl/rc5.h>
151 #ifndef OPENSSL_NO_RC2
152 # include <openssl/rc2.h>
154 #ifndef OPENSSL_NO_IDEA
155 # include <openssl/idea.h>
157 #ifndef OPENSSL_NO_SEED
158 # include <openssl/seed.h>
160 #ifndef OPENSSL_NO_BF
161 # include <openssl/blowfish.h>
163 #ifndef OPENSSL_NO_CAST
164 # include <openssl/cast.h>
166 #ifndef OPENSSL_NO_RSA
167 # include <openssl/rsa.h>
168 # include "./testrsa.h"
170 #include <openssl/x509.h>
171 #ifndef OPENSSL_NO_DSA
172 # include <openssl/dsa.h>
173 # include "./testdsa.h"
175 #ifndef OPENSSL_NO_ECDSA
176 # include <openssl/ecdsa.h>
178 #ifndef OPENSSL_NO_ECDH
179 # include <openssl/ecdh.h>
181 #include <openssl/modes.h>
183 #include <openssl/bn.h>
186 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
200 #define BUFSIZE (1024*8+1)
201 #define MAX_MISALIGNMENT 63
203 static volatile int run = 0;
206 static int usertime = 1;
208 static double Time_F(int s);
209 static void print_message(const char *s, long num, int length);
210 static void pkey_print_message(const char *str, const char *str2,
211 long num, int bits, int sec);
212 static void print_result(int alg, int run_no, int count, double time_used);
214 static int do_multi(int multi);
224 #define MAX_ECDH_SIZE 256
226 static const char *names[ALGOR_NUM] = {
227 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
228 "des cbc", "des ede3", "idea cbc", "seed cbc",
229 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
230 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
231 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
232 "evp", "sha256", "sha512", "whirlpool",
233 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
236 static double results[ALGOR_NUM][SIZE_NUM];
237 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
239 #ifndef OPENSSL_NO_RSA
240 static double rsa_results[RSA_NUM][2];
242 #ifndef OPENSSL_NO_DSA
243 static double dsa_results[DSA_NUM][2];
245 #ifndef OPENSSL_NO_ECDSA
246 static double ecdsa_results[EC_NUM][2];
248 #ifndef OPENSSL_NO_ECDH
249 static double ecdh_results[EC_NUM][1];
252 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
253 static const char rnd_seed[] =
254 "string to make the random number generator think it has entropy";
255 static int rnd_fake = 0;
259 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
260 # define SIGRETTYPE void
262 # define SIGRETTYPE int
265 static SIGRETTYPE sig_done(int sig);
266 static SIGRETTYPE sig_done(int sig)
268 signal(SIGALRM, sig_done);
278 # if !defined(SIGALRM)
281 static unsigned int lapse, schlock;
282 static void alarm_win32(unsigned int secs)
287 # define alarm alarm_win32
289 static DWORD WINAPI sleepy(VOID * arg)
297 static double Time_F(int s)
304 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
306 DWORD ret = GetLastError();
307 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
311 Sleep(0); /* scheduler spinlock */
312 ret = app_tminterval(s, usertime);
314 ret = app_tminterval(s, usertime);
316 TerminateThread(thr, 0);
324 static double Time_F(int s)
326 double ret = app_tminterval(s, usertime);
333 #ifndef OPENSSL_NO_ECDH
334 static const int KDF1_SHA1_len = 20;
335 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
338 if (*outlen < SHA_DIGEST_LENGTH)
340 *outlen = SHA_DIGEST_LENGTH;
341 return SHA1(in, inlen, out);
343 #endif /* OPENSSL_NO_ECDH */
345 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
347 int MAIN(int, char **);
349 int MAIN(int argc, char **argv)
351 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
352 unsigned char *buf = NULL, *buf2 = NULL;
354 long count = 0, save_count = 0;
356 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
359 #ifndef OPENSSL_NO_RSA
362 unsigned char md[EVP_MAX_MD_SIZE];
363 #ifndef OPENSSL_NO_MD2
364 unsigned char md2[MD2_DIGEST_LENGTH];
366 #ifndef OPENSSL_NO_MDC2
367 unsigned char mdc2[MDC2_DIGEST_LENGTH];
369 #ifndef OPENSSL_NO_MD4
370 unsigned char md4[MD4_DIGEST_LENGTH];
372 #ifndef OPENSSL_NO_MD5
373 unsigned char md5[MD5_DIGEST_LENGTH];
374 unsigned char hmac[MD5_DIGEST_LENGTH];
376 unsigned char sha[SHA_DIGEST_LENGTH];
377 unsigned char sha256[SHA256_DIGEST_LENGTH];
378 unsigned char sha512[SHA512_DIGEST_LENGTH];
379 #ifndef OPENSSL_NO_WHIRLPOOL
380 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
382 #ifndef OPENSSL_NO_RMD160
383 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
385 #ifndef OPENSSL_NO_RC4
388 #ifndef OPENSSL_NO_RC5
391 #ifndef OPENSSL_NO_RC2
394 #ifndef OPENSSL_NO_IDEA
395 IDEA_KEY_SCHEDULE idea_ks;
397 #ifndef OPENSSL_NO_SEED
398 SEED_KEY_SCHEDULE seed_ks;
400 #ifndef OPENSSL_NO_BF
403 #ifndef OPENSSL_NO_CAST
406 static const unsigned char key16[16] = {
407 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
408 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
410 #ifndef OPENSSL_NO_AES
411 static const unsigned char key24[24] = {
412 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
413 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
414 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
416 static const unsigned char key32[32] = {
417 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
418 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
419 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
420 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
423 #ifndef OPENSSL_NO_CAMELLIA
424 static const unsigned char ckey24[24] = {
425 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
426 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
427 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
429 static const unsigned char ckey32[32] = {
430 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
431 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
432 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
433 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
436 #ifndef OPENSSL_NO_AES
437 # define MAX_BLOCK_SIZE 128
439 # define MAX_BLOCK_SIZE 64
441 unsigned char DES_iv[8];
442 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
443 #ifndef OPENSSL_NO_DES
444 static DES_cblock key =
445 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
446 static DES_cblock key2 =
447 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
448 static DES_cblock key3 =
449 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
450 DES_key_schedule sch;
451 DES_key_schedule sch2;
452 DES_key_schedule sch3;
454 #ifndef OPENSSL_NO_AES
455 AES_KEY aes_ks1, aes_ks2, aes_ks3;
457 #ifndef OPENSSL_NO_CAMELLIA
458 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
470 #define D_CBC_IDEA 10
471 #define D_CBC_SEED 11
475 #define D_CBC_CAST 15
476 #define D_CBC_128_AES 16
477 #define D_CBC_192_AES 17
478 #define D_CBC_256_AES 18
479 #define D_CBC_128_CML 19
480 #define D_CBC_192_CML 20
481 #define D_CBC_256_CML 21
485 #define D_WHIRLPOOL 25
486 #define D_IGE_128_AES 26
487 #define D_IGE_192_AES 27
488 #define D_IGE_256_AES 28
491 long c[ALGOR_NUM][SIZE_NUM];
493 #ifndef OPENSSL_SYS_WIN32
504 #define R_RSA_15360 6
523 #ifndef OPENSSL_NO_RSA
524 RSA *rsa_key[RSA_NUM];
525 long rsa_c[RSA_NUM][2];
526 static unsigned int rsa_bits[RSA_NUM] = {
527 512, 1024, 2048, 3072, 4096, 7680, 15360
529 static unsigned char *rsa_data[RSA_NUM] = {
530 test512, test1024, test2048, test3072, test4096, test7680, test15360
532 static int rsa_data_length[RSA_NUM] = {
533 sizeof(test512), sizeof(test1024),
534 sizeof(test2048), sizeof(test3072),
535 sizeof(test4096), sizeof(test7680),
539 #ifndef OPENSSL_NO_DSA
540 DSA *dsa_key[DSA_NUM];
541 long dsa_c[DSA_NUM][2];
542 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
544 #ifndef OPENSSL_NO_EC
546 * We only test over the following curves as they are representative, To
547 * add tests over more curves, simply add the curve NID and curve name to
548 * the following arrays and increase the EC_NUM value accordingly.
550 static unsigned int test_curves[EC_NUM] = {
553 NID_X9_62_prime192v1,
555 NID_X9_62_prime256v1,
570 static const char *test_curves_names[EC_NUM] = {
590 static int test_curves_bits[EC_NUM] = {
591 160, 192, 224, 256, 384, 521,
592 163, 233, 283, 409, 571,
593 163, 233, 283, 409, 571
598 #ifndef OPENSSL_NO_ECDSA
599 unsigned char ecdsasig[256];
600 unsigned int ecdsasiglen;
601 EC_KEY *ecdsa[EC_NUM];
602 long ecdsa_c[EC_NUM][2];
605 #ifndef OPENSSL_NO_ECDH
606 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
607 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
608 int secret_size_a, secret_size_b;
611 long ecdh_c[EC_NUM][2];
614 int rsa_doit[RSA_NUM];
615 int dsa_doit[DSA_NUM];
616 #ifndef OPENSSL_NO_ECDSA
617 int ecdsa_doit[EC_NUM];
619 #ifndef OPENSSL_NO_ECDH
620 int ecdh_doit[EC_NUM];
624 const EVP_CIPHER *evp_cipher = NULL;
625 const EVP_MD *evp_md = NULL;
631 int misalign = MAX_MISALIGNMENT + 1;
638 memset(results, 0, sizeof(results));
639 #ifndef OPENSSL_NO_DSA
640 memset(dsa_key, 0, sizeof(dsa_key));
642 #ifndef OPENSSL_NO_ECDSA
643 for (i = 0; i < EC_NUM; i++)
646 #ifndef OPENSSL_NO_ECDH
647 for (i = 0; i < EC_NUM; i++) {
654 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
655 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
657 if (!load_config(bio_err, NULL))
660 #ifndef OPENSSL_NO_RSA
661 memset(rsa_key, 0, sizeof(rsa_key));
662 for (i = 0; i < RSA_NUM; i++)
667 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
668 BIO_printf(bio_err, "out of memory\n");
672 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
673 BIO_printf(bio_err, "out of memory\n");
677 misalign = 0; /* set later and buf/buf2 are adjusted
682 memset(c, 0, sizeof(c));
683 memset(DES_iv, 0, sizeof(DES_iv));
684 memset(iv, 0, sizeof(iv));
686 for (i = 0; i < ALGOR_NUM; i++)
688 for (i = 0; i < RSA_NUM; i++)
690 for (i = 0; i < DSA_NUM; i++)
692 #ifndef OPENSSL_NO_ECDSA
693 for (i = 0; i < EC_NUM; i++)
696 #ifndef OPENSSL_NO_ECDH
697 for (i = 0; i < EC_NUM; i++)
705 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
707 j--; /* Otherwise, -elapsed gets confused with an
709 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
713 BIO_printf(bio_err, "no EVP given\n");
716 evp_cipher = EVP_get_cipherbyname(*argv);
718 evp_md = EVP_get_digestbyname(*argv);
720 if (!evp_cipher && !evp_md) {
721 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
726 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
728 j--; /* Otherwise, -elapsed gets confused with an
731 #ifndef OPENSSL_NO_ENGINE
732 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
736 BIO_printf(bio_err, "no engine given\n");
739 setup_engine(bio_err, *argv, 0);
741 * j will be increased again further down. We just don't want
742 * speed to confuse an engine with an algorithm, especially when
743 * none is given (which means all of them should be run)
749 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
753 BIO_printf(bio_err, "no multi count given\n");
756 multi = atoi(argv[0]);
758 BIO_printf(bio_err, "bad multi count\n");
761 j--; /* Otherwise, -mr gets confused with an
765 else if (argc > 0 && !strcmp(*argv, "-mr")) {
767 j--; /* Otherwise, -mr gets confused with an
769 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
772 } else if (argc > 0 && !strcmp(*argv, "-misalign")) {
776 BIO_printf(bio_err, "no misalignment given\n");
779 misalign = atoi(argv[0]);
780 if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
782 "misalignment is outsize permitted range 0-%d\n",
786 buf = buf_malloc + misalign;
787 buf2 = buf2_malloc + misalign;
790 #ifndef OPENSSL_NO_MD2
791 if (strcmp(*argv, "md2") == 0)
795 #ifndef OPENSSL_NO_MDC2
796 if (strcmp(*argv, "mdc2") == 0)
800 #ifndef OPENSSL_NO_MD4
801 if (strcmp(*argv, "md4") == 0)
805 #ifndef OPENSSL_NO_MD5
806 if (strcmp(*argv, "md5") == 0)
810 #ifndef OPENSSL_NO_MD5
811 if (strcmp(*argv, "hmac") == 0)
815 if (strcmp(*argv, "sha1") == 0)
817 else if (strcmp(*argv, "sha") == 0)
818 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
819 else if (strcmp(*argv, "sha256") == 0)
821 else if (strcmp(*argv, "sha512") == 0)
824 #ifndef OPENSSL_NO_WHIRLPOOL
825 if (strcmp(*argv, "whirlpool") == 0)
826 doit[D_WHIRLPOOL] = 1;
829 #ifndef OPENSSL_NO_RMD160
830 if (strcmp(*argv, "ripemd") == 0)
832 else if (strcmp(*argv, "rmd160") == 0)
834 else if (strcmp(*argv, "ripemd160") == 0)
838 #ifndef OPENSSL_NO_RC4
839 if (strcmp(*argv, "rc4") == 0)
843 #ifndef OPENSSL_NO_DES
844 if (strcmp(*argv, "des-cbc") == 0)
846 else if (strcmp(*argv, "des-ede3") == 0)
847 doit[D_EDE3_DES] = 1;
850 #ifndef OPENSSL_NO_AES
851 if (strcmp(*argv, "aes-128-cbc") == 0)
852 doit[D_CBC_128_AES] = 1;
853 else if (strcmp(*argv, "aes-192-cbc") == 0)
854 doit[D_CBC_192_AES] = 1;
855 else if (strcmp(*argv, "aes-256-cbc") == 0)
856 doit[D_CBC_256_AES] = 1;
857 else if (strcmp(*argv, "aes-128-ige") == 0)
858 doit[D_IGE_128_AES] = 1;
859 else if (strcmp(*argv, "aes-192-ige") == 0)
860 doit[D_IGE_192_AES] = 1;
861 else if (strcmp(*argv, "aes-256-ige") == 0)
862 doit[D_IGE_256_AES] = 1;
865 #ifndef OPENSSL_NO_CAMELLIA
866 if (strcmp(*argv, "camellia-128-cbc") == 0)
867 doit[D_CBC_128_CML] = 1;
868 else if (strcmp(*argv, "camellia-192-cbc") == 0)
869 doit[D_CBC_192_CML] = 1;
870 else if (strcmp(*argv, "camellia-256-cbc") == 0)
871 doit[D_CBC_256_CML] = 1;
874 #ifndef OPENSSL_NO_RSA
876 if (strcmp(*argv, "openssl") == 0) {
877 RSA_set_default_method(RSA_PKCS1_SSLeay());
881 #endif /* !OPENSSL_NO_RSA */
882 if (strcmp(*argv, "dsa512") == 0)
883 dsa_doit[R_DSA_512] = 2;
884 else if (strcmp(*argv, "dsa1024") == 0)
885 dsa_doit[R_DSA_1024] = 2;
886 else if (strcmp(*argv, "dsa2048") == 0)
887 dsa_doit[R_DSA_2048] = 2;
888 else if (strcmp(*argv, "rsa512") == 0)
889 rsa_doit[R_RSA_512] = 2;
890 else if (strcmp(*argv, "rsa1024") == 0)
891 rsa_doit[R_RSA_1024] = 2;
892 else if (strcmp(*argv, "rsa2048") == 0)
893 rsa_doit[R_RSA_2048] = 2;
894 else if (strcmp(*argv, "rsa3072") == 0)
895 rsa_doit[R_RSA_3072] = 2;
896 else if (strcmp(*argv, "rsa4096") == 0)
897 rsa_doit[R_RSA_4096] = 2;
898 else if (strcmp(*argv, "rsa7680") == 0)
899 rsa_doit[R_RSA_7680] = 2;
900 else if (strcmp(*argv, "rsa15360") == 0)
901 rsa_doit[R_RSA_15360] = 2;
903 #ifndef OPENSSL_NO_RC2
904 if (strcmp(*argv, "rc2-cbc") == 0)
906 else if (strcmp(*argv, "rc2") == 0)
910 #ifndef OPENSSL_NO_RC5
911 if (strcmp(*argv, "rc5-cbc") == 0)
913 else if (strcmp(*argv, "rc5") == 0)
917 #ifndef OPENSSL_NO_IDEA
918 if (strcmp(*argv, "idea-cbc") == 0)
919 doit[D_CBC_IDEA] = 1;
920 else if (strcmp(*argv, "idea") == 0)
921 doit[D_CBC_IDEA] = 1;
924 #ifndef OPENSSL_NO_SEED
925 if (strcmp(*argv, "seed-cbc") == 0)
926 doit[D_CBC_SEED] = 1;
927 else if (strcmp(*argv, "seed") == 0)
928 doit[D_CBC_SEED] = 1;
931 #ifndef OPENSSL_NO_BF
932 if (strcmp(*argv, "bf-cbc") == 0)
934 else if (strcmp(*argv, "blowfish") == 0)
936 else if (strcmp(*argv, "bf") == 0)
940 #ifndef OPENSSL_NO_CAST
941 if (strcmp(*argv, "cast-cbc") == 0)
942 doit[D_CBC_CAST] = 1;
943 else if (strcmp(*argv, "cast") == 0)
944 doit[D_CBC_CAST] = 1;
945 else if (strcmp(*argv, "cast5") == 0)
946 doit[D_CBC_CAST] = 1;
949 #ifndef OPENSSL_NO_DES
950 if (strcmp(*argv, "des") == 0) {
952 doit[D_EDE3_DES] = 1;
955 #ifndef OPENSSL_NO_AES
956 if (strcmp(*argv, "aes") == 0) {
957 doit[D_CBC_128_AES] = 1;
958 doit[D_CBC_192_AES] = 1;
959 doit[D_CBC_256_AES] = 1;
960 } else if (strcmp(*argv, "ghash") == 0) {
964 #ifndef OPENSSL_NO_CAMELLIA
965 if (strcmp(*argv, "camellia") == 0) {
966 doit[D_CBC_128_CML] = 1;
967 doit[D_CBC_192_CML] = 1;
968 doit[D_CBC_256_CML] = 1;
971 #ifndef OPENSSL_NO_RSA
972 if (strcmp(*argv, "rsa") == 0) {
973 rsa_doit[R_RSA_512] = 1;
974 rsa_doit[R_RSA_1024] = 1;
975 rsa_doit[R_RSA_2048] = 1;
976 rsa_doit[R_RSA_3072] = 1;
977 rsa_doit[R_RSA_4096] = 1;
978 rsa_doit[R_RSA_7680] = 1;
979 rsa_doit[R_RSA_15360] = 1;
982 #ifndef OPENSSL_NO_DSA
983 if (strcmp(*argv, "dsa") == 0) {
984 dsa_doit[R_DSA_512] = 1;
985 dsa_doit[R_DSA_1024] = 1;
986 dsa_doit[R_DSA_2048] = 1;
989 #ifndef OPENSSL_NO_ECDSA
990 if (strcmp(*argv, "ecdsap160") == 0)
991 ecdsa_doit[R_EC_P160] = 2;
992 else if (strcmp(*argv, "ecdsap192") == 0)
993 ecdsa_doit[R_EC_P192] = 2;
994 else if (strcmp(*argv, "ecdsap224") == 0)
995 ecdsa_doit[R_EC_P224] = 2;
996 else if (strcmp(*argv, "ecdsap256") == 0)
997 ecdsa_doit[R_EC_P256] = 2;
998 else if (strcmp(*argv, "ecdsap384") == 0)
999 ecdsa_doit[R_EC_P384] = 2;
1000 else if (strcmp(*argv, "ecdsap521") == 0)
1001 ecdsa_doit[R_EC_P521] = 2;
1002 else if (strcmp(*argv, "ecdsak163") == 0)
1003 ecdsa_doit[R_EC_K163] = 2;
1004 else if (strcmp(*argv, "ecdsak233") == 0)
1005 ecdsa_doit[R_EC_K233] = 2;
1006 else if (strcmp(*argv, "ecdsak283") == 0)
1007 ecdsa_doit[R_EC_K283] = 2;
1008 else if (strcmp(*argv, "ecdsak409") == 0)
1009 ecdsa_doit[R_EC_K409] = 2;
1010 else if (strcmp(*argv, "ecdsak571") == 0)
1011 ecdsa_doit[R_EC_K571] = 2;
1012 else if (strcmp(*argv, "ecdsab163") == 0)
1013 ecdsa_doit[R_EC_B163] = 2;
1014 else if (strcmp(*argv, "ecdsab233") == 0)
1015 ecdsa_doit[R_EC_B233] = 2;
1016 else if (strcmp(*argv, "ecdsab283") == 0)
1017 ecdsa_doit[R_EC_B283] = 2;
1018 else if (strcmp(*argv, "ecdsab409") == 0)
1019 ecdsa_doit[R_EC_B409] = 2;
1020 else if (strcmp(*argv, "ecdsab571") == 0)
1021 ecdsa_doit[R_EC_B571] = 2;
1022 else if (strcmp(*argv, "ecdsa") == 0) {
1023 for (i = 0; i < EC_NUM; i++)
1027 #ifndef OPENSSL_NO_ECDH
1028 if (strcmp(*argv, "ecdhp160") == 0)
1029 ecdh_doit[R_EC_P160] = 2;
1030 else if (strcmp(*argv, "ecdhp192") == 0)
1031 ecdh_doit[R_EC_P192] = 2;
1032 else if (strcmp(*argv, "ecdhp224") == 0)
1033 ecdh_doit[R_EC_P224] = 2;
1034 else if (strcmp(*argv, "ecdhp256") == 0)
1035 ecdh_doit[R_EC_P256] = 2;
1036 else if (strcmp(*argv, "ecdhp384") == 0)
1037 ecdh_doit[R_EC_P384] = 2;
1038 else if (strcmp(*argv, "ecdhp521") == 0)
1039 ecdh_doit[R_EC_P521] = 2;
1040 else if (strcmp(*argv, "ecdhk163") == 0)
1041 ecdh_doit[R_EC_K163] = 2;
1042 else if (strcmp(*argv, "ecdhk233") == 0)
1043 ecdh_doit[R_EC_K233] = 2;
1044 else if (strcmp(*argv, "ecdhk283") == 0)
1045 ecdh_doit[R_EC_K283] = 2;
1046 else if (strcmp(*argv, "ecdhk409") == 0)
1047 ecdh_doit[R_EC_K409] = 2;
1048 else if (strcmp(*argv, "ecdhk571") == 0)
1049 ecdh_doit[R_EC_K571] = 2;
1050 else if (strcmp(*argv, "ecdhb163") == 0)
1051 ecdh_doit[R_EC_B163] = 2;
1052 else if (strcmp(*argv, "ecdhb233") == 0)
1053 ecdh_doit[R_EC_B233] = 2;
1054 else if (strcmp(*argv, "ecdhb283") == 0)
1055 ecdh_doit[R_EC_B283] = 2;
1056 else if (strcmp(*argv, "ecdhb409") == 0)
1057 ecdh_doit[R_EC_B409] = 2;
1058 else if (strcmp(*argv, "ecdhb571") == 0)
1059 ecdh_doit[R_EC_B571] = 2;
1060 else if (strcmp(*argv, "ecdh") == 0) {
1061 for (i = 0; i < EC_NUM; i++)
1066 BIO_printf(bio_err, "Error: bad option or value\n");
1067 BIO_printf(bio_err, "\n");
1068 BIO_printf(bio_err, "Available values:\n");
1069 #ifndef OPENSSL_NO_MD2
1070 BIO_printf(bio_err, "md2 ");
1072 #ifndef OPENSSL_NO_MDC2
1073 BIO_printf(bio_err, "mdc2 ");
1075 #ifndef OPENSSL_NO_MD4
1076 BIO_printf(bio_err, "md4 ");
1078 #ifndef OPENSSL_NO_MD5
1079 BIO_printf(bio_err, "md5 ");
1080 BIO_printf(bio_err, "hmac ");
1082 BIO_printf(bio_err, "sha1 ");
1083 BIO_printf(bio_err, "sha256 ");
1084 BIO_printf(bio_err, "sha512 ");
1085 #ifndef OPENSSL_NO_WHIRLPOOL
1086 BIO_printf(bio_err, "whirlpool");
1088 #ifndef OPENSSL_NO_RMD160
1089 BIO_printf(bio_err, "rmd160");
1091 BIO_printf(bio_err, "\n");
1093 #ifndef OPENSSL_NO_IDEA
1094 BIO_printf(bio_err, "idea-cbc ");
1096 #ifndef OPENSSL_NO_SEED
1097 BIO_printf(bio_err, "seed-cbc ");
1099 #ifndef OPENSSL_NO_RC2
1100 BIO_printf(bio_err, "rc2-cbc ");
1102 #ifndef OPENSSL_NO_RC5
1103 BIO_printf(bio_err, "rc5-cbc ");
1105 #ifndef OPENSSL_NO_BF
1106 BIO_printf(bio_err, "bf-cbc");
1108 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1109 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1110 BIO_printf(bio_err, "\n");
1112 #ifndef OPENSSL_NO_DES
1113 BIO_printf(bio_err, "des-cbc des-ede3 ");
1115 #ifndef OPENSSL_NO_AES
1116 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1117 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1119 #ifndef OPENSSL_NO_CAMELLIA
1120 BIO_printf(bio_err, "\n");
1122 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1124 #ifndef OPENSSL_NO_RC4
1125 BIO_printf(bio_err, "rc4");
1127 BIO_printf(bio_err, "\n");
1129 #ifndef OPENSSL_NO_RSA
1131 "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1132 BIO_printf(bio_err, "rsa7680 rsa15360\n");
1135 #ifndef OPENSSL_NO_DSA
1136 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1138 #ifndef OPENSSL_NO_ECDSA
1139 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1140 "ecdsap256 ecdsap384 ecdsap521\n");
1142 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1144 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1145 BIO_printf(bio_err, "ecdsa\n");
1147 #ifndef OPENSSL_NO_ECDH
1148 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1149 "ecdhp256 ecdhp384 ecdhp521\n");
1151 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1153 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1154 BIO_printf(bio_err, "ecdh\n");
1157 #ifndef OPENSSL_NO_IDEA
1158 BIO_printf(bio_err, "idea ");
1160 #ifndef OPENSSL_NO_SEED
1161 BIO_printf(bio_err, "seed ");
1163 #ifndef OPENSSL_NO_RC2
1164 BIO_printf(bio_err, "rc2 ");
1166 #ifndef OPENSSL_NO_DES
1167 BIO_printf(bio_err, "des ");
1169 #ifndef OPENSSL_NO_AES
1170 BIO_printf(bio_err, "aes ");
1172 #ifndef OPENSSL_NO_CAMELLIA
1173 BIO_printf(bio_err, "camellia ");
1175 #ifndef OPENSSL_NO_RSA
1176 BIO_printf(bio_err, "rsa ");
1178 #ifndef OPENSSL_NO_BF
1179 BIO_printf(bio_err, "blowfish");
1181 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1182 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1183 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1184 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1185 BIO_printf(bio_err, "\n");
1188 BIO_printf(bio_err, "\n");
1189 BIO_printf(bio_err, "Available options:\n");
1190 #if defined(TIMES) || defined(USE_TOD)
1191 BIO_printf(bio_err, "-elapsed "
1192 "measure time in real time instead of CPU user time.\n");
1194 #ifndef OPENSSL_NO_ENGINE
1197 "use engine e, possibly a hardware device.\n");
1199 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1202 "time decryption instead of encryption (only EVP).\n");
1205 "produce machine readable output.\n");
1208 "perform multi-block benchmark (for specific ciphers)\n");
1211 "perform benchmark with misaligned data\n");
1214 "-multi n " "run n benchmarks in parallel.\n");
1224 if (multi && do_multi(multi))
1229 for (i = 0; i < ALGOR_NUM; i++) {
1233 for (i = 0; i < RSA_NUM; i++)
1235 for (i = 0; i < DSA_NUM; i++)
1237 #ifndef OPENSSL_NO_ECDSA
1238 for (i = 0; i < EC_NUM; i++)
1241 #ifndef OPENSSL_NO_ECDH
1242 for (i = 0; i < EC_NUM; i++)
1246 for (i = 0; i < ALGOR_NUM; i++)
1250 if (usertime == 0 && !mr)
1252 "You have chosen to measure elapsed time "
1253 "instead of user CPU time.\n");
1255 #ifndef OPENSSL_NO_RSA
1256 for (i = 0; i < RSA_NUM; i++) {
1257 const unsigned char *p;
1260 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1261 if (rsa_key[i] == NULL) {
1262 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1269 #ifndef OPENSSL_NO_DSA
1270 dsa_key[0] = get_dsa512();
1271 dsa_key[1] = get_dsa1024();
1272 dsa_key[2] = get_dsa2048();
1275 #ifndef OPENSSL_NO_DES
1276 DES_set_key_unchecked(&key, &sch);
1277 DES_set_key_unchecked(&key2, &sch2);
1278 DES_set_key_unchecked(&key3, &sch3);
1280 #ifndef OPENSSL_NO_AES
1281 AES_set_encrypt_key(key16, 128, &aes_ks1);
1282 AES_set_encrypt_key(key24, 192, &aes_ks2);
1283 AES_set_encrypt_key(key32, 256, &aes_ks3);
1285 #ifndef OPENSSL_NO_CAMELLIA
1286 Camellia_set_key(key16, 128, &camellia_ks1);
1287 Camellia_set_key(ckey24, 192, &camellia_ks2);
1288 Camellia_set_key(ckey32, 256, &camellia_ks3);
1290 #ifndef OPENSSL_NO_IDEA
1291 idea_set_encrypt_key(key16, &idea_ks);
1293 #ifndef OPENSSL_NO_SEED
1294 SEED_set_key(key16, &seed_ks);
1296 #ifndef OPENSSL_NO_RC4
1297 RC4_set_key(&rc4_ks, 16, key16);
1299 #ifndef OPENSSL_NO_RC2
1300 RC2_set_key(&rc2_ks, 16, key16, 128);
1302 #ifndef OPENSSL_NO_RC5
1303 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1305 #ifndef OPENSSL_NO_BF
1306 BF_set_key(&bf_ks, 16, key16);
1308 #ifndef OPENSSL_NO_CAST
1309 CAST_set_key(&cast_ks, 16, key16);
1311 #ifndef OPENSSL_NO_RSA
1312 memset(rsa_c, 0, sizeof(rsa_c));
1315 # ifndef OPENSSL_NO_DES
1316 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1322 for (it = count; it; it--)
1323 DES_ecb_encrypt((DES_cblock *)buf,
1324 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1328 c[D_MD2][0] = count / 10;
1329 c[D_MDC2][0] = count / 10;
1330 c[D_MD4][0] = count;
1331 c[D_MD5][0] = count;
1332 c[D_HMAC][0] = count;
1333 c[D_SHA1][0] = count;
1334 c[D_RMD160][0] = count;
1335 c[D_RC4][0] = count * 5;
1336 c[D_CBC_DES][0] = count;
1337 c[D_EDE3_DES][0] = count / 3;
1338 c[D_CBC_IDEA][0] = count;
1339 c[D_CBC_SEED][0] = count;
1340 c[D_CBC_RC2][0] = count;
1341 c[D_CBC_RC5][0] = count;
1342 c[D_CBC_BF][0] = count;
1343 c[D_CBC_CAST][0] = count;
1344 c[D_CBC_128_AES][0] = count;
1345 c[D_CBC_192_AES][0] = count;
1346 c[D_CBC_256_AES][0] = count;
1347 c[D_CBC_128_CML][0] = count;
1348 c[D_CBC_192_CML][0] = count;
1349 c[D_CBC_256_CML][0] = count;
1350 c[D_SHA256][0] = count;
1351 c[D_SHA512][0] = count;
1352 c[D_WHIRLPOOL][0] = count;
1353 c[D_IGE_128_AES][0] = count;
1354 c[D_IGE_192_AES][0] = count;
1355 c[D_IGE_256_AES][0] = count;
1356 c[D_GHASH][0] = count;
1358 for (i = 1; i < SIZE_NUM; i++) {
1361 l0 = (long)lengths[0];
1362 l1 = (long)lengths[i];
1364 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1365 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1366 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1367 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1368 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1369 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1370 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1371 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1372 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1373 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1375 l0 = (long)lengths[i - 1];
1377 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1378 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1379 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1380 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1381 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1382 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1383 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1384 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1385 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1386 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1387 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1388 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1389 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1390 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1391 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1392 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1393 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1394 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1397 # ifndef OPENSSL_NO_RSA
1398 rsa_c[R_RSA_512][0] = count / 2000;
1399 rsa_c[R_RSA_512][1] = count / 400;
1400 for (i = 1; i < RSA_NUM; i++) {
1401 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1402 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1403 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1406 if (rsa_c[i][0] == 0) {
1414 # ifndef OPENSSL_NO_DSA
1415 dsa_c[R_DSA_512][0] = count / 1000;
1416 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1417 for (i = 1; i < DSA_NUM; i++) {
1418 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1419 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1420 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1423 if (dsa_c[i] == 0) {
1431 # ifndef OPENSSL_NO_ECDSA
1432 ecdsa_c[R_EC_P160][0] = count / 1000;
1433 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1434 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1435 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1436 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1437 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1440 if (ecdsa_c[i] == 0) {
1446 ecdsa_c[R_EC_K163][0] = count / 1000;
1447 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1448 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1449 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1450 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1451 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1454 if (ecdsa_c[i] == 0) {
1460 ecdsa_c[R_EC_B163][0] = count / 1000;
1461 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1462 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1463 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1464 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1465 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1468 if (ecdsa_c[i] == 0) {
1476 # ifndef OPENSSL_NO_ECDH
1477 ecdh_c[R_EC_P160][0] = count / 1000;
1478 ecdh_c[R_EC_P160][1] = count / 1000;
1479 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1480 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1481 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1482 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1485 if (ecdh_c[i] == 0) {
1491 ecdh_c[R_EC_K163][0] = count / 1000;
1492 ecdh_c[R_EC_K163][1] = count / 1000;
1493 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1494 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1495 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1496 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1499 if (ecdh_c[i] == 0) {
1505 ecdh_c[R_EC_B163][0] = count / 1000;
1506 ecdh_c[R_EC_B163][1] = count / 1000;
1507 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1508 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1509 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1510 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1513 if (ecdh_c[i] == 0) {
1521 # define COND(d) (count < (d))
1522 # define COUNT(d) (d)
1524 /* not worth fixing */
1525 # error "You cannot disable DES on systems without SIGALRM."
1526 # endif /* OPENSSL_NO_DES */
1528 # define COND(c) (run && count<0x7fffffff)
1529 # define COUNT(d) (count)
1531 signal(SIGALRM, sig_done);
1533 #endif /* SIGALRM */
1535 #ifndef OPENSSL_NO_MD2
1537 for (j = 0; j < SIZE_NUM; j++) {
1538 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1540 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1541 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1544 print_result(D_MD2, j, count, d);
1548 #ifndef OPENSSL_NO_MDC2
1550 for (j = 0; j < SIZE_NUM; j++) {
1551 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1553 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1554 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1557 print_result(D_MDC2, j, count, d);
1562 #ifndef OPENSSL_NO_MD4
1564 for (j = 0; j < SIZE_NUM; j++) {
1565 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1567 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1568 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1569 NULL, EVP_md4(), NULL);
1571 print_result(D_MD4, j, count, d);
1576 #ifndef OPENSSL_NO_MD5
1578 for (j = 0; j < SIZE_NUM; j++) {
1579 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1581 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1582 MD5(buf, lengths[j], md5);
1584 print_result(D_MD5, j, count, d);
1589 #if !defined(OPENSSL_NO_MD5)
1593 HMAC_CTX_init(&hctx);
1594 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1595 16, EVP_md5(), NULL);
1597 for (j = 0; j < SIZE_NUM; j++) {
1598 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1600 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1601 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1602 HMAC_Update(&hctx, buf, lengths[j]);
1603 HMAC_Final(&hctx, &(hmac[0]), NULL);
1606 print_result(D_HMAC, j, count, d);
1608 HMAC_CTX_cleanup(&hctx);
1612 for (j = 0; j < SIZE_NUM; j++) {
1613 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1615 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1616 SHA1(buf, lengths[j], sha);
1618 print_result(D_SHA1, j, count, d);
1621 if (doit[D_SHA256]) {
1622 for (j = 0; j < SIZE_NUM; j++) {
1623 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1625 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1626 SHA256(buf, lengths[j], sha256);
1628 print_result(D_SHA256, j, count, d);
1631 if (doit[D_SHA512]) {
1632 for (j = 0; j < SIZE_NUM; j++) {
1633 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1635 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1636 SHA512(buf, lengths[j], sha512);
1638 print_result(D_SHA512, j, count, d);
1642 #ifndef OPENSSL_NO_WHIRLPOOL
1643 if (doit[D_WHIRLPOOL]) {
1644 for (j = 0; j < SIZE_NUM; j++) {
1645 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1647 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1648 WHIRLPOOL(buf, lengths[j], whirlpool);
1650 print_result(D_WHIRLPOOL, j, count, d);
1655 #ifndef OPENSSL_NO_RMD160
1656 if (doit[D_RMD160]) {
1657 for (j = 0; j < SIZE_NUM; j++) {
1658 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1660 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1661 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1662 EVP_ripemd160(), NULL);
1664 print_result(D_RMD160, j, count, d);
1668 #ifndef OPENSSL_NO_RC4
1670 for (j = 0; j < SIZE_NUM; j++) {
1671 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1673 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1674 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1676 print_result(D_RC4, j, count, d);
1680 #ifndef OPENSSL_NO_DES
1681 if (doit[D_CBC_DES]) {
1682 for (j = 0; j < SIZE_NUM; j++) {
1683 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1685 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1686 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1687 &DES_iv, DES_ENCRYPT);
1689 print_result(D_CBC_DES, j, count, d);
1693 if (doit[D_EDE3_DES]) {
1694 for (j = 0; j < SIZE_NUM; j++) {
1695 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1697 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1698 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1700 &DES_iv, DES_ENCRYPT);
1702 print_result(D_EDE3_DES, j, count, d);
1706 #ifndef OPENSSL_NO_AES
1707 if (doit[D_CBC_128_AES]) {
1708 for (j = 0; j < SIZE_NUM; j++) {
1709 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1712 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1713 AES_cbc_encrypt(buf, buf,
1714 (unsigned long)lengths[j], &aes_ks1,
1717 print_result(D_CBC_128_AES, j, count, d);
1720 if (doit[D_CBC_192_AES]) {
1721 for (j = 0; j < SIZE_NUM; j++) {
1722 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1725 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1726 AES_cbc_encrypt(buf, buf,
1727 (unsigned long)lengths[j], &aes_ks2,
1730 print_result(D_CBC_192_AES, j, count, d);
1733 if (doit[D_CBC_256_AES]) {
1734 for (j = 0; j < SIZE_NUM; j++) {
1735 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1738 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1739 AES_cbc_encrypt(buf, buf,
1740 (unsigned long)lengths[j], &aes_ks3,
1743 print_result(D_CBC_256_AES, j, count, d);
1747 if (doit[D_IGE_128_AES]) {
1748 for (j = 0; j < SIZE_NUM; j++) {
1749 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1752 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1753 AES_ige_encrypt(buf, buf2,
1754 (unsigned long)lengths[j], &aes_ks1,
1757 print_result(D_IGE_128_AES, j, count, d);
1760 if (doit[D_IGE_192_AES]) {
1761 for (j = 0; j < SIZE_NUM; j++) {
1762 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1765 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1766 AES_ige_encrypt(buf, buf2,
1767 (unsigned long)lengths[j], &aes_ks2,
1770 print_result(D_IGE_192_AES, j, count, d);
1773 if (doit[D_IGE_256_AES]) {
1774 for (j = 0; j < SIZE_NUM; j++) {
1775 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1778 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1779 AES_ige_encrypt(buf, buf2,
1780 (unsigned long)lengths[j], &aes_ks3,
1783 print_result(D_IGE_256_AES, j, count, d);
1786 if (doit[D_GHASH]) {
1787 GCM128_CONTEXT *ctx =
1788 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1789 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1791 for (j = 0; j < SIZE_NUM; j++) {
1792 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1794 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1795 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1797 print_result(D_GHASH, j, count, d);
1799 CRYPTO_gcm128_release(ctx);
1802 #ifndef OPENSSL_NO_CAMELLIA
1803 if (doit[D_CBC_128_CML]) {
1804 for (j = 0; j < SIZE_NUM; j++) {
1805 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1808 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1809 Camellia_cbc_encrypt(buf, buf,
1810 (unsigned long)lengths[j], &camellia_ks1,
1811 iv, CAMELLIA_ENCRYPT);
1813 print_result(D_CBC_128_CML, j, count, d);
1816 if (doit[D_CBC_192_CML]) {
1817 for (j = 0; j < SIZE_NUM; j++) {
1818 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1821 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1822 Camellia_cbc_encrypt(buf, buf,
1823 (unsigned long)lengths[j], &camellia_ks2,
1824 iv, CAMELLIA_ENCRYPT);
1826 print_result(D_CBC_192_CML, j, count, d);
1829 if (doit[D_CBC_256_CML]) {
1830 for (j = 0; j < SIZE_NUM; j++) {
1831 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1834 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1835 Camellia_cbc_encrypt(buf, buf,
1836 (unsigned long)lengths[j], &camellia_ks3,
1837 iv, CAMELLIA_ENCRYPT);
1839 print_result(D_CBC_256_CML, j, count, d);
1843 #ifndef OPENSSL_NO_IDEA
1844 if (doit[D_CBC_IDEA]) {
1845 for (j = 0; j < SIZE_NUM; j++) {
1846 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1848 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1849 idea_cbc_encrypt(buf, buf,
1850 (unsigned long)lengths[j], &idea_ks,
1853 print_result(D_CBC_IDEA, j, count, d);
1857 #ifndef OPENSSL_NO_SEED
1858 if (doit[D_CBC_SEED]) {
1859 for (j = 0; j < SIZE_NUM; j++) {
1860 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1862 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1863 SEED_cbc_encrypt(buf, buf,
1864 (unsigned long)lengths[j], &seed_ks, iv, 1);
1866 print_result(D_CBC_SEED, j, count, d);
1870 #ifndef OPENSSL_NO_RC2
1871 if (doit[D_CBC_RC2]) {
1872 for (j = 0; j < SIZE_NUM; j++) {
1873 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1875 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1876 RC2_cbc_encrypt(buf, buf,
1877 (unsigned long)lengths[j], &rc2_ks,
1880 print_result(D_CBC_RC2, j, count, d);
1884 #ifndef OPENSSL_NO_RC5
1885 if (doit[D_CBC_RC5]) {
1886 for (j = 0; j < SIZE_NUM; j++) {
1887 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1889 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1890 RC5_32_cbc_encrypt(buf, buf,
1891 (unsigned long)lengths[j], &rc5_ks,
1894 print_result(D_CBC_RC5, j, count, d);
1898 #ifndef OPENSSL_NO_BF
1899 if (doit[D_CBC_BF]) {
1900 for (j = 0; j < SIZE_NUM; j++) {
1901 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1903 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1904 BF_cbc_encrypt(buf, buf,
1905 (unsigned long)lengths[j], &bf_ks,
1908 print_result(D_CBC_BF, j, count, d);
1912 #ifndef OPENSSL_NO_CAST
1913 if (doit[D_CBC_CAST]) {
1914 for (j = 0; j < SIZE_NUM; j++) {
1915 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1917 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1918 CAST_cbc_encrypt(buf, buf,
1919 (unsigned long)lengths[j], &cast_ks,
1922 print_result(D_CBC_CAST, j, count, d);
1928 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1929 if (multiblock && evp_cipher) {
1931 (EVP_CIPHER_flags(evp_cipher) &
1932 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1933 fprintf(stderr, "%s is not multi-block capable\n",
1934 OBJ_nid2ln(evp_cipher->nid));
1937 multiblock_speed(evp_cipher);
1942 for (j = 0; j < SIZE_NUM; j++) {
1947 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1949 * -O3 -fschedule-insns messes up an optimization here!
1950 * names[D_EVP] somehow becomes NULL
1952 print_message(names[D_EVP], save_count, lengths[j]);
1954 EVP_CIPHER_CTX_init(&ctx);
1956 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1958 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1959 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1963 for (count = 0, run = 1;
1964 COND(save_count * 4 * lengths[0] / lengths[j]);
1966 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1968 for (count = 0, run = 1;
1969 COND(save_count * 4 * lengths[0] / lengths[j]);
1971 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1973 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1975 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1977 EVP_CIPHER_CTX_cleanup(&ctx);
1980 names[D_EVP] = OBJ_nid2ln(evp_md->type);
1981 print_message(names[D_EVP], save_count, lengths[j]);
1984 for (count = 0, run = 1;
1985 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1986 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1990 print_result(D_EVP, j, count, d);
1993 #ifndef OPENSSL_SYS_WIN32
1995 RAND_pseudo_bytes(buf, 36);
1996 #ifndef OPENSSL_NO_RSA
1997 for (j = 0; j < RSA_NUM; j++) {
2001 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2004 "RSA sign failure. No RSA sign will be done.\n");
2005 ERR_print_errors(bio_err);
2008 pkey_print_message("private", "rsa",
2009 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2010 /* RSA_blinding_on(rsa_key[j],NULL); */
2012 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2013 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2014 &rsa_num, rsa_key[j]);
2016 BIO_printf(bio_err, "RSA sign failure\n");
2017 ERR_print_errors(bio_err);
2024 mr ? "+R1:%ld:%d:%.2f\n"
2025 : "%ld %d bit private RSA's in %.2fs\n",
2026 count, rsa_bits[j], d);
2027 rsa_results[j][0] = d / (double)count;
2032 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2035 "RSA verify failure. No RSA verify will be done.\n");
2036 ERR_print_errors(bio_err);
2039 pkey_print_message("public", "rsa",
2040 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2042 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2043 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2044 rsa_num, rsa_key[j]);
2046 BIO_printf(bio_err, "RSA verify failure\n");
2047 ERR_print_errors(bio_err);
2054 mr ? "+R2:%ld:%d:%.2f\n"
2055 : "%ld %d bit public RSA's in %.2fs\n",
2056 count, rsa_bits[j], d);
2057 rsa_results[j][1] = d / (double)count;
2061 if (rsa_count <= 1) {
2062 /* if longer than 10s, don't do any more */
2063 for (j++; j < RSA_NUM; j++)
2069 RAND_pseudo_bytes(buf, 20);
2070 #ifndef OPENSSL_NO_DSA
2071 if (RAND_status() != 1) {
2072 RAND_seed(rnd_seed, sizeof rnd_seed);
2075 for (j = 0; j < DSA_NUM; j++) {
2082 /* DSA_generate_key(dsa_key[j]); */
2083 /* DSA_sign_setup(dsa_key[j],NULL); */
2084 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2087 "DSA sign failure. No DSA sign will be done.\n");
2088 ERR_print_errors(bio_err);
2091 pkey_print_message("sign", "dsa",
2092 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2094 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2095 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2097 BIO_printf(bio_err, "DSA sign failure\n");
2098 ERR_print_errors(bio_err);
2105 mr ? "+R3:%ld:%d:%.2f\n"
2106 : "%ld %d bit DSA signs in %.2fs\n",
2107 count, dsa_bits[j], d);
2108 dsa_results[j][0] = d / (double)count;
2112 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2115 "DSA verify failure. No DSA verify will be done.\n");
2116 ERR_print_errors(bio_err);
2119 pkey_print_message("verify", "dsa",
2120 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2122 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2123 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2125 BIO_printf(bio_err, "DSA verify failure\n");
2126 ERR_print_errors(bio_err);
2133 mr ? "+R4:%ld:%d:%.2f\n"
2134 : "%ld %d bit DSA verify in %.2fs\n",
2135 count, dsa_bits[j], d);
2136 dsa_results[j][1] = d / (double)count;
2139 if (rsa_count <= 1) {
2140 /* if longer than 10s, don't do any more */
2141 for (j++; j < DSA_NUM; j++)
2149 #ifndef OPENSSL_NO_ECDSA
2150 if (RAND_status() != 1) {
2151 RAND_seed(rnd_seed, sizeof rnd_seed);
2154 for (j = 0; j < EC_NUM; j++) {
2158 continue; /* Ignore Curve */
2159 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2160 if (ecdsa[j] == NULL) {
2161 BIO_printf(bio_err, "ECDSA failure.\n");
2162 ERR_print_errors(bio_err);
2166 EC_KEY_precompute_mult(ecdsa[j], NULL);
2168 /* Perform ECDSA signature test */
2169 EC_KEY_generate_key(ecdsa[j]);
2170 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2173 "ECDSA sign failure. No ECDSA sign will be done.\n");
2174 ERR_print_errors(bio_err);
2177 pkey_print_message("sign", "ecdsa",
2179 test_curves_bits[j], ECDSA_SECONDS);
2182 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2183 ret = ECDSA_sign(0, buf, 20,
2184 ecdsasig, &ecdsasiglen, ecdsa[j]);
2186 BIO_printf(bio_err, "ECDSA sign failure\n");
2187 ERR_print_errors(bio_err);
2195 mr ? "+R5:%ld:%d:%.2f\n" :
2196 "%ld %d bit ECDSA signs in %.2fs \n",
2197 count, test_curves_bits[j], d);
2198 ecdsa_results[j][0] = d / (double)count;
2202 /* Perform ECDSA verification test */
2203 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2206 "ECDSA verify failure. No ECDSA verify will be done.\n");
2207 ERR_print_errors(bio_err);
2210 pkey_print_message("verify", "ecdsa",
2212 test_curves_bits[j], ECDSA_SECONDS);
2214 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2216 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2219 BIO_printf(bio_err, "ECDSA verify failure\n");
2220 ERR_print_errors(bio_err);
2227 mr ? "+R6:%ld:%d:%.2f\n"
2228 : "%ld %d bit ECDSA verify in %.2fs\n",
2229 count, test_curves_bits[j], d);
2230 ecdsa_results[j][1] = d / (double)count;
2233 if (rsa_count <= 1) {
2234 /* if longer than 10s, don't do any more */
2235 for (j++; j < EC_NUM; j++)
2244 #ifndef OPENSSL_NO_ECDH
2245 if (RAND_status() != 1) {
2246 RAND_seed(rnd_seed, sizeof rnd_seed);
2249 for (j = 0; j < EC_NUM; j++) {
2252 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2253 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2254 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2255 BIO_printf(bio_err, "ECDH failure.\n");
2256 ERR_print_errors(bio_err);
2259 /* generate two ECDH key pairs */
2260 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2261 !EC_KEY_generate_key(ecdh_b[j])) {
2262 BIO_printf(bio_err, "ECDH key generation failure.\n");
2263 ERR_print_errors(bio_err);
2267 * If field size is not more than 24 octets, then use SHA-1
2268 * hash of result; otherwise, use result (see section 4.8 of
2269 * draft-ietf-tls-ecc-03.txt).
2271 int field_size, outlen;
2272 void *(*kdf) (const void *in, size_t inlen, void *out,
2275 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2276 if (field_size <= 24 * 8) {
2277 outlen = KDF1_SHA1_len;
2280 outlen = (field_size + 7) / 8;
2284 ECDH_compute_key(secret_a, outlen,
2285 EC_KEY_get0_public_key(ecdh_b[j]),
2288 ECDH_compute_key(secret_b, outlen,
2289 EC_KEY_get0_public_key(ecdh_a[j]),
2291 if (secret_size_a != secret_size_b)
2296 for (secret_idx = 0; (secret_idx < secret_size_a)
2297 && (ecdh_checks == 1); secret_idx++) {
2298 if (secret_a[secret_idx] != secret_b[secret_idx])
2302 if (ecdh_checks == 0) {
2303 BIO_printf(bio_err, "ECDH computations don't match.\n");
2304 ERR_print_errors(bio_err);
2308 pkey_print_message("", "ecdh",
2310 test_curves_bits[j], ECDH_SECONDS);
2312 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2313 ECDH_compute_key(secret_a, outlen,
2314 EC_KEY_get0_public_key(ecdh_b[j]),
2319 mr ? "+R7:%ld:%d:%.2f\n" :
2320 "%ld %d-bit ECDH ops in %.2fs\n", count,
2321 test_curves_bits[j], d);
2322 ecdh_results[j][0] = d / (double)count;
2327 if (rsa_count <= 1) {
2328 /* if longer than 10s, don't do any more */
2329 for (j++; j < EC_NUM; j++)
2340 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2341 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2343 printf("%s ", BN_options());
2344 #ifndef OPENSSL_NO_MD2
2345 printf("%s ", MD2_options());
2347 #ifndef OPENSSL_NO_RC4
2348 printf("%s ", RC4_options());
2350 #ifndef OPENSSL_NO_DES
2351 printf("%s ", DES_options());
2353 #ifndef OPENSSL_NO_AES
2354 printf("%s ", AES_options());
2356 #ifndef OPENSSL_NO_IDEA
2357 printf("%s ", idea_options());
2359 #ifndef OPENSSL_NO_BF
2360 printf("%s ", BF_options());
2362 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2367 fprintf(stdout, "+H");
2370 "The 'numbers' are in 1000s of bytes per second processed.\n");
2371 fprintf(stdout, "type ");
2373 for (j = 0; j < SIZE_NUM; j++)
2374 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2375 fprintf(stdout, "\n");
2378 for (k = 0; k < ALGOR_NUM; k++) {
2382 fprintf(stdout, "+F:%d:%s", k, names[k]);
2384 fprintf(stdout, "%-13s", names[k]);
2385 for (j = 0; j < SIZE_NUM; j++) {
2386 if (results[k][j] > 10000 && !mr)
2387 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2389 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2391 fprintf(stdout, "\n");
2393 #ifndef OPENSSL_NO_RSA
2395 for (k = 0; k < RSA_NUM; k++) {
2399 printf("%18ssign verify sign/s verify/s\n", " ");
2403 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2404 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2406 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2407 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2408 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2411 #ifndef OPENSSL_NO_DSA
2413 for (k = 0; k < DSA_NUM; k++) {
2417 printf("%18ssign verify sign/s verify/s\n", " ");
2421 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2422 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2424 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2425 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2426 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2429 #ifndef OPENSSL_NO_ECDSA
2431 for (k = 0; k < EC_NUM; k++) {
2435 printf("%30ssign verify sign/s verify/s\n", " ");
2440 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2441 k, test_curves_bits[k],
2442 ecdsa_results[k][0], ecdsa_results[k][1]);
2445 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2446 test_curves_bits[k],
2447 test_curves_names[k],
2448 ecdsa_results[k][0], ecdsa_results[k][1],
2449 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2453 #ifndef OPENSSL_NO_ECDH
2455 for (k = 0; k < EC_NUM; k++) {
2459 printf("%30sop op/s\n", " ");
2463 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2464 k, test_curves_bits[k],
2465 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2468 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2469 test_curves_bits[k],
2470 test_curves_names[k],
2471 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2478 ERR_print_errors(bio_err);
2479 if (buf_malloc != NULL)
2480 OPENSSL_free(buf_malloc);
2481 if (buf2_malloc != NULL)
2482 OPENSSL_free(buf2_malloc);
2483 #ifndef OPENSSL_NO_RSA
2484 for (i = 0; i < RSA_NUM; i++)
2485 if (rsa_key[i] != NULL)
2486 RSA_free(rsa_key[i]);
2488 #ifndef OPENSSL_NO_DSA
2489 for (i = 0; i < DSA_NUM; i++)
2490 if (dsa_key[i] != NULL)
2491 DSA_free(dsa_key[i]);
2494 #ifndef OPENSSL_NO_ECDSA
2495 for (i = 0; i < EC_NUM; i++)
2496 if (ecdsa[i] != NULL)
2497 EC_KEY_free(ecdsa[i]);
2499 #ifndef OPENSSL_NO_ECDH
2500 for (i = 0; i < EC_NUM; i++) {
2501 if (ecdh_a[i] != NULL)
2502 EC_KEY_free(ecdh_a[i]);
2503 if (ecdh_b[i] != NULL)
2504 EC_KEY_free(ecdh_b[i]);
2512 static void print_message(const char *s, long num, int length)
2516 mr ? "+DT:%s:%d:%d\n"
2517 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2518 (void)BIO_flush(bio_err);
2522 mr ? "+DN:%s:%ld:%d\n"
2523 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2524 (void)BIO_flush(bio_err);
2528 static void pkey_print_message(const char *str, const char *str2, long num,
2533 mr ? "+DTP:%d:%s:%s:%d\n"
2534 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2535 (void)BIO_flush(bio_err);
2539 mr ? "+DNP:%ld:%d:%s:%s\n"
2540 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2541 (void)BIO_flush(bio_err);
2545 static void print_result(int alg, int run_no, int count, double time_used)
2548 mr ? "+R:%d:%s:%f\n"
2549 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2550 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2554 static char *sstrsep(char **string, const char *delim)
2557 char *token = *string;
2562 memset(isdelim, 0, sizeof isdelim);
2566 isdelim[(unsigned char)(*delim)] = 1;
2570 while (!isdelim[(unsigned char)(**string)]) {
2582 static int do_multi(int multi)
2587 static char sep[] = ":";
2589 fds = malloc(multi * sizeof *fds);
2590 for (n = 0; n < multi; ++n) {
2591 if (pipe(fd) == -1) {
2592 fprintf(stderr, "pipe failure\n");
2603 if (dup(fd[1]) == -1) {
2604 fprintf(stderr, "dup failed\n");
2613 printf("Forked child %d\n", n);
2616 /* for now, assume the pipe is long enough to take all the output */
2617 for (n = 0; n < multi; ++n) {
2622 f = fdopen(fds[n], "r");
2623 while (fgets(buf, sizeof buf, f)) {
2624 p = strchr(buf, '\n');
2627 if (buf[0] != '+') {
2628 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2632 printf("Got: %s from %d\n", buf, n);
2633 if (!strncmp(buf, "+F:", 3)) {
2638 alg = atoi(sstrsep(&p, sep));
2640 for (j = 0; j < SIZE_NUM; ++j)
2641 results[alg][j] += atof(sstrsep(&p, sep));
2642 } else if (!strncmp(buf, "+F2:", 4)) {
2647 k = atoi(sstrsep(&p, sep));
2650 d = atof(sstrsep(&p, sep));
2652 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2654 rsa_results[k][0] = d;
2656 d = atof(sstrsep(&p, sep));
2658 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2660 rsa_results[k][1] = d;
2661 } else if (!strncmp(buf, "+F2:", 4)) {
2666 k = atoi(sstrsep(&p, sep));
2669 d = atof(sstrsep(&p, sep));
2671 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2673 rsa_results[k][0] = d;
2675 d = atof(sstrsep(&p, sep));
2677 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2679 rsa_results[k][1] = d;
2681 # ifndef OPENSSL_NO_DSA
2682 else if (!strncmp(buf, "+F3:", 4)) {
2687 k = atoi(sstrsep(&p, sep));
2690 d = atof(sstrsep(&p, sep));
2692 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2694 dsa_results[k][0] = d;
2696 d = atof(sstrsep(&p, sep));
2698 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2700 dsa_results[k][1] = d;
2703 # ifndef OPENSSL_NO_ECDSA
2704 else if (!strncmp(buf, "+F4:", 4)) {
2709 k = atoi(sstrsep(&p, sep));
2712 d = atof(sstrsep(&p, sep));
2714 ecdsa_results[k][0] =
2715 1 / (1 / ecdsa_results[k][0] + 1 / d);
2717 ecdsa_results[k][0] = d;
2719 d = atof(sstrsep(&p, sep));
2721 ecdsa_results[k][1] =
2722 1 / (1 / ecdsa_results[k][1] + 1 / d);
2724 ecdsa_results[k][1] = d;
2728 # ifndef OPENSSL_NO_ECDH
2729 else if (!strncmp(buf, "+F5:", 4)) {
2734 k = atoi(sstrsep(&p, sep));
2737 d = atof(sstrsep(&p, sep));
2739 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2741 ecdh_results[k][0] = d;
2746 else if (!strncmp(buf, "+H:", 3)) {
2748 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2758 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2760 static int mblengths[] =
2761 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2762 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2763 const char *alg_name;
2764 unsigned char *inp, *out, no_key[32], no_iv[16];
2768 inp = OPENSSL_malloc(mblengths[num - 1]);
2769 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2771 EVP_CIPHER_CTX_init(&ctx);
2772 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2773 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2775 alg_name = OBJ_nid2ln(evp_cipher->nid);
2777 for (j = 0; j < num; j++) {
2778 print_message(alg_name, 0, mblengths[j]);
2780 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2781 unsigned char aad[13];
2782 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2783 size_t len = mblengths[j];
2786 memset(aad, 0, 8); /* avoid uninitialized values */
2787 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2788 aad[9] = 3; /* version */
2790 aad[11] = 0; /* length */
2792 mb_param.out = NULL;
2795 mb_param.interleave = 8;
2797 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2798 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2799 sizeof(mb_param), &mb_param);
2805 EVP_CIPHER_CTX_ctrl(&ctx,
2806 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2807 sizeof(mb_param), &mb_param);
2811 RAND_bytes(out, 16);
2815 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2816 EVP_CTRL_AEAD_TLS1_AAD, 13, aad);
2817 EVP_Cipher(&ctx, out, inp, len + pad);
2822 mr ? "+R:%d:%s:%f\n"
2823 : "%d %s's in %.2fs\n", count, "evp", d);
2824 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2828 fprintf(stdout, "+H");
2829 for (j = 0; j < num; j++)
2830 fprintf(stdout, ":%d", mblengths[j]);
2831 fprintf(stdout, "\n");
2832 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2833 for (j = 0; j < num; j++)
2834 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2835 fprintf(stdout, "\n");
2838 "The 'numbers' are in 1000s of bytes per second processed.\n");
2839 fprintf(stdout, "type ");
2840 for (j = 0; j < num; j++)
2841 fprintf(stdout, "%7d bytes", mblengths[j]);
2842 fprintf(stdout, "\n");
2843 fprintf(stdout, "%-24s", alg_name);
2845 for (j = 0; j < num; j++) {
2846 if (results[D_EVP][j] > 10000)
2847 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2849 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2851 fprintf(stdout, "\n");