1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
4 * This package is an SSL implementation written
5 * by Eric Young (eay@cryptsoft.com).
6 * The implementation was written so as to conform with Netscapes SSL.
8 * This library is free for commercial and non-commercial use as long as
9 * the following conditions are aheared to. The following conditions
10 * apply to all code found in this distribution, be it the RC4, RSA,
11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12 * included with this distribution is covered by the same copyright terms
13 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * Copyright remains Eric Young's, and as such any Copyright notices in
16 * the code are not to be removed.
17 * If this package is used in a product, Eric Young should be given attribution
18 * as the author of the parts of the library used.
19 * This can be in the form of a textual message at program startup or
20 * in documentation (online or textual) provided with the package.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
25 * 1. Redistributions of source code must retain the copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * "This product includes cryptographic software written by
33 * Eric Young (eay@cryptsoft.com)"
34 * The word 'cryptographic' can be left out if the rouines from the library
35 * being used are not cryptographic related :-).
36 * 4. If you include any Windows specific code (or a derivative thereof) from
37 * the apps directory (application code) you must include an acknowledgement:
38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * The licence and distribution terms for any publically available version or
53 * derivative of this code cannot be changed. i.e. this code cannot simply be
54 * copied and put under another distribution licence
55 * [including the GNU Public Licence.]
57 /* ====================================================================
58 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * Portions of the attached software ("Contribution") are developed by
61 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63 * The Contribution is licensed pursuant to the OpenSSL open source
64 * license provided above.
66 * The ECDH and ECDSA speed test software is originally written by
67 * Sumit Gupta of Sun Microsystems Laboratories.
73 #define PRIME_SECONDS 10
74 #define RSA_SECONDS 10
75 #define DSA_SECONDS 10
76 #define ECDSA_SECONDS 10
77 #define ECDH_SECONDS 10
84 #include <openssl/crypto.h>
85 #include <openssl/rand.h>
86 #include <openssl/err.h>
87 #include <openssl/evp.h>
88 #include <openssl/objects.h>
89 #if !defined(OPENSSL_SYS_MSDOS)
90 # include OPENSSL_UNISTD
93 #ifndef OPENSSL_SYS_NETWARE
101 #include <openssl/bn.h>
102 #ifndef OPENSSL_NO_DES
103 # include <openssl/des.h>
105 #ifndef OPENSSL_NO_AES
106 # include <openssl/aes.h>
108 #ifndef OPENSSL_NO_CAMELLIA
109 # include <openssl/camellia.h>
111 #ifndef OPENSSL_NO_MD2
112 # include <openssl/md2.h>
114 #ifndef OPENSSL_NO_MDC2
115 # include <openssl/mdc2.h>
117 #ifndef OPENSSL_NO_MD4
118 # include <openssl/md4.h>
120 #ifndef OPENSSL_NO_MD5
121 # include <openssl/md5.h>
123 #include <openssl/hmac.h>
124 #include <openssl/evp.h>
125 #include <openssl/sha.h>
126 #ifndef OPENSSL_NO_RMD160
127 # include <openssl/ripemd.h>
129 #ifndef OPENSSL_NO_WHIRLPOOL
130 # include <openssl/whrlpool.h>
132 #ifndef OPENSSL_NO_RC4
133 # include <openssl/rc4.h>
135 #ifndef OPENSSL_NO_RC5
136 # include <openssl/rc5.h>
138 #ifndef OPENSSL_NO_RC2
139 # include <openssl/rc2.h>
141 #ifndef OPENSSL_NO_IDEA
142 # include <openssl/idea.h>
144 #ifndef OPENSSL_NO_SEED
145 # include <openssl/seed.h>
147 #ifndef OPENSSL_NO_BF
148 # include <openssl/blowfish.h>
150 #ifndef OPENSSL_NO_CAST
151 # include <openssl/cast.h>
153 #ifndef OPENSSL_NO_RSA
154 # include <openssl/rsa.h>
155 # include "./testrsa.h"
157 #include <openssl/x509.h>
158 #ifndef OPENSSL_NO_DSA
159 # include <openssl/dsa.h>
160 # include "./testdsa.h"
162 #ifndef OPENSSL_NO_EC
163 # include <openssl/ec.h>
165 #include <openssl/modes.h>
167 #include <openssl/bn.h>
170 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
184 #define BUFSIZE (1024*8+1)
185 #define MAX_MISALIGNMENT 63
187 static volatile int run = 0;
190 static int usertime = 1;
192 static double Time_F(int s);
193 static void print_message(const char *s, long num, int length);
194 static void pkey_print_message(const char *str, const char *str2,
195 long num, int bits, int sec);
196 static void print_result(int alg, int run_no, int count, double time_used);
198 static int do_multi(int multi);
208 #define MAX_ECDH_SIZE 256
211 static const char *names[ALGOR_NUM] = {
212 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
213 "des cbc", "des ede3", "idea cbc", "seed cbc",
214 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
215 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
216 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
217 "evp", "sha256", "sha512", "whirlpool",
218 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
221 static double results[ALGOR_NUM][SIZE_NUM];
222 static int lengths[SIZE_NUM] = {
223 16, 64, 256, 1024, 8 * 1024
226 #ifndef OPENSSL_NO_RSA
227 static double rsa_results[RSA_NUM][2];
229 #ifndef OPENSSL_NO_DSA
230 static double dsa_results[DSA_NUM][2];
232 #ifndef OPENSSL_NO_EC
233 static double ecdsa_results[EC_NUM][2];
234 static double ecdh_results[EC_NUM][1];
237 #if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
238 static const char rnd_seed[] =
239 "string to make the random number generator think it has entropy";
240 static int rnd_fake = 0;
244 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
245 # define SIGRETTYPE void
247 # define SIGRETTYPE int
250 static SIGRETTYPE sig_done(int sig);
251 static SIGRETTYPE sig_done(int sig)
253 signal(SIGALRM, sig_done);
263 # if !defined(SIGALRM)
266 static unsigned int lapse, schlock;
267 static void alarm_win32(unsigned int secs)
272 # define alarm alarm_win32
274 static DWORD WINAPI sleepy(VOID * arg)
282 static double Time_F(int s)
289 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
291 DWORD err = GetLastError();
292 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
296 Sleep(0); /* scheduler spinlock */
297 ret = app_tminterval(s, usertime);
299 ret = app_tminterval(s, usertime);
301 TerminateThread(thr, 0);
309 static double Time_F(int s)
311 double ret = app_tminterval(s, usertime);
318 #ifndef OPENSSL_NO_EC
319 static const int KDF1_SHA1_len = 20;
320 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
323 if (*outlen < SHA_DIGEST_LENGTH)
325 *outlen = SHA_DIGEST_LENGTH;
326 return SHA1(in, inlen, out);
328 #endif /* OPENSSL_NO_EC */
330 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
332 static int found(const char *name, const OPT_PAIR * pairs, int *result)
334 for (; pairs->name; pairs++)
335 if (strcmp(name, pairs->name) == 0) {
336 *result = pairs->retval;
342 typedef enum OPTION_choice {
343 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
344 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
345 OPT_MR, OPT_MB, OPT_MISALIGN
348 OPTIONS speed_options[] = {
349 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
350 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
351 {"help", OPT_HELP, '-', "Display this summary"},
352 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
353 {"decrypt", OPT_DECRYPT, '-',
354 "Time decryption instead of encryption (only EVP)"},
355 {"mr", OPT_MR, '-', "Produce machine readable output"},
357 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
358 {"elapsed", OPT_ELAPSED, '-',
359 "Measure time in real time instead of CPU user time"},
361 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
363 #ifndef OPENSSL_NO_ENGINE
364 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
379 #define D_CBC_IDEA 10
380 #define D_CBC_SEED 11
384 #define D_CBC_CAST 15
385 #define D_CBC_128_AES 16
386 #define D_CBC_192_AES 17
387 #define D_CBC_256_AES 18
388 #define D_CBC_128_CML 19
389 #define D_CBC_192_CML 20
390 #define D_CBC_256_CML 21
394 #define D_WHIRLPOOL 25
395 #define D_IGE_128_AES 26
396 #define D_IGE_192_AES 27
397 #define D_IGE_256_AES 28
399 static OPT_PAIR doit_choices[] = {
400 #ifndef OPENSSL_NO_MD2
403 #ifndef OPENSSL_NO_MDC2
406 #ifndef OPENSSL_NO_MD4
409 #ifndef OPENSSL_NO_MD5
412 #ifndef OPENSSL_NO_MD5
416 {"sha256", D_SHA256},
417 {"sha512", D_SHA512},
418 #ifndef OPENSSL_NO_WHIRLPOOL
419 {"whirlpool", D_WHIRLPOOL},
421 #ifndef OPENSSL_NO_RMD160
422 {"ripemd", D_RMD160},
423 {"rmd160", D_RMD160},
424 {"ripemd160", D_RMD160},
426 #ifndef OPENSSL_NO_RC4
429 #ifndef OPENSSL_NO_DES
430 {"des-cbc", D_CBC_DES},
431 {"des-ede3", D_EDE3_DES},
433 #ifndef OPENSSL_NO_AES
434 {"aes-128-cbc", D_CBC_128_AES},
435 {"aes-192-cbc", D_CBC_192_AES},
436 {"aes-256-cbc", D_CBC_256_AES},
437 {"aes-128-ige", D_IGE_128_AES},
438 {"aes-192-ige", D_IGE_192_AES},
439 {"aes-256-ige", D_IGE_256_AES},
441 #ifndef OPENSSL_NO_RC2
442 {"rc2-cbc", D_CBC_RC2},
445 #ifndef OPENSSL_NO_RC5
446 {"rc5-cbc", D_CBC_RC5},
449 #ifndef OPENSSL_NO_IDEA
450 {"idea-cbc", D_CBC_IDEA},
451 {"idea", D_CBC_IDEA},
453 #ifndef OPENSSL_NO_SEED
454 {"seed-cbc", D_CBC_SEED},
455 {"seed", D_CBC_SEED},
457 #ifndef OPENSSL_NO_BF
458 {"bf-cbc", D_CBC_BF},
459 {"blowfish", D_CBC_BF},
462 #ifndef OPENSSL_NO_CAST
463 {"cast-cbc", D_CBC_CAST},
464 {"cast", D_CBC_CAST},
465 {"cast5", D_CBC_CAST},
474 static OPT_PAIR dsa_choices[] = {
475 {"dsa512", R_DSA_512},
476 {"dsa1024", R_DSA_1024},
477 {"dsa2048", R_DSA_2048},
487 #define R_RSA_15360 6
488 static OPT_PAIR rsa_choices[] = {
489 {"rsa512", R_RSA_512},
490 {"rsa1024", R_RSA_1024},
491 {"rsa2048", R_RSA_2048},
492 {"rsa3072", R_RSA_3072},
493 {"rsa4096", R_RSA_4096},
494 {"rsa7680", R_RSA_7680},
495 {"rsa15360", R_RSA_15360},
515 #ifndef OPENSSL_NO_EC
516 static OPT_PAIR ecdsa_choices[] = {
517 {"ecdsap160", R_EC_P160},
518 {"ecdsap192", R_EC_P192},
519 {"ecdsap224", R_EC_P224},
520 {"ecdsap256", R_EC_P256},
521 {"ecdsap384", R_EC_P384},
522 {"ecdsap521", R_EC_P521},
523 {"ecdsak163", R_EC_K163},
524 {"ecdsak233", R_EC_K233},
525 {"ecdsak283", R_EC_K283},
526 {"ecdsak409", R_EC_K409},
527 {"ecdsak571", R_EC_K571},
528 {"ecdsab163", R_EC_B163},
529 {"ecdsab233", R_EC_B233},
530 {"ecdsab283", R_EC_B283},
531 {"ecdsab409", R_EC_B409},
532 {"ecdsab571", R_EC_B571},
535 static OPT_PAIR ecdh_choices[] = {
536 {"ecdhp160", R_EC_P160},
537 {"ecdhp192", R_EC_P192},
538 {"ecdhp224", R_EC_P224},
539 {"ecdhp256", R_EC_P256},
540 {"ecdhp384", R_EC_P384},
541 {"ecdhp521", R_EC_P521},
542 {"ecdhk163", R_EC_K163},
543 {"ecdhk233", R_EC_K233},
544 {"ecdhk283", R_EC_K283},
545 {"ecdhk409", R_EC_K409},
546 {"ecdhk571", R_EC_K571},
547 {"ecdhb163", R_EC_B163},
548 {"ecdhb233", R_EC_B233},
549 {"ecdhb283", R_EC_B283},
550 {"ecdhb409", R_EC_B409},
551 {"ecdhb571", R_EC_B571},
556 int speed_main(int argc, char **argv)
559 const EVP_CIPHER *evp_cipher = NULL;
560 const EVP_MD *evp_md = NULL;
563 int decrypt = 0, multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
564 int dsa_doit[DSA_NUM], rsa_doit[RSA_NUM];
565 int ret = 1, i, j, k, misalign = MAX_MISALIGNMENT + 1;
566 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
567 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
568 unsigned char *buf = NULL, *buf2 = NULL;
569 unsigned char md[EVP_MAX_MD_SIZE];
573 /* What follows are the buffers and key material. */
574 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
577 #ifndef OPENSSL_NO_MD2
578 unsigned char md2[MD2_DIGEST_LENGTH];
580 #ifndef OPENSSL_NO_MDC2
581 unsigned char mdc2[MDC2_DIGEST_LENGTH];
583 #ifndef OPENSSL_NO_MD4
584 unsigned char md4[MD4_DIGEST_LENGTH];
586 #ifndef OPENSSL_NO_MD5
587 unsigned char md5[MD5_DIGEST_LENGTH];
588 unsigned char hmac[MD5_DIGEST_LENGTH];
590 unsigned char sha[SHA_DIGEST_LENGTH];
591 unsigned char sha256[SHA256_DIGEST_LENGTH];
592 unsigned char sha512[SHA512_DIGEST_LENGTH];
593 #ifndef OPENSSL_NO_WHIRLPOOL
594 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
596 #ifndef OPENSSL_NO_RMD160
597 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
599 #ifndef OPENSSL_NO_RC4
602 #ifndef OPENSSL_NO_RC5
605 #ifndef OPENSSL_NO_RC2
608 #ifndef OPENSSL_NO_IDEA
609 IDEA_KEY_SCHEDULE idea_ks;
611 #ifndef OPENSSL_NO_SEED
612 SEED_KEY_SCHEDULE seed_ks;
614 #ifndef OPENSSL_NO_BF
617 #ifndef OPENSSL_NO_CAST
620 static const unsigned char key16[16] = {
621 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
622 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
624 #ifndef OPENSSL_NO_AES
625 static const unsigned char key24[24] = {
626 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
627 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
628 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
630 static const unsigned char key32[32] = {
631 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
632 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
633 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
634 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
637 #ifndef OPENSSL_NO_CAMELLIA
638 static const unsigned char ckey24[24] = {
639 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
640 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
641 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
643 static const unsigned char ckey32[32] = {
644 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
645 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
646 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
647 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
649 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
651 #ifndef OPENSSL_NO_AES
652 # define MAX_BLOCK_SIZE 128
654 # define MAX_BLOCK_SIZE 64
656 unsigned char DES_iv[8];
657 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
658 #ifndef OPENSSL_NO_DES
659 static DES_cblock key = {
660 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
662 static DES_cblock key2 = {
663 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
665 static DES_cblock key3 = {
666 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
668 DES_key_schedule sch;
669 DES_key_schedule sch2;
670 DES_key_schedule sch3;
672 #ifndef OPENSSL_NO_AES
673 AES_KEY aes_ks1, aes_ks2, aes_ks3;
675 #ifndef OPENSSL_NO_RSA
677 RSA *rsa_key[RSA_NUM];
678 long rsa_c[RSA_NUM][2];
679 static unsigned int rsa_bits[RSA_NUM] = {
680 512, 1024, 2048, 3072, 4096, 7680, 15360
682 static unsigned char *rsa_data[RSA_NUM] = {
683 test512, test1024, test2048, test3072, test4096, test7680, test15360
685 static int rsa_data_length[RSA_NUM] = {
686 sizeof(test512), sizeof(test1024),
687 sizeof(test2048), sizeof(test3072),
688 sizeof(test4096), sizeof(test7680),
692 #ifndef OPENSSL_NO_DSA
693 DSA *dsa_key[DSA_NUM];
694 long dsa_c[DSA_NUM][2];
695 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
697 #ifndef OPENSSL_NO_EC
699 * We only test over the following curves as they are representative, To
700 * add tests over more curves, simply add the curve NID and curve name to
701 * the following arrays and increase the EC_NUM value accordingly.
703 static unsigned int test_curves[EC_NUM] = {
705 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
706 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
708 NID_sect163k1, NID_sect233k1, NID_sect283k1,
709 NID_sect409k1, NID_sect571k1, NID_sect163r2,
710 NID_sect233r1, NID_sect283r1, NID_sect409r1,
713 static const char *test_curves_names[EC_NUM] = {
715 "secp160r1", "nistp192", "nistp224",
716 "nistp256", "nistp384", "nistp521",
718 "nistk163", "nistk233", "nistk283",
719 "nistk409", "nistk571", "nistb163",
720 "nistb233", "nistb283", "nistb409",
723 static int test_curves_bits[EC_NUM] = {
732 #ifndef OPENSSL_NO_EC
733 unsigned char ecdsasig[256];
734 unsigned int ecdsasiglen;
735 EC_KEY *ecdsa[EC_NUM];
736 long ecdsa_c[EC_NUM][2];
737 int ecdsa_doit[EC_NUM];
738 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
739 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
740 int secret_size_a, secret_size_b;
743 long ecdh_c[EC_NUM][2];
744 int ecdh_doit[EC_NUM];
747 memset(results, 0, sizeof(results));
748 #ifndef OPENSSL_NO_DSA
749 memset(dsa_key, 0, sizeof(dsa_key));
751 #ifndef OPENSSL_NO_EC
752 for (i = 0; i < EC_NUM; i++)
754 for (i = 0; i < EC_NUM; i++)
755 ecdh_a[i] = ecdh_b[i] = NULL;
757 #ifndef OPENSSL_NO_RSA
758 memset(rsa_key, 0, sizeof(rsa_key));
759 for (i = 0; i < RSA_NUM; i++)
763 memset(c, 0, sizeof(c));
764 memset(DES_iv, 0, sizeof(DES_iv));
765 memset(iv, 0, sizeof(iv));
767 for (i = 0; i < ALGOR_NUM; i++)
769 for (i = 0; i < RSA_NUM; i++)
771 for (i = 0; i < DSA_NUM; i++)
773 #ifndef OPENSSL_NO_EC
774 for (i = 0; i < EC_NUM; i++)
776 for (i = 0; i < EC_NUM; i++)
780 buf = buf_malloc = app_malloc((int)BUFSIZE + misalign, "input buffer");
781 buf2 = buf2_malloc = app_malloc((int)BUFSIZE + misalign, "output buffer");
784 prog = opt_init(argc, argv, speed_options);
785 while ((o = opt_next()) != OPT_EOF) {
790 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
793 opt_help(speed_options);
800 evp_cipher = EVP_get_cipherbyname(opt_arg());
801 if (evp_cipher == NULL)
802 evp_md = EVP_get_digestbyname(opt_arg());
803 if (evp_cipher == NULL && evp_md == NULL) {
805 "%s: %s an unknown cipher or digest\n",
815 (void)setup_engine(opt_arg(), 0);
819 multi = atoi(opt_arg());
823 if (!opt_int(opt_arg(), &misalign))
825 if (misalign > MISALIGN) {
827 "%s: Maximum offset is %d\n", prog, MISALIGN);
830 buf = buf_malloc + misalign;
831 buf2 = buf2_malloc + misalign;
841 argc = opt_num_rest();
844 /* Remaining arguments are algorithms. */
845 for ( ; *argv; argv++) {
846 if (found(*argv, doit_choices, &i)) {
850 #ifndef OPENSSL_NO_DES
851 if (strcmp(*argv, "des") == 0) {
852 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
856 if (strcmp(*argv, "sha") == 0) {
857 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
860 #ifndef OPENSSL_NO_RSA
862 if (strcmp(*argv, "openssl") == 0) {
863 RSA_set_default_method(RSA_PKCS1_OpenSSL());
867 if (strcmp(*argv, "rsa") == 0) {
868 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
869 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
870 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
871 rsa_doit[R_RSA_15360] = 1;
874 if (found(*argv, rsa_choices, &i)) {
879 #ifndef OPENSSL_NO_DSA
880 if (strcmp(*argv, "dsa") == 0) {
881 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
882 dsa_doit[R_DSA_2048] = 1;
885 if (found(*argv, dsa_choices, &i)) {
890 #ifndef OPENSSL_NO_AES
891 if (strcmp(*argv, "aes") == 0) {
892 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
893 doit[D_CBC_256_AES] = 1;
897 #ifndef OPENSSL_NO_CAMELLIA
898 if (strcmp(*argv, "camellia") == 0) {
899 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
900 doit[D_CBC_256_CML] = 1;
904 #ifndef OPENSSL_NO_EC
905 if (strcmp(*argv, "ecdsa") == 0) {
906 for (i = 0; i < EC_NUM; i++)
910 if (found(*argv, ecdsa_choices, &i)) {
914 if (strcmp(*argv, "ecdh") == 0) {
915 for (i = 0; i < EC_NUM; i++)
919 if (found(*argv, ecdh_choices, &i)) {
924 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
929 if (multi && do_multi(multi))
933 /* No parameters; turn on everything. */
934 if ((argc == 0) && !doit[D_EVP]) {
935 for (i = 0; i < ALGOR_NUM; i++)
938 for (i = 0; i < RSA_NUM; i++)
940 for (i = 0; i < DSA_NUM; i++)
942 #ifndef OPENSSL_NO_EC
943 for (i = 0; i < EC_NUM; i++)
945 for (i = 0; i < EC_NUM; i++)
949 for (i = 0; i < ALGOR_NUM; i++)
953 if (usertime == 0 && !mr)
955 "You have chosen to measure elapsed time "
956 "instead of user CPU time.\n");
958 #ifndef OPENSSL_NO_RSA
959 for (i = 0; i < RSA_NUM; i++) {
960 const unsigned char *p;
963 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
964 if (rsa_key[i] == NULL) {
965 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
972 #ifndef OPENSSL_NO_DSA
973 dsa_key[0] = get_dsa512();
974 dsa_key[1] = get_dsa1024();
975 dsa_key[2] = get_dsa2048();
978 #ifndef OPENSSL_NO_DES
979 DES_set_key_unchecked(&key, &sch);
980 DES_set_key_unchecked(&key2, &sch2);
981 DES_set_key_unchecked(&key3, &sch3);
983 #ifndef OPENSSL_NO_AES
984 AES_set_encrypt_key(key16, 128, &aes_ks1);
985 AES_set_encrypt_key(key24, 192, &aes_ks2);
986 AES_set_encrypt_key(key32, 256, &aes_ks3);
988 #ifndef OPENSSL_NO_CAMELLIA
989 Camellia_set_key(key16, 128, &camellia_ks1);
990 Camellia_set_key(ckey24, 192, &camellia_ks2);
991 Camellia_set_key(ckey32, 256, &camellia_ks3);
993 #ifndef OPENSSL_NO_IDEA
994 idea_set_encrypt_key(key16, &idea_ks);
996 #ifndef OPENSSL_NO_SEED
997 SEED_set_key(key16, &seed_ks);
999 #ifndef OPENSSL_NO_RC4
1000 RC4_set_key(&rc4_ks, 16, key16);
1002 #ifndef OPENSSL_NO_RC2
1003 RC2_set_key(&rc2_ks, 16, key16, 128);
1005 #ifndef OPENSSL_NO_RC5
1006 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1008 #ifndef OPENSSL_NO_BF
1009 BF_set_key(&bf_ks, 16, key16);
1011 #ifndef OPENSSL_NO_CAST
1012 CAST_set_key(&cast_ks, 16, key16);
1014 #ifndef OPENSSL_NO_RSA
1015 memset(rsa_c, 0, sizeof(rsa_c));
1018 # ifndef OPENSSL_NO_DES
1019 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1025 for (it = count; it; it--)
1026 DES_ecb_encrypt((DES_cblock *)buf,
1027 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1031 c[D_MD2][0] = count / 10;
1032 c[D_MDC2][0] = count / 10;
1033 c[D_MD4][0] = count;
1034 c[D_MD5][0] = count;
1035 c[D_HMAC][0] = count;
1036 c[D_SHA1][0] = count;
1037 c[D_RMD160][0] = count;
1038 c[D_RC4][0] = count * 5;
1039 c[D_CBC_DES][0] = count;
1040 c[D_EDE3_DES][0] = count / 3;
1041 c[D_CBC_IDEA][0] = count;
1042 c[D_CBC_SEED][0] = count;
1043 c[D_CBC_RC2][0] = count;
1044 c[D_CBC_RC5][0] = count;
1045 c[D_CBC_BF][0] = count;
1046 c[D_CBC_CAST][0] = count;
1047 c[D_CBC_128_AES][0] = count;
1048 c[D_CBC_192_AES][0] = count;
1049 c[D_CBC_256_AES][0] = count;
1050 c[D_CBC_128_CML][0] = count;
1051 c[D_CBC_192_CML][0] = count;
1052 c[D_CBC_256_CML][0] = count;
1053 c[D_SHA256][0] = count;
1054 c[D_SHA512][0] = count;
1055 c[D_WHIRLPOOL][0] = count;
1056 c[D_IGE_128_AES][0] = count;
1057 c[D_IGE_192_AES][0] = count;
1058 c[D_IGE_256_AES][0] = count;
1059 c[D_GHASH][0] = count;
1061 for (i = 1; i < SIZE_NUM; i++) {
1064 l0 = (long)lengths[0];
1065 l1 = (long)lengths[i];
1067 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1068 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1069 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1070 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1071 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1072 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1073 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1074 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1075 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1076 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1078 l0 = (long)lengths[i - 1];
1080 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1081 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1082 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1083 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1084 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1085 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1086 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1087 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1088 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1089 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1090 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1091 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1092 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1093 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1094 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1095 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1096 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1097 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1100 # ifndef OPENSSL_NO_RSA
1101 rsa_c[R_RSA_512][0] = count / 2000;
1102 rsa_c[R_RSA_512][1] = count / 400;
1103 for (i = 1; i < RSA_NUM; i++) {
1104 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1105 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1106 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1109 if (rsa_c[i][0] == 0) {
1117 # ifndef OPENSSL_NO_DSA
1118 dsa_c[R_DSA_512][0] = count / 1000;
1119 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1120 for (i = 1; i < DSA_NUM; i++) {
1121 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1122 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1123 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1126 if (dsa_c[i] == 0) {
1134 # ifndef OPENSSL_NO_EC
1135 ecdsa_c[R_EC_P160][0] = count / 1000;
1136 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1137 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1138 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1139 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1140 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1143 if (ecdsa_c[i] == 0) {
1149 ecdsa_c[R_EC_K163][0] = count / 1000;
1150 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1151 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1152 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1153 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1154 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1157 if (ecdsa_c[i] == 0) {
1163 ecdsa_c[R_EC_B163][0] = count / 1000;
1164 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1165 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1166 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1167 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1168 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1171 if (ecdsa_c[i] == 0) {
1178 ecdh_c[R_EC_P160][0] = count / 1000;
1179 ecdh_c[R_EC_P160][1] = count / 1000;
1180 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1181 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1182 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1183 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1186 if (ecdh_c[i] == 0) {
1192 ecdh_c[R_EC_K163][0] = count / 1000;
1193 ecdh_c[R_EC_K163][1] = count / 1000;
1194 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1195 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1196 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1197 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1200 if (ecdh_c[i] == 0) {
1206 ecdh_c[R_EC_B163][0] = count / 1000;
1207 ecdh_c[R_EC_B163][1] = count / 1000;
1208 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1209 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1210 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1211 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1214 if (ecdh_c[i] == 0) {
1222 # define COND(d) (count < (d))
1223 # define COUNT(d) (d)
1225 /* not worth fixing */
1226 # error "You cannot disable DES on systems without SIGALRM."
1227 # endif /* OPENSSL_NO_DES */
1229 # define COND(c) (run && count<0x7fffffff)
1230 # define COUNT(d) (count)
1232 signal(SIGALRM, sig_done);
1234 #endif /* SIGALRM */
1236 #ifndef OPENSSL_NO_MD2
1238 for (j = 0; j < SIZE_NUM; j++) {
1239 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1241 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1242 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1245 print_result(D_MD2, j, count, d);
1249 #ifndef OPENSSL_NO_MDC2
1251 for (j = 0; j < SIZE_NUM; j++) {
1252 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1254 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1255 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1258 print_result(D_MDC2, j, count, d);
1263 #ifndef OPENSSL_NO_MD4
1265 for (j = 0; j < SIZE_NUM; j++) {
1266 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1268 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1269 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1270 NULL, EVP_md4(), NULL);
1272 print_result(D_MD4, j, count, d);
1277 #ifndef OPENSSL_NO_MD5
1279 for (j = 0; j < SIZE_NUM; j++) {
1280 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1282 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1283 MD5(buf, lengths[j], md5);
1285 print_result(D_MD5, j, count, d);
1290 #if !defined(OPENSSL_NO_MD5)
1292 HMAC_CTX *hctx = NULL;
1294 hctx = HMAC_CTX_new();
1296 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1299 HMAC_Init_ex(hctx, (unsigned char *)"This is a key...",
1300 16, EVP_md5(), NULL);
1302 for (j = 0; j < SIZE_NUM; j++) {
1303 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1305 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1306 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
1307 HMAC_Update(hctx, buf, lengths[j]);
1308 HMAC_Final(hctx, &(hmac[0]), NULL);
1311 print_result(D_HMAC, j, count, d);
1313 HMAC_CTX_free(hctx);
1317 for (j = 0; j < SIZE_NUM; j++) {
1318 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1320 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1321 SHA1(buf, lengths[j], sha);
1323 print_result(D_SHA1, j, count, d);
1326 if (doit[D_SHA256]) {
1327 for (j = 0; j < SIZE_NUM; j++) {
1328 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1330 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1331 SHA256(buf, lengths[j], sha256);
1333 print_result(D_SHA256, j, count, d);
1336 if (doit[D_SHA512]) {
1337 for (j = 0; j < SIZE_NUM; j++) {
1338 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1340 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1341 SHA512(buf, lengths[j], sha512);
1343 print_result(D_SHA512, j, count, d);
1347 #ifndef OPENSSL_NO_WHIRLPOOL
1348 if (doit[D_WHIRLPOOL]) {
1349 for (j = 0; j < SIZE_NUM; j++) {
1350 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1352 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1353 WHIRLPOOL(buf, lengths[j], whirlpool);
1355 print_result(D_WHIRLPOOL, j, count, d);
1360 #ifndef OPENSSL_NO_RMD160
1361 if (doit[D_RMD160]) {
1362 for (j = 0; j < SIZE_NUM; j++) {
1363 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1365 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1366 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1367 EVP_ripemd160(), NULL);
1369 print_result(D_RMD160, j, count, d);
1373 #ifndef OPENSSL_NO_RC4
1375 for (j = 0; j < SIZE_NUM; j++) {
1376 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1378 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1379 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1381 print_result(D_RC4, j, count, d);
1385 #ifndef OPENSSL_NO_DES
1386 if (doit[D_CBC_DES]) {
1387 for (j = 0; j < SIZE_NUM; j++) {
1388 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1390 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1391 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1392 &DES_iv, DES_ENCRYPT);
1394 print_result(D_CBC_DES, j, count, d);
1398 if (doit[D_EDE3_DES]) {
1399 for (j = 0; j < SIZE_NUM; j++) {
1400 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1402 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1403 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1405 &DES_iv, DES_ENCRYPT);
1407 print_result(D_EDE3_DES, j, count, d);
1411 #ifndef OPENSSL_NO_AES
1412 if (doit[D_CBC_128_AES]) {
1413 for (j = 0; j < SIZE_NUM; j++) {
1414 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1417 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1418 AES_cbc_encrypt(buf, buf,
1419 (unsigned long)lengths[j], &aes_ks1,
1422 print_result(D_CBC_128_AES, j, count, d);
1425 if (doit[D_CBC_192_AES]) {
1426 for (j = 0; j < SIZE_NUM; j++) {
1427 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1430 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1431 AES_cbc_encrypt(buf, buf,
1432 (unsigned long)lengths[j], &aes_ks2,
1435 print_result(D_CBC_192_AES, j, count, d);
1438 if (doit[D_CBC_256_AES]) {
1439 for (j = 0; j < SIZE_NUM; j++) {
1440 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1443 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1444 AES_cbc_encrypt(buf, buf,
1445 (unsigned long)lengths[j], &aes_ks3,
1448 print_result(D_CBC_256_AES, j, count, d);
1452 if (doit[D_IGE_128_AES]) {
1453 for (j = 0; j < SIZE_NUM; j++) {
1454 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1457 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1458 AES_ige_encrypt(buf, buf2,
1459 (unsigned long)lengths[j], &aes_ks1,
1462 print_result(D_IGE_128_AES, j, count, d);
1465 if (doit[D_IGE_192_AES]) {
1466 for (j = 0; j < SIZE_NUM; j++) {
1467 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1470 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1471 AES_ige_encrypt(buf, buf2,
1472 (unsigned long)lengths[j], &aes_ks2,
1475 print_result(D_IGE_192_AES, j, count, d);
1478 if (doit[D_IGE_256_AES]) {
1479 for (j = 0; j < SIZE_NUM; j++) {
1480 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1483 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1484 AES_ige_encrypt(buf, buf2,
1485 (unsigned long)lengths[j], &aes_ks3,
1488 print_result(D_IGE_256_AES, j, count, d);
1491 if (doit[D_GHASH]) {
1492 GCM128_CONTEXT *ctx =
1493 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1494 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1496 for (j = 0; j < SIZE_NUM; j++) {
1497 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1499 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1500 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1502 print_result(D_GHASH, j, count, d);
1504 CRYPTO_gcm128_release(ctx);
1507 #ifndef OPENSSL_NO_CAMELLIA
1508 if (doit[D_CBC_128_CML]) {
1509 for (j = 0; j < SIZE_NUM; j++) {
1510 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1513 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1514 Camellia_cbc_encrypt(buf, buf,
1515 (unsigned long)lengths[j], &camellia_ks1,
1516 iv, CAMELLIA_ENCRYPT);
1518 print_result(D_CBC_128_CML, j, count, d);
1521 if (doit[D_CBC_192_CML]) {
1522 for (j = 0; j < SIZE_NUM; j++) {
1523 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1526 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1527 Camellia_cbc_encrypt(buf, buf,
1528 (unsigned long)lengths[j], &camellia_ks2,
1529 iv, CAMELLIA_ENCRYPT);
1531 print_result(D_CBC_192_CML, j, count, d);
1534 if (doit[D_CBC_256_CML]) {
1535 for (j = 0; j < SIZE_NUM; j++) {
1536 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1539 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1540 Camellia_cbc_encrypt(buf, buf,
1541 (unsigned long)lengths[j], &camellia_ks3,
1542 iv, CAMELLIA_ENCRYPT);
1544 print_result(D_CBC_256_CML, j, count, d);
1548 #ifndef OPENSSL_NO_IDEA
1549 if (doit[D_CBC_IDEA]) {
1550 for (j = 0; j < SIZE_NUM; j++) {
1551 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1553 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1554 idea_cbc_encrypt(buf, buf,
1555 (unsigned long)lengths[j], &idea_ks,
1558 print_result(D_CBC_IDEA, j, count, d);
1562 #ifndef OPENSSL_NO_SEED
1563 if (doit[D_CBC_SEED]) {
1564 for (j = 0; j < SIZE_NUM; j++) {
1565 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1567 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1568 SEED_cbc_encrypt(buf, buf,
1569 (unsigned long)lengths[j], &seed_ks, iv, 1);
1571 print_result(D_CBC_SEED, j, count, d);
1575 #ifndef OPENSSL_NO_RC2
1576 if (doit[D_CBC_RC2]) {
1577 for (j = 0; j < SIZE_NUM; j++) {
1578 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1580 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1581 RC2_cbc_encrypt(buf, buf,
1582 (unsigned long)lengths[j], &rc2_ks,
1585 print_result(D_CBC_RC2, j, count, d);
1589 #ifndef OPENSSL_NO_RC5
1590 if (doit[D_CBC_RC5]) {
1591 for (j = 0; j < SIZE_NUM; j++) {
1592 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1594 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1595 RC5_32_cbc_encrypt(buf, buf,
1596 (unsigned long)lengths[j], &rc5_ks,
1599 print_result(D_CBC_RC5, j, count, d);
1603 #ifndef OPENSSL_NO_BF
1604 if (doit[D_CBC_BF]) {
1605 for (j = 0; j < SIZE_NUM; j++) {
1606 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1608 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1609 BF_cbc_encrypt(buf, buf,
1610 (unsigned long)lengths[j], &bf_ks,
1613 print_result(D_CBC_BF, j, count, d);
1617 #ifndef OPENSSL_NO_CAST
1618 if (doit[D_CBC_CAST]) {
1619 for (j = 0; j < SIZE_NUM; j++) {
1620 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1622 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1623 CAST_cbc_encrypt(buf, buf,
1624 (unsigned long)lengths[j], &cast_ks,
1627 print_result(D_CBC_CAST, j, count, d);
1633 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1634 if (multiblock && evp_cipher) {
1636 (EVP_CIPHER_flags(evp_cipher) &
1637 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1638 BIO_printf(bio_err, "%s is not multi-block capable\n",
1639 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1642 multiblock_speed(evp_cipher);
1647 for (j = 0; j < SIZE_NUM; j++) {
1649 EVP_CIPHER_CTX *ctx;
1652 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
1654 * -O3 -fschedule-insns messes up an optimization here!
1655 * names[D_EVP] somehow becomes NULL
1657 print_message(names[D_EVP], save_count, lengths[j]);
1659 ctx = EVP_CIPHER_CTX_new();
1661 EVP_DecryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
1663 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
1664 EVP_CIPHER_CTX_set_padding(ctx, 0);
1668 for (count = 0, run = 1;
1669 COND(save_count * 4 * lengths[0] / lengths[j]);
1671 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1673 for (count = 0, run = 1;
1674 COND(save_count * 4 * lengths[0] / lengths[j]);
1676 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1678 EVP_DecryptFinal_ex(ctx, buf, &outl);
1680 EVP_EncryptFinal_ex(ctx, buf, &outl);
1682 EVP_CIPHER_CTX_free(ctx);
1685 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
1686 print_message(names[D_EVP], save_count, lengths[j]);
1689 for (count = 0, run = 1;
1690 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1691 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1695 print_result(D_EVP, j, count, d);
1699 RAND_bytes(buf, 36);
1700 #ifndef OPENSSL_NO_RSA
1701 for (j = 0; j < RSA_NUM; j++) {
1705 st = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1708 "RSA sign failure. No RSA sign will be done.\n");
1709 ERR_print_errors(bio_err);
1712 pkey_print_message("private", "rsa",
1713 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
1714 /* RSA_blinding_on(rsa_key[j],NULL); */
1716 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1717 st = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1718 &rsa_num, rsa_key[j]);
1720 BIO_printf(bio_err, "RSA sign failure\n");
1721 ERR_print_errors(bio_err);
1728 mr ? "+R1:%ld:%d:%.2f\n"
1729 : "%ld %d bit private RSA's in %.2fs\n",
1730 count, rsa_bits[j], d);
1731 rsa_results[j][0] = d / (double)count;
1735 st = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1738 "RSA verify failure. No RSA verify will be done.\n");
1739 ERR_print_errors(bio_err);
1742 pkey_print_message("public", "rsa",
1743 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
1745 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1746 st = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1747 rsa_num, rsa_key[j]);
1749 BIO_printf(bio_err, "RSA verify failure\n");
1750 ERR_print_errors(bio_err);
1757 mr ? "+R2:%ld:%d:%.2f\n"
1758 : "%ld %d bit public RSA's in %.2fs\n",
1759 count, rsa_bits[j], d);
1760 rsa_results[j][1] = d / (double)count;
1763 if (rsa_count <= 1) {
1764 /* if longer than 10s, don't do any more */
1765 for (j++; j < RSA_NUM; j++)
1771 RAND_bytes(buf, 20);
1772 #ifndef OPENSSL_NO_DSA
1773 if (RAND_status() != 1) {
1774 RAND_seed(rnd_seed, sizeof rnd_seed);
1777 for (j = 0; j < DSA_NUM; j++) {
1784 /* DSA_generate_key(dsa_key[j]); */
1785 /* DSA_sign_setup(dsa_key[j],NULL); */
1786 st = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
1789 "DSA sign failure. No DSA sign will be done.\n");
1790 ERR_print_errors(bio_err);
1793 pkey_print_message("sign", "dsa",
1794 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
1796 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
1797 st = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
1799 BIO_printf(bio_err, "DSA sign failure\n");
1800 ERR_print_errors(bio_err);
1807 mr ? "+R3:%ld:%d:%.2f\n"
1808 : "%ld %d bit DSA signs in %.2fs\n",
1809 count, dsa_bits[j], d);
1810 dsa_results[j][0] = d / (double)count;
1814 st = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
1817 "DSA verify failure. No DSA verify will be done.\n");
1818 ERR_print_errors(bio_err);
1821 pkey_print_message("verify", "dsa",
1822 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
1824 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
1825 st = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
1827 BIO_printf(bio_err, "DSA verify failure\n");
1828 ERR_print_errors(bio_err);
1835 mr ? "+R4:%ld:%d:%.2f\n"
1836 : "%ld %d bit DSA verify in %.2fs\n",
1837 count, dsa_bits[j], d);
1838 dsa_results[j][1] = d / (double)count;
1841 if (rsa_count <= 1) {
1842 /* if longer than 10s, don't do any more */
1843 for (j++; j < DSA_NUM; j++)
1851 #ifndef OPENSSL_NO_EC
1852 if (RAND_status() != 1) {
1853 RAND_seed(rnd_seed, sizeof rnd_seed);
1856 for (j = 0; j < EC_NUM; j++) {
1860 continue; /* Ignore Curve */
1861 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1862 if (ecdsa[j] == NULL) {
1863 BIO_printf(bio_err, "ECDSA failure.\n");
1864 ERR_print_errors(bio_err);
1867 EC_KEY_precompute_mult(ecdsa[j], NULL);
1868 /* Perform ECDSA signature test */
1869 EC_KEY_generate_key(ecdsa[j]);
1870 st = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
1873 "ECDSA sign failure. No ECDSA sign will be done.\n");
1874 ERR_print_errors(bio_err);
1877 pkey_print_message("sign", "ecdsa",
1879 test_curves_bits[j], ECDSA_SECONDS);
1882 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
1883 st = ECDSA_sign(0, buf, 20,
1884 ecdsasig, &ecdsasiglen, ecdsa[j]);
1886 BIO_printf(bio_err, "ECDSA sign failure\n");
1887 ERR_print_errors(bio_err);
1895 mr ? "+R5:%ld:%d:%.2f\n" :
1896 "%ld %d bit ECDSA signs in %.2fs \n",
1897 count, test_curves_bits[j], d);
1898 ecdsa_results[j][0] = d / (double)count;
1902 /* Perform ECDSA verification test */
1903 st = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
1906 "ECDSA verify failure. No ECDSA verify will be done.\n");
1907 ERR_print_errors(bio_err);
1910 pkey_print_message("verify", "ecdsa",
1912 test_curves_bits[j], ECDSA_SECONDS);
1914 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
1915 st = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1918 BIO_printf(bio_err, "ECDSA verify failure\n");
1919 ERR_print_errors(bio_err);
1926 mr ? "+R6:%ld:%d:%.2f\n"
1927 : "%ld %d bit ECDSA verify in %.2fs\n",
1928 count, test_curves_bits[j], d);
1929 ecdsa_results[j][1] = d / (double)count;
1932 if (rsa_count <= 1) {
1933 /* if longer than 10s, don't do any more */
1934 for (j++; j < EC_NUM; j++)
1943 #ifndef OPENSSL_NO_EC
1944 if (RAND_status() != 1) {
1945 RAND_seed(rnd_seed, sizeof rnd_seed);
1948 for (j = 0; j < EC_NUM; j++) {
1951 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1952 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1953 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
1954 BIO_printf(bio_err, "ECDH failure.\n");
1955 ERR_print_errors(bio_err);
1958 /* generate two ECDH key pairs */
1959 if (!EC_KEY_generate_key(ecdh_a[j]) ||
1960 !EC_KEY_generate_key(ecdh_b[j])) {
1961 BIO_printf(bio_err, "ECDH key generation failure.\n");
1962 ERR_print_errors(bio_err);
1966 * If field size is not more than 24 octets, then use SHA-1
1967 * hash of result; otherwise, use result (see section 4.8 of
1968 * draft-ietf-tls-ecc-03.txt).
1970 int field_size, outlen;
1971 void *(*kdf) (const void *in, size_t inlen, void *out,
1974 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
1975 if (field_size <= 24 * 8) {
1976 outlen = KDF1_SHA1_len;
1979 outlen = (field_size + 7) / 8;
1983 ECDH_compute_key(secret_a, outlen,
1984 EC_KEY_get0_public_key(ecdh_b[j]),
1987 ECDH_compute_key(secret_b, outlen,
1988 EC_KEY_get0_public_key(ecdh_a[j]),
1990 if (secret_size_a != secret_size_b)
1995 for (secret_idx = 0; (secret_idx < secret_size_a)
1996 && (ecdh_checks == 1); secret_idx++) {
1997 if (secret_a[secret_idx] != secret_b[secret_idx])
2001 if (ecdh_checks == 0) {
2002 BIO_printf(bio_err, "ECDH computations don't match.\n");
2003 ERR_print_errors(bio_err);
2007 pkey_print_message("", "ecdh",
2009 test_curves_bits[j], ECDH_SECONDS);
2011 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2012 ECDH_compute_key(secret_a, outlen,
2013 EC_KEY_get0_public_key(ecdh_b[j]),
2018 mr ? "+R7:%ld:%d:%.2f\n" :
2019 "%ld %d-bit ECDH ops in %.2fs\n", count,
2020 test_curves_bits[j], d);
2021 ecdh_results[j][0] = d / (double)count;
2026 if (rsa_count <= 1) {
2027 /* if longer than 10s, don't do any more */
2028 for (j++; j < EC_NUM; j++)
2039 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2040 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2042 printf("%s ", BN_options());
2043 #ifndef OPENSSL_NO_MD2
2044 printf("%s ", MD2_options());
2046 #ifndef OPENSSL_NO_RC4
2047 printf("%s ", RC4_options());
2049 #ifndef OPENSSL_NO_DES
2050 printf("%s ", DES_options());
2052 #ifndef OPENSSL_NO_AES
2053 printf("%s ", AES_options());
2055 #ifndef OPENSSL_NO_IDEA
2056 printf("%s ", idea_options());
2058 #ifndef OPENSSL_NO_BF
2059 printf("%s ", BF_options());
2061 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2069 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2072 for (j = 0; j < SIZE_NUM; j++)
2073 printf(mr ? ":%d" : "%7d bytes", lengths[j]);
2077 for (k = 0; k < ALGOR_NUM; k++) {
2081 printf("+F:%d:%s", k, names[k]);
2083 printf("%-13s", names[k]);
2084 for (j = 0; j < SIZE_NUM; j++) {
2085 if (results[k][j] > 10000 && !mr)
2086 printf(" %11.2fk", results[k][j] / 1e3);
2088 printf(mr ? ":%.2f" : " %11.2f ", results[k][j]);
2092 #ifndef OPENSSL_NO_RSA
2094 for (k = 0; k < RSA_NUM; k++) {
2098 printf("%18ssign verify sign/s verify/s\n", " ");
2102 printf("+F2:%u:%u:%f:%f\n",
2103 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2105 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2106 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2107 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2110 #ifndef OPENSSL_NO_DSA
2112 for (k = 0; k < DSA_NUM; k++) {
2116 printf("%18ssign verify sign/s verify/s\n", " ");
2120 printf("+F3:%u:%u:%f:%f\n",
2121 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2123 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2124 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2125 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2128 #ifndef OPENSSL_NO_EC
2130 for (k = 0; k < EC_NUM; k++) {
2134 printf("%30ssign verify sign/s verify/s\n", " ");
2139 printf("+F4:%u:%u:%f:%f\n",
2140 k, test_curves_bits[k],
2141 ecdsa_results[k][0], ecdsa_results[k][1]);
2143 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2144 test_curves_bits[k],
2145 test_curves_names[k],
2146 ecdsa_results[k][0], ecdsa_results[k][1],
2147 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2151 #ifndef OPENSSL_NO_EC
2153 for (k = 0; k < EC_NUM; k++) {
2157 printf("%30sop op/s\n", " ");
2161 printf("+F5:%u:%u:%f:%f\n",
2162 k, test_curves_bits[k],
2163 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2166 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2167 test_curves_bits[k],
2168 test_curves_names[k],
2169 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2176 ERR_print_errors(bio_err);
2177 OPENSSL_free(buf_malloc);
2178 OPENSSL_free(buf2_malloc);
2179 #ifndef OPENSSL_NO_RSA
2180 for (i = 0; i < RSA_NUM; i++)
2181 RSA_free(rsa_key[i]);
2183 #ifndef OPENSSL_NO_DSA
2184 for (i = 0; i < DSA_NUM; i++)
2185 DSA_free(dsa_key[i]);
2188 #ifndef OPENSSL_NO_EC
2189 for (i = 0; i < EC_NUM; i++) {
2190 EC_KEY_free(ecdsa[i]);
2191 EC_KEY_free(ecdh_a[i]);
2192 EC_KEY_free(ecdh_b[i]);
2198 static void print_message(const char *s, long num, int length)
2202 mr ? "+DT:%s:%d:%d\n"
2203 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2204 (void)BIO_flush(bio_err);
2208 mr ? "+DN:%s:%ld:%d\n"
2209 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2210 (void)BIO_flush(bio_err);
2214 static void pkey_print_message(const char *str, const char *str2, long num,
2219 mr ? "+DTP:%d:%s:%s:%d\n"
2220 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2221 (void)BIO_flush(bio_err);
2225 mr ? "+DNP:%ld:%d:%s:%s\n"
2226 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2227 (void)BIO_flush(bio_err);
2231 static void print_result(int alg, int run_no, int count, double time_used)
2234 mr ? "+R:%d:%s:%f\n"
2235 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2236 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2240 static char *sstrsep(char **string, const char *delim)
2243 char *token = *string;
2248 memset(isdelim, 0, sizeof isdelim);
2252 isdelim[(unsigned char)(*delim)] = 1;
2256 while (!isdelim[(unsigned char)(**string)]) {
2268 static int do_multi(int multi)
2273 static char sep[] = ":";
2275 fds = malloc(sizeof(*fds) * multi);
2276 for (n = 0; n < multi; ++n) {
2277 if (pipe(fd) == -1) {
2278 BIO_printf(bio_err, "pipe failure\n");
2282 (void)BIO_flush(bio_err);
2289 if (dup(fd[1]) == -1) {
2290 BIO_printf(bio_err, "dup failed\n");
2299 printf("Forked child %d\n", n);
2302 /* for now, assume the pipe is long enough to take all the output */
2303 for (n = 0; n < multi; ++n) {
2308 f = fdopen(fds[n], "r");
2309 while (fgets(buf, sizeof buf, f)) {
2310 p = strchr(buf, '\n');
2313 if (buf[0] != '+') {
2314 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2318 printf("Got: %s from %d\n", buf, n);
2319 if (strncmp(buf, "+F:", 3) == 0) {
2324 alg = atoi(sstrsep(&p, sep));
2326 for (j = 0; j < SIZE_NUM; ++j)
2327 results[alg][j] += atof(sstrsep(&p, sep));
2328 } else if (strncmp(buf, "+F2:", 4) == 0) {
2333 k = atoi(sstrsep(&p, sep));
2336 d = atof(sstrsep(&p, sep));
2338 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2340 rsa_results[k][0] = d;
2342 d = atof(sstrsep(&p, sep));
2344 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2346 rsa_results[k][1] = d;
2348 # ifndef OPENSSL_NO_DSA
2349 else if (strncmp(buf, "+F3:", 4) == 0) {
2354 k = atoi(sstrsep(&p, sep));
2357 d = atof(sstrsep(&p, sep));
2359 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2361 dsa_results[k][0] = d;
2363 d = atof(sstrsep(&p, sep));
2365 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2367 dsa_results[k][1] = d;
2370 # ifndef OPENSSL_NO_EC
2371 else if (strncmp(buf, "+F4:", 4) == 0) {
2376 k = atoi(sstrsep(&p, sep));
2379 d = atof(sstrsep(&p, sep));
2381 ecdsa_results[k][0] =
2382 1 / (1 / ecdsa_results[k][0] + 1 / d);
2384 ecdsa_results[k][0] = d;
2386 d = atof(sstrsep(&p, sep));
2388 ecdsa_results[k][1] =
2389 1 / (1 / ecdsa_results[k][1] + 1 / d);
2391 ecdsa_results[k][1] = d;
2395 # ifndef OPENSSL_NO_EC
2396 else if (strncmp(buf, "+F5:", 4) == 0) {
2401 k = atoi(sstrsep(&p, sep));
2404 d = atof(sstrsep(&p, sep));
2406 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2408 ecdh_results[k][0] = d;
2413 else if (strncmp(buf, "+H:", 3) == 0) {
2416 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
2426 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2428 static int mblengths[] =
2429 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2430 int j, count, num = OSSL_NELEM(lengths);
2431 const char *alg_name;
2432 unsigned char *inp, *out, no_key[32], no_iv[16];
2433 EVP_CIPHER_CTX *ctx;
2436 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
2437 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
2438 ctx = EVP_CIPHER_CTX_new();
2439 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
2440 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2442 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2444 for (j = 0; j < num; j++) {
2445 print_message(alg_name, 0, mblengths[j]);
2447 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2448 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
2449 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2450 size_t len = mblengths[j];
2453 memset(aad, 0, 8); /* avoid uninitialized values */
2454 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2455 aad[9] = 3; /* version */
2457 aad[11] = 0; /* length */
2459 mb_param.out = NULL;
2462 mb_param.interleave = 8;
2464 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2465 sizeof(mb_param), &mb_param);
2471 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2472 sizeof(mb_param), &mb_param);
2476 RAND_bytes(out, 16);
2480 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
2481 EVP_AEAD_TLS1_AAD_LEN, aad);
2482 EVP_Cipher(ctx, out, inp, len + pad);
2486 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
2487 : "%d %s's in %.2fs\n", count, "evp", d);
2488 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2492 fprintf(stdout, "+H");
2493 for (j = 0; j < num; j++)
2494 fprintf(stdout, ":%d", mblengths[j]);
2495 fprintf(stdout, "\n");
2496 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2497 for (j = 0; j < num; j++)
2498 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2499 fprintf(stdout, "\n");
2502 "The 'numbers' are in 1000s of bytes per second processed.\n");
2503 fprintf(stdout, "type ");
2504 for (j = 0; j < num; j++)
2505 fprintf(stdout, "%7d bytes", mblengths[j]);
2506 fprintf(stdout, "\n");
2507 fprintf(stdout, "%-24s", alg_name);
2509 for (j = 0; j < num; j++) {
2510 if (results[D_EVP][j] > 10000)
2511 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2513 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2515 fprintf(stdout, "\n");
2520 EVP_CIPHER_CTX_free(ctx);