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 volatile unsigned int lapse;
311 static volatile unsigned int schlock;
312 static void alarm_win32(unsigned int secs)
317 # define alarm alarm_win32
319 static DWORD WINAPI sleepy(VOID * arg)
327 static double Time_F(int s)
332 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
334 DWORD ret = GetLastError();
335 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
338 CloseHandle(thr); /* detach the thread */
340 Sleep(0); /* scheduler spinlock */
343 return app_tminterval(s, usertime);
347 static double Time_F(int s)
349 return app_tminterval(s, usertime);
353 # ifndef OPENSSL_NO_ECDH
354 static const int KDF1_SHA1_len = 20;
355 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
358 # ifndef OPENSSL_NO_SHA
359 if (*outlen < SHA_DIGEST_LENGTH)
362 *outlen = SHA_DIGEST_LENGTH;
363 return SHA1(in, inlen, out);
366 # endif /* OPENSSL_NO_SHA */
368 # endif /* OPENSSL_NO_ECDH */
370 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
372 int MAIN(int, char **);
374 int MAIN(int argc, char **argv)
377 unsigned char *buf = NULL, *buf2 = NULL;
379 long count = 0, save_count = 0;
381 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
384 # ifndef OPENSSL_NO_RSA
387 unsigned char md[EVP_MAX_MD_SIZE];
388 # ifndef OPENSSL_NO_MD2
389 unsigned char md2[MD2_DIGEST_LENGTH];
391 # ifndef OPENSSL_NO_MDC2
392 unsigned char mdc2[MDC2_DIGEST_LENGTH];
394 # ifndef OPENSSL_NO_MD4
395 unsigned char md4[MD4_DIGEST_LENGTH];
397 # ifndef OPENSSL_NO_MD5
398 unsigned char md5[MD5_DIGEST_LENGTH];
399 unsigned char hmac[MD5_DIGEST_LENGTH];
401 # ifndef OPENSSL_NO_SHA
402 unsigned char sha[SHA_DIGEST_LENGTH];
403 # ifndef OPENSSL_NO_SHA256
404 unsigned char sha256[SHA256_DIGEST_LENGTH];
406 # ifndef OPENSSL_NO_SHA512
407 unsigned char sha512[SHA512_DIGEST_LENGTH];
410 # ifndef OPENSSL_NO_WHIRLPOOL
411 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
413 # ifndef OPENSSL_NO_RIPEMD
414 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
416 # ifndef OPENSSL_NO_RC4
419 # ifndef OPENSSL_NO_RC5
422 # ifndef OPENSSL_NO_RC2
425 # ifndef OPENSSL_NO_IDEA
426 IDEA_KEY_SCHEDULE idea_ks;
428 # ifndef OPENSSL_NO_SEED
429 SEED_KEY_SCHEDULE seed_ks;
431 # ifndef OPENSSL_NO_BF
434 # ifndef OPENSSL_NO_CAST
437 static const unsigned char key16[16] = {
438 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
439 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
441 # ifndef OPENSSL_NO_AES
442 static const unsigned char key24[24] = {
443 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
444 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
445 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
447 static const unsigned char key32[32] = {
448 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
449 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
450 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
451 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
454 # ifndef OPENSSL_NO_CAMELLIA
455 static const unsigned char ckey24[24] = {
456 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
457 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
458 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
460 static const unsigned char ckey32[32] = {
461 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
462 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
463 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
464 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
467 # ifndef OPENSSL_NO_AES
468 # define MAX_BLOCK_SIZE 128
470 # define MAX_BLOCK_SIZE 64
472 unsigned char DES_iv[8];
473 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
474 # ifndef OPENSSL_NO_DES
475 static DES_cblock key =
476 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
477 static DES_cblock key2 =
478 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
479 static DES_cblock key3 =
480 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
481 DES_key_schedule sch;
482 DES_key_schedule sch2;
483 DES_key_schedule sch3;
485 # ifndef OPENSSL_NO_AES
486 AES_KEY aes_ks1, aes_ks2, aes_ks3;
488 # ifndef OPENSSL_NO_CAMELLIA
489 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
500 # define D_EDE3_DES 9
501 # define D_CBC_IDEA 10
502 # define D_CBC_SEED 11
503 # define D_CBC_RC2 12
504 # define D_CBC_RC5 13
506 # define D_CBC_CAST 15
507 # define D_CBC_128_AES 16
508 # define D_CBC_192_AES 17
509 # define D_CBC_256_AES 18
510 # define D_CBC_128_CML 19
511 # define D_CBC_192_CML 20
512 # define D_CBC_256_CML 21
516 # define D_WHIRLPOOL 25
517 # define D_IGE_128_AES 26
518 # define D_IGE_192_AES 27
519 # define D_IGE_256_AES 28
522 long c[ALGOR_NUM][SIZE_NUM];
524 # define R_DSA_1024 1
525 # define R_DSA_2048 2
527 # define R_RSA_1024 1
528 # define R_RSA_2048 2
529 # define R_RSA_4096 3
541 # define R_EC_K571 10
542 # define R_EC_B163 11
543 # define R_EC_B233 12
544 # define R_EC_B283 13
545 # define R_EC_B409 14
546 # define R_EC_B571 15
548 # ifndef OPENSSL_NO_RSA
549 RSA *rsa_key[RSA_NUM];
550 long rsa_c[RSA_NUM][2];
551 static unsigned int rsa_bits[RSA_NUM] = {
552 512, 1024, 2048, 4096
554 static unsigned char *rsa_data[RSA_NUM] = {
555 test512, test1024, test2048, test4096
557 static int rsa_data_length[RSA_NUM] = {
558 sizeof(test512), sizeof(test1024),
559 sizeof(test2048), sizeof(test4096)
562 # ifndef OPENSSL_NO_DSA
563 DSA *dsa_key[DSA_NUM];
564 long dsa_c[DSA_NUM][2];
565 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
567 # ifndef OPENSSL_NO_EC
569 * We only test over the following curves as they are representative, To
570 * add tests over more curves, simply add the curve NID and curve name to
571 * the following arrays and increase the EC_NUM value accordingly.
573 static unsigned int test_curves[EC_NUM] = {
576 NID_X9_62_prime192v1,
578 NID_X9_62_prime256v1,
593 static const char *test_curves_names[EC_NUM] = {
613 static int test_curves_bits[EC_NUM] = {
614 160, 192, 224, 256, 384, 521,
615 163, 233, 283, 409, 571,
616 163, 233, 283, 409, 571
621 # ifndef OPENSSL_NO_ECDSA
622 unsigned char ecdsasig[256];
623 unsigned int ecdsasiglen;
624 EC_KEY *ecdsa[EC_NUM];
625 long ecdsa_c[EC_NUM][2];
628 # ifndef OPENSSL_NO_ECDH
629 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
630 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
631 int secret_size_a, secret_size_b;
634 long ecdh_c[EC_NUM][2];
637 int rsa_doit[RSA_NUM];
638 int dsa_doit[DSA_NUM];
639 # ifndef OPENSSL_NO_ECDSA
640 int ecdsa_doit[EC_NUM];
642 # ifndef OPENSSL_NO_ECDH
643 int ecdh_doit[EC_NUM];
647 const EVP_CIPHER *evp_cipher = NULL;
648 const EVP_MD *evp_md = NULL;
660 memset(results, 0, sizeof(results));
661 # ifndef OPENSSL_NO_DSA
662 memset(dsa_key, 0, sizeof(dsa_key));
664 # ifndef OPENSSL_NO_ECDSA
665 for (i = 0; i < EC_NUM; i++)
668 # ifndef OPENSSL_NO_ECDH
669 for (i = 0; i < EC_NUM; i++) {
674 # ifndef OPENSSL_NO_RSA
675 for (i = 0; i < RSA_NUM; i++)
680 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
681 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
683 if (!load_config(bio_err, NULL))
686 if ((buf = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
687 BIO_printf(bio_err, "out of memory\n");
690 if ((buf2 = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
691 BIO_printf(bio_err, "out of memory\n");
695 memset(c, 0, sizeof(c));
696 memset(DES_iv, 0, sizeof(DES_iv));
697 memset(iv, 0, sizeof(iv));
699 for (i = 0; i < ALGOR_NUM; i++)
701 for (i = 0; i < RSA_NUM; i++)
703 for (i = 0; i < DSA_NUM; i++)
705 # ifndef OPENSSL_NO_ECDSA
706 for (i = 0; i < EC_NUM; i++)
709 # ifndef OPENSSL_NO_ECDH
710 for (i = 0; i < EC_NUM; i++)
718 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
720 j--; /* Otherwise, -elapsed gets confused with an
722 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
726 BIO_printf(bio_err, "no EVP given\n");
730 evp_cipher = EVP_get_cipherbyname(*argv);
732 evp_md = EVP_get_digestbyname(*argv);
734 if (!evp_cipher && !evp_md) {
735 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
740 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
742 j--; /* Otherwise, -elapsed gets confused with an
745 # ifndef OPENSSL_NO_ENGINE
746 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
750 BIO_printf(bio_err, "no engine given\n");
753 e = setup_engine(bio_err, *argv, 0);
755 * j will be increased again further down. We just don't want
756 * speed to confuse an engine with an algorithm, especially when
757 * none is given (which means all of them should be run)
763 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
767 BIO_printf(bio_err, "no multi count given\n");
770 multi = atoi(argv[0]);
772 BIO_printf(bio_err, "bad multi count\n");
775 j--; /* Otherwise, -mr gets confused with an
779 else if (argc > 0 && !strcmp(*argv, "-mr")) {
781 j--; /* Otherwise, -mr gets confused with an
783 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
787 # ifndef OPENSSL_NO_MD2
788 if (strcmp(*argv, "md2") == 0)
792 # ifndef OPENSSL_NO_MDC2
793 if (strcmp(*argv, "mdc2") == 0)
797 # ifndef OPENSSL_NO_MD4
798 if (strcmp(*argv, "md4") == 0)
802 # ifndef OPENSSL_NO_MD5
803 if (strcmp(*argv, "md5") == 0)
807 # ifndef OPENSSL_NO_MD5
808 if (strcmp(*argv, "hmac") == 0)
812 # ifndef OPENSSL_NO_SHA
813 if (strcmp(*argv, "sha1") == 0)
815 else if (strcmp(*argv, "sha") == 0)
816 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
818 # ifndef OPENSSL_NO_SHA256
819 if (strcmp(*argv, "sha256") == 0)
823 # ifndef OPENSSL_NO_SHA512
824 if (strcmp(*argv, "sha512") == 0)
829 # ifndef OPENSSL_NO_WHIRLPOOL
830 if (strcmp(*argv, "whirlpool") == 0)
831 doit[D_WHIRLPOOL] = 1;
834 # ifndef OPENSSL_NO_RIPEMD
835 if (strcmp(*argv, "ripemd") == 0)
837 else if (strcmp(*argv, "rmd160") == 0)
839 else if (strcmp(*argv, "ripemd160") == 0)
843 # ifndef OPENSSL_NO_RC4
844 if (strcmp(*argv, "rc4") == 0)
848 # ifndef OPENSSL_NO_DES
849 if (strcmp(*argv, "des-cbc") == 0)
851 else if (strcmp(*argv, "des-ede3") == 0)
852 doit[D_EDE3_DES] = 1;
855 # ifndef OPENSSL_NO_AES
856 if (strcmp(*argv, "aes-128-cbc") == 0)
857 doit[D_CBC_128_AES] = 1;
858 else if (strcmp(*argv, "aes-192-cbc") == 0)
859 doit[D_CBC_192_AES] = 1;
860 else if (strcmp(*argv, "aes-256-cbc") == 0)
861 doit[D_CBC_256_AES] = 1;
862 else if (strcmp(*argv, "aes-128-ige") == 0)
863 doit[D_IGE_128_AES] = 1;
864 else if (strcmp(*argv, "aes-192-ige") == 0)
865 doit[D_IGE_192_AES] = 1;
866 else if (strcmp(*argv, "aes-256-ige") == 0)
867 doit[D_IGE_256_AES] = 1;
870 # ifndef OPENSSL_NO_CAMELLIA
871 if (strcmp(*argv, "camellia-128-cbc") == 0)
872 doit[D_CBC_128_CML] = 1;
873 else if (strcmp(*argv, "camellia-192-cbc") == 0)
874 doit[D_CBC_192_CML] = 1;
875 else if (strcmp(*argv, "camellia-256-cbc") == 0)
876 doit[D_CBC_256_CML] = 1;
879 # ifndef OPENSSL_NO_RSA
880 # if 0 /* was: #ifdef RSAref */
881 if (strcmp(*argv, "rsaref") == 0) {
882 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
887 if (strcmp(*argv, "openssl") == 0) {
888 RSA_set_default_method(RSA_PKCS1_SSLeay());
892 # endif /* !OPENSSL_NO_RSA */
893 if (strcmp(*argv, "dsa512") == 0)
894 dsa_doit[R_DSA_512] = 2;
895 else if (strcmp(*argv, "dsa1024") == 0)
896 dsa_doit[R_DSA_1024] = 2;
897 else if (strcmp(*argv, "dsa2048") == 0)
898 dsa_doit[R_DSA_2048] = 2;
899 else if (strcmp(*argv, "rsa512") == 0)
900 rsa_doit[R_RSA_512] = 2;
901 else if (strcmp(*argv, "rsa1024") == 0)
902 rsa_doit[R_RSA_1024] = 2;
903 else if (strcmp(*argv, "rsa2048") == 0)
904 rsa_doit[R_RSA_2048] = 2;
905 else if (strcmp(*argv, "rsa4096") == 0)
906 rsa_doit[R_RSA_4096] = 2;
908 # ifndef OPENSSL_NO_RC2
909 if (strcmp(*argv, "rc2-cbc") == 0)
911 else if (strcmp(*argv, "rc2") == 0)
915 # ifndef OPENSSL_NO_RC5
916 if (strcmp(*argv, "rc5-cbc") == 0)
918 else if (strcmp(*argv, "rc5") == 0)
922 # ifndef OPENSSL_NO_IDEA
923 if (strcmp(*argv, "idea-cbc") == 0)
924 doit[D_CBC_IDEA] = 1;
925 else if (strcmp(*argv, "idea") == 0)
926 doit[D_CBC_IDEA] = 1;
929 # ifndef OPENSSL_NO_SEED
930 if (strcmp(*argv, "seed-cbc") == 0)
931 doit[D_CBC_SEED] = 1;
932 else if (strcmp(*argv, "seed") == 0)
933 doit[D_CBC_SEED] = 1;
936 # ifndef OPENSSL_NO_BF
937 if (strcmp(*argv, "bf-cbc") == 0)
939 else if (strcmp(*argv, "blowfish") == 0)
941 else if (strcmp(*argv, "bf") == 0)
945 # ifndef OPENSSL_NO_CAST
946 if (strcmp(*argv, "cast-cbc") == 0)
947 doit[D_CBC_CAST] = 1;
948 else if (strcmp(*argv, "cast") == 0)
949 doit[D_CBC_CAST] = 1;
950 else if (strcmp(*argv, "cast5") == 0)
951 doit[D_CBC_CAST] = 1;
954 # ifndef OPENSSL_NO_DES
955 if (strcmp(*argv, "des") == 0) {
957 doit[D_EDE3_DES] = 1;
960 # ifndef OPENSSL_NO_AES
961 if (strcmp(*argv, "aes") == 0) {
962 doit[D_CBC_128_AES] = 1;
963 doit[D_CBC_192_AES] = 1;
964 doit[D_CBC_256_AES] = 1;
965 } else if (strcmp(*argv, "ghash") == 0) {
969 # ifndef OPENSSL_NO_CAMELLIA
970 if (strcmp(*argv, "camellia") == 0) {
971 doit[D_CBC_128_CML] = 1;
972 doit[D_CBC_192_CML] = 1;
973 doit[D_CBC_256_CML] = 1;
976 # ifndef OPENSSL_NO_RSA
977 if (strcmp(*argv, "rsa") == 0) {
978 rsa_doit[R_RSA_512] = 1;
979 rsa_doit[R_RSA_1024] = 1;
980 rsa_doit[R_RSA_2048] = 1;
981 rsa_doit[R_RSA_4096] = 1;
984 # ifndef OPENSSL_NO_DSA
985 if (strcmp(*argv, "dsa") == 0) {
986 dsa_doit[R_DSA_512] = 1;
987 dsa_doit[R_DSA_1024] = 1;
988 dsa_doit[R_DSA_2048] = 1;
991 # ifndef OPENSSL_NO_ECDSA
992 if (strcmp(*argv, "ecdsap160") == 0)
993 ecdsa_doit[R_EC_P160] = 2;
994 else if (strcmp(*argv, "ecdsap192") == 0)
995 ecdsa_doit[R_EC_P192] = 2;
996 else if (strcmp(*argv, "ecdsap224") == 0)
997 ecdsa_doit[R_EC_P224] = 2;
998 else if (strcmp(*argv, "ecdsap256") == 0)
999 ecdsa_doit[R_EC_P256] = 2;
1000 else if (strcmp(*argv, "ecdsap384") == 0)
1001 ecdsa_doit[R_EC_P384] = 2;
1002 else if (strcmp(*argv, "ecdsap521") == 0)
1003 ecdsa_doit[R_EC_P521] = 2;
1004 else if (strcmp(*argv, "ecdsak163") == 0)
1005 ecdsa_doit[R_EC_K163] = 2;
1006 else if (strcmp(*argv, "ecdsak233") == 0)
1007 ecdsa_doit[R_EC_K233] = 2;
1008 else if (strcmp(*argv, "ecdsak283") == 0)
1009 ecdsa_doit[R_EC_K283] = 2;
1010 else if (strcmp(*argv, "ecdsak409") == 0)
1011 ecdsa_doit[R_EC_K409] = 2;
1012 else if (strcmp(*argv, "ecdsak571") == 0)
1013 ecdsa_doit[R_EC_K571] = 2;
1014 else if (strcmp(*argv, "ecdsab163") == 0)
1015 ecdsa_doit[R_EC_B163] = 2;
1016 else if (strcmp(*argv, "ecdsab233") == 0)
1017 ecdsa_doit[R_EC_B233] = 2;
1018 else if (strcmp(*argv, "ecdsab283") == 0)
1019 ecdsa_doit[R_EC_B283] = 2;
1020 else if (strcmp(*argv, "ecdsab409") == 0)
1021 ecdsa_doit[R_EC_B409] = 2;
1022 else if (strcmp(*argv, "ecdsab571") == 0)
1023 ecdsa_doit[R_EC_B571] = 2;
1024 else if (strcmp(*argv, "ecdsa") == 0) {
1025 for (i = 0; i < EC_NUM; i++)
1029 # ifndef OPENSSL_NO_ECDH
1030 if (strcmp(*argv, "ecdhp160") == 0)
1031 ecdh_doit[R_EC_P160] = 2;
1032 else if (strcmp(*argv, "ecdhp192") == 0)
1033 ecdh_doit[R_EC_P192] = 2;
1034 else if (strcmp(*argv, "ecdhp224") == 0)
1035 ecdh_doit[R_EC_P224] = 2;
1036 else if (strcmp(*argv, "ecdhp256") == 0)
1037 ecdh_doit[R_EC_P256] = 2;
1038 else if (strcmp(*argv, "ecdhp384") == 0)
1039 ecdh_doit[R_EC_P384] = 2;
1040 else if (strcmp(*argv, "ecdhp521") == 0)
1041 ecdh_doit[R_EC_P521] = 2;
1042 else if (strcmp(*argv, "ecdhk163") == 0)
1043 ecdh_doit[R_EC_K163] = 2;
1044 else if (strcmp(*argv, "ecdhk233") == 0)
1045 ecdh_doit[R_EC_K233] = 2;
1046 else if (strcmp(*argv, "ecdhk283") == 0)
1047 ecdh_doit[R_EC_K283] = 2;
1048 else if (strcmp(*argv, "ecdhk409") == 0)
1049 ecdh_doit[R_EC_K409] = 2;
1050 else if (strcmp(*argv, "ecdhk571") == 0)
1051 ecdh_doit[R_EC_K571] = 2;
1052 else if (strcmp(*argv, "ecdhb163") == 0)
1053 ecdh_doit[R_EC_B163] = 2;
1054 else if (strcmp(*argv, "ecdhb233") == 0)
1055 ecdh_doit[R_EC_B233] = 2;
1056 else if (strcmp(*argv, "ecdhb283") == 0)
1057 ecdh_doit[R_EC_B283] = 2;
1058 else if (strcmp(*argv, "ecdhb409") == 0)
1059 ecdh_doit[R_EC_B409] = 2;
1060 else if (strcmp(*argv, "ecdhb571") == 0)
1061 ecdh_doit[R_EC_B571] = 2;
1062 else if (strcmp(*argv, "ecdh") == 0) {
1063 for (i = 0; i < EC_NUM; i++)
1068 BIO_printf(bio_err, "Error: bad option or value\n");
1069 BIO_printf(bio_err, "\n");
1070 BIO_printf(bio_err, "Available values:\n");
1071 # ifndef OPENSSL_NO_MD2
1072 BIO_printf(bio_err, "md2 ");
1074 # ifndef OPENSSL_NO_MDC2
1075 BIO_printf(bio_err, "mdc2 ");
1077 # ifndef OPENSSL_NO_MD4
1078 BIO_printf(bio_err, "md4 ");
1080 # ifndef OPENSSL_NO_MD5
1081 BIO_printf(bio_err, "md5 ");
1082 # ifndef OPENSSL_NO_HMAC
1083 BIO_printf(bio_err, "hmac ");
1086 # ifndef OPENSSL_NO_SHA1
1087 BIO_printf(bio_err, "sha1 ");
1089 # ifndef OPENSSL_NO_SHA256
1090 BIO_printf(bio_err, "sha256 ");
1092 # ifndef OPENSSL_NO_SHA512
1093 BIO_printf(bio_err, "sha512 ");
1095 # ifndef OPENSSL_NO_WHIRLPOOL
1096 BIO_printf(bio_err, "whirlpool");
1098 # ifndef OPENSSL_NO_RIPEMD160
1099 BIO_printf(bio_err, "rmd160");
1101 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1102 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1103 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1104 !defined(OPENSSL_NO_WHIRLPOOL)
1105 BIO_printf(bio_err, "\n");
1108 # ifndef OPENSSL_NO_IDEA
1109 BIO_printf(bio_err, "idea-cbc ");
1111 # ifndef OPENSSL_NO_SEED
1112 BIO_printf(bio_err, "seed-cbc ");
1114 # ifndef OPENSSL_NO_RC2
1115 BIO_printf(bio_err, "rc2-cbc ");
1117 # ifndef OPENSSL_NO_RC5
1118 BIO_printf(bio_err, "rc5-cbc ");
1120 # ifndef OPENSSL_NO_BF
1121 BIO_printf(bio_err, "bf-cbc");
1123 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1124 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1125 BIO_printf(bio_err, "\n");
1127 # ifndef OPENSSL_NO_DES
1128 BIO_printf(bio_err, "des-cbc des-ede3 ");
1130 # ifndef OPENSSL_NO_AES
1131 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1132 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1134 # ifndef OPENSSL_NO_CAMELLIA
1135 BIO_printf(bio_err, "\n");
1137 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1139 # ifndef OPENSSL_NO_RC4
1140 BIO_printf(bio_err, "rc4");
1142 BIO_printf(bio_err, "\n");
1144 # ifndef OPENSSL_NO_RSA
1145 BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
1148 # ifndef OPENSSL_NO_DSA
1149 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1151 # ifndef OPENSSL_NO_ECDSA
1152 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1153 "ecdsap256 ecdsap384 ecdsap521\n");
1155 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1157 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1158 BIO_printf(bio_err, "ecdsa\n");
1160 # ifndef OPENSSL_NO_ECDH
1161 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1162 "ecdhp256 ecdhp384 ecdhp521\n");
1164 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1166 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1167 BIO_printf(bio_err, "ecdh\n");
1170 # ifndef OPENSSL_NO_IDEA
1171 BIO_printf(bio_err, "idea ");
1173 # ifndef OPENSSL_NO_SEED
1174 BIO_printf(bio_err, "seed ");
1176 # ifndef OPENSSL_NO_RC2
1177 BIO_printf(bio_err, "rc2 ");
1179 # ifndef OPENSSL_NO_DES
1180 BIO_printf(bio_err, "des ");
1182 # ifndef OPENSSL_NO_AES
1183 BIO_printf(bio_err, "aes ");
1185 # ifndef OPENSSL_NO_CAMELLIA
1186 BIO_printf(bio_err, "camellia ");
1188 # ifndef OPENSSL_NO_RSA
1189 BIO_printf(bio_err, "rsa ");
1191 # ifndef OPENSSL_NO_BF
1192 BIO_printf(bio_err, "blowfish");
1194 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1195 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1196 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1197 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1198 BIO_printf(bio_err, "\n");
1201 BIO_printf(bio_err, "\n");
1202 BIO_printf(bio_err, "Available options:\n");
1203 # if defined(TIMES) || defined(USE_TOD)
1204 BIO_printf(bio_err, "-elapsed "
1205 "measure time in real time instead of CPU user time.\n");
1207 # ifndef OPENSSL_NO_ENGINE
1210 "use engine e, possibly a hardware device.\n");
1212 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1215 "time decryption instead of encryption (only EVP).\n");
1218 "produce machine readable output.\n");
1221 "-multi n " "run n benchmarks in parallel.\n");
1231 if (multi && do_multi(multi))
1236 for (i = 0; i < ALGOR_NUM; i++) {
1240 for (i = 0; i < RSA_NUM; i++)
1242 for (i = 0; i < DSA_NUM; i++)
1244 # ifndef OPENSSL_NO_ECDSA
1245 for (i = 0; i < EC_NUM; i++)
1248 # ifndef OPENSSL_NO_ECDH
1249 for (i = 0; i < EC_NUM; i++)
1253 for (i = 0; i < ALGOR_NUM; i++)
1257 if (usertime == 0 && !mr)
1259 "You have chosen to measure elapsed time "
1260 "instead of user CPU time.\n");
1262 # ifndef OPENSSL_NO_RSA
1263 for (i = 0; i < RSA_NUM; i++) {
1264 const unsigned char *p;
1267 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1268 if (rsa_key[i] == NULL) {
1269 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1277 : "Loaded RSA key, %d bit modulus and e= 0x",
1278 BN_num_bits(rsa_key[i]->n));
1279 BN_print(bio_err, rsa_key[i]->e);
1280 BIO_printf(bio_err, "\n");
1286 # ifndef OPENSSL_NO_DSA
1287 dsa_key[0] = get_dsa512();
1288 dsa_key[1] = get_dsa1024();
1289 dsa_key[2] = get_dsa2048();
1292 # ifndef OPENSSL_NO_DES
1293 DES_set_key_unchecked(&key, &sch);
1294 DES_set_key_unchecked(&key2, &sch2);
1295 DES_set_key_unchecked(&key3, &sch3);
1297 # ifndef OPENSSL_NO_AES
1298 AES_set_encrypt_key(key16, 128, &aes_ks1);
1299 AES_set_encrypt_key(key24, 192, &aes_ks2);
1300 AES_set_encrypt_key(key32, 256, &aes_ks3);
1302 # ifndef OPENSSL_NO_CAMELLIA
1303 Camellia_set_key(key16, 128, &camellia_ks1);
1304 Camellia_set_key(ckey24, 192, &camellia_ks2);
1305 Camellia_set_key(ckey32, 256, &camellia_ks3);
1307 # ifndef OPENSSL_NO_IDEA
1308 idea_set_encrypt_key(key16, &idea_ks);
1310 # ifndef OPENSSL_NO_SEED
1311 SEED_set_key(key16, &seed_ks);
1313 # ifndef OPENSSL_NO_RC4
1314 RC4_set_key(&rc4_ks, 16, key16);
1316 # ifndef OPENSSL_NO_RC2
1317 RC2_set_key(&rc2_ks, 16, key16, 128);
1319 # ifndef OPENSSL_NO_RC5
1320 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1322 # ifndef OPENSSL_NO_BF
1323 BF_set_key(&bf_ks, 16, key16);
1325 # ifndef OPENSSL_NO_CAST
1326 CAST_set_key(&cast_ks, 16, key16);
1328 # ifndef OPENSSL_NO_RSA
1329 memset(rsa_c, 0, sizeof(rsa_c));
1332 # ifndef OPENSSL_NO_DES
1333 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1339 for (it = count; it; it--)
1340 DES_ecb_encrypt((DES_cblock *)buf,
1341 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1345 c[D_MD2][0] = count / 10;
1346 c[D_MDC2][0] = count / 10;
1347 c[D_MD4][0] = count;
1348 c[D_MD5][0] = count;
1349 c[D_HMAC][0] = count;
1350 c[D_SHA1][0] = count;
1351 c[D_RMD160][0] = count;
1352 c[D_RC4][0] = count * 5;
1353 c[D_CBC_DES][0] = count;
1354 c[D_EDE3_DES][0] = count / 3;
1355 c[D_CBC_IDEA][0] = count;
1356 c[D_CBC_SEED][0] = count;
1357 c[D_CBC_RC2][0] = count;
1358 c[D_CBC_RC5][0] = count;
1359 c[D_CBC_BF][0] = count;
1360 c[D_CBC_CAST][0] = count;
1361 c[D_CBC_128_AES][0] = count;
1362 c[D_CBC_192_AES][0] = count;
1363 c[D_CBC_256_AES][0] = count;
1364 c[D_CBC_128_CML][0] = count;
1365 c[D_CBC_192_CML][0] = count;
1366 c[D_CBC_256_CML][0] = count;
1367 c[D_SHA256][0] = count;
1368 c[D_SHA512][0] = count;
1369 c[D_WHIRLPOOL][0] = count;
1370 c[D_IGE_128_AES][0] = count;
1371 c[D_IGE_192_AES][0] = count;
1372 c[D_IGE_256_AES][0] = count;
1373 c[D_GHASH][0] = count;
1375 for (i = 1; i < SIZE_NUM; i++) {
1376 c[D_MD2][i] = c[D_MD2][0] * 4 * lengths[0] / lengths[i];
1377 c[D_MDC2][i] = c[D_MDC2][0] * 4 * lengths[0] / lengths[i];
1378 c[D_MD4][i] = c[D_MD4][0] * 4 * lengths[0] / lengths[i];
1379 c[D_MD5][i] = c[D_MD5][0] * 4 * lengths[0] / lengths[i];
1380 c[D_HMAC][i] = c[D_HMAC][0] * 4 * lengths[0] / lengths[i];
1381 c[D_SHA1][i] = c[D_SHA1][0] * 4 * lengths[0] / lengths[i];
1382 c[D_RMD160][i] = c[D_RMD160][0] * 4 * lengths[0] / lengths[i];
1383 c[D_SHA256][i] = c[D_SHA256][0] * 4 * lengths[0] / lengths[i];
1384 c[D_SHA512][i] = c[D_SHA512][0] * 4 * lengths[0] / lengths[i];
1385 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * lengths[0] / lengths[i];
1387 for (i = 1; i < SIZE_NUM; i++) {
1390 l0 = (long)lengths[i - 1];
1391 l1 = (long)lengths[i];
1392 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1393 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1394 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1395 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1396 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1397 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1398 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1399 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1400 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1401 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1402 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1403 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1404 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1405 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1406 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1407 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1408 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1409 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1411 # ifndef OPENSSL_NO_RSA
1412 rsa_c[R_RSA_512][0] = count / 2000;
1413 rsa_c[R_RSA_512][1] = count / 400;
1414 for (i = 1; i < RSA_NUM; i++) {
1415 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1416 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1417 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1420 if (rsa_c[i][0] == 0) {
1428 # ifndef OPENSSL_NO_DSA
1429 dsa_c[R_DSA_512][0] = count / 1000;
1430 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1431 for (i = 1; i < DSA_NUM; i++) {
1432 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1433 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1434 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1437 if (dsa_c[i] == 0) {
1445 # ifndef OPENSSL_NO_ECDSA
1446 ecdsa_c[R_EC_P160][0] = count / 1000;
1447 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1448 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1449 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1450 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1451 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1454 if (ecdsa_c[i] == 0) {
1460 ecdsa_c[R_EC_K163][0] = count / 1000;
1461 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1462 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1463 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1464 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1465 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1468 if (ecdsa_c[i] == 0) {
1474 ecdsa_c[R_EC_B163][0] = count / 1000;
1475 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1476 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1477 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1478 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1479 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1482 if (ecdsa_c[i] == 0) {
1490 # ifndef OPENSSL_NO_ECDH
1491 ecdh_c[R_EC_P160][0] = count / 1000;
1492 ecdh_c[R_EC_P160][1] = count / 1000;
1493 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1494 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1495 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1496 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1499 if (ecdh_c[i] == 0) {
1505 ecdh_c[R_EC_K163][0] = count / 1000;
1506 ecdh_c[R_EC_K163][1] = count / 1000;
1507 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1508 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1509 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1510 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1513 if (ecdh_c[i] == 0) {
1519 ecdh_c[R_EC_B163][0] = count / 1000;
1520 ecdh_c[R_EC_B163][1] = count / 1000;
1521 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1522 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1523 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1524 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1527 if (ecdh_c[i] == 0) {
1535 # define COND(d) (count < (d))
1536 # define COUNT(d) (d)
1538 /* not worth fixing */
1539 # error "You cannot disable DES on systems without SIGALRM."
1540 # endif /* OPENSSL_NO_DES */
1542 # define COND(c) (run && count<0x7fffffff)
1543 # define COUNT(d) (count)
1545 signal(SIGALRM, sig_done);
1547 # endif /* SIGALRM */
1549 # ifndef OPENSSL_NO_MD2
1551 for (j = 0; j < SIZE_NUM; j++) {
1552 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1554 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1555 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1558 print_result(D_MD2, j, count, d);
1562 # ifndef OPENSSL_NO_MDC2
1564 for (j = 0; j < SIZE_NUM; j++) {
1565 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1567 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1568 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1571 print_result(D_MDC2, j, count, d);
1576 # ifndef OPENSSL_NO_MD4
1578 for (j = 0; j < SIZE_NUM; j++) {
1579 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1581 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1582 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1583 NULL, EVP_md4(), NULL);
1585 print_result(D_MD4, j, count, d);
1590 # ifndef OPENSSL_NO_MD5
1592 for (j = 0; j < SIZE_NUM; j++) {
1593 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1595 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1596 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md5[0]),
1597 NULL, EVP_get_digestbyname("md5"), NULL);
1599 print_result(D_MD5, j, count, d);
1604 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1608 HMAC_CTX_init(&hctx);
1609 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1610 16, EVP_md5(), NULL);
1612 for (j = 0; j < SIZE_NUM; j++) {
1613 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1615 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1616 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1617 HMAC_Update(&hctx, buf, lengths[j]);
1618 HMAC_Final(&hctx, &(hmac[0]), NULL);
1621 print_result(D_HMAC, j, count, d);
1623 HMAC_CTX_cleanup(&hctx);
1626 # ifndef OPENSSL_NO_SHA
1628 for (j = 0; j < SIZE_NUM; j++) {
1629 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1631 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1632 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1635 print_result(D_SHA1, j, count, d);
1638 # ifndef OPENSSL_NO_SHA256
1639 if (doit[D_SHA256]) {
1640 for (j = 0; j < SIZE_NUM; j++) {
1641 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1643 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1644 SHA256(buf, lengths[j], sha256);
1646 print_result(D_SHA256, j, count, d);
1651 # ifndef OPENSSL_NO_SHA512
1652 if (doit[D_SHA512]) {
1653 for (j = 0; j < SIZE_NUM; j++) {
1654 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1656 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1657 SHA512(buf, lengths[j], sha512);
1659 print_result(D_SHA512, j, count, d);
1665 # ifndef OPENSSL_NO_WHIRLPOOL
1666 if (doit[D_WHIRLPOOL]) {
1667 for (j = 0; j < SIZE_NUM; j++) {
1668 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1670 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1671 WHIRLPOOL(buf, lengths[j], whirlpool);
1673 print_result(D_WHIRLPOOL, j, count, d);
1678 # ifndef OPENSSL_NO_RIPEMD
1679 if (doit[D_RMD160]) {
1680 for (j = 0; j < SIZE_NUM; j++) {
1681 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1683 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1684 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1685 EVP_ripemd160(), NULL);
1687 print_result(D_RMD160, j, count, d);
1691 # ifndef OPENSSL_NO_RC4
1693 for (j = 0; j < SIZE_NUM; j++) {
1694 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1696 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1697 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1699 print_result(D_RC4, j, count, d);
1703 # ifndef OPENSSL_NO_DES
1704 if (doit[D_CBC_DES]) {
1705 for (j = 0; j < SIZE_NUM; j++) {
1706 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1708 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1709 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1710 &DES_iv, DES_ENCRYPT);
1712 print_result(D_CBC_DES, j, count, d);
1716 if (doit[D_EDE3_DES]) {
1717 for (j = 0; j < SIZE_NUM; j++) {
1718 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1720 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1721 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1723 &DES_iv, DES_ENCRYPT);
1725 print_result(D_EDE3_DES, j, count, d);
1729 # ifndef OPENSSL_NO_AES
1730 if (doit[D_CBC_128_AES]) {
1731 for (j = 0; j < SIZE_NUM; j++) {
1732 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1735 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1736 AES_cbc_encrypt(buf, buf,
1737 (unsigned long)lengths[j], &aes_ks1,
1740 print_result(D_CBC_128_AES, j, count, d);
1743 if (doit[D_CBC_192_AES]) {
1744 for (j = 0; j < SIZE_NUM; j++) {
1745 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1748 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1749 AES_cbc_encrypt(buf, buf,
1750 (unsigned long)lengths[j], &aes_ks2,
1753 print_result(D_CBC_192_AES, j, count, d);
1756 if (doit[D_CBC_256_AES]) {
1757 for (j = 0; j < SIZE_NUM; j++) {
1758 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1761 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1762 AES_cbc_encrypt(buf, buf,
1763 (unsigned long)lengths[j], &aes_ks3,
1766 print_result(D_CBC_256_AES, j, count, d);
1770 if (doit[D_IGE_128_AES]) {
1771 for (j = 0; j < SIZE_NUM; j++) {
1772 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1775 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1776 AES_ige_encrypt(buf, buf2,
1777 (unsigned long)lengths[j], &aes_ks1,
1780 print_result(D_IGE_128_AES, j, count, d);
1783 if (doit[D_IGE_192_AES]) {
1784 for (j = 0; j < SIZE_NUM; j++) {
1785 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1788 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1789 AES_ige_encrypt(buf, buf2,
1790 (unsigned long)lengths[j], &aes_ks2,
1793 print_result(D_IGE_192_AES, j, count, d);
1796 if (doit[D_IGE_256_AES]) {
1797 for (j = 0; j < SIZE_NUM; j++) {
1798 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1801 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1802 AES_ige_encrypt(buf, buf2,
1803 (unsigned long)lengths[j], &aes_ks3,
1806 print_result(D_IGE_256_AES, j, count, d);
1809 if (doit[D_GHASH]) {
1810 GCM128_CONTEXT *ctx =
1811 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1812 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1814 for (j = 0; j < SIZE_NUM; j++) {
1815 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1817 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1818 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1820 print_result(D_GHASH, j, count, d);
1822 CRYPTO_gcm128_release(ctx);
1825 # ifndef OPENSSL_NO_CAMELLIA
1826 if (doit[D_CBC_128_CML]) {
1827 for (j = 0; j < SIZE_NUM; j++) {
1828 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1831 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1832 Camellia_cbc_encrypt(buf, buf,
1833 (unsigned long)lengths[j], &camellia_ks1,
1834 iv, CAMELLIA_ENCRYPT);
1836 print_result(D_CBC_128_CML, j, count, d);
1839 if (doit[D_CBC_192_CML]) {
1840 for (j = 0; j < SIZE_NUM; j++) {
1841 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1844 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1845 Camellia_cbc_encrypt(buf, buf,
1846 (unsigned long)lengths[j], &camellia_ks2,
1847 iv, CAMELLIA_ENCRYPT);
1849 print_result(D_CBC_192_CML, j, count, d);
1852 if (doit[D_CBC_256_CML]) {
1853 for (j = 0; j < SIZE_NUM; j++) {
1854 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1857 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1858 Camellia_cbc_encrypt(buf, buf,
1859 (unsigned long)lengths[j], &camellia_ks3,
1860 iv, CAMELLIA_ENCRYPT);
1862 print_result(D_CBC_256_CML, j, count, d);
1866 # ifndef OPENSSL_NO_IDEA
1867 if (doit[D_CBC_IDEA]) {
1868 for (j = 0; j < SIZE_NUM; j++) {
1869 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1871 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1872 idea_cbc_encrypt(buf, buf,
1873 (unsigned long)lengths[j], &idea_ks,
1876 print_result(D_CBC_IDEA, j, count, d);
1880 # ifndef OPENSSL_NO_SEED
1881 if (doit[D_CBC_SEED]) {
1882 for (j = 0; j < SIZE_NUM; j++) {
1883 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1885 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1886 SEED_cbc_encrypt(buf, buf,
1887 (unsigned long)lengths[j], &seed_ks, iv, 1);
1889 print_result(D_CBC_SEED, j, count, d);
1893 # ifndef OPENSSL_NO_RC2
1894 if (doit[D_CBC_RC2]) {
1895 for (j = 0; j < SIZE_NUM; j++) {
1896 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1898 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1899 RC2_cbc_encrypt(buf, buf,
1900 (unsigned long)lengths[j], &rc2_ks,
1903 print_result(D_CBC_RC2, j, count, d);
1907 # ifndef OPENSSL_NO_RC5
1908 if (doit[D_CBC_RC5]) {
1909 for (j = 0; j < SIZE_NUM; j++) {
1910 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1912 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1913 RC5_32_cbc_encrypt(buf, buf,
1914 (unsigned long)lengths[j], &rc5_ks,
1917 print_result(D_CBC_RC5, j, count, d);
1921 # ifndef OPENSSL_NO_BF
1922 if (doit[D_CBC_BF]) {
1923 for (j = 0; j < SIZE_NUM; j++) {
1924 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1926 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1927 BF_cbc_encrypt(buf, buf,
1928 (unsigned long)lengths[j], &bf_ks,
1931 print_result(D_CBC_BF, j, count, d);
1935 # ifndef OPENSSL_NO_CAST
1936 if (doit[D_CBC_CAST]) {
1937 for (j = 0; j < SIZE_NUM; j++) {
1938 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1940 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1941 CAST_cbc_encrypt(buf, buf,
1942 (unsigned long)lengths[j], &cast_ks,
1945 print_result(D_CBC_CAST, j, count, d);
1951 # ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1952 if (multiblock && evp_cipher) {
1954 (EVP_CIPHER_flags(evp_cipher) &
1955 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1956 fprintf(stderr, "%s is not multi-block capable\n",
1957 OBJ_nid2ln(evp_cipher->nid));
1960 multiblock_speed(evp_cipher);
1965 for (j = 0; j < SIZE_NUM; j++) {
1970 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1972 * -O3 -fschedule-insns messes up an optimization here!
1973 * names[D_EVP] somehow becomes NULL
1975 print_message(names[D_EVP], save_count, lengths[j]);
1977 EVP_CIPHER_CTX_init(&ctx);
1979 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1981 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1982 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1986 for (count = 0, run = 1;
1987 COND(save_count * 4 * lengths[0] / lengths[j]);
1989 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1991 for (count = 0, run = 1;
1992 COND(save_count * 4 * lengths[0] / lengths[j]);
1994 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1996 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1998 EVP_EncryptFinal_ex(&ctx, buf, &outl);
2000 EVP_CIPHER_CTX_cleanup(&ctx);
2003 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2004 print_message(names[D_EVP], save_count, lengths[j]);
2007 for (count = 0, run = 1;
2008 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2009 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2013 print_result(D_EVP, j, count, d);
2017 RAND_pseudo_bytes(buf, 36);
2018 # ifndef OPENSSL_NO_RSA
2019 for (j = 0; j < RSA_NUM; j++) {
2023 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2026 "RSA sign failure. No RSA sign will be done.\n");
2027 ERR_print_errors(bio_err);
2030 pkey_print_message("private", "rsa",
2031 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2032 /* RSA_blinding_on(rsa_key[j],NULL); */
2034 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2035 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2036 &rsa_num, rsa_key[j]);
2038 BIO_printf(bio_err, "RSA sign failure\n");
2039 ERR_print_errors(bio_err);
2046 mr ? "+R1:%ld:%d:%.2f\n"
2047 : "%ld %d bit private RSA's in %.2fs\n",
2048 count, rsa_bits[j], d);
2049 rsa_results[j][0] = d / (double)count;
2054 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2057 "RSA verify failure. No RSA verify will be done.\n");
2058 ERR_print_errors(bio_err);
2061 pkey_print_message("public", "rsa",
2062 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2064 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2065 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2066 rsa_num, rsa_key[j]);
2068 BIO_printf(bio_err, "RSA verify failure\n");
2069 ERR_print_errors(bio_err);
2076 mr ? "+R2:%ld:%d:%.2f\n"
2077 : "%ld %d bit public RSA's in %.2fs\n",
2078 count, rsa_bits[j], d);
2079 rsa_results[j][1] = d / (double)count;
2083 if (rsa_count <= 1) {
2084 /* if longer than 10s, don't do any more */
2085 for (j++; j < RSA_NUM; j++)
2091 RAND_pseudo_bytes(buf, 20);
2092 # ifndef OPENSSL_NO_DSA
2093 if (RAND_status() != 1) {
2094 RAND_seed(rnd_seed, sizeof(rnd_seed));
2097 for (j = 0; j < DSA_NUM; j++) {
2104 /* DSA_generate_key(dsa_key[j]); */
2105 /* DSA_sign_setup(dsa_key[j],NULL); */
2106 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2109 "DSA sign failure. No DSA sign will be done.\n");
2110 ERR_print_errors(bio_err);
2113 pkey_print_message("sign", "dsa",
2114 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2116 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2117 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2119 BIO_printf(bio_err, "DSA sign failure\n");
2120 ERR_print_errors(bio_err);
2127 mr ? "+R3:%ld:%d:%.2f\n"
2128 : "%ld %d bit DSA signs in %.2fs\n",
2129 count, dsa_bits[j], d);
2130 dsa_results[j][0] = d / (double)count;
2134 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2137 "DSA verify failure. No DSA verify will be done.\n");
2138 ERR_print_errors(bio_err);
2141 pkey_print_message("verify", "dsa",
2142 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2144 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2145 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2147 BIO_printf(bio_err, "DSA verify failure\n");
2148 ERR_print_errors(bio_err);
2155 mr ? "+R4:%ld:%d:%.2f\n"
2156 : "%ld %d bit DSA verify in %.2fs\n",
2157 count, dsa_bits[j], d);
2158 dsa_results[j][1] = d / (double)count;
2161 if (rsa_count <= 1) {
2162 /* if longer than 10s, don't do any more */
2163 for (j++; j < DSA_NUM; j++)
2171 # ifndef OPENSSL_NO_ECDSA
2172 if (RAND_status() != 1) {
2173 RAND_seed(rnd_seed, sizeof(rnd_seed));
2176 for (j = 0; j < EC_NUM; j++) {
2180 continue; /* Ignore Curve */
2181 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2182 if (ecdsa[j] == NULL) {
2183 BIO_printf(bio_err, "ECDSA failure.\n");
2184 ERR_print_errors(bio_err);
2188 EC_KEY_precompute_mult(ecdsa[j], NULL);
2190 /* Perform ECDSA signature test */
2191 EC_KEY_generate_key(ecdsa[j]);
2192 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2195 "ECDSA sign failure. No ECDSA sign will be done.\n");
2196 ERR_print_errors(bio_err);
2199 pkey_print_message("sign", "ecdsa",
2201 test_curves_bits[j], ECDSA_SECONDS);
2204 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2205 ret = ECDSA_sign(0, buf, 20,
2206 ecdsasig, &ecdsasiglen, ecdsa[j]);
2208 BIO_printf(bio_err, "ECDSA sign failure\n");
2209 ERR_print_errors(bio_err);
2217 mr ? "+R5:%ld:%d:%.2f\n" :
2218 "%ld %d bit ECDSA signs in %.2fs \n",
2219 count, test_curves_bits[j], d);
2220 ecdsa_results[j][0] = d / (double)count;
2224 /* Perform ECDSA verification test */
2225 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2228 "ECDSA verify failure. No ECDSA verify will be done.\n");
2229 ERR_print_errors(bio_err);
2232 pkey_print_message("verify", "ecdsa",
2234 test_curves_bits[j], ECDSA_SECONDS);
2236 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2238 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2241 BIO_printf(bio_err, "ECDSA verify failure\n");
2242 ERR_print_errors(bio_err);
2249 mr ? "+R6:%ld:%d:%.2f\n"
2250 : "%ld %d bit ECDSA verify in %.2fs\n",
2251 count, test_curves_bits[j], d);
2252 ecdsa_results[j][1] = d / (double)count;
2255 if (rsa_count <= 1) {
2256 /* if longer than 10s, don't do any more */
2257 for (j++; j < EC_NUM; j++)
2266 # ifndef OPENSSL_NO_ECDH
2267 if (RAND_status() != 1) {
2268 RAND_seed(rnd_seed, sizeof(rnd_seed));
2271 for (j = 0; j < EC_NUM; j++) {
2274 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2275 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2276 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2277 BIO_printf(bio_err, "ECDH failure.\n");
2278 ERR_print_errors(bio_err);
2281 /* generate two ECDH key pairs */
2282 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2283 !EC_KEY_generate_key(ecdh_b[j])) {
2284 BIO_printf(bio_err, "ECDH key generation failure.\n");
2285 ERR_print_errors(bio_err);
2289 * If field size is not more than 24 octets, then use SHA-1
2290 * hash of result; otherwise, use result (see section 4.8 of
2291 * draft-ietf-tls-ecc-03.txt).
2293 int field_size, outlen;
2294 void *(*kdf) (const void *in, size_t inlen, void *out,
2297 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2298 if (field_size <= 24 * 8) {
2299 outlen = KDF1_SHA1_len;
2302 outlen = (field_size + 7) / 8;
2306 ECDH_compute_key(secret_a, outlen,
2307 EC_KEY_get0_public_key(ecdh_b[j]),
2310 ECDH_compute_key(secret_b, outlen,
2311 EC_KEY_get0_public_key(ecdh_a[j]),
2313 if (secret_size_a != secret_size_b)
2318 for (secret_idx = 0; (secret_idx < secret_size_a)
2319 && (ecdh_checks == 1); secret_idx++) {
2320 if (secret_a[secret_idx] != secret_b[secret_idx])
2324 if (ecdh_checks == 0) {
2325 BIO_printf(bio_err, "ECDH computations don't match.\n");
2326 ERR_print_errors(bio_err);
2330 pkey_print_message("", "ecdh",
2332 test_curves_bits[j], ECDH_SECONDS);
2334 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2335 ECDH_compute_key(secret_a, outlen,
2336 EC_KEY_get0_public_key(ecdh_b[j]),
2341 mr ? "+R7:%ld:%d:%.2f\n" :
2342 "%ld %d-bit ECDH ops in %.2fs\n", count,
2343 test_curves_bits[j], d);
2344 ecdh_results[j][0] = d / (double)count;
2349 if (rsa_count <= 1) {
2350 /* if longer than 10s, don't do any more */
2351 for (j++; j < EC_NUM; j++)
2362 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2363 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2365 printf("%s ", BN_options());
2366 # ifndef OPENSSL_NO_MD2
2367 printf("%s ", MD2_options());
2369 # ifndef OPENSSL_NO_RC4
2370 printf("%s ", RC4_options());
2372 # ifndef OPENSSL_NO_DES
2373 printf("%s ", DES_options());
2375 # ifndef OPENSSL_NO_AES
2376 printf("%s ", AES_options());
2378 # ifndef OPENSSL_NO_IDEA
2379 printf("%s ", idea_options());
2381 # ifndef OPENSSL_NO_BF
2382 printf("%s ", BF_options());
2384 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2389 fprintf(stdout, "+H");
2392 "The 'numbers' are in 1000s of bytes per second processed.\n");
2393 fprintf(stdout, "type ");
2395 for (j = 0; j < SIZE_NUM; j++)
2396 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2397 fprintf(stdout, "\n");
2400 for (k = 0; k < ALGOR_NUM; k++) {
2404 fprintf(stdout, "+F:%d:%s", k, names[k]);
2406 fprintf(stdout, "%-13s", names[k]);
2407 for (j = 0; j < SIZE_NUM; j++) {
2408 if (results[k][j] > 10000 && !mr)
2409 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2411 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2413 fprintf(stdout, "\n");
2415 # ifndef OPENSSL_NO_RSA
2417 for (k = 0; k < RSA_NUM; k++) {
2421 printf("%18ssign verify sign/s verify/s\n", " ");
2425 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2426 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2428 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2429 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2430 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2433 # ifndef OPENSSL_NO_DSA
2435 for (k = 0; k < DSA_NUM; k++) {
2439 printf("%18ssign verify sign/s verify/s\n", " ");
2443 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2444 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2446 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2447 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2448 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2451 # ifndef OPENSSL_NO_ECDSA
2453 for (k = 0; k < EC_NUM; k++) {
2457 printf("%30ssign verify sign/s verify/s\n", " ");
2462 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2463 k, test_curves_bits[k],
2464 ecdsa_results[k][0], ecdsa_results[k][1]);
2467 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2468 test_curves_bits[k],
2469 test_curves_names[k],
2470 ecdsa_results[k][0], ecdsa_results[k][1],
2471 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2475 # ifndef OPENSSL_NO_ECDH
2477 for (k = 0; k < EC_NUM; k++) {
2481 printf("%30sop op/s\n", " ");
2485 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2486 k, test_curves_bits[k],
2487 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2490 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2491 test_curves_bits[k],
2492 test_curves_names[k],
2493 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2500 ERR_print_errors(bio_err);
2505 # ifndef OPENSSL_NO_RSA
2506 for (i = 0; i < RSA_NUM; i++)
2507 if (rsa_key[i] != NULL)
2508 RSA_free(rsa_key[i]);
2510 # ifndef OPENSSL_NO_DSA
2511 for (i = 0; i < DSA_NUM; i++)
2512 if (dsa_key[i] != NULL)
2513 DSA_free(dsa_key[i]);
2516 # ifndef OPENSSL_NO_ECDSA
2517 for (i = 0; i < EC_NUM; i++)
2518 if (ecdsa[i] != NULL)
2519 EC_KEY_free(ecdsa[i]);
2521 # ifndef OPENSSL_NO_ECDH
2522 for (i = 0; i < EC_NUM; i++) {
2523 if (ecdh_a[i] != NULL)
2524 EC_KEY_free(ecdh_a[i]);
2525 if (ecdh_b[i] != NULL)
2526 EC_KEY_free(ecdh_b[i]);
2535 static void print_message(const char *s, long num, int length)
2539 mr ? "+DT:%s:%d:%d\n"
2540 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2541 (void)BIO_flush(bio_err);
2545 mr ? "+DN:%s:%ld:%d\n"
2546 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2547 (void)BIO_flush(bio_err);
2554 static void pkey_print_message(const char *str, const char *str2, long num,
2559 mr ? "+DTP:%d:%s:%s:%d\n"
2560 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2561 (void)BIO_flush(bio_err);
2565 mr ? "+DNP:%ld:%d:%s:%s\n"
2566 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2567 (void)BIO_flush(bio_err);
2574 static void print_result(int alg, int run_no, int count, double time_used)
2577 mr ? "+R:%d:%s:%f\n"
2578 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2579 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2583 static char *sstrsep(char **string, const char *delim)
2586 char *token = *string;
2591 memset(isdelim, 0, sizeof(isdelim));
2595 isdelim[(unsigned char)(*delim)] = 1;
2599 while (!isdelim[(unsigned char)(**string)]) {
2611 static int do_multi(int multi)
2616 static char sep[] = ":";
2618 fds = malloc(multi * sizeof(*fds));
2620 fprintf(stderr, "Out of memory in speed (do_multi)\n");
2623 for (n = 0; n < multi; ++n) {
2624 if (pipe(fd) == -1) {
2625 fprintf(stderr, "pipe failure\n");
2636 if (dup(fd[1]) == -1) {
2637 fprintf(stderr, "dup failed\n");
2646 printf("Forked child %d\n", n);
2649 /* for now, assume the pipe is long enough to take all the output */
2650 for (n = 0; n < multi; ++n) {
2655 f = fdopen(fds[n], "r");
2656 while (fgets(buf, sizeof(buf), f)) {
2657 p = strchr(buf, '\n');
2660 if (buf[0] != '+') {
2661 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2665 printf("Got: %s from %d\n", buf, n);
2666 if (!strncmp(buf, "+F:", 3)) {
2671 alg = atoi(sstrsep(&p, sep));
2673 for (j = 0; j < SIZE_NUM; ++j)
2674 results[alg][j] += atof(sstrsep(&p, sep));
2675 } else if (!strncmp(buf, "+F2:", 4)) {
2680 k = atoi(sstrsep(&p, sep));
2683 d = atof(sstrsep(&p, sep));
2685 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2687 rsa_results[k][0] = d;
2689 d = atof(sstrsep(&p, sep));
2691 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2693 rsa_results[k][1] = d;
2695 # ifndef OPENSSL_NO_DSA
2696 else if (!strncmp(buf, "+F3:", 4)) {
2701 k = atoi(sstrsep(&p, sep));
2704 d = atof(sstrsep(&p, sep));
2706 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2708 dsa_results[k][0] = d;
2710 d = atof(sstrsep(&p, sep));
2712 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2714 dsa_results[k][1] = d;
2717 # ifndef OPENSSL_NO_ECDSA
2718 else if (!strncmp(buf, "+F4:", 4)) {
2723 k = atoi(sstrsep(&p, sep));
2726 d = atof(sstrsep(&p, sep));
2728 ecdsa_results[k][0] =
2729 1 / (1 / ecdsa_results[k][0] + 1 / d);
2731 ecdsa_results[k][0] = d;
2733 d = atof(sstrsep(&p, sep));
2735 ecdsa_results[k][1] =
2736 1 / (1 / ecdsa_results[k][1] + 1 / d);
2738 ecdsa_results[k][1] = d;
2742 # ifndef OPENSSL_NO_ECDH
2743 else if (!strncmp(buf, "+F5:", 4)) {
2748 k = atoi(sstrsep(&p, sep));
2751 d = atof(sstrsep(&p, sep));
2753 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2755 ecdh_results[k][0] = d;
2760 else if (!strncmp(buf, "+H:", 3)) {
2762 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2772 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2774 static int mblengths[] =
2775 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2776 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2777 const char *alg_name;
2778 unsigned char *inp, *out, no_key[32], no_iv[16];
2782 inp = OPENSSL_malloc(mblengths[num - 1]);
2783 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2785 BIO_printf(bio_err,"Out of memory\n");
2790 EVP_CIPHER_CTX_init(&ctx);
2791 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2792 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2794 alg_name = OBJ_nid2ln(evp_cipher->nid);
2796 for (j = 0; j < num; j++) {
2797 print_message(alg_name, 0, mblengths[j]);
2799 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2800 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
2801 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2802 size_t len = mblengths[j];
2805 memset(aad, 0, 8); /* avoid uninitialized values */
2806 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2807 aad[9] = 3; /* version */
2809 aad[11] = 0; /* length */
2811 mb_param.out = NULL;
2814 mb_param.interleave = 8;
2816 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2817 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2818 sizeof(mb_param), &mb_param);
2824 EVP_CIPHER_CTX_ctrl(&ctx,
2825 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2826 sizeof(mb_param), &mb_param);
2830 RAND_bytes(out, 16);
2832 aad[11] = (unsigned char)(len >> 8);
2833 aad[12] = (unsigned char)(len);
2834 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2835 EVP_CTRL_AEAD_TLS1_AAD,
2836 EVP_AEAD_TLS1_AAD_LEN, aad);
2837 EVP_Cipher(&ctx, out, inp, len + pad);
2842 mr ? "+R:%d:%s:%f\n"
2843 : "%d %s's in %.2fs\n", count, "evp", d);
2844 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2848 fprintf(stdout, "+H");
2849 for (j = 0; j < num; j++)
2850 fprintf(stdout, ":%d", mblengths[j]);
2851 fprintf(stdout, "\n");
2852 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2853 for (j = 0; j < num; j++)
2854 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2855 fprintf(stdout, "\n");
2858 "The 'numbers' are in 1000s of bytes per second processed.\n");
2859 fprintf(stdout, "type ");
2860 for (j = 0; j < num; j++)
2861 fprintf(stdout, "%7d bytes", mblengths[j]);
2862 fprintf(stdout, "\n");
2863 fprintf(stdout, "%-24s", alg_name);
2865 for (j = 0; j < num; j++) {
2866 if (results[D_EVP][j] > 10000)
2867 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2869 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2871 fprintf(stdout, "\n");