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)
375 unsigned char *buf = NULL, *buf2 = NULL;
377 long count = 0, save_count = 0;
379 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
382 # ifndef OPENSSL_NO_RSA
385 unsigned char md[EVP_MAX_MD_SIZE];
386 # ifndef OPENSSL_NO_MD2
387 unsigned char md2[MD2_DIGEST_LENGTH];
389 # ifndef OPENSSL_NO_MDC2
390 unsigned char mdc2[MDC2_DIGEST_LENGTH];
392 # ifndef OPENSSL_NO_MD4
393 unsigned char md4[MD4_DIGEST_LENGTH];
395 # ifndef OPENSSL_NO_MD5
396 unsigned char md5[MD5_DIGEST_LENGTH];
397 unsigned char hmac[MD5_DIGEST_LENGTH];
399 # ifndef OPENSSL_NO_SHA
400 unsigned char sha[SHA_DIGEST_LENGTH];
401 # ifndef OPENSSL_NO_SHA256
402 unsigned char sha256[SHA256_DIGEST_LENGTH];
404 # ifndef OPENSSL_NO_SHA512
405 unsigned char sha512[SHA512_DIGEST_LENGTH];
408 # ifndef OPENSSL_NO_WHIRLPOOL
409 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
411 # ifndef OPENSSL_NO_RIPEMD
412 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
414 # ifndef OPENSSL_NO_RC4
417 # ifndef OPENSSL_NO_RC5
420 # ifndef OPENSSL_NO_RC2
423 # ifndef OPENSSL_NO_IDEA
424 IDEA_KEY_SCHEDULE idea_ks;
426 # ifndef OPENSSL_NO_SEED
427 SEED_KEY_SCHEDULE seed_ks;
429 # ifndef OPENSSL_NO_BF
432 # ifndef OPENSSL_NO_CAST
435 static const unsigned char key16[16] = {
436 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
437 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
439 # ifndef OPENSSL_NO_AES
440 static const unsigned char key24[24] = {
441 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
442 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
443 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
445 static const unsigned char key32[32] = {
446 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
447 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
448 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
449 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
452 # ifndef OPENSSL_NO_CAMELLIA
453 static const unsigned char ckey24[24] = {
454 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
455 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
456 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
458 static const unsigned char ckey32[32] = {
459 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
460 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
461 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
462 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
465 # ifndef OPENSSL_NO_AES
466 # define MAX_BLOCK_SIZE 128
468 # define MAX_BLOCK_SIZE 64
470 unsigned char DES_iv[8];
471 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
472 # ifndef OPENSSL_NO_DES
473 static DES_cblock key =
474 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
475 static DES_cblock key2 =
476 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
477 static DES_cblock key3 =
478 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
479 DES_key_schedule sch;
480 DES_key_schedule sch2;
481 DES_key_schedule sch3;
483 # ifndef OPENSSL_NO_AES
484 AES_KEY aes_ks1, aes_ks2, aes_ks3;
486 # ifndef OPENSSL_NO_CAMELLIA
487 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
498 # define D_EDE3_DES 9
499 # define D_CBC_IDEA 10
500 # define D_CBC_SEED 11
501 # define D_CBC_RC2 12
502 # define D_CBC_RC5 13
504 # define D_CBC_CAST 15
505 # define D_CBC_128_AES 16
506 # define D_CBC_192_AES 17
507 # define D_CBC_256_AES 18
508 # define D_CBC_128_CML 19
509 # define D_CBC_192_CML 20
510 # define D_CBC_256_CML 21
514 # define D_WHIRLPOOL 25
515 # define D_IGE_128_AES 26
516 # define D_IGE_192_AES 27
517 # define D_IGE_256_AES 28
520 long c[ALGOR_NUM][SIZE_NUM];
522 # define R_DSA_1024 1
523 # define R_DSA_2048 2
525 # define R_RSA_1024 1
526 # define R_RSA_2048 2
527 # define R_RSA_4096 3
539 # define R_EC_K571 10
540 # define R_EC_B163 11
541 # define R_EC_B233 12
542 # define R_EC_B283 13
543 # define R_EC_B409 14
544 # define R_EC_B571 15
546 # ifndef OPENSSL_NO_RSA
547 RSA *rsa_key[RSA_NUM];
548 long rsa_c[RSA_NUM][2];
549 static unsigned int rsa_bits[RSA_NUM] = {
550 512, 1024, 2048, 4096
552 static unsigned char *rsa_data[RSA_NUM] = {
553 test512, test1024, test2048, test4096
555 static int rsa_data_length[RSA_NUM] = {
556 sizeof(test512), sizeof(test1024),
557 sizeof(test2048), sizeof(test4096)
560 # ifndef OPENSSL_NO_DSA
561 DSA *dsa_key[DSA_NUM];
562 long dsa_c[DSA_NUM][2];
563 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
565 # ifndef OPENSSL_NO_EC
567 * We only test over the following curves as they are representative, To
568 * add tests over more curves, simply add the curve NID and curve name to
569 * the following arrays and increase the EC_NUM value accordingly.
571 static unsigned int test_curves[EC_NUM] = {
574 NID_X9_62_prime192v1,
576 NID_X9_62_prime256v1,
591 static const char *test_curves_names[EC_NUM] = {
611 static int test_curves_bits[EC_NUM] = {
612 160, 192, 224, 256, 384, 521,
613 163, 233, 283, 409, 571,
614 163, 233, 283, 409, 571
619 # ifndef OPENSSL_NO_ECDSA
620 unsigned char ecdsasig[256];
621 unsigned int ecdsasiglen;
622 EC_KEY *ecdsa[EC_NUM];
623 long ecdsa_c[EC_NUM][2];
626 # ifndef OPENSSL_NO_ECDH
627 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
628 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
629 int secret_size_a, secret_size_b;
632 long ecdh_c[EC_NUM][2];
635 int rsa_doit[RSA_NUM];
636 int dsa_doit[DSA_NUM];
637 # ifndef OPENSSL_NO_ECDSA
638 int ecdsa_doit[EC_NUM];
640 # ifndef OPENSSL_NO_ECDH
641 int ecdh_doit[EC_NUM];
645 const EVP_CIPHER *evp_cipher = NULL;
646 const EVP_MD *evp_md = NULL;
658 memset(results, 0, sizeof(results));
659 # ifndef OPENSSL_NO_DSA
660 memset(dsa_key, 0, sizeof(dsa_key));
662 # ifndef OPENSSL_NO_ECDSA
663 for (i = 0; i < EC_NUM; i++)
666 # ifndef OPENSSL_NO_ECDH
667 for (i = 0; i < EC_NUM; i++) {
674 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
675 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
677 if (!load_config(bio_err, NULL))
680 # ifndef OPENSSL_NO_RSA
681 memset(rsa_key, 0, sizeof(rsa_key));
682 for (i = 0; i < RSA_NUM; i++)
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");
729 evp_cipher = EVP_get_cipherbyname(*argv);
731 evp_md = EVP_get_digestbyname(*argv);
733 if (!evp_cipher && !evp_md) {
734 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
739 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
741 j--; /* Otherwise, -elapsed gets confused with an
744 # ifndef OPENSSL_NO_ENGINE
745 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
749 BIO_printf(bio_err, "no engine given\n");
752 setup_engine(bio_err, *argv, 0);
754 * j will be increased again further down. We just don't want
755 * speed to confuse an engine with an algorithm, especially when
756 * none is given (which means all of them should be run)
762 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
766 BIO_printf(bio_err, "no multi count given\n");
769 multi = atoi(argv[0]);
771 BIO_printf(bio_err, "bad multi count\n");
774 j--; /* Otherwise, -mr gets confused with an
778 else if (argc > 0 && !strcmp(*argv, "-mr")) {
780 j--; /* Otherwise, -mr gets confused with an
782 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
786 # ifndef OPENSSL_NO_MD2
787 if (strcmp(*argv, "md2") == 0)
791 # ifndef OPENSSL_NO_MDC2
792 if (strcmp(*argv, "mdc2") == 0)
796 # ifndef OPENSSL_NO_MD4
797 if (strcmp(*argv, "md4") == 0)
801 # ifndef OPENSSL_NO_MD5
802 if (strcmp(*argv, "md5") == 0)
806 # ifndef OPENSSL_NO_MD5
807 if (strcmp(*argv, "hmac") == 0)
811 # ifndef OPENSSL_NO_SHA
812 if (strcmp(*argv, "sha1") == 0)
814 else if (strcmp(*argv, "sha") == 0)
815 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
817 # ifndef OPENSSL_NO_SHA256
818 if (strcmp(*argv, "sha256") == 0)
822 # ifndef OPENSSL_NO_SHA512
823 if (strcmp(*argv, "sha512") == 0)
828 # ifndef OPENSSL_NO_WHIRLPOOL
829 if (strcmp(*argv, "whirlpool") == 0)
830 doit[D_WHIRLPOOL] = 1;
833 # ifndef OPENSSL_NO_RIPEMD
834 if (strcmp(*argv, "ripemd") == 0)
836 else if (strcmp(*argv, "rmd160") == 0)
838 else if (strcmp(*argv, "ripemd160") == 0)
842 # ifndef OPENSSL_NO_RC4
843 if (strcmp(*argv, "rc4") == 0)
847 # ifndef OPENSSL_NO_DES
848 if (strcmp(*argv, "des-cbc") == 0)
850 else if (strcmp(*argv, "des-ede3") == 0)
851 doit[D_EDE3_DES] = 1;
854 # ifndef OPENSSL_NO_AES
855 if (strcmp(*argv, "aes-128-cbc") == 0)
856 doit[D_CBC_128_AES] = 1;
857 else if (strcmp(*argv, "aes-192-cbc") == 0)
858 doit[D_CBC_192_AES] = 1;
859 else if (strcmp(*argv, "aes-256-cbc") == 0)
860 doit[D_CBC_256_AES] = 1;
861 else if (strcmp(*argv, "aes-128-ige") == 0)
862 doit[D_IGE_128_AES] = 1;
863 else if (strcmp(*argv, "aes-192-ige") == 0)
864 doit[D_IGE_192_AES] = 1;
865 else if (strcmp(*argv, "aes-256-ige") == 0)
866 doit[D_IGE_256_AES] = 1;
869 # ifndef OPENSSL_NO_CAMELLIA
870 if (strcmp(*argv, "camellia-128-cbc") == 0)
871 doit[D_CBC_128_CML] = 1;
872 else if (strcmp(*argv, "camellia-192-cbc") == 0)
873 doit[D_CBC_192_CML] = 1;
874 else if (strcmp(*argv, "camellia-256-cbc") == 0)
875 doit[D_CBC_256_CML] = 1;
878 # ifndef OPENSSL_NO_RSA
879 # if 0 /* was: #ifdef RSAref */
880 if (strcmp(*argv, "rsaref") == 0) {
881 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
886 if (strcmp(*argv, "openssl") == 0) {
887 RSA_set_default_method(RSA_PKCS1_SSLeay());
891 # endif /* !OPENSSL_NO_RSA */
892 if (strcmp(*argv, "dsa512") == 0)
893 dsa_doit[R_DSA_512] = 2;
894 else if (strcmp(*argv, "dsa1024") == 0)
895 dsa_doit[R_DSA_1024] = 2;
896 else if (strcmp(*argv, "dsa2048") == 0)
897 dsa_doit[R_DSA_2048] = 2;
898 else if (strcmp(*argv, "rsa512") == 0)
899 rsa_doit[R_RSA_512] = 2;
900 else if (strcmp(*argv, "rsa1024") == 0)
901 rsa_doit[R_RSA_1024] = 2;
902 else if (strcmp(*argv, "rsa2048") == 0)
903 rsa_doit[R_RSA_2048] = 2;
904 else if (strcmp(*argv, "rsa4096") == 0)
905 rsa_doit[R_RSA_4096] = 2;
907 # ifndef OPENSSL_NO_RC2
908 if (strcmp(*argv, "rc2-cbc") == 0)
910 else if (strcmp(*argv, "rc2") == 0)
914 # ifndef OPENSSL_NO_RC5
915 if (strcmp(*argv, "rc5-cbc") == 0)
917 else if (strcmp(*argv, "rc5") == 0)
921 # ifndef OPENSSL_NO_IDEA
922 if (strcmp(*argv, "idea-cbc") == 0)
923 doit[D_CBC_IDEA] = 1;
924 else if (strcmp(*argv, "idea") == 0)
925 doit[D_CBC_IDEA] = 1;
928 # ifndef OPENSSL_NO_SEED
929 if (strcmp(*argv, "seed-cbc") == 0)
930 doit[D_CBC_SEED] = 1;
931 else if (strcmp(*argv, "seed") == 0)
932 doit[D_CBC_SEED] = 1;
935 # ifndef OPENSSL_NO_BF
936 if (strcmp(*argv, "bf-cbc") == 0)
938 else if (strcmp(*argv, "blowfish") == 0)
940 else if (strcmp(*argv, "bf") == 0)
944 # ifndef OPENSSL_NO_CAST
945 if (strcmp(*argv, "cast-cbc") == 0)
946 doit[D_CBC_CAST] = 1;
947 else if (strcmp(*argv, "cast") == 0)
948 doit[D_CBC_CAST] = 1;
949 else if (strcmp(*argv, "cast5") == 0)
950 doit[D_CBC_CAST] = 1;
953 # ifndef OPENSSL_NO_DES
954 if (strcmp(*argv, "des") == 0) {
956 doit[D_EDE3_DES] = 1;
959 # ifndef OPENSSL_NO_AES
960 if (strcmp(*argv, "aes") == 0) {
961 doit[D_CBC_128_AES] = 1;
962 doit[D_CBC_192_AES] = 1;
963 doit[D_CBC_256_AES] = 1;
964 } else if (strcmp(*argv, "ghash") == 0) {
968 # ifndef OPENSSL_NO_CAMELLIA
969 if (strcmp(*argv, "camellia") == 0) {
970 doit[D_CBC_128_CML] = 1;
971 doit[D_CBC_192_CML] = 1;
972 doit[D_CBC_256_CML] = 1;
975 # ifndef OPENSSL_NO_RSA
976 if (strcmp(*argv, "rsa") == 0) {
977 rsa_doit[R_RSA_512] = 1;
978 rsa_doit[R_RSA_1024] = 1;
979 rsa_doit[R_RSA_2048] = 1;
980 rsa_doit[R_RSA_4096] = 1;
983 # ifndef OPENSSL_NO_DSA
984 if (strcmp(*argv, "dsa") == 0) {
985 dsa_doit[R_DSA_512] = 1;
986 dsa_doit[R_DSA_1024] = 1;
987 dsa_doit[R_DSA_2048] = 1;
990 # ifndef OPENSSL_NO_ECDSA
991 if (strcmp(*argv, "ecdsap160") == 0)
992 ecdsa_doit[R_EC_P160] = 2;
993 else if (strcmp(*argv, "ecdsap192") == 0)
994 ecdsa_doit[R_EC_P192] = 2;
995 else if (strcmp(*argv, "ecdsap224") == 0)
996 ecdsa_doit[R_EC_P224] = 2;
997 else if (strcmp(*argv, "ecdsap256") == 0)
998 ecdsa_doit[R_EC_P256] = 2;
999 else if (strcmp(*argv, "ecdsap384") == 0)
1000 ecdsa_doit[R_EC_P384] = 2;
1001 else if (strcmp(*argv, "ecdsap521") == 0)
1002 ecdsa_doit[R_EC_P521] = 2;
1003 else if (strcmp(*argv, "ecdsak163") == 0)
1004 ecdsa_doit[R_EC_K163] = 2;
1005 else if (strcmp(*argv, "ecdsak233") == 0)
1006 ecdsa_doit[R_EC_K233] = 2;
1007 else if (strcmp(*argv, "ecdsak283") == 0)
1008 ecdsa_doit[R_EC_K283] = 2;
1009 else if (strcmp(*argv, "ecdsak409") == 0)
1010 ecdsa_doit[R_EC_K409] = 2;
1011 else if (strcmp(*argv, "ecdsak571") == 0)
1012 ecdsa_doit[R_EC_K571] = 2;
1013 else if (strcmp(*argv, "ecdsab163") == 0)
1014 ecdsa_doit[R_EC_B163] = 2;
1015 else if (strcmp(*argv, "ecdsab233") == 0)
1016 ecdsa_doit[R_EC_B233] = 2;
1017 else if (strcmp(*argv, "ecdsab283") == 0)
1018 ecdsa_doit[R_EC_B283] = 2;
1019 else if (strcmp(*argv, "ecdsab409") == 0)
1020 ecdsa_doit[R_EC_B409] = 2;
1021 else if (strcmp(*argv, "ecdsab571") == 0)
1022 ecdsa_doit[R_EC_B571] = 2;
1023 else if (strcmp(*argv, "ecdsa") == 0) {
1024 for (i = 0; i < EC_NUM; i++)
1028 # ifndef OPENSSL_NO_ECDH
1029 if (strcmp(*argv, "ecdhp160") == 0)
1030 ecdh_doit[R_EC_P160] = 2;
1031 else if (strcmp(*argv, "ecdhp192") == 0)
1032 ecdh_doit[R_EC_P192] = 2;
1033 else if (strcmp(*argv, "ecdhp224") == 0)
1034 ecdh_doit[R_EC_P224] = 2;
1035 else if (strcmp(*argv, "ecdhp256") == 0)
1036 ecdh_doit[R_EC_P256] = 2;
1037 else if (strcmp(*argv, "ecdhp384") == 0)
1038 ecdh_doit[R_EC_P384] = 2;
1039 else if (strcmp(*argv, "ecdhp521") == 0)
1040 ecdh_doit[R_EC_P521] = 2;
1041 else if (strcmp(*argv, "ecdhk163") == 0)
1042 ecdh_doit[R_EC_K163] = 2;
1043 else if (strcmp(*argv, "ecdhk233") == 0)
1044 ecdh_doit[R_EC_K233] = 2;
1045 else if (strcmp(*argv, "ecdhk283") == 0)
1046 ecdh_doit[R_EC_K283] = 2;
1047 else if (strcmp(*argv, "ecdhk409") == 0)
1048 ecdh_doit[R_EC_K409] = 2;
1049 else if (strcmp(*argv, "ecdhk571") == 0)
1050 ecdh_doit[R_EC_K571] = 2;
1051 else if (strcmp(*argv, "ecdhb163") == 0)
1052 ecdh_doit[R_EC_B163] = 2;
1053 else if (strcmp(*argv, "ecdhb233") == 0)
1054 ecdh_doit[R_EC_B233] = 2;
1055 else if (strcmp(*argv, "ecdhb283") == 0)
1056 ecdh_doit[R_EC_B283] = 2;
1057 else if (strcmp(*argv, "ecdhb409") == 0)
1058 ecdh_doit[R_EC_B409] = 2;
1059 else if (strcmp(*argv, "ecdhb571") == 0)
1060 ecdh_doit[R_EC_B571] = 2;
1061 else if (strcmp(*argv, "ecdh") == 0) {
1062 for (i = 0; i < EC_NUM; i++)
1067 BIO_printf(bio_err, "Error: bad option or value\n");
1068 BIO_printf(bio_err, "\n");
1069 BIO_printf(bio_err, "Available values:\n");
1070 # ifndef OPENSSL_NO_MD2
1071 BIO_printf(bio_err, "md2 ");
1073 # ifndef OPENSSL_NO_MDC2
1074 BIO_printf(bio_err, "mdc2 ");
1076 # ifndef OPENSSL_NO_MD4
1077 BIO_printf(bio_err, "md4 ");
1079 # ifndef OPENSSL_NO_MD5
1080 BIO_printf(bio_err, "md5 ");
1081 # ifndef OPENSSL_NO_HMAC
1082 BIO_printf(bio_err, "hmac ");
1085 # ifndef OPENSSL_NO_SHA1
1086 BIO_printf(bio_err, "sha1 ");
1088 # ifndef OPENSSL_NO_SHA256
1089 BIO_printf(bio_err, "sha256 ");
1091 # ifndef OPENSSL_NO_SHA512
1092 BIO_printf(bio_err, "sha512 ");
1094 # ifndef OPENSSL_NO_WHIRLPOOL
1095 BIO_printf(bio_err, "whirlpool");
1097 # ifndef OPENSSL_NO_RIPEMD160
1098 BIO_printf(bio_err, "rmd160");
1100 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1101 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1102 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1103 !defined(OPENSSL_NO_WHIRLPOOL)
1104 BIO_printf(bio_err, "\n");
1107 # ifndef OPENSSL_NO_IDEA
1108 BIO_printf(bio_err, "idea-cbc ");
1110 # ifndef OPENSSL_NO_SEED
1111 BIO_printf(bio_err, "seed-cbc ");
1113 # ifndef OPENSSL_NO_RC2
1114 BIO_printf(bio_err, "rc2-cbc ");
1116 # ifndef OPENSSL_NO_RC5
1117 BIO_printf(bio_err, "rc5-cbc ");
1119 # ifndef OPENSSL_NO_BF
1120 BIO_printf(bio_err, "bf-cbc");
1122 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1123 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1124 BIO_printf(bio_err, "\n");
1126 # ifndef OPENSSL_NO_DES
1127 BIO_printf(bio_err, "des-cbc des-ede3 ");
1129 # ifndef OPENSSL_NO_AES
1130 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1131 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1133 # ifndef OPENSSL_NO_CAMELLIA
1134 BIO_printf(bio_err, "\n");
1136 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1138 # ifndef OPENSSL_NO_RC4
1139 BIO_printf(bio_err, "rc4");
1141 BIO_printf(bio_err, "\n");
1143 # ifndef OPENSSL_NO_RSA
1144 BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
1147 # ifndef OPENSSL_NO_DSA
1148 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1150 # ifndef OPENSSL_NO_ECDSA
1151 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1152 "ecdsap256 ecdsap384 ecdsap521\n");
1154 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1156 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1157 BIO_printf(bio_err, "ecdsa\n");
1159 # ifndef OPENSSL_NO_ECDH
1160 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1161 "ecdhp256 ecdhp384 ecdhp521\n");
1163 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1165 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1166 BIO_printf(bio_err, "ecdh\n");
1169 # ifndef OPENSSL_NO_IDEA
1170 BIO_printf(bio_err, "idea ");
1172 # ifndef OPENSSL_NO_SEED
1173 BIO_printf(bio_err, "seed ");
1175 # ifndef OPENSSL_NO_RC2
1176 BIO_printf(bio_err, "rc2 ");
1178 # ifndef OPENSSL_NO_DES
1179 BIO_printf(bio_err, "des ");
1181 # ifndef OPENSSL_NO_AES
1182 BIO_printf(bio_err, "aes ");
1184 # ifndef OPENSSL_NO_CAMELLIA
1185 BIO_printf(bio_err, "camellia ");
1187 # ifndef OPENSSL_NO_RSA
1188 BIO_printf(bio_err, "rsa ");
1190 # ifndef OPENSSL_NO_BF
1191 BIO_printf(bio_err, "blowfish");
1193 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1194 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1195 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1196 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1197 BIO_printf(bio_err, "\n");
1200 BIO_printf(bio_err, "\n");
1201 BIO_printf(bio_err, "Available options:\n");
1202 # if defined(TIMES) || defined(USE_TOD)
1203 BIO_printf(bio_err, "-elapsed "
1204 "measure time in real time instead of CPU user time.\n");
1206 # ifndef OPENSSL_NO_ENGINE
1209 "use engine e, possibly a hardware device.\n");
1211 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1214 "time decryption instead of encryption (only EVP).\n");
1217 "produce machine readable output.\n");
1220 "-multi n " "run n benchmarks in parallel.\n");
1230 if (multi && do_multi(multi))
1235 for (i = 0; i < ALGOR_NUM; i++) {
1239 for (i = 0; i < RSA_NUM; i++)
1241 for (i = 0; i < DSA_NUM; i++)
1243 # ifndef OPENSSL_NO_ECDSA
1244 for (i = 0; i < EC_NUM; i++)
1247 # ifndef OPENSSL_NO_ECDH
1248 for (i = 0; i < EC_NUM; i++)
1252 for (i = 0; i < ALGOR_NUM; i++)
1256 if (usertime == 0 && !mr)
1258 "You have chosen to measure elapsed time "
1259 "instead of user CPU time.\n");
1261 # ifndef OPENSSL_NO_RSA
1262 for (i = 0; i < RSA_NUM; i++) {
1263 const unsigned char *p;
1266 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1267 if (rsa_key[i] == NULL) {
1268 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1276 : "Loaded RSA key, %d bit modulus and e= 0x",
1277 BN_num_bits(rsa_key[i]->n));
1278 BN_print(bio_err, rsa_key[i]->e);
1279 BIO_printf(bio_err, "\n");
1285 # ifndef OPENSSL_NO_DSA
1286 dsa_key[0] = get_dsa512();
1287 dsa_key[1] = get_dsa1024();
1288 dsa_key[2] = get_dsa2048();
1291 # ifndef OPENSSL_NO_DES
1292 DES_set_key_unchecked(&key, &sch);
1293 DES_set_key_unchecked(&key2, &sch2);
1294 DES_set_key_unchecked(&key3, &sch3);
1296 # ifndef OPENSSL_NO_AES
1297 AES_set_encrypt_key(key16, 128, &aes_ks1);
1298 AES_set_encrypt_key(key24, 192, &aes_ks2);
1299 AES_set_encrypt_key(key32, 256, &aes_ks3);
1301 # ifndef OPENSSL_NO_CAMELLIA
1302 Camellia_set_key(key16, 128, &camellia_ks1);
1303 Camellia_set_key(ckey24, 192, &camellia_ks2);
1304 Camellia_set_key(ckey32, 256, &camellia_ks3);
1306 # ifndef OPENSSL_NO_IDEA
1307 idea_set_encrypt_key(key16, &idea_ks);
1309 # ifndef OPENSSL_NO_SEED
1310 SEED_set_key(key16, &seed_ks);
1312 # ifndef OPENSSL_NO_RC4
1313 RC4_set_key(&rc4_ks, 16, key16);
1315 # ifndef OPENSSL_NO_RC2
1316 RC2_set_key(&rc2_ks, 16, key16, 128);
1318 # ifndef OPENSSL_NO_RC5
1319 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1321 # ifndef OPENSSL_NO_BF
1322 BF_set_key(&bf_ks, 16, key16);
1324 # ifndef OPENSSL_NO_CAST
1325 CAST_set_key(&cast_ks, 16, key16);
1327 # ifndef OPENSSL_NO_RSA
1328 memset(rsa_c, 0, sizeof(rsa_c));
1331 # ifndef OPENSSL_NO_DES
1332 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1338 for (it = count; it; it--)
1339 DES_ecb_encrypt((DES_cblock *)buf,
1340 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1344 c[D_MD2][0] = count / 10;
1345 c[D_MDC2][0] = count / 10;
1346 c[D_MD4][0] = count;
1347 c[D_MD5][0] = count;
1348 c[D_HMAC][0] = count;
1349 c[D_SHA1][0] = count;
1350 c[D_RMD160][0] = count;
1351 c[D_RC4][0] = count * 5;
1352 c[D_CBC_DES][0] = count;
1353 c[D_EDE3_DES][0] = count / 3;
1354 c[D_CBC_IDEA][0] = count;
1355 c[D_CBC_SEED][0] = count;
1356 c[D_CBC_RC2][0] = count;
1357 c[D_CBC_RC5][0] = count;
1358 c[D_CBC_BF][0] = count;
1359 c[D_CBC_CAST][0] = count;
1360 c[D_CBC_128_AES][0] = count;
1361 c[D_CBC_192_AES][0] = count;
1362 c[D_CBC_256_AES][0] = count;
1363 c[D_CBC_128_CML][0] = count;
1364 c[D_CBC_192_CML][0] = count;
1365 c[D_CBC_256_CML][0] = count;
1366 c[D_SHA256][0] = count;
1367 c[D_SHA512][0] = count;
1368 c[D_WHIRLPOOL][0] = count;
1369 c[D_IGE_128_AES][0] = count;
1370 c[D_IGE_192_AES][0] = count;
1371 c[D_IGE_256_AES][0] = count;
1372 c[D_GHASH][0] = count;
1374 for (i = 1; i < SIZE_NUM; i++) {
1375 c[D_MD2][i] = c[D_MD2][0] * 4 * lengths[0] / lengths[i];
1376 c[D_MDC2][i] = c[D_MDC2][0] * 4 * lengths[0] / lengths[i];
1377 c[D_MD4][i] = c[D_MD4][0] * 4 * lengths[0] / lengths[i];
1378 c[D_MD5][i] = c[D_MD5][0] * 4 * lengths[0] / lengths[i];
1379 c[D_HMAC][i] = c[D_HMAC][0] * 4 * lengths[0] / lengths[i];
1380 c[D_SHA1][i] = c[D_SHA1][0] * 4 * lengths[0] / lengths[i];
1381 c[D_RMD160][i] = c[D_RMD160][0] * 4 * lengths[0] / lengths[i];
1382 c[D_SHA256][i] = c[D_SHA256][0] * 4 * lengths[0] / lengths[i];
1383 c[D_SHA512][i] = c[D_SHA512][0] * 4 * lengths[0] / lengths[i];
1384 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * lengths[0] / lengths[i];
1386 for (i = 1; i < SIZE_NUM; i++) {
1389 l0 = (long)lengths[i - 1];
1390 l1 = (long)lengths[i];
1391 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1392 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1393 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1394 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1395 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1396 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1397 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1398 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1399 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1400 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1401 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1402 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1403 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1404 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1405 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1406 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1407 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1408 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1410 # ifndef OPENSSL_NO_RSA
1411 rsa_c[R_RSA_512][0] = count / 2000;
1412 rsa_c[R_RSA_512][1] = count / 400;
1413 for (i = 1; i < RSA_NUM; i++) {
1414 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1415 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1416 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1419 if (rsa_c[i][0] == 0) {
1427 # ifndef OPENSSL_NO_DSA
1428 dsa_c[R_DSA_512][0] = count / 1000;
1429 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1430 for (i = 1; i < DSA_NUM; i++) {
1431 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1432 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1433 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1436 if (dsa_c[i] == 0) {
1444 # ifndef OPENSSL_NO_ECDSA
1445 ecdsa_c[R_EC_P160][0] = count / 1000;
1446 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1447 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1448 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1449 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1450 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1453 if (ecdsa_c[i] == 0) {
1459 ecdsa_c[R_EC_K163][0] = count / 1000;
1460 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1461 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1462 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1463 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1464 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1467 if (ecdsa_c[i] == 0) {
1473 ecdsa_c[R_EC_B163][0] = count / 1000;
1474 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1475 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1476 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1477 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1478 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1481 if (ecdsa_c[i] == 0) {
1489 # ifndef OPENSSL_NO_ECDH
1490 ecdh_c[R_EC_P160][0] = count / 1000;
1491 ecdh_c[R_EC_P160][1] = count / 1000;
1492 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1493 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1494 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1495 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1498 if (ecdh_c[i] == 0) {
1504 ecdh_c[R_EC_K163][0] = count / 1000;
1505 ecdh_c[R_EC_K163][1] = count / 1000;
1506 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1507 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1508 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1509 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1512 if (ecdh_c[i] == 0) {
1518 ecdh_c[R_EC_B163][0] = count / 1000;
1519 ecdh_c[R_EC_B163][1] = count / 1000;
1520 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1521 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1522 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1523 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1526 if (ecdh_c[i] == 0) {
1534 # define COND(d) (count < (d))
1535 # define COUNT(d) (d)
1537 /* not worth fixing */
1538 # error "You cannot disable DES on systems without SIGALRM."
1539 # endif /* OPENSSL_NO_DES */
1541 # define COND(c) (run && count<0x7fffffff)
1542 # define COUNT(d) (count)
1544 signal(SIGALRM, sig_done);
1546 # endif /* SIGALRM */
1548 # ifndef OPENSSL_NO_MD2
1550 for (j = 0; j < SIZE_NUM; j++) {
1551 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1553 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1554 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1557 print_result(D_MD2, j, count, d);
1561 # ifndef OPENSSL_NO_MDC2
1563 for (j = 0; j < SIZE_NUM; j++) {
1564 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1566 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1567 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1570 print_result(D_MDC2, j, count, d);
1575 # ifndef OPENSSL_NO_MD4
1577 for (j = 0; j < SIZE_NUM; j++) {
1578 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1580 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1581 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1582 NULL, EVP_md4(), NULL);
1584 print_result(D_MD4, j, count, d);
1589 # ifndef OPENSSL_NO_MD5
1591 for (j = 0; j < SIZE_NUM; j++) {
1592 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1594 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1595 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md5[0]),
1596 NULL, EVP_get_digestbyname("md5"), NULL);
1598 print_result(D_MD5, j, count, d);
1603 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1607 HMAC_CTX_init(&hctx);
1608 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1609 16, EVP_md5(), NULL);
1611 for (j = 0; j < SIZE_NUM; j++) {
1612 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1614 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1615 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1616 HMAC_Update(&hctx, buf, lengths[j]);
1617 HMAC_Final(&hctx, &(hmac[0]), NULL);
1620 print_result(D_HMAC, j, count, d);
1622 HMAC_CTX_cleanup(&hctx);
1625 # ifndef OPENSSL_NO_SHA
1627 for (j = 0; j < SIZE_NUM; j++) {
1628 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1630 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1631 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1634 print_result(D_SHA1, j, count, d);
1637 # ifndef OPENSSL_NO_SHA256
1638 if (doit[D_SHA256]) {
1639 for (j = 0; j < SIZE_NUM; j++) {
1640 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1642 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1643 SHA256(buf, lengths[j], sha256);
1645 print_result(D_SHA256, j, count, d);
1650 # ifndef OPENSSL_NO_SHA512
1651 if (doit[D_SHA512]) {
1652 for (j = 0; j < SIZE_NUM; j++) {
1653 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1655 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1656 SHA512(buf, lengths[j], sha512);
1658 print_result(D_SHA512, j, count, d);
1664 # ifndef OPENSSL_NO_WHIRLPOOL
1665 if (doit[D_WHIRLPOOL]) {
1666 for (j = 0; j < SIZE_NUM; j++) {
1667 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1669 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1670 WHIRLPOOL(buf, lengths[j], whirlpool);
1672 print_result(D_WHIRLPOOL, j, count, d);
1677 # ifndef OPENSSL_NO_RIPEMD
1678 if (doit[D_RMD160]) {
1679 for (j = 0; j < SIZE_NUM; j++) {
1680 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1682 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1683 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1684 EVP_ripemd160(), NULL);
1686 print_result(D_RMD160, j, count, d);
1690 # ifndef OPENSSL_NO_RC4
1692 for (j = 0; j < SIZE_NUM; j++) {
1693 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1695 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1696 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1698 print_result(D_RC4, j, count, d);
1702 # ifndef OPENSSL_NO_DES
1703 if (doit[D_CBC_DES]) {
1704 for (j = 0; j < SIZE_NUM; j++) {
1705 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1707 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1708 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1709 &DES_iv, DES_ENCRYPT);
1711 print_result(D_CBC_DES, j, count, d);
1715 if (doit[D_EDE3_DES]) {
1716 for (j = 0; j < SIZE_NUM; j++) {
1717 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1719 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1720 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1722 &DES_iv, DES_ENCRYPT);
1724 print_result(D_EDE3_DES, j, count, d);
1728 # ifndef OPENSSL_NO_AES
1729 if (doit[D_CBC_128_AES]) {
1730 for (j = 0; j < SIZE_NUM; j++) {
1731 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1734 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1735 AES_cbc_encrypt(buf, buf,
1736 (unsigned long)lengths[j], &aes_ks1,
1739 print_result(D_CBC_128_AES, j, count, d);
1742 if (doit[D_CBC_192_AES]) {
1743 for (j = 0; j < SIZE_NUM; j++) {
1744 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1747 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1748 AES_cbc_encrypt(buf, buf,
1749 (unsigned long)lengths[j], &aes_ks2,
1752 print_result(D_CBC_192_AES, j, count, d);
1755 if (doit[D_CBC_256_AES]) {
1756 for (j = 0; j < SIZE_NUM; j++) {
1757 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1760 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1761 AES_cbc_encrypt(buf, buf,
1762 (unsigned long)lengths[j], &aes_ks3,
1765 print_result(D_CBC_256_AES, j, count, d);
1769 if (doit[D_IGE_128_AES]) {
1770 for (j = 0; j < SIZE_NUM; j++) {
1771 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1774 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1775 AES_ige_encrypt(buf, buf2,
1776 (unsigned long)lengths[j], &aes_ks1,
1779 print_result(D_IGE_128_AES, j, count, d);
1782 if (doit[D_IGE_192_AES]) {
1783 for (j = 0; j < SIZE_NUM; j++) {
1784 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1787 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1788 AES_ige_encrypt(buf, buf2,
1789 (unsigned long)lengths[j], &aes_ks2,
1792 print_result(D_IGE_192_AES, j, count, d);
1795 if (doit[D_IGE_256_AES]) {
1796 for (j = 0; j < SIZE_NUM; j++) {
1797 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1800 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1801 AES_ige_encrypt(buf, buf2,
1802 (unsigned long)lengths[j], &aes_ks3,
1805 print_result(D_IGE_256_AES, j, count, d);
1808 if (doit[D_GHASH]) {
1809 GCM128_CONTEXT *ctx =
1810 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1811 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1813 for (j = 0; j < SIZE_NUM; j++) {
1814 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1816 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1817 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1819 print_result(D_GHASH, j, count, d);
1821 CRYPTO_gcm128_release(ctx);
1824 # ifndef OPENSSL_NO_CAMELLIA
1825 if (doit[D_CBC_128_CML]) {
1826 for (j = 0; j < SIZE_NUM; j++) {
1827 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1830 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1831 Camellia_cbc_encrypt(buf, buf,
1832 (unsigned long)lengths[j], &camellia_ks1,
1833 iv, CAMELLIA_ENCRYPT);
1835 print_result(D_CBC_128_CML, j, count, d);
1838 if (doit[D_CBC_192_CML]) {
1839 for (j = 0; j < SIZE_NUM; j++) {
1840 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1843 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1844 Camellia_cbc_encrypt(buf, buf,
1845 (unsigned long)lengths[j], &camellia_ks2,
1846 iv, CAMELLIA_ENCRYPT);
1848 print_result(D_CBC_192_CML, j, count, d);
1851 if (doit[D_CBC_256_CML]) {
1852 for (j = 0; j < SIZE_NUM; j++) {
1853 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1856 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1857 Camellia_cbc_encrypt(buf, buf,
1858 (unsigned long)lengths[j], &camellia_ks3,
1859 iv, CAMELLIA_ENCRYPT);
1861 print_result(D_CBC_256_CML, j, count, d);
1865 # ifndef OPENSSL_NO_IDEA
1866 if (doit[D_CBC_IDEA]) {
1867 for (j = 0; j < SIZE_NUM; j++) {
1868 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1870 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1871 idea_cbc_encrypt(buf, buf,
1872 (unsigned long)lengths[j], &idea_ks,
1875 print_result(D_CBC_IDEA, j, count, d);
1879 # ifndef OPENSSL_NO_SEED
1880 if (doit[D_CBC_SEED]) {
1881 for (j = 0; j < SIZE_NUM; j++) {
1882 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1884 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1885 SEED_cbc_encrypt(buf, buf,
1886 (unsigned long)lengths[j], &seed_ks, iv, 1);
1888 print_result(D_CBC_SEED, j, count, d);
1892 # ifndef OPENSSL_NO_RC2
1893 if (doit[D_CBC_RC2]) {
1894 for (j = 0; j < SIZE_NUM; j++) {
1895 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1897 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1898 RC2_cbc_encrypt(buf, buf,
1899 (unsigned long)lengths[j], &rc2_ks,
1902 print_result(D_CBC_RC2, j, count, d);
1906 # ifndef OPENSSL_NO_RC5
1907 if (doit[D_CBC_RC5]) {
1908 for (j = 0; j < SIZE_NUM; j++) {
1909 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1911 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1912 RC5_32_cbc_encrypt(buf, buf,
1913 (unsigned long)lengths[j], &rc5_ks,
1916 print_result(D_CBC_RC5, j, count, d);
1920 # ifndef OPENSSL_NO_BF
1921 if (doit[D_CBC_BF]) {
1922 for (j = 0; j < SIZE_NUM; j++) {
1923 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1925 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1926 BF_cbc_encrypt(buf, buf,
1927 (unsigned long)lengths[j], &bf_ks,
1930 print_result(D_CBC_BF, j, count, d);
1934 # ifndef OPENSSL_NO_CAST
1935 if (doit[D_CBC_CAST]) {
1936 for (j = 0; j < SIZE_NUM; j++) {
1937 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1939 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1940 CAST_cbc_encrypt(buf, buf,
1941 (unsigned long)lengths[j], &cast_ks,
1944 print_result(D_CBC_CAST, j, count, d);
1950 # ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1951 if (multiblock && evp_cipher) {
1953 (EVP_CIPHER_flags(evp_cipher) &
1954 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1955 fprintf(stderr, "%s is not multi-block capable\n",
1956 OBJ_nid2ln(evp_cipher->nid));
1959 multiblock_speed(evp_cipher);
1964 for (j = 0; j < SIZE_NUM; j++) {
1969 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1971 * -O3 -fschedule-insns messes up an optimization here!
1972 * names[D_EVP] somehow becomes NULL
1974 print_message(names[D_EVP], save_count, lengths[j]);
1976 EVP_CIPHER_CTX_init(&ctx);
1978 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1980 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1981 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1985 for (count = 0, run = 1;
1986 COND(save_count * 4 * lengths[0] / lengths[j]);
1988 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1990 for (count = 0, run = 1;
1991 COND(save_count * 4 * lengths[0] / lengths[j]);
1993 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1995 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1997 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1999 EVP_CIPHER_CTX_cleanup(&ctx);
2002 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2003 print_message(names[D_EVP], save_count, lengths[j]);
2006 for (count = 0, run = 1;
2007 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2008 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2012 print_result(D_EVP, j, count, d);
2016 RAND_pseudo_bytes(buf, 36);
2017 # ifndef OPENSSL_NO_RSA
2018 for (j = 0; j < RSA_NUM; j++) {
2022 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2025 "RSA sign failure. No RSA sign will be done.\n");
2026 ERR_print_errors(bio_err);
2029 pkey_print_message("private", "rsa",
2030 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2031 /* RSA_blinding_on(rsa_key[j],NULL); */
2033 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2034 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2035 &rsa_num, rsa_key[j]);
2037 BIO_printf(bio_err, "RSA sign failure\n");
2038 ERR_print_errors(bio_err);
2045 mr ? "+R1:%ld:%d:%.2f\n"
2046 : "%ld %d bit private RSA's in %.2fs\n",
2047 count, rsa_bits[j], d);
2048 rsa_results[j][0] = d / (double)count;
2053 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2056 "RSA verify failure. No RSA verify will be done.\n");
2057 ERR_print_errors(bio_err);
2060 pkey_print_message("public", "rsa",
2061 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2063 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2064 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2065 rsa_num, rsa_key[j]);
2067 BIO_printf(bio_err, "RSA verify failure\n");
2068 ERR_print_errors(bio_err);
2075 mr ? "+R2:%ld:%d:%.2f\n"
2076 : "%ld %d bit public RSA's in %.2fs\n",
2077 count, rsa_bits[j], d);
2078 rsa_results[j][1] = d / (double)count;
2082 if (rsa_count <= 1) {
2083 /* if longer than 10s, don't do any more */
2084 for (j++; j < RSA_NUM; j++)
2090 RAND_pseudo_bytes(buf, 20);
2091 # ifndef OPENSSL_NO_DSA
2092 if (RAND_status() != 1) {
2093 RAND_seed(rnd_seed, sizeof rnd_seed);
2096 for (j = 0; j < DSA_NUM; j++) {
2103 /* DSA_generate_key(dsa_key[j]); */
2104 /* DSA_sign_setup(dsa_key[j],NULL); */
2105 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2108 "DSA sign failure. No DSA sign will be done.\n");
2109 ERR_print_errors(bio_err);
2112 pkey_print_message("sign", "dsa",
2113 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2115 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2116 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2118 BIO_printf(bio_err, "DSA sign failure\n");
2119 ERR_print_errors(bio_err);
2126 mr ? "+R3:%ld:%d:%.2f\n"
2127 : "%ld %d bit DSA signs in %.2fs\n",
2128 count, dsa_bits[j], d);
2129 dsa_results[j][0] = d / (double)count;
2133 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2136 "DSA verify failure. No DSA verify will be done.\n");
2137 ERR_print_errors(bio_err);
2140 pkey_print_message("verify", "dsa",
2141 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2143 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2144 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2146 BIO_printf(bio_err, "DSA verify failure\n");
2147 ERR_print_errors(bio_err);
2154 mr ? "+R4:%ld:%d:%.2f\n"
2155 : "%ld %d bit DSA verify in %.2fs\n",
2156 count, dsa_bits[j], d);
2157 dsa_results[j][1] = d / (double)count;
2160 if (rsa_count <= 1) {
2161 /* if longer than 10s, don't do any more */
2162 for (j++; j < DSA_NUM; j++)
2170 # ifndef OPENSSL_NO_ECDSA
2171 if (RAND_status() != 1) {
2172 RAND_seed(rnd_seed, sizeof rnd_seed);
2175 for (j = 0; j < EC_NUM; j++) {
2179 continue; /* Ignore Curve */
2180 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2181 if (ecdsa[j] == NULL) {
2182 BIO_printf(bio_err, "ECDSA failure.\n");
2183 ERR_print_errors(bio_err);
2187 EC_KEY_precompute_mult(ecdsa[j], NULL);
2189 /* Perform ECDSA signature test */
2190 EC_KEY_generate_key(ecdsa[j]);
2191 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2194 "ECDSA sign failure. No ECDSA sign will be done.\n");
2195 ERR_print_errors(bio_err);
2198 pkey_print_message("sign", "ecdsa",
2200 test_curves_bits[j], ECDSA_SECONDS);
2203 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2204 ret = ECDSA_sign(0, buf, 20,
2205 ecdsasig, &ecdsasiglen, ecdsa[j]);
2207 BIO_printf(bio_err, "ECDSA sign failure\n");
2208 ERR_print_errors(bio_err);
2216 mr ? "+R5:%ld:%d:%.2f\n" :
2217 "%ld %d bit ECDSA signs in %.2fs \n",
2218 count, test_curves_bits[j], d);
2219 ecdsa_results[j][0] = d / (double)count;
2223 /* Perform ECDSA verification test */
2224 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2227 "ECDSA verify failure. No ECDSA verify will be done.\n");
2228 ERR_print_errors(bio_err);
2231 pkey_print_message("verify", "ecdsa",
2233 test_curves_bits[j], ECDSA_SECONDS);
2235 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2237 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2240 BIO_printf(bio_err, "ECDSA verify failure\n");
2241 ERR_print_errors(bio_err);
2248 mr ? "+R6:%ld:%d:%.2f\n"
2249 : "%ld %d bit ECDSA verify in %.2fs\n",
2250 count, test_curves_bits[j], d);
2251 ecdsa_results[j][1] = d / (double)count;
2254 if (rsa_count <= 1) {
2255 /* if longer than 10s, don't do any more */
2256 for (j++; j < EC_NUM; j++)
2265 # ifndef OPENSSL_NO_ECDH
2266 if (RAND_status() != 1) {
2267 RAND_seed(rnd_seed, sizeof rnd_seed);
2270 for (j = 0; j < EC_NUM; j++) {
2273 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2274 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2275 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2276 BIO_printf(bio_err, "ECDH failure.\n");
2277 ERR_print_errors(bio_err);
2280 /* generate two ECDH key pairs */
2281 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2282 !EC_KEY_generate_key(ecdh_b[j])) {
2283 BIO_printf(bio_err, "ECDH key generation failure.\n");
2284 ERR_print_errors(bio_err);
2288 * If field size is not more than 24 octets, then use SHA-1
2289 * hash of result; otherwise, use result (see section 4.8 of
2290 * draft-ietf-tls-ecc-03.txt).
2292 int field_size, outlen;
2293 void *(*kdf) (const void *in, size_t inlen, void *out,
2296 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2297 if (field_size <= 24 * 8) {
2298 outlen = KDF1_SHA1_len;
2301 outlen = (field_size + 7) / 8;
2305 ECDH_compute_key(secret_a, outlen,
2306 EC_KEY_get0_public_key(ecdh_b[j]),
2309 ECDH_compute_key(secret_b, outlen,
2310 EC_KEY_get0_public_key(ecdh_a[j]),
2312 if (secret_size_a != secret_size_b)
2317 for (secret_idx = 0; (secret_idx < secret_size_a)
2318 && (ecdh_checks == 1); secret_idx++) {
2319 if (secret_a[secret_idx] != secret_b[secret_idx])
2323 if (ecdh_checks == 0) {
2324 BIO_printf(bio_err, "ECDH computations don't match.\n");
2325 ERR_print_errors(bio_err);
2329 pkey_print_message("", "ecdh",
2331 test_curves_bits[j], ECDH_SECONDS);
2333 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2334 ECDH_compute_key(secret_a, outlen,
2335 EC_KEY_get0_public_key(ecdh_b[j]),
2340 mr ? "+R7:%ld:%d:%.2f\n" :
2341 "%ld %d-bit ECDH ops in %.2fs\n", count,
2342 test_curves_bits[j], d);
2343 ecdh_results[j][0] = d / (double)count;
2348 if (rsa_count <= 1) {
2349 /* if longer than 10s, don't do any more */
2350 for (j++; j < EC_NUM; j++)
2361 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2362 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2364 printf("%s ", BN_options());
2365 # ifndef OPENSSL_NO_MD2
2366 printf("%s ", MD2_options());
2368 # ifndef OPENSSL_NO_RC4
2369 printf("%s ", RC4_options());
2371 # ifndef OPENSSL_NO_DES
2372 printf("%s ", DES_options());
2374 # ifndef OPENSSL_NO_AES
2375 printf("%s ", AES_options());
2377 # ifndef OPENSSL_NO_IDEA
2378 printf("%s ", idea_options());
2380 # ifndef OPENSSL_NO_BF
2381 printf("%s ", BF_options());
2383 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2388 fprintf(stdout, "+H");
2391 "The 'numbers' are in 1000s of bytes per second processed.\n");
2392 fprintf(stdout, "type ");
2394 for (j = 0; j < SIZE_NUM; j++)
2395 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2396 fprintf(stdout, "\n");
2399 for (k = 0; k < ALGOR_NUM; k++) {
2403 fprintf(stdout, "+F:%d:%s", k, names[k]);
2405 fprintf(stdout, "%-13s", names[k]);
2406 for (j = 0; j < SIZE_NUM; j++) {
2407 if (results[k][j] > 10000 && !mr)
2408 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2410 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2412 fprintf(stdout, "\n");
2414 # ifndef OPENSSL_NO_RSA
2416 for (k = 0; k < RSA_NUM; k++) {
2420 printf("%18ssign verify sign/s verify/s\n", " ");
2424 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2425 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2427 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2428 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2429 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2432 # ifndef OPENSSL_NO_DSA
2434 for (k = 0; k < DSA_NUM; k++) {
2438 printf("%18ssign verify sign/s verify/s\n", " ");
2442 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2443 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2445 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2446 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2447 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2450 # ifndef OPENSSL_NO_ECDSA
2452 for (k = 0; k < EC_NUM; k++) {
2456 printf("%30ssign verify sign/s verify/s\n", " ");
2461 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2462 k, test_curves_bits[k],
2463 ecdsa_results[k][0], ecdsa_results[k][1]);
2466 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2467 test_curves_bits[k],
2468 test_curves_names[k],
2469 ecdsa_results[k][0], ecdsa_results[k][1],
2470 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2474 # ifndef OPENSSL_NO_ECDH
2476 for (k = 0; k < EC_NUM; k++) {
2480 printf("%30sop op/s\n", " ");
2484 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2485 k, test_curves_bits[k],
2486 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2489 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2490 test_curves_bits[k],
2491 test_curves_names[k],
2492 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2499 ERR_print_errors(bio_err);
2504 # ifndef OPENSSL_NO_RSA
2505 for (i = 0; i < RSA_NUM; i++)
2506 if (rsa_key[i] != NULL)
2507 RSA_free(rsa_key[i]);
2509 # ifndef OPENSSL_NO_DSA
2510 for (i = 0; i < DSA_NUM; i++)
2511 if (dsa_key[i] != NULL)
2512 DSA_free(dsa_key[i]);
2515 # ifndef OPENSSL_NO_ECDSA
2516 for (i = 0; i < EC_NUM; i++)
2517 if (ecdsa[i] != NULL)
2518 EC_KEY_free(ecdsa[i]);
2520 # ifndef OPENSSL_NO_ECDH
2521 for (i = 0; i < EC_NUM; i++) {
2522 if (ecdh_a[i] != NULL)
2523 EC_KEY_free(ecdh_a[i]);
2524 if (ecdh_b[i] != NULL)
2525 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);
2617 for (n = 0; n < multi; ++n) {
2618 if (pipe(fd) == -1) {
2619 fprintf(stderr, "pipe failure\n");
2630 if (dup(fd[1]) == -1) {
2631 fprintf(stderr, "dup failed\n");
2640 printf("Forked child %d\n", n);
2643 /* for now, assume the pipe is long enough to take all the output */
2644 for (n = 0; n < multi; ++n) {
2649 f = fdopen(fds[n], "r");
2650 while (fgets(buf, sizeof buf, f)) {
2651 p = strchr(buf, '\n');
2654 if (buf[0] != '+') {
2655 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2659 printf("Got: %s from %d\n", buf, n);
2660 if (!strncmp(buf, "+F:", 3)) {
2665 alg = atoi(sstrsep(&p, sep));
2667 for (j = 0; j < SIZE_NUM; ++j)
2668 results[alg][j] += atof(sstrsep(&p, sep));
2669 } else if (!strncmp(buf, "+F2:", 4)) {
2674 k = atoi(sstrsep(&p, sep));
2677 d = atof(sstrsep(&p, sep));
2679 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2681 rsa_results[k][0] = d;
2683 d = atof(sstrsep(&p, sep));
2685 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2687 rsa_results[k][1] = d;
2689 # ifndef OPENSSL_NO_DSA
2690 else if (!strncmp(buf, "+F3:", 4)) {
2695 k = atoi(sstrsep(&p, sep));
2698 d = atof(sstrsep(&p, sep));
2700 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2702 dsa_results[k][0] = d;
2704 d = atof(sstrsep(&p, sep));
2706 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2708 dsa_results[k][1] = d;
2711 # ifndef OPENSSL_NO_ECDSA
2712 else if (!strncmp(buf, "+F4:", 4)) {
2717 k = atoi(sstrsep(&p, sep));
2720 d = atof(sstrsep(&p, sep));
2722 ecdsa_results[k][0] =
2723 1 / (1 / ecdsa_results[k][0] + 1 / d);
2725 ecdsa_results[k][0] = d;
2727 d = atof(sstrsep(&p, sep));
2729 ecdsa_results[k][1] =
2730 1 / (1 / ecdsa_results[k][1] + 1 / d);
2732 ecdsa_results[k][1] = d;
2736 # ifndef OPENSSL_NO_ECDH
2737 else if (!strncmp(buf, "+F5:", 4)) {
2742 k = atoi(sstrsep(&p, sep));
2745 d = atof(sstrsep(&p, sep));
2747 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2749 ecdh_results[k][0] = d;
2754 else if (!strncmp(buf, "+H:", 3)) {
2756 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2766 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2768 static int mblengths[] =
2769 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2770 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2771 const char *alg_name;
2772 unsigned char *inp, *out, no_key[32], no_iv[16];
2776 inp = OPENSSL_malloc(mblengths[num - 1]);
2777 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2779 BIO_printf(bio_err,"Out of memory\n");
2784 EVP_CIPHER_CTX_init(&ctx);
2785 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2786 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2788 alg_name = OBJ_nid2ln(evp_cipher->nid);
2790 for (j = 0; j < num; j++) {
2791 print_message(alg_name, 0, mblengths[j]);
2793 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2794 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
2795 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2796 size_t len = mblengths[j];
2799 memset(aad, 0, 8); /* avoid uninitialized values */
2800 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2801 aad[9] = 3; /* version */
2803 aad[11] = 0; /* length */
2805 mb_param.out = NULL;
2808 mb_param.interleave = 8;
2810 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2811 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2812 sizeof(mb_param), &mb_param);
2818 EVP_CIPHER_CTX_ctrl(&ctx,
2819 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2820 sizeof(mb_param), &mb_param);
2824 RAND_bytes(out, 16);
2828 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2829 EVP_CTRL_AEAD_TLS1_AAD,
2830 EVP_AEAD_TLS1_AAD_LEN, aad);
2831 EVP_Cipher(&ctx, out, inp, len + pad);
2836 mr ? "+R:%d:%s:%f\n"
2837 : "%d %s's in %.2fs\n", count, "evp", d);
2838 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2842 fprintf(stdout, "+H");
2843 for (j = 0; j < num; j++)
2844 fprintf(stdout, ":%d", mblengths[j]);
2845 fprintf(stdout, "\n");
2846 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2847 for (j = 0; j < num; j++)
2848 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2849 fprintf(stdout, "\n");
2852 "The 'numbers' are in 1000s of bytes per second processed.\n");
2853 fprintf(stdout, "type ");
2854 for (j = 0; j < num; j++)
2855 fprintf(stdout, "%7d bytes", mblengths[j]);
2856 fprintf(stdout, "\n");
2857 fprintf(stdout, "%-24s", alg_name);
2859 for (j = 0; j < num; j++) {
2860 if (results[D_EVP][j] > 10000)
2861 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2863 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2865 fprintf(stdout, "\n");