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 # ifndef OPENSSL_NO_ENGINE
378 unsigned char *buf = NULL, *buf2 = NULL;
380 long count = 0, save_count = 0;
382 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
385 # ifndef OPENSSL_NO_RSA
388 unsigned char md[EVP_MAX_MD_SIZE];
389 # ifndef OPENSSL_NO_MD2
390 unsigned char md2[MD2_DIGEST_LENGTH];
392 # ifndef OPENSSL_NO_MDC2
393 unsigned char mdc2[MDC2_DIGEST_LENGTH];
395 # ifndef OPENSSL_NO_MD4
396 unsigned char md4[MD4_DIGEST_LENGTH];
398 # ifndef OPENSSL_NO_MD5
399 unsigned char md5[MD5_DIGEST_LENGTH];
400 unsigned char hmac[MD5_DIGEST_LENGTH];
402 # ifndef OPENSSL_NO_SHA
403 unsigned char sha[SHA_DIGEST_LENGTH];
404 # ifndef OPENSSL_NO_SHA256
405 unsigned char sha256[SHA256_DIGEST_LENGTH];
407 # ifndef OPENSSL_NO_SHA512
408 unsigned char sha512[SHA512_DIGEST_LENGTH];
411 # ifndef OPENSSL_NO_WHIRLPOOL
412 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
414 # ifndef OPENSSL_NO_RIPEMD
415 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
417 # ifndef OPENSSL_NO_RC4
420 # ifndef OPENSSL_NO_RC5
423 # ifndef OPENSSL_NO_RC2
426 # ifndef OPENSSL_NO_IDEA
427 IDEA_KEY_SCHEDULE idea_ks;
429 # ifndef OPENSSL_NO_SEED
430 SEED_KEY_SCHEDULE seed_ks;
432 # ifndef OPENSSL_NO_BF
435 # ifndef OPENSSL_NO_CAST
438 static const unsigned char key16[16] = {
439 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
440 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
442 # ifndef OPENSSL_NO_AES
443 static const unsigned char key24[24] = {
444 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
445 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
446 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
448 static const unsigned char key32[32] = {
449 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
450 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
451 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
452 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
455 # ifndef OPENSSL_NO_CAMELLIA
456 static const unsigned char ckey24[24] = {
457 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
458 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
459 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
461 static const unsigned char ckey32[32] = {
462 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
463 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
464 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
465 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
468 # ifndef OPENSSL_NO_AES
469 # define MAX_BLOCK_SIZE 128
471 # define MAX_BLOCK_SIZE 64
473 unsigned char DES_iv[8];
474 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
475 # ifndef OPENSSL_NO_DES
476 static DES_cblock key =
477 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
478 static DES_cblock key2 =
479 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
480 static DES_cblock key3 =
481 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
482 DES_key_schedule sch;
483 DES_key_schedule sch2;
484 DES_key_schedule sch3;
486 # ifndef OPENSSL_NO_AES
487 AES_KEY aes_ks1, aes_ks2, aes_ks3;
489 # ifndef OPENSSL_NO_CAMELLIA
490 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
501 # define D_EDE3_DES 9
502 # define D_CBC_IDEA 10
503 # define D_CBC_SEED 11
504 # define D_CBC_RC2 12
505 # define D_CBC_RC5 13
507 # define D_CBC_CAST 15
508 # define D_CBC_128_AES 16
509 # define D_CBC_192_AES 17
510 # define D_CBC_256_AES 18
511 # define D_CBC_128_CML 19
512 # define D_CBC_192_CML 20
513 # define D_CBC_256_CML 21
517 # define D_WHIRLPOOL 25
518 # define D_IGE_128_AES 26
519 # define D_IGE_192_AES 27
520 # define D_IGE_256_AES 28
523 long c[ALGOR_NUM][SIZE_NUM];
525 # define R_DSA_1024 1
526 # define R_DSA_2048 2
528 # define R_RSA_1024 1
529 # define R_RSA_2048 2
530 # define R_RSA_4096 3
542 # define R_EC_K571 10
543 # define R_EC_B163 11
544 # define R_EC_B233 12
545 # define R_EC_B283 13
546 # define R_EC_B409 14
547 # define R_EC_B571 15
549 # ifndef OPENSSL_NO_RSA
550 RSA *rsa_key[RSA_NUM];
551 long rsa_c[RSA_NUM][2];
552 static unsigned int rsa_bits[RSA_NUM] = {
553 512, 1024, 2048, 4096
555 static unsigned char *rsa_data[RSA_NUM] = {
556 test512, test1024, test2048, test4096
558 static int rsa_data_length[RSA_NUM] = {
559 sizeof(test512), sizeof(test1024),
560 sizeof(test2048), sizeof(test4096)
563 # ifndef OPENSSL_NO_DSA
564 DSA *dsa_key[DSA_NUM];
565 long dsa_c[DSA_NUM][2];
566 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
568 # ifndef OPENSSL_NO_EC
570 * We only test over the following curves as they are representative, To
571 * add tests over more curves, simply add the curve NID and curve name to
572 * the following arrays and increase the EC_NUM value accordingly.
574 static unsigned int test_curves[EC_NUM] = {
577 NID_X9_62_prime192v1,
579 NID_X9_62_prime256v1,
594 static const char *test_curves_names[EC_NUM] = {
614 static int test_curves_bits[EC_NUM] = {
615 160, 192, 224, 256, 384, 521,
616 163, 233, 283, 409, 571,
617 163, 233, 283, 409, 571
622 # ifndef OPENSSL_NO_ECDSA
623 unsigned char ecdsasig[256];
624 unsigned int ecdsasiglen;
625 EC_KEY *ecdsa[EC_NUM];
626 long ecdsa_c[EC_NUM][2];
629 # ifndef OPENSSL_NO_ECDH
630 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
631 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
632 int secret_size_a, secret_size_b;
635 long ecdh_c[EC_NUM][2];
638 int rsa_doit[RSA_NUM];
639 int dsa_doit[DSA_NUM];
640 # ifndef OPENSSL_NO_ECDSA
641 int ecdsa_doit[EC_NUM];
643 # ifndef OPENSSL_NO_ECDH
644 int ecdh_doit[EC_NUM];
648 const EVP_CIPHER *evp_cipher = NULL;
649 const EVP_MD *evp_md = NULL;
661 memset(results, 0, sizeof(results));
662 # ifndef OPENSSL_NO_DSA
663 memset(dsa_key, 0, sizeof(dsa_key));
665 # ifndef OPENSSL_NO_ECDSA
666 for (i = 0; i < EC_NUM; i++)
669 # ifndef OPENSSL_NO_ECDH
670 for (i = 0; i < EC_NUM; i++) {
677 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
678 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
680 if (!load_config(bio_err, NULL))
683 # ifndef OPENSSL_NO_RSA
684 memset(rsa_key, 0, sizeof(rsa_key));
685 for (i = 0; i < RSA_NUM; i++)
689 if ((buf = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
690 BIO_printf(bio_err, "out of memory\n");
693 if ((buf2 = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
694 BIO_printf(bio_err, "out of memory\n");
698 memset(c, 0, sizeof(c));
699 memset(DES_iv, 0, sizeof(DES_iv));
700 memset(iv, 0, sizeof(iv));
702 for (i = 0; i < ALGOR_NUM; i++)
704 for (i = 0; i < RSA_NUM; i++)
706 for (i = 0; i < DSA_NUM; i++)
708 # ifndef OPENSSL_NO_ECDSA
709 for (i = 0; i < EC_NUM; i++)
712 # ifndef OPENSSL_NO_ECDH
713 for (i = 0; i < EC_NUM; i++)
721 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
723 j--; /* Otherwise, -elapsed gets confused with an
725 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
729 BIO_printf(bio_err, "no EVP given\n");
732 evp_cipher = EVP_get_cipherbyname(*argv);
734 evp_md = EVP_get_digestbyname(*argv);
736 if (!evp_cipher && !evp_md) {
737 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
742 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
744 j--; /* Otherwise, -elapsed gets confused with an
747 # ifndef OPENSSL_NO_ENGINE
748 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
752 BIO_printf(bio_err, "no engine given\n");
755 e = setup_engine(bio_err, *argv, 0);
757 * j will be increased again further down. We just don't want
758 * speed to confuse an engine with an algorithm, especially when
759 * none is given (which means all of them should be run)
765 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
769 BIO_printf(bio_err, "no multi count given\n");
772 multi = atoi(argv[0]);
774 BIO_printf(bio_err, "bad multi count\n");
777 j--; /* Otherwise, -mr gets confused with an
781 else if (argc > 0 && !strcmp(*argv, "-mr")) {
783 j--; /* Otherwise, -mr gets confused with an
785 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
789 # ifndef OPENSSL_NO_MD2
790 if (strcmp(*argv, "md2") == 0)
794 # ifndef OPENSSL_NO_MDC2
795 if (strcmp(*argv, "mdc2") == 0)
799 # ifndef OPENSSL_NO_MD4
800 if (strcmp(*argv, "md4") == 0)
804 # ifndef OPENSSL_NO_MD5
805 if (strcmp(*argv, "md5") == 0)
809 # ifndef OPENSSL_NO_MD5
810 if (strcmp(*argv, "hmac") == 0)
814 # ifndef OPENSSL_NO_SHA
815 if (strcmp(*argv, "sha1") == 0)
817 else if (strcmp(*argv, "sha") == 0)
818 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
820 # ifndef OPENSSL_NO_SHA256
821 if (strcmp(*argv, "sha256") == 0)
825 # ifndef OPENSSL_NO_SHA512
826 if (strcmp(*argv, "sha512") == 0)
831 # ifndef OPENSSL_NO_WHIRLPOOL
832 if (strcmp(*argv, "whirlpool") == 0)
833 doit[D_WHIRLPOOL] = 1;
836 # ifndef OPENSSL_NO_RIPEMD
837 if (strcmp(*argv, "ripemd") == 0)
839 else if (strcmp(*argv, "rmd160") == 0)
841 else if (strcmp(*argv, "ripemd160") == 0)
845 # ifndef OPENSSL_NO_RC4
846 if (strcmp(*argv, "rc4") == 0)
850 # ifndef OPENSSL_NO_DES
851 if (strcmp(*argv, "des-cbc") == 0)
853 else if (strcmp(*argv, "des-ede3") == 0)
854 doit[D_EDE3_DES] = 1;
857 # ifndef OPENSSL_NO_AES
858 if (strcmp(*argv, "aes-128-cbc") == 0)
859 doit[D_CBC_128_AES] = 1;
860 else if (strcmp(*argv, "aes-192-cbc") == 0)
861 doit[D_CBC_192_AES] = 1;
862 else if (strcmp(*argv, "aes-256-cbc") == 0)
863 doit[D_CBC_256_AES] = 1;
864 else if (strcmp(*argv, "aes-128-ige") == 0)
865 doit[D_IGE_128_AES] = 1;
866 else if (strcmp(*argv, "aes-192-ige") == 0)
867 doit[D_IGE_192_AES] = 1;
868 else if (strcmp(*argv, "aes-256-ige") == 0)
869 doit[D_IGE_256_AES] = 1;
872 # ifndef OPENSSL_NO_CAMELLIA
873 if (strcmp(*argv, "camellia-128-cbc") == 0)
874 doit[D_CBC_128_CML] = 1;
875 else if (strcmp(*argv, "camellia-192-cbc") == 0)
876 doit[D_CBC_192_CML] = 1;
877 else if (strcmp(*argv, "camellia-256-cbc") == 0)
878 doit[D_CBC_256_CML] = 1;
881 # ifndef OPENSSL_NO_RSA
882 # if 0 /* was: #ifdef RSAref */
883 if (strcmp(*argv, "rsaref") == 0) {
884 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
889 if (strcmp(*argv, "openssl") == 0) {
890 RSA_set_default_method(RSA_PKCS1_SSLeay());
894 # endif /* !OPENSSL_NO_RSA */
895 if (strcmp(*argv, "dsa512") == 0)
896 dsa_doit[R_DSA_512] = 2;
897 else if (strcmp(*argv, "dsa1024") == 0)
898 dsa_doit[R_DSA_1024] = 2;
899 else if (strcmp(*argv, "dsa2048") == 0)
900 dsa_doit[R_DSA_2048] = 2;
901 else if (strcmp(*argv, "rsa512") == 0)
902 rsa_doit[R_RSA_512] = 2;
903 else if (strcmp(*argv, "rsa1024") == 0)
904 rsa_doit[R_RSA_1024] = 2;
905 else if (strcmp(*argv, "rsa2048") == 0)
906 rsa_doit[R_RSA_2048] = 2;
907 else if (strcmp(*argv, "rsa4096") == 0)
908 rsa_doit[R_RSA_4096] = 2;
910 # ifndef OPENSSL_NO_RC2
911 if (strcmp(*argv, "rc2-cbc") == 0)
913 else if (strcmp(*argv, "rc2") == 0)
917 # ifndef OPENSSL_NO_RC5
918 if (strcmp(*argv, "rc5-cbc") == 0)
920 else if (strcmp(*argv, "rc5") == 0)
924 # ifndef OPENSSL_NO_IDEA
925 if (strcmp(*argv, "idea-cbc") == 0)
926 doit[D_CBC_IDEA] = 1;
927 else if (strcmp(*argv, "idea") == 0)
928 doit[D_CBC_IDEA] = 1;
931 # ifndef OPENSSL_NO_SEED
932 if (strcmp(*argv, "seed-cbc") == 0)
933 doit[D_CBC_SEED] = 1;
934 else if (strcmp(*argv, "seed") == 0)
935 doit[D_CBC_SEED] = 1;
938 # ifndef OPENSSL_NO_BF
939 if (strcmp(*argv, "bf-cbc") == 0)
941 else if (strcmp(*argv, "blowfish") == 0)
943 else if (strcmp(*argv, "bf") == 0)
947 # ifndef OPENSSL_NO_CAST
948 if (strcmp(*argv, "cast-cbc") == 0)
949 doit[D_CBC_CAST] = 1;
950 else if (strcmp(*argv, "cast") == 0)
951 doit[D_CBC_CAST] = 1;
952 else if (strcmp(*argv, "cast5") == 0)
953 doit[D_CBC_CAST] = 1;
956 # ifndef OPENSSL_NO_DES
957 if (strcmp(*argv, "des") == 0) {
959 doit[D_EDE3_DES] = 1;
962 # ifndef OPENSSL_NO_AES
963 if (strcmp(*argv, "aes") == 0) {
964 doit[D_CBC_128_AES] = 1;
965 doit[D_CBC_192_AES] = 1;
966 doit[D_CBC_256_AES] = 1;
967 } else if (strcmp(*argv, "ghash") == 0) {
971 # ifndef OPENSSL_NO_CAMELLIA
972 if (strcmp(*argv, "camellia") == 0) {
973 doit[D_CBC_128_CML] = 1;
974 doit[D_CBC_192_CML] = 1;
975 doit[D_CBC_256_CML] = 1;
978 # ifndef OPENSSL_NO_RSA
979 if (strcmp(*argv, "rsa") == 0) {
980 rsa_doit[R_RSA_512] = 1;
981 rsa_doit[R_RSA_1024] = 1;
982 rsa_doit[R_RSA_2048] = 1;
983 rsa_doit[R_RSA_4096] = 1;
986 # ifndef OPENSSL_NO_DSA
987 if (strcmp(*argv, "dsa") == 0) {
988 dsa_doit[R_DSA_512] = 1;
989 dsa_doit[R_DSA_1024] = 1;
990 dsa_doit[R_DSA_2048] = 1;
993 # ifndef OPENSSL_NO_ECDSA
994 if (strcmp(*argv, "ecdsap160") == 0)
995 ecdsa_doit[R_EC_P160] = 2;
996 else if (strcmp(*argv, "ecdsap192") == 0)
997 ecdsa_doit[R_EC_P192] = 2;
998 else if (strcmp(*argv, "ecdsap224") == 0)
999 ecdsa_doit[R_EC_P224] = 2;
1000 else if (strcmp(*argv, "ecdsap256") == 0)
1001 ecdsa_doit[R_EC_P256] = 2;
1002 else if (strcmp(*argv, "ecdsap384") == 0)
1003 ecdsa_doit[R_EC_P384] = 2;
1004 else if (strcmp(*argv, "ecdsap521") == 0)
1005 ecdsa_doit[R_EC_P521] = 2;
1006 else if (strcmp(*argv, "ecdsak163") == 0)
1007 ecdsa_doit[R_EC_K163] = 2;
1008 else if (strcmp(*argv, "ecdsak233") == 0)
1009 ecdsa_doit[R_EC_K233] = 2;
1010 else if (strcmp(*argv, "ecdsak283") == 0)
1011 ecdsa_doit[R_EC_K283] = 2;
1012 else if (strcmp(*argv, "ecdsak409") == 0)
1013 ecdsa_doit[R_EC_K409] = 2;
1014 else if (strcmp(*argv, "ecdsak571") == 0)
1015 ecdsa_doit[R_EC_K571] = 2;
1016 else if (strcmp(*argv, "ecdsab163") == 0)
1017 ecdsa_doit[R_EC_B163] = 2;
1018 else if (strcmp(*argv, "ecdsab233") == 0)
1019 ecdsa_doit[R_EC_B233] = 2;
1020 else if (strcmp(*argv, "ecdsab283") == 0)
1021 ecdsa_doit[R_EC_B283] = 2;
1022 else if (strcmp(*argv, "ecdsab409") == 0)
1023 ecdsa_doit[R_EC_B409] = 2;
1024 else if (strcmp(*argv, "ecdsab571") == 0)
1025 ecdsa_doit[R_EC_B571] = 2;
1026 else if (strcmp(*argv, "ecdsa") == 0) {
1027 for (i = 0; i < EC_NUM; i++)
1031 # ifndef OPENSSL_NO_ECDH
1032 if (strcmp(*argv, "ecdhp160") == 0)
1033 ecdh_doit[R_EC_P160] = 2;
1034 else if (strcmp(*argv, "ecdhp192") == 0)
1035 ecdh_doit[R_EC_P192] = 2;
1036 else if (strcmp(*argv, "ecdhp224") == 0)
1037 ecdh_doit[R_EC_P224] = 2;
1038 else if (strcmp(*argv, "ecdhp256") == 0)
1039 ecdh_doit[R_EC_P256] = 2;
1040 else if (strcmp(*argv, "ecdhp384") == 0)
1041 ecdh_doit[R_EC_P384] = 2;
1042 else if (strcmp(*argv, "ecdhp521") == 0)
1043 ecdh_doit[R_EC_P521] = 2;
1044 else if (strcmp(*argv, "ecdhk163") == 0)
1045 ecdh_doit[R_EC_K163] = 2;
1046 else if (strcmp(*argv, "ecdhk233") == 0)
1047 ecdh_doit[R_EC_K233] = 2;
1048 else if (strcmp(*argv, "ecdhk283") == 0)
1049 ecdh_doit[R_EC_K283] = 2;
1050 else if (strcmp(*argv, "ecdhk409") == 0)
1051 ecdh_doit[R_EC_K409] = 2;
1052 else if (strcmp(*argv, "ecdhk571") == 0)
1053 ecdh_doit[R_EC_K571] = 2;
1054 else if (strcmp(*argv, "ecdhb163") == 0)
1055 ecdh_doit[R_EC_B163] = 2;
1056 else if (strcmp(*argv, "ecdhb233") == 0)
1057 ecdh_doit[R_EC_B233] = 2;
1058 else if (strcmp(*argv, "ecdhb283") == 0)
1059 ecdh_doit[R_EC_B283] = 2;
1060 else if (strcmp(*argv, "ecdhb409") == 0)
1061 ecdh_doit[R_EC_B409] = 2;
1062 else if (strcmp(*argv, "ecdhb571") == 0)
1063 ecdh_doit[R_EC_B571] = 2;
1064 else if (strcmp(*argv, "ecdh") == 0) {
1065 for (i = 0; i < EC_NUM; i++)
1070 BIO_printf(bio_err, "Error: bad option or value\n");
1071 BIO_printf(bio_err, "\n");
1072 BIO_printf(bio_err, "Available values:\n");
1073 # ifndef OPENSSL_NO_MD2
1074 BIO_printf(bio_err, "md2 ");
1076 # ifndef OPENSSL_NO_MDC2
1077 BIO_printf(bio_err, "mdc2 ");
1079 # ifndef OPENSSL_NO_MD4
1080 BIO_printf(bio_err, "md4 ");
1082 # ifndef OPENSSL_NO_MD5
1083 BIO_printf(bio_err, "md5 ");
1084 # ifndef OPENSSL_NO_HMAC
1085 BIO_printf(bio_err, "hmac ");
1088 # ifndef OPENSSL_NO_SHA1
1089 BIO_printf(bio_err, "sha1 ");
1091 # ifndef OPENSSL_NO_SHA256
1092 BIO_printf(bio_err, "sha256 ");
1094 # ifndef OPENSSL_NO_SHA512
1095 BIO_printf(bio_err, "sha512 ");
1097 # ifndef OPENSSL_NO_WHIRLPOOL
1098 BIO_printf(bio_err, "whirlpool");
1100 # ifndef OPENSSL_NO_RIPEMD160
1101 BIO_printf(bio_err, "rmd160");
1103 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1104 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1105 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1106 !defined(OPENSSL_NO_WHIRLPOOL)
1107 BIO_printf(bio_err, "\n");
1110 # ifndef OPENSSL_NO_IDEA
1111 BIO_printf(bio_err, "idea-cbc ");
1113 # ifndef OPENSSL_NO_SEED
1114 BIO_printf(bio_err, "seed-cbc ");
1116 # ifndef OPENSSL_NO_RC2
1117 BIO_printf(bio_err, "rc2-cbc ");
1119 # ifndef OPENSSL_NO_RC5
1120 BIO_printf(bio_err, "rc5-cbc ");
1122 # ifndef OPENSSL_NO_BF
1123 BIO_printf(bio_err, "bf-cbc");
1125 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1126 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1127 BIO_printf(bio_err, "\n");
1129 # ifndef OPENSSL_NO_DES
1130 BIO_printf(bio_err, "des-cbc des-ede3 ");
1132 # ifndef OPENSSL_NO_AES
1133 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1134 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1136 # ifndef OPENSSL_NO_CAMELLIA
1137 BIO_printf(bio_err, "\n");
1139 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1141 # ifndef OPENSSL_NO_RC4
1142 BIO_printf(bio_err, "rc4");
1144 BIO_printf(bio_err, "\n");
1146 # ifndef OPENSSL_NO_RSA
1147 BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
1150 # ifndef OPENSSL_NO_DSA
1151 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1153 # ifndef OPENSSL_NO_ECDSA
1154 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1155 "ecdsap256 ecdsap384 ecdsap521\n");
1157 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1159 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1160 BIO_printf(bio_err, "ecdsa\n");
1162 # ifndef OPENSSL_NO_ECDH
1163 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1164 "ecdhp256 ecdhp384 ecdhp521\n");
1166 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1168 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1169 BIO_printf(bio_err, "ecdh\n");
1172 # ifndef OPENSSL_NO_IDEA
1173 BIO_printf(bio_err, "idea ");
1175 # ifndef OPENSSL_NO_SEED
1176 BIO_printf(bio_err, "seed ");
1178 # ifndef OPENSSL_NO_RC2
1179 BIO_printf(bio_err, "rc2 ");
1181 # ifndef OPENSSL_NO_DES
1182 BIO_printf(bio_err, "des ");
1184 # ifndef OPENSSL_NO_AES
1185 BIO_printf(bio_err, "aes ");
1187 # ifndef OPENSSL_NO_CAMELLIA
1188 BIO_printf(bio_err, "camellia ");
1190 # ifndef OPENSSL_NO_RSA
1191 BIO_printf(bio_err, "rsa ");
1193 # ifndef OPENSSL_NO_BF
1194 BIO_printf(bio_err, "blowfish");
1196 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1197 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1198 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1199 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1200 BIO_printf(bio_err, "\n");
1203 BIO_printf(bio_err, "\n");
1204 BIO_printf(bio_err, "Available options:\n");
1205 # if defined(TIMES) || defined(USE_TOD)
1206 BIO_printf(bio_err, "-elapsed "
1207 "measure time in real time instead of CPU user time.\n");
1209 # ifndef OPENSSL_NO_ENGINE
1212 "use engine e, possibly a hardware device.\n");
1214 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1217 "time decryption instead of encryption (only EVP).\n");
1220 "produce machine readable output.\n");
1223 "-multi n " "run n benchmarks in parallel.\n");
1233 if (multi && do_multi(multi))
1238 for (i = 0; i < ALGOR_NUM; i++) {
1242 for (i = 0; i < RSA_NUM; i++)
1244 for (i = 0; i < DSA_NUM; i++)
1246 # ifndef OPENSSL_NO_ECDSA
1247 for (i = 0; i < EC_NUM; i++)
1250 # ifndef OPENSSL_NO_ECDH
1251 for (i = 0; i < EC_NUM; i++)
1255 for (i = 0; i < ALGOR_NUM; i++)
1259 if (usertime == 0 && !mr)
1261 "You have chosen to measure elapsed time "
1262 "instead of user CPU time.\n");
1264 # ifndef OPENSSL_NO_RSA
1265 for (i = 0; i < RSA_NUM; i++) {
1266 const unsigned char *p;
1269 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1270 if (rsa_key[i] == NULL) {
1271 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1279 : "Loaded RSA key, %d bit modulus and e= 0x",
1280 BN_num_bits(rsa_key[i]->n));
1281 BN_print(bio_err, rsa_key[i]->e);
1282 BIO_printf(bio_err, "\n");
1288 # ifndef OPENSSL_NO_DSA
1289 dsa_key[0] = get_dsa512();
1290 dsa_key[1] = get_dsa1024();
1291 dsa_key[2] = get_dsa2048();
1294 # ifndef OPENSSL_NO_DES
1295 DES_set_key_unchecked(&key, &sch);
1296 DES_set_key_unchecked(&key2, &sch2);
1297 DES_set_key_unchecked(&key3, &sch3);
1299 # ifndef OPENSSL_NO_AES
1300 AES_set_encrypt_key(key16, 128, &aes_ks1);
1301 AES_set_encrypt_key(key24, 192, &aes_ks2);
1302 AES_set_encrypt_key(key32, 256, &aes_ks3);
1304 # ifndef OPENSSL_NO_CAMELLIA
1305 Camellia_set_key(key16, 128, &camellia_ks1);
1306 Camellia_set_key(ckey24, 192, &camellia_ks2);
1307 Camellia_set_key(ckey32, 256, &camellia_ks3);
1309 # ifndef OPENSSL_NO_IDEA
1310 idea_set_encrypt_key(key16, &idea_ks);
1312 # ifndef OPENSSL_NO_SEED
1313 SEED_set_key(key16, &seed_ks);
1315 # ifndef OPENSSL_NO_RC4
1316 RC4_set_key(&rc4_ks, 16, key16);
1318 # ifndef OPENSSL_NO_RC2
1319 RC2_set_key(&rc2_ks, 16, key16, 128);
1321 # ifndef OPENSSL_NO_RC5
1322 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1324 # ifndef OPENSSL_NO_BF
1325 BF_set_key(&bf_ks, 16, key16);
1327 # ifndef OPENSSL_NO_CAST
1328 CAST_set_key(&cast_ks, 16, key16);
1330 # ifndef OPENSSL_NO_RSA
1331 memset(rsa_c, 0, sizeof(rsa_c));
1334 # ifndef OPENSSL_NO_DES
1335 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1341 for (it = count; it; it--)
1342 DES_ecb_encrypt((DES_cblock *)buf,
1343 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1347 c[D_MD2][0] = count / 10;
1348 c[D_MDC2][0] = count / 10;
1349 c[D_MD4][0] = count;
1350 c[D_MD5][0] = count;
1351 c[D_HMAC][0] = count;
1352 c[D_SHA1][0] = count;
1353 c[D_RMD160][0] = count;
1354 c[D_RC4][0] = count * 5;
1355 c[D_CBC_DES][0] = count;
1356 c[D_EDE3_DES][0] = count / 3;
1357 c[D_CBC_IDEA][0] = count;
1358 c[D_CBC_SEED][0] = count;
1359 c[D_CBC_RC2][0] = count;
1360 c[D_CBC_RC5][0] = count;
1361 c[D_CBC_BF][0] = count;
1362 c[D_CBC_CAST][0] = count;
1363 c[D_CBC_128_AES][0] = count;
1364 c[D_CBC_192_AES][0] = count;
1365 c[D_CBC_256_AES][0] = count;
1366 c[D_CBC_128_CML][0] = count;
1367 c[D_CBC_192_CML][0] = count;
1368 c[D_CBC_256_CML][0] = count;
1369 c[D_SHA256][0] = count;
1370 c[D_SHA512][0] = count;
1371 c[D_WHIRLPOOL][0] = count;
1372 c[D_IGE_128_AES][0] = count;
1373 c[D_IGE_192_AES][0] = count;
1374 c[D_IGE_256_AES][0] = count;
1375 c[D_GHASH][0] = count;
1377 for (i = 1; i < SIZE_NUM; i++) {
1378 c[D_MD2][i] = c[D_MD2][0] * 4 * lengths[0] / lengths[i];
1379 c[D_MDC2][i] = c[D_MDC2][0] * 4 * lengths[0] / lengths[i];
1380 c[D_MD4][i] = c[D_MD4][0] * 4 * lengths[0] / lengths[i];
1381 c[D_MD5][i] = c[D_MD5][0] * 4 * lengths[0] / lengths[i];
1382 c[D_HMAC][i] = c[D_HMAC][0] * 4 * lengths[0] / lengths[i];
1383 c[D_SHA1][i] = c[D_SHA1][0] * 4 * lengths[0] / lengths[i];
1384 c[D_RMD160][i] = c[D_RMD160][0] * 4 * lengths[0] / lengths[i];
1385 c[D_SHA256][i] = c[D_SHA256][0] * 4 * lengths[0] / lengths[i];
1386 c[D_SHA512][i] = c[D_SHA512][0] * 4 * lengths[0] / lengths[i];
1387 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * lengths[0] / lengths[i];
1389 for (i = 1; i < SIZE_NUM; i++) {
1392 l0 = (long)lengths[i - 1];
1393 l1 = (long)lengths[i];
1394 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1395 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1396 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1397 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1398 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1399 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1400 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1401 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1402 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1403 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1404 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1405 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1406 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1407 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1408 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1409 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1410 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1411 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1413 # ifndef OPENSSL_NO_RSA
1414 rsa_c[R_RSA_512][0] = count / 2000;
1415 rsa_c[R_RSA_512][1] = count / 400;
1416 for (i = 1; i < RSA_NUM; i++) {
1417 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1418 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1419 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1422 if (rsa_c[i][0] == 0) {
1430 # ifndef OPENSSL_NO_DSA
1431 dsa_c[R_DSA_512][0] = count / 1000;
1432 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1433 for (i = 1; i < DSA_NUM; i++) {
1434 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1435 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1436 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1439 if (dsa_c[i] == 0) {
1447 # ifndef OPENSSL_NO_ECDSA
1448 ecdsa_c[R_EC_P160][0] = count / 1000;
1449 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1450 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1451 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1452 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1453 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1456 if (ecdsa_c[i] == 0) {
1462 ecdsa_c[R_EC_K163][0] = count / 1000;
1463 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1464 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1465 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1466 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1467 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1470 if (ecdsa_c[i] == 0) {
1476 ecdsa_c[R_EC_B163][0] = count / 1000;
1477 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1478 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1479 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1480 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1481 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1484 if (ecdsa_c[i] == 0) {
1492 # ifndef OPENSSL_NO_ECDH
1493 ecdh_c[R_EC_P160][0] = count / 1000;
1494 ecdh_c[R_EC_P160][1] = count / 1000;
1495 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1496 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1497 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1498 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1501 if (ecdh_c[i] == 0) {
1507 ecdh_c[R_EC_K163][0] = count / 1000;
1508 ecdh_c[R_EC_K163][1] = count / 1000;
1509 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1510 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1511 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1512 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1515 if (ecdh_c[i] == 0) {
1521 ecdh_c[R_EC_B163][0] = count / 1000;
1522 ecdh_c[R_EC_B163][1] = count / 1000;
1523 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1524 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1525 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1526 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1529 if (ecdh_c[i] == 0) {
1537 # define COND(d) (count < (d))
1538 # define COUNT(d) (d)
1540 /* not worth fixing */
1541 # error "You cannot disable DES on systems without SIGALRM."
1542 # endif /* OPENSSL_NO_DES */
1544 # define COND(c) (run && count<0x7fffffff)
1545 # define COUNT(d) (count)
1547 signal(SIGALRM, sig_done);
1549 # endif /* SIGALRM */
1551 # ifndef OPENSSL_NO_MD2
1553 for (j = 0; j < SIZE_NUM; j++) {
1554 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1556 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1557 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1560 print_result(D_MD2, j, count, d);
1564 # ifndef OPENSSL_NO_MDC2
1566 for (j = 0; j < SIZE_NUM; j++) {
1567 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1569 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1570 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1573 print_result(D_MDC2, j, count, d);
1578 # ifndef OPENSSL_NO_MD4
1580 for (j = 0; j < SIZE_NUM; j++) {
1581 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1583 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1584 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1585 NULL, EVP_md4(), NULL);
1587 print_result(D_MD4, j, count, d);
1592 # ifndef OPENSSL_NO_MD5
1594 for (j = 0; j < SIZE_NUM; j++) {
1595 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1597 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1598 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md5[0]),
1599 NULL, EVP_get_digestbyname("md5"), NULL);
1601 print_result(D_MD5, j, count, d);
1606 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1610 HMAC_CTX_init(&hctx);
1611 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1612 16, EVP_md5(), NULL);
1614 for (j = 0; j < SIZE_NUM; j++) {
1615 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1617 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1618 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1619 HMAC_Update(&hctx, buf, lengths[j]);
1620 HMAC_Final(&hctx, &(hmac[0]), NULL);
1623 print_result(D_HMAC, j, count, d);
1625 HMAC_CTX_cleanup(&hctx);
1628 # ifndef OPENSSL_NO_SHA
1630 for (j = 0; j < SIZE_NUM; j++) {
1631 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1633 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1634 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1637 print_result(D_SHA1, j, count, d);
1640 # ifndef OPENSSL_NO_SHA256
1641 if (doit[D_SHA256]) {
1642 for (j = 0; j < SIZE_NUM; j++) {
1643 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1645 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1646 SHA256(buf, lengths[j], sha256);
1648 print_result(D_SHA256, j, count, d);
1653 # ifndef OPENSSL_NO_SHA512
1654 if (doit[D_SHA512]) {
1655 for (j = 0; j < SIZE_NUM; j++) {
1656 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1658 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1659 SHA512(buf, lengths[j], sha512);
1661 print_result(D_SHA512, j, count, d);
1667 # ifndef OPENSSL_NO_WHIRLPOOL
1668 if (doit[D_WHIRLPOOL]) {
1669 for (j = 0; j < SIZE_NUM; j++) {
1670 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1672 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1673 WHIRLPOOL(buf, lengths[j], whirlpool);
1675 print_result(D_WHIRLPOOL, j, count, d);
1680 # ifndef OPENSSL_NO_RIPEMD
1681 if (doit[D_RMD160]) {
1682 for (j = 0; j < SIZE_NUM; j++) {
1683 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1685 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1686 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1687 EVP_ripemd160(), NULL);
1689 print_result(D_RMD160, j, count, d);
1693 # ifndef OPENSSL_NO_RC4
1695 for (j = 0; j < SIZE_NUM; j++) {
1696 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1698 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1699 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1701 print_result(D_RC4, j, count, d);
1705 # ifndef OPENSSL_NO_DES
1706 if (doit[D_CBC_DES]) {
1707 for (j = 0; j < SIZE_NUM; j++) {
1708 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1710 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1711 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1712 &DES_iv, DES_ENCRYPT);
1714 print_result(D_CBC_DES, j, count, d);
1718 if (doit[D_EDE3_DES]) {
1719 for (j = 0; j < SIZE_NUM; j++) {
1720 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1722 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1723 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1725 &DES_iv, DES_ENCRYPT);
1727 print_result(D_EDE3_DES, j, count, d);
1731 # ifndef OPENSSL_NO_AES
1732 if (doit[D_CBC_128_AES]) {
1733 for (j = 0; j < SIZE_NUM; j++) {
1734 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1737 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1738 AES_cbc_encrypt(buf, buf,
1739 (unsigned long)lengths[j], &aes_ks1,
1742 print_result(D_CBC_128_AES, j, count, d);
1745 if (doit[D_CBC_192_AES]) {
1746 for (j = 0; j < SIZE_NUM; j++) {
1747 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1750 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1751 AES_cbc_encrypt(buf, buf,
1752 (unsigned long)lengths[j], &aes_ks2,
1755 print_result(D_CBC_192_AES, j, count, d);
1758 if (doit[D_CBC_256_AES]) {
1759 for (j = 0; j < SIZE_NUM; j++) {
1760 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1763 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1764 AES_cbc_encrypt(buf, buf,
1765 (unsigned long)lengths[j], &aes_ks3,
1768 print_result(D_CBC_256_AES, j, count, d);
1772 if (doit[D_IGE_128_AES]) {
1773 for (j = 0; j < SIZE_NUM; j++) {
1774 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1777 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1778 AES_ige_encrypt(buf, buf2,
1779 (unsigned long)lengths[j], &aes_ks1,
1782 print_result(D_IGE_128_AES, j, count, d);
1785 if (doit[D_IGE_192_AES]) {
1786 for (j = 0; j < SIZE_NUM; j++) {
1787 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1790 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1791 AES_ige_encrypt(buf, buf2,
1792 (unsigned long)lengths[j], &aes_ks2,
1795 print_result(D_IGE_192_AES, j, count, d);
1798 if (doit[D_IGE_256_AES]) {
1799 for (j = 0; j < SIZE_NUM; j++) {
1800 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1803 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1804 AES_ige_encrypt(buf, buf2,
1805 (unsigned long)lengths[j], &aes_ks3,
1808 print_result(D_IGE_256_AES, j, count, d);
1811 if (doit[D_GHASH]) {
1812 GCM128_CONTEXT *ctx =
1813 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1814 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1816 for (j = 0; j < SIZE_NUM; j++) {
1817 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1819 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1820 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1822 print_result(D_GHASH, j, count, d);
1824 CRYPTO_gcm128_release(ctx);
1827 # ifndef OPENSSL_NO_CAMELLIA
1828 if (doit[D_CBC_128_CML]) {
1829 for (j = 0; j < SIZE_NUM; j++) {
1830 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1833 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1834 Camellia_cbc_encrypt(buf, buf,
1835 (unsigned long)lengths[j], &camellia_ks1,
1836 iv, CAMELLIA_ENCRYPT);
1838 print_result(D_CBC_128_CML, j, count, d);
1841 if (doit[D_CBC_192_CML]) {
1842 for (j = 0; j < SIZE_NUM; j++) {
1843 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1846 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1847 Camellia_cbc_encrypt(buf, buf,
1848 (unsigned long)lengths[j], &camellia_ks2,
1849 iv, CAMELLIA_ENCRYPT);
1851 print_result(D_CBC_192_CML, j, count, d);
1854 if (doit[D_CBC_256_CML]) {
1855 for (j = 0; j < SIZE_NUM; j++) {
1856 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1859 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1860 Camellia_cbc_encrypt(buf, buf,
1861 (unsigned long)lengths[j], &camellia_ks3,
1862 iv, CAMELLIA_ENCRYPT);
1864 print_result(D_CBC_256_CML, j, count, d);
1868 # ifndef OPENSSL_NO_IDEA
1869 if (doit[D_CBC_IDEA]) {
1870 for (j = 0; j < SIZE_NUM; j++) {
1871 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1873 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1874 idea_cbc_encrypt(buf, buf,
1875 (unsigned long)lengths[j], &idea_ks,
1878 print_result(D_CBC_IDEA, j, count, d);
1882 # ifndef OPENSSL_NO_SEED
1883 if (doit[D_CBC_SEED]) {
1884 for (j = 0; j < SIZE_NUM; j++) {
1885 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1887 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1888 SEED_cbc_encrypt(buf, buf,
1889 (unsigned long)lengths[j], &seed_ks, iv, 1);
1891 print_result(D_CBC_SEED, j, count, d);
1895 # ifndef OPENSSL_NO_RC2
1896 if (doit[D_CBC_RC2]) {
1897 for (j = 0; j < SIZE_NUM; j++) {
1898 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1900 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1901 RC2_cbc_encrypt(buf, buf,
1902 (unsigned long)lengths[j], &rc2_ks,
1905 print_result(D_CBC_RC2, j, count, d);
1909 # ifndef OPENSSL_NO_RC5
1910 if (doit[D_CBC_RC5]) {
1911 for (j = 0; j < SIZE_NUM; j++) {
1912 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1914 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1915 RC5_32_cbc_encrypt(buf, buf,
1916 (unsigned long)lengths[j], &rc5_ks,
1919 print_result(D_CBC_RC5, j, count, d);
1923 # ifndef OPENSSL_NO_BF
1924 if (doit[D_CBC_BF]) {
1925 for (j = 0; j < SIZE_NUM; j++) {
1926 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1928 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1929 BF_cbc_encrypt(buf, buf,
1930 (unsigned long)lengths[j], &bf_ks,
1933 print_result(D_CBC_BF, j, count, d);
1937 # ifndef OPENSSL_NO_CAST
1938 if (doit[D_CBC_CAST]) {
1939 for (j = 0; j < SIZE_NUM; j++) {
1940 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1942 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1943 CAST_cbc_encrypt(buf, buf,
1944 (unsigned long)lengths[j], &cast_ks,
1947 print_result(D_CBC_CAST, j, count, d);
1953 # ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1954 if (multiblock && evp_cipher) {
1956 (EVP_CIPHER_flags(evp_cipher) &
1957 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1958 fprintf(stderr, "%s is not multi-block capable\n",
1959 OBJ_nid2ln(evp_cipher->nid));
1962 multiblock_speed(evp_cipher);
1967 for (j = 0; j < SIZE_NUM; j++) {
1972 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1974 * -O3 -fschedule-insns messes up an optimization here!
1975 * names[D_EVP] somehow becomes NULL
1977 print_message(names[D_EVP], save_count, lengths[j]);
1979 EVP_CIPHER_CTX_init(&ctx);
1981 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1983 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1984 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1988 for (count = 0, run = 1;
1989 COND(save_count * 4 * lengths[0] / lengths[j]);
1991 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1993 for (count = 0, run = 1;
1994 COND(save_count * 4 * lengths[0] / lengths[j]);
1996 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1998 EVP_DecryptFinal_ex(&ctx, buf, &outl);
2000 EVP_EncryptFinal_ex(&ctx, buf, &outl);
2002 EVP_CIPHER_CTX_cleanup(&ctx);
2005 names[D_EVP] = OBJ_nid2ln(evp_md->type);
2006 print_message(names[D_EVP], save_count, lengths[j]);
2009 for (count = 0, run = 1;
2010 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
2011 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
2015 print_result(D_EVP, j, count, d);
2019 RAND_pseudo_bytes(buf, 36);
2020 # ifndef OPENSSL_NO_RSA
2021 for (j = 0; j < RSA_NUM; j++) {
2025 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
2028 "RSA sign failure. No RSA sign will be done.\n");
2029 ERR_print_errors(bio_err);
2032 pkey_print_message("private", "rsa",
2033 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
2034 /* RSA_blinding_on(rsa_key[j],NULL); */
2036 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
2037 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
2038 &rsa_num, rsa_key[j]);
2040 BIO_printf(bio_err, "RSA sign failure\n");
2041 ERR_print_errors(bio_err);
2048 mr ? "+R1:%ld:%d:%.2f\n"
2049 : "%ld %d bit private RSA's in %.2fs\n",
2050 count, rsa_bits[j], d);
2051 rsa_results[j][0] = d / (double)count;
2056 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2059 "RSA verify failure. No RSA verify will be done.\n");
2060 ERR_print_errors(bio_err);
2063 pkey_print_message("public", "rsa",
2064 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2066 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2067 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2068 rsa_num, rsa_key[j]);
2070 BIO_printf(bio_err, "RSA verify failure\n");
2071 ERR_print_errors(bio_err);
2078 mr ? "+R2:%ld:%d:%.2f\n"
2079 : "%ld %d bit public RSA's in %.2fs\n",
2080 count, rsa_bits[j], d);
2081 rsa_results[j][1] = d / (double)count;
2085 if (rsa_count <= 1) {
2086 /* if longer than 10s, don't do any more */
2087 for (j++; j < RSA_NUM; j++)
2093 RAND_pseudo_bytes(buf, 20);
2094 # ifndef OPENSSL_NO_DSA
2095 if (RAND_status() != 1) {
2096 RAND_seed(rnd_seed, sizeof rnd_seed);
2099 for (j = 0; j < DSA_NUM; j++) {
2106 /* DSA_generate_key(dsa_key[j]); */
2107 /* DSA_sign_setup(dsa_key[j],NULL); */
2108 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2111 "DSA sign failure. No DSA sign will be done.\n");
2112 ERR_print_errors(bio_err);
2115 pkey_print_message("sign", "dsa",
2116 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2118 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2119 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2121 BIO_printf(bio_err, "DSA sign failure\n");
2122 ERR_print_errors(bio_err);
2129 mr ? "+R3:%ld:%d:%.2f\n"
2130 : "%ld %d bit DSA signs in %.2fs\n",
2131 count, dsa_bits[j], d);
2132 dsa_results[j][0] = d / (double)count;
2136 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2139 "DSA verify failure. No DSA verify will be done.\n");
2140 ERR_print_errors(bio_err);
2143 pkey_print_message("verify", "dsa",
2144 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2146 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2147 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2149 BIO_printf(bio_err, "DSA verify failure\n");
2150 ERR_print_errors(bio_err);
2157 mr ? "+R4:%ld:%d:%.2f\n"
2158 : "%ld %d bit DSA verify in %.2fs\n",
2159 count, dsa_bits[j], d);
2160 dsa_results[j][1] = d / (double)count;
2163 if (rsa_count <= 1) {
2164 /* if longer than 10s, don't do any more */
2165 for (j++; j < DSA_NUM; j++)
2173 # ifndef OPENSSL_NO_ECDSA
2174 if (RAND_status() != 1) {
2175 RAND_seed(rnd_seed, sizeof rnd_seed);
2178 for (j = 0; j < EC_NUM; j++) {
2182 continue; /* Ignore Curve */
2183 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2184 if (ecdsa[j] == NULL) {
2185 BIO_printf(bio_err, "ECDSA failure.\n");
2186 ERR_print_errors(bio_err);
2190 EC_KEY_precompute_mult(ecdsa[j], NULL);
2192 /* Perform ECDSA signature test */
2193 EC_KEY_generate_key(ecdsa[j]);
2194 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2197 "ECDSA sign failure. No ECDSA sign will be done.\n");
2198 ERR_print_errors(bio_err);
2201 pkey_print_message("sign", "ecdsa",
2203 test_curves_bits[j], ECDSA_SECONDS);
2206 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2207 ret = ECDSA_sign(0, buf, 20,
2208 ecdsasig, &ecdsasiglen, ecdsa[j]);
2210 BIO_printf(bio_err, "ECDSA sign failure\n");
2211 ERR_print_errors(bio_err);
2219 mr ? "+R5:%ld:%d:%.2f\n" :
2220 "%ld %d bit ECDSA signs in %.2fs \n",
2221 count, test_curves_bits[j], d);
2222 ecdsa_results[j][0] = d / (double)count;
2226 /* Perform ECDSA verification test */
2227 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2230 "ECDSA verify failure. No ECDSA verify will be done.\n");
2231 ERR_print_errors(bio_err);
2234 pkey_print_message("verify", "ecdsa",
2236 test_curves_bits[j], ECDSA_SECONDS);
2238 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2240 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2243 BIO_printf(bio_err, "ECDSA verify failure\n");
2244 ERR_print_errors(bio_err);
2251 mr ? "+R6:%ld:%d:%.2f\n"
2252 : "%ld %d bit ECDSA verify in %.2fs\n",
2253 count, test_curves_bits[j], d);
2254 ecdsa_results[j][1] = d / (double)count;
2257 if (rsa_count <= 1) {
2258 /* if longer than 10s, don't do any more */
2259 for (j++; j < EC_NUM; j++)
2268 # ifndef OPENSSL_NO_ECDH
2269 if (RAND_status() != 1) {
2270 RAND_seed(rnd_seed, sizeof rnd_seed);
2273 for (j = 0; j < EC_NUM; j++) {
2276 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2277 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2278 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2279 BIO_printf(bio_err, "ECDH failure.\n");
2280 ERR_print_errors(bio_err);
2283 /* generate two ECDH key pairs */
2284 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2285 !EC_KEY_generate_key(ecdh_b[j])) {
2286 BIO_printf(bio_err, "ECDH key generation failure.\n");
2287 ERR_print_errors(bio_err);
2291 * If field size is not more than 24 octets, then use SHA-1
2292 * hash of result; otherwise, use result (see section 4.8 of
2293 * draft-ietf-tls-ecc-03.txt).
2295 int field_size, outlen;
2296 void *(*kdf) (const void *in, size_t inlen, void *out,
2299 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2300 if (field_size <= 24 * 8) {
2301 outlen = KDF1_SHA1_len;
2304 outlen = (field_size + 7) / 8;
2308 ECDH_compute_key(secret_a, outlen,
2309 EC_KEY_get0_public_key(ecdh_b[j]),
2312 ECDH_compute_key(secret_b, outlen,
2313 EC_KEY_get0_public_key(ecdh_a[j]),
2315 if (secret_size_a != secret_size_b)
2320 for (secret_idx = 0; (secret_idx < secret_size_a)
2321 && (ecdh_checks == 1); secret_idx++) {
2322 if (secret_a[secret_idx] != secret_b[secret_idx])
2326 if (ecdh_checks == 0) {
2327 BIO_printf(bio_err, "ECDH computations don't match.\n");
2328 ERR_print_errors(bio_err);
2332 pkey_print_message("", "ecdh",
2334 test_curves_bits[j], ECDH_SECONDS);
2336 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2337 ECDH_compute_key(secret_a, outlen,
2338 EC_KEY_get0_public_key(ecdh_b[j]),
2343 mr ? "+R7:%ld:%d:%.2f\n" :
2344 "%ld %d-bit ECDH ops in %.2fs\n", count,
2345 test_curves_bits[j], d);
2346 ecdh_results[j][0] = d / (double)count;
2351 if (rsa_count <= 1) {
2352 /* if longer than 10s, don't do any more */
2353 for (j++; j < EC_NUM; j++)
2364 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2365 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2367 printf("%s ", BN_options());
2368 # ifndef OPENSSL_NO_MD2
2369 printf("%s ", MD2_options());
2371 # ifndef OPENSSL_NO_RC4
2372 printf("%s ", RC4_options());
2374 # ifndef OPENSSL_NO_DES
2375 printf("%s ", DES_options());
2377 # ifndef OPENSSL_NO_AES
2378 printf("%s ", AES_options());
2380 # ifndef OPENSSL_NO_IDEA
2381 printf("%s ", idea_options());
2383 # ifndef OPENSSL_NO_BF
2384 printf("%s ", BF_options());
2386 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2391 fprintf(stdout, "+H");
2394 "The 'numbers' are in 1000s of bytes per second processed.\n");
2395 fprintf(stdout, "type ");
2397 for (j = 0; j < SIZE_NUM; j++)
2398 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2399 fprintf(stdout, "\n");
2402 for (k = 0; k < ALGOR_NUM; k++) {
2406 fprintf(stdout, "+F:%d:%s", k, names[k]);
2408 fprintf(stdout, "%-13s", names[k]);
2409 for (j = 0; j < SIZE_NUM; j++) {
2410 if (results[k][j] > 10000 && !mr)
2411 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2413 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2415 fprintf(stdout, "\n");
2417 # ifndef OPENSSL_NO_RSA
2419 for (k = 0; k < RSA_NUM; k++) {
2423 printf("%18ssign verify sign/s verify/s\n", " ");
2427 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2428 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2430 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2431 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2432 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2435 # ifndef OPENSSL_NO_DSA
2437 for (k = 0; k < DSA_NUM; k++) {
2441 printf("%18ssign verify sign/s verify/s\n", " ");
2445 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2446 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2448 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2449 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2450 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2453 # ifndef OPENSSL_NO_ECDSA
2455 for (k = 0; k < EC_NUM; k++) {
2459 printf("%30ssign verify sign/s verify/s\n", " ");
2464 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2465 k, test_curves_bits[k],
2466 ecdsa_results[k][0], ecdsa_results[k][1]);
2469 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2470 test_curves_bits[k],
2471 test_curves_names[k],
2472 ecdsa_results[k][0], ecdsa_results[k][1],
2473 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2477 # ifndef OPENSSL_NO_ECDH
2479 for (k = 0; k < EC_NUM; k++) {
2483 printf("%30sop op/s\n", " ");
2487 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2488 k, test_curves_bits[k],
2489 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2492 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2493 test_curves_bits[k],
2494 test_curves_names[k],
2495 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2502 ERR_print_errors(bio_err);
2507 # ifndef OPENSSL_NO_RSA
2508 for (i = 0; i < RSA_NUM; i++)
2509 if (rsa_key[i] != NULL)
2510 RSA_free(rsa_key[i]);
2512 # ifndef OPENSSL_NO_DSA
2513 for (i = 0; i < DSA_NUM; i++)
2514 if (dsa_key[i] != NULL)
2515 DSA_free(dsa_key[i]);
2518 # ifndef OPENSSL_NO_ECDSA
2519 for (i = 0; i < EC_NUM; i++)
2520 if (ecdsa[i] != NULL)
2521 EC_KEY_free(ecdsa[i]);
2523 # ifndef OPENSSL_NO_ECDH
2524 for (i = 0; i < EC_NUM; i++) {
2525 if (ecdh_a[i] != NULL)
2526 EC_KEY_free(ecdh_a[i]);
2527 if (ecdh_b[i] != NULL)
2528 EC_KEY_free(ecdh_b[i]);
2532 #ifndef OPENSSL_NO_ENGINE
2540 static void print_message(const char *s, long num, int length)
2544 mr ? "+DT:%s:%d:%d\n"
2545 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2546 (void)BIO_flush(bio_err);
2550 mr ? "+DN:%s:%ld:%d\n"
2551 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2552 (void)BIO_flush(bio_err);
2559 static void pkey_print_message(const char *str, const char *str2, long num,
2564 mr ? "+DTP:%d:%s:%s:%d\n"
2565 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2566 (void)BIO_flush(bio_err);
2570 mr ? "+DNP:%ld:%d:%s:%s\n"
2571 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2572 (void)BIO_flush(bio_err);
2579 static void print_result(int alg, int run_no, int count, double time_used)
2582 mr ? "+R:%d:%s:%f\n"
2583 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2584 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2588 static char *sstrsep(char **string, const char *delim)
2591 char *token = *string;
2596 memset(isdelim, 0, sizeof isdelim);
2600 isdelim[(unsigned char)(*delim)] = 1;
2604 while (!isdelim[(unsigned char)(**string)]) {
2616 static int do_multi(int multi)
2621 static char sep[] = ":";
2623 fds = malloc(multi * sizeof *fds);
2625 fprintf(stderr, "Out of memory in speed (do_multi)\n");
2628 for (n = 0; n < multi; ++n) {
2629 if (pipe(fd) == -1) {
2630 fprintf(stderr, "pipe failure\n");
2641 if (dup(fd[1]) == -1) {
2642 fprintf(stderr, "dup failed\n");
2651 printf("Forked child %d\n", n);
2654 /* for now, assume the pipe is long enough to take all the output */
2655 for (n = 0; n < multi; ++n) {
2660 f = fdopen(fds[n], "r");
2661 while (fgets(buf, sizeof buf, f)) {
2662 p = strchr(buf, '\n');
2665 if (buf[0] != '+') {
2666 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2670 printf("Got: %s from %d\n", buf, n);
2671 if (!strncmp(buf, "+F:", 3)) {
2676 alg = atoi(sstrsep(&p, sep));
2678 for (j = 0; j < SIZE_NUM; ++j)
2679 results[alg][j] += atof(sstrsep(&p, sep));
2680 } else if (!strncmp(buf, "+F2:", 4)) {
2685 k = atoi(sstrsep(&p, sep));
2688 d = atof(sstrsep(&p, sep));
2690 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2692 rsa_results[k][0] = d;
2694 d = atof(sstrsep(&p, sep));
2696 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2698 rsa_results[k][1] = d;
2700 # ifndef OPENSSL_NO_DSA
2701 else if (!strncmp(buf, "+F3:", 4)) {
2706 k = atoi(sstrsep(&p, sep));
2709 d = atof(sstrsep(&p, sep));
2711 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2713 dsa_results[k][0] = d;
2715 d = atof(sstrsep(&p, sep));
2717 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2719 dsa_results[k][1] = d;
2722 # ifndef OPENSSL_NO_ECDSA
2723 else if (!strncmp(buf, "+F4:", 4)) {
2728 k = atoi(sstrsep(&p, sep));
2731 d = atof(sstrsep(&p, sep));
2733 ecdsa_results[k][0] =
2734 1 / (1 / ecdsa_results[k][0] + 1 / d);
2736 ecdsa_results[k][0] = d;
2738 d = atof(sstrsep(&p, sep));
2740 ecdsa_results[k][1] =
2741 1 / (1 / ecdsa_results[k][1] + 1 / d);
2743 ecdsa_results[k][1] = d;
2747 # ifndef OPENSSL_NO_ECDH
2748 else if (!strncmp(buf, "+F5:", 4)) {
2753 k = atoi(sstrsep(&p, sep));
2756 d = atof(sstrsep(&p, sep));
2758 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2760 ecdh_results[k][0] = d;
2765 else if (!strncmp(buf, "+H:", 3)) {
2767 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2777 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2779 static int mblengths[] =
2780 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2781 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2782 const char *alg_name;
2783 unsigned char *inp, *out, no_key[32], no_iv[16];
2787 inp = OPENSSL_malloc(mblengths[num - 1]);
2788 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
2790 BIO_printf(bio_err,"Out of memory\n");
2795 EVP_CIPHER_CTX_init(&ctx);
2796 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2797 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2799 alg_name = OBJ_nid2ln(evp_cipher->nid);
2801 for (j = 0; j < num; j++) {
2802 print_message(alg_name, 0, mblengths[j]);
2804 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2805 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
2806 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2807 size_t len = mblengths[j];
2810 memset(aad, 0, 8); /* avoid uninitialized values */
2811 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2812 aad[9] = 3; /* version */
2814 aad[11] = 0; /* length */
2816 mb_param.out = NULL;
2819 mb_param.interleave = 8;
2821 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2822 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2823 sizeof(mb_param), &mb_param);
2829 EVP_CIPHER_CTX_ctrl(&ctx,
2830 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2831 sizeof(mb_param), &mb_param);
2835 RAND_bytes(out, 16);
2839 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2840 EVP_CTRL_AEAD_TLS1_AAD,
2841 EVP_AEAD_TLS1_AAD_LEN, aad);
2842 EVP_Cipher(&ctx, out, inp, len + pad);
2847 mr ? "+R:%d:%s:%f\n"
2848 : "%d %s's in %.2fs\n", count, "evp", d);
2849 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2853 fprintf(stdout, "+H");
2854 for (j = 0; j < num; j++)
2855 fprintf(stdout, ":%d", mblengths[j]);
2856 fprintf(stdout, "\n");
2857 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2858 for (j = 0; j < num; j++)
2859 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2860 fprintf(stdout, "\n");
2863 "The 'numbers' are in 1000s of bytes per second processed.\n");
2864 fprintf(stdout, "type ");
2865 for (j = 0; j < num; j++)
2866 fprintf(stdout, "%7d bytes", mblengths[j]);
2867 fprintf(stdout, "\n");
2868 fprintf(stdout, "%-24s", alg_name);
2870 for (j = 0; j < num; j++) {
2871 if (results[D_EVP][j] > 10000)
2872 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2874 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2876 fprintf(stdout, "\n");