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.
72 /* most of this code has been pilfered from my libdes speed.c program */
74 #ifndef OPENSSL_NO_SPEED
78 # define RSA_SECONDS 10
79 # define DSA_SECONDS 10
80 # define ECDSA_SECONDS 10
81 # define ECDH_SECONDS 10
83 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
84 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
87 # define PROG speed_main
95 # ifdef OPENSSL_NO_STDIO
98 # include <openssl/crypto.h>
99 # include <openssl/rand.h>
100 # include <openssl/err.h>
101 # include <openssl/evp.h>
102 # include <openssl/objects.h>
103 # if !defined(OPENSSL_SYS_MSDOS)
104 # include OPENSSL_UNISTD
107 # ifndef OPENSSL_SYS_NETWARE
111 # if defined(_WIN32) || defined(__CYGWIN__)
112 # include <windows.h>
113 # if defined(__CYGWIN__) && !defined(_WIN32)
115 * <windows.h> should define _WIN32, which normally is mutually exclusive
116 * with __CYGWIN__, but if it didn't...
119 /* this is done because Cygwin alarm() fails sometimes. */
123 # include <openssl/bn.h>
124 # ifndef OPENSSL_NO_DES
125 # include <openssl/des.h>
127 # ifndef OPENSSL_NO_AES
128 # include <openssl/aes.h>
130 # ifndef OPENSSL_NO_CAMELLIA
131 # include <openssl/camellia.h>
133 # ifndef OPENSSL_NO_MD2
134 # include <openssl/md2.h>
136 # ifndef OPENSSL_NO_MDC2
137 # include <openssl/mdc2.h>
139 # ifndef OPENSSL_NO_MD4
140 # include <openssl/md4.h>
142 # ifndef OPENSSL_NO_MD5
143 # include <openssl/md5.h>
145 # ifndef OPENSSL_NO_HMAC
146 # include <openssl/hmac.h>
148 # include <openssl/evp.h>
149 # ifndef OPENSSL_NO_SHA
150 # include <openssl/sha.h>
152 # ifndef OPENSSL_NO_RIPEMD
153 # include <openssl/ripemd.h>
155 # ifndef OPENSSL_NO_WHIRLPOOL
156 # include <openssl/whrlpool.h>
158 # ifndef OPENSSL_NO_RC4
159 # include <openssl/rc4.h>
161 # ifndef OPENSSL_NO_RC5
162 # include <openssl/rc5.h>
164 # ifndef OPENSSL_NO_RC2
165 # include <openssl/rc2.h>
167 # ifndef OPENSSL_NO_IDEA
168 # include <openssl/idea.h>
170 # ifndef OPENSSL_NO_SEED
171 # include <openssl/seed.h>
173 # ifndef OPENSSL_NO_BF
174 # include <openssl/blowfish.h>
176 # ifndef OPENSSL_NO_CAST
177 # include <openssl/cast.h>
179 # ifndef OPENSSL_NO_RSA
180 # include <openssl/rsa.h>
181 # include "./testrsa.h"
183 # include <openssl/x509.h>
184 # ifndef OPENSSL_NO_DSA
185 # include <openssl/dsa.h>
186 # include "./testdsa.h"
188 # ifndef OPENSSL_NO_ECDSA
189 # include <openssl/ecdsa.h>
191 # ifndef OPENSSL_NO_ECDH
192 # include <openssl/ecdh.h>
194 # include <openssl/modes.h>
197 # ifdef OPENSSL_DOING_MAKEDEPEND
198 # undef AES_set_encrypt_key
199 # undef AES_set_decrypt_key
200 # undef DES_set_key_unchecked
202 # define BF_set_key private_BF_set_key
203 # define CAST_set_key private_CAST_set_key
204 # define idea_set_encrypt_key private_idea_set_encrypt_key
205 # define SEED_set_key private_SEED_set_key
206 # define RC2_set_key private_RC2_set_key
207 # define RC4_set_key private_RC4_set_key
208 # define DES_set_key_unchecked private_DES_set_key_unchecked
209 # define AES_set_encrypt_key private_AES_set_encrypt_key
210 # define AES_set_decrypt_key private_AES_set_decrypt_key
211 # define Camellia_set_key private_Camellia_set_key
215 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
229 # define BUFSIZE ((long)1024*8+1)
230 static volatile int run = 0;
233 static int usertime = 1;
235 static double Time_F(int s);
236 static void print_message(const char *s, long num, int length);
237 static void pkey_print_message(const char *str, const char *str2,
238 long num, int bits, int sec);
239 static void print_result(int alg, int run_no, int count, double time_used);
241 static int do_multi(int multi);
244 # define ALGOR_NUM 30
250 # define MAX_ECDH_SIZE 256
252 static const char *names[ALGOR_NUM] = {
253 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
254 "des cbc", "des ede3", "idea cbc", "seed cbc",
255 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
256 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
257 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
258 "evp", "sha256", "sha512", "whirlpool",
259 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
262 static double results[ALGOR_NUM][SIZE_NUM];
263 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
265 # ifndef OPENSSL_NO_RSA
266 static double rsa_results[RSA_NUM][2];
268 # ifndef OPENSSL_NO_DSA
269 static double dsa_results[DSA_NUM][2];
271 # ifndef OPENSSL_NO_ECDSA
272 static double ecdsa_results[EC_NUM][2];
274 # ifndef OPENSSL_NO_ECDH
275 static double ecdh_results[EC_NUM][1];
278 # if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
279 static const char rnd_seed[] =
280 "string to make the random number generator think it has entropy";
281 static int rnd_fake = 0;
285 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
286 # define SIGRETTYPE void
288 # define SIGRETTYPE int
291 static SIGRETTYPE sig_done(int sig);
292 static SIGRETTYPE sig_done(int sig)
294 signal(SIGALRM, sig_done);
307 # if !defined(SIGALRM)
310 static unsigned int lapse, schlock;
311 static void alarm_win32(unsigned int secs)
316 # define alarm alarm_win32
318 static DWORD WINAPI sleepy(VOID * arg)
326 static double Time_F(int s)
331 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
333 DWORD ret = GetLastError();
334 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
337 CloseHandle(thr); /* detach the thread */
339 Sleep(0); /* scheduler spinlock */
342 return app_tminterval(s, usertime);
346 static double Time_F(int s)
348 return app_tminterval(s, usertime);
352 # ifndef OPENSSL_NO_ECDH
353 static const int KDF1_SHA1_len = 20;
354 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
357 # ifndef OPENSSL_NO_SHA
358 if (*outlen < SHA_DIGEST_LENGTH)
361 *outlen = SHA_DIGEST_LENGTH;
362 return SHA1(in, inlen, out);
365 # endif /* OPENSSL_NO_SHA */
367 # endif /* OPENSSL_NO_ECDH */
369 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
371 int MAIN(int, char **);
373 int MAIN(int argc, char **argv)
376 unsigned char *buf = NULL, *buf2 = NULL;
378 long count = 0, save_count = 0;
380 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
383 # ifndef OPENSSL_NO_RSA
386 unsigned char md[EVP_MAX_MD_SIZE];
387 # ifndef OPENSSL_NO_MD2
388 unsigned char md2[MD2_DIGEST_LENGTH];
390 # ifndef OPENSSL_NO_MDC2
391 unsigned char mdc2[MDC2_DIGEST_LENGTH];
393 # ifndef OPENSSL_NO_MD4
394 unsigned char md4[MD4_DIGEST_LENGTH];
396 # ifndef OPENSSL_NO_MD5
397 unsigned char md5[MD5_DIGEST_LENGTH];
398 unsigned char hmac[MD5_DIGEST_LENGTH];
400 # ifndef OPENSSL_NO_SHA
401 unsigned char sha[SHA_DIGEST_LENGTH];
402 # ifndef OPENSSL_NO_SHA256
403 unsigned char sha256[SHA256_DIGEST_LENGTH];
405 # ifndef OPENSSL_NO_SHA512
406 unsigned char sha512[SHA512_DIGEST_LENGTH];
409 # ifndef OPENSSL_NO_WHIRLPOOL
410 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
412 # ifndef OPENSSL_NO_RIPEMD
413 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
415 # ifndef OPENSSL_NO_RC4
418 # ifndef OPENSSL_NO_RC5
421 # ifndef OPENSSL_NO_RC2
424 # ifndef OPENSSL_NO_IDEA
425 IDEA_KEY_SCHEDULE idea_ks;
427 # ifndef OPENSSL_NO_SEED
428 SEED_KEY_SCHEDULE seed_ks;
430 # ifndef OPENSSL_NO_BF
433 # ifndef OPENSSL_NO_CAST
436 static const unsigned char key16[16] = {
437 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
438 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
440 # ifndef OPENSSL_NO_AES
441 static const unsigned char key24[24] = {
442 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
443 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
444 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
446 static const unsigned char key32[32] = {
447 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
448 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
449 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
450 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
453 # ifndef OPENSSL_NO_CAMELLIA
454 static const unsigned char ckey24[24] = {
455 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
456 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
457 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
459 static const unsigned char ckey32[32] = {
460 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
461 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
462 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
463 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
466 # ifndef OPENSSL_NO_AES
467 # define MAX_BLOCK_SIZE 128
469 # define MAX_BLOCK_SIZE 64
471 unsigned char DES_iv[8];
472 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
473 # ifndef OPENSSL_NO_DES
474 static DES_cblock key =
475 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
476 static DES_cblock key2 =
477 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
478 static DES_cblock key3 =
479 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
480 DES_key_schedule sch;
481 DES_key_schedule sch2;
482 DES_key_schedule sch3;
484 # ifndef OPENSSL_NO_AES
485 AES_KEY aes_ks1, aes_ks2, aes_ks3;
487 # ifndef OPENSSL_NO_CAMELLIA
488 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
499 # define D_EDE3_DES 9
500 # define D_CBC_IDEA 10
501 # define D_CBC_SEED 11
502 # define D_CBC_RC2 12
503 # define D_CBC_RC5 13
505 # define D_CBC_CAST 15
506 # define D_CBC_128_AES 16
507 # define D_CBC_192_AES 17
508 # define D_CBC_256_AES 18
509 # define D_CBC_128_CML 19
510 # define D_CBC_192_CML 20
511 # define D_CBC_256_CML 21
515 # define D_WHIRLPOOL 25
516 # define D_IGE_128_AES 26
517 # define D_IGE_192_AES 27
518 # define D_IGE_256_AES 28
521 long c[ALGOR_NUM][SIZE_NUM];
523 # define R_DSA_1024 1
524 # define R_DSA_2048 2
526 # define R_RSA_1024 1
527 # define R_RSA_2048 2
528 # define R_RSA_4096 3
540 # define R_EC_K571 10
541 # define R_EC_B163 11
542 # define R_EC_B233 12
543 # define R_EC_B283 13
544 # define R_EC_B409 14
545 # define R_EC_B571 15
547 # ifndef OPENSSL_NO_RSA
548 RSA *rsa_key[RSA_NUM];
549 long rsa_c[RSA_NUM][2];
550 static unsigned int rsa_bits[RSA_NUM] = {
551 512, 1024, 2048, 4096
553 static unsigned char *rsa_data[RSA_NUM] = {
554 test512, test1024, test2048, test4096
556 static int rsa_data_length[RSA_NUM] = {
557 sizeof(test512), sizeof(test1024),
558 sizeof(test2048), sizeof(test4096)
561 # ifndef OPENSSL_NO_DSA
562 DSA *dsa_key[DSA_NUM];
563 long dsa_c[DSA_NUM][2];
564 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
566 # ifndef OPENSSL_NO_EC
568 * We only test over the following curves as they are representative, To
569 * add tests over more curves, simply add the curve NID and curve name to
570 * the following arrays and increase the EC_NUM value accordingly.
572 static unsigned int test_curves[EC_NUM] = {
575 NID_X9_62_prime192v1,
577 NID_X9_62_prime256v1,
592 static const char *test_curves_names[EC_NUM] = {
612 static int test_curves_bits[EC_NUM] = {
613 160, 192, 224, 256, 384, 521,
614 163, 233, 283, 409, 571,
615 163, 233, 283, 409, 571
620 # ifndef OPENSSL_NO_ECDSA
621 unsigned char ecdsasig[256];
622 unsigned int ecdsasiglen;
623 EC_KEY *ecdsa[EC_NUM];
624 long ecdsa_c[EC_NUM][2];
627 # ifndef OPENSSL_NO_ECDH
628 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
629 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
630 int secret_size_a, secret_size_b;
633 long ecdh_c[EC_NUM][2];
636 int rsa_doit[RSA_NUM];
637 int dsa_doit[DSA_NUM];
638 # ifndef OPENSSL_NO_ECDSA
639 int ecdsa_doit[EC_NUM];
641 # ifndef OPENSSL_NO_ECDH
642 int ecdh_doit[EC_NUM];
646 const EVP_CIPHER *evp_cipher = NULL;
647 const EVP_MD *evp_md = NULL;
659 memset(results, 0, sizeof(results));
660 # ifndef OPENSSL_NO_DSA
661 memset(dsa_key, 0, sizeof(dsa_key));
663 # ifndef OPENSSL_NO_ECDSA
664 for (i = 0; i < EC_NUM; i++)
667 # ifndef OPENSSL_NO_ECDH
668 for (i = 0; i < EC_NUM; i++) {
673 # ifndef OPENSSL_NO_RSA
674 for (i = 0; i < RSA_NUM; i++)
679 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
680 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
682 if (!load_config(bio_err, NULL))
685 if ((buf = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
686 BIO_printf(bio_err, "out of memory\n");
689 if ((buf2 = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
690 BIO_printf(bio_err, "out of memory\n");
694 memset(c, 0, sizeof(c));
695 memset(DES_iv, 0, sizeof(DES_iv));
696 memset(iv, 0, sizeof(iv));
698 for (i = 0; i < ALGOR_NUM; i++)
700 for (i = 0; i < RSA_NUM; i++)
702 for (i = 0; i < DSA_NUM; i++)
704 # ifndef OPENSSL_NO_ECDSA
705 for (i = 0; i < EC_NUM; i++)
708 # ifndef OPENSSL_NO_ECDH
709 for (i = 0; i < EC_NUM; i++)
717 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
719 j--; /* Otherwise, -elapsed gets confused with an
721 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
725 BIO_printf(bio_err, "no EVP given\n");
728 evp_cipher = EVP_get_cipherbyname(*argv);
730 evp_md = EVP_get_digestbyname(*argv);
732 if (!evp_cipher && !evp_md) {
733 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
738 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
740 j--; /* Otherwise, -elapsed gets confused with an
743 # ifndef OPENSSL_NO_ENGINE
744 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
748 BIO_printf(bio_err, "no engine given\n");
751 e = setup_engine(bio_err, *argv, 0);
753 * j will be increased again further down. We just don't want
754 * speed to confuse an engine with an algorithm, especially when
755 * none is given (which means all of them should be run)
761 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
765 BIO_printf(bio_err, "no multi count given\n");
768 multi = atoi(argv[0]);
770 BIO_printf(bio_err, "bad multi count\n");
773 j--; /* Otherwise, -mr gets confused with an
777 else if (argc > 0 && !strcmp(*argv, "-mr")) {
779 j--; /* Otherwise, -mr gets confused with an
781 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
785 # ifndef OPENSSL_NO_MD2
786 if (strcmp(*argv, "md2") == 0)
790 # ifndef OPENSSL_NO_MDC2
791 if (strcmp(*argv, "mdc2") == 0)
795 # ifndef OPENSSL_NO_MD4
796 if (strcmp(*argv, "md4") == 0)
800 # ifndef OPENSSL_NO_MD5
801 if (strcmp(*argv, "md5") == 0)
805 # ifndef OPENSSL_NO_MD5
806 if (strcmp(*argv, "hmac") == 0)
810 # ifndef OPENSSL_NO_SHA
811 if (strcmp(*argv, "sha1") == 0)
813 else if (strcmp(*argv, "sha") == 0)
814 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
816 # ifndef OPENSSL_NO_SHA256
817 if (strcmp(*argv, "sha256") == 0)
821 # ifndef OPENSSL_NO_SHA512
822 if (strcmp(*argv, "sha512") == 0)
827 # ifndef OPENSSL_NO_WHIRLPOOL
828 if (strcmp(*argv, "whirlpool") == 0)
829 doit[D_WHIRLPOOL] = 1;
832 # ifndef OPENSSL_NO_RIPEMD
833 if (strcmp(*argv, "ripemd") == 0)
835 else if (strcmp(*argv, "rmd160") == 0)
837 else if (strcmp(*argv, "ripemd160") == 0)
841 # ifndef OPENSSL_NO_RC4
842 if (strcmp(*argv, "rc4") == 0)
846 # ifndef OPENSSL_NO_DES
847 if (strcmp(*argv, "des-cbc") == 0)
849 else if (strcmp(*argv, "des-ede3") == 0)
850 doit[D_EDE3_DES] = 1;
853 # ifndef OPENSSL_NO_AES
854 if (strcmp(*argv, "aes-128-cbc") == 0)
855 doit[D_CBC_128_AES] = 1;
856 else if (strcmp(*argv, "aes-192-cbc") == 0)
857 doit[D_CBC_192_AES] = 1;
858 else if (strcmp(*argv, "aes-256-cbc") == 0)
859 doit[D_CBC_256_AES] = 1;
860 else if (strcmp(*argv, "aes-128-ige") == 0)
861 doit[D_IGE_128_AES] = 1;
862 else if (strcmp(*argv, "aes-192-ige") == 0)
863 doit[D_IGE_192_AES] = 1;
864 else if (strcmp(*argv, "aes-256-ige") == 0)
865 doit[D_IGE_256_AES] = 1;
868 # ifndef OPENSSL_NO_CAMELLIA
869 if (strcmp(*argv, "camellia-128-cbc") == 0)
870 doit[D_CBC_128_CML] = 1;
871 else if (strcmp(*argv, "camellia-192-cbc") == 0)
872 doit[D_CBC_192_CML] = 1;
873 else if (strcmp(*argv, "camellia-256-cbc") == 0)
874 doit[D_CBC_256_CML] = 1;
877 # ifndef OPENSSL_NO_RSA
878 # if 0 /* was: #ifdef RSAref */
879 if (strcmp(*argv, "rsaref") == 0) {
880 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
885 if (strcmp(*argv, "openssl") == 0) {
886 RSA_set_default_method(RSA_PKCS1_SSLeay());
890 # endif /* !OPENSSL_NO_RSA */
891 if (strcmp(*argv, "dsa512") == 0)
892 dsa_doit[R_DSA_512] = 2;
893 else if (strcmp(*argv, "dsa1024") == 0)
894 dsa_doit[R_DSA_1024] = 2;
895 else if (strcmp(*argv, "dsa2048") == 0)
896 dsa_doit[R_DSA_2048] = 2;
897 else if (strcmp(*argv, "rsa512") == 0)
898 rsa_doit[R_RSA_512] = 2;
899 else if (strcmp(*argv, "rsa1024") == 0)
900 rsa_doit[R_RSA_1024] = 2;
901 else if (strcmp(*argv, "rsa2048") == 0)
902 rsa_doit[R_RSA_2048] = 2;
903 else if (strcmp(*argv, "rsa4096") == 0)
904 rsa_doit[R_RSA_4096] = 2;
906 # ifndef OPENSSL_NO_RC2
907 if (strcmp(*argv, "rc2-cbc") == 0)
909 else if (strcmp(*argv, "rc2") == 0)
913 # ifndef OPENSSL_NO_RC5
914 if (strcmp(*argv, "rc5-cbc") == 0)
916 else if (strcmp(*argv, "rc5") == 0)
920 # ifndef OPENSSL_NO_IDEA
921 if (strcmp(*argv, "idea-cbc") == 0)
922 doit[D_CBC_IDEA] = 1;
923 else if (strcmp(*argv, "idea") == 0)
924 doit[D_CBC_IDEA] = 1;
927 # ifndef OPENSSL_NO_SEED
928 if (strcmp(*argv, "seed-cbc") == 0)
929 doit[D_CBC_SEED] = 1;
930 else if (strcmp(*argv, "seed") == 0)
931 doit[D_CBC_SEED] = 1;
934 # ifndef OPENSSL_NO_BF
935 if (strcmp(*argv, "bf-cbc") == 0)
937 else if (strcmp(*argv, "blowfish") == 0)
939 else if (strcmp(*argv, "bf") == 0)
943 # ifndef OPENSSL_NO_CAST
944 if (strcmp(*argv, "cast-cbc") == 0)
945 doit[D_CBC_CAST] = 1;
946 else if (strcmp(*argv, "cast") == 0)
947 doit[D_CBC_CAST] = 1;
948 else if (strcmp(*argv, "cast5") == 0)
949 doit[D_CBC_CAST] = 1;
952 # ifndef OPENSSL_NO_DES
953 if (strcmp(*argv, "des") == 0) {
955 doit[D_EDE3_DES] = 1;
958 # ifndef OPENSSL_NO_AES
959 if (strcmp(*argv, "aes") == 0) {
960 doit[D_CBC_128_AES] = 1;
961 doit[D_CBC_192_AES] = 1;
962 doit[D_CBC_256_AES] = 1;
963 } else if (strcmp(*argv, "ghash") == 0) {
967 # ifndef OPENSSL_NO_CAMELLIA
968 if (strcmp(*argv, "camellia") == 0) {
969 doit[D_CBC_128_CML] = 1;
970 doit[D_CBC_192_CML] = 1;
971 doit[D_CBC_256_CML] = 1;
974 # ifndef OPENSSL_NO_RSA
975 if (strcmp(*argv, "rsa") == 0) {
976 rsa_doit[R_RSA_512] = 1;
977 rsa_doit[R_RSA_1024] = 1;
978 rsa_doit[R_RSA_2048] = 1;
979 rsa_doit[R_RSA_4096] = 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 # ifndef OPENSSL_NO_HMAC
1081 BIO_printf(bio_err, "hmac ");
1084 # ifndef OPENSSL_NO_SHA1
1085 BIO_printf(bio_err, "sha1 ");
1087 # ifndef OPENSSL_NO_SHA256
1088 BIO_printf(bio_err, "sha256 ");
1090 # ifndef OPENSSL_NO_SHA512
1091 BIO_printf(bio_err, "sha512 ");
1093 # ifndef OPENSSL_NO_WHIRLPOOL
1094 BIO_printf(bio_err, "whirlpool");
1096 # ifndef OPENSSL_NO_RIPEMD160
1097 BIO_printf(bio_err, "rmd160");
1099 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1100 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1101 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1102 !defined(OPENSSL_NO_WHIRLPOOL)
1103 BIO_printf(bio_err, "\n");
1106 # ifndef OPENSSL_NO_IDEA
1107 BIO_printf(bio_err, "idea-cbc ");
1109 # ifndef OPENSSL_NO_SEED
1110 BIO_printf(bio_err, "seed-cbc ");
1112 # ifndef OPENSSL_NO_RC2
1113 BIO_printf(bio_err, "rc2-cbc ");
1115 # ifndef OPENSSL_NO_RC5
1116 BIO_printf(bio_err, "rc5-cbc ");
1118 # ifndef OPENSSL_NO_BF
1119 BIO_printf(bio_err, "bf-cbc");
1121 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1122 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1123 BIO_printf(bio_err, "\n");
1125 # ifndef OPENSSL_NO_DES
1126 BIO_printf(bio_err, "des-cbc des-ede3 ");
1128 # ifndef OPENSSL_NO_AES
1129 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1130 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1132 # ifndef OPENSSL_NO_CAMELLIA
1133 BIO_printf(bio_err, "\n");
1135 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1137 # ifndef OPENSSL_NO_RC4
1138 BIO_printf(bio_err, "rc4");
1140 BIO_printf(bio_err, "\n");
1142 # ifndef OPENSSL_NO_RSA
1143 BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
1146 # ifndef OPENSSL_NO_DSA
1147 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1149 # ifndef OPENSSL_NO_ECDSA
1150 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1151 "ecdsap256 ecdsap384 ecdsap521\n");
1153 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1155 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1156 BIO_printf(bio_err, "ecdsa\n");
1158 # ifndef OPENSSL_NO_ECDH
1159 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1160 "ecdhp256 ecdhp384 ecdhp521\n");
1162 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1164 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1165 BIO_printf(bio_err, "ecdh\n");
1168 # ifndef OPENSSL_NO_IDEA
1169 BIO_printf(bio_err, "idea ");
1171 # ifndef OPENSSL_NO_SEED
1172 BIO_printf(bio_err, "seed ");
1174 # ifndef OPENSSL_NO_RC2
1175 BIO_printf(bio_err, "rc2 ");
1177 # ifndef OPENSSL_NO_DES
1178 BIO_printf(bio_err, "des ");
1180 # ifndef OPENSSL_NO_AES
1181 BIO_printf(bio_err, "aes ");
1183 # ifndef OPENSSL_NO_CAMELLIA
1184 BIO_printf(bio_err, "camellia ");
1186 # ifndef OPENSSL_NO_RSA
1187 BIO_printf(bio_err, "rsa ");
1189 # ifndef OPENSSL_NO_BF
1190 BIO_printf(bio_err, "blowfish");
1192 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1193 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1194 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1195 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1196 BIO_printf(bio_err, "\n");
1199 BIO_printf(bio_err, "\n");
1200 BIO_printf(bio_err, "Available options:\n");
1201 # if defined(TIMES) || defined(USE_TOD)
1202 BIO_printf(bio_err, "-elapsed "
1203 "measure time in real time instead of CPU user time.\n");
1205 # ifndef OPENSSL_NO_ENGINE
1208 "use engine e, possibly a hardware device.\n");
1210 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1213 "time decryption instead of encryption (only EVP).\n");
1216 "produce machine readable output.\n");
1219 "-multi n " "run n benchmarks in parallel.\n");
1229 if (multi && do_multi(multi))
1234 for (i = 0; i < ALGOR_NUM; i++) {
1238 for (i = 0; i < RSA_NUM; i++)
1240 for (i = 0; i < DSA_NUM; i++)
1242 # ifndef OPENSSL_NO_ECDSA
1243 for (i = 0; i < EC_NUM; i++)
1246 # ifndef OPENSSL_NO_ECDH
1247 for (i = 0; i < EC_NUM; i++)
1251 for (i = 0; i < ALGOR_NUM; i++)
1255 if (usertime == 0 && !mr)
1257 "You have chosen to measure elapsed time "
1258 "instead of user CPU time.\n");
1260 # ifndef OPENSSL_NO_RSA
1261 for (i = 0; i < RSA_NUM; i++) {
1262 const unsigned char *p;
1265 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1266 if (rsa_key[i] == NULL) {
1267 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1275 : "Loaded RSA key, %d bit modulus and e= 0x",
1276 BN_num_bits(rsa_key[i]->n));
1277 BN_print(bio_err, rsa_key[i]->e);
1278 BIO_printf(bio_err, "\n");
1284 # ifndef OPENSSL_NO_DSA
1285 dsa_key[0] = get_dsa512();
1286 dsa_key[1] = get_dsa1024();
1287 dsa_key[2] = get_dsa2048();
1290 # ifndef OPENSSL_NO_DES
1291 DES_set_key_unchecked(&key, &sch);
1292 DES_set_key_unchecked(&key2, &sch2);
1293 DES_set_key_unchecked(&key3, &sch3);
1295 # ifndef OPENSSL_NO_AES
1296 AES_set_encrypt_key(key16, 128, &aes_ks1);
1297 AES_set_encrypt_key(key24, 192, &aes_ks2);
1298 AES_set_encrypt_key(key32, 256, &aes_ks3);
1300 # ifndef OPENSSL_NO_CAMELLIA
1301 Camellia_set_key(key16, 128, &camellia_ks1);
1302 Camellia_set_key(ckey24, 192, &camellia_ks2);
1303 Camellia_set_key(ckey32, 256, &camellia_ks3);
1305 # ifndef OPENSSL_NO_IDEA
1306 idea_set_encrypt_key(key16, &idea_ks);
1308 # ifndef OPENSSL_NO_SEED
1309 SEED_set_key(key16, &seed_ks);
1311 # ifndef OPENSSL_NO_RC4
1312 RC4_set_key(&rc4_ks, 16, key16);
1314 # ifndef OPENSSL_NO_RC2
1315 RC2_set_key(&rc2_ks, 16, key16, 128);
1317 # ifndef OPENSSL_NO_RC5
1318 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1320 # ifndef OPENSSL_NO_BF
1321 BF_set_key(&bf_ks, 16, key16);
1323 # ifndef OPENSSL_NO_CAST
1324 CAST_set_key(&cast_ks, 16, key16);
1326 # ifndef OPENSSL_NO_RSA
1327 memset(rsa_c, 0, sizeof(rsa_c));
1330 # ifndef OPENSSL_NO_DES
1331 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1337 for (it = count; it; it--)
1338 DES_ecb_encrypt((DES_cblock *)buf,
1339 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1343 c[D_MD2][0] = count / 10;
1344 c[D_MDC2][0] = count / 10;
1345 c[D_MD4][0] = count;
1346 c[D_MD5][0] = count;
1347 c[D_HMAC][0] = count;
1348 c[D_SHA1][0] = count;
1349 c[D_RMD160][0] = count;
1350 c[D_RC4][0] = count * 5;
1351 c[D_CBC_DES][0] = count;
1352 c[D_EDE3_DES][0] = count / 3;
1353 c[D_CBC_IDEA][0] = count;
1354 c[D_CBC_SEED][0] = count;
1355 c[D_CBC_RC2][0] = count;
1356 c[D_CBC_RC5][0] = count;
1357 c[D_CBC_BF][0] = count;
1358 c[D_CBC_CAST][0] = count;
1359 c[D_CBC_128_AES][0] = count;
1360 c[D_CBC_192_AES][0] = count;
1361 c[D_CBC_256_AES][0] = count;
1362 c[D_CBC_128_CML][0] = count;
1363 c[D_CBC_192_CML][0] = count;
1364 c[D_CBC_256_CML][0] = count;
1365 c[D_SHA256][0] = count;
1366 c[D_SHA512][0] = count;
1367 c[D_WHIRLPOOL][0] = count;
1368 c[D_IGE_128_AES][0] = count;
1369 c[D_IGE_192_AES][0] = count;
1370 c[D_IGE_256_AES][0] = count;
1371 c[D_GHASH][0] = count;
1373 for (i = 1; i < SIZE_NUM; i++) {
1374 c[D_MD2][i] = c[D_MD2][0] * 4 * lengths[0] / lengths[i];
1375 c[D_MDC2][i] = c[D_MDC2][0] * 4 * lengths[0] / lengths[i];
1376 c[D_MD4][i] = c[D_MD4][0] * 4 * lengths[0] / lengths[i];
1377 c[D_MD5][i] = c[D_MD5][0] * 4 * lengths[0] / lengths[i];
1378 c[D_HMAC][i] = c[D_HMAC][0] * 4 * lengths[0] / lengths[i];
1379 c[D_SHA1][i] = c[D_SHA1][0] * 4 * lengths[0] / lengths[i];
1380 c[D_RMD160][i] = c[D_RMD160][0] * 4 * lengths[0] / lengths[i];
1381 c[D_SHA256][i] = c[D_SHA256][0] * 4 * lengths[0] / lengths[i];
1382 c[D_SHA512][i] = c[D_SHA512][0] * 4 * lengths[0] / lengths[i];
1383 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * lengths[0] / lengths[i];
1385 for (i = 1; i < SIZE_NUM; i++) {
1388 l0 = (long)lengths[i - 1];
1389 l1 = (long)lengths[i];
1390 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1391 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1392 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1393 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1394 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1395 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1396 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1397 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1398 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1399 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1400 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1401 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1402 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1403 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1404 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1405 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1406 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1407 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1409 # ifndef OPENSSL_NO_RSA
1410 rsa_c[R_RSA_512][0] = count / 2000;
1411 rsa_c[R_RSA_512][1] = count / 400;
1412 for (i = 1; i < RSA_NUM; i++) {
1413 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1414 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1415 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1418 if (rsa_c[i][0] == 0) {
1426 # ifndef OPENSSL_NO_DSA
1427 dsa_c[R_DSA_512][0] = count / 1000;
1428 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1429 for (i = 1; i < DSA_NUM; i++) {
1430 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1431 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1432 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1435 if (dsa_c[i] == 0) {
1443 # ifndef OPENSSL_NO_ECDSA
1444 ecdsa_c[R_EC_P160][0] = count / 1000;
1445 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1446 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1447 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1448 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1449 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1452 if (ecdsa_c[i] == 0) {
1458 ecdsa_c[R_EC_K163][0] = count / 1000;
1459 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1460 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1461 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1462 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1463 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1466 if (ecdsa_c[i] == 0) {
1472 ecdsa_c[R_EC_B163][0] = count / 1000;
1473 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1474 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1475 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1476 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1477 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1480 if (ecdsa_c[i] == 0) {
1488 # ifndef OPENSSL_NO_ECDH
1489 ecdh_c[R_EC_P160][0] = count / 1000;
1490 ecdh_c[R_EC_P160][1] = count / 1000;
1491 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1492 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1493 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1494 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1497 if (ecdh_c[i] == 0) {
1503 ecdh_c[R_EC_K163][0] = count / 1000;
1504 ecdh_c[R_EC_K163][1] = count / 1000;
1505 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1506 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1507 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1508 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1511 if (ecdh_c[i] == 0) {
1517 ecdh_c[R_EC_B163][0] = count / 1000;
1518 ecdh_c[R_EC_B163][1] = count / 1000;
1519 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1520 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1521 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1522 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1525 if (ecdh_c[i] == 0) {
1533 # define COND(d) (count < (d))
1534 # define COUNT(d) (d)
1536 /* not worth fixing */
1537 # error "You cannot disable DES on systems without SIGALRM."
1538 # endif /* OPENSSL_NO_DES */
1540 # define COND(c) (run && count<0x7fffffff)
1541 # define COUNT(d) (count)
1543 signal(SIGALRM, sig_done);
1545 # endif /* SIGALRM */
1547 # ifndef OPENSSL_NO_MD2
1549 for (j = 0; j < SIZE_NUM; j++) {
1550 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1552 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1553 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1556 print_result(D_MD2, j, count, d);
1560 # ifndef OPENSSL_NO_MDC2
1562 for (j = 0; j < SIZE_NUM; j++) {
1563 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1565 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1566 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1569 print_result(D_MDC2, j, count, d);
1574 # ifndef OPENSSL_NO_MD4
1576 for (j = 0; j < SIZE_NUM; j++) {
1577 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1579 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1580 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1581 NULL, EVP_md4(), NULL);
1583 print_result(D_MD4, j, count, d);
1588 # ifndef OPENSSL_NO_MD5
1590 for (j = 0; j < SIZE_NUM; j++) {
1591 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1593 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1594 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md5[0]),
1595 NULL, EVP_get_digestbyname("md5"), NULL);
1597 print_result(D_MD5, j, count, d);
1602 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1606 HMAC_CTX_init(&hctx);
1607 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1608 16, EVP_md5(), NULL);
1610 for (j = 0; j < SIZE_NUM; j++) {
1611 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1613 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1614 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1615 HMAC_Update(&hctx, buf, lengths[j]);
1616 HMAC_Final(&hctx, &(hmac[0]), NULL);
1619 print_result(D_HMAC, j, count, d);
1621 HMAC_CTX_cleanup(&hctx);
1624 # ifndef OPENSSL_NO_SHA
1626 for (j = 0; j < SIZE_NUM; j++) {
1627 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1629 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1630 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1633 print_result(D_SHA1, j, count, d);
1636 # ifndef OPENSSL_NO_SHA256
1637 if (doit[D_SHA256]) {
1638 for (j = 0; j < SIZE_NUM; j++) {
1639 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1641 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1642 SHA256(buf, lengths[j], sha256);
1644 print_result(D_SHA256, j, count, d);
1649 # ifndef OPENSSL_NO_SHA512
1650 if (doit[D_SHA512]) {
1651 for (j = 0; j < SIZE_NUM; j++) {
1652 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1654 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1655 SHA512(buf, lengths[j], sha512);
1657 print_result(D_SHA512, j, count, d);
1663 # ifndef OPENSSL_NO_WHIRLPOOL
1664 if (doit[D_WHIRLPOOL]) {
1665 for (j = 0; j < SIZE_NUM; j++) {
1666 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1668 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1669 WHIRLPOOL(buf, lengths[j], whirlpool);
1671 print_result(D_WHIRLPOOL, j, count, d);
1676 # ifndef OPENSSL_NO_RIPEMD
1677 if (doit[D_RMD160]) {
1678 for (j = 0; j < SIZE_NUM; j++) {
1679 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1681 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1682 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1683 EVP_ripemd160(), NULL);
1685 print_result(D_RMD160, j, count, d);
1689 # ifndef OPENSSL_NO_RC4
1691 for (j = 0; j < SIZE_NUM; j++) {
1692 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1694 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1695 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1697 print_result(D_RC4, j, count, d);
1701 # ifndef OPENSSL_NO_DES
1702 if (doit[D_CBC_DES]) {
1703 for (j = 0; j < SIZE_NUM; j++) {
1704 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1706 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1707 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1708 &DES_iv, DES_ENCRYPT);
1710 print_result(D_CBC_DES, j, count, d);
1714 if (doit[D_EDE3_DES]) {
1715 for (j = 0; j < SIZE_NUM; j++) {
1716 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1718 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1719 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1721 &DES_iv, DES_ENCRYPT);
1723 print_result(D_EDE3_DES, j, count, d);
1727 # ifndef OPENSSL_NO_AES
1728 if (doit[D_CBC_128_AES]) {
1729 for (j = 0; j < SIZE_NUM; j++) {
1730 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1733 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1734 AES_cbc_encrypt(buf, buf,
1735 (unsigned long)lengths[j], &aes_ks1,
1738 print_result(D_CBC_128_AES, j, count, d);
1741 if (doit[D_CBC_192_AES]) {
1742 for (j = 0; j < SIZE_NUM; j++) {
1743 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1746 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1747 AES_cbc_encrypt(buf, buf,
1748 (unsigned long)lengths[j], &aes_ks2,
1751 print_result(D_CBC_192_AES, j, count, d);
1754 if (doit[D_CBC_256_AES]) {
1755 for (j = 0; j < SIZE_NUM; j++) {
1756 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1759 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1760 AES_cbc_encrypt(buf, buf,
1761 (unsigned long)lengths[j], &aes_ks3,
1764 print_result(D_CBC_256_AES, j, count, d);
1768 if (doit[D_IGE_128_AES]) {
1769 for (j = 0; j < SIZE_NUM; j++) {
1770 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1773 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1774 AES_ige_encrypt(buf, buf2,
1775 (unsigned long)lengths[j], &aes_ks1,
1778 print_result(D_IGE_128_AES, j, count, d);
1781 if (doit[D_IGE_192_AES]) {
1782 for (j = 0; j < SIZE_NUM; j++) {
1783 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1786 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1787 AES_ige_encrypt(buf, buf2,
1788 (unsigned long)lengths[j], &aes_ks2,
1791 print_result(D_IGE_192_AES, j, count, d);
1794 if (doit[D_IGE_256_AES]) {
1795 for (j = 0; j < SIZE_NUM; j++) {
1796 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1799 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1800 AES_ige_encrypt(buf, buf2,
1801 (unsigned long)lengths[j], &aes_ks3,
1804 print_result(D_IGE_256_AES, j, count, d);
1807 if (doit[D_GHASH]) {
1808 GCM128_CONTEXT *ctx =
1809 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1810 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1812 for (j = 0; j < SIZE_NUM; j++) {
1813 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1815 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1816 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1818 print_result(D_GHASH, j, count, d);
1820 CRYPTO_gcm128_release(ctx);
1823 # ifndef OPENSSL_NO_CAMELLIA
1824 if (doit[D_CBC_128_CML]) {
1825 for (j = 0; j < SIZE_NUM; j++) {
1826 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1829 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1830 Camellia_cbc_encrypt(buf, buf,
1831 (unsigned long)lengths[j], &camellia_ks1,
1832 iv, CAMELLIA_ENCRYPT);
1834 print_result(D_CBC_128_CML, j, count, d);
1837 if (doit[D_CBC_192_CML]) {
1838 for (j = 0; j < SIZE_NUM; j++) {
1839 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1842 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1843 Camellia_cbc_encrypt(buf, buf,
1844 (unsigned long)lengths[j], &camellia_ks2,
1845 iv, CAMELLIA_ENCRYPT);
1847 print_result(D_CBC_192_CML, j, count, d);
1850 if (doit[D_CBC_256_CML]) {
1851 for (j = 0; j < SIZE_NUM; j++) {
1852 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1855 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1856 Camellia_cbc_encrypt(buf, buf,
1857 (unsigned long)lengths[j], &camellia_ks3,
1858 iv, CAMELLIA_ENCRYPT);
1860 print_result(D_CBC_256_CML, j, count, d);
1864 # ifndef OPENSSL_NO_IDEA
1865 if (doit[D_CBC_IDEA]) {
1866 for (j = 0; j < SIZE_NUM; j++) {
1867 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1869 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1870 idea_cbc_encrypt(buf, buf,
1871 (unsigned long)lengths[j], &idea_ks,
1874 print_result(D_CBC_IDEA, j, count, d);
1878 # ifndef OPENSSL_NO_SEED
1879 if (doit[D_CBC_SEED]) {
1880 for (j = 0; j < SIZE_NUM; j++) {
1881 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1883 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1884 SEED_cbc_encrypt(buf, buf,
1885 (unsigned long)lengths[j], &seed_ks, iv, 1);
1887 print_result(D_CBC_SEED, j, count, d);
1891 # ifndef OPENSSL_NO_RC2
1892 if (doit[D_CBC_RC2]) {
1893 for (j = 0; j < SIZE_NUM; j++) {
1894 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1896 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1897 RC2_cbc_encrypt(buf, buf,
1898 (unsigned long)lengths[j], &rc2_ks,
1901 print_result(D_CBC_RC2, j, count, d);
1905 # ifndef OPENSSL_NO_RC5
1906 if (doit[D_CBC_RC5]) {
1907 for (j = 0; j < SIZE_NUM; j++) {
1908 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1910 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1911 RC5_32_cbc_encrypt(buf, buf,
1912 (unsigned long)lengths[j], &rc5_ks,
1915 print_result(D_CBC_RC5, j, count, d);
1919 # ifndef OPENSSL_NO_BF
1920 if (doit[D_CBC_BF]) {
1921 for (j = 0; j < SIZE_NUM; j++) {
1922 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1924 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1925 BF_cbc_encrypt(buf, buf,
1926 (unsigned long)lengths[j], &bf_ks,
1929 print_result(D_CBC_BF, j, count, d);
1933 # ifndef OPENSSL_NO_CAST
1934 if (doit[D_CBC_CAST]) {
1935 for (j = 0; j < SIZE_NUM; j++) {
1936 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1938 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1939 CAST_cbc_encrypt(buf, buf,
1940 (unsigned long)lengths[j], &cast_ks,
1943 print_result(D_CBC_CAST, j, count, d);
1949 # ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1950 if (multiblock && evp_cipher) {
1952 (EVP_CIPHER_flags(evp_cipher) &
1953 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1954 fprintf(stderr, "%s is not multi-block capable\n",
1955 OBJ_nid2ln(evp_cipher->nid));
1958 multiblock_speed(evp_cipher);
1963 for (j = 0; j < SIZE_NUM; j++) {
1968 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1970 * -O3 -fschedule-insns messes up an optimization here!
1971 * names[D_EVP] somehow becomes NULL
1973 print_message(names[D_EVP], save_count, lengths[j]);
1975 EVP_CIPHER_CTX_init(&ctx);
1977 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1979 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1980 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1984 for (count = 0, run = 1;
1985 COND(save_count * 4 * lengths[0] / lengths[j]);
1987 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1989 for (count = 0, run = 1;
1990 COND(save_count * 4 * lengths[0] / lengths[j]);
1992 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1994 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1996 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1998 EVP_CIPHER_CTX_cleanup(&ctx);
2001 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2002 print_message(names[D_EVP], save_count, lengths[j]);
2005 for (count = 0, run = 1;
2006 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2007 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2011 print_result(D_EVP, j, count, d);
2015 RAND_pseudo_bytes(buf, 36);
2016 # ifndef OPENSSL_NO_RSA
2017 for (j = 0; j < RSA_NUM; j++) {
2021 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2024 "RSA sign failure. No RSA sign will be done.\n");
2025 ERR_print_errors(bio_err);
2028 pkey_print_message("private", "rsa",
2029 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2030 /* RSA_blinding_on(rsa_key[j],NULL); */
2032 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2033 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2034 &rsa_num, rsa_key[j]);
2036 BIO_printf(bio_err, "RSA sign failure\n");
2037 ERR_print_errors(bio_err);
2044 mr ? "+R1:%ld:%d:%.2f\n"
2045 : "%ld %d bit private RSA's in %.2fs\n",
2046 count, rsa_bits[j], d);
2047 rsa_results[j][0] = d / (double)count;
2052 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2055 "RSA verify failure. No RSA verify will be done.\n");
2056 ERR_print_errors(bio_err);
2059 pkey_print_message("public", "rsa",
2060 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2062 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2063 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2064 rsa_num, rsa_key[j]);
2066 BIO_printf(bio_err, "RSA verify failure\n");
2067 ERR_print_errors(bio_err);
2074 mr ? "+R2:%ld:%d:%.2f\n"
2075 : "%ld %d bit public RSA's in %.2fs\n",
2076 count, rsa_bits[j], d);
2077 rsa_results[j][1] = d / (double)count;
2081 if (rsa_count <= 1) {
2082 /* if longer than 10s, don't do any more */
2083 for (j++; j < RSA_NUM; j++)
2089 RAND_pseudo_bytes(buf, 20);
2090 # ifndef OPENSSL_NO_DSA
2091 if (RAND_status() != 1) {
2092 RAND_seed(rnd_seed, sizeof rnd_seed);
2095 for (j = 0; j < DSA_NUM; j++) {
2102 /* DSA_generate_key(dsa_key[j]); */
2103 /* DSA_sign_setup(dsa_key[j],NULL); */
2104 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2107 "DSA sign failure. No DSA sign will be done.\n");
2108 ERR_print_errors(bio_err);
2111 pkey_print_message("sign", "dsa",
2112 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2114 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2115 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2117 BIO_printf(bio_err, "DSA sign failure\n");
2118 ERR_print_errors(bio_err);
2125 mr ? "+R3:%ld:%d:%.2f\n"
2126 : "%ld %d bit DSA signs in %.2fs\n",
2127 count, dsa_bits[j], d);
2128 dsa_results[j][0] = d / (double)count;
2132 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2135 "DSA verify failure. No DSA verify will be done.\n");
2136 ERR_print_errors(bio_err);
2139 pkey_print_message("verify", "dsa",
2140 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2142 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2143 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2145 BIO_printf(bio_err, "DSA verify failure\n");
2146 ERR_print_errors(bio_err);
2153 mr ? "+R4:%ld:%d:%.2f\n"
2154 : "%ld %d bit DSA verify in %.2fs\n",
2155 count, dsa_bits[j], d);
2156 dsa_results[j][1] = d / (double)count;
2159 if (rsa_count <= 1) {
2160 /* if longer than 10s, don't do any more */
2161 for (j++; j < DSA_NUM; j++)
2169 # ifndef OPENSSL_NO_ECDSA
2170 if (RAND_status() != 1) {
2171 RAND_seed(rnd_seed, sizeof rnd_seed);
2174 for (j = 0; j < EC_NUM; j++) {
2178 continue; /* Ignore Curve */
2179 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2180 if (ecdsa[j] == NULL) {
2181 BIO_printf(bio_err, "ECDSA failure.\n");
2182 ERR_print_errors(bio_err);
2186 EC_KEY_precompute_mult(ecdsa[j], NULL);
2188 /* Perform ECDSA signature test */
2189 EC_KEY_generate_key(ecdsa[j]);
2190 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2193 "ECDSA sign failure. No ECDSA sign will be done.\n");
2194 ERR_print_errors(bio_err);
2197 pkey_print_message("sign", "ecdsa",
2199 test_curves_bits[j], ECDSA_SECONDS);
2202 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2203 ret = ECDSA_sign(0, buf, 20,
2204 ecdsasig, &ecdsasiglen, ecdsa[j]);
2206 BIO_printf(bio_err, "ECDSA sign failure\n");
2207 ERR_print_errors(bio_err);
2215 mr ? "+R5:%ld:%d:%.2f\n" :
2216 "%ld %d bit ECDSA signs in %.2fs \n",
2217 count, test_curves_bits[j], d);
2218 ecdsa_results[j][0] = d / (double)count;
2222 /* Perform ECDSA verification test */
2223 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2226 "ECDSA verify failure. No ECDSA verify will be done.\n");
2227 ERR_print_errors(bio_err);
2230 pkey_print_message("verify", "ecdsa",
2232 test_curves_bits[j], ECDSA_SECONDS);
2234 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2236 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2239 BIO_printf(bio_err, "ECDSA verify failure\n");
2240 ERR_print_errors(bio_err);
2247 mr ? "+R6:%ld:%d:%.2f\n"
2248 : "%ld %d bit ECDSA verify in %.2fs\n",
2249 count, test_curves_bits[j], d);
2250 ecdsa_results[j][1] = d / (double)count;
2253 if (rsa_count <= 1) {
2254 /* if longer than 10s, don't do any more */
2255 for (j++; j < EC_NUM; j++)
2264 # ifndef OPENSSL_NO_ECDH
2265 if (RAND_status() != 1) {
2266 RAND_seed(rnd_seed, sizeof rnd_seed);
2269 for (j = 0; j < EC_NUM; j++) {
2272 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2273 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2274 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2275 BIO_printf(bio_err, "ECDH failure.\n");
2276 ERR_print_errors(bio_err);
2279 /* generate two ECDH key pairs */
2280 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2281 !EC_KEY_generate_key(ecdh_b[j])) {
2282 BIO_printf(bio_err, "ECDH key generation failure.\n");
2283 ERR_print_errors(bio_err);
2287 * If field size is not more than 24 octets, then use SHA-1
2288 * hash of result; otherwise, use result (see section 4.8 of
2289 * draft-ietf-tls-ecc-03.txt).
2291 int field_size, outlen;
2292 void *(*kdf) (const void *in, size_t inlen, void *out,
2295 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2296 if (field_size <= 24 * 8) {
2297 outlen = KDF1_SHA1_len;
2300 outlen = (field_size + 7) / 8;
2304 ECDH_compute_key(secret_a, outlen,
2305 EC_KEY_get0_public_key(ecdh_b[j]),
2308 ECDH_compute_key(secret_b, outlen,
2309 EC_KEY_get0_public_key(ecdh_a[j]),
2311 if (secret_size_a != secret_size_b)
2316 for (secret_idx = 0; (secret_idx < secret_size_a)
2317 && (ecdh_checks == 1); secret_idx++) {
2318 if (secret_a[secret_idx] != secret_b[secret_idx])
2322 if (ecdh_checks == 0) {
2323 BIO_printf(bio_err, "ECDH computations don't match.\n");
2324 ERR_print_errors(bio_err);
2328 pkey_print_message("", "ecdh",
2330 test_curves_bits[j], ECDH_SECONDS);
2332 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2333 ECDH_compute_key(secret_a, outlen,
2334 EC_KEY_get0_public_key(ecdh_b[j]),
2339 mr ? "+R7:%ld:%d:%.2f\n" :
2340 "%ld %d-bit ECDH ops in %.2fs\n", count,
2341 test_curves_bits[j], d);
2342 ecdh_results[j][0] = d / (double)count;
2347 if (rsa_count <= 1) {
2348 /* if longer than 10s, don't do any more */
2349 for (j++; j < EC_NUM; j++)
2360 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2361 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2363 printf("%s ", BN_options());
2364 # ifndef OPENSSL_NO_MD2
2365 printf("%s ", MD2_options());
2367 # ifndef OPENSSL_NO_RC4
2368 printf("%s ", RC4_options());
2370 # ifndef OPENSSL_NO_DES
2371 printf("%s ", DES_options());
2373 # ifndef OPENSSL_NO_AES
2374 printf("%s ", AES_options());
2376 # ifndef OPENSSL_NO_IDEA
2377 printf("%s ", idea_options());
2379 # ifndef OPENSSL_NO_BF
2380 printf("%s ", BF_options());
2382 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2387 fprintf(stdout, "+H");
2390 "The 'numbers' are in 1000s of bytes per second processed.\n");
2391 fprintf(stdout, "type ");
2393 for (j = 0; j < SIZE_NUM; j++)
2394 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2395 fprintf(stdout, "\n");
2398 for (k = 0; k < ALGOR_NUM; k++) {
2402 fprintf(stdout, "+F:%d:%s", k, names[k]);
2404 fprintf(stdout, "%-13s", names[k]);
2405 for (j = 0; j < SIZE_NUM; j++) {
2406 if (results[k][j] > 10000 && !mr)
2407 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2409 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2411 fprintf(stdout, "\n");
2413 # ifndef OPENSSL_NO_RSA
2415 for (k = 0; k < RSA_NUM; k++) {
2419 printf("%18ssign verify sign/s verify/s\n", " ");
2423 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2424 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2426 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2427 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2428 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2431 # ifndef OPENSSL_NO_DSA
2433 for (k = 0; k < DSA_NUM; k++) {
2437 printf("%18ssign verify sign/s verify/s\n", " ");
2441 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2442 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2444 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2445 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2446 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2449 # ifndef OPENSSL_NO_ECDSA
2451 for (k = 0; k < EC_NUM; k++) {
2455 printf("%30ssign verify sign/s verify/s\n", " ");
2460 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2461 k, test_curves_bits[k],
2462 ecdsa_results[k][0], ecdsa_results[k][1]);
2465 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2466 test_curves_bits[k],
2467 test_curves_names[k],
2468 ecdsa_results[k][0], ecdsa_results[k][1],
2469 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2473 # ifndef OPENSSL_NO_ECDH
2475 for (k = 0; k < EC_NUM; k++) {
2479 printf("%30sop op/s\n", " ");
2483 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2484 k, test_curves_bits[k],
2485 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2488 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2489 test_curves_bits[k],
2490 test_curves_names[k],
2491 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2498 ERR_print_errors(bio_err);
2503 # ifndef OPENSSL_NO_RSA
2504 for (i = 0; i < RSA_NUM; i++)
2505 if (rsa_key[i] != NULL)
2506 RSA_free(rsa_key[i]);
2508 # ifndef OPENSSL_NO_DSA
2509 for (i = 0; i < DSA_NUM; i++)
2510 if (dsa_key[i] != NULL)
2511 DSA_free(dsa_key[i]);
2514 # ifndef OPENSSL_NO_ECDSA
2515 for (i = 0; i < EC_NUM; i++)
2516 if (ecdsa[i] != NULL)
2517 EC_KEY_free(ecdsa[i]);
2519 # ifndef OPENSSL_NO_ECDH
2520 for (i = 0; i < EC_NUM; i++) {
2521 if (ecdh_a[i] != NULL)
2522 EC_KEY_free(ecdh_a[i]);
2523 if (ecdh_b[i] != NULL)
2524 EC_KEY_free(ecdh_b[i]);
2533 static void print_message(const char *s, long num, int length)
2537 mr ? "+DT:%s:%d:%d\n"
2538 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2539 (void)BIO_flush(bio_err);
2543 mr ? "+DN:%s:%ld:%d\n"
2544 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2545 (void)BIO_flush(bio_err);
2552 static void pkey_print_message(const char *str, const char *str2, long num,
2557 mr ? "+DTP:%d:%s:%s:%d\n"
2558 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2559 (void)BIO_flush(bio_err);
2563 mr ? "+DNP:%ld:%d:%s:%s\n"
2564 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2565 (void)BIO_flush(bio_err);
2572 static void print_result(int alg, int run_no, int count, double time_used)
2575 mr ? "+R:%d:%s:%f\n"
2576 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2577 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2581 static char *sstrsep(char **string, const char *delim)
2584 char *token = *string;
2589 memset(isdelim, 0, sizeof isdelim);
2593 isdelim[(unsigned char)(*delim)] = 1;
2597 while (!isdelim[(unsigned char)(**string)]) {
2609 static int do_multi(int multi)
2614 static char sep[] = ":";
2616 fds = malloc(multi * sizeof *fds);
2618 fprintf(stderr, "Out of memory in speed (do_multi)\n");
2621 for (n = 0; n < multi; ++n) {
2622 if (pipe(fd) == -1) {
2623 fprintf(stderr, "pipe failure\n");
2634 if (dup(fd[1]) == -1) {
2635 fprintf(stderr, "dup failed\n");
2644 printf("Forked child %d\n", n);
2647 /* for now, assume the pipe is long enough to take all the output */
2648 for (n = 0; n < multi; ++n) {
2653 f = fdopen(fds[n], "r");
2654 while (fgets(buf, sizeof buf, f)) {
2655 p = strchr(buf, '\n');
2658 if (buf[0] != '+') {
2659 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2663 printf("Got: %s from %d\n", buf, n);
2664 if (!strncmp(buf, "+F:", 3)) {
2669 alg = atoi(sstrsep(&p, sep));
2671 for (j = 0; j < SIZE_NUM; ++j)
2672 results[alg][j] += atof(sstrsep(&p, sep));
2673 } else if (!strncmp(buf, "+F2:", 4)) {
2678 k = atoi(sstrsep(&p, sep));
2681 d = atof(sstrsep(&p, sep));
2683 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2685 rsa_results[k][0] = d;
2687 d = atof(sstrsep(&p, sep));
2689 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2691 rsa_results[k][1] = d;
2693 # ifndef OPENSSL_NO_DSA
2694 else if (!strncmp(buf, "+F3:", 4)) {
2699 k = atoi(sstrsep(&p, sep));
2702 d = atof(sstrsep(&p, sep));
2704 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2706 dsa_results[k][0] = d;
2708 d = atof(sstrsep(&p, sep));
2710 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2712 dsa_results[k][1] = d;
2715 # ifndef OPENSSL_NO_ECDSA
2716 else if (!strncmp(buf, "+F4:", 4)) {
2721 k = atoi(sstrsep(&p, sep));
2724 d = atof(sstrsep(&p, sep));
2726 ecdsa_results[k][0] =
2727 1 / (1 / ecdsa_results[k][0] + 1 / d);
2729 ecdsa_results[k][0] = d;
2731 d = atof(sstrsep(&p, sep));
2733 ecdsa_results[k][1] =
2734 1 / (1 / ecdsa_results[k][1] + 1 / d);
2736 ecdsa_results[k][1] = d;
2740 # ifndef OPENSSL_NO_ECDH
2741 else if (!strncmp(buf, "+F5:", 4)) {
2746 k = atoi(sstrsep(&p, sep));
2749 d = atof(sstrsep(&p, sep));
2751 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2753 ecdh_results[k][0] = d;
2758 else if (!strncmp(buf, "+H:", 3)) {
2760 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2770 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2772 static int mblengths[] =
2773 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2774 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2775 const char *alg_name;
2776 unsigned char *inp, *out, no_key[32], no_iv[16];
2780 inp = OPENSSL_malloc(mblengths[num - 1]);
2781 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2783 BIO_printf(bio_err,"Out of memory\n");
2788 EVP_CIPHER_CTX_init(&ctx);
2789 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2790 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2792 alg_name = OBJ_nid2ln(evp_cipher->nid);
2794 for (j = 0; j < num; j++) {
2795 print_message(alg_name, 0, mblengths[j]);
2797 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2798 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
2799 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2800 size_t len = mblengths[j];
2803 memset(aad, 0, 8); /* avoid uninitialized values */
2804 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2805 aad[9] = 3; /* version */
2807 aad[11] = 0; /* length */
2809 mb_param.out = NULL;
2812 mb_param.interleave = 8;
2814 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2815 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2816 sizeof(mb_param), &mb_param);
2822 EVP_CIPHER_CTX_ctrl(&ctx,
2823 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2824 sizeof(mb_param), &mb_param);
2828 RAND_bytes(out, 16);
2832 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2833 EVP_CTRL_AEAD_TLS1_AAD,
2834 EVP_AEAD_TLS1_AAD_LEN, aad);
2835 EVP_Cipher(&ctx, out, inp, len + pad);
2840 mr ? "+R:%d:%s:%f\n"
2841 : "%d %s's in %.2fs\n", count, "evp", d);
2842 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2846 fprintf(stdout, "+H");
2847 for (j = 0; j < num; j++)
2848 fprintf(stdout, ":%d", mblengths[j]);
2849 fprintf(stdout, "\n");
2850 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2851 for (j = 0; j < num; j++)
2852 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2853 fprintf(stdout, "\n");
2856 "The 'numbers' are in 1000s of bytes per second processed.\n");
2857 fprintf(stdout, "type ");
2858 for (j = 0; j < num; j++)
2859 fprintf(stdout, "%7d bytes", mblengths[j]);
2860 fprintf(stdout, "\n");
2861 fprintf(stdout, "%-24s", alg_name);
2863 for (j = 0; j < num; j++) {
2864 if (results[D_EVP][j] > 10000)
2865 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2867 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2869 fprintf(stdout, "\n");