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/sha.h>
125 #ifndef OPENSSL_NO_RMD160
126 # include <openssl/ripemd.h>
128 #ifndef OPENSSL_NO_WHIRLPOOL
129 # include <openssl/whrlpool.h>
131 #ifndef OPENSSL_NO_RC4
132 # include <openssl/rc4.h>
134 #ifndef OPENSSL_NO_RC5
135 # include <openssl/rc5.h>
137 #ifndef OPENSSL_NO_RC2
138 # include <openssl/rc2.h>
140 #ifndef OPENSSL_NO_IDEA
141 # include <openssl/idea.h>
143 #ifndef OPENSSL_NO_SEED
144 # include <openssl/seed.h>
146 #ifndef OPENSSL_NO_BF
147 # include <openssl/blowfish.h>
149 #ifndef OPENSSL_NO_CAST
150 # include <openssl/cast.h>
152 #ifndef OPENSSL_NO_RSA
153 # include <openssl/rsa.h>
154 # include "./testrsa.h"
156 #include <openssl/x509.h>
157 #ifndef OPENSSL_NO_DSA
158 # include <openssl/dsa.h>
159 # include "./testdsa.h"
161 #ifndef OPENSSL_NO_EC
162 # include <openssl/ec.h>
164 #include <openssl/modes.h>
167 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
181 #define BUFSIZE (1024*8+1)
182 #define MAX_MISALIGNMENT 63
184 static volatile int run = 0;
187 static int usertime = 1;
189 static double Time_F(int s);
190 static void print_message(const char *s, long num, int length);
191 static void pkey_print_message(const char *str, const char *str2,
192 long num, int bits, int sec);
193 static void print_result(int alg, int run_no, int count, double time_used);
195 static int do_multi(int multi);
205 #define MAX_ECDH_SIZE 256
208 static const char *names[ALGOR_NUM] = {
209 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
210 "des cbc", "des ede3", "idea cbc", "seed cbc",
211 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
212 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
213 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
214 "evp", "sha256", "sha512", "whirlpool",
215 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
218 static double results[ALGOR_NUM][SIZE_NUM];
219 static int lengths[SIZE_NUM] = {
220 16, 64, 256, 1024, 8 * 1024
223 #ifndef OPENSSL_NO_RSA
224 static double rsa_results[RSA_NUM][2];
226 #ifndef OPENSSL_NO_DSA
227 static double dsa_results[DSA_NUM][2];
229 #ifndef OPENSSL_NO_EC
230 static double ecdsa_results[EC_NUM][2];
231 static double ecdh_results[EC_NUM][1];
234 #if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
235 static const char rnd_seed[] =
236 "string to make the random number generator think it has entropy";
237 static int rnd_fake = 0;
241 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
242 # define SIGRETTYPE void
244 # define SIGRETTYPE int
247 static SIGRETTYPE sig_done(int sig);
248 static SIGRETTYPE sig_done(int sig)
250 signal(SIGALRM, sig_done);
260 # if !defined(SIGALRM)
263 static unsigned int lapse, schlock;
264 static void alarm_win32(unsigned int secs)
269 # define alarm alarm_win32
271 static DWORD WINAPI sleepy(VOID * arg)
279 static double Time_F(int s)
286 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
288 DWORD err = GetLastError();
289 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
293 Sleep(0); /* scheduler spinlock */
294 ret = app_tminterval(s, usertime);
296 ret = app_tminterval(s, usertime);
298 TerminateThread(thr, 0);
306 static double Time_F(int s)
308 double ret = app_tminterval(s, usertime);
315 #ifndef OPENSSL_NO_EC
316 static const int KDF1_SHA1_len = 20;
317 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
320 if (*outlen < SHA_DIGEST_LENGTH)
322 *outlen = SHA_DIGEST_LENGTH;
323 return SHA1(in, inlen, out);
325 #endif /* OPENSSL_NO_EC */
327 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
329 static int found(const char *name, const OPT_PAIR * pairs, int *result)
331 for (; pairs->name; pairs++)
332 if (strcmp(name, pairs->name) == 0) {
333 *result = pairs->retval;
339 typedef enum OPTION_choice {
340 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
341 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
342 OPT_MR, OPT_MB, OPT_MISALIGN
345 OPTIONS speed_options[] = {
346 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
347 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
348 {"help", OPT_HELP, '-', "Display this summary"},
349 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
350 {"decrypt", OPT_DECRYPT, '-',
351 "Time decryption instead of encryption (only EVP)"},
352 {"mr", OPT_MR, '-', "Produce machine readable output"},
354 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
355 {"elapsed", OPT_ELAPSED, '-',
356 "Measure time in real time instead of CPU user time"},
358 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
360 #ifndef OPENSSL_NO_ENGINE
361 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
376 #define D_CBC_IDEA 10
377 #define D_CBC_SEED 11
381 #define D_CBC_CAST 15
382 #define D_CBC_128_AES 16
383 #define D_CBC_192_AES 17
384 #define D_CBC_256_AES 18
385 #define D_CBC_128_CML 19
386 #define D_CBC_192_CML 20
387 #define D_CBC_256_CML 21
391 #define D_WHIRLPOOL 25
392 #define D_IGE_128_AES 26
393 #define D_IGE_192_AES 27
394 #define D_IGE_256_AES 28
396 static OPT_PAIR doit_choices[] = {
397 #ifndef OPENSSL_NO_MD2
400 #ifndef OPENSSL_NO_MDC2
403 #ifndef OPENSSL_NO_MD4
406 #ifndef OPENSSL_NO_MD5
409 #ifndef OPENSSL_NO_MD5
413 {"sha256", D_SHA256},
414 {"sha512", D_SHA512},
415 #ifndef OPENSSL_NO_WHIRLPOOL
416 {"whirlpool", D_WHIRLPOOL},
418 #ifndef OPENSSL_NO_RMD160
419 {"ripemd", D_RMD160},
420 {"rmd160", D_RMD160},
421 {"ripemd160", D_RMD160},
423 #ifndef OPENSSL_NO_RC4
426 #ifndef OPENSSL_NO_DES
427 {"des-cbc", D_CBC_DES},
428 {"des-ede3", D_EDE3_DES},
430 #ifndef OPENSSL_NO_AES
431 {"aes-128-cbc", D_CBC_128_AES},
432 {"aes-192-cbc", D_CBC_192_AES},
433 {"aes-256-cbc", D_CBC_256_AES},
434 {"aes-128-ige", D_IGE_128_AES},
435 {"aes-192-ige", D_IGE_192_AES},
436 {"aes-256-ige", D_IGE_256_AES},
438 #ifndef OPENSSL_NO_RC2
439 {"rc2-cbc", D_CBC_RC2},
442 #ifndef OPENSSL_NO_RC5
443 {"rc5-cbc", D_CBC_RC5},
446 #ifndef OPENSSL_NO_IDEA
447 {"idea-cbc", D_CBC_IDEA},
448 {"idea", D_CBC_IDEA},
450 #ifndef OPENSSL_NO_SEED
451 {"seed-cbc", D_CBC_SEED},
452 {"seed", D_CBC_SEED},
454 #ifndef OPENSSL_NO_BF
455 {"bf-cbc", D_CBC_BF},
456 {"blowfish", D_CBC_BF},
459 #ifndef OPENSSL_NO_CAST
460 {"cast-cbc", D_CBC_CAST},
461 {"cast", D_CBC_CAST},
462 {"cast5", D_CBC_CAST},
471 static OPT_PAIR dsa_choices[] = {
472 {"dsa512", R_DSA_512},
473 {"dsa1024", R_DSA_1024},
474 {"dsa2048", R_DSA_2048},
484 #define R_RSA_15360 6
485 static OPT_PAIR rsa_choices[] = {
486 {"rsa512", R_RSA_512},
487 {"rsa1024", R_RSA_1024},
488 {"rsa2048", R_RSA_2048},
489 {"rsa3072", R_RSA_3072},
490 {"rsa4096", R_RSA_4096},
491 {"rsa7680", R_RSA_7680},
492 {"rsa15360", R_RSA_15360},
512 #ifndef OPENSSL_NO_EC
513 static OPT_PAIR ecdsa_choices[] = {
514 {"ecdsap160", R_EC_P160},
515 {"ecdsap192", R_EC_P192},
516 {"ecdsap224", R_EC_P224},
517 {"ecdsap256", R_EC_P256},
518 {"ecdsap384", R_EC_P384},
519 {"ecdsap521", R_EC_P521},
520 {"ecdsak163", R_EC_K163},
521 {"ecdsak233", R_EC_K233},
522 {"ecdsak283", R_EC_K283},
523 {"ecdsak409", R_EC_K409},
524 {"ecdsak571", R_EC_K571},
525 {"ecdsab163", R_EC_B163},
526 {"ecdsab233", R_EC_B233},
527 {"ecdsab283", R_EC_B283},
528 {"ecdsab409", R_EC_B409},
529 {"ecdsab571", R_EC_B571},
532 static OPT_PAIR ecdh_choices[] = {
533 {"ecdhp160", R_EC_P160},
534 {"ecdhp192", R_EC_P192},
535 {"ecdhp224", R_EC_P224},
536 {"ecdhp256", R_EC_P256},
537 {"ecdhp384", R_EC_P384},
538 {"ecdhp521", R_EC_P521},
539 {"ecdhk163", R_EC_K163},
540 {"ecdhk233", R_EC_K233},
541 {"ecdhk283", R_EC_K283},
542 {"ecdhk409", R_EC_K409},
543 {"ecdhk571", R_EC_K571},
544 {"ecdhb163", R_EC_B163},
545 {"ecdhb233", R_EC_B233},
546 {"ecdhb283", R_EC_B283},
547 {"ecdhb409", R_EC_B409},
548 {"ecdhb571", R_EC_B571},
553 int speed_main(int argc, char **argv)
556 const EVP_CIPHER *evp_cipher = NULL;
557 const EVP_MD *evp_md = NULL;
560 int decrypt = 0, multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
561 int dsa_doit[DSA_NUM], rsa_doit[RSA_NUM];
562 int ret = 1, i, j, k, misalign = MAX_MISALIGNMENT + 1;
563 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
564 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
565 unsigned char *buf = NULL, *buf2 = NULL;
566 unsigned char md[EVP_MAX_MD_SIZE];
570 /* What follows are the buffers and key material. */
571 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
574 #ifndef OPENSSL_NO_MD2
575 unsigned char md2[MD2_DIGEST_LENGTH];
577 #ifndef OPENSSL_NO_MDC2
578 unsigned char mdc2[MDC2_DIGEST_LENGTH];
580 #ifndef OPENSSL_NO_MD4
581 unsigned char md4[MD4_DIGEST_LENGTH];
583 #ifndef OPENSSL_NO_MD5
584 unsigned char md5[MD5_DIGEST_LENGTH];
585 unsigned char hmac[MD5_DIGEST_LENGTH];
587 unsigned char sha[SHA_DIGEST_LENGTH];
588 unsigned char sha256[SHA256_DIGEST_LENGTH];
589 unsigned char sha512[SHA512_DIGEST_LENGTH];
590 #ifndef OPENSSL_NO_WHIRLPOOL
591 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
593 #ifndef OPENSSL_NO_RMD160
594 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
596 #ifndef OPENSSL_NO_RC4
599 #ifndef OPENSSL_NO_RC5
602 #ifndef OPENSSL_NO_RC2
605 #ifndef OPENSSL_NO_IDEA
606 IDEA_KEY_SCHEDULE idea_ks;
608 #ifndef OPENSSL_NO_SEED
609 SEED_KEY_SCHEDULE seed_ks;
611 #ifndef OPENSSL_NO_BF
614 #ifndef OPENSSL_NO_CAST
617 static const unsigned char key16[16] = {
618 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
619 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
621 #ifndef OPENSSL_NO_AES
622 static const unsigned char key24[24] = {
623 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
624 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
625 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
627 static const unsigned char key32[32] = {
628 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
629 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
630 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
631 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
634 #ifndef OPENSSL_NO_CAMELLIA
635 static const unsigned char ckey24[24] = {
636 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
637 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
638 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
640 static const unsigned char ckey32[32] = {
641 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
642 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
643 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
644 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
646 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
648 #ifndef OPENSSL_NO_AES
649 # define MAX_BLOCK_SIZE 128
651 # define MAX_BLOCK_SIZE 64
653 unsigned char DES_iv[8];
654 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
655 #ifndef OPENSSL_NO_DES
656 static DES_cblock key = {
657 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
659 static DES_cblock key2 = {
660 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
662 static DES_cblock key3 = {
663 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
665 DES_key_schedule sch;
666 DES_key_schedule sch2;
667 DES_key_schedule sch3;
669 #ifndef OPENSSL_NO_AES
670 AES_KEY aes_ks1, aes_ks2, aes_ks3;
672 #ifndef OPENSSL_NO_RSA
674 RSA *rsa_key[RSA_NUM];
675 long rsa_c[RSA_NUM][2];
676 static unsigned int rsa_bits[RSA_NUM] = {
677 512, 1024, 2048, 3072, 4096, 7680, 15360
679 static unsigned char *rsa_data[RSA_NUM] = {
680 test512, test1024, test2048, test3072, test4096, test7680, test15360
682 static int rsa_data_length[RSA_NUM] = {
683 sizeof(test512), sizeof(test1024),
684 sizeof(test2048), sizeof(test3072),
685 sizeof(test4096), sizeof(test7680),
689 #ifndef OPENSSL_NO_DSA
690 DSA *dsa_key[DSA_NUM];
691 long dsa_c[DSA_NUM][2];
692 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
694 #ifndef OPENSSL_NO_EC
696 * We only test over the following curves as they are representative, To
697 * add tests over more curves, simply add the curve NID and curve name to
698 * the following arrays and increase the EC_NUM value accordingly.
700 static unsigned int test_curves[EC_NUM] = {
702 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
703 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
705 NID_sect163k1, NID_sect233k1, NID_sect283k1,
706 NID_sect409k1, NID_sect571k1, NID_sect163r2,
707 NID_sect233r1, NID_sect283r1, NID_sect409r1,
710 static const char *test_curves_names[EC_NUM] = {
712 "secp160r1", "nistp192", "nistp224",
713 "nistp256", "nistp384", "nistp521",
715 "nistk163", "nistk233", "nistk283",
716 "nistk409", "nistk571", "nistb163",
717 "nistb233", "nistb283", "nistb409",
720 static int test_curves_bits[EC_NUM] = {
729 #ifndef OPENSSL_NO_EC
730 unsigned char ecdsasig[256];
731 unsigned int ecdsasiglen;
732 EC_KEY *ecdsa[EC_NUM];
733 long ecdsa_c[EC_NUM][2];
734 int ecdsa_doit[EC_NUM];
735 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
736 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
737 int secret_size_a, secret_size_b;
740 long ecdh_c[EC_NUM][2];
741 int ecdh_doit[EC_NUM];
744 memset(results, 0, sizeof(results));
745 #ifndef OPENSSL_NO_DSA
746 memset(dsa_key, 0, sizeof(dsa_key));
748 #ifndef OPENSSL_NO_EC
749 for (i = 0; i < EC_NUM; i++)
751 for (i = 0; i < EC_NUM; i++)
752 ecdh_a[i] = ecdh_b[i] = NULL;
754 #ifndef OPENSSL_NO_RSA
755 memset(rsa_key, 0, sizeof(rsa_key));
756 for (i = 0; i < RSA_NUM; i++)
760 memset(c, 0, sizeof(c));
761 memset(DES_iv, 0, sizeof(DES_iv));
762 memset(iv, 0, sizeof(iv));
764 for (i = 0; i < ALGOR_NUM; i++)
766 for (i = 0; i < RSA_NUM; i++)
768 for (i = 0; i < DSA_NUM; i++)
770 #ifndef OPENSSL_NO_EC
771 for (i = 0; i < EC_NUM; i++)
773 for (i = 0; i < EC_NUM; i++)
777 buf = buf_malloc = app_malloc((int)BUFSIZE + misalign, "input buffer");
778 buf2 = buf2_malloc = app_malloc((int)BUFSIZE + misalign, "output buffer");
781 prog = opt_init(argc, argv, speed_options);
782 while ((o = opt_next()) != OPT_EOF) {
787 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
790 opt_help(speed_options);
797 evp_cipher = EVP_get_cipherbyname(opt_arg());
798 if (evp_cipher == NULL)
799 evp_md = EVP_get_digestbyname(opt_arg());
800 if (evp_cipher == NULL && evp_md == NULL) {
802 "%s: %s an unknown cipher or digest\n",
812 (void)setup_engine(opt_arg(), 0);
816 multi = atoi(opt_arg());
820 if (!opt_int(opt_arg(), &misalign))
822 if (misalign > MISALIGN) {
824 "%s: Maximum offset is %d\n", prog, MISALIGN);
827 buf = buf_malloc + misalign;
828 buf2 = buf2_malloc + misalign;
838 argc = opt_num_rest();
841 /* Remaining arguments are algorithms. */
842 for ( ; *argv; argv++) {
843 if (found(*argv, doit_choices, &i)) {
847 #ifndef OPENSSL_NO_DES
848 if (strcmp(*argv, "des") == 0) {
849 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
853 if (strcmp(*argv, "sha") == 0) {
854 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
857 #ifndef OPENSSL_NO_RSA
859 if (strcmp(*argv, "openssl") == 0) {
860 RSA_set_default_method(RSA_PKCS1_OpenSSL());
864 if (strcmp(*argv, "rsa") == 0) {
865 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
866 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
867 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
868 rsa_doit[R_RSA_15360] = 1;
871 if (found(*argv, rsa_choices, &i)) {
876 #ifndef OPENSSL_NO_DSA
877 if (strcmp(*argv, "dsa") == 0) {
878 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
879 dsa_doit[R_DSA_2048] = 1;
882 if (found(*argv, dsa_choices, &i)) {
887 #ifndef OPENSSL_NO_AES
888 if (strcmp(*argv, "aes") == 0) {
889 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
890 doit[D_CBC_256_AES] = 1;
894 #ifndef OPENSSL_NO_CAMELLIA
895 if (strcmp(*argv, "camellia") == 0) {
896 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
897 doit[D_CBC_256_CML] = 1;
901 #ifndef OPENSSL_NO_EC
902 if (strcmp(*argv, "ecdsa") == 0) {
903 for (i = 0; i < EC_NUM; i++)
907 if (found(*argv, ecdsa_choices, &i)) {
911 if (strcmp(*argv, "ecdh") == 0) {
912 for (i = 0; i < EC_NUM; i++)
916 if (found(*argv, ecdh_choices, &i)) {
921 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
926 if (multi && do_multi(multi))
930 /* No parameters; turn on everything. */
931 if ((argc == 0) && !doit[D_EVP]) {
932 for (i = 0; i < ALGOR_NUM; i++)
935 for (i = 0; i < RSA_NUM; i++)
937 for (i = 0; i < DSA_NUM; i++)
939 #ifndef OPENSSL_NO_EC
940 for (i = 0; i < EC_NUM; i++)
942 for (i = 0; i < EC_NUM; i++)
946 for (i = 0; i < ALGOR_NUM; i++)
950 if (usertime == 0 && !mr)
952 "You have chosen to measure elapsed time "
953 "instead of user CPU time.\n");
955 #ifndef OPENSSL_NO_RSA
956 for (i = 0; i < RSA_NUM; i++) {
957 const unsigned char *p;
960 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
961 if (rsa_key[i] == NULL) {
962 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
969 #ifndef OPENSSL_NO_DSA
970 dsa_key[0] = get_dsa512();
971 dsa_key[1] = get_dsa1024();
972 dsa_key[2] = get_dsa2048();
975 #ifndef OPENSSL_NO_DES
976 DES_set_key_unchecked(&key, &sch);
977 DES_set_key_unchecked(&key2, &sch2);
978 DES_set_key_unchecked(&key3, &sch3);
980 #ifndef OPENSSL_NO_AES
981 AES_set_encrypt_key(key16, 128, &aes_ks1);
982 AES_set_encrypt_key(key24, 192, &aes_ks2);
983 AES_set_encrypt_key(key32, 256, &aes_ks3);
985 #ifndef OPENSSL_NO_CAMELLIA
986 Camellia_set_key(key16, 128, &camellia_ks1);
987 Camellia_set_key(ckey24, 192, &camellia_ks2);
988 Camellia_set_key(ckey32, 256, &camellia_ks3);
990 #ifndef OPENSSL_NO_IDEA
991 idea_set_encrypt_key(key16, &idea_ks);
993 #ifndef OPENSSL_NO_SEED
994 SEED_set_key(key16, &seed_ks);
996 #ifndef OPENSSL_NO_RC4
997 RC4_set_key(&rc4_ks, 16, key16);
999 #ifndef OPENSSL_NO_RC2
1000 RC2_set_key(&rc2_ks, 16, key16, 128);
1002 #ifndef OPENSSL_NO_RC5
1003 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1005 #ifndef OPENSSL_NO_BF
1006 BF_set_key(&bf_ks, 16, key16);
1008 #ifndef OPENSSL_NO_CAST
1009 CAST_set_key(&cast_ks, 16, key16);
1011 #ifndef OPENSSL_NO_RSA
1012 memset(rsa_c, 0, sizeof(rsa_c));
1015 # ifndef OPENSSL_NO_DES
1016 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1022 for (it = count; it; it--)
1023 DES_ecb_encrypt((DES_cblock *)buf,
1024 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1028 c[D_MD2][0] = count / 10;
1029 c[D_MDC2][0] = count / 10;
1030 c[D_MD4][0] = count;
1031 c[D_MD5][0] = count;
1032 c[D_HMAC][0] = count;
1033 c[D_SHA1][0] = count;
1034 c[D_RMD160][0] = count;
1035 c[D_RC4][0] = count * 5;
1036 c[D_CBC_DES][0] = count;
1037 c[D_EDE3_DES][0] = count / 3;
1038 c[D_CBC_IDEA][0] = count;
1039 c[D_CBC_SEED][0] = count;
1040 c[D_CBC_RC2][0] = count;
1041 c[D_CBC_RC5][0] = count;
1042 c[D_CBC_BF][0] = count;
1043 c[D_CBC_CAST][0] = count;
1044 c[D_CBC_128_AES][0] = count;
1045 c[D_CBC_192_AES][0] = count;
1046 c[D_CBC_256_AES][0] = count;
1047 c[D_CBC_128_CML][0] = count;
1048 c[D_CBC_192_CML][0] = count;
1049 c[D_CBC_256_CML][0] = count;
1050 c[D_SHA256][0] = count;
1051 c[D_SHA512][0] = count;
1052 c[D_WHIRLPOOL][0] = count;
1053 c[D_IGE_128_AES][0] = count;
1054 c[D_IGE_192_AES][0] = count;
1055 c[D_IGE_256_AES][0] = count;
1056 c[D_GHASH][0] = count;
1058 for (i = 1; i < SIZE_NUM; i++) {
1061 l0 = (long)lengths[0];
1062 l1 = (long)lengths[i];
1064 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1065 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1066 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1067 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1068 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1069 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1070 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1071 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1072 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1073 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1075 l0 = (long)lengths[i - 1];
1077 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1078 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1079 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1080 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1081 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1082 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1083 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1084 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1085 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1086 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1087 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1088 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1089 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1090 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1091 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1092 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1093 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1094 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1097 # ifndef OPENSSL_NO_RSA
1098 rsa_c[R_RSA_512][0] = count / 2000;
1099 rsa_c[R_RSA_512][1] = count / 400;
1100 for (i = 1; i < RSA_NUM; i++) {
1101 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1102 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1103 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1106 if (rsa_c[i][0] == 0) {
1114 # ifndef OPENSSL_NO_DSA
1115 dsa_c[R_DSA_512][0] = count / 1000;
1116 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1117 for (i = 1; i < DSA_NUM; i++) {
1118 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1119 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1120 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1123 if (dsa_c[i] == 0) {
1131 # ifndef OPENSSL_NO_EC
1132 ecdsa_c[R_EC_P160][0] = count / 1000;
1133 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1134 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1135 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1136 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1137 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1140 if (ecdsa_c[i] == 0) {
1146 ecdsa_c[R_EC_K163][0] = count / 1000;
1147 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1148 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1149 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1150 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1151 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1154 if (ecdsa_c[i] == 0) {
1160 ecdsa_c[R_EC_B163][0] = count / 1000;
1161 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1162 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1163 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1164 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1165 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1168 if (ecdsa_c[i] == 0) {
1175 ecdh_c[R_EC_P160][0] = count / 1000;
1176 ecdh_c[R_EC_P160][1] = count / 1000;
1177 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1178 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1179 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1180 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1183 if (ecdh_c[i] == 0) {
1189 ecdh_c[R_EC_K163][0] = count / 1000;
1190 ecdh_c[R_EC_K163][1] = count / 1000;
1191 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1192 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1193 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1194 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1197 if (ecdh_c[i] == 0) {
1203 ecdh_c[R_EC_B163][0] = count / 1000;
1204 ecdh_c[R_EC_B163][1] = count / 1000;
1205 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1206 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1207 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1208 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1211 if (ecdh_c[i] == 0) {
1219 # define COND(d) (count < (d))
1220 # define COUNT(d) (d)
1222 /* not worth fixing */
1223 # error "You cannot disable DES on systems without SIGALRM."
1224 # endif /* OPENSSL_NO_DES */
1226 # define COND(c) (run && count<0x7fffffff)
1227 # define COUNT(d) (count)
1229 signal(SIGALRM, sig_done);
1231 #endif /* SIGALRM */
1233 #ifndef OPENSSL_NO_MD2
1235 for (j = 0; j < SIZE_NUM; j++) {
1236 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1238 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1239 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1242 print_result(D_MD2, j, count, d);
1246 #ifndef OPENSSL_NO_MDC2
1248 for (j = 0; j < SIZE_NUM; j++) {
1249 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1251 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1252 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1255 print_result(D_MDC2, j, count, d);
1260 #ifndef OPENSSL_NO_MD4
1262 for (j = 0; j < SIZE_NUM; j++) {
1263 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1265 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1266 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1267 NULL, EVP_md4(), NULL);
1269 print_result(D_MD4, j, count, d);
1274 #ifndef OPENSSL_NO_MD5
1276 for (j = 0; j < SIZE_NUM; j++) {
1277 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1279 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1280 MD5(buf, lengths[j], md5);
1282 print_result(D_MD5, j, count, d);
1287 #if !defined(OPENSSL_NO_MD5)
1289 HMAC_CTX *hctx = NULL;
1291 hctx = HMAC_CTX_new();
1293 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1296 HMAC_Init_ex(hctx, (unsigned char *)"This is a key...",
1297 16, EVP_md5(), NULL);
1299 for (j = 0; j < SIZE_NUM; j++) {
1300 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1302 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1303 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
1304 HMAC_Update(hctx, buf, lengths[j]);
1305 HMAC_Final(hctx, &(hmac[0]), NULL);
1308 print_result(D_HMAC, j, count, d);
1310 HMAC_CTX_free(hctx);
1314 for (j = 0; j < SIZE_NUM; j++) {
1315 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1317 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1318 SHA1(buf, lengths[j], sha);
1320 print_result(D_SHA1, j, count, d);
1323 if (doit[D_SHA256]) {
1324 for (j = 0; j < SIZE_NUM; j++) {
1325 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1327 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1328 SHA256(buf, lengths[j], sha256);
1330 print_result(D_SHA256, j, count, d);
1333 if (doit[D_SHA512]) {
1334 for (j = 0; j < SIZE_NUM; j++) {
1335 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1337 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1338 SHA512(buf, lengths[j], sha512);
1340 print_result(D_SHA512, j, count, d);
1344 #ifndef OPENSSL_NO_WHIRLPOOL
1345 if (doit[D_WHIRLPOOL]) {
1346 for (j = 0; j < SIZE_NUM; j++) {
1347 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1349 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1350 WHIRLPOOL(buf, lengths[j], whirlpool);
1352 print_result(D_WHIRLPOOL, j, count, d);
1357 #ifndef OPENSSL_NO_RMD160
1358 if (doit[D_RMD160]) {
1359 for (j = 0; j < SIZE_NUM; j++) {
1360 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1362 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1363 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1364 EVP_ripemd160(), NULL);
1366 print_result(D_RMD160, j, count, d);
1370 #ifndef OPENSSL_NO_RC4
1372 for (j = 0; j < SIZE_NUM; j++) {
1373 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1375 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1376 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1378 print_result(D_RC4, j, count, d);
1382 #ifndef OPENSSL_NO_DES
1383 if (doit[D_CBC_DES]) {
1384 for (j = 0; j < SIZE_NUM; j++) {
1385 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1387 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1388 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1389 &DES_iv, DES_ENCRYPT);
1391 print_result(D_CBC_DES, j, count, d);
1395 if (doit[D_EDE3_DES]) {
1396 for (j = 0; j < SIZE_NUM; j++) {
1397 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1399 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1400 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1402 &DES_iv, DES_ENCRYPT);
1404 print_result(D_EDE3_DES, j, count, d);
1408 #ifndef OPENSSL_NO_AES
1409 if (doit[D_CBC_128_AES]) {
1410 for (j = 0; j < SIZE_NUM; j++) {
1411 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1414 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1415 AES_cbc_encrypt(buf, buf,
1416 (unsigned long)lengths[j], &aes_ks1,
1419 print_result(D_CBC_128_AES, j, count, d);
1422 if (doit[D_CBC_192_AES]) {
1423 for (j = 0; j < SIZE_NUM; j++) {
1424 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1427 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1428 AES_cbc_encrypt(buf, buf,
1429 (unsigned long)lengths[j], &aes_ks2,
1432 print_result(D_CBC_192_AES, j, count, d);
1435 if (doit[D_CBC_256_AES]) {
1436 for (j = 0; j < SIZE_NUM; j++) {
1437 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1440 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1441 AES_cbc_encrypt(buf, buf,
1442 (unsigned long)lengths[j], &aes_ks3,
1445 print_result(D_CBC_256_AES, j, count, d);
1449 if (doit[D_IGE_128_AES]) {
1450 for (j = 0; j < SIZE_NUM; j++) {
1451 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1454 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1455 AES_ige_encrypt(buf, buf2,
1456 (unsigned long)lengths[j], &aes_ks1,
1459 print_result(D_IGE_128_AES, j, count, d);
1462 if (doit[D_IGE_192_AES]) {
1463 for (j = 0; j < SIZE_NUM; j++) {
1464 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1467 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1468 AES_ige_encrypt(buf, buf2,
1469 (unsigned long)lengths[j], &aes_ks2,
1472 print_result(D_IGE_192_AES, j, count, d);
1475 if (doit[D_IGE_256_AES]) {
1476 for (j = 0; j < SIZE_NUM; j++) {
1477 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1480 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1481 AES_ige_encrypt(buf, buf2,
1482 (unsigned long)lengths[j], &aes_ks3,
1485 print_result(D_IGE_256_AES, j, count, d);
1488 if (doit[D_GHASH]) {
1489 GCM128_CONTEXT *ctx =
1490 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1491 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1493 for (j = 0; j < SIZE_NUM; j++) {
1494 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1496 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1497 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1499 print_result(D_GHASH, j, count, d);
1501 CRYPTO_gcm128_release(ctx);
1504 #ifndef OPENSSL_NO_CAMELLIA
1505 if (doit[D_CBC_128_CML]) {
1506 for (j = 0; j < SIZE_NUM; j++) {
1507 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1510 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1511 Camellia_cbc_encrypt(buf, buf,
1512 (unsigned long)lengths[j], &camellia_ks1,
1513 iv, CAMELLIA_ENCRYPT);
1515 print_result(D_CBC_128_CML, j, count, d);
1518 if (doit[D_CBC_192_CML]) {
1519 for (j = 0; j < SIZE_NUM; j++) {
1520 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1523 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1524 Camellia_cbc_encrypt(buf, buf,
1525 (unsigned long)lengths[j], &camellia_ks2,
1526 iv, CAMELLIA_ENCRYPT);
1528 print_result(D_CBC_192_CML, j, count, d);
1531 if (doit[D_CBC_256_CML]) {
1532 for (j = 0; j < SIZE_NUM; j++) {
1533 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1536 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1537 Camellia_cbc_encrypt(buf, buf,
1538 (unsigned long)lengths[j], &camellia_ks3,
1539 iv, CAMELLIA_ENCRYPT);
1541 print_result(D_CBC_256_CML, j, count, d);
1545 #ifndef OPENSSL_NO_IDEA
1546 if (doit[D_CBC_IDEA]) {
1547 for (j = 0; j < SIZE_NUM; j++) {
1548 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1550 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1551 idea_cbc_encrypt(buf, buf,
1552 (unsigned long)lengths[j], &idea_ks,
1555 print_result(D_CBC_IDEA, j, count, d);
1559 #ifndef OPENSSL_NO_SEED
1560 if (doit[D_CBC_SEED]) {
1561 for (j = 0; j < SIZE_NUM; j++) {
1562 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1564 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1565 SEED_cbc_encrypt(buf, buf,
1566 (unsigned long)lengths[j], &seed_ks, iv, 1);
1568 print_result(D_CBC_SEED, j, count, d);
1572 #ifndef OPENSSL_NO_RC2
1573 if (doit[D_CBC_RC2]) {
1574 for (j = 0; j < SIZE_NUM; j++) {
1575 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1577 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1578 RC2_cbc_encrypt(buf, buf,
1579 (unsigned long)lengths[j], &rc2_ks,
1582 print_result(D_CBC_RC2, j, count, d);
1586 #ifndef OPENSSL_NO_RC5
1587 if (doit[D_CBC_RC5]) {
1588 for (j = 0; j < SIZE_NUM; j++) {
1589 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1591 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1592 RC5_32_cbc_encrypt(buf, buf,
1593 (unsigned long)lengths[j], &rc5_ks,
1596 print_result(D_CBC_RC5, j, count, d);
1600 #ifndef OPENSSL_NO_BF
1601 if (doit[D_CBC_BF]) {
1602 for (j = 0; j < SIZE_NUM; j++) {
1603 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1605 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1606 BF_cbc_encrypt(buf, buf,
1607 (unsigned long)lengths[j], &bf_ks,
1610 print_result(D_CBC_BF, j, count, d);
1614 #ifndef OPENSSL_NO_CAST
1615 if (doit[D_CBC_CAST]) {
1616 for (j = 0; j < SIZE_NUM; j++) {
1617 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1619 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1620 CAST_cbc_encrypt(buf, buf,
1621 (unsigned long)lengths[j], &cast_ks,
1624 print_result(D_CBC_CAST, j, count, d);
1630 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1631 if (multiblock && evp_cipher) {
1633 (EVP_CIPHER_flags(evp_cipher) &
1634 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1635 BIO_printf(bio_err, "%s is not multi-block capable\n",
1636 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1639 multiblock_speed(evp_cipher);
1644 for (j = 0; j < SIZE_NUM; j++) {
1646 EVP_CIPHER_CTX *ctx;
1649 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
1651 * -O3 -fschedule-insns messes up an optimization here!
1652 * names[D_EVP] somehow becomes NULL
1654 print_message(names[D_EVP], save_count, lengths[j]);
1656 ctx = EVP_CIPHER_CTX_new();
1658 EVP_DecryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
1660 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
1661 EVP_CIPHER_CTX_set_padding(ctx, 0);
1665 for (count = 0, run = 1;
1666 COND(save_count * 4 * lengths[0] / lengths[j]);
1668 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1670 for (count = 0, run = 1;
1671 COND(save_count * 4 * lengths[0] / lengths[j]);
1673 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1675 EVP_DecryptFinal_ex(ctx, buf, &outl);
1677 EVP_EncryptFinal_ex(ctx, buf, &outl);
1679 EVP_CIPHER_CTX_free(ctx);
1682 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
1683 print_message(names[D_EVP], save_count, lengths[j]);
1686 for (count = 0, run = 1;
1687 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1688 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1692 print_result(D_EVP, j, count, d);
1696 RAND_bytes(buf, 36);
1697 #ifndef OPENSSL_NO_RSA
1698 for (j = 0; j < RSA_NUM; j++) {
1702 st = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1705 "RSA sign failure. No RSA sign will be done.\n");
1706 ERR_print_errors(bio_err);
1709 pkey_print_message("private", "rsa",
1710 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
1711 /* RSA_blinding_on(rsa_key[j],NULL); */
1713 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1714 st = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1715 &rsa_num, rsa_key[j]);
1717 BIO_printf(bio_err, "RSA sign failure\n");
1718 ERR_print_errors(bio_err);
1725 mr ? "+R1:%ld:%d:%.2f\n"
1726 : "%ld %d bit private RSA's in %.2fs\n",
1727 count, rsa_bits[j], d);
1728 rsa_results[j][0] = d / (double)count;
1732 st = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1735 "RSA verify failure. No RSA verify will be done.\n");
1736 ERR_print_errors(bio_err);
1739 pkey_print_message("public", "rsa",
1740 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
1742 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1743 st = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1744 rsa_num, rsa_key[j]);
1746 BIO_printf(bio_err, "RSA verify failure\n");
1747 ERR_print_errors(bio_err);
1754 mr ? "+R2:%ld:%d:%.2f\n"
1755 : "%ld %d bit public RSA's in %.2fs\n",
1756 count, rsa_bits[j], d);
1757 rsa_results[j][1] = d / (double)count;
1760 if (rsa_count <= 1) {
1761 /* if longer than 10s, don't do any more */
1762 for (j++; j < RSA_NUM; j++)
1768 RAND_bytes(buf, 20);
1769 #ifndef OPENSSL_NO_DSA
1770 if (RAND_status() != 1) {
1771 RAND_seed(rnd_seed, sizeof rnd_seed);
1774 for (j = 0; j < DSA_NUM; j++) {
1781 /* DSA_generate_key(dsa_key[j]); */
1782 /* DSA_sign_setup(dsa_key[j],NULL); */
1783 st = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
1786 "DSA sign failure. No DSA sign will be done.\n");
1787 ERR_print_errors(bio_err);
1790 pkey_print_message("sign", "dsa",
1791 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
1793 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
1794 st = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
1796 BIO_printf(bio_err, "DSA sign failure\n");
1797 ERR_print_errors(bio_err);
1804 mr ? "+R3:%ld:%d:%.2f\n"
1805 : "%ld %d bit DSA signs in %.2fs\n",
1806 count, dsa_bits[j], d);
1807 dsa_results[j][0] = d / (double)count;
1811 st = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
1814 "DSA verify failure. No DSA verify will be done.\n");
1815 ERR_print_errors(bio_err);
1818 pkey_print_message("verify", "dsa",
1819 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
1821 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
1822 st = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
1824 BIO_printf(bio_err, "DSA verify failure\n");
1825 ERR_print_errors(bio_err);
1832 mr ? "+R4:%ld:%d:%.2f\n"
1833 : "%ld %d bit DSA verify in %.2fs\n",
1834 count, dsa_bits[j], d);
1835 dsa_results[j][1] = d / (double)count;
1838 if (rsa_count <= 1) {
1839 /* if longer than 10s, don't do any more */
1840 for (j++; j < DSA_NUM; j++)
1848 #ifndef OPENSSL_NO_EC
1849 if (RAND_status() != 1) {
1850 RAND_seed(rnd_seed, sizeof rnd_seed);
1853 for (j = 0; j < EC_NUM; j++) {
1857 continue; /* Ignore Curve */
1858 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1859 if (ecdsa[j] == NULL) {
1860 BIO_printf(bio_err, "ECDSA failure.\n");
1861 ERR_print_errors(bio_err);
1864 EC_KEY_precompute_mult(ecdsa[j], NULL);
1865 /* Perform ECDSA signature test */
1866 EC_KEY_generate_key(ecdsa[j]);
1867 st = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
1870 "ECDSA sign failure. No ECDSA sign will be done.\n");
1871 ERR_print_errors(bio_err);
1874 pkey_print_message("sign", "ecdsa",
1876 test_curves_bits[j], ECDSA_SECONDS);
1879 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
1880 st = ECDSA_sign(0, buf, 20,
1881 ecdsasig, &ecdsasiglen, ecdsa[j]);
1883 BIO_printf(bio_err, "ECDSA sign failure\n");
1884 ERR_print_errors(bio_err);
1892 mr ? "+R5:%ld:%d:%.2f\n" :
1893 "%ld %d bit ECDSA signs in %.2fs \n",
1894 count, test_curves_bits[j], d);
1895 ecdsa_results[j][0] = d / (double)count;
1899 /* Perform ECDSA verification test */
1900 st = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
1903 "ECDSA verify failure. No ECDSA verify will be done.\n");
1904 ERR_print_errors(bio_err);
1907 pkey_print_message("verify", "ecdsa",
1909 test_curves_bits[j], ECDSA_SECONDS);
1911 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
1912 st = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1915 BIO_printf(bio_err, "ECDSA verify failure\n");
1916 ERR_print_errors(bio_err);
1923 mr ? "+R6:%ld:%d:%.2f\n"
1924 : "%ld %d bit ECDSA verify in %.2fs\n",
1925 count, test_curves_bits[j], d);
1926 ecdsa_results[j][1] = d / (double)count;
1929 if (rsa_count <= 1) {
1930 /* if longer than 10s, don't do any more */
1931 for (j++; j < EC_NUM; j++)
1940 #ifndef OPENSSL_NO_EC
1941 if (RAND_status() != 1) {
1942 RAND_seed(rnd_seed, sizeof rnd_seed);
1945 for (j = 0; j < EC_NUM; j++) {
1948 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1949 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1950 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
1951 BIO_printf(bio_err, "ECDH failure.\n");
1952 ERR_print_errors(bio_err);
1955 /* generate two ECDH key pairs */
1956 if (!EC_KEY_generate_key(ecdh_a[j]) ||
1957 !EC_KEY_generate_key(ecdh_b[j])) {
1958 BIO_printf(bio_err, "ECDH key generation failure.\n");
1959 ERR_print_errors(bio_err);
1963 * If field size is not more than 24 octets, then use SHA-1
1964 * hash of result; otherwise, use result (see section 4.8 of
1965 * draft-ietf-tls-ecc-03.txt).
1967 int field_size, outlen;
1968 void *(*kdf) (const void *in, size_t inlen, void *out,
1971 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
1972 if (field_size <= 24 * 8) {
1973 outlen = KDF1_SHA1_len;
1976 outlen = (field_size + 7) / 8;
1980 ECDH_compute_key(secret_a, outlen,
1981 EC_KEY_get0_public_key(ecdh_b[j]),
1984 ECDH_compute_key(secret_b, outlen,
1985 EC_KEY_get0_public_key(ecdh_a[j]),
1987 if (secret_size_a != secret_size_b)
1992 for (secret_idx = 0; (secret_idx < secret_size_a)
1993 && (ecdh_checks == 1); secret_idx++) {
1994 if (secret_a[secret_idx] != secret_b[secret_idx])
1998 if (ecdh_checks == 0) {
1999 BIO_printf(bio_err, "ECDH computations don't match.\n");
2000 ERR_print_errors(bio_err);
2004 pkey_print_message("", "ecdh",
2006 test_curves_bits[j], ECDH_SECONDS);
2008 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2009 ECDH_compute_key(secret_a, outlen,
2010 EC_KEY_get0_public_key(ecdh_b[j]),
2015 mr ? "+R7:%ld:%d:%.2f\n" :
2016 "%ld %d-bit ECDH ops in %.2fs\n", count,
2017 test_curves_bits[j], d);
2018 ecdh_results[j][0] = d / (double)count;
2023 if (rsa_count <= 1) {
2024 /* if longer than 10s, don't do any more */
2025 for (j++; j < EC_NUM; j++)
2036 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2037 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2039 printf("%s ", BN_options());
2040 #ifndef OPENSSL_NO_MD2
2041 printf("%s ", MD2_options());
2043 #ifndef OPENSSL_NO_RC4
2044 printf("%s ", RC4_options());
2046 #ifndef OPENSSL_NO_DES
2047 printf("%s ", DES_options());
2049 #ifndef OPENSSL_NO_AES
2050 printf("%s ", AES_options());
2052 #ifndef OPENSSL_NO_IDEA
2053 printf("%s ", idea_options());
2055 #ifndef OPENSSL_NO_BF
2056 printf("%s ", BF_options());
2058 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2066 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2069 for (j = 0; j < SIZE_NUM; j++)
2070 printf(mr ? ":%d" : "%7d bytes", lengths[j]);
2074 for (k = 0; k < ALGOR_NUM; k++) {
2078 printf("+F:%d:%s", k, names[k]);
2080 printf("%-13s", names[k]);
2081 for (j = 0; j < SIZE_NUM; j++) {
2082 if (results[k][j] > 10000 && !mr)
2083 printf(" %11.2fk", results[k][j] / 1e3);
2085 printf(mr ? ":%.2f" : " %11.2f ", results[k][j]);
2089 #ifndef OPENSSL_NO_RSA
2091 for (k = 0; k < RSA_NUM; k++) {
2095 printf("%18ssign verify sign/s verify/s\n", " ");
2099 printf("+F2:%u:%u:%f:%f\n",
2100 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2102 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2103 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2104 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2107 #ifndef OPENSSL_NO_DSA
2109 for (k = 0; k < DSA_NUM; k++) {
2113 printf("%18ssign verify sign/s verify/s\n", " ");
2117 printf("+F3:%u:%u:%f:%f\n",
2118 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2120 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2121 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2122 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2125 #ifndef OPENSSL_NO_EC
2127 for (k = 0; k < EC_NUM; k++) {
2131 printf("%30ssign verify sign/s verify/s\n", " ");
2136 printf("+F4:%u:%u:%f:%f\n",
2137 k, test_curves_bits[k],
2138 ecdsa_results[k][0], ecdsa_results[k][1]);
2140 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2141 test_curves_bits[k],
2142 test_curves_names[k],
2143 ecdsa_results[k][0], ecdsa_results[k][1],
2144 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2148 #ifndef OPENSSL_NO_EC
2150 for (k = 0; k < EC_NUM; k++) {
2154 printf("%30sop op/s\n", " ");
2158 printf("+F5:%u:%u:%f:%f\n",
2159 k, test_curves_bits[k],
2160 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2163 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2164 test_curves_bits[k],
2165 test_curves_names[k],
2166 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2173 ERR_print_errors(bio_err);
2174 OPENSSL_free(buf_malloc);
2175 OPENSSL_free(buf2_malloc);
2176 #ifndef OPENSSL_NO_RSA
2177 for (i = 0; i < RSA_NUM; i++)
2178 RSA_free(rsa_key[i]);
2180 #ifndef OPENSSL_NO_DSA
2181 for (i = 0; i < DSA_NUM; i++)
2182 DSA_free(dsa_key[i]);
2185 #ifndef OPENSSL_NO_EC
2186 for (i = 0; i < EC_NUM; i++) {
2187 EC_KEY_free(ecdsa[i]);
2188 EC_KEY_free(ecdh_a[i]);
2189 EC_KEY_free(ecdh_b[i]);
2195 static void print_message(const char *s, long num, int length)
2199 mr ? "+DT:%s:%d:%d\n"
2200 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2201 (void)BIO_flush(bio_err);
2205 mr ? "+DN:%s:%ld:%d\n"
2206 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2207 (void)BIO_flush(bio_err);
2211 static void pkey_print_message(const char *str, const char *str2, long num,
2216 mr ? "+DTP:%d:%s:%s:%d\n"
2217 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2218 (void)BIO_flush(bio_err);
2222 mr ? "+DNP:%ld:%d:%s:%s\n"
2223 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2224 (void)BIO_flush(bio_err);
2228 static void print_result(int alg, int run_no, int count, double time_used)
2231 mr ? "+R:%d:%s:%f\n"
2232 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2233 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2237 static char *sstrsep(char **string, const char *delim)
2240 char *token = *string;
2245 memset(isdelim, 0, sizeof isdelim);
2249 isdelim[(unsigned char)(*delim)] = 1;
2253 while (!isdelim[(unsigned char)(**string)]) {
2265 static int do_multi(int multi)
2270 static char sep[] = ":";
2272 fds = malloc(sizeof(*fds) * multi);
2273 for (n = 0; n < multi; ++n) {
2274 if (pipe(fd) == -1) {
2275 BIO_printf(bio_err, "pipe failure\n");
2279 (void)BIO_flush(bio_err);
2286 if (dup(fd[1]) == -1) {
2287 BIO_printf(bio_err, "dup failed\n");
2296 printf("Forked child %d\n", n);
2299 /* for now, assume the pipe is long enough to take all the output */
2300 for (n = 0; n < multi; ++n) {
2305 f = fdopen(fds[n], "r");
2306 while (fgets(buf, sizeof buf, f)) {
2307 p = strchr(buf, '\n');
2310 if (buf[0] != '+') {
2311 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2315 printf("Got: %s from %d\n", buf, n);
2316 if (strncmp(buf, "+F:", 3) == 0) {
2321 alg = atoi(sstrsep(&p, sep));
2323 for (j = 0; j < SIZE_NUM; ++j)
2324 results[alg][j] += atof(sstrsep(&p, sep));
2325 } else if (strncmp(buf, "+F2:", 4) == 0) {
2330 k = atoi(sstrsep(&p, sep));
2333 d = atof(sstrsep(&p, sep));
2335 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2337 rsa_results[k][0] = d;
2339 d = atof(sstrsep(&p, sep));
2341 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2343 rsa_results[k][1] = d;
2345 # ifndef OPENSSL_NO_DSA
2346 else if (strncmp(buf, "+F3:", 4) == 0) {
2351 k = atoi(sstrsep(&p, sep));
2354 d = atof(sstrsep(&p, sep));
2356 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2358 dsa_results[k][0] = d;
2360 d = atof(sstrsep(&p, sep));
2362 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2364 dsa_results[k][1] = d;
2367 # ifndef OPENSSL_NO_EC
2368 else if (strncmp(buf, "+F4:", 4) == 0) {
2373 k = atoi(sstrsep(&p, sep));
2376 d = atof(sstrsep(&p, sep));
2378 ecdsa_results[k][0] =
2379 1 / (1 / ecdsa_results[k][0] + 1 / d);
2381 ecdsa_results[k][0] = d;
2383 d = atof(sstrsep(&p, sep));
2385 ecdsa_results[k][1] =
2386 1 / (1 / ecdsa_results[k][1] + 1 / d);
2388 ecdsa_results[k][1] = d;
2392 # ifndef OPENSSL_NO_EC
2393 else if (strncmp(buf, "+F5:", 4) == 0) {
2398 k = atoi(sstrsep(&p, sep));
2401 d = atof(sstrsep(&p, sep));
2403 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2405 ecdh_results[k][0] = d;
2410 else if (strncmp(buf, "+H:", 3) == 0) {
2413 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
2423 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2425 static int mblengths[] =
2426 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2427 int j, count, num = OSSL_NELEM(lengths);
2428 const char *alg_name;
2429 unsigned char *inp, *out, no_key[32], no_iv[16];
2430 EVP_CIPHER_CTX *ctx;
2433 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
2434 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
2435 ctx = EVP_CIPHER_CTX_new();
2436 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
2437 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2439 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2441 for (j = 0; j < num; j++) {
2442 print_message(alg_name, 0, mblengths[j]);
2444 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2445 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
2446 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2447 size_t len = mblengths[j];
2450 memset(aad, 0, 8); /* avoid uninitialized values */
2451 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2452 aad[9] = 3; /* version */
2454 aad[11] = 0; /* length */
2456 mb_param.out = NULL;
2459 mb_param.interleave = 8;
2461 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2462 sizeof(mb_param), &mb_param);
2468 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2469 sizeof(mb_param), &mb_param);
2473 RAND_bytes(out, 16);
2477 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
2478 EVP_AEAD_TLS1_AAD_LEN, aad);
2479 EVP_Cipher(ctx, out, inp, len + pad);
2483 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
2484 : "%d %s's in %.2fs\n", count, "evp", d);
2485 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2489 fprintf(stdout, "+H");
2490 for (j = 0; j < num; j++)
2491 fprintf(stdout, ":%d", mblengths[j]);
2492 fprintf(stdout, "\n");
2493 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2494 for (j = 0; j < num; j++)
2495 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2496 fprintf(stdout, "\n");
2499 "The 'numbers' are in 1000s of bytes per second processed.\n");
2500 fprintf(stdout, "type ");
2501 for (j = 0; j < num; j++)
2502 fprintf(stdout, "%7d bytes", mblengths[j]);
2503 fprintf(stdout, "\n");
2504 fprintf(stdout, "%-24s", alg_name);
2506 for (j = 0; j < num; j++) {
2507 if (results[D_EVP][j] > 10000)
2508 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2510 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2512 fprintf(stdout, "\n");
2517 EVP_CIPHER_CTX_free(ctx);