1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
58 /* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
67 * The ECDH and ECDSA speed test software is originally written by
68 * Sumit Gupta of Sun Microsystems Laboratories.
72 /* most of this code has been pilfered from my libdes speed.c program */
74 #ifndef OPENSSL_NO_SPEED
78 # define PRIME_SECONDS 10
79 # define RSA_SECONDS 10
80 # define DSA_SECONDS 10
81 # define ECDSA_SECONDS 10
82 # define ECDH_SECONDS 10
84 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
85 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
88 # define PROG speed_main
96 # include <openssl/crypto.h>
97 # include <openssl/rand.h>
98 # include <openssl/err.h>
99 # include <openssl/evp.h>
100 # include <openssl/objects.h>
101 # if !defined(OPENSSL_SYS_MSDOS)
102 # include OPENSSL_UNISTD
105 # ifndef OPENSSL_SYS_NETWARE
109 # if defined(_WIN32) || defined(__CYGWIN__)
110 # include <windows.h>
111 # if defined(__CYGWIN__) && !defined(_WIN32)
113 * <windows.h> should define _WIN32, which normally is mutually exclusive
114 * with __CYGWIN__, but if it didn't...
117 /* this is done because Cygwin alarm() fails sometimes. */
121 # include <openssl/bn.h>
122 # ifndef OPENSSL_NO_DES
123 # include <openssl/des.h>
125 # ifndef OPENSSL_NO_AES
126 # include <openssl/aes.h>
128 # ifndef OPENSSL_NO_CAMELLIA
129 # include <openssl/camellia.h>
131 # ifndef OPENSSL_NO_MD2
132 # include <openssl/md2.h>
134 # ifndef OPENSSL_NO_MDC2
135 # include <openssl/mdc2.h>
137 # ifndef OPENSSL_NO_MD4
138 # include <openssl/md4.h>
140 # ifndef OPENSSL_NO_MD5
141 # include <openssl/md5.h>
143 # ifndef OPENSSL_NO_HMAC
144 # include <openssl/hmac.h>
146 # include <openssl/evp.h>
147 # ifndef OPENSSL_NO_SHA
148 # include <openssl/sha.h>
150 # ifndef OPENSSL_NO_RMD160
151 # include <openssl/ripemd.h>
153 # ifndef OPENSSL_NO_WHIRLPOOL
154 # include <openssl/whrlpool.h>
156 # ifndef OPENSSL_NO_RC4
157 # include <openssl/rc4.h>
159 # ifndef OPENSSL_NO_RC5
160 # include <openssl/rc5.h>
162 # ifndef OPENSSL_NO_RC2
163 # include <openssl/rc2.h>
165 # ifndef OPENSSL_NO_IDEA
166 # include <openssl/idea.h>
168 # ifndef OPENSSL_NO_SEED
169 # include <openssl/seed.h>
171 # ifndef OPENSSL_NO_BF
172 # include <openssl/blowfish.h>
174 # ifndef OPENSSL_NO_CAST
175 # include <openssl/cast.h>
177 # ifndef OPENSSL_NO_RSA
178 # include <openssl/rsa.h>
179 # include "./testrsa.h"
181 # include <openssl/x509.h>
182 # ifndef OPENSSL_NO_DSA
183 # include <openssl/dsa.h>
184 # include "./testdsa.h"
186 # ifndef OPENSSL_NO_ECDSA
187 # include <openssl/ecdsa.h>
189 # ifndef OPENSSL_NO_ECDH
190 # include <openssl/ecdh.h>
192 # include <openssl/modes.h>
194 # include <openssl/bn.h>
197 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
211 # define BUFSIZE (1024*8+1)
212 # define MAX_MISALIGNMENT 63
214 static volatile int run = 0;
217 static int usertime = 1;
219 static double Time_F(int s);
220 static void print_message(const char *s, long num, int length);
221 static void pkey_print_message(const char *str, const char *str2,
222 long num, int bits, int sec);
223 static void print_result(int alg, int run_no, int count, double time_used);
225 static int do_multi(int multi);
228 # define ALGOR_NUM 30
235 # define MAX_ECDH_SIZE 256
237 static const char *names[ALGOR_NUM] = {
238 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
239 "des cbc", "des ede3", "idea cbc", "seed cbc",
240 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
241 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
242 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
243 "evp", "sha256", "sha512", "whirlpool",
244 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
247 static double results[ALGOR_NUM][SIZE_NUM];
248 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
250 # ifndef OPENSSL_NO_RSA
251 static double rsa_results[RSA_NUM][2];
253 # ifndef OPENSSL_NO_DSA
254 static double dsa_results[DSA_NUM][2];
256 # ifndef OPENSSL_NO_ECDSA
257 static double ecdsa_results[EC_NUM][2];
259 # ifndef OPENSSL_NO_ECDH
260 static double ecdh_results[EC_NUM][1];
263 # if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
264 static const char rnd_seed[] =
265 "string to make the random number generator think it has entropy";
266 static int rnd_fake = 0;
270 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
271 # define SIGRETTYPE void
273 # define SIGRETTYPE int
276 static SIGRETTYPE sig_done(int sig);
277 static SIGRETTYPE sig_done(int sig)
279 signal(SIGALRM, sig_done);
289 # if !defined(SIGALRM)
292 static unsigned int lapse, schlock;
293 static void alarm_win32(unsigned int secs)
298 # define alarm alarm_win32
300 static DWORD WINAPI sleepy(VOID * arg)
308 static double Time_F(int s)
315 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
317 DWORD ret = GetLastError();
318 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
322 Sleep(0); /* scheduler spinlock */
323 ret = app_tminterval(s, usertime);
325 ret = app_tminterval(s, usertime);
327 TerminateThread(thr, 0);
335 static double Time_F(int s)
337 double ret = app_tminterval(s, usertime);
344 # ifndef OPENSSL_NO_ECDH
345 static const int KDF1_SHA1_len = 20;
346 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
349 # ifndef OPENSSL_NO_SHA
350 if (*outlen < SHA_DIGEST_LENGTH)
353 *outlen = SHA_DIGEST_LENGTH;
354 return SHA1(in, inlen, out);
357 # endif /* OPENSSL_NO_SHA */
359 # endif /* OPENSSL_NO_ECDH */
361 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
363 int MAIN(int, char **);
365 int MAIN(int argc, char **argv)
367 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
368 unsigned char *buf = NULL, *buf2 = NULL;
370 long count = 0, save_count = 0;
372 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
375 # ifndef OPENSSL_NO_RSA
378 unsigned char md[EVP_MAX_MD_SIZE];
379 # ifndef OPENSSL_NO_MD2
380 unsigned char md2[MD2_DIGEST_LENGTH];
382 # ifndef OPENSSL_NO_MDC2
383 unsigned char mdc2[MDC2_DIGEST_LENGTH];
385 # ifndef OPENSSL_NO_MD4
386 unsigned char md4[MD4_DIGEST_LENGTH];
388 # ifndef OPENSSL_NO_MD5
389 unsigned char md5[MD5_DIGEST_LENGTH];
390 unsigned char hmac[MD5_DIGEST_LENGTH];
392 # ifndef OPENSSL_NO_SHA
393 unsigned char sha[SHA_DIGEST_LENGTH];
394 # ifndef OPENSSL_NO_SHA256
395 unsigned char sha256[SHA256_DIGEST_LENGTH];
397 # ifndef OPENSSL_NO_SHA512
398 unsigned char sha512[SHA512_DIGEST_LENGTH];
401 # ifndef OPENSSL_NO_WHIRLPOOL
402 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
404 # ifndef OPENSSL_NO_RMD160
405 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
407 # ifndef OPENSSL_NO_RC4
410 # ifndef OPENSSL_NO_RC5
413 # ifndef OPENSSL_NO_RC2
416 # ifndef OPENSSL_NO_IDEA
417 IDEA_KEY_SCHEDULE idea_ks;
419 # ifndef OPENSSL_NO_SEED
420 SEED_KEY_SCHEDULE seed_ks;
422 # ifndef OPENSSL_NO_BF
425 # ifndef OPENSSL_NO_CAST
428 static const unsigned char key16[16] = {
429 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
430 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
432 # ifndef OPENSSL_NO_AES
433 static const unsigned char key24[24] = {
434 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
435 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
436 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
438 static const unsigned char key32[32] = {
439 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
440 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
441 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
442 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
445 # ifndef OPENSSL_NO_CAMELLIA
446 static const unsigned char ckey24[24] = {
447 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
448 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
449 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
451 static const unsigned char ckey32[32] = {
452 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
453 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
454 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
455 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
458 # ifndef OPENSSL_NO_AES
459 # define MAX_BLOCK_SIZE 128
461 # define MAX_BLOCK_SIZE 64
463 unsigned char DES_iv[8];
464 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
465 # ifndef OPENSSL_NO_DES
466 static DES_cblock key =
467 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
468 static DES_cblock key2 =
469 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
470 static DES_cblock key3 =
471 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
472 DES_key_schedule sch;
473 DES_key_schedule sch2;
474 DES_key_schedule sch3;
476 # ifndef OPENSSL_NO_AES
477 AES_KEY aes_ks1, aes_ks2, aes_ks3;
479 # ifndef OPENSSL_NO_CAMELLIA
480 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
491 # define D_EDE3_DES 9
492 # define D_CBC_IDEA 10
493 # define D_CBC_SEED 11
494 # define D_CBC_RC2 12
495 # define D_CBC_RC5 13
497 # define D_CBC_CAST 15
498 # define D_CBC_128_AES 16
499 # define D_CBC_192_AES 17
500 # define D_CBC_256_AES 18
501 # define D_CBC_128_CML 19
502 # define D_CBC_192_CML 20
503 # define D_CBC_256_CML 21
507 # define D_WHIRLPOOL 25
508 # define D_IGE_128_AES 26
509 # define D_IGE_192_AES 27
510 # define D_IGE_256_AES 28
513 long c[ALGOR_NUM][SIZE_NUM];
515 # ifndef OPENSSL_SYS_WIN32
518 # define R_DSA_1024 1
519 # define R_DSA_2048 2
521 # define R_RSA_1024 1
522 # define R_RSA_2048 2
523 # define R_RSA_3072 3
524 # define R_RSA_4096 4
525 # define R_RSA_7680 5
526 # define R_RSA_15360 6
538 # define R_EC_K571 10
539 # define R_EC_B163 11
540 # define R_EC_B233 12
541 # define R_EC_B283 13
542 # define R_EC_B409 14
543 # define R_EC_B571 15
545 # ifndef OPENSSL_NO_RSA
546 RSA *rsa_key[RSA_NUM];
547 long rsa_c[RSA_NUM][2];
548 static unsigned int rsa_bits[RSA_NUM] = {
549 512, 1024, 2048, 3072, 4096, 7680, 15360
551 static unsigned char *rsa_data[RSA_NUM] = {
552 test512, test1024, test2048, test3072, test4096, test7680, test15360
554 static int rsa_data_length[RSA_NUM] = {
555 sizeof(test512), sizeof(test1024),
556 sizeof(test2048), sizeof(test3072),
557 sizeof(test4096), sizeof(test7680),
561 # ifndef OPENSSL_NO_DSA
562 DSA *dsa_key[DSA_NUM];
563 long dsa_c[DSA_NUM][2];
564 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
566 # ifndef OPENSSL_NO_EC
568 * We only test over the following curves as they are representative, To
569 * add tests over more curves, simply add the curve NID and curve name to
570 * the following arrays and increase the EC_NUM value accordingly.
572 static unsigned int test_curves[EC_NUM] = {
575 NID_X9_62_prime192v1,
577 NID_X9_62_prime256v1,
592 static const char *test_curves_names[EC_NUM] = {
612 static int test_curves_bits[EC_NUM] = {
613 160, 192, 224, 256, 384, 521,
614 163, 233, 283, 409, 571,
615 163, 233, 283, 409, 571
620 # ifndef OPENSSL_NO_ECDSA
621 unsigned char ecdsasig[256];
622 unsigned int ecdsasiglen;
623 EC_KEY *ecdsa[EC_NUM];
624 long ecdsa_c[EC_NUM][2];
627 # ifndef OPENSSL_NO_ECDH
628 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
629 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
630 int secret_size_a, secret_size_b;
633 long ecdh_c[EC_NUM][2];
636 int rsa_doit[RSA_NUM];
637 int dsa_doit[DSA_NUM];
638 # ifndef OPENSSL_NO_ECDSA
639 int ecdsa_doit[EC_NUM];
641 # ifndef OPENSSL_NO_ECDH
642 int ecdh_doit[EC_NUM];
646 const EVP_CIPHER *evp_cipher = NULL;
647 const EVP_MD *evp_md = NULL;
653 int misalign = MAX_MISALIGNMENT + 1;
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++) {
676 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
677 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
679 if (!load_config(bio_err, NULL))
682 # ifndef OPENSSL_NO_RSA
683 memset(rsa_key, 0, sizeof(rsa_key));
684 for (i = 0; i < RSA_NUM; i++)
689 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
690 BIO_printf(bio_err, "out of memory\n");
694 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
695 BIO_printf(bio_err, "out of memory\n");
699 misalign = 0; /* set later and buf/buf2 are adjusted
704 memset(c, 0, sizeof(c));
705 memset(DES_iv, 0, sizeof(DES_iv));
706 memset(iv, 0, sizeof(iv));
708 for (i = 0; i < ALGOR_NUM; i++)
710 for (i = 0; i < RSA_NUM; i++)
712 for (i = 0; i < DSA_NUM; i++)
714 # ifndef OPENSSL_NO_ECDSA
715 for (i = 0; i < EC_NUM; i++)
718 # ifndef OPENSSL_NO_ECDH
719 for (i = 0; i < EC_NUM; i++)
727 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
729 j--; /* Otherwise, -elapsed gets confused with an
731 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
735 BIO_printf(bio_err, "no EVP given\n");
738 evp_cipher = EVP_get_cipherbyname(*argv);
740 evp_md = EVP_get_digestbyname(*argv);
742 if (!evp_cipher && !evp_md) {
743 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
748 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
750 j--; /* Otherwise, -elapsed gets confused with an
753 # ifndef OPENSSL_NO_ENGINE
754 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
758 BIO_printf(bio_err, "no engine given\n");
761 setup_engine(bio_err, *argv, 0);
763 * j will be increased again further down. We just don't want
764 * speed to confuse an engine with an algorithm, especially when
765 * none is given (which means all of them should be run)
771 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
775 BIO_printf(bio_err, "no multi count given\n");
778 multi = atoi(argv[0]);
780 BIO_printf(bio_err, "bad multi count\n");
783 j--; /* Otherwise, -mr gets confused with an
787 else if (argc > 0 && !strcmp(*argv, "-mr")) {
789 j--; /* Otherwise, -mr gets confused with an
791 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
794 } else if (argc > 0 && !strcmp(*argv, "-misalign")) {
798 BIO_printf(bio_err, "no misalignment given\n");
801 misalign = atoi(argv[0]);
802 if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
804 "misalignment is outsize permitted range 0-%d\n",
808 buf = buf_malloc + misalign;
809 buf2 = buf2_malloc + misalign;
812 # ifndef OPENSSL_NO_MD2
813 if (strcmp(*argv, "md2") == 0)
817 # ifndef OPENSSL_NO_MDC2
818 if (strcmp(*argv, "mdc2") == 0)
822 # ifndef OPENSSL_NO_MD4
823 if (strcmp(*argv, "md4") == 0)
827 # ifndef OPENSSL_NO_MD5
828 if (strcmp(*argv, "md5") == 0)
832 # ifndef OPENSSL_NO_MD5
833 if (strcmp(*argv, "hmac") == 0)
837 # ifndef OPENSSL_NO_SHA
838 if (strcmp(*argv, "sha1") == 0)
840 else if (strcmp(*argv, "sha") == 0)
841 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
843 # ifndef OPENSSL_NO_SHA256
844 if (strcmp(*argv, "sha256") == 0)
848 # ifndef OPENSSL_NO_SHA512
849 if (strcmp(*argv, "sha512") == 0)
854 # ifndef OPENSSL_NO_WHIRLPOOL
855 if (strcmp(*argv, "whirlpool") == 0)
856 doit[D_WHIRLPOOL] = 1;
859 # ifndef OPENSSL_NO_RMD160
860 if (strcmp(*argv, "ripemd") == 0)
862 else if (strcmp(*argv, "rmd160") == 0)
864 else if (strcmp(*argv, "ripemd160") == 0)
868 # ifndef OPENSSL_NO_RC4
869 if (strcmp(*argv, "rc4") == 0)
873 # ifndef OPENSSL_NO_DES
874 if (strcmp(*argv, "des-cbc") == 0)
876 else if (strcmp(*argv, "des-ede3") == 0)
877 doit[D_EDE3_DES] = 1;
880 # ifndef OPENSSL_NO_AES
881 if (strcmp(*argv, "aes-128-cbc") == 0)
882 doit[D_CBC_128_AES] = 1;
883 else if (strcmp(*argv, "aes-192-cbc") == 0)
884 doit[D_CBC_192_AES] = 1;
885 else if (strcmp(*argv, "aes-256-cbc") == 0)
886 doit[D_CBC_256_AES] = 1;
887 else if (strcmp(*argv, "aes-128-ige") == 0)
888 doit[D_IGE_128_AES] = 1;
889 else if (strcmp(*argv, "aes-192-ige") == 0)
890 doit[D_IGE_192_AES] = 1;
891 else if (strcmp(*argv, "aes-256-ige") == 0)
892 doit[D_IGE_256_AES] = 1;
895 # ifndef OPENSSL_NO_CAMELLIA
896 if (strcmp(*argv, "camellia-128-cbc") == 0)
897 doit[D_CBC_128_CML] = 1;
898 else if (strcmp(*argv, "camellia-192-cbc") == 0)
899 doit[D_CBC_192_CML] = 1;
900 else if (strcmp(*argv, "camellia-256-cbc") == 0)
901 doit[D_CBC_256_CML] = 1;
904 # ifndef OPENSSL_NO_RSA
905 # if 0 /* was: #ifdef RSAref */
906 if (strcmp(*argv, "rsaref") == 0) {
907 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
912 if (strcmp(*argv, "openssl") == 0) {
913 RSA_set_default_method(RSA_PKCS1_SSLeay());
917 # endif /* !OPENSSL_NO_RSA */
918 if (strcmp(*argv, "dsa512") == 0)
919 dsa_doit[R_DSA_512] = 2;
920 else if (strcmp(*argv, "dsa1024") == 0)
921 dsa_doit[R_DSA_1024] = 2;
922 else if (strcmp(*argv, "dsa2048") == 0)
923 dsa_doit[R_DSA_2048] = 2;
924 else if (strcmp(*argv, "rsa512") == 0)
925 rsa_doit[R_RSA_512] = 2;
926 else if (strcmp(*argv, "rsa1024") == 0)
927 rsa_doit[R_RSA_1024] = 2;
928 else if (strcmp(*argv, "rsa2048") == 0)
929 rsa_doit[R_RSA_2048] = 2;
930 else if (strcmp(*argv, "rsa3072") == 0)
931 rsa_doit[R_RSA_3072] = 2;
932 else if (strcmp(*argv, "rsa4096") == 0)
933 rsa_doit[R_RSA_4096] = 2;
934 else if (strcmp(*argv, "rsa7680") == 0)
935 rsa_doit[R_RSA_7680] = 2;
936 else if (strcmp(*argv, "rsa15360") == 0)
937 rsa_doit[R_RSA_15360] = 2;
939 # ifndef OPENSSL_NO_RC2
940 if (strcmp(*argv, "rc2-cbc") == 0)
942 else if (strcmp(*argv, "rc2") == 0)
946 # ifndef OPENSSL_NO_RC5
947 if (strcmp(*argv, "rc5-cbc") == 0)
949 else if (strcmp(*argv, "rc5") == 0)
953 # ifndef OPENSSL_NO_IDEA
954 if (strcmp(*argv, "idea-cbc") == 0)
955 doit[D_CBC_IDEA] = 1;
956 else if (strcmp(*argv, "idea") == 0)
957 doit[D_CBC_IDEA] = 1;
960 # ifndef OPENSSL_NO_SEED
961 if (strcmp(*argv, "seed-cbc") == 0)
962 doit[D_CBC_SEED] = 1;
963 else if (strcmp(*argv, "seed") == 0)
964 doit[D_CBC_SEED] = 1;
967 # ifndef OPENSSL_NO_BF
968 if (strcmp(*argv, "bf-cbc") == 0)
970 else if (strcmp(*argv, "blowfish") == 0)
972 else if (strcmp(*argv, "bf") == 0)
976 # ifndef OPENSSL_NO_CAST
977 if (strcmp(*argv, "cast-cbc") == 0)
978 doit[D_CBC_CAST] = 1;
979 else if (strcmp(*argv, "cast") == 0)
980 doit[D_CBC_CAST] = 1;
981 else if (strcmp(*argv, "cast5") == 0)
982 doit[D_CBC_CAST] = 1;
985 # ifndef OPENSSL_NO_DES
986 if (strcmp(*argv, "des") == 0) {
988 doit[D_EDE3_DES] = 1;
991 # ifndef OPENSSL_NO_AES
992 if (strcmp(*argv, "aes") == 0) {
993 doit[D_CBC_128_AES] = 1;
994 doit[D_CBC_192_AES] = 1;
995 doit[D_CBC_256_AES] = 1;
996 } else if (strcmp(*argv, "ghash") == 0) {
1000 # ifndef OPENSSL_NO_CAMELLIA
1001 if (strcmp(*argv, "camellia") == 0) {
1002 doit[D_CBC_128_CML] = 1;
1003 doit[D_CBC_192_CML] = 1;
1004 doit[D_CBC_256_CML] = 1;
1007 # ifndef OPENSSL_NO_RSA
1008 if (strcmp(*argv, "rsa") == 0) {
1009 rsa_doit[R_RSA_512] = 1;
1010 rsa_doit[R_RSA_1024] = 1;
1011 rsa_doit[R_RSA_2048] = 1;
1012 rsa_doit[R_RSA_3072] = 1;
1013 rsa_doit[R_RSA_4096] = 1;
1014 rsa_doit[R_RSA_7680] = 1;
1015 rsa_doit[R_RSA_15360] = 1;
1018 # ifndef OPENSSL_NO_DSA
1019 if (strcmp(*argv, "dsa") == 0) {
1020 dsa_doit[R_DSA_512] = 1;
1021 dsa_doit[R_DSA_1024] = 1;
1022 dsa_doit[R_DSA_2048] = 1;
1025 # ifndef OPENSSL_NO_ECDSA
1026 if (strcmp(*argv, "ecdsap160") == 0)
1027 ecdsa_doit[R_EC_P160] = 2;
1028 else if (strcmp(*argv, "ecdsap192") == 0)
1029 ecdsa_doit[R_EC_P192] = 2;
1030 else if (strcmp(*argv, "ecdsap224") == 0)
1031 ecdsa_doit[R_EC_P224] = 2;
1032 else if (strcmp(*argv, "ecdsap256") == 0)
1033 ecdsa_doit[R_EC_P256] = 2;
1034 else if (strcmp(*argv, "ecdsap384") == 0)
1035 ecdsa_doit[R_EC_P384] = 2;
1036 else if (strcmp(*argv, "ecdsap521") == 0)
1037 ecdsa_doit[R_EC_P521] = 2;
1038 else if (strcmp(*argv, "ecdsak163") == 0)
1039 ecdsa_doit[R_EC_K163] = 2;
1040 else if (strcmp(*argv, "ecdsak233") == 0)
1041 ecdsa_doit[R_EC_K233] = 2;
1042 else if (strcmp(*argv, "ecdsak283") == 0)
1043 ecdsa_doit[R_EC_K283] = 2;
1044 else if (strcmp(*argv, "ecdsak409") == 0)
1045 ecdsa_doit[R_EC_K409] = 2;
1046 else if (strcmp(*argv, "ecdsak571") == 0)
1047 ecdsa_doit[R_EC_K571] = 2;
1048 else if (strcmp(*argv, "ecdsab163") == 0)
1049 ecdsa_doit[R_EC_B163] = 2;
1050 else if (strcmp(*argv, "ecdsab233") == 0)
1051 ecdsa_doit[R_EC_B233] = 2;
1052 else if (strcmp(*argv, "ecdsab283") == 0)
1053 ecdsa_doit[R_EC_B283] = 2;
1054 else if (strcmp(*argv, "ecdsab409") == 0)
1055 ecdsa_doit[R_EC_B409] = 2;
1056 else if (strcmp(*argv, "ecdsab571") == 0)
1057 ecdsa_doit[R_EC_B571] = 2;
1058 else if (strcmp(*argv, "ecdsa") == 0) {
1059 for (i = 0; i < EC_NUM; i++)
1063 # ifndef OPENSSL_NO_ECDH
1064 if (strcmp(*argv, "ecdhp160") == 0)
1065 ecdh_doit[R_EC_P160] = 2;
1066 else if (strcmp(*argv, "ecdhp192") == 0)
1067 ecdh_doit[R_EC_P192] = 2;
1068 else if (strcmp(*argv, "ecdhp224") == 0)
1069 ecdh_doit[R_EC_P224] = 2;
1070 else if (strcmp(*argv, "ecdhp256") == 0)
1071 ecdh_doit[R_EC_P256] = 2;
1072 else if (strcmp(*argv, "ecdhp384") == 0)
1073 ecdh_doit[R_EC_P384] = 2;
1074 else if (strcmp(*argv, "ecdhp521") == 0)
1075 ecdh_doit[R_EC_P521] = 2;
1076 else if (strcmp(*argv, "ecdhk163") == 0)
1077 ecdh_doit[R_EC_K163] = 2;
1078 else if (strcmp(*argv, "ecdhk233") == 0)
1079 ecdh_doit[R_EC_K233] = 2;
1080 else if (strcmp(*argv, "ecdhk283") == 0)
1081 ecdh_doit[R_EC_K283] = 2;
1082 else if (strcmp(*argv, "ecdhk409") == 0)
1083 ecdh_doit[R_EC_K409] = 2;
1084 else if (strcmp(*argv, "ecdhk571") == 0)
1085 ecdh_doit[R_EC_K571] = 2;
1086 else if (strcmp(*argv, "ecdhb163") == 0)
1087 ecdh_doit[R_EC_B163] = 2;
1088 else if (strcmp(*argv, "ecdhb233") == 0)
1089 ecdh_doit[R_EC_B233] = 2;
1090 else if (strcmp(*argv, "ecdhb283") == 0)
1091 ecdh_doit[R_EC_B283] = 2;
1092 else if (strcmp(*argv, "ecdhb409") == 0)
1093 ecdh_doit[R_EC_B409] = 2;
1094 else if (strcmp(*argv, "ecdhb571") == 0)
1095 ecdh_doit[R_EC_B571] = 2;
1096 else if (strcmp(*argv, "ecdh") == 0) {
1097 for (i = 0; i < EC_NUM; i++)
1102 BIO_printf(bio_err, "Error: bad option or value\n");
1103 BIO_printf(bio_err, "\n");
1104 BIO_printf(bio_err, "Available values:\n");
1105 # ifndef OPENSSL_NO_MD2
1106 BIO_printf(bio_err, "md2 ");
1108 # ifndef OPENSSL_NO_MDC2
1109 BIO_printf(bio_err, "mdc2 ");
1111 # ifndef OPENSSL_NO_MD4
1112 BIO_printf(bio_err, "md4 ");
1114 # ifndef OPENSSL_NO_MD5
1115 BIO_printf(bio_err, "md5 ");
1116 # ifndef OPENSSL_NO_HMAC
1117 BIO_printf(bio_err, "hmac ");
1120 # ifndef OPENSSL_NO_SHA1
1121 BIO_printf(bio_err, "sha1 ");
1123 # ifndef OPENSSL_NO_SHA256
1124 BIO_printf(bio_err, "sha256 ");
1126 # ifndef OPENSSL_NO_SHA512
1127 BIO_printf(bio_err, "sha512 ");
1129 # ifndef OPENSSL_NO_WHIRLPOOL
1130 BIO_printf(bio_err, "whirlpool");
1132 # ifndef OPENSSL_NO_RMD160
1133 BIO_printf(bio_err, "rmd160");
1135 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1136 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1137 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \
1138 !defined(OPENSSL_NO_WHIRLPOOL)
1139 BIO_printf(bio_err, "\n");
1142 # ifndef OPENSSL_NO_IDEA
1143 BIO_printf(bio_err, "idea-cbc ");
1145 # ifndef OPENSSL_NO_SEED
1146 BIO_printf(bio_err, "seed-cbc ");
1148 # ifndef OPENSSL_NO_RC2
1149 BIO_printf(bio_err, "rc2-cbc ");
1151 # ifndef OPENSSL_NO_RC5
1152 BIO_printf(bio_err, "rc5-cbc ");
1154 # ifndef OPENSSL_NO_BF
1155 BIO_printf(bio_err, "bf-cbc");
1157 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1158 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1159 BIO_printf(bio_err, "\n");
1161 # ifndef OPENSSL_NO_DES
1162 BIO_printf(bio_err, "des-cbc des-ede3 ");
1164 # ifndef OPENSSL_NO_AES
1165 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1166 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1168 # ifndef OPENSSL_NO_CAMELLIA
1169 BIO_printf(bio_err, "\n");
1171 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1173 # ifndef OPENSSL_NO_RC4
1174 BIO_printf(bio_err, "rc4");
1176 BIO_printf(bio_err, "\n");
1178 # ifndef OPENSSL_NO_RSA
1180 "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1181 BIO_printf(bio_err, "rsa7680 rsa15360\n");
1184 # ifndef OPENSSL_NO_DSA
1185 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1187 # ifndef OPENSSL_NO_ECDSA
1188 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1189 "ecdsap256 ecdsap384 ecdsap521\n");
1191 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1193 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1194 BIO_printf(bio_err, "ecdsa\n");
1196 # ifndef OPENSSL_NO_ECDH
1197 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1198 "ecdhp256 ecdhp384 ecdhp521\n");
1200 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1202 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1203 BIO_printf(bio_err, "ecdh\n");
1206 # ifndef OPENSSL_NO_IDEA
1207 BIO_printf(bio_err, "idea ");
1209 # ifndef OPENSSL_NO_SEED
1210 BIO_printf(bio_err, "seed ");
1212 # ifndef OPENSSL_NO_RC2
1213 BIO_printf(bio_err, "rc2 ");
1215 # ifndef OPENSSL_NO_DES
1216 BIO_printf(bio_err, "des ");
1218 # ifndef OPENSSL_NO_AES
1219 BIO_printf(bio_err, "aes ");
1221 # ifndef OPENSSL_NO_CAMELLIA
1222 BIO_printf(bio_err, "camellia ");
1224 # ifndef OPENSSL_NO_RSA
1225 BIO_printf(bio_err, "rsa ");
1227 # ifndef OPENSSL_NO_BF
1228 BIO_printf(bio_err, "blowfish");
1230 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1231 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1232 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1233 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1234 BIO_printf(bio_err, "\n");
1237 BIO_printf(bio_err, "\n");
1238 BIO_printf(bio_err, "Available options:\n");
1239 # if defined(TIMES) || defined(USE_TOD)
1240 BIO_printf(bio_err, "-elapsed "
1241 "measure time in real time instead of CPU user time.\n");
1243 # ifndef OPENSSL_NO_ENGINE
1246 "use engine e, possibly a hardware device.\n");
1248 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1251 "time decryption instead of encryption (only EVP).\n");
1254 "produce machine readable output.\n");
1257 "perform multi-block benchmark (for specific ciphers)\n");
1260 "perform benchmark with misaligned data\n");
1263 "-multi n " "run n benchmarks in parallel.\n");
1273 if (multi && do_multi(multi))
1278 for (i = 0; i < ALGOR_NUM; i++) {
1282 for (i = 0; i < RSA_NUM; i++)
1284 for (i = 0; i < DSA_NUM; i++)
1286 # ifndef OPENSSL_NO_ECDSA
1287 for (i = 0; i < EC_NUM; i++)
1290 # ifndef OPENSSL_NO_ECDH
1291 for (i = 0; i < EC_NUM; i++)
1295 for (i = 0; i < ALGOR_NUM; i++)
1299 if (usertime == 0 && !mr)
1301 "You have chosen to measure elapsed time "
1302 "instead of user CPU time.\n");
1304 # ifndef OPENSSL_NO_RSA
1305 for (i = 0; i < RSA_NUM; i++) {
1306 const unsigned char *p;
1309 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1310 if (rsa_key[i] == NULL) {
1311 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1319 : "Loaded RSA key, %d bit modulus and e= 0x",
1320 BN_num_bits(rsa_key[i]->n));
1321 BN_print(bio_err, rsa_key[i]->e);
1322 BIO_printf(bio_err, "\n");
1328 # ifndef OPENSSL_NO_DSA
1329 dsa_key[0] = get_dsa512();
1330 dsa_key[1] = get_dsa1024();
1331 dsa_key[2] = get_dsa2048();
1334 # ifndef OPENSSL_NO_DES
1335 DES_set_key_unchecked(&key, &sch);
1336 DES_set_key_unchecked(&key2, &sch2);
1337 DES_set_key_unchecked(&key3, &sch3);
1339 # ifndef OPENSSL_NO_AES
1340 AES_set_encrypt_key(key16, 128, &aes_ks1);
1341 AES_set_encrypt_key(key24, 192, &aes_ks2);
1342 AES_set_encrypt_key(key32, 256, &aes_ks3);
1344 # ifndef OPENSSL_NO_CAMELLIA
1345 Camellia_set_key(key16, 128, &camellia_ks1);
1346 Camellia_set_key(ckey24, 192, &camellia_ks2);
1347 Camellia_set_key(ckey32, 256, &camellia_ks3);
1349 # ifndef OPENSSL_NO_IDEA
1350 idea_set_encrypt_key(key16, &idea_ks);
1352 # ifndef OPENSSL_NO_SEED
1353 SEED_set_key(key16, &seed_ks);
1355 # ifndef OPENSSL_NO_RC4
1356 RC4_set_key(&rc4_ks, 16, key16);
1358 # ifndef OPENSSL_NO_RC2
1359 RC2_set_key(&rc2_ks, 16, key16, 128);
1361 # ifndef OPENSSL_NO_RC5
1362 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1364 # ifndef OPENSSL_NO_BF
1365 BF_set_key(&bf_ks, 16, key16);
1367 # ifndef OPENSSL_NO_CAST
1368 CAST_set_key(&cast_ks, 16, key16);
1370 # ifndef OPENSSL_NO_RSA
1371 memset(rsa_c, 0, sizeof(rsa_c));
1374 # ifndef OPENSSL_NO_DES
1375 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1381 for (it = count; it; it--)
1382 DES_ecb_encrypt((DES_cblock *)buf,
1383 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1387 c[D_MD2][0] = count / 10;
1388 c[D_MDC2][0] = count / 10;
1389 c[D_MD4][0] = count;
1390 c[D_MD5][0] = count;
1391 c[D_HMAC][0] = count;
1392 c[D_SHA1][0] = count;
1393 c[D_RMD160][0] = count;
1394 c[D_RC4][0] = count * 5;
1395 c[D_CBC_DES][0] = count;
1396 c[D_EDE3_DES][0] = count / 3;
1397 c[D_CBC_IDEA][0] = count;
1398 c[D_CBC_SEED][0] = count;
1399 c[D_CBC_RC2][0] = count;
1400 c[D_CBC_RC5][0] = count;
1401 c[D_CBC_BF][0] = count;
1402 c[D_CBC_CAST][0] = count;
1403 c[D_CBC_128_AES][0] = count;
1404 c[D_CBC_192_AES][0] = count;
1405 c[D_CBC_256_AES][0] = count;
1406 c[D_CBC_128_CML][0] = count;
1407 c[D_CBC_192_CML][0] = count;
1408 c[D_CBC_256_CML][0] = count;
1409 c[D_SHA256][0] = count;
1410 c[D_SHA512][0] = count;
1411 c[D_WHIRLPOOL][0] = count;
1412 c[D_IGE_128_AES][0] = count;
1413 c[D_IGE_192_AES][0] = count;
1414 c[D_IGE_256_AES][0] = count;
1415 c[D_GHASH][0] = count;
1417 for (i = 1; i < SIZE_NUM; i++) {
1420 l0 = (long)lengths[0];
1421 l1 = (long)lengths[i];
1423 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1424 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1425 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1426 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1427 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1428 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1429 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1430 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1431 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1432 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1434 l0 = (long)lengths[i - 1];
1436 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1437 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1438 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1439 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1440 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1441 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1442 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1443 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1444 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1445 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1446 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1447 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1448 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1449 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1450 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1451 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1452 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1453 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1456 # ifndef OPENSSL_NO_RSA
1457 rsa_c[R_RSA_512][0] = count / 2000;
1458 rsa_c[R_RSA_512][1] = count / 400;
1459 for (i = 1; i < RSA_NUM; i++) {
1460 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1461 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1462 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1465 if (rsa_c[i][0] == 0) {
1473 # ifndef OPENSSL_NO_DSA
1474 dsa_c[R_DSA_512][0] = count / 1000;
1475 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1476 for (i = 1; i < DSA_NUM; i++) {
1477 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1478 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1479 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1482 if (dsa_c[i] == 0) {
1490 # ifndef OPENSSL_NO_ECDSA
1491 ecdsa_c[R_EC_P160][0] = count / 1000;
1492 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1493 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1494 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1495 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1496 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1499 if (ecdsa_c[i] == 0) {
1505 ecdsa_c[R_EC_K163][0] = count / 1000;
1506 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1507 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1508 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1509 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1510 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1513 if (ecdsa_c[i] == 0) {
1519 ecdsa_c[R_EC_B163][0] = count / 1000;
1520 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1521 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1522 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1523 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1524 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1527 if (ecdsa_c[i] == 0) {
1535 # ifndef OPENSSL_NO_ECDH
1536 ecdh_c[R_EC_P160][0] = count / 1000;
1537 ecdh_c[R_EC_P160][1] = count / 1000;
1538 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1539 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1540 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1541 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1544 if (ecdh_c[i] == 0) {
1550 ecdh_c[R_EC_K163][0] = count / 1000;
1551 ecdh_c[R_EC_K163][1] = count / 1000;
1552 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1553 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1554 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1555 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1558 if (ecdh_c[i] == 0) {
1564 ecdh_c[R_EC_B163][0] = count / 1000;
1565 ecdh_c[R_EC_B163][1] = count / 1000;
1566 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1567 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1568 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1569 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1572 if (ecdh_c[i] == 0) {
1580 # define COND(d) (count < (d))
1581 # define COUNT(d) (d)
1583 /* not worth fixing */
1584 # error "You cannot disable DES on systems without SIGALRM."
1585 # endif /* OPENSSL_NO_DES */
1587 # define COND(c) (run && count<0x7fffffff)
1588 # define COUNT(d) (count)
1590 signal(SIGALRM, sig_done);
1592 # endif /* SIGALRM */
1594 # ifndef OPENSSL_NO_MD2
1596 for (j = 0; j < SIZE_NUM; j++) {
1597 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1599 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1600 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1603 print_result(D_MD2, j, count, d);
1607 # ifndef OPENSSL_NO_MDC2
1609 for (j = 0; j < SIZE_NUM; j++) {
1610 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1612 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1613 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1616 print_result(D_MDC2, j, count, d);
1621 # ifndef OPENSSL_NO_MD4
1623 for (j = 0; j < SIZE_NUM; j++) {
1624 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1626 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1627 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1628 NULL, EVP_md4(), NULL);
1630 print_result(D_MD4, j, count, d);
1635 # ifndef OPENSSL_NO_MD5
1637 for (j = 0; j < SIZE_NUM; j++) {
1638 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1640 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1641 MD5(buf, lengths[j], md5);
1643 print_result(D_MD5, j, count, d);
1648 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1652 HMAC_CTX_init(&hctx);
1653 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1654 16, EVP_md5(), NULL);
1656 for (j = 0; j < SIZE_NUM; j++) {
1657 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1659 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1660 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1661 HMAC_Update(&hctx, buf, lengths[j]);
1662 HMAC_Final(&hctx, &(hmac[0]), NULL);
1665 print_result(D_HMAC, j, count, d);
1667 HMAC_CTX_cleanup(&hctx);
1670 # ifndef OPENSSL_NO_SHA
1672 for (j = 0; j < SIZE_NUM; j++) {
1673 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1675 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1677 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1680 SHA1(buf, lengths[j], sha);
1683 print_result(D_SHA1, j, count, d);
1686 # ifndef OPENSSL_NO_SHA256
1687 if (doit[D_SHA256]) {
1688 for (j = 0; j < SIZE_NUM; j++) {
1689 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1691 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1692 SHA256(buf, lengths[j], sha256);
1694 print_result(D_SHA256, j, count, d);
1699 # ifndef OPENSSL_NO_SHA512
1700 if (doit[D_SHA512]) {
1701 for (j = 0; j < SIZE_NUM; j++) {
1702 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1704 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1705 SHA512(buf, lengths[j], sha512);
1707 print_result(D_SHA512, j, count, d);
1713 # ifndef OPENSSL_NO_WHIRLPOOL
1714 if (doit[D_WHIRLPOOL]) {
1715 for (j = 0; j < SIZE_NUM; j++) {
1716 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1718 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1719 WHIRLPOOL(buf, lengths[j], whirlpool);
1721 print_result(D_WHIRLPOOL, j, count, d);
1726 # ifndef OPENSSL_NO_RMD160
1727 if (doit[D_RMD160]) {
1728 for (j = 0; j < SIZE_NUM; j++) {
1729 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1731 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1732 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1733 EVP_ripemd160(), NULL);
1735 print_result(D_RMD160, j, count, d);
1739 # ifndef OPENSSL_NO_RC4
1741 for (j = 0; j < SIZE_NUM; j++) {
1742 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1744 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1745 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1747 print_result(D_RC4, j, count, d);
1751 # ifndef OPENSSL_NO_DES
1752 if (doit[D_CBC_DES]) {
1753 for (j = 0; j < SIZE_NUM; j++) {
1754 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1756 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1757 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1758 &DES_iv, DES_ENCRYPT);
1760 print_result(D_CBC_DES, j, count, d);
1764 if (doit[D_EDE3_DES]) {
1765 for (j = 0; j < SIZE_NUM; j++) {
1766 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1768 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1769 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1771 &DES_iv, DES_ENCRYPT);
1773 print_result(D_EDE3_DES, j, count, d);
1777 # ifndef OPENSSL_NO_AES
1778 if (doit[D_CBC_128_AES]) {
1779 for (j = 0; j < SIZE_NUM; j++) {
1780 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1783 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1784 AES_cbc_encrypt(buf, buf,
1785 (unsigned long)lengths[j], &aes_ks1,
1788 print_result(D_CBC_128_AES, j, count, d);
1791 if (doit[D_CBC_192_AES]) {
1792 for (j = 0; j < SIZE_NUM; j++) {
1793 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1796 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1797 AES_cbc_encrypt(buf, buf,
1798 (unsigned long)lengths[j], &aes_ks2,
1801 print_result(D_CBC_192_AES, j, count, d);
1804 if (doit[D_CBC_256_AES]) {
1805 for (j = 0; j < SIZE_NUM; j++) {
1806 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1809 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1810 AES_cbc_encrypt(buf, buf,
1811 (unsigned long)lengths[j], &aes_ks3,
1814 print_result(D_CBC_256_AES, j, count, d);
1818 if (doit[D_IGE_128_AES]) {
1819 for (j = 0; j < SIZE_NUM; j++) {
1820 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1823 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1824 AES_ige_encrypt(buf, buf2,
1825 (unsigned long)lengths[j], &aes_ks1,
1828 print_result(D_IGE_128_AES, j, count, d);
1831 if (doit[D_IGE_192_AES]) {
1832 for (j = 0; j < SIZE_NUM; j++) {
1833 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1836 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1837 AES_ige_encrypt(buf, buf2,
1838 (unsigned long)lengths[j], &aes_ks2,
1841 print_result(D_IGE_192_AES, j, count, d);
1844 if (doit[D_IGE_256_AES]) {
1845 for (j = 0; j < SIZE_NUM; j++) {
1846 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1849 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1850 AES_ige_encrypt(buf, buf2,
1851 (unsigned long)lengths[j], &aes_ks3,
1854 print_result(D_IGE_256_AES, j, count, d);
1857 if (doit[D_GHASH]) {
1858 GCM128_CONTEXT *ctx =
1859 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1860 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1862 for (j = 0; j < SIZE_NUM; j++) {
1863 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1865 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1866 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1868 print_result(D_GHASH, j, count, d);
1870 CRYPTO_gcm128_release(ctx);
1873 # ifndef OPENSSL_NO_CAMELLIA
1874 if (doit[D_CBC_128_CML]) {
1875 for (j = 0; j < SIZE_NUM; j++) {
1876 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1879 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1880 Camellia_cbc_encrypt(buf, buf,
1881 (unsigned long)lengths[j], &camellia_ks1,
1882 iv, CAMELLIA_ENCRYPT);
1884 print_result(D_CBC_128_CML, j, count, d);
1887 if (doit[D_CBC_192_CML]) {
1888 for (j = 0; j < SIZE_NUM; j++) {
1889 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1892 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1893 Camellia_cbc_encrypt(buf, buf,
1894 (unsigned long)lengths[j], &camellia_ks2,
1895 iv, CAMELLIA_ENCRYPT);
1897 print_result(D_CBC_192_CML, j, count, d);
1900 if (doit[D_CBC_256_CML]) {
1901 for (j = 0; j < SIZE_NUM; j++) {
1902 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1905 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1906 Camellia_cbc_encrypt(buf, buf,
1907 (unsigned long)lengths[j], &camellia_ks3,
1908 iv, CAMELLIA_ENCRYPT);
1910 print_result(D_CBC_256_CML, j, count, d);
1914 # ifndef OPENSSL_NO_IDEA
1915 if (doit[D_CBC_IDEA]) {
1916 for (j = 0; j < SIZE_NUM; j++) {
1917 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1919 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1920 idea_cbc_encrypt(buf, buf,
1921 (unsigned long)lengths[j], &idea_ks,
1924 print_result(D_CBC_IDEA, j, count, d);
1928 # ifndef OPENSSL_NO_SEED
1929 if (doit[D_CBC_SEED]) {
1930 for (j = 0; j < SIZE_NUM; j++) {
1931 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1933 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1934 SEED_cbc_encrypt(buf, buf,
1935 (unsigned long)lengths[j], &seed_ks, iv, 1);
1937 print_result(D_CBC_SEED, j, count, d);
1941 # ifndef OPENSSL_NO_RC2
1942 if (doit[D_CBC_RC2]) {
1943 for (j = 0; j < SIZE_NUM; j++) {
1944 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1946 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1947 RC2_cbc_encrypt(buf, buf,
1948 (unsigned long)lengths[j], &rc2_ks,
1951 print_result(D_CBC_RC2, j, count, d);
1955 # ifndef OPENSSL_NO_RC5
1956 if (doit[D_CBC_RC5]) {
1957 for (j = 0; j < SIZE_NUM; j++) {
1958 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1960 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1961 RC5_32_cbc_encrypt(buf, buf,
1962 (unsigned long)lengths[j], &rc5_ks,
1965 print_result(D_CBC_RC5, j, count, d);
1969 # ifndef OPENSSL_NO_BF
1970 if (doit[D_CBC_BF]) {
1971 for (j = 0; j < SIZE_NUM; j++) {
1972 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1974 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1975 BF_cbc_encrypt(buf, buf,
1976 (unsigned long)lengths[j], &bf_ks,
1979 print_result(D_CBC_BF, j, count, d);
1983 # ifndef OPENSSL_NO_CAST
1984 if (doit[D_CBC_CAST]) {
1985 for (j = 0; j < SIZE_NUM; j++) {
1986 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1988 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1989 CAST_cbc_encrypt(buf, buf,
1990 (unsigned long)lengths[j], &cast_ks,
1993 print_result(D_CBC_CAST, j, count, d);
1999 # ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2000 if (multiblock && evp_cipher) {
2002 (EVP_CIPHER_flags(evp_cipher) &
2003 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2004 fprintf(stderr, "%s is not multi-block capable\n",
2005 OBJ_nid2ln(evp_cipher->nid));
2008 multiblock_speed(evp_cipher);
2013 for (j = 0; j < SIZE_NUM; j++) {
2018 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
2020 * -O3 -fschedule-insns messes up an optimization here!
2021 * names[D_EVP] somehow becomes NULL
2023 print_message(names[D_EVP], save_count, lengths[j]);
2025 EVP_CIPHER_CTX_init(&ctx);
2027 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
2029 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
2030 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2034 for (count = 0, run = 1;
2035 COND(save_count * 4 * lengths[0] / lengths[j]);
2037 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
2039 for (count = 0, run = 1;
2040 COND(save_count * 4 * lengths[0] / lengths[j]);
2042 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
2044 EVP_DecryptFinal_ex(&ctx, buf, &outl);
2046 EVP_EncryptFinal_ex(&ctx, buf, &outl);
2048 EVP_CIPHER_CTX_cleanup(&ctx);
2051 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2052 print_message(names[D_EVP], save_count, lengths[j]);
2055 for (count = 0, run = 1;
2056 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2057 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2061 print_result(D_EVP, j, count, d);
2064 # ifndef OPENSSL_SYS_WIN32
2066 RAND_pseudo_bytes(buf, 36);
2067 # ifndef OPENSSL_NO_RSA
2068 for (j = 0; j < RSA_NUM; j++) {
2072 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2075 "RSA sign failure. No RSA sign will be done.\n");
2076 ERR_print_errors(bio_err);
2079 pkey_print_message("private", "rsa",
2080 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2081 /* RSA_blinding_on(rsa_key[j],NULL); */
2083 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2084 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2085 &rsa_num, rsa_key[j]);
2087 BIO_printf(bio_err, "RSA sign failure\n");
2088 ERR_print_errors(bio_err);
2095 mr ? "+R1:%ld:%d:%.2f\n"
2096 : "%ld %d bit private RSA's in %.2fs\n",
2097 count, rsa_bits[j], d);
2098 rsa_results[j][0] = d / (double)count;
2103 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2106 "RSA verify failure. No RSA verify will be done.\n");
2107 ERR_print_errors(bio_err);
2110 pkey_print_message("public", "rsa",
2111 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2113 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2114 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2115 rsa_num, rsa_key[j]);
2117 BIO_printf(bio_err, "RSA verify failure\n");
2118 ERR_print_errors(bio_err);
2125 mr ? "+R2:%ld:%d:%.2f\n"
2126 : "%ld %d bit public RSA's in %.2fs\n",
2127 count, rsa_bits[j], d);
2128 rsa_results[j][1] = d / (double)count;
2132 if (rsa_count <= 1) {
2133 /* if longer than 10s, don't do any more */
2134 for (j++; j < RSA_NUM; j++)
2140 RAND_pseudo_bytes(buf, 20);
2141 # ifndef OPENSSL_NO_DSA
2142 if (RAND_status() != 1) {
2143 RAND_seed(rnd_seed, sizeof rnd_seed);
2146 for (j = 0; j < DSA_NUM; j++) {
2153 /* DSA_generate_key(dsa_key[j]); */
2154 /* DSA_sign_setup(dsa_key[j],NULL); */
2155 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2158 "DSA sign failure. No DSA sign will be done.\n");
2159 ERR_print_errors(bio_err);
2162 pkey_print_message("sign", "dsa",
2163 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2165 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2166 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2168 BIO_printf(bio_err, "DSA sign failure\n");
2169 ERR_print_errors(bio_err);
2176 mr ? "+R3:%ld:%d:%.2f\n"
2177 : "%ld %d bit DSA signs in %.2fs\n",
2178 count, dsa_bits[j], d);
2179 dsa_results[j][0] = d / (double)count;
2183 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2186 "DSA verify failure. No DSA verify will be done.\n");
2187 ERR_print_errors(bio_err);
2190 pkey_print_message("verify", "dsa",
2191 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2193 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2194 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2196 BIO_printf(bio_err, "DSA verify failure\n");
2197 ERR_print_errors(bio_err);
2204 mr ? "+R4:%ld:%d:%.2f\n"
2205 : "%ld %d bit DSA verify in %.2fs\n",
2206 count, dsa_bits[j], d);
2207 dsa_results[j][1] = d / (double)count;
2210 if (rsa_count <= 1) {
2211 /* if longer than 10s, don't do any more */
2212 for (j++; j < DSA_NUM; j++)
2220 # ifndef OPENSSL_NO_ECDSA
2221 if (RAND_status() != 1) {
2222 RAND_seed(rnd_seed, sizeof rnd_seed);
2225 for (j = 0; j < EC_NUM; j++) {
2229 continue; /* Ignore Curve */
2230 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2231 if (ecdsa[j] == NULL) {
2232 BIO_printf(bio_err, "ECDSA failure.\n");
2233 ERR_print_errors(bio_err);
2237 EC_KEY_precompute_mult(ecdsa[j], NULL);
2239 /* Perform ECDSA signature test */
2240 EC_KEY_generate_key(ecdsa[j]);
2241 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2244 "ECDSA sign failure. No ECDSA sign will be done.\n");
2245 ERR_print_errors(bio_err);
2248 pkey_print_message("sign", "ecdsa",
2250 test_curves_bits[j], ECDSA_SECONDS);
2253 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2254 ret = ECDSA_sign(0, buf, 20,
2255 ecdsasig, &ecdsasiglen, ecdsa[j]);
2257 BIO_printf(bio_err, "ECDSA sign failure\n");
2258 ERR_print_errors(bio_err);
2266 mr ? "+R5:%ld:%d:%.2f\n" :
2267 "%ld %d bit ECDSA signs in %.2fs \n",
2268 count, test_curves_bits[j], d);
2269 ecdsa_results[j][0] = d / (double)count;
2273 /* Perform ECDSA verification test */
2274 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2277 "ECDSA verify failure. No ECDSA verify will be done.\n");
2278 ERR_print_errors(bio_err);
2281 pkey_print_message("verify", "ecdsa",
2283 test_curves_bits[j], ECDSA_SECONDS);
2285 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2287 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2290 BIO_printf(bio_err, "ECDSA verify failure\n");
2291 ERR_print_errors(bio_err);
2298 mr ? "+R6:%ld:%d:%.2f\n"
2299 : "%ld %d bit ECDSA verify in %.2fs\n",
2300 count, test_curves_bits[j], d);
2301 ecdsa_results[j][1] = d / (double)count;
2304 if (rsa_count <= 1) {
2305 /* if longer than 10s, don't do any more */
2306 for (j++; j < EC_NUM; j++)
2315 # ifndef OPENSSL_NO_ECDH
2316 if (RAND_status() != 1) {
2317 RAND_seed(rnd_seed, sizeof rnd_seed);
2320 for (j = 0; j < EC_NUM; j++) {
2323 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2324 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2325 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2326 BIO_printf(bio_err, "ECDH failure.\n");
2327 ERR_print_errors(bio_err);
2330 /* generate two ECDH key pairs */
2331 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2332 !EC_KEY_generate_key(ecdh_b[j])) {
2333 BIO_printf(bio_err, "ECDH key generation failure.\n");
2334 ERR_print_errors(bio_err);
2338 * If field size is not more than 24 octets, then use SHA-1
2339 * hash of result; otherwise, use result (see section 4.8 of
2340 * draft-ietf-tls-ecc-03.txt).
2342 int field_size, outlen;
2343 void *(*kdf) (const void *in, size_t inlen, void *out,
2346 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2347 if (field_size <= 24 * 8) {
2348 outlen = KDF1_SHA1_len;
2351 outlen = (field_size + 7) / 8;
2355 ECDH_compute_key(secret_a, outlen,
2356 EC_KEY_get0_public_key(ecdh_b[j]),
2359 ECDH_compute_key(secret_b, outlen,
2360 EC_KEY_get0_public_key(ecdh_a[j]),
2362 if (secret_size_a != secret_size_b)
2367 for (secret_idx = 0; (secret_idx < secret_size_a)
2368 && (ecdh_checks == 1); secret_idx++) {
2369 if (secret_a[secret_idx] != secret_b[secret_idx])
2373 if (ecdh_checks == 0) {
2374 BIO_printf(bio_err, "ECDH computations don't match.\n");
2375 ERR_print_errors(bio_err);
2379 pkey_print_message("", "ecdh",
2381 test_curves_bits[j], ECDH_SECONDS);
2383 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2384 ECDH_compute_key(secret_a, outlen,
2385 EC_KEY_get0_public_key(ecdh_b[j]),
2390 mr ? "+R7:%ld:%d:%.2f\n" :
2391 "%ld %d-bit ECDH ops in %.2fs\n", count,
2392 test_curves_bits[j], d);
2393 ecdh_results[j][0] = d / (double)count;
2398 if (rsa_count <= 1) {
2399 /* if longer than 10s, don't do any more */
2400 for (j++; j < EC_NUM; j++)
2411 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2412 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2414 printf("%s ", BN_options());
2415 # ifndef OPENSSL_NO_MD2
2416 printf("%s ", MD2_options());
2418 # ifndef OPENSSL_NO_RC4
2419 printf("%s ", RC4_options());
2421 # ifndef OPENSSL_NO_DES
2422 printf("%s ", DES_options());
2424 # ifndef OPENSSL_NO_AES
2425 printf("%s ", AES_options());
2427 # ifndef OPENSSL_NO_IDEA
2428 printf("%s ", idea_options());
2430 # ifndef OPENSSL_NO_BF
2431 printf("%s ", BF_options());
2433 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2438 fprintf(stdout, "+H");
2441 "The 'numbers' are in 1000s of bytes per second processed.\n");
2442 fprintf(stdout, "type ");
2444 for (j = 0; j < SIZE_NUM; j++)
2445 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2446 fprintf(stdout, "\n");
2449 for (k = 0; k < ALGOR_NUM; k++) {
2453 fprintf(stdout, "+F:%d:%s", k, names[k]);
2455 fprintf(stdout, "%-13s", names[k]);
2456 for (j = 0; j < SIZE_NUM; j++) {
2457 if (results[k][j] > 10000 && !mr)
2458 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2460 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2462 fprintf(stdout, "\n");
2464 # ifndef OPENSSL_NO_RSA
2466 for (k = 0; k < RSA_NUM; k++) {
2470 printf("%18ssign verify sign/s verify/s\n", " ");
2474 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2475 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2477 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2478 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2479 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2482 # ifndef OPENSSL_NO_DSA
2484 for (k = 0; k < DSA_NUM; k++) {
2488 printf("%18ssign verify sign/s verify/s\n", " ");
2492 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2493 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2495 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2496 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2497 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2500 # ifndef OPENSSL_NO_ECDSA
2502 for (k = 0; k < EC_NUM; k++) {
2506 printf("%30ssign verify sign/s verify/s\n", " ");
2511 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2512 k, test_curves_bits[k],
2513 ecdsa_results[k][0], ecdsa_results[k][1]);
2516 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2517 test_curves_bits[k],
2518 test_curves_names[k],
2519 ecdsa_results[k][0], ecdsa_results[k][1],
2520 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2524 # ifndef OPENSSL_NO_ECDH
2526 for (k = 0; k < EC_NUM; k++) {
2530 printf("%30sop op/s\n", " ");
2534 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2535 k, test_curves_bits[k],
2536 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2539 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2540 test_curves_bits[k],
2541 test_curves_names[k],
2542 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2549 ERR_print_errors(bio_err);
2550 if (buf_malloc != NULL)
2551 OPENSSL_free(buf_malloc);
2552 if (buf2_malloc != NULL)
2553 OPENSSL_free(buf2_malloc);
2554 # ifndef OPENSSL_NO_RSA
2555 for (i = 0; i < RSA_NUM; i++)
2556 if (rsa_key[i] != NULL)
2557 RSA_free(rsa_key[i]);
2559 # ifndef OPENSSL_NO_DSA
2560 for (i = 0; i < DSA_NUM; i++)
2561 if (dsa_key[i] != NULL)
2562 DSA_free(dsa_key[i]);
2565 # ifndef OPENSSL_NO_ECDSA
2566 for (i = 0; i < EC_NUM; i++)
2567 if (ecdsa[i] != NULL)
2568 EC_KEY_free(ecdsa[i]);
2570 # ifndef OPENSSL_NO_ECDH
2571 for (i = 0; i < EC_NUM; i++) {
2572 if (ecdh_a[i] != NULL)
2573 EC_KEY_free(ecdh_a[i]);
2574 if (ecdh_b[i] != NULL)
2575 EC_KEY_free(ecdh_b[i]);
2583 static void print_message(const char *s, long num, int length)
2587 mr ? "+DT:%s:%d:%d\n"
2588 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2589 (void)BIO_flush(bio_err);
2593 mr ? "+DN:%s:%ld:%d\n"
2594 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2595 (void)BIO_flush(bio_err);
2599 static void pkey_print_message(const char *str, const char *str2, long num,
2604 mr ? "+DTP:%d:%s:%s:%d\n"
2605 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2606 (void)BIO_flush(bio_err);
2610 mr ? "+DNP:%ld:%d:%s:%s\n"
2611 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2612 (void)BIO_flush(bio_err);
2616 static void print_result(int alg, int run_no, int count, double time_used)
2619 mr ? "+R:%d:%s:%f\n"
2620 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2621 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2625 static char *sstrsep(char **string, const char *delim)
2628 char *token = *string;
2633 memset(isdelim, 0, sizeof isdelim);
2637 isdelim[(unsigned char)(*delim)] = 1;
2641 while (!isdelim[(unsigned char)(**string)]) {
2653 static int do_multi(int multi)
2658 static char sep[] = ":";
2660 fds = malloc(multi * sizeof *fds);
2661 for (n = 0; n < multi; ++n) {
2662 if (pipe(fd) == -1) {
2663 fprintf(stderr, "pipe failure\n");
2674 if (dup(fd[1]) == -1) {
2675 fprintf(stderr, "dup failed\n");
2684 printf("Forked child %d\n", n);
2687 /* for now, assume the pipe is long enough to take all the output */
2688 for (n = 0; n < multi; ++n) {
2693 f = fdopen(fds[n], "r");
2694 while (fgets(buf, sizeof buf, f)) {
2695 p = strchr(buf, '\n');
2698 if (buf[0] != '+') {
2699 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2703 printf("Got: %s from %d\n", buf, n);
2704 if (!strncmp(buf, "+F:", 3)) {
2709 alg = atoi(sstrsep(&p, sep));
2711 for (j = 0; j < SIZE_NUM; ++j)
2712 results[alg][j] += atof(sstrsep(&p, sep));
2713 } else if (!strncmp(buf, "+F2:", 4)) {
2718 k = atoi(sstrsep(&p, sep));
2721 d = atof(sstrsep(&p, sep));
2723 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2725 rsa_results[k][0] = d;
2727 d = atof(sstrsep(&p, sep));
2729 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2731 rsa_results[k][1] = d;
2732 } else if (!strncmp(buf, "+F2:", 4)) {
2737 k = atoi(sstrsep(&p, sep));
2740 d = atof(sstrsep(&p, sep));
2742 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2744 rsa_results[k][0] = d;
2746 d = atof(sstrsep(&p, sep));
2748 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2750 rsa_results[k][1] = d;
2752 # ifndef OPENSSL_NO_DSA
2753 else if (!strncmp(buf, "+F3:", 4)) {
2758 k = atoi(sstrsep(&p, sep));
2761 d = atof(sstrsep(&p, sep));
2763 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2765 dsa_results[k][0] = d;
2767 d = atof(sstrsep(&p, sep));
2769 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2771 dsa_results[k][1] = d;
2774 # ifndef OPENSSL_NO_ECDSA
2775 else if (!strncmp(buf, "+F4:", 4)) {
2780 k = atoi(sstrsep(&p, sep));
2783 d = atof(sstrsep(&p, sep));
2785 ecdsa_results[k][0] =
2786 1 / (1 / ecdsa_results[k][0] + 1 / d);
2788 ecdsa_results[k][0] = d;
2790 d = atof(sstrsep(&p, sep));
2792 ecdsa_results[k][1] =
2793 1 / (1 / ecdsa_results[k][1] + 1 / d);
2795 ecdsa_results[k][1] = d;
2799 # ifndef OPENSSL_NO_ECDH
2800 else if (!strncmp(buf, "+F5:", 4)) {
2805 k = atoi(sstrsep(&p, sep));
2808 d = atof(sstrsep(&p, sep));
2810 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2812 ecdh_results[k][0] = d;
2817 else if (!strncmp(buf, "+H:", 3)) {
2819 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2829 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2831 static int mblengths[] =
2832 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2833 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2834 const char *alg_name;
2835 unsigned char *inp, *out, no_key[32], no_iv[16];
2839 inp = OPENSSL_malloc(mblengths[num - 1]);
2840 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2842 EVP_CIPHER_CTX_init(&ctx);
2843 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2844 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2846 alg_name = OBJ_nid2ln(evp_cipher->nid);
2848 for (j = 0; j < num; j++) {
2849 print_message(alg_name, 0, mblengths[j]);
2851 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2852 unsigned char aad[13];
2853 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2854 size_t len = mblengths[j];
2857 memset(aad, 0, 8); /* avoid uninitialized values */
2858 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2859 aad[9] = 3; /* version */
2861 aad[11] = 0; /* length */
2863 mb_param.out = NULL;
2866 mb_param.interleave = 8;
2868 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2869 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2870 sizeof(mb_param), &mb_param);
2876 EVP_CIPHER_CTX_ctrl(&ctx,
2877 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2878 sizeof(mb_param), &mb_param);
2882 RAND_bytes(out, 16);
2886 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2887 EVP_CTRL_AEAD_TLS1_AAD, 13, aad);
2888 EVP_Cipher(&ctx, out, inp, len + pad);
2893 mr ? "+R:%d:%s:%f\n"
2894 : "%d %s's in %.2fs\n", count, "evp", d);
2895 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2899 fprintf(stdout, "+H");
2900 for (j = 0; j < num; j++)
2901 fprintf(stdout, ":%d", mblengths[j]);
2902 fprintf(stdout, "\n");
2903 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2904 for (j = 0; j < num; j++)
2905 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2906 fprintf(stdout, "\n");
2909 "The 'numbers' are in 1000s of bytes per second processed.\n");
2910 fprintf(stdout, "type ");
2911 for (j = 0; j < num; j++)
2912 fprintf(stdout, "%7d bytes", mblengths[j]);
2913 fprintf(stdout, "\n");
2914 fprintf(stdout, "%-24s", alg_name);
2916 for (j = 0; j < num; j++) {
2917 if (results[D_EVP][j] > 10000)
2918 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2920 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2922 fprintf(stdout, "\n");