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 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
112 # include <windows.h>
115 # include <openssl/bn.h>
116 # ifndef OPENSSL_NO_DES
117 # include <openssl/des.h>
119 # ifndef OPENSSL_NO_AES
120 # include <openssl/aes.h>
122 # ifndef OPENSSL_NO_CAMELLIA
123 # include <openssl/camellia.h>
125 # ifndef OPENSSL_NO_MD2
126 # include <openssl/md2.h>
128 # ifndef OPENSSL_NO_MDC2
129 # include <openssl/mdc2.h>
131 # ifndef OPENSSL_NO_MD4
132 # include <openssl/md4.h>
134 # ifndef OPENSSL_NO_MD5
135 # include <openssl/md5.h>
137 # ifndef OPENSSL_NO_HMAC
138 # include <openssl/hmac.h>
140 # include <openssl/evp.h>
141 # ifndef OPENSSL_NO_SHA
142 # include <openssl/sha.h>
144 # ifndef OPENSSL_NO_RIPEMD
145 # include <openssl/ripemd.h>
147 # ifndef OPENSSL_NO_WHIRLPOOL
148 # include <openssl/whrlpool.h>
150 # ifndef OPENSSL_NO_RC4
151 # include <openssl/rc4.h>
153 # ifndef OPENSSL_NO_RC5
154 # include <openssl/rc5.h>
156 # ifndef OPENSSL_NO_RC2
157 # include <openssl/rc2.h>
159 # ifndef OPENSSL_NO_IDEA
160 # include <openssl/idea.h>
162 # ifndef OPENSSL_NO_SEED
163 # include <openssl/seed.h>
165 # ifndef OPENSSL_NO_BF
166 # include <openssl/blowfish.h>
168 # ifndef OPENSSL_NO_CAST
169 # include <openssl/cast.h>
171 # ifndef OPENSSL_NO_RSA
172 # include <openssl/rsa.h>
173 # include "./testrsa.h"
175 # include <openssl/x509.h>
176 # ifndef OPENSSL_NO_DSA
177 # include <openssl/dsa.h>
178 # include "./testdsa.h"
180 # ifndef OPENSSL_NO_ECDSA
181 # include <openssl/ecdsa.h>
183 # ifndef OPENSSL_NO_ECDH
184 # include <openssl/ecdh.h>
188 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
202 # define BUFSIZE ((long)1024*8+1)
206 static int usertime = 1;
208 static double Time_F(int s);
209 static void print_message(const char *s, long num, int length);
210 static void pkey_print_message(const char *str, const char *str2,
211 long num, int bits, int sec);
212 static void print_result(int alg, int run_no, int count, double time_used);
214 static int do_multi(int multi);
217 # define ALGOR_NUM 29
223 # define MAX_ECDH_SIZE 256
225 static const char *names[ALGOR_NUM] = {
226 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
227 "des cbc", "des ede3", "idea cbc", "seed cbc",
228 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
229 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
230 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
231 "evp", "sha256", "sha512", "whirlpool",
232 "aes-128 ige", "aes-192 ige", "aes-256 ige"
235 static double results[ALGOR_NUM][SIZE_NUM];
236 static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
238 # ifndef OPENSSL_NO_RSA
239 static double rsa_results[RSA_NUM][2];
241 # ifndef OPENSSL_NO_DSA
242 static double dsa_results[DSA_NUM][2];
244 # ifndef OPENSSL_NO_ECDSA
245 static double ecdsa_results[EC_NUM][2];
247 # ifndef OPENSSL_NO_ECDH
248 static double ecdh_results[EC_NUM][1];
251 # if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
252 static const char rnd_seed[] =
253 "string to make the random number generator think it has entropy";
254 static int rnd_fake = 0;
258 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
259 # define SIGRETTYPE void
261 # define SIGRETTYPE int
264 static SIGRETTYPE sig_done(int sig);
265 static SIGRETTYPE sig_done(int sig)
267 signal(SIGALRM, sig_done);
281 static unsigned int lapse, schlock;
282 static void alarm(unsigned int secs)
287 static DWORD WINAPI sleepy(VOID * arg)
295 static double Time_F(int s)
300 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
302 DWORD ret = GetLastError();
303 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
306 CloseHandle(thr); /* detach the thread */
308 Sleep(0); /* scheduler spinlock */
311 return app_tminterval(s, usertime);
315 static double Time_F(int s)
317 return app_tminterval(s, usertime);
321 # ifndef OPENSSL_NO_ECDH
322 static const int KDF1_SHA1_len = 20;
323 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
326 # ifndef OPENSSL_NO_SHA
327 if (*outlen < SHA_DIGEST_LENGTH)
330 *outlen = SHA_DIGEST_LENGTH;
331 return SHA1(in, inlen, out);
334 # endif /* OPENSSL_NO_SHA */
336 # endif /* OPENSSL_NO_ECDH */
338 int MAIN(int, char **);
340 int MAIN(int argc, char **argv)
342 unsigned char *buf = NULL, *buf2 = NULL;
344 long count = 0, save_count = 0;
346 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
349 # ifndef OPENSSL_NO_RSA
352 unsigned char md[EVP_MAX_MD_SIZE];
353 # ifndef OPENSSL_NO_MD2
354 unsigned char md2[MD2_DIGEST_LENGTH];
356 # ifndef OPENSSL_NO_MDC2
357 unsigned char mdc2[MDC2_DIGEST_LENGTH];
359 # ifndef OPENSSL_NO_MD4
360 unsigned char md4[MD4_DIGEST_LENGTH];
362 # ifndef OPENSSL_NO_MD5
363 unsigned char md5[MD5_DIGEST_LENGTH];
364 unsigned char hmac[MD5_DIGEST_LENGTH];
366 # ifndef OPENSSL_NO_SHA
367 unsigned char sha[SHA_DIGEST_LENGTH];
368 # ifndef OPENSSL_NO_SHA256
369 unsigned char sha256[SHA256_DIGEST_LENGTH];
371 # ifndef OPENSSL_NO_SHA512
372 unsigned char sha512[SHA512_DIGEST_LENGTH];
375 # ifndef OPENSSL_NO_WHIRLPOOL
376 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
378 # ifndef OPENSSL_NO_RIPEMD
379 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
381 # ifndef OPENSSL_NO_RC4
384 # ifndef OPENSSL_NO_RC5
387 # ifndef OPENSSL_NO_RC2
390 # ifndef OPENSSL_NO_IDEA
391 IDEA_KEY_SCHEDULE idea_ks;
393 # ifndef OPENSSL_NO_SEED
394 SEED_KEY_SCHEDULE seed_ks;
396 # ifndef OPENSSL_NO_BF
399 # ifndef OPENSSL_NO_CAST
402 static const unsigned char key16[16] = {
403 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
404 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
406 # ifndef OPENSSL_NO_AES
407 static const unsigned char key24[24] = {
408 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
409 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
410 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
412 static const unsigned char key32[32] = {
413 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
414 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
415 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
416 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
419 # ifndef OPENSSL_NO_CAMELLIA
420 static const unsigned char ckey24[24] = {
421 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
422 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
423 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
425 static const unsigned char ckey32[32] = {
426 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
427 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
428 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
429 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
432 # ifndef OPENSSL_NO_AES
433 # define MAX_BLOCK_SIZE 128
435 # define MAX_BLOCK_SIZE 64
437 unsigned char DES_iv[8];
438 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
439 # ifndef OPENSSL_NO_DES
440 static DES_cblock key =
441 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
442 static DES_cblock key2 =
443 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
444 static DES_cblock key3 =
445 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
446 DES_key_schedule sch;
447 DES_key_schedule sch2;
448 DES_key_schedule sch3;
450 # ifndef OPENSSL_NO_AES
451 AES_KEY aes_ks1, aes_ks2, aes_ks3;
453 # ifndef OPENSSL_NO_CAMELLIA
454 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
465 # define D_EDE3_DES 9
466 # define D_CBC_IDEA 10
467 # define D_CBC_SEED 11
468 # define D_CBC_RC2 12
469 # define D_CBC_RC5 13
471 # define D_CBC_CAST 15
472 # define D_CBC_128_AES 16
473 # define D_CBC_192_AES 17
474 # define D_CBC_256_AES 18
475 # define D_CBC_128_CML 19
476 # define D_CBC_192_CML 20
477 # define D_CBC_256_CML 21
481 # define D_WHIRLPOOL 25
482 # define D_IGE_128_AES 26
483 # define D_IGE_192_AES 27
484 # define D_IGE_256_AES 28
486 long c[ALGOR_NUM][SIZE_NUM];
488 # define R_DSA_1024 1
489 # define R_DSA_2048 2
491 # define R_RSA_1024 1
492 # define R_RSA_2048 2
493 # define R_RSA_4096 3
505 # define R_EC_K571 10
506 # define R_EC_B163 11
507 # define R_EC_B233 12
508 # define R_EC_B283 13
509 # define R_EC_B409 14
510 # define R_EC_B571 15
512 # ifndef OPENSSL_NO_RSA
513 RSA *rsa_key[RSA_NUM];
514 long rsa_c[RSA_NUM][2];
515 static unsigned int rsa_bits[RSA_NUM] = {
516 512, 1024, 2048, 4096
518 static unsigned char *rsa_data[RSA_NUM] = {
519 test512, test1024, test2048, test4096
521 static int rsa_data_length[RSA_NUM] = {
522 sizeof(test512), sizeof(test1024),
523 sizeof(test2048), sizeof(test4096)
526 # ifndef OPENSSL_NO_DSA
527 DSA *dsa_key[DSA_NUM];
528 long dsa_c[DSA_NUM][2];
529 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
531 # ifndef OPENSSL_NO_EC
533 * We only test over the following curves as they are representative, To
534 * add tests over more curves, simply add the curve NID and curve name to
535 * the following arrays and increase the EC_NUM value accordingly.
537 static unsigned int test_curves[EC_NUM] = {
540 NID_X9_62_prime192v1,
542 NID_X9_62_prime256v1,
557 static const char *test_curves_names[EC_NUM] = {
577 static int test_curves_bits[EC_NUM] = {
578 160, 192, 224, 256, 384, 521,
579 163, 233, 283, 409, 571,
580 163, 233, 283, 409, 571
585 # ifndef OPENSSL_NO_ECDSA
586 unsigned char ecdsasig[256];
587 unsigned int ecdsasiglen;
588 EC_KEY *ecdsa[EC_NUM];
589 long ecdsa_c[EC_NUM][2];
592 # ifndef OPENSSL_NO_ECDH
593 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
594 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
595 int secret_size_a, secret_size_b;
598 long ecdh_c[EC_NUM][2];
601 int rsa_doit[RSA_NUM];
602 int dsa_doit[DSA_NUM];
603 # ifndef OPENSSL_NO_ECDSA
604 int ecdsa_doit[EC_NUM];
606 # ifndef OPENSSL_NO_ECDH
607 int ecdh_doit[EC_NUM];
611 const EVP_CIPHER *evp_cipher = NULL;
612 const EVP_MD *evp_md = NULL;
623 memset(results, 0, sizeof(results));
624 # ifndef OPENSSL_NO_DSA
625 memset(dsa_key, 0, sizeof(dsa_key));
627 # ifndef OPENSSL_NO_ECDSA
628 for (i = 0; i < EC_NUM; i++)
631 # ifndef OPENSSL_NO_ECDH
632 for (i = 0; i < EC_NUM; i++) {
639 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
640 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
642 if (!load_config(bio_err, NULL))
645 # ifndef OPENSSL_NO_RSA
646 memset(rsa_key, 0, sizeof(rsa_key));
647 for (i = 0; i < RSA_NUM; i++)
651 if ((buf = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
652 BIO_printf(bio_err, "out of memory\n");
655 if ((buf2 = (unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) {
656 BIO_printf(bio_err, "out of memory\n");
660 memset(c, 0, sizeof(c));
661 memset(DES_iv, 0, sizeof(DES_iv));
662 memset(iv, 0, sizeof(iv));
664 for (i = 0; i < ALGOR_NUM; i++)
666 for (i = 0; i < RSA_NUM; i++)
668 for (i = 0; i < DSA_NUM; i++)
670 # ifndef OPENSSL_NO_ECDSA
671 for (i = 0; i < EC_NUM; i++)
674 # ifndef OPENSSL_NO_ECDH
675 for (i = 0; i < EC_NUM; i++)
683 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
685 j--; /* Otherwise, -elapsed gets confused with an
687 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
691 BIO_printf(bio_err, "no EVP given\n");
694 evp_cipher = EVP_get_cipherbyname(*argv);
696 evp_md = EVP_get_digestbyname(*argv);
698 if (!evp_cipher && !evp_md) {
699 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
704 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
706 j--; /* Otherwise, -elapsed gets confused with an
709 # ifndef OPENSSL_NO_ENGINE
710 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
714 BIO_printf(bio_err, "no engine given\n");
717 setup_engine(bio_err, *argv, 0);
719 * j will be increased again further down. We just don't want
720 * speed to confuse an engine with an algorithm, especially when
721 * none is given (which means all of them should be run)
727 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
731 BIO_printf(bio_err, "no multi count given\n");
734 multi = atoi(argv[0]);
736 BIO_printf(bio_err, "bad multi count\n");
739 j--; /* Otherwise, -mr gets confused with an
743 else if (argc > 0 && !strcmp(*argv, "-mr")) {
745 j--; /* Otherwise, -mr gets confused with an
748 # ifndef OPENSSL_NO_MD2
749 if (strcmp(*argv, "md2") == 0)
753 # ifndef OPENSSL_NO_MDC2
754 if (strcmp(*argv, "mdc2") == 0)
758 # ifndef OPENSSL_NO_MD4
759 if (strcmp(*argv, "md4") == 0)
763 # ifndef OPENSSL_NO_MD5
764 if (strcmp(*argv, "md5") == 0)
768 # ifndef OPENSSL_NO_MD5
769 if (strcmp(*argv, "hmac") == 0)
773 # ifndef OPENSSL_NO_SHA
774 if (strcmp(*argv, "sha1") == 0)
776 else if (strcmp(*argv, "sha") == 0)
777 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
779 # ifndef OPENSSL_NO_SHA256
780 if (strcmp(*argv, "sha256") == 0)
784 # ifndef OPENSSL_NO_SHA512
785 if (strcmp(*argv, "sha512") == 0)
790 # ifndef OPENSSL_NO_WHIRLPOOL
791 if (strcmp(*argv, "whirlpool") == 0)
792 doit[D_WHIRLPOOL] = 1;
795 # ifndef OPENSSL_NO_RIPEMD
796 if (strcmp(*argv, "ripemd") == 0)
798 else if (strcmp(*argv, "rmd160") == 0)
800 else if (strcmp(*argv, "ripemd160") == 0)
804 # ifndef OPENSSL_NO_RC4
805 if (strcmp(*argv, "rc4") == 0)
809 # ifndef OPENSSL_NO_DES
810 if (strcmp(*argv, "des-cbc") == 0)
812 else if (strcmp(*argv, "des-ede3") == 0)
813 doit[D_EDE3_DES] = 1;
816 # ifndef OPENSSL_NO_AES
817 if (strcmp(*argv, "aes-128-cbc") == 0)
818 doit[D_CBC_128_AES] = 1;
819 else if (strcmp(*argv, "aes-192-cbc") == 0)
820 doit[D_CBC_192_AES] = 1;
821 else if (strcmp(*argv, "aes-256-cbc") == 0)
822 doit[D_CBC_256_AES] = 1;
823 else if (strcmp(*argv, "aes-128-ige") == 0)
824 doit[D_IGE_128_AES] = 1;
825 else if (strcmp(*argv, "aes-192-ige") == 0)
826 doit[D_IGE_192_AES] = 1;
827 else if (strcmp(*argv, "aes-256-ige") == 0)
828 doit[D_IGE_256_AES] = 1;
831 # ifndef OPENSSL_NO_CAMELLIA
832 if (strcmp(*argv, "camellia-128-cbc") == 0)
833 doit[D_CBC_128_CML] = 1;
834 else if (strcmp(*argv, "camellia-192-cbc") == 0)
835 doit[D_CBC_192_CML] = 1;
836 else if (strcmp(*argv, "camellia-256-cbc") == 0)
837 doit[D_CBC_256_CML] = 1;
840 # ifndef OPENSSL_NO_RSA
841 # if 0 /* was: #ifdef RSAref */
842 if (strcmp(*argv, "rsaref") == 0) {
843 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
848 if (strcmp(*argv, "openssl") == 0) {
849 RSA_set_default_method(RSA_PKCS1_SSLeay());
853 # endif /* !OPENSSL_NO_RSA */
854 if (strcmp(*argv, "dsa512") == 0)
855 dsa_doit[R_DSA_512] = 2;
856 else if (strcmp(*argv, "dsa1024") == 0)
857 dsa_doit[R_DSA_1024] = 2;
858 else if (strcmp(*argv, "dsa2048") == 0)
859 dsa_doit[R_DSA_2048] = 2;
860 else if (strcmp(*argv, "rsa512") == 0)
861 rsa_doit[R_RSA_512] = 2;
862 else if (strcmp(*argv, "rsa1024") == 0)
863 rsa_doit[R_RSA_1024] = 2;
864 else if (strcmp(*argv, "rsa2048") == 0)
865 rsa_doit[R_RSA_2048] = 2;
866 else if (strcmp(*argv, "rsa4096") == 0)
867 rsa_doit[R_RSA_4096] = 2;
869 # ifndef OPENSSL_NO_RC2
870 if (strcmp(*argv, "rc2-cbc") == 0)
872 else if (strcmp(*argv, "rc2") == 0)
876 # ifndef OPENSSL_NO_RC5
877 if (strcmp(*argv, "rc5-cbc") == 0)
879 else if (strcmp(*argv, "rc5") == 0)
883 # ifndef OPENSSL_NO_IDEA
884 if (strcmp(*argv, "idea-cbc") == 0)
885 doit[D_CBC_IDEA] = 1;
886 else if (strcmp(*argv, "idea") == 0)
887 doit[D_CBC_IDEA] = 1;
890 # ifndef OPENSSL_NO_SEED
891 if (strcmp(*argv, "seed-cbc") == 0)
892 doit[D_CBC_SEED] = 1;
893 else if (strcmp(*argv, "seed") == 0)
894 doit[D_CBC_SEED] = 1;
897 # ifndef OPENSSL_NO_BF
898 if (strcmp(*argv, "bf-cbc") == 0)
900 else if (strcmp(*argv, "blowfish") == 0)
902 else if (strcmp(*argv, "bf") == 0)
906 # ifndef OPENSSL_NO_CAST
907 if (strcmp(*argv, "cast-cbc") == 0)
908 doit[D_CBC_CAST] = 1;
909 else if (strcmp(*argv, "cast") == 0)
910 doit[D_CBC_CAST] = 1;
911 else if (strcmp(*argv, "cast5") == 0)
912 doit[D_CBC_CAST] = 1;
915 # ifndef OPENSSL_NO_DES
916 if (strcmp(*argv, "des") == 0) {
918 doit[D_EDE3_DES] = 1;
921 # ifndef OPENSSL_NO_AES
922 if (strcmp(*argv, "aes") == 0) {
923 doit[D_CBC_128_AES] = 1;
924 doit[D_CBC_192_AES] = 1;
925 doit[D_CBC_256_AES] = 1;
928 # ifndef OPENSSL_NO_CAMELLIA
929 if (strcmp(*argv, "camellia") == 0) {
930 doit[D_CBC_128_CML] = 1;
931 doit[D_CBC_192_CML] = 1;
932 doit[D_CBC_256_CML] = 1;
935 # ifndef OPENSSL_NO_RSA
936 if (strcmp(*argv, "rsa") == 0) {
937 rsa_doit[R_RSA_512] = 1;
938 rsa_doit[R_RSA_1024] = 1;
939 rsa_doit[R_RSA_2048] = 1;
940 rsa_doit[R_RSA_4096] = 1;
943 # ifndef OPENSSL_NO_DSA
944 if (strcmp(*argv, "dsa") == 0) {
945 dsa_doit[R_DSA_512] = 1;
946 dsa_doit[R_DSA_1024] = 1;
947 dsa_doit[R_DSA_2048] = 1;
950 # ifndef OPENSSL_NO_ECDSA
951 if (strcmp(*argv, "ecdsap160") == 0)
952 ecdsa_doit[R_EC_P160] = 2;
953 else if (strcmp(*argv, "ecdsap192") == 0)
954 ecdsa_doit[R_EC_P192] = 2;
955 else if (strcmp(*argv, "ecdsap224") == 0)
956 ecdsa_doit[R_EC_P224] = 2;
957 else if (strcmp(*argv, "ecdsap256") == 0)
958 ecdsa_doit[R_EC_P256] = 2;
959 else if (strcmp(*argv, "ecdsap384") == 0)
960 ecdsa_doit[R_EC_P384] = 2;
961 else if (strcmp(*argv, "ecdsap521") == 0)
962 ecdsa_doit[R_EC_P521] = 2;
963 else if (strcmp(*argv, "ecdsak163") == 0)
964 ecdsa_doit[R_EC_K163] = 2;
965 else if (strcmp(*argv, "ecdsak233") == 0)
966 ecdsa_doit[R_EC_K233] = 2;
967 else if (strcmp(*argv, "ecdsak283") == 0)
968 ecdsa_doit[R_EC_K283] = 2;
969 else if (strcmp(*argv, "ecdsak409") == 0)
970 ecdsa_doit[R_EC_K409] = 2;
971 else if (strcmp(*argv, "ecdsak571") == 0)
972 ecdsa_doit[R_EC_K571] = 2;
973 else if (strcmp(*argv, "ecdsab163") == 0)
974 ecdsa_doit[R_EC_B163] = 2;
975 else if (strcmp(*argv, "ecdsab233") == 0)
976 ecdsa_doit[R_EC_B233] = 2;
977 else if (strcmp(*argv, "ecdsab283") == 0)
978 ecdsa_doit[R_EC_B283] = 2;
979 else if (strcmp(*argv, "ecdsab409") == 0)
980 ecdsa_doit[R_EC_B409] = 2;
981 else if (strcmp(*argv, "ecdsab571") == 0)
982 ecdsa_doit[R_EC_B571] = 2;
983 else if (strcmp(*argv, "ecdsa") == 0) {
984 for (i = 0; i < EC_NUM; i++)
988 # ifndef OPENSSL_NO_ECDH
989 if (strcmp(*argv, "ecdhp160") == 0)
990 ecdh_doit[R_EC_P160] = 2;
991 else if (strcmp(*argv, "ecdhp192") == 0)
992 ecdh_doit[R_EC_P192] = 2;
993 else if (strcmp(*argv, "ecdhp224") == 0)
994 ecdh_doit[R_EC_P224] = 2;
995 else if (strcmp(*argv, "ecdhp256") == 0)
996 ecdh_doit[R_EC_P256] = 2;
997 else if (strcmp(*argv, "ecdhp384") == 0)
998 ecdh_doit[R_EC_P384] = 2;
999 else if (strcmp(*argv, "ecdhp521") == 0)
1000 ecdh_doit[R_EC_P521] = 2;
1001 else if (strcmp(*argv, "ecdhk163") == 0)
1002 ecdh_doit[R_EC_K163] = 2;
1003 else if (strcmp(*argv, "ecdhk233") == 0)
1004 ecdh_doit[R_EC_K233] = 2;
1005 else if (strcmp(*argv, "ecdhk283") == 0)
1006 ecdh_doit[R_EC_K283] = 2;
1007 else if (strcmp(*argv, "ecdhk409") == 0)
1008 ecdh_doit[R_EC_K409] = 2;
1009 else if (strcmp(*argv, "ecdhk571") == 0)
1010 ecdh_doit[R_EC_K571] = 2;
1011 else if (strcmp(*argv, "ecdhb163") == 0)
1012 ecdh_doit[R_EC_B163] = 2;
1013 else if (strcmp(*argv, "ecdhb233") == 0)
1014 ecdh_doit[R_EC_B233] = 2;
1015 else if (strcmp(*argv, "ecdhb283") == 0)
1016 ecdh_doit[R_EC_B283] = 2;
1017 else if (strcmp(*argv, "ecdhb409") == 0)
1018 ecdh_doit[R_EC_B409] = 2;
1019 else if (strcmp(*argv, "ecdhb571") == 0)
1020 ecdh_doit[R_EC_B571] = 2;
1021 else if (strcmp(*argv, "ecdh") == 0) {
1022 for (i = 0; i < EC_NUM; i++)
1027 BIO_printf(bio_err, "Error: bad option or value\n");
1028 BIO_printf(bio_err, "\n");
1029 BIO_printf(bio_err, "Available values:\n");
1030 # ifndef OPENSSL_NO_MD2
1031 BIO_printf(bio_err, "md2 ");
1033 # ifndef OPENSSL_NO_MDC2
1034 BIO_printf(bio_err, "mdc2 ");
1036 # ifndef OPENSSL_NO_MD4
1037 BIO_printf(bio_err, "md4 ");
1039 # ifndef OPENSSL_NO_MD5
1040 BIO_printf(bio_err, "md5 ");
1041 # ifndef OPENSSL_NO_HMAC
1042 BIO_printf(bio_err, "hmac ");
1045 # ifndef OPENSSL_NO_SHA1
1046 BIO_printf(bio_err, "sha1 ");
1048 # ifndef OPENSSL_NO_SHA256
1049 BIO_printf(bio_err, "sha256 ");
1051 # ifndef OPENSSL_NO_SHA512
1052 BIO_printf(bio_err, "sha512 ");
1054 # ifndef OPENSSL_NO_WHIRLPOOL
1055 BIO_printf(bio_err, "whirlpool");
1057 # ifndef OPENSSL_NO_RIPEMD160
1058 BIO_printf(bio_err, "rmd160");
1060 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1061 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1062 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1063 !defined(OPENSSL_NO_WHIRLPOOL)
1064 BIO_printf(bio_err, "\n");
1067 # ifndef OPENSSL_NO_IDEA
1068 BIO_printf(bio_err, "idea-cbc ");
1070 # ifndef OPENSSL_NO_SEED
1071 BIO_printf(bio_err, "seed-cbc ");
1073 # ifndef OPENSSL_NO_RC2
1074 BIO_printf(bio_err, "rc2-cbc ");
1076 # ifndef OPENSSL_NO_RC5
1077 BIO_printf(bio_err, "rc5-cbc ");
1079 # ifndef OPENSSL_NO_BF
1080 BIO_printf(bio_err, "bf-cbc");
1082 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1083 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1084 BIO_printf(bio_err, "\n");
1086 # ifndef OPENSSL_NO_DES
1087 BIO_printf(bio_err, "des-cbc des-ede3 ");
1089 # ifndef OPENSSL_NO_AES
1090 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1091 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
1093 # ifndef OPENSSL_NO_CAMELLIA
1094 BIO_printf(bio_err, "\n");
1096 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1098 # ifndef OPENSSL_NO_RC4
1099 BIO_printf(bio_err, "rc4");
1101 BIO_printf(bio_err, "\n");
1103 # ifndef OPENSSL_NO_RSA
1104 BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
1107 # ifndef OPENSSL_NO_DSA
1108 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
1110 # ifndef OPENSSL_NO_ECDSA
1111 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1112 "ecdsap256 ecdsap384 ecdsap521\n");
1114 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1116 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1117 BIO_printf(bio_err, "ecdsa\n");
1119 # ifndef OPENSSL_NO_ECDH
1120 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1121 "ecdhp256 ecdhp384 ecdhp521\n");
1123 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1125 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1126 BIO_printf(bio_err, "ecdh\n");
1129 # ifndef OPENSSL_NO_IDEA
1130 BIO_printf(bio_err, "idea ");
1132 # ifndef OPENSSL_NO_SEED
1133 BIO_printf(bio_err, "seed ");
1135 # ifndef OPENSSL_NO_RC2
1136 BIO_printf(bio_err, "rc2 ");
1138 # ifndef OPENSSL_NO_DES
1139 BIO_printf(bio_err, "des ");
1141 # ifndef OPENSSL_NO_AES
1142 BIO_printf(bio_err, "aes ");
1144 # ifndef OPENSSL_NO_CAMELLIA
1145 BIO_printf(bio_err, "camellia ");
1147 # ifndef OPENSSL_NO_RSA
1148 BIO_printf(bio_err, "rsa ");
1150 # ifndef OPENSSL_NO_BF
1151 BIO_printf(bio_err, "blowfish");
1153 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1154 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1155 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1156 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1157 BIO_printf(bio_err, "\n");
1160 BIO_printf(bio_err, "\n");
1161 BIO_printf(bio_err, "Available options:\n");
1162 # if defined(TIMES) || defined(USE_TOD)
1163 BIO_printf(bio_err, "-elapsed "
1164 "measure time in real time instead of CPU user time.\n");
1166 # ifndef OPENSSL_NO_ENGINE
1169 "use engine e, possibly a hardware device.\n");
1171 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1174 "time decryption instead of encryption (only EVP).\n");
1177 "produce machine readable output.\n");
1180 "-multi n " "run n benchmarks in parallel.\n");
1190 if (multi && do_multi(multi))
1195 for (i = 0; i < ALGOR_NUM; i++) {
1199 for (i = 0; i < RSA_NUM; i++)
1201 for (i = 0; i < DSA_NUM; i++)
1203 # ifndef OPENSSL_NO_ECDSA
1204 for (i = 0; i < EC_NUM; i++)
1207 # ifndef OPENSSL_NO_ECDH
1208 for (i = 0; i < EC_NUM; i++)
1212 for (i = 0; i < ALGOR_NUM; i++)
1216 if (usertime == 0 && !mr)
1218 "You have chosen to measure elapsed time "
1219 "instead of user CPU time.\n");
1221 # ifndef OPENSSL_NO_RSA
1222 for (i = 0; i < RSA_NUM; i++) {
1223 const unsigned char *p;
1226 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1227 if (rsa_key[i] == NULL) {
1228 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1236 : "Loaded RSA key, %d bit modulus and e= 0x",
1237 BN_num_bits(rsa_key[i]->n));
1238 BN_print(bio_err, rsa_key[i]->e);
1239 BIO_printf(bio_err, "\n");
1245 # ifndef OPENSSL_NO_DSA
1246 dsa_key[0] = get_dsa512();
1247 dsa_key[1] = get_dsa1024();
1248 dsa_key[2] = get_dsa2048();
1251 # ifndef OPENSSL_NO_DES
1252 DES_set_key_unchecked(&key, &sch);
1253 DES_set_key_unchecked(&key2, &sch2);
1254 DES_set_key_unchecked(&key3, &sch3);
1256 # ifndef OPENSSL_NO_AES
1257 AES_set_encrypt_key(key16, 128, &aes_ks1);
1258 AES_set_encrypt_key(key24, 192, &aes_ks2);
1259 AES_set_encrypt_key(key32, 256, &aes_ks3);
1261 # ifndef OPENSSL_NO_CAMELLIA
1262 Camellia_set_key(key16, 128, &camellia_ks1);
1263 Camellia_set_key(ckey24, 192, &camellia_ks2);
1264 Camellia_set_key(ckey32, 256, &camellia_ks3);
1266 # ifndef OPENSSL_NO_IDEA
1267 idea_set_encrypt_key(key16, &idea_ks);
1269 # ifndef OPENSSL_NO_SEED
1270 SEED_set_key(key16, &seed_ks);
1272 # ifndef OPENSSL_NO_RC4
1273 RC4_set_key(&rc4_ks, 16, key16);
1275 # ifndef OPENSSL_NO_RC2
1276 RC2_set_key(&rc2_ks, 16, key16, 128);
1278 # ifndef OPENSSL_NO_RC5
1279 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1281 # ifndef OPENSSL_NO_BF
1282 BF_set_key(&bf_ks, 16, key16);
1284 # ifndef OPENSSL_NO_CAST
1285 CAST_set_key(&cast_ks, 16, key16);
1287 # ifndef OPENSSL_NO_RSA
1288 memset(rsa_c, 0, sizeof(rsa_c));
1291 # ifndef OPENSSL_NO_DES
1292 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1298 for (it = count; it; it--)
1299 DES_ecb_encrypt((DES_cblock *)buf,
1300 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1304 c[D_MD2][0] = count / 10;
1305 c[D_MDC2][0] = count / 10;
1306 c[D_MD4][0] = count;
1307 c[D_MD5][0] = count;
1308 c[D_HMAC][0] = count;
1309 c[D_SHA1][0] = count;
1310 c[D_RMD160][0] = count;
1311 c[D_RC4][0] = count * 5;
1312 c[D_CBC_DES][0] = count;
1313 c[D_EDE3_DES][0] = count / 3;
1314 c[D_CBC_IDEA][0] = count;
1315 c[D_CBC_SEED][0] = count;
1316 c[D_CBC_RC2][0] = count;
1317 c[D_CBC_RC5][0] = count;
1318 c[D_CBC_BF][0] = count;
1319 c[D_CBC_CAST][0] = count;
1320 c[D_CBC_128_AES][0] = count;
1321 c[D_CBC_192_AES][0] = count;
1322 c[D_CBC_256_AES][0] = count;
1323 c[D_CBC_128_CML][0] = count;
1324 c[D_CBC_192_CML][0] = count;
1325 c[D_CBC_256_CML][0] = count;
1326 c[D_SHA256][0] = count;
1327 c[D_SHA512][0] = count;
1328 c[D_WHIRLPOOL][0] = count;
1329 c[D_IGE_128_AES][0] = count;
1330 c[D_IGE_192_AES][0] = count;
1331 c[D_IGE_256_AES][0] = count;
1333 for (i = 1; i < SIZE_NUM; i++) {
1334 c[D_MD2][i] = c[D_MD2][0] * 4 * lengths[0] / lengths[i];
1335 c[D_MDC2][i] = c[D_MDC2][0] * 4 * lengths[0] / lengths[i];
1336 c[D_MD4][i] = c[D_MD4][0] * 4 * lengths[0] / lengths[i];
1337 c[D_MD5][i] = c[D_MD5][0] * 4 * lengths[0] / lengths[i];
1338 c[D_HMAC][i] = c[D_HMAC][0] * 4 * lengths[0] / lengths[i];
1339 c[D_SHA1][i] = c[D_SHA1][0] * 4 * lengths[0] / lengths[i];
1340 c[D_RMD160][i] = c[D_RMD160][0] * 4 * lengths[0] / lengths[i];
1341 c[D_SHA256][i] = c[D_SHA256][0] * 4 * lengths[0] / lengths[i];
1342 c[D_SHA512][i] = c[D_SHA512][0] * 4 * lengths[0] / lengths[i];
1343 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * lengths[0] / lengths[i];
1345 for (i = 1; i < SIZE_NUM; i++) {
1348 l0 = (long)lengths[i - 1];
1349 l1 = (long)lengths[i];
1350 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1351 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1352 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1353 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1354 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1355 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1356 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1357 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1358 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1359 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1360 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1361 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1362 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1363 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1364 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1365 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1366 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1367 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1369 # ifndef OPENSSL_NO_RSA
1370 rsa_c[R_RSA_512][0] = count / 2000;
1371 rsa_c[R_RSA_512][1] = count / 400;
1372 for (i = 1; i < RSA_NUM; i++) {
1373 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1374 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1375 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1378 if (rsa_c[i][0] == 0) {
1386 # ifndef OPENSSL_NO_DSA
1387 dsa_c[R_DSA_512][0] = count / 1000;
1388 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1389 for (i = 1; i < DSA_NUM; i++) {
1390 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1391 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1392 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1395 if (dsa_c[i] == 0) {
1403 # ifndef OPENSSL_NO_ECDSA
1404 ecdsa_c[R_EC_P160][0] = count / 1000;
1405 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1406 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1407 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1408 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1409 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1412 if (ecdsa_c[i] == 0) {
1418 ecdsa_c[R_EC_K163][0] = count / 1000;
1419 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1420 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1421 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1422 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1423 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1426 if (ecdsa_c[i] == 0) {
1432 ecdsa_c[R_EC_B163][0] = count / 1000;
1433 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1434 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1435 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1436 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1437 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1440 if (ecdsa_c[i] == 0) {
1448 # ifndef OPENSSL_NO_ECDH
1449 ecdh_c[R_EC_P160][0] = count / 1000;
1450 ecdh_c[R_EC_P160][1] = count / 1000;
1451 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1452 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1453 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1454 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1457 if (ecdh_c[i] == 0) {
1463 ecdh_c[R_EC_K163][0] = count / 1000;
1464 ecdh_c[R_EC_K163][1] = count / 1000;
1465 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1466 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1467 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1468 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1471 if (ecdh_c[i] == 0) {
1477 ecdh_c[R_EC_B163][0] = count / 1000;
1478 ecdh_c[R_EC_B163][1] = count / 1000;
1479 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1480 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1481 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1482 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1485 if (ecdh_c[i] == 0) {
1493 # define COND(d) (count < (d))
1494 # define COUNT(d) (d)
1496 /* not worth fixing */
1497 # error "You cannot disable DES on systems without SIGALRM."
1498 # endif /* OPENSSL_NO_DES */
1500 # define COND(c) (run)
1501 # define COUNT(d) (count)
1503 signal(SIGALRM, sig_done);
1505 # endif /* SIGALRM */
1507 # ifndef OPENSSL_NO_MD2
1509 for (j = 0; j < SIZE_NUM; j++) {
1510 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1512 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1513 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1516 print_result(D_MD2, j, count, d);
1520 # ifndef OPENSSL_NO_MDC2
1522 for (j = 0; j < SIZE_NUM; j++) {
1523 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1525 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1526 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1529 print_result(D_MDC2, j, count, d);
1534 # ifndef OPENSSL_NO_MD4
1536 for (j = 0; j < SIZE_NUM; j++) {
1537 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1539 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1540 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1541 NULL, EVP_md4(), NULL);
1543 print_result(D_MD4, j, count, d);
1548 # ifndef OPENSSL_NO_MD5
1550 for (j = 0; j < SIZE_NUM; j++) {
1551 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1553 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1554 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md5[0]),
1555 NULL, EVP_get_digestbyname("md5"), NULL);
1557 print_result(D_MD5, j, count, d);
1562 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1566 HMAC_CTX_init(&hctx);
1567 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1568 16, EVP_md5(), NULL);
1570 for (j = 0; j < SIZE_NUM; j++) {
1571 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1573 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1574 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1575 HMAC_Update(&hctx, buf, lengths[j]);
1576 HMAC_Final(&hctx, &(hmac[0]), NULL);
1579 print_result(D_HMAC, j, count, d);
1581 HMAC_CTX_cleanup(&hctx);
1584 # ifndef OPENSSL_NO_SHA
1586 for (j = 0; j < SIZE_NUM; j++) {
1587 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1589 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1590 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
1593 print_result(D_SHA1, j, count, d);
1596 # ifndef OPENSSL_NO_SHA256
1597 if (doit[D_SHA256]) {
1598 for (j = 0; j < SIZE_NUM; j++) {
1599 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1601 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1602 SHA256(buf, lengths[j], sha256);
1604 print_result(D_SHA256, j, count, d);
1609 # ifndef OPENSSL_NO_SHA512
1610 if (doit[D_SHA512]) {
1611 for (j = 0; j < SIZE_NUM; j++) {
1612 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1614 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1615 SHA512(buf, lengths[j], sha512);
1617 print_result(D_SHA512, j, count, d);
1623 # ifndef OPENSSL_NO_WHIRLPOOL
1624 if (doit[D_WHIRLPOOL]) {
1625 for (j = 0; j < SIZE_NUM; j++) {
1626 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1628 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1629 WHIRLPOOL(buf, lengths[j], whirlpool);
1631 print_result(D_WHIRLPOOL, j, count, d);
1636 # ifndef OPENSSL_NO_RIPEMD
1637 if (doit[D_RMD160]) {
1638 for (j = 0; j < SIZE_NUM; j++) {
1639 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1641 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1642 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1643 EVP_ripemd160(), NULL);
1645 print_result(D_RMD160, j, count, d);
1649 # ifndef OPENSSL_NO_RC4
1651 for (j = 0; j < SIZE_NUM; j++) {
1652 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1654 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1655 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1657 print_result(D_RC4, j, count, d);
1661 # ifndef OPENSSL_NO_DES
1662 if (doit[D_CBC_DES]) {
1663 for (j = 0; j < SIZE_NUM; j++) {
1664 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1666 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1667 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1668 &DES_iv, DES_ENCRYPT);
1670 print_result(D_CBC_DES, j, count, d);
1674 if (doit[D_EDE3_DES]) {
1675 for (j = 0; j < SIZE_NUM; j++) {
1676 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1678 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1679 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1681 &DES_iv, DES_ENCRYPT);
1683 print_result(D_EDE3_DES, j, count, d);
1687 # ifndef OPENSSL_NO_AES
1688 if (doit[D_CBC_128_AES]) {
1689 for (j = 0; j < SIZE_NUM; j++) {
1690 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1693 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1694 AES_cbc_encrypt(buf, buf,
1695 (unsigned long)lengths[j], &aes_ks1,
1698 print_result(D_CBC_128_AES, j, count, d);
1701 if (doit[D_CBC_192_AES]) {
1702 for (j = 0; j < SIZE_NUM; j++) {
1703 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1706 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1707 AES_cbc_encrypt(buf, buf,
1708 (unsigned long)lengths[j], &aes_ks2,
1711 print_result(D_CBC_192_AES, j, count, d);
1714 if (doit[D_CBC_256_AES]) {
1715 for (j = 0; j < SIZE_NUM; j++) {
1716 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1719 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1720 AES_cbc_encrypt(buf, buf,
1721 (unsigned long)lengths[j], &aes_ks3,
1724 print_result(D_CBC_256_AES, j, count, d);
1728 if (doit[D_IGE_128_AES]) {
1729 for (j = 0; j < SIZE_NUM; j++) {
1730 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1733 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1734 AES_ige_encrypt(buf, buf2,
1735 (unsigned long)lengths[j], &aes_ks1,
1738 print_result(D_IGE_128_AES, j, count, d);
1741 if (doit[D_IGE_192_AES]) {
1742 for (j = 0; j < SIZE_NUM; j++) {
1743 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1746 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1747 AES_ige_encrypt(buf, buf2,
1748 (unsigned long)lengths[j], &aes_ks2,
1751 print_result(D_IGE_192_AES, j, count, d);
1754 if (doit[D_IGE_256_AES]) {
1755 for (j = 0; j < SIZE_NUM; j++) {
1756 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1759 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1760 AES_ige_encrypt(buf, buf2,
1761 (unsigned long)lengths[j], &aes_ks3,
1764 print_result(D_IGE_256_AES, j, count, d);
1768 # ifndef OPENSSL_NO_CAMELLIA
1769 if (doit[D_CBC_128_CML]) {
1770 for (j = 0; j < SIZE_NUM; j++) {
1771 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1774 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1775 Camellia_cbc_encrypt(buf, buf,
1776 (unsigned long)lengths[j], &camellia_ks1,
1777 iv, CAMELLIA_ENCRYPT);
1779 print_result(D_CBC_128_CML, j, count, d);
1782 if (doit[D_CBC_192_CML]) {
1783 for (j = 0; j < SIZE_NUM; j++) {
1784 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1787 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1788 Camellia_cbc_encrypt(buf, buf,
1789 (unsigned long)lengths[j], &camellia_ks2,
1790 iv, CAMELLIA_ENCRYPT);
1792 print_result(D_CBC_192_CML, j, count, d);
1795 if (doit[D_CBC_256_CML]) {
1796 for (j = 0; j < SIZE_NUM; j++) {
1797 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1800 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1801 Camellia_cbc_encrypt(buf, buf,
1802 (unsigned long)lengths[j], &camellia_ks3,
1803 iv, CAMELLIA_ENCRYPT);
1805 print_result(D_CBC_256_CML, j, count, d);
1809 # ifndef OPENSSL_NO_IDEA
1810 if (doit[D_CBC_IDEA]) {
1811 for (j = 0; j < SIZE_NUM; j++) {
1812 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1814 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1815 idea_cbc_encrypt(buf, buf,
1816 (unsigned long)lengths[j], &idea_ks,
1819 print_result(D_CBC_IDEA, j, count, d);
1823 # ifndef OPENSSL_NO_SEED
1824 if (doit[D_CBC_SEED]) {
1825 for (j = 0; j < SIZE_NUM; j++) {
1826 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1828 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1829 SEED_cbc_encrypt(buf, buf,
1830 (unsigned long)lengths[j], &seed_ks, iv, 1);
1832 print_result(D_CBC_SEED, j, count, d);
1836 # ifndef OPENSSL_NO_RC2
1837 if (doit[D_CBC_RC2]) {
1838 for (j = 0; j < SIZE_NUM; j++) {
1839 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1841 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1842 RC2_cbc_encrypt(buf, buf,
1843 (unsigned long)lengths[j], &rc2_ks,
1846 print_result(D_CBC_RC2, j, count, d);
1850 # ifndef OPENSSL_NO_RC5
1851 if (doit[D_CBC_RC5]) {
1852 for (j = 0; j < SIZE_NUM; j++) {
1853 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1855 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1856 RC5_32_cbc_encrypt(buf, buf,
1857 (unsigned long)lengths[j], &rc5_ks,
1860 print_result(D_CBC_RC5, j, count, d);
1864 # ifndef OPENSSL_NO_BF
1865 if (doit[D_CBC_BF]) {
1866 for (j = 0; j < SIZE_NUM; j++) {
1867 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1869 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1870 BF_cbc_encrypt(buf, buf,
1871 (unsigned long)lengths[j], &bf_ks,
1874 print_result(D_CBC_BF, j, count, d);
1878 # ifndef OPENSSL_NO_CAST
1879 if (doit[D_CBC_CAST]) {
1880 for (j = 0; j < SIZE_NUM; j++) {
1881 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1883 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1884 CAST_cbc_encrypt(buf, buf,
1885 (unsigned long)lengths[j], &cast_ks,
1888 print_result(D_CBC_CAST, j, count, d);
1894 for (j = 0; j < SIZE_NUM; j++) {
1899 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1901 * -O3 -fschedule-insns messes up an optimization here!
1902 * names[D_EVP] somehow becomes NULL
1904 print_message(names[D_EVP], save_count, lengths[j]);
1906 EVP_CIPHER_CTX_init(&ctx);
1908 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1910 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1911 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1915 for (count = 0, run = 1;
1916 COND(save_count * 4 * lengths[0] / lengths[j]);
1918 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1920 for (count = 0, run = 1;
1921 COND(save_count * 4 * lengths[0] / lengths[j]);
1923 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1925 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1927 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1929 EVP_CIPHER_CTX_cleanup(&ctx);
1932 names[D_EVP] = OBJ_nid2ln(evp_md->type);
1933 print_message(names[D_EVP], save_count, lengths[j]);
1936 for (count = 0, run = 1;
1937 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1938 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1942 print_result(D_EVP, j, count, d);
1946 RAND_pseudo_bytes(buf, 36);
1947 # ifndef OPENSSL_NO_RSA
1948 for (j = 0; j < RSA_NUM; j++) {
1952 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1955 "RSA sign failure. No RSA sign will be done.\n");
1956 ERR_print_errors(bio_err);
1959 pkey_print_message("private", "rsa",
1960 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
1961 /* RSA_blinding_on(rsa_key[j],NULL); */
1963 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1964 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1965 &rsa_num, rsa_key[j]);
1967 BIO_printf(bio_err, "RSA sign failure\n");
1968 ERR_print_errors(bio_err);
1975 mr ? "+R1:%ld:%d:%.2f\n"
1976 : "%ld %d bit private RSA's in %.2fs\n",
1977 count, rsa_bits[j], d);
1978 rsa_results[j][0] = d / (double)count;
1983 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1986 "RSA verify failure. No RSA verify will be done.\n");
1987 ERR_print_errors(bio_err);
1990 pkey_print_message("public", "rsa",
1991 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
1993 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1994 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1995 rsa_num, rsa_key[j]);
1997 BIO_printf(bio_err, "RSA verify failure\n");
1998 ERR_print_errors(bio_err);
2005 mr ? "+R2:%ld:%d:%.2f\n"
2006 : "%ld %d bit public RSA's in %.2fs\n",
2007 count, rsa_bits[j], d);
2008 rsa_results[j][1] = d / (double)count;
2012 if (rsa_count <= 1) {
2013 /* if longer than 10s, don't do any more */
2014 for (j++; j < RSA_NUM; j++)
2020 RAND_pseudo_bytes(buf, 20);
2021 # ifndef OPENSSL_NO_DSA
2022 if (RAND_status() != 1) {
2023 RAND_seed(rnd_seed, sizeof rnd_seed);
2026 for (j = 0; j < DSA_NUM; j++) {
2033 /* DSA_generate_key(dsa_key[j]); */
2034 /* DSA_sign_setup(dsa_key[j],NULL); */
2035 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2038 "DSA sign failure. No DSA sign will be done.\n");
2039 ERR_print_errors(bio_err);
2042 pkey_print_message("sign", "dsa",
2043 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2045 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2046 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2048 BIO_printf(bio_err, "DSA sign failure\n");
2049 ERR_print_errors(bio_err);
2056 mr ? "+R3:%ld:%d:%.2f\n"
2057 : "%ld %d bit DSA signs in %.2fs\n",
2058 count, dsa_bits[j], d);
2059 dsa_results[j][0] = d / (double)count;
2063 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2066 "DSA verify failure. No DSA verify will be done.\n");
2067 ERR_print_errors(bio_err);
2070 pkey_print_message("verify", "dsa",
2071 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2073 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2074 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2076 BIO_printf(bio_err, "DSA verify failure\n");
2077 ERR_print_errors(bio_err);
2084 mr ? "+R4:%ld:%d:%.2f\n"
2085 : "%ld %d bit DSA verify in %.2fs\n",
2086 count, dsa_bits[j], d);
2087 dsa_results[j][1] = d / (double)count;
2090 if (rsa_count <= 1) {
2091 /* if longer than 10s, don't do any more */
2092 for (j++; j < DSA_NUM; j++)
2100 # ifndef OPENSSL_NO_ECDSA
2101 if (RAND_status() != 1) {
2102 RAND_seed(rnd_seed, sizeof rnd_seed);
2105 for (j = 0; j < EC_NUM; j++) {
2109 continue; /* Ignore Curve */
2110 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2111 if (ecdsa[j] == NULL) {
2112 BIO_printf(bio_err, "ECDSA failure.\n");
2113 ERR_print_errors(bio_err);
2117 EC_KEY_precompute_mult(ecdsa[j], NULL);
2119 /* Perform ECDSA signature test */
2120 EC_KEY_generate_key(ecdsa[j]);
2121 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2124 "ECDSA sign failure. No ECDSA sign will be done.\n");
2125 ERR_print_errors(bio_err);
2128 pkey_print_message("sign", "ecdsa",
2130 test_curves_bits[j], ECDSA_SECONDS);
2133 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2134 ret = ECDSA_sign(0, buf, 20,
2135 ecdsasig, &ecdsasiglen, ecdsa[j]);
2137 BIO_printf(bio_err, "ECDSA sign failure\n");
2138 ERR_print_errors(bio_err);
2146 mr ? "+R5:%ld:%d:%.2f\n" :
2147 "%ld %d bit ECDSA signs in %.2fs \n",
2148 count, test_curves_bits[j], d);
2149 ecdsa_results[j][0] = d / (double)count;
2153 /* Perform ECDSA verification test */
2154 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2157 "ECDSA verify failure. No ECDSA verify will be done.\n");
2158 ERR_print_errors(bio_err);
2161 pkey_print_message("verify", "ecdsa",
2163 test_curves_bits[j], ECDSA_SECONDS);
2165 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2167 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2170 BIO_printf(bio_err, "ECDSA verify failure\n");
2171 ERR_print_errors(bio_err);
2178 mr ? "+R6:%ld:%d:%.2f\n"
2179 : "%ld %d bit ECDSA verify in %.2fs\n",
2180 count, test_curves_bits[j], d);
2181 ecdsa_results[j][1] = d / (double)count;
2184 if (rsa_count <= 1) {
2185 /* if longer than 10s, don't do any more */
2186 for (j++; j < EC_NUM; j++)
2195 # ifndef OPENSSL_NO_ECDH
2196 if (RAND_status() != 1) {
2197 RAND_seed(rnd_seed, sizeof rnd_seed);
2200 for (j = 0; j < EC_NUM; j++) {
2203 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2204 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2205 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2206 BIO_printf(bio_err, "ECDH failure.\n");
2207 ERR_print_errors(bio_err);
2210 /* generate two ECDH key pairs */
2211 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2212 !EC_KEY_generate_key(ecdh_b[j])) {
2213 BIO_printf(bio_err, "ECDH key generation failure.\n");
2214 ERR_print_errors(bio_err);
2218 * If field size is not more than 24 octets, then use SHA-1
2219 * hash of result; otherwise, use result (see section 4.8 of
2220 * draft-ietf-tls-ecc-03.txt).
2222 int field_size, outlen;
2223 void *(*kdf) (const void *in, size_t inlen, void *out,
2226 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2227 if (field_size <= 24 * 8) {
2228 outlen = KDF1_SHA1_len;
2231 outlen = (field_size + 7) / 8;
2235 ECDH_compute_key(secret_a, outlen,
2236 EC_KEY_get0_public_key(ecdh_b[j]),
2239 ECDH_compute_key(secret_b, outlen,
2240 EC_KEY_get0_public_key(ecdh_a[j]),
2242 if (secret_size_a != secret_size_b)
2247 for (secret_idx = 0; (secret_idx < secret_size_a)
2248 && (ecdh_checks == 1); secret_idx++) {
2249 if (secret_a[secret_idx] != secret_b[secret_idx])
2253 if (ecdh_checks == 0) {
2254 BIO_printf(bio_err, "ECDH computations don't match.\n");
2255 ERR_print_errors(bio_err);
2259 pkey_print_message("", "ecdh",
2261 test_curves_bits[j], ECDH_SECONDS);
2263 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2264 ECDH_compute_key(secret_a, outlen,
2265 EC_KEY_get0_public_key(ecdh_b[j]),
2270 mr ? "+R7:%ld:%d:%.2f\n" :
2271 "%ld %d-bit ECDH ops in %.2fs\n", count,
2272 test_curves_bits[j], d);
2273 ecdh_results[j][0] = d / (double)count;
2278 if (rsa_count <= 1) {
2279 /* if longer than 10s, don't do any more */
2280 for (j++; j < EC_NUM; j++)
2291 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2292 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2294 printf("%s ", BN_options());
2295 # ifndef OPENSSL_NO_MD2
2296 printf("%s ", MD2_options());
2298 # ifndef OPENSSL_NO_RC4
2299 printf("%s ", RC4_options());
2301 # ifndef OPENSSL_NO_DES
2302 printf("%s ", DES_options());
2304 # ifndef OPENSSL_NO_AES
2305 printf("%s ", AES_options());
2307 # ifndef OPENSSL_NO_IDEA
2308 printf("%s ", idea_options());
2310 # ifndef OPENSSL_NO_BF
2311 printf("%s ", BF_options());
2313 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2318 fprintf(stdout, "+H");
2321 "The 'numbers' are in 1000s of bytes per second processed.\n");
2322 fprintf(stdout, "type ");
2324 for (j = 0; j < SIZE_NUM; j++)
2325 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2326 fprintf(stdout, "\n");
2329 for (k = 0; k < ALGOR_NUM; k++) {
2333 fprintf(stdout, "+F:%d:%s", k, names[k]);
2335 fprintf(stdout, "%-13s", names[k]);
2336 for (j = 0; j < SIZE_NUM; j++) {
2337 if (results[k][j] > 10000 && !mr)
2338 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2340 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2342 fprintf(stdout, "\n");
2344 # ifndef OPENSSL_NO_RSA
2346 for (k = 0; k < RSA_NUM; k++) {
2350 printf("%18ssign verify sign/s verify/s\n", " ");
2354 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2355 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2357 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2358 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2359 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2362 # ifndef OPENSSL_NO_DSA
2364 for (k = 0; k < DSA_NUM; k++) {
2368 printf("%18ssign verify sign/s verify/s\n", " ");
2372 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2373 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2375 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2376 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2377 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2380 # ifndef OPENSSL_NO_ECDSA
2382 for (k = 0; k < EC_NUM; k++) {
2386 printf("%30ssign verify sign/s verify/s\n", " ");
2391 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2392 k, test_curves_bits[k],
2393 ecdsa_results[k][0], ecdsa_results[k][1]);
2396 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2397 test_curves_bits[k],
2398 test_curves_names[k],
2399 ecdsa_results[k][0], ecdsa_results[k][1],
2400 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2404 # ifndef OPENSSL_NO_ECDH
2406 for (k = 0; k < EC_NUM; k++) {
2410 printf("%30sop op/s\n", " ");
2414 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2415 k, test_curves_bits[k],
2416 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2419 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2420 test_curves_bits[k],
2421 test_curves_names[k],
2422 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2429 ERR_print_errors(bio_err);
2434 # ifndef OPENSSL_NO_RSA
2435 for (i = 0; i < RSA_NUM; i++)
2436 if (rsa_key[i] != NULL)
2437 RSA_free(rsa_key[i]);
2439 # ifndef OPENSSL_NO_DSA
2440 for (i = 0; i < DSA_NUM; i++)
2441 if (dsa_key[i] != NULL)
2442 DSA_free(dsa_key[i]);
2445 # ifndef OPENSSL_NO_ECDSA
2446 for (i = 0; i < EC_NUM; i++)
2447 if (ecdsa[i] != NULL)
2448 EC_KEY_free(ecdsa[i]);
2450 # ifndef OPENSSL_NO_ECDH
2451 for (i = 0; i < EC_NUM; i++) {
2452 if (ecdh_a[i] != NULL)
2453 EC_KEY_free(ecdh_a[i]);
2454 if (ecdh_b[i] != NULL)
2455 EC_KEY_free(ecdh_b[i]);
2463 static void print_message(const char *s, long num, int length)
2467 mr ? "+DT:%s:%d:%d\n"
2468 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2469 (void)BIO_flush(bio_err);
2473 mr ? "+DN:%s:%ld:%d\n"
2474 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2475 (void)BIO_flush(bio_err);
2482 static void pkey_print_message(const char *str, const char *str2, long num,
2487 mr ? "+DTP:%d:%s:%s:%d\n"
2488 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2489 (void)BIO_flush(bio_err);
2493 mr ? "+DNP:%ld:%d:%s:%s\n"
2494 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2495 (void)BIO_flush(bio_err);
2502 static void print_result(int alg, int run_no, int count, double time_used)
2505 mr ? "+R:%d:%s:%f\n"
2506 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2507 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2511 static char *sstrsep(char **string, const char *delim)
2514 char *token = *string;
2519 memset(isdelim, 0, sizeof isdelim);
2523 isdelim[(unsigned char)(*delim)] = 1;
2527 while (!isdelim[(unsigned char)(**string)]) {
2539 static int do_multi(int multi)
2544 static char sep[] = ":";
2546 fds = malloc(multi * sizeof *fds);
2547 for (n = 0; n < multi; ++n) {
2548 if (pipe(fd) == -1) {
2549 fprintf(stderr, "pipe failure\n");
2560 if (dup(fd[1]) == -1) {
2561 fprintf(stderr, "dup failed\n");
2570 printf("Forked child %d\n", n);
2573 /* for now, assume the pipe is long enough to take all the output */
2574 for (n = 0; n < multi; ++n) {
2579 f = fdopen(fds[n], "r");
2580 while (fgets(buf, sizeof buf, f)) {
2581 p = strchr(buf, '\n');
2584 if (buf[0] != '+') {
2585 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2589 printf("Got: %s from %d\n", buf, n);
2590 if (!strncmp(buf, "+F:", 3)) {
2595 alg = atoi(sstrsep(&p, sep));
2597 for (j = 0; j < SIZE_NUM; ++j)
2598 results[alg][j] += atof(sstrsep(&p, sep));
2599 } else if (!strncmp(buf, "+F2:", 4)) {
2604 k = atoi(sstrsep(&p, sep));
2607 d = atof(sstrsep(&p, sep));
2609 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2611 rsa_results[k][0] = d;
2613 d = atof(sstrsep(&p, sep));
2615 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2617 rsa_results[k][1] = d;
2619 # ifndef OPENSSL_NO_DSA
2620 else if (!strncmp(buf, "+F3:", 4)) {
2625 k = atoi(sstrsep(&p, sep));
2628 d = atof(sstrsep(&p, sep));
2630 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2632 dsa_results[k][0] = d;
2634 d = atof(sstrsep(&p, sep));
2636 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2638 dsa_results[k][1] = d;
2641 # ifndef OPENSSL_NO_ECDSA
2642 else if (!strncmp(buf, "+F4:", 4)) {
2647 k = atoi(sstrsep(&p, sep));
2650 d = atof(sstrsep(&p, sep));
2652 ecdsa_results[k][0] =
2653 1 / (1 / ecdsa_results[k][0] + 1 / d);
2655 ecdsa_results[k][0] = d;
2657 d = atof(sstrsep(&p, sep));
2659 ecdsa_results[k][1] =
2660 1 / (1 / ecdsa_results[k][1] + 1 / d);
2662 ecdsa_results[k][1] = d;
2666 # ifndef OPENSSL_NO_ECDH
2667 else if (!strncmp(buf, "+F5:", 4)) {
2672 k = atoi(sstrsep(&p, sep));
2675 d = atof(sstrsep(&p, sep));
2677 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2679 ecdh_results[k][0] = d;
2684 else if (!strncmp(buf, "+H:", 3)) {
2686 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);