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_EC
176 # include <openssl/ecdsa.h>
177 # include <openssl/ecdh.h>
179 #include <openssl/modes.h>
181 #include <openssl/bn.h>
184 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
198 #define BUFSIZE (1024*8+1)
199 #define MAX_MISALIGNMENT 63
201 static volatile int run = 0;
204 static int usertime = 1;
206 static double Time_F(int s);
207 static void print_message(const char *s, long num, int length);
208 static void pkey_print_message(const char *str, const char *str2,
209 long num, int bits, int sec);
210 static void print_result(int alg, int run_no, int count, double time_used);
212 static int do_multi(int multi);
222 #define MAX_ECDH_SIZE 256
224 static const char *names[ALGOR_NUM] = {
225 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
226 "des cbc", "des ede3", "idea cbc", "seed cbc",
227 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
228 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
229 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
230 "evp", "sha256", "sha512", "whirlpool",
231 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
234 static double results[ALGOR_NUM][SIZE_NUM];
235 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
237 #ifndef OPENSSL_NO_RSA
238 static double rsa_results[RSA_NUM][2];
240 #ifndef OPENSSL_NO_DSA
241 static double dsa_results[DSA_NUM][2];
243 #ifndef OPENSSL_NO_EC
244 static double ecdsa_results[EC_NUM][2];
245 static double ecdh_results[EC_NUM][1];
248 #if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
249 static const char rnd_seed[] =
250 "string to make the random number generator think it has entropy";
251 static int rnd_fake = 0;
255 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
256 # define SIGRETTYPE void
258 # define SIGRETTYPE int
261 static SIGRETTYPE sig_done(int sig);
262 static SIGRETTYPE sig_done(int sig)
264 signal(SIGALRM, sig_done);
274 # if !defined(SIGALRM)
277 static unsigned int lapse, schlock;
278 static void alarm_win32(unsigned int secs)
283 # define alarm alarm_win32
285 static DWORD WINAPI sleepy(VOID * arg)
293 static double Time_F(int s)
300 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
302 DWORD ret = GetLastError();
303 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
307 Sleep(0); /* scheduler spinlock */
308 ret = app_tminterval(s, usertime);
310 ret = app_tminterval(s, usertime);
312 TerminateThread(thr, 0);
320 static double Time_F(int s)
322 double ret = app_tminterval(s, usertime);
329 #ifndef OPENSSL_NO_EC
330 static const int KDF1_SHA1_len = 20;
331 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
334 if (*outlen < SHA_DIGEST_LENGTH)
336 *outlen = SHA_DIGEST_LENGTH;
337 return SHA1(in, inlen, out);
339 #endif /* OPENSSL_NO_EC */
341 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
343 int MAIN(int, char **);
345 int MAIN(int argc, char **argv)
347 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
348 unsigned char *buf = NULL, *buf2 = NULL;
350 long count = 0, save_count = 0;
352 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
355 #ifndef OPENSSL_NO_RSA
358 unsigned char md[EVP_MAX_MD_SIZE];
359 #ifndef OPENSSL_NO_MD2
360 unsigned char md2[MD2_DIGEST_LENGTH];
362 #ifndef OPENSSL_NO_MDC2
363 unsigned char mdc2[MDC2_DIGEST_LENGTH];
365 #ifndef OPENSSL_NO_MD4
366 unsigned char md4[MD4_DIGEST_LENGTH];
368 #ifndef OPENSSL_NO_MD5
369 unsigned char md5[MD5_DIGEST_LENGTH];
370 unsigned char hmac[MD5_DIGEST_LENGTH];
372 unsigned char sha[SHA_DIGEST_LENGTH];
373 unsigned char sha256[SHA256_DIGEST_LENGTH];
374 unsigned char sha512[SHA512_DIGEST_LENGTH];
375 #ifndef OPENSSL_NO_WHIRLPOOL
376 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
378 #ifndef OPENSSL_NO_RMD160
379 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
381 #ifndef OPENSSL_NO_RC4
384 #ifndef OPENSSL_NO_RC5
387 #ifndef OPENSSL_NO_RC2
390 #ifndef OPENSSL_NO_IDEA
391 IDEA_KEY_SCHEDULE idea_ks;
393 #ifndef OPENSSL_NO_SEED
394 SEED_KEY_SCHEDULE seed_ks;
396 #ifndef OPENSSL_NO_BF
399 #ifndef OPENSSL_NO_CAST
402 static const unsigned char key16[16] = {
403 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
404 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
406 #ifndef OPENSSL_NO_AES
407 static const unsigned char key24[24] = {
408 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
409 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
410 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
412 static const unsigned char key32[32] = {
413 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
414 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
415 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
416 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
419 #ifndef OPENSSL_NO_CAMELLIA
420 static const unsigned char ckey24[24] = {
421 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
422 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
423 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
425 static const unsigned char ckey32[32] = {
426 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
427 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
428 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
429 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
432 #ifndef OPENSSL_NO_AES
433 # define MAX_BLOCK_SIZE 128
435 # define MAX_BLOCK_SIZE 64
437 unsigned char DES_iv[8];
438 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
439 #ifndef OPENSSL_NO_DES
440 static DES_cblock key =
441 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
442 static DES_cblock key2 =
443 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
444 static DES_cblock key3 =
445 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
446 DES_key_schedule sch;
447 DES_key_schedule sch2;
448 DES_key_schedule sch3;
450 #ifndef OPENSSL_NO_AES
451 AES_KEY aes_ks1, aes_ks2, aes_ks3;
453 #ifndef OPENSSL_NO_CAMELLIA
454 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
466 #define D_CBC_IDEA 10
467 #define D_CBC_SEED 11
471 #define D_CBC_CAST 15
472 #define D_CBC_128_AES 16
473 #define D_CBC_192_AES 17
474 #define D_CBC_256_AES 18
475 #define D_CBC_128_CML 19
476 #define D_CBC_192_CML 20
477 #define D_CBC_256_CML 21
481 #define D_WHIRLPOOL 25
482 #define D_IGE_128_AES 26
483 #define D_IGE_192_AES 27
484 #define D_IGE_256_AES 28
487 long c[ALGOR_NUM][SIZE_NUM];
489 #ifndef OPENSSL_SYS_WIN32
500 #define R_RSA_15360 6
519 #ifndef OPENSSL_NO_RSA
520 RSA *rsa_key[RSA_NUM];
521 long rsa_c[RSA_NUM][2];
522 static unsigned int rsa_bits[RSA_NUM] = {
523 512, 1024, 2048, 3072, 4096, 7680, 15360
525 static unsigned char *rsa_data[RSA_NUM] = {
526 test512, test1024, test2048, test3072, test4096, test7680, test15360
528 static int rsa_data_length[RSA_NUM] = {
529 sizeof(test512), sizeof(test1024),
530 sizeof(test2048), sizeof(test3072),
531 sizeof(test4096), sizeof(test7680),
535 #ifndef OPENSSL_NO_DSA
536 DSA *dsa_key[DSA_NUM];
537 long dsa_c[DSA_NUM][2];
538 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
540 #ifndef OPENSSL_NO_EC
542 * We only test over the following curves as they are representative, To
543 * add tests over more curves, simply add the curve NID and curve name to
544 * the following arrays and increase the EC_NUM value accordingly.
546 static unsigned int test_curves[EC_NUM] = {
549 NID_X9_62_prime192v1,
551 NID_X9_62_prime256v1,
566 static const char *test_curves_names[EC_NUM] = {
586 static int test_curves_bits[EC_NUM] = {
587 160, 192, 224, 256, 384, 521,
588 163, 233, 283, 409, 571,
589 163, 233, 283, 409, 571
594 #ifndef OPENSSL_NO_EC
595 unsigned char ecdsasig[256];
596 unsigned int ecdsasiglen;
597 EC_KEY *ecdsa[EC_NUM];
598 long ecdsa_c[EC_NUM][2];
599 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
600 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
601 int secret_size_a, secret_size_b;
604 long ecdh_c[EC_NUM][2];
605 int ecdsa_doit[EC_NUM];
606 int ecdh_doit[EC_NUM];
609 int rsa_doit[RSA_NUM];
610 int dsa_doit[DSA_NUM];
613 const EVP_CIPHER *evp_cipher = NULL;
614 const EVP_MD *evp_md = NULL;
620 int misalign = MAX_MISALIGNMENT + 1;
627 memset(results, 0, sizeof(results));
628 #ifndef OPENSSL_NO_DSA
629 memset(dsa_key, 0, sizeof(dsa_key));
631 #ifndef OPENSSL_NO_EC
632 for (i = 0; i < EC_NUM; i++)
634 for (i = 0; i < EC_NUM; i++) {
641 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
642 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
644 if (!load_config(bio_err, NULL))
647 #ifndef OPENSSL_NO_RSA
648 memset(rsa_key, 0, sizeof(rsa_key));
649 for (i = 0; i < RSA_NUM; i++)
654 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
655 BIO_printf(bio_err, "out of memory\n");
659 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
660 BIO_printf(bio_err, "out of memory\n");
664 misalign = 0; /* set later and buf/buf2 are adjusted
669 memset(c, 0, sizeof(c));
670 memset(DES_iv, 0, sizeof(DES_iv));
671 memset(iv, 0, sizeof(iv));
673 for (i = 0; i < ALGOR_NUM; i++)
675 for (i = 0; i < RSA_NUM; i++)
677 for (i = 0; i < DSA_NUM; i++)
679 #ifndef OPENSSL_NO_EC
680 for (i = 0; i < EC_NUM; i++)
682 for (i = 0; i < EC_NUM; i++)
690 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
692 j--; /* Otherwise, -elapsed gets confused with an
694 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
698 BIO_printf(bio_err, "no EVP given\n");
701 evp_cipher = EVP_get_cipherbyname(*argv);
703 evp_md = EVP_get_digestbyname(*argv);
705 if (!evp_cipher && !evp_md) {
706 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
711 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
713 j--; /* Otherwise, -elapsed gets confused with an
716 #ifndef OPENSSL_NO_ENGINE
717 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
721 BIO_printf(bio_err, "no engine given\n");
724 setup_engine(bio_err, *argv, 0);
726 * j will be increased again further down. We just don't want
727 * speed to confuse an engine with an algorithm, especially when
728 * none is given (which means all of them should be run)
734 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
738 BIO_printf(bio_err, "no multi count given\n");
741 multi = atoi(argv[0]);
743 BIO_printf(bio_err, "bad multi count\n");
746 j--; /* Otherwise, -mr gets confused with an
750 else if (argc > 0 && !strcmp(*argv, "-mr")) {
752 j--; /* Otherwise, -mr gets confused with an
754 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
757 } else if (argc > 0 && !strcmp(*argv, "-misalign")) {
761 BIO_printf(bio_err, "no misalignment given\n");
764 misalign = atoi(argv[0]);
765 if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
767 "misalignment is outsize permitted range 0-%d\n",
771 buf = buf_malloc + misalign;
772 buf2 = buf2_malloc + misalign;
775 #ifndef OPENSSL_NO_MD2
776 if (strcmp(*argv, "md2") == 0)
780 #ifndef OPENSSL_NO_MDC2
781 if (strcmp(*argv, "mdc2") == 0)
785 #ifndef OPENSSL_NO_MD4
786 if (strcmp(*argv, "md4") == 0)
790 #ifndef OPENSSL_NO_MD5
791 if (strcmp(*argv, "md5") == 0)
795 #ifndef OPENSSL_NO_MD5
796 if (strcmp(*argv, "hmac") == 0)
800 if (strcmp(*argv, "sha1") == 0)
802 else if (strcmp(*argv, "sha") == 0)
803 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
804 else if (strcmp(*argv, "sha256") == 0)
806 else if (strcmp(*argv, "sha512") == 0)
809 #ifndef OPENSSL_NO_WHIRLPOOL
810 if (strcmp(*argv, "whirlpool") == 0)
811 doit[D_WHIRLPOOL] = 1;
814 #ifndef OPENSSL_NO_RMD160
815 if (strcmp(*argv, "ripemd") == 0)
817 else if (strcmp(*argv, "rmd160") == 0)
819 else if (strcmp(*argv, "ripemd160") == 0)
823 #ifndef OPENSSL_NO_RC4
824 if (strcmp(*argv, "rc4") == 0)
828 #ifndef OPENSSL_NO_DES
829 if (strcmp(*argv, "des-cbc") == 0)
831 else if (strcmp(*argv, "des-ede3") == 0)
832 doit[D_EDE3_DES] = 1;
835 #ifndef OPENSSL_NO_AES
836 if (strcmp(*argv, "aes-128-cbc") == 0)
837 doit[D_CBC_128_AES] = 1;
838 else if (strcmp(*argv, "aes-192-cbc") == 0)
839 doit[D_CBC_192_AES] = 1;
840 else if (strcmp(*argv, "aes-256-cbc") == 0)
841 doit[D_CBC_256_AES] = 1;
842 else if (strcmp(*argv, "aes-128-ige") == 0)
843 doit[D_IGE_128_AES] = 1;
844 else if (strcmp(*argv, "aes-192-ige") == 0)
845 doit[D_IGE_192_AES] = 1;
846 else if (strcmp(*argv, "aes-256-ige") == 0)
847 doit[D_IGE_256_AES] = 1;
850 #ifndef OPENSSL_NO_CAMELLIA
851 if (strcmp(*argv, "camellia-128-cbc") == 0)
852 doit[D_CBC_128_CML] = 1;
853 else if (strcmp(*argv, "camellia-192-cbc") == 0)
854 doit[D_CBC_192_CML] = 1;
855 else if (strcmp(*argv, "camellia-256-cbc") == 0)
856 doit[D_CBC_256_CML] = 1;
859 #ifndef OPENSSL_NO_RSA
861 if (strcmp(*argv, "openssl") == 0) {
862 RSA_set_default_method(RSA_PKCS1_SSLeay());
866 #endif /* !OPENSSL_NO_RSA */
867 if (strcmp(*argv, "dsa512") == 0)
868 dsa_doit[R_DSA_512] = 2;
869 else if (strcmp(*argv, "dsa1024") == 0)
870 dsa_doit[R_DSA_1024] = 2;
871 else if (strcmp(*argv, "dsa2048") == 0)
872 dsa_doit[R_DSA_2048] = 2;
873 else if (strcmp(*argv, "rsa512") == 0)
874 rsa_doit[R_RSA_512] = 2;
875 else if (strcmp(*argv, "rsa1024") == 0)
876 rsa_doit[R_RSA_1024] = 2;
877 else if (strcmp(*argv, "rsa2048") == 0)
878 rsa_doit[R_RSA_2048] = 2;
879 else if (strcmp(*argv, "rsa3072") == 0)
880 rsa_doit[R_RSA_3072] = 2;
881 else if (strcmp(*argv, "rsa4096") == 0)
882 rsa_doit[R_RSA_4096] = 2;
883 else if (strcmp(*argv, "rsa7680") == 0)
884 rsa_doit[R_RSA_7680] = 2;
885 else if (strcmp(*argv, "rsa15360") == 0)
886 rsa_doit[R_RSA_15360] = 2;
888 #ifndef OPENSSL_NO_RC2
889 if (strcmp(*argv, "rc2-cbc") == 0)
891 else if (strcmp(*argv, "rc2") == 0)
895 #ifndef OPENSSL_NO_RC5
896 if (strcmp(*argv, "rc5-cbc") == 0)
898 else if (strcmp(*argv, "rc5") == 0)
902 #ifndef OPENSSL_NO_IDEA
903 if (strcmp(*argv, "idea-cbc") == 0)
904 doit[D_CBC_IDEA] = 1;
905 else if (strcmp(*argv, "idea") == 0)
906 doit[D_CBC_IDEA] = 1;
909 #ifndef OPENSSL_NO_SEED
910 if (strcmp(*argv, "seed-cbc") == 0)
911 doit[D_CBC_SEED] = 1;
912 else if (strcmp(*argv, "seed") == 0)
913 doit[D_CBC_SEED] = 1;
916 #ifndef OPENSSL_NO_BF
917 if (strcmp(*argv, "bf-cbc") == 0)
919 else if (strcmp(*argv, "blowfish") == 0)
921 else if (strcmp(*argv, "bf") == 0)
925 #ifndef OPENSSL_NO_CAST
926 if (strcmp(*argv, "cast-cbc") == 0)
927 doit[D_CBC_CAST] = 1;
928 else if (strcmp(*argv, "cast") == 0)
929 doit[D_CBC_CAST] = 1;
930 else if (strcmp(*argv, "cast5") == 0)
931 doit[D_CBC_CAST] = 1;
934 #ifndef OPENSSL_NO_DES
935 if (strcmp(*argv, "des") == 0) {
937 doit[D_EDE3_DES] = 1;
940 #ifndef OPENSSL_NO_AES
941 if (strcmp(*argv, "aes") == 0) {
942 doit[D_CBC_128_AES] = 1;
943 doit[D_CBC_192_AES] = 1;
944 doit[D_CBC_256_AES] = 1;
945 } else if (strcmp(*argv, "ghash") == 0) {
949 #ifndef OPENSSL_NO_CAMELLIA
950 if (strcmp(*argv, "camellia") == 0) {
951 doit[D_CBC_128_CML] = 1;
952 doit[D_CBC_192_CML] = 1;
953 doit[D_CBC_256_CML] = 1;
956 #ifndef OPENSSL_NO_RSA
957 if (strcmp(*argv, "rsa") == 0) {
958 rsa_doit[R_RSA_512] = 1;
959 rsa_doit[R_RSA_1024] = 1;
960 rsa_doit[R_RSA_2048] = 1;
961 rsa_doit[R_RSA_3072] = 1;
962 rsa_doit[R_RSA_4096] = 1;
963 rsa_doit[R_RSA_7680] = 1;
964 rsa_doit[R_RSA_15360] = 1;
967 #ifndef OPENSSL_NO_DSA
968 if (strcmp(*argv, "dsa") == 0) {
969 dsa_doit[R_DSA_512] = 1;
970 dsa_doit[R_DSA_1024] = 1;
971 dsa_doit[R_DSA_2048] = 1;
974 #ifndef OPENSSL_NO_EC
975 if (strcmp(*argv, "ecdsap160") == 0)
976 ecdsa_doit[R_EC_P160] = 2;
977 else if (strcmp(*argv, "ecdsap192") == 0)
978 ecdsa_doit[R_EC_P192] = 2;
979 else if (strcmp(*argv, "ecdsap224") == 0)
980 ecdsa_doit[R_EC_P224] = 2;
981 else if (strcmp(*argv, "ecdsap256") == 0)
982 ecdsa_doit[R_EC_P256] = 2;
983 else if (strcmp(*argv, "ecdsap384") == 0)
984 ecdsa_doit[R_EC_P384] = 2;
985 else if (strcmp(*argv, "ecdsap521") == 0)
986 ecdsa_doit[R_EC_P521] = 2;
987 else if (strcmp(*argv, "ecdsak163") == 0)
988 ecdsa_doit[R_EC_K163] = 2;
989 else if (strcmp(*argv, "ecdsak233") == 0)
990 ecdsa_doit[R_EC_K233] = 2;
991 else if (strcmp(*argv, "ecdsak283") == 0)
992 ecdsa_doit[R_EC_K283] = 2;
993 else if (strcmp(*argv, "ecdsak409") == 0)
994 ecdsa_doit[R_EC_K409] = 2;
995 else if (strcmp(*argv, "ecdsak571") == 0)
996 ecdsa_doit[R_EC_K571] = 2;
997 else if (strcmp(*argv, "ecdsab163") == 0)
998 ecdsa_doit[R_EC_B163] = 2;
999 else if (strcmp(*argv, "ecdsab233") == 0)
1000 ecdsa_doit[R_EC_B233] = 2;
1001 else if (strcmp(*argv, "ecdsab283") == 0)
1002 ecdsa_doit[R_EC_B283] = 2;
1003 else if (strcmp(*argv, "ecdsab409") == 0)
1004 ecdsa_doit[R_EC_B409] = 2;
1005 else if (strcmp(*argv, "ecdsab571") == 0)
1006 ecdsa_doit[R_EC_B571] = 2;
1007 else if (strcmp(*argv, "ecdsa") == 0) {
1008 for (i = 0; i < EC_NUM; i++)
1010 } else if (strcmp(*argv, "ecdhp160") == 0)
1011 ecdh_doit[R_EC_P160] = 2;
1012 else if (strcmp(*argv, "ecdhp192") == 0)
1013 ecdh_doit[R_EC_P192] = 2;
1014 else if (strcmp(*argv, "ecdhp224") == 0)
1015 ecdh_doit[R_EC_P224] = 2;
1016 else if (strcmp(*argv, "ecdhp256") == 0)
1017 ecdh_doit[R_EC_P256] = 2;
1018 else if (strcmp(*argv, "ecdhp384") == 0)
1019 ecdh_doit[R_EC_P384] = 2;
1020 else if (strcmp(*argv, "ecdhp521") == 0)
1021 ecdh_doit[R_EC_P521] = 2;
1022 else if (strcmp(*argv, "ecdhk163") == 0)
1023 ecdh_doit[R_EC_K163] = 2;
1024 else if (strcmp(*argv, "ecdhk233") == 0)
1025 ecdh_doit[R_EC_K233] = 2;
1026 else if (strcmp(*argv, "ecdhk283") == 0)
1027 ecdh_doit[R_EC_K283] = 2;
1028 else if (strcmp(*argv, "ecdhk409") == 0)
1029 ecdh_doit[R_EC_K409] = 2;
1030 else if (strcmp(*argv, "ecdhk571") == 0)
1031 ecdh_doit[R_EC_K571] = 2;
1032 else if (strcmp(*argv, "ecdhb163") == 0)
1033 ecdh_doit[R_EC_B163] = 2;
1034 else if (strcmp(*argv, "ecdhb233") == 0)
1035 ecdh_doit[R_EC_B233] = 2;
1036 else if (strcmp(*argv, "ecdhb283") == 0)
1037 ecdh_doit[R_EC_B283] = 2;
1038 else if (strcmp(*argv, "ecdhb409") == 0)
1039 ecdh_doit[R_EC_B409] = 2;
1040 else if (strcmp(*argv, "ecdhb571") == 0)
1041 ecdh_doit[R_EC_B571] = 2;
1042 else if (strcmp(*argv, "ecdh") == 0) {
1043 for (i = 0; i < EC_NUM; i++)
1048 BIO_printf(bio_err, "Error: bad option or value\n");
1049 BIO_printf(bio_err, "\n");
1050 BIO_printf(bio_err, "Available values:\n");
1051 #ifndef OPENSSL_NO_MD2
1052 BIO_printf(bio_err, "md2 ");
1054 #ifndef OPENSSL_NO_MDC2
1055 BIO_printf(bio_err, "mdc2 ");
1057 #ifndef OPENSSL_NO_MD4
1058 BIO_printf(bio_err, "md4 ");
1060 #ifndef OPENSSL_NO_MD5
1061 BIO_printf(bio_err, "md5 ");
1062 BIO_printf(bio_err, "hmac ");
1064 BIO_printf(bio_err, "sha1 ");
1065 BIO_printf(bio_err, "sha256 ");
1066 BIO_printf(bio_err, "sha512 ");
1067 #ifndef OPENSSL_NO_WHIRLPOOL
1068 BIO_printf(bio_err, "whirlpool");
1070 #ifndef OPENSSL_NO_RMD160
1071 BIO_printf(bio_err, "rmd160");
1073 BIO_printf(bio_err, "\n");
1075 #ifndef OPENSSL_NO_IDEA
1076 BIO_printf(bio_err, "idea-cbc ");
1078 #ifndef OPENSSL_NO_SEED
1079 BIO_printf(bio_err, "seed-cbc ");
1081 #ifndef OPENSSL_NO_RC2
1082 BIO_printf(bio_err, "rc2-cbc ");
1084 #ifndef OPENSSL_NO_RC5
1085 BIO_printf(bio_err, "rc5-cbc ");
1087 #ifndef OPENSSL_NO_BF
1088 BIO_printf(bio_err, "bf-cbc");
1090 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1091 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1092 BIO_printf(bio_err, "\n");
1094 #ifndef OPENSSL_NO_DES
1095 BIO_printf(bio_err, "des-cbc des-ede3 ");
1097 #ifndef OPENSSL_NO_AES
1098 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1099 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1101 #ifndef OPENSSL_NO_CAMELLIA
1102 BIO_printf(bio_err, "\n");
1104 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1106 #ifndef OPENSSL_NO_RC4
1107 BIO_printf(bio_err, "rc4");
1109 BIO_printf(bio_err, "\n");
1111 #ifndef OPENSSL_NO_RSA
1113 "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1114 BIO_printf(bio_err, "rsa7680 rsa15360\n");
1117 #ifndef OPENSSL_NO_DSA
1118 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1120 #ifndef OPENSSL_NO_EC
1121 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1122 "ecdsap256 ecdsap384 ecdsap521\n");
1124 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1126 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1127 BIO_printf(bio_err, "ecdsa\n");
1128 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1129 "ecdhp256 ecdhp384 ecdhp521\n");
1131 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1133 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1134 BIO_printf(bio_err, "ecdh\n");
1137 #ifndef OPENSSL_NO_IDEA
1138 BIO_printf(bio_err, "idea ");
1140 #ifndef OPENSSL_NO_SEED
1141 BIO_printf(bio_err, "seed ");
1143 #ifndef OPENSSL_NO_RC2
1144 BIO_printf(bio_err, "rc2 ");
1146 #ifndef OPENSSL_NO_DES
1147 BIO_printf(bio_err, "des ");
1149 #ifndef OPENSSL_NO_AES
1150 BIO_printf(bio_err, "aes ");
1152 #ifndef OPENSSL_NO_CAMELLIA
1153 BIO_printf(bio_err, "camellia ");
1155 #ifndef OPENSSL_NO_RSA
1156 BIO_printf(bio_err, "rsa ");
1158 #ifndef OPENSSL_NO_BF
1159 BIO_printf(bio_err, "blowfish");
1161 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1162 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1163 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1164 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1165 BIO_printf(bio_err, "\n");
1168 BIO_printf(bio_err, "\n");
1169 BIO_printf(bio_err, "Available options:\n");
1170 #if defined(TIMES) || defined(USE_TOD)
1171 BIO_printf(bio_err, "-elapsed "
1172 "measure time in real time instead of CPU user time.\n");
1174 #ifndef OPENSSL_NO_ENGINE
1177 "use engine e, possibly a hardware device.\n");
1179 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1182 "time decryption instead of encryption (only EVP).\n");
1185 "produce machine readable output.\n");
1188 "perform multi-block benchmark (for specific ciphers)\n");
1191 "perform benchmark with misaligned data\n");
1194 "-multi n " "run n benchmarks in parallel.\n");
1204 if (multi && do_multi(multi))
1209 for (i = 0; i < ALGOR_NUM; i++) {
1213 for (i = 0; i < RSA_NUM; i++)
1215 for (i = 0; i < DSA_NUM; i++)
1217 #ifndef OPENSSL_NO_EC
1218 for (i = 0; i < EC_NUM; i++)
1220 for (i = 0; i < EC_NUM; i++)
1224 for (i = 0; i < ALGOR_NUM; i++)
1228 if (usertime == 0 && !mr)
1230 "You have chosen to measure elapsed time "
1231 "instead of user CPU time.\n");
1233 #ifndef OPENSSL_NO_RSA
1234 for (i = 0; i < RSA_NUM; i++) {
1235 const unsigned char *p;
1238 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1239 if (rsa_key[i] == NULL) {
1240 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1247 #ifndef OPENSSL_NO_DSA
1248 dsa_key[0] = get_dsa512();
1249 dsa_key[1] = get_dsa1024();
1250 dsa_key[2] = get_dsa2048();
1253 #ifndef OPENSSL_NO_DES
1254 DES_set_key_unchecked(&key, &sch);
1255 DES_set_key_unchecked(&key2, &sch2);
1256 DES_set_key_unchecked(&key3, &sch3);
1258 #ifndef OPENSSL_NO_AES
1259 AES_set_encrypt_key(key16, 128, &aes_ks1);
1260 AES_set_encrypt_key(key24, 192, &aes_ks2);
1261 AES_set_encrypt_key(key32, 256, &aes_ks3);
1263 #ifndef OPENSSL_NO_CAMELLIA
1264 Camellia_set_key(key16, 128, &camellia_ks1);
1265 Camellia_set_key(ckey24, 192, &camellia_ks2);
1266 Camellia_set_key(ckey32, 256, &camellia_ks3);
1268 #ifndef OPENSSL_NO_IDEA
1269 idea_set_encrypt_key(key16, &idea_ks);
1271 #ifndef OPENSSL_NO_SEED
1272 SEED_set_key(key16, &seed_ks);
1274 #ifndef OPENSSL_NO_RC4
1275 RC4_set_key(&rc4_ks, 16, key16);
1277 #ifndef OPENSSL_NO_RC2
1278 RC2_set_key(&rc2_ks, 16, key16, 128);
1280 #ifndef OPENSSL_NO_RC5
1281 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1283 #ifndef OPENSSL_NO_BF
1284 BF_set_key(&bf_ks, 16, key16);
1286 #ifndef OPENSSL_NO_CAST
1287 CAST_set_key(&cast_ks, 16, key16);
1289 #ifndef OPENSSL_NO_RSA
1290 memset(rsa_c, 0, sizeof(rsa_c));
1293 # ifndef OPENSSL_NO_DES
1294 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1300 for (it = count; it; it--)
1301 DES_ecb_encrypt((DES_cblock *)buf,
1302 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1306 c[D_MD2][0] = count / 10;
1307 c[D_MDC2][0] = count / 10;
1308 c[D_MD4][0] = count;
1309 c[D_MD5][0] = count;
1310 c[D_HMAC][0] = count;
1311 c[D_SHA1][0] = count;
1312 c[D_RMD160][0] = count;
1313 c[D_RC4][0] = count * 5;
1314 c[D_CBC_DES][0] = count;
1315 c[D_EDE3_DES][0] = count / 3;
1316 c[D_CBC_IDEA][0] = count;
1317 c[D_CBC_SEED][0] = count;
1318 c[D_CBC_RC2][0] = count;
1319 c[D_CBC_RC5][0] = count;
1320 c[D_CBC_BF][0] = count;
1321 c[D_CBC_CAST][0] = count;
1322 c[D_CBC_128_AES][0] = count;
1323 c[D_CBC_192_AES][0] = count;
1324 c[D_CBC_256_AES][0] = count;
1325 c[D_CBC_128_CML][0] = count;
1326 c[D_CBC_192_CML][0] = count;
1327 c[D_CBC_256_CML][0] = count;
1328 c[D_SHA256][0] = count;
1329 c[D_SHA512][0] = count;
1330 c[D_WHIRLPOOL][0] = count;
1331 c[D_IGE_128_AES][0] = count;
1332 c[D_IGE_192_AES][0] = count;
1333 c[D_IGE_256_AES][0] = count;
1334 c[D_GHASH][0] = count;
1336 for (i = 1; i < SIZE_NUM; i++) {
1339 l0 = (long)lengths[0];
1340 l1 = (long)lengths[i];
1342 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1343 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1344 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1345 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1346 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1347 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1348 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1349 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1350 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1351 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1353 l0 = (long)lengths[i - 1];
1355 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1356 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1357 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1358 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1359 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1360 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1361 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1362 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1363 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1364 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1365 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1366 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1367 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1368 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1369 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1370 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1371 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1372 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1375 # ifndef OPENSSL_NO_RSA
1376 rsa_c[R_RSA_512][0] = count / 2000;
1377 rsa_c[R_RSA_512][1] = count / 400;
1378 for (i = 1; i < RSA_NUM; i++) {
1379 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1380 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1381 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1384 if (rsa_c[i][0] == 0) {
1392 # ifndef OPENSSL_NO_DSA
1393 dsa_c[R_DSA_512][0] = count / 1000;
1394 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1395 for (i = 1; i < DSA_NUM; i++) {
1396 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1397 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1398 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1401 if (dsa_c[i] == 0) {
1409 # ifndef OPENSSL_NO_EC
1410 ecdsa_c[R_EC_P160][0] = count / 1000;
1411 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1412 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1413 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1414 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1415 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1418 if (ecdsa_c[i] == 0) {
1424 ecdsa_c[R_EC_K163][0] = count / 1000;
1425 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1426 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1427 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1428 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1429 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1432 if (ecdsa_c[i] == 0) {
1438 ecdsa_c[R_EC_B163][0] = count / 1000;
1439 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1440 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1441 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1442 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1443 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1446 if (ecdsa_c[i] == 0) {
1452 ecdh_c[R_EC_P160][0] = count / 1000;
1453 ecdh_c[R_EC_P160][1] = count / 1000;
1454 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1455 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1456 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1457 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1460 if (ecdh_c[i] == 0) {
1466 ecdh_c[R_EC_K163][0] = count / 1000;
1467 ecdh_c[R_EC_K163][1] = count / 1000;
1468 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1469 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1470 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1471 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1474 if (ecdh_c[i] == 0) {
1480 ecdh_c[R_EC_B163][0] = count / 1000;
1481 ecdh_c[R_EC_B163][1] = count / 1000;
1482 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1483 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1484 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1485 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1488 if (ecdh_c[i] == 0) {
1496 # define COND(d) (count < (d))
1497 # define COUNT(d) (d)
1499 /* not worth fixing */
1500 # error "You cannot disable DES on systems without SIGALRM."
1501 # endif /* OPENSSL_NO_DES */
1503 # define COND(c) (run && count<0x7fffffff)
1504 # define COUNT(d) (count)
1506 signal(SIGALRM, sig_done);
1508 #endif /* SIGALRM */
1510 #ifndef OPENSSL_NO_MD2
1512 for (j = 0; j < SIZE_NUM; j++) {
1513 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1515 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1516 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1519 print_result(D_MD2, j, count, d);
1523 #ifndef OPENSSL_NO_MDC2
1525 for (j = 0; j < SIZE_NUM; j++) {
1526 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1528 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1529 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1532 print_result(D_MDC2, j, count, d);
1537 #ifndef OPENSSL_NO_MD4
1539 for (j = 0; j < SIZE_NUM; j++) {
1540 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1542 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1543 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1544 NULL, EVP_md4(), NULL);
1546 print_result(D_MD4, j, count, d);
1551 #ifndef OPENSSL_NO_MD5
1553 for (j = 0; j < SIZE_NUM; j++) {
1554 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1556 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1557 MD5(buf, lengths[j], md5);
1559 print_result(D_MD5, j, count, d);
1564 #if !defined(OPENSSL_NO_MD5)
1568 HMAC_CTX_init(&hctx);
1569 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1570 16, EVP_md5(), NULL);
1572 for (j = 0; j < SIZE_NUM; j++) {
1573 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1575 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1576 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1577 HMAC_Update(&hctx, buf, lengths[j]);
1578 HMAC_Final(&hctx, &(hmac[0]), NULL);
1581 print_result(D_HMAC, j, count, d);
1583 HMAC_CTX_cleanup(&hctx);
1587 for (j = 0; j < SIZE_NUM; j++) {
1588 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1590 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1591 SHA1(buf, lengths[j], sha);
1593 print_result(D_SHA1, j, count, d);
1596 if (doit[D_SHA256]) {
1597 for (j = 0; j < SIZE_NUM; j++) {
1598 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1600 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1601 SHA256(buf, lengths[j], sha256);
1603 print_result(D_SHA256, j, count, d);
1606 if (doit[D_SHA512]) {
1607 for (j = 0; j < SIZE_NUM; j++) {
1608 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1610 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1611 SHA512(buf, lengths[j], sha512);
1613 print_result(D_SHA512, j, count, d);
1617 #ifndef OPENSSL_NO_WHIRLPOOL
1618 if (doit[D_WHIRLPOOL]) {
1619 for (j = 0; j < SIZE_NUM; j++) {
1620 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1622 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1623 WHIRLPOOL(buf, lengths[j], whirlpool);
1625 print_result(D_WHIRLPOOL, j, count, d);
1630 #ifndef OPENSSL_NO_RMD160
1631 if (doit[D_RMD160]) {
1632 for (j = 0; j < SIZE_NUM; j++) {
1633 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1635 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1636 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1637 EVP_ripemd160(), NULL);
1639 print_result(D_RMD160, j, count, d);
1643 #ifndef OPENSSL_NO_RC4
1645 for (j = 0; j < SIZE_NUM; j++) {
1646 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1648 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1649 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1651 print_result(D_RC4, j, count, d);
1655 #ifndef OPENSSL_NO_DES
1656 if (doit[D_CBC_DES]) {
1657 for (j = 0; j < SIZE_NUM; j++) {
1658 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1660 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1661 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1662 &DES_iv, DES_ENCRYPT);
1664 print_result(D_CBC_DES, j, count, d);
1668 if (doit[D_EDE3_DES]) {
1669 for (j = 0; j < SIZE_NUM; j++) {
1670 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1672 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1673 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1675 &DES_iv, DES_ENCRYPT);
1677 print_result(D_EDE3_DES, j, count, d);
1681 #ifndef OPENSSL_NO_AES
1682 if (doit[D_CBC_128_AES]) {
1683 for (j = 0; j < SIZE_NUM; j++) {
1684 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1687 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1688 AES_cbc_encrypt(buf, buf,
1689 (unsigned long)lengths[j], &aes_ks1,
1692 print_result(D_CBC_128_AES, j, count, d);
1695 if (doit[D_CBC_192_AES]) {
1696 for (j = 0; j < SIZE_NUM; j++) {
1697 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1700 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1701 AES_cbc_encrypt(buf, buf,
1702 (unsigned long)lengths[j], &aes_ks2,
1705 print_result(D_CBC_192_AES, j, count, d);
1708 if (doit[D_CBC_256_AES]) {
1709 for (j = 0; j < SIZE_NUM; j++) {
1710 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1713 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1714 AES_cbc_encrypt(buf, buf,
1715 (unsigned long)lengths[j], &aes_ks3,
1718 print_result(D_CBC_256_AES, j, count, d);
1722 if (doit[D_IGE_128_AES]) {
1723 for (j = 0; j < SIZE_NUM; j++) {
1724 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1727 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1728 AES_ige_encrypt(buf, buf2,
1729 (unsigned long)lengths[j], &aes_ks1,
1732 print_result(D_IGE_128_AES, j, count, d);
1735 if (doit[D_IGE_192_AES]) {
1736 for (j = 0; j < SIZE_NUM; j++) {
1737 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1740 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1741 AES_ige_encrypt(buf, buf2,
1742 (unsigned long)lengths[j], &aes_ks2,
1745 print_result(D_IGE_192_AES, j, count, d);
1748 if (doit[D_IGE_256_AES]) {
1749 for (j = 0; j < SIZE_NUM; j++) {
1750 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1753 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1754 AES_ige_encrypt(buf, buf2,
1755 (unsigned long)lengths[j], &aes_ks3,
1758 print_result(D_IGE_256_AES, j, count, d);
1761 if (doit[D_GHASH]) {
1762 GCM128_CONTEXT *ctx =
1763 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1764 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1766 for (j = 0; j < SIZE_NUM; j++) {
1767 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1769 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1770 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1772 print_result(D_GHASH, j, count, d);
1774 CRYPTO_gcm128_release(ctx);
1777 #ifndef OPENSSL_NO_CAMELLIA
1778 if (doit[D_CBC_128_CML]) {
1779 for (j = 0; j < SIZE_NUM; j++) {
1780 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1783 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1784 Camellia_cbc_encrypt(buf, buf,
1785 (unsigned long)lengths[j], &camellia_ks1,
1786 iv, CAMELLIA_ENCRYPT);
1788 print_result(D_CBC_128_CML, j, count, d);
1791 if (doit[D_CBC_192_CML]) {
1792 for (j = 0; j < SIZE_NUM; j++) {
1793 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1796 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1797 Camellia_cbc_encrypt(buf, buf,
1798 (unsigned long)lengths[j], &camellia_ks2,
1799 iv, CAMELLIA_ENCRYPT);
1801 print_result(D_CBC_192_CML, j, count, d);
1804 if (doit[D_CBC_256_CML]) {
1805 for (j = 0; j < SIZE_NUM; j++) {
1806 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1809 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1810 Camellia_cbc_encrypt(buf, buf,
1811 (unsigned long)lengths[j], &camellia_ks3,
1812 iv, CAMELLIA_ENCRYPT);
1814 print_result(D_CBC_256_CML, j, count, d);
1818 #ifndef OPENSSL_NO_IDEA
1819 if (doit[D_CBC_IDEA]) {
1820 for (j = 0; j < SIZE_NUM; j++) {
1821 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1823 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1824 idea_cbc_encrypt(buf, buf,
1825 (unsigned long)lengths[j], &idea_ks,
1828 print_result(D_CBC_IDEA, j, count, d);
1832 #ifndef OPENSSL_NO_SEED
1833 if (doit[D_CBC_SEED]) {
1834 for (j = 0; j < SIZE_NUM; j++) {
1835 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1837 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1838 SEED_cbc_encrypt(buf, buf,
1839 (unsigned long)lengths[j], &seed_ks, iv, 1);
1841 print_result(D_CBC_SEED, j, count, d);
1845 #ifndef OPENSSL_NO_RC2
1846 if (doit[D_CBC_RC2]) {
1847 for (j = 0; j < SIZE_NUM; j++) {
1848 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1850 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1851 RC2_cbc_encrypt(buf, buf,
1852 (unsigned long)lengths[j], &rc2_ks,
1855 print_result(D_CBC_RC2, j, count, d);
1859 #ifndef OPENSSL_NO_RC5
1860 if (doit[D_CBC_RC5]) {
1861 for (j = 0; j < SIZE_NUM; j++) {
1862 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1864 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1865 RC5_32_cbc_encrypt(buf, buf,
1866 (unsigned long)lengths[j], &rc5_ks,
1869 print_result(D_CBC_RC5, j, count, d);
1873 #ifndef OPENSSL_NO_BF
1874 if (doit[D_CBC_BF]) {
1875 for (j = 0; j < SIZE_NUM; j++) {
1876 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1878 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1879 BF_cbc_encrypt(buf, buf,
1880 (unsigned long)lengths[j], &bf_ks,
1883 print_result(D_CBC_BF, j, count, d);
1887 #ifndef OPENSSL_NO_CAST
1888 if (doit[D_CBC_CAST]) {
1889 for (j = 0; j < SIZE_NUM; j++) {
1890 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1892 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1893 CAST_cbc_encrypt(buf, buf,
1894 (unsigned long)lengths[j], &cast_ks,
1897 print_result(D_CBC_CAST, j, count, d);
1903 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1904 if (multiblock && evp_cipher) {
1906 (EVP_CIPHER_flags(evp_cipher) &
1907 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1908 fprintf(stderr, "%s is not multi-block capable\n",
1909 OBJ_nid2ln(evp_cipher->nid));
1912 multiblock_speed(evp_cipher);
1917 for (j = 0; j < SIZE_NUM; j++) {
1922 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1924 * -O3 -fschedule-insns messes up an optimization here!
1925 * names[D_EVP] somehow becomes NULL
1927 print_message(names[D_EVP], save_count, lengths[j]);
1929 EVP_CIPHER_CTX_init(&ctx);
1931 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1933 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1934 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1938 for (count = 0, run = 1;
1939 COND(save_count * 4 * lengths[0] / lengths[j]);
1941 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1943 for (count = 0, run = 1;
1944 COND(save_count * 4 * lengths[0] / lengths[j]);
1946 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1948 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1950 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1952 EVP_CIPHER_CTX_cleanup(&ctx);
1955 names[D_EVP] = OBJ_nid2ln(evp_md->type);
1956 print_message(names[D_EVP], save_count, lengths[j]);
1959 for (count = 0, run = 1;
1960 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1961 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1965 print_result(D_EVP, j, count, d);
1968 #ifndef OPENSSL_SYS_WIN32
1970 RAND_pseudo_bytes(buf, 36);
1971 #ifndef OPENSSL_NO_RSA
1972 for (j = 0; j < RSA_NUM; j++) {
1976 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1979 "RSA sign failure. No RSA sign will be done.\n");
1980 ERR_print_errors(bio_err);
1983 pkey_print_message("private", "rsa",
1984 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
1985 /* RSA_blinding_on(rsa_key[j],NULL); */
1987 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1988 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1989 &rsa_num, rsa_key[j]);
1991 BIO_printf(bio_err, "RSA sign failure\n");
1992 ERR_print_errors(bio_err);
1999 mr ? "+R1:%ld:%d:%.2f\n"
2000 : "%ld %d bit private RSA's in %.2fs\n",
2001 count, rsa_bits[j], d);
2002 rsa_results[j][0] = d / (double)count;
2006 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2009 "RSA verify failure. No RSA verify will be done.\n");
2010 ERR_print_errors(bio_err);
2013 pkey_print_message("public", "rsa",
2014 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2016 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2017 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2018 rsa_num, rsa_key[j]);
2020 BIO_printf(bio_err, "RSA verify failure\n");
2021 ERR_print_errors(bio_err);
2028 mr ? "+R2:%ld:%d:%.2f\n"
2029 : "%ld %d bit public RSA's in %.2fs\n",
2030 count, rsa_bits[j], d);
2031 rsa_results[j][1] = d / (double)count;
2034 if (rsa_count <= 1) {
2035 /* if longer than 10s, don't do any more */
2036 for (j++; j < RSA_NUM; j++)
2042 RAND_pseudo_bytes(buf, 20);
2043 #ifndef OPENSSL_NO_DSA
2044 if (RAND_status() != 1) {
2045 RAND_seed(rnd_seed, sizeof rnd_seed);
2048 for (j = 0; j < DSA_NUM; j++) {
2055 /* DSA_generate_key(dsa_key[j]); */
2056 /* DSA_sign_setup(dsa_key[j],NULL); */
2057 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2060 "DSA sign failure. No DSA sign will be done.\n");
2061 ERR_print_errors(bio_err);
2064 pkey_print_message("sign", "dsa",
2065 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2067 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2068 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2070 BIO_printf(bio_err, "DSA sign failure\n");
2071 ERR_print_errors(bio_err);
2078 mr ? "+R3:%ld:%d:%.2f\n"
2079 : "%ld %d bit DSA signs in %.2fs\n",
2080 count, dsa_bits[j], d);
2081 dsa_results[j][0] = d / (double)count;
2085 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2088 "DSA verify failure. No DSA verify will be done.\n");
2089 ERR_print_errors(bio_err);
2092 pkey_print_message("verify", "dsa",
2093 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2095 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2096 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2098 BIO_printf(bio_err, "DSA verify failure\n");
2099 ERR_print_errors(bio_err);
2106 mr ? "+R4:%ld:%d:%.2f\n"
2107 : "%ld %d bit DSA verify in %.2fs\n",
2108 count, dsa_bits[j], d);
2109 dsa_results[j][1] = d / (double)count;
2112 if (rsa_count <= 1) {
2113 /* if longer than 10s, don't do any more */
2114 for (j++; j < DSA_NUM; j++)
2122 #ifndef OPENSSL_NO_EC
2123 if (RAND_status() != 1) {
2124 RAND_seed(rnd_seed, sizeof rnd_seed);
2127 for (j = 0; j < EC_NUM; j++) {
2131 continue; /* Ignore Curve */
2132 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2133 if (ecdsa[j] == NULL) {
2134 BIO_printf(bio_err, "ECDSA failure.\n");
2135 ERR_print_errors(bio_err);
2138 EC_KEY_precompute_mult(ecdsa[j], NULL);
2140 /* Perform ECDSA signature test */
2141 EC_KEY_generate_key(ecdsa[j]);
2142 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2145 "ECDSA sign failure. No ECDSA sign will be done.\n");
2146 ERR_print_errors(bio_err);
2149 pkey_print_message("sign", "ecdsa",
2151 test_curves_bits[j], ECDSA_SECONDS);
2154 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2155 ret = ECDSA_sign(0, buf, 20,
2156 ecdsasig, &ecdsasiglen, ecdsa[j]);
2158 BIO_printf(bio_err, "ECDSA sign failure\n");
2159 ERR_print_errors(bio_err);
2167 mr ? "+R5:%ld:%d:%.2f\n" :
2168 "%ld %d bit ECDSA signs in %.2fs \n",
2169 count, test_curves_bits[j], d);
2170 ecdsa_results[j][0] = d / (double)count;
2174 /* Perform ECDSA verification test */
2175 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2178 "ECDSA verify failure. No ECDSA verify will be done.\n");
2179 ERR_print_errors(bio_err);
2182 pkey_print_message("verify", "ecdsa",
2184 test_curves_bits[j], ECDSA_SECONDS);
2186 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2188 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2191 BIO_printf(bio_err, "ECDSA verify failure\n");
2192 ERR_print_errors(bio_err);
2199 mr ? "+R6:%ld:%d:%.2f\n"
2200 : "%ld %d bit ECDSA verify in %.2fs\n",
2201 count, test_curves_bits[j], d);
2202 ecdsa_results[j][1] = d / (double)count;
2205 if (rsa_count <= 1) {
2206 /* if longer than 10s, don't do any more */
2207 for (j++; j < EC_NUM; j++)
2214 if (RAND_status() != 1) {
2215 RAND_seed(rnd_seed, sizeof rnd_seed);
2218 for (j = 0; j < EC_NUM; j++) {
2221 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2222 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2223 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2224 BIO_printf(bio_err, "ECDH failure.\n");
2225 ERR_print_errors(bio_err);
2228 /* generate two ECDH key pairs */
2229 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2230 !EC_KEY_generate_key(ecdh_b[j])) {
2231 BIO_printf(bio_err, "ECDH key generation failure.\n");
2232 ERR_print_errors(bio_err);
2236 * If field size is not more than 24 octets, then use SHA-1
2237 * hash of result; otherwise, use result (see section 4.8 of
2238 * draft-ietf-tls-ecc-03.txt).
2240 int field_size, outlen;
2241 void *(*kdf) (const void *in, size_t inlen, void *out,
2244 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2245 if (field_size <= 24 * 8) {
2246 outlen = KDF1_SHA1_len;
2249 outlen = (field_size + 7) / 8;
2253 ECDH_compute_key(secret_a, outlen,
2254 EC_KEY_get0_public_key(ecdh_b[j]),
2257 ECDH_compute_key(secret_b, outlen,
2258 EC_KEY_get0_public_key(ecdh_a[j]),
2260 if (secret_size_a != secret_size_b)
2265 for (secret_idx = 0; (secret_idx < secret_size_a)
2266 && (ecdh_checks == 1); secret_idx++) {
2267 if (secret_a[secret_idx] != secret_b[secret_idx])
2271 if (ecdh_checks == 0) {
2272 BIO_printf(bio_err, "ECDH computations don't match.\n");
2273 ERR_print_errors(bio_err);
2277 pkey_print_message("", "ecdh",
2279 test_curves_bits[j], ECDH_SECONDS);
2281 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2282 ECDH_compute_key(secret_a, outlen,
2283 EC_KEY_get0_public_key(ecdh_b[j]),
2288 mr ? "+R7:%ld:%d:%.2f\n" :
2289 "%ld %d-bit ECDH ops in %.2fs\n", count,
2290 test_curves_bits[j], d);
2291 ecdh_results[j][0] = d / (double)count;
2296 if (rsa_count <= 1) {
2297 /* if longer than 10s, don't do any more */
2298 for (j++; j < EC_NUM; j++)
2309 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2310 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2312 printf("%s ", BN_options());
2313 #ifndef OPENSSL_NO_MD2
2314 printf("%s ", MD2_options());
2316 #ifndef OPENSSL_NO_RC4
2317 printf("%s ", RC4_options());
2319 #ifndef OPENSSL_NO_DES
2320 printf("%s ", DES_options());
2322 #ifndef OPENSSL_NO_AES
2323 printf("%s ", AES_options());
2325 #ifndef OPENSSL_NO_IDEA
2326 printf("%s ", idea_options());
2328 #ifndef OPENSSL_NO_BF
2329 printf("%s ", BF_options());
2331 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2336 fprintf(stdout, "+H");
2339 "The 'numbers' are in 1000s of bytes per second processed.\n");
2340 fprintf(stdout, "type ");
2342 for (j = 0; j < SIZE_NUM; j++)
2343 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2344 fprintf(stdout, "\n");
2347 for (k = 0; k < ALGOR_NUM; k++) {
2351 fprintf(stdout, "+F:%d:%s", k, names[k]);
2353 fprintf(stdout, "%-13s", names[k]);
2354 for (j = 0; j < SIZE_NUM; j++) {
2355 if (results[k][j] > 10000 && !mr)
2356 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2358 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2360 fprintf(stdout, "\n");
2362 #ifndef OPENSSL_NO_RSA
2364 for (k = 0; k < RSA_NUM; k++) {
2368 printf("%18ssign verify sign/s verify/s\n", " ");
2372 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2373 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2375 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2376 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2377 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2380 #ifndef OPENSSL_NO_DSA
2382 for (k = 0; k < DSA_NUM; k++) {
2386 printf("%18ssign verify sign/s verify/s\n", " ");
2390 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2391 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2393 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2394 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2395 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2398 #ifndef OPENSSL_NO_EC
2400 for (k = 0; k < EC_NUM; k++) {
2404 printf("%30ssign verify sign/s verify/s\n", " ");
2409 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2410 k, test_curves_bits[k],
2411 ecdsa_results[k][0], ecdsa_results[k][1]);
2414 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2415 test_curves_bits[k],
2416 test_curves_names[k],
2417 ecdsa_results[k][0], ecdsa_results[k][1],
2418 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2421 for (k = 0; k < EC_NUM; k++) {
2425 printf("%30sop op/s\n", " ");
2429 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2430 k, test_curves_bits[k],
2431 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2434 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2435 test_curves_bits[k],
2436 test_curves_names[k],
2437 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2444 ERR_print_errors(bio_err);
2445 if (buf_malloc != NULL)
2446 OPENSSL_free(buf_malloc);
2447 if (buf2_malloc != NULL)
2448 OPENSSL_free(buf2_malloc);
2449 #ifndef OPENSSL_NO_RSA
2450 for (i = 0; i < RSA_NUM; i++)
2451 RSA_free(rsa_key[i]);
2453 #ifndef OPENSSL_NO_DSA
2454 for (i = 0; i < DSA_NUM; i++)
2455 DSA_free(dsa_key[i]);
2458 #ifndef OPENSSL_NO_EC
2459 for (i = 0; i < EC_NUM; i++)
2460 if (ecdsa[i] != NULL)
2461 EC_KEY_free(ecdsa[i]);
2462 for (i = 0; i < EC_NUM; i++) {
2463 if (ecdh_a[i] != NULL)
2464 EC_KEY_free(ecdh_a[i]);
2465 if (ecdh_b[i] != NULL)
2466 EC_KEY_free(ecdh_b[i]);
2474 static void print_message(const char *s, long num, int length)
2478 mr ? "+DT:%s:%d:%d\n"
2479 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2480 (void)BIO_flush(bio_err);
2484 mr ? "+DN:%s:%ld:%d\n"
2485 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2486 (void)BIO_flush(bio_err);
2490 static void pkey_print_message(const char *str, const char *str2, long num,
2495 mr ? "+DTP:%d:%s:%s:%d\n"
2496 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2497 (void)BIO_flush(bio_err);
2501 mr ? "+DNP:%ld:%d:%s:%s\n"
2502 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2503 (void)BIO_flush(bio_err);
2507 static void print_result(int alg, int run_no, int count, double time_used)
2510 mr ? "+R:%d:%s:%f\n"
2511 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2512 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2516 static char *sstrsep(char **string, const char *delim)
2519 char *token = *string;
2524 memset(isdelim, 0, sizeof isdelim);
2528 isdelim[(unsigned char)(*delim)] = 1;
2532 while (!isdelim[(unsigned char)(**string)]) {
2544 static int do_multi(int multi)
2549 static char sep[] = ":";
2551 fds = malloc(multi * sizeof *fds);
2552 for (n = 0; n < multi; ++n) {
2553 if (pipe(fd) == -1) {
2554 fprintf(stderr, "pipe failure\n");
2565 if (dup(fd[1]) == -1) {
2566 fprintf(stderr, "dup failed\n");
2575 printf("Forked child %d\n", n);
2578 /* for now, assume the pipe is long enough to take all the output */
2579 for (n = 0; n < multi; ++n) {
2584 f = fdopen(fds[n], "r");
2585 while (fgets(buf, sizeof buf, f)) {
2586 p = strchr(buf, '\n');
2589 if (buf[0] != '+') {
2590 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2594 printf("Got: %s from %d\n", buf, n);
2595 if (!strncmp(buf, "+F:", 3)) {
2600 alg = atoi(sstrsep(&p, sep));
2602 for (j = 0; j < SIZE_NUM; ++j)
2603 results[alg][j] += atof(sstrsep(&p, sep));
2604 } else if (!strncmp(buf, "+F2:", 4)) {
2609 k = atoi(sstrsep(&p, sep));
2612 d = atof(sstrsep(&p, sep));
2614 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2616 rsa_results[k][0] = d;
2618 d = atof(sstrsep(&p, sep));
2620 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2622 rsa_results[k][1] = d;
2623 } else if (!strncmp(buf, "+F2:", 4)) {
2628 k = atoi(sstrsep(&p, sep));
2631 d = atof(sstrsep(&p, sep));
2633 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2635 rsa_results[k][0] = d;
2637 d = atof(sstrsep(&p, sep));
2639 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2641 rsa_results[k][1] = d;
2643 # ifndef OPENSSL_NO_DSA
2644 else if (!strncmp(buf, "+F3:", 4)) {
2649 k = atoi(sstrsep(&p, sep));
2652 d = atof(sstrsep(&p, sep));
2654 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2656 dsa_results[k][0] = d;
2658 d = atof(sstrsep(&p, sep));
2660 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2662 dsa_results[k][1] = d;
2665 # ifndef OPENSSL_NO_EC
2666 else if (!strncmp(buf, "+F4:", 4)) {
2671 k = atoi(sstrsep(&p, sep));
2674 d = atof(sstrsep(&p, sep));
2676 ecdsa_results[k][0] =
2677 1 / (1 / ecdsa_results[k][0] + 1 / d);
2679 ecdsa_results[k][0] = d;
2681 d = atof(sstrsep(&p, sep));
2683 ecdsa_results[k][1] =
2684 1 / (1 / ecdsa_results[k][1] + 1 / d);
2686 ecdsa_results[k][1] = d;
2688 else if (!strncmp(buf, "+F5:", 4)) {
2693 k = atoi(sstrsep(&p, sep));
2696 d = atof(sstrsep(&p, sep));
2698 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2700 ecdh_results[k][0] = d;
2705 else if (!strncmp(buf, "+H:", 3)) {
2707 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2717 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2719 static int mblengths[] =
2720 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2721 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2722 const char *alg_name;
2723 unsigned char *inp, *out, no_key[32], no_iv[16];
2727 inp = OPENSSL_malloc(mblengths[num - 1]);
2728 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2730 BIO_printf(bio_err,"Out of memory\n");
2735 EVP_CIPHER_CTX_init(&ctx);
2736 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2737 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2739 alg_name = OBJ_nid2ln(evp_cipher->nid);
2741 for (j = 0; j < num; j++) {
2742 print_message(alg_name, 0, mblengths[j]);
2744 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2745 unsigned char aad[13];
2746 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2747 size_t len = mblengths[j];
2750 memset(aad, 0, 8); /* avoid uninitialized values */
2751 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2752 aad[9] = 3; /* version */
2754 aad[11] = 0; /* length */
2756 mb_param.out = NULL;
2759 mb_param.interleave = 8;
2761 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2762 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2763 sizeof(mb_param), &mb_param);
2769 EVP_CIPHER_CTX_ctrl(&ctx,
2770 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2771 sizeof(mb_param), &mb_param);
2775 RAND_bytes(out, 16);
2779 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2780 EVP_CTRL_AEAD_TLS1_AAD, 13, aad);
2781 EVP_Cipher(&ctx, out, inp, len + pad);
2786 mr ? "+R:%d:%s:%f\n"
2787 : "%d %s's in %.2fs\n", count, "evp", d);
2788 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2792 fprintf(stdout, "+H");
2793 for (j = 0; j < num; j++)
2794 fprintf(stdout, ":%d", mblengths[j]);
2795 fprintf(stdout, "\n");
2796 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2797 for (j = 0; j < num; j++)
2798 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2799 fprintf(stdout, "\n");
2802 "The 'numbers' are in 1000s of bytes per second processed.\n");
2803 fprintf(stdout, "type ");
2804 for (j = 0; j < num; j++)
2805 fprintf(stdout, "%7d bytes", mblengths[j]);
2806 fprintf(stdout, "\n");
2807 fprintf(stdout, "%-24s", alg_name);
2809 for (j = 0; j < num; j++) {
2810 if (results[D_EVP][j] > 10000)
2811 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2813 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2815 fprintf(stdout, "\n");