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
97 #if defined(_WIN32) || defined(__CYGWIN__)
99 # if defined(__CYGWIN__) && !defined(_WIN32)
101 * <windows.h> should define _WIN32, which normally is mutually exclusive
102 * with __CYGWIN__, but if it didn't...
105 /* this is done because Cygwin alarm() fails sometimes. */
109 #include <openssl/bn.h>
110 #ifndef OPENSSL_NO_DES
111 # include <openssl/des.h>
113 #ifndef OPENSSL_NO_AES
114 # include <openssl/aes.h>
116 #ifndef OPENSSL_NO_CAMELLIA
117 # include <openssl/camellia.h>
119 #ifndef OPENSSL_NO_MD2
120 # include <openssl/md2.h>
122 #ifndef OPENSSL_NO_MDC2
123 # include <openssl/mdc2.h>
125 #ifndef OPENSSL_NO_MD4
126 # include <openssl/md4.h>
128 #ifndef OPENSSL_NO_MD5
129 # include <openssl/md5.h>
131 #include <openssl/hmac.h>
132 #include <openssl/evp.h>
133 #include <openssl/sha.h>
134 #ifndef OPENSSL_NO_RMD160
135 # include <openssl/ripemd.h>
137 #ifndef OPENSSL_NO_WHIRLPOOL
138 # include <openssl/whrlpool.h>
140 #ifndef OPENSSL_NO_RC4
141 # include <openssl/rc4.h>
143 #ifndef OPENSSL_NO_RC5
144 # include <openssl/rc5.h>
146 #ifndef OPENSSL_NO_RC2
147 # include <openssl/rc2.h>
149 #ifndef OPENSSL_NO_IDEA
150 # include <openssl/idea.h>
152 #ifndef OPENSSL_NO_SEED
153 # include <openssl/seed.h>
155 #ifndef OPENSSL_NO_BF
156 # include <openssl/blowfish.h>
158 #ifndef OPENSSL_NO_CAST
159 # include <openssl/cast.h>
161 #ifndef OPENSSL_NO_RSA
162 # include <openssl/rsa.h>
163 # include "./testrsa.h"
165 #include <openssl/x509.h>
166 #ifndef OPENSSL_NO_DSA
167 # include <openssl/dsa.h>
168 # include "./testdsa.h"
170 #ifndef OPENSSL_NO_EC
171 # include <openssl/ecdsa.h>
172 # include <openssl/ecdh.h>
174 #include <openssl/modes.h>
176 #include <openssl/bn.h>
179 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
193 #define BUFSIZE (1024*8+1)
194 #define MAX_MISALIGNMENT 63
196 static volatile int run = 0;
199 static int usertime = 1;
201 static double Time_F(int s);
202 static void print_message(const char *s, long num, int length);
203 static void pkey_print_message(const char *str, const char *str2,
204 long num, int bits, int sec);
205 static void print_result(int alg, int run_no, int count, double time_used);
207 static int do_multi(int multi);
217 #define MAX_ECDH_SIZE 256
220 static const char *names[ALGOR_NUM] = {
221 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
222 "des cbc", "des ede3", "idea cbc", "seed cbc",
223 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
224 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
225 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
226 "evp", "sha256", "sha512", "whirlpool",
227 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
230 static double results[ALGOR_NUM][SIZE_NUM];
231 static int lengths[SIZE_NUM] = {
232 16, 64, 256, 1024, 8 * 1024
235 #ifndef OPENSSL_NO_RSA
236 static double rsa_results[RSA_NUM][2];
238 #ifndef OPENSSL_NO_DSA
239 static double dsa_results[DSA_NUM][2];
241 #ifndef OPENSSL_NO_EC
242 static double ecdsa_results[EC_NUM][2];
243 static double ecdh_results[EC_NUM][1];
246 #if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
247 static const char rnd_seed[] =
248 "string to make the random number generator think it has entropy";
249 static int rnd_fake = 0;
253 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
254 # define SIGRETTYPE void
256 # define SIGRETTYPE int
259 static SIGRETTYPE sig_done(int sig);
260 static SIGRETTYPE sig_done(int sig)
262 signal(SIGALRM, sig_done);
272 # if !defined(SIGALRM)
275 static unsigned int lapse, schlock;
276 static void alarm_win32(unsigned int secs)
281 # define alarm alarm_win32
283 static DWORD WINAPI sleepy(VOID * arg)
291 static double Time_F(int s)
298 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
300 DWORD err = GetLastError();
301 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
305 Sleep(0); /* scheduler spinlock */
306 ret = app_tminterval(s, usertime);
308 ret = app_tminterval(s, usertime);
310 TerminateThread(thr, 0);
318 static double Time_F(int s)
320 double ret = app_tminterval(s, usertime);
327 #ifndef OPENSSL_NO_EC
328 static const int KDF1_SHA1_len = 20;
329 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
332 if (*outlen < SHA_DIGEST_LENGTH)
334 *outlen = SHA_DIGEST_LENGTH;
335 return SHA1(in, inlen, out);
337 #endif /* OPENSSL_NO_EC */
339 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
341 static int found(const char *name, const OPT_PAIR * pairs, int *result)
343 for (; pairs->name; pairs++)
344 if (strcmp(name, pairs->name) == 0) {
345 *result = pairs->retval;
351 typedef enum OPTION_choice {
352 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
353 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
354 OPT_MR, OPT_MB, OPT_MISALIGN
357 OPTIONS speed_options[] = {
358 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
359 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
360 {"help", OPT_HELP, '-', "Display this summary"},
361 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
362 {"decrypt", OPT_DECRYPT, '-',
363 "Time decryption instead of encryption (only EVP)"},
364 {"mr", OPT_MR, '-', "Produce machine readable output"},
366 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
367 {"elapsed", OPT_ELAPSED, '-',
368 "Measure time in real time instead of CPU user time"},
370 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
372 #ifndef OPENSSL_NO_ENGINE
373 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
388 #define D_CBC_IDEA 10
389 #define D_CBC_SEED 11
393 #define D_CBC_CAST 15
394 #define D_CBC_128_AES 16
395 #define D_CBC_192_AES 17
396 #define D_CBC_256_AES 18
397 #define D_CBC_128_CML 19
398 #define D_CBC_192_CML 20
399 #define D_CBC_256_CML 21
403 #define D_WHIRLPOOL 25
404 #define D_IGE_128_AES 26
405 #define D_IGE_192_AES 27
406 #define D_IGE_256_AES 28
408 static OPT_PAIR doit_choices[] = {
409 #ifndef OPENSSL_NO_MD2
412 #ifndef OPENSSL_NO_MDC2
415 #ifndef OPENSSL_NO_MD4
418 #ifndef OPENSSL_NO_MD5
421 #ifndef OPENSSL_NO_MD5
425 {"sha256", D_SHA256},
426 {"sha512", D_SHA512},
427 #ifndef OPENSSL_NO_WHIRLPOOL
428 {"whirlpool", D_WHIRLPOOL},
430 #ifndef OPENSSL_NO_RMD160
431 {"ripemd", D_RMD160},
432 {"rmd160", D_RMD160},
433 {"ripemd160", D_RMD160},
435 #ifndef OPENSSL_NO_RC4
438 #ifndef OPENSSL_NO_DES
439 {"des-cbc", D_CBC_DES},
440 {"des-ede3", D_EDE3_DES},
442 #ifndef OPENSSL_NO_AES
443 {"aes-128-cbc", D_CBC_128_AES},
444 {"aes-192-cbc", D_CBC_192_AES},
445 {"aes-256-cbc", D_CBC_256_AES},
446 {"aes-128-ige", D_IGE_128_AES},
447 {"aes-192-ige", D_IGE_192_AES},
448 {"aes-256-ige", D_IGE_256_AES},
450 #ifndef OPENSSL_NO_RC2
451 {"rc2-cbc", D_CBC_RC2},
454 #ifndef OPENSSL_NO_RC5
455 {"rc5-cbc", D_CBC_RC5},
458 #ifndef OPENSSL_NO_IDEA
459 {"idea-cbc", D_CBC_IDEA},
460 {"idea", D_CBC_IDEA},
462 #ifndef OPENSSL_NO_SEED
463 {"seed-cbc", D_CBC_SEED},
464 {"seed", D_CBC_SEED},
466 #ifndef OPENSSL_NO_BF
467 {"bf-cbc", D_CBC_BF},
468 {"blowfish", D_CBC_BF},
471 #ifndef OPENSSL_NO_CAST
472 {"cast-cbc", D_CBC_CAST},
473 {"cast", D_CBC_CAST},
474 {"cast5", D_CBC_CAST},
483 static OPT_PAIR dsa_choices[] = {
484 {"dsa512", R_DSA_512},
485 {"dsa1024", R_DSA_1024},
486 {"dsa2048", R_DSA_2048},
496 #define R_RSA_15360 6
497 static OPT_PAIR rsa_choices[] = {
498 {"rsa512", R_RSA_512},
499 {"rsa1024", R_RSA_1024},
500 {"rsa2048", R_RSA_2048},
501 {"rsa3072", R_RSA_3072},
502 {"rsa4096", R_RSA_4096},
503 {"rsa7680", R_RSA_7680},
504 {"rsa15360", R_RSA_15360},
524 #ifndef OPENSSL_NO_EC
525 static OPT_PAIR ecdsa_choices[] = {
526 {"ecdsap160", R_EC_P160},
527 {"ecdsap192", R_EC_P192},
528 {"ecdsap224", R_EC_P224},
529 {"ecdsap256", R_EC_P256},
530 {"ecdsap384", R_EC_P384},
531 {"ecdsap521", R_EC_P521},
532 {"ecdsak163", R_EC_K163},
533 {"ecdsak233", R_EC_K233},
534 {"ecdsak283", R_EC_K283},
535 {"ecdsak409", R_EC_K409},
536 {"ecdsak571", R_EC_K571},
537 {"ecdsab163", R_EC_B163},
538 {"ecdsab233", R_EC_B233},
539 {"ecdsab283", R_EC_B283},
540 {"ecdsab409", R_EC_B409},
541 {"ecdsab571", R_EC_B571},
544 static OPT_PAIR ecdh_choices[] = {
545 {"ecdhp160", R_EC_P160},
546 {"ecdhp192", R_EC_P192},
547 {"ecdhp224", R_EC_P224},
548 {"ecdhp256", R_EC_P256},
549 {"ecdhp384", R_EC_P384},
550 {"ecdhp521", R_EC_P521},
551 {"ecdhk163", R_EC_K163},
552 {"ecdhk233", R_EC_K233},
553 {"ecdhk283", R_EC_K283},
554 {"ecdhk409", R_EC_K409},
555 {"ecdhk571", R_EC_K571},
556 {"ecdhb163", R_EC_B163},
557 {"ecdhb233", R_EC_B233},
558 {"ecdhb283", R_EC_B283},
559 {"ecdhb409", R_EC_B409},
560 {"ecdhb571", R_EC_B571},
565 int speed_main(int argc, char **argv)
568 const EVP_CIPHER *evp_cipher = NULL;
569 const EVP_MD *evp_md = NULL;
572 int decrypt = 0, multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
573 int dsa_doit[DSA_NUM], rsa_doit[RSA_NUM];
574 int ret = 1, i, j, k, misalign = MAX_MISALIGNMENT + 1;
575 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
576 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
577 unsigned char *buf = NULL, *buf2 = NULL;
578 unsigned char md[EVP_MAX_MD_SIZE];
582 /* What follows are the buffers and key material. */
583 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
586 #ifndef OPENSSL_NO_MD2
587 unsigned char md2[MD2_DIGEST_LENGTH];
589 #ifndef OPENSSL_NO_MDC2
590 unsigned char mdc2[MDC2_DIGEST_LENGTH];
592 #ifndef OPENSSL_NO_MD4
593 unsigned char md4[MD4_DIGEST_LENGTH];
595 #ifndef OPENSSL_NO_MD5
596 unsigned char md5[MD5_DIGEST_LENGTH];
597 unsigned char hmac[MD5_DIGEST_LENGTH];
599 unsigned char sha[SHA_DIGEST_LENGTH];
600 unsigned char sha256[SHA256_DIGEST_LENGTH];
601 unsigned char sha512[SHA512_DIGEST_LENGTH];
602 #ifndef OPENSSL_NO_WHIRLPOOL
603 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
605 #ifndef OPENSSL_NO_RMD160
606 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
608 #ifndef OPENSSL_NO_RC4
611 #ifndef OPENSSL_NO_RC5
614 #ifndef OPENSSL_NO_RC2
617 #ifndef OPENSSL_NO_IDEA
618 IDEA_KEY_SCHEDULE idea_ks;
620 #ifndef OPENSSL_NO_SEED
621 SEED_KEY_SCHEDULE seed_ks;
623 #ifndef OPENSSL_NO_BF
626 #ifndef OPENSSL_NO_CAST
629 static const unsigned char key16[16] = {
630 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
631 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
633 #ifndef OPENSSL_NO_AES
634 static const unsigned char key24[24] = {
635 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
636 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
637 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
639 static const unsigned char key32[32] = {
640 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
641 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
642 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
643 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
646 #ifndef OPENSSL_NO_CAMELLIA
647 static const unsigned char ckey24[24] = {
648 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
649 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
650 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
652 static const unsigned char ckey32[32] = {
653 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
654 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
655 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
656 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
658 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
660 #ifndef OPENSSL_NO_AES
661 # define MAX_BLOCK_SIZE 128
663 # define MAX_BLOCK_SIZE 64
665 unsigned char DES_iv[8];
666 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
667 #ifndef OPENSSL_NO_DES
668 static DES_cblock key = {
669 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
671 static DES_cblock key2 = {
672 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
674 static DES_cblock key3 = {
675 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
677 DES_key_schedule sch;
678 DES_key_schedule sch2;
679 DES_key_schedule sch3;
681 #ifndef OPENSSL_NO_AES
682 AES_KEY aes_ks1, aes_ks2, aes_ks3;
684 #ifndef OPENSSL_NO_RSA
686 RSA *rsa_key[RSA_NUM];
687 long rsa_c[RSA_NUM][2];
688 static unsigned int rsa_bits[RSA_NUM] = {
689 512, 1024, 2048, 3072, 4096, 7680, 15360
691 static unsigned char *rsa_data[RSA_NUM] = {
692 test512, test1024, test2048, test3072, test4096, test7680, test15360
694 static int rsa_data_length[RSA_NUM] = {
695 sizeof(test512), sizeof(test1024),
696 sizeof(test2048), sizeof(test3072),
697 sizeof(test4096), sizeof(test7680),
701 #ifndef OPENSSL_NO_DSA
702 DSA *dsa_key[DSA_NUM];
703 long dsa_c[DSA_NUM][2];
704 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
706 #ifndef OPENSSL_NO_EC
708 * We only test over the following curves as they are representative, To
709 * add tests over more curves, simply add the curve NID and curve name to
710 * the following arrays and increase the EC_NUM value accordingly.
712 static unsigned int test_curves[EC_NUM] = {
714 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
715 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
717 NID_sect163k1, NID_sect233k1, NID_sect283k1,
718 NID_sect409k1, NID_sect571k1, NID_sect163r2,
719 NID_sect233r1, NID_sect283r1, NID_sect409r1,
722 static const char *test_curves_names[EC_NUM] = {
724 "secp160r1", "nistp192", "nistp224",
725 "nistp256", "nistp384", "nistp521",
727 "nistk163", "nistk233", "nistk283",
728 "nistk409", "nistk571", "nistb163",
729 "nistb233", "nistb283", "nistb409",
732 static int test_curves_bits[EC_NUM] = {
741 #ifndef OPENSSL_NO_EC
742 unsigned char ecdsasig[256];
743 unsigned int ecdsasiglen;
744 EC_KEY *ecdsa[EC_NUM];
745 long ecdsa_c[EC_NUM][2];
746 int ecdsa_doit[EC_NUM];
747 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
748 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
749 int secret_size_a, secret_size_b;
752 long ecdh_c[EC_NUM][2];
753 int ecdh_doit[EC_NUM];
756 memset(results, 0, sizeof(results));
757 #ifndef OPENSSL_NO_DSA
758 memset(dsa_key, 0, sizeof(dsa_key));
760 #ifndef OPENSSL_NO_EC
761 for (i = 0; i < EC_NUM; i++)
763 for (i = 0; i < EC_NUM; i++)
764 ecdh_a[i] = ecdh_b[i] = NULL;
766 #ifndef OPENSSL_NO_RSA
767 memset(rsa_key, 0, sizeof(rsa_key));
768 for (i = 0; i < RSA_NUM; i++)
772 memset(c, 0, sizeof(c));
773 memset(DES_iv, 0, sizeof(DES_iv));
774 memset(iv, 0, sizeof(iv));
776 for (i = 0; i < ALGOR_NUM; i++)
778 for (i = 0; i < RSA_NUM; i++)
780 for (i = 0; i < DSA_NUM; i++)
782 #ifndef OPENSSL_NO_EC
783 for (i = 0; i < EC_NUM; i++)
785 for (i = 0; i < EC_NUM; i++)
789 buf = buf_malloc = app_malloc((int)BUFSIZE + misalign, "input buffer");
790 buf2 = buf2_malloc = app_malloc((int)BUFSIZE + misalign, "output buffer");
793 prog = opt_init(argc, argv, speed_options);
794 while ((o = opt_next()) != OPT_EOF) {
799 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
802 opt_help(speed_options);
809 evp_cipher = EVP_get_cipherbyname(opt_arg());
810 if (evp_cipher == NULL)
811 evp_md = EVP_get_digestbyname(opt_arg());
812 if (evp_cipher == NULL && evp_md == NULL) {
814 "%s: %s an unknown cipher or digest\n",
824 (void)setup_engine(opt_arg(), 0);
828 multi = atoi(opt_arg());
832 if (!opt_int(opt_arg(), &misalign))
834 if (misalign > MISALIGN) {
836 "%s: Maximum offset is %d\n", prog, MISALIGN);
839 buf = buf_malloc + misalign;
840 buf2 = buf2_malloc + misalign;
850 argc = opt_num_rest();
853 /* Remaining arguments are algorithms. */
854 for ( ; *argv; argv++) {
855 if (found(*argv, doit_choices, &i)) {
859 #ifndef OPENSSL_NO_DES
860 if (strcmp(*argv, "des") == 0) {
861 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
865 if (strcmp(*argv, "sha") == 0) {
866 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
869 #ifndef OPENSSL_NO_RSA
871 if (strcmp(*argv, "openssl") == 0) {
872 RSA_set_default_method(RSA_PKCS1_SSLeay());
876 if (strcmp(*argv, "rsa") == 0) {
877 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
878 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
879 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
880 rsa_doit[R_RSA_15360] = 1;
883 if (found(*argv, rsa_choices, &i)) {
888 #ifndef OPENSSL_NO_DSA
889 if (strcmp(*argv, "dsa") == 0) {
890 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
891 dsa_doit[R_DSA_2048] = 1;
894 if (found(*argv, dsa_choices, &i)) {
899 #ifndef OPENSSL_NO_AES
900 if (strcmp(*argv, "aes") == 0) {
901 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
902 doit[D_CBC_256_AES] = 1;
906 #ifndef OPENSSL_NO_CAMELLIA
907 if (strcmp(*argv, "camellia") == 0) {
908 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
909 doit[D_CBC_256_CML] = 1;
913 #ifndef OPENSSL_NO_EC
914 if (strcmp(*argv, "ecdsa") == 0) {
915 for (i = 0; i < EC_NUM; i++)
919 if (found(*argv, ecdsa_choices, &i)) {
923 if (strcmp(*argv, "ecdh") == 0) {
924 for (i = 0; i < EC_NUM; i++)
928 if (found(*argv, ecdh_choices, &i)) {
933 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
938 if (multi && do_multi(multi))
942 /* No parameters; turn on everything. */
943 if ((argc == 0) && !doit[D_EVP]) {
944 for (i = 0; i < ALGOR_NUM; i++)
947 for (i = 0; i < RSA_NUM; i++)
949 for (i = 0; i < DSA_NUM; i++)
951 #ifndef OPENSSL_NO_EC
952 for (i = 0; i < EC_NUM; i++)
954 for (i = 0; i < EC_NUM; i++)
958 for (i = 0; i < ALGOR_NUM; i++)
962 if (usertime == 0 && !mr)
964 "You have chosen to measure elapsed time "
965 "instead of user CPU time.\n");
967 #ifndef OPENSSL_NO_RSA
968 for (i = 0; i < RSA_NUM; i++) {
969 const unsigned char *p;
972 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
973 if (rsa_key[i] == NULL) {
974 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
981 #ifndef OPENSSL_NO_DSA
982 dsa_key[0] = get_dsa512();
983 dsa_key[1] = get_dsa1024();
984 dsa_key[2] = get_dsa2048();
987 #ifndef OPENSSL_NO_DES
988 DES_set_key_unchecked(&key, &sch);
989 DES_set_key_unchecked(&key2, &sch2);
990 DES_set_key_unchecked(&key3, &sch3);
992 #ifndef OPENSSL_NO_AES
993 AES_set_encrypt_key(key16, 128, &aes_ks1);
994 AES_set_encrypt_key(key24, 192, &aes_ks2);
995 AES_set_encrypt_key(key32, 256, &aes_ks3);
997 #ifndef OPENSSL_NO_CAMELLIA
998 Camellia_set_key(key16, 128, &camellia_ks1);
999 Camellia_set_key(ckey24, 192, &camellia_ks2);
1000 Camellia_set_key(ckey32, 256, &camellia_ks3);
1002 #ifndef OPENSSL_NO_IDEA
1003 idea_set_encrypt_key(key16, &idea_ks);
1005 #ifndef OPENSSL_NO_SEED
1006 SEED_set_key(key16, &seed_ks);
1008 #ifndef OPENSSL_NO_RC4
1009 RC4_set_key(&rc4_ks, 16, key16);
1011 #ifndef OPENSSL_NO_RC2
1012 RC2_set_key(&rc2_ks, 16, key16, 128);
1014 #ifndef OPENSSL_NO_RC5
1015 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1017 #ifndef OPENSSL_NO_BF
1018 BF_set_key(&bf_ks, 16, key16);
1020 #ifndef OPENSSL_NO_CAST
1021 CAST_set_key(&cast_ks, 16, key16);
1023 #ifndef OPENSSL_NO_RSA
1024 memset(rsa_c, 0, sizeof(rsa_c));
1027 # ifndef OPENSSL_NO_DES
1028 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1034 for (it = count; it; it--)
1035 DES_ecb_encrypt((DES_cblock *)buf,
1036 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1040 c[D_MD2][0] = count / 10;
1041 c[D_MDC2][0] = count / 10;
1042 c[D_MD4][0] = count;
1043 c[D_MD5][0] = count;
1044 c[D_HMAC][0] = count;
1045 c[D_SHA1][0] = count;
1046 c[D_RMD160][0] = count;
1047 c[D_RC4][0] = count * 5;
1048 c[D_CBC_DES][0] = count;
1049 c[D_EDE3_DES][0] = count / 3;
1050 c[D_CBC_IDEA][0] = count;
1051 c[D_CBC_SEED][0] = count;
1052 c[D_CBC_RC2][0] = count;
1053 c[D_CBC_RC5][0] = count;
1054 c[D_CBC_BF][0] = count;
1055 c[D_CBC_CAST][0] = count;
1056 c[D_CBC_128_AES][0] = count;
1057 c[D_CBC_192_AES][0] = count;
1058 c[D_CBC_256_AES][0] = count;
1059 c[D_CBC_128_CML][0] = count;
1060 c[D_CBC_192_CML][0] = count;
1061 c[D_CBC_256_CML][0] = count;
1062 c[D_SHA256][0] = count;
1063 c[D_SHA512][0] = count;
1064 c[D_WHIRLPOOL][0] = count;
1065 c[D_IGE_128_AES][0] = count;
1066 c[D_IGE_192_AES][0] = count;
1067 c[D_IGE_256_AES][0] = count;
1068 c[D_GHASH][0] = count;
1070 for (i = 1; i < SIZE_NUM; i++) {
1073 l0 = (long)lengths[0];
1074 l1 = (long)lengths[i];
1076 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1077 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1078 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1079 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1080 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1081 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1082 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1083 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1084 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1085 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1087 l0 = (long)lengths[i - 1];
1089 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1090 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1091 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1092 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1093 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1094 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1095 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1096 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1097 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1098 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1099 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1100 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1101 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1102 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1103 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1104 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1105 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1106 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1109 # ifndef OPENSSL_NO_RSA
1110 rsa_c[R_RSA_512][0] = count / 2000;
1111 rsa_c[R_RSA_512][1] = count / 400;
1112 for (i = 1; i < RSA_NUM; i++) {
1113 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1114 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1115 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1118 if (rsa_c[i][0] == 0) {
1126 # ifndef OPENSSL_NO_DSA
1127 dsa_c[R_DSA_512][0] = count / 1000;
1128 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1129 for (i = 1; i < DSA_NUM; i++) {
1130 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1131 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1132 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1135 if (dsa_c[i] == 0) {
1143 # ifndef OPENSSL_NO_EC
1144 ecdsa_c[R_EC_P160][0] = count / 1000;
1145 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1146 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1147 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1148 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1149 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1152 if (ecdsa_c[i] == 0) {
1158 ecdsa_c[R_EC_K163][0] = count / 1000;
1159 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1160 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1161 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1162 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1163 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1166 if (ecdsa_c[i] == 0) {
1172 ecdsa_c[R_EC_B163][0] = count / 1000;
1173 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1174 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1175 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1176 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1177 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1180 if (ecdsa_c[i] == 0) {
1187 ecdh_c[R_EC_P160][0] = count / 1000;
1188 ecdh_c[R_EC_P160][1] = count / 1000;
1189 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1190 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1191 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1192 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1195 if (ecdh_c[i] == 0) {
1201 ecdh_c[R_EC_K163][0] = count / 1000;
1202 ecdh_c[R_EC_K163][1] = count / 1000;
1203 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1204 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1205 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1206 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1209 if (ecdh_c[i] == 0) {
1215 ecdh_c[R_EC_B163][0] = count / 1000;
1216 ecdh_c[R_EC_B163][1] = count / 1000;
1217 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1218 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1219 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1220 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1223 if (ecdh_c[i] == 0) {
1231 # define COND(d) (count < (d))
1232 # define COUNT(d) (d)
1234 /* not worth fixing */
1235 # error "You cannot disable DES on systems without SIGALRM."
1236 # endif /* OPENSSL_NO_DES */
1238 # define COND(c) (run && count<0x7fffffff)
1239 # define COUNT(d) (count)
1241 signal(SIGALRM, sig_done);
1243 #endif /* SIGALRM */
1245 #ifndef OPENSSL_NO_MD2
1247 for (j = 0; j < SIZE_NUM; j++) {
1248 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1250 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1251 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1254 print_result(D_MD2, j, count, d);
1258 #ifndef OPENSSL_NO_MDC2
1260 for (j = 0; j < SIZE_NUM; j++) {
1261 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1263 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1264 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1267 print_result(D_MDC2, j, count, d);
1272 #ifndef OPENSSL_NO_MD4
1274 for (j = 0; j < SIZE_NUM; j++) {
1275 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1277 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1278 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1279 NULL, EVP_md4(), NULL);
1281 print_result(D_MD4, j, count, d);
1286 #ifndef OPENSSL_NO_MD5
1288 for (j = 0; j < SIZE_NUM; j++) {
1289 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1291 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1292 MD5(buf, lengths[j], md5);
1294 print_result(D_MD5, j, count, d);
1299 #if !defined(OPENSSL_NO_MD5)
1303 HMAC_CTX_init(&hctx);
1304 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1305 16, EVP_md5(), NULL);
1307 for (j = 0; j < SIZE_NUM; j++) {
1308 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1310 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1311 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1312 HMAC_Update(&hctx, buf, lengths[j]);
1313 HMAC_Final(&hctx, &(hmac[0]), NULL);
1316 print_result(D_HMAC, j, count, d);
1318 HMAC_CTX_cleanup(&hctx);
1322 for (j = 0; j < SIZE_NUM; j++) {
1323 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1325 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1326 SHA1(buf, lengths[j], sha);
1328 print_result(D_SHA1, j, count, d);
1331 if (doit[D_SHA256]) {
1332 for (j = 0; j < SIZE_NUM; j++) {
1333 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1335 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1336 SHA256(buf, lengths[j], sha256);
1338 print_result(D_SHA256, j, count, d);
1341 if (doit[D_SHA512]) {
1342 for (j = 0; j < SIZE_NUM; j++) {
1343 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1345 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1346 SHA512(buf, lengths[j], sha512);
1348 print_result(D_SHA512, j, count, d);
1352 #ifndef OPENSSL_NO_WHIRLPOOL
1353 if (doit[D_WHIRLPOOL]) {
1354 for (j = 0; j < SIZE_NUM; j++) {
1355 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1357 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1358 WHIRLPOOL(buf, lengths[j], whirlpool);
1360 print_result(D_WHIRLPOOL, j, count, d);
1365 #ifndef OPENSSL_NO_RMD160
1366 if (doit[D_RMD160]) {
1367 for (j = 0; j < SIZE_NUM; j++) {
1368 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1370 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1371 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1372 EVP_ripemd160(), NULL);
1374 print_result(D_RMD160, j, count, d);
1378 #ifndef OPENSSL_NO_RC4
1380 for (j = 0; j < SIZE_NUM; j++) {
1381 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1383 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1384 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1386 print_result(D_RC4, j, count, d);
1390 #ifndef OPENSSL_NO_DES
1391 if (doit[D_CBC_DES]) {
1392 for (j = 0; j < SIZE_NUM; j++) {
1393 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1395 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1396 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1397 &DES_iv, DES_ENCRYPT);
1399 print_result(D_CBC_DES, j, count, d);
1403 if (doit[D_EDE3_DES]) {
1404 for (j = 0; j < SIZE_NUM; j++) {
1405 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1407 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1408 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1410 &DES_iv, DES_ENCRYPT);
1412 print_result(D_EDE3_DES, j, count, d);
1416 #ifndef OPENSSL_NO_AES
1417 if (doit[D_CBC_128_AES]) {
1418 for (j = 0; j < SIZE_NUM; j++) {
1419 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1422 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1423 AES_cbc_encrypt(buf, buf,
1424 (unsigned long)lengths[j], &aes_ks1,
1427 print_result(D_CBC_128_AES, j, count, d);
1430 if (doit[D_CBC_192_AES]) {
1431 for (j = 0; j < SIZE_NUM; j++) {
1432 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1435 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1436 AES_cbc_encrypt(buf, buf,
1437 (unsigned long)lengths[j], &aes_ks2,
1440 print_result(D_CBC_192_AES, j, count, d);
1443 if (doit[D_CBC_256_AES]) {
1444 for (j = 0; j < SIZE_NUM; j++) {
1445 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1448 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1449 AES_cbc_encrypt(buf, buf,
1450 (unsigned long)lengths[j], &aes_ks3,
1453 print_result(D_CBC_256_AES, j, count, d);
1457 if (doit[D_IGE_128_AES]) {
1458 for (j = 0; j < SIZE_NUM; j++) {
1459 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1462 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1463 AES_ige_encrypt(buf, buf2,
1464 (unsigned long)lengths[j], &aes_ks1,
1467 print_result(D_IGE_128_AES, j, count, d);
1470 if (doit[D_IGE_192_AES]) {
1471 for (j = 0; j < SIZE_NUM; j++) {
1472 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1475 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1476 AES_ige_encrypt(buf, buf2,
1477 (unsigned long)lengths[j], &aes_ks2,
1480 print_result(D_IGE_192_AES, j, count, d);
1483 if (doit[D_IGE_256_AES]) {
1484 for (j = 0; j < SIZE_NUM; j++) {
1485 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1488 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1489 AES_ige_encrypt(buf, buf2,
1490 (unsigned long)lengths[j], &aes_ks3,
1493 print_result(D_IGE_256_AES, j, count, d);
1496 if (doit[D_GHASH]) {
1497 GCM128_CONTEXT *ctx =
1498 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1499 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1501 for (j = 0; j < SIZE_NUM; j++) {
1502 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1504 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1505 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1507 print_result(D_GHASH, j, count, d);
1509 CRYPTO_gcm128_release(ctx);
1512 #ifndef OPENSSL_NO_CAMELLIA
1513 if (doit[D_CBC_128_CML]) {
1514 for (j = 0; j < SIZE_NUM; j++) {
1515 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1518 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1519 Camellia_cbc_encrypt(buf, buf,
1520 (unsigned long)lengths[j], &camellia_ks1,
1521 iv, CAMELLIA_ENCRYPT);
1523 print_result(D_CBC_128_CML, j, count, d);
1526 if (doit[D_CBC_192_CML]) {
1527 for (j = 0; j < SIZE_NUM; j++) {
1528 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1531 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1532 Camellia_cbc_encrypt(buf, buf,
1533 (unsigned long)lengths[j], &camellia_ks2,
1534 iv, CAMELLIA_ENCRYPT);
1536 print_result(D_CBC_192_CML, j, count, d);
1539 if (doit[D_CBC_256_CML]) {
1540 for (j = 0; j < SIZE_NUM; j++) {
1541 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1544 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1545 Camellia_cbc_encrypt(buf, buf,
1546 (unsigned long)lengths[j], &camellia_ks3,
1547 iv, CAMELLIA_ENCRYPT);
1549 print_result(D_CBC_256_CML, j, count, d);
1553 #ifndef OPENSSL_NO_IDEA
1554 if (doit[D_CBC_IDEA]) {
1555 for (j = 0; j < SIZE_NUM; j++) {
1556 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1558 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1559 idea_cbc_encrypt(buf, buf,
1560 (unsigned long)lengths[j], &idea_ks,
1563 print_result(D_CBC_IDEA, j, count, d);
1567 #ifndef OPENSSL_NO_SEED
1568 if (doit[D_CBC_SEED]) {
1569 for (j = 0; j < SIZE_NUM; j++) {
1570 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1572 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1573 SEED_cbc_encrypt(buf, buf,
1574 (unsigned long)lengths[j], &seed_ks, iv, 1);
1576 print_result(D_CBC_SEED, j, count, d);
1580 #ifndef OPENSSL_NO_RC2
1581 if (doit[D_CBC_RC2]) {
1582 for (j = 0; j < SIZE_NUM; j++) {
1583 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1585 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1586 RC2_cbc_encrypt(buf, buf,
1587 (unsigned long)lengths[j], &rc2_ks,
1590 print_result(D_CBC_RC2, j, count, d);
1594 #ifndef OPENSSL_NO_RC5
1595 if (doit[D_CBC_RC5]) {
1596 for (j = 0; j < SIZE_NUM; j++) {
1597 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1599 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1600 RC5_32_cbc_encrypt(buf, buf,
1601 (unsigned long)lengths[j], &rc5_ks,
1604 print_result(D_CBC_RC5, j, count, d);
1608 #ifndef OPENSSL_NO_BF
1609 if (doit[D_CBC_BF]) {
1610 for (j = 0; j < SIZE_NUM; j++) {
1611 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1613 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1614 BF_cbc_encrypt(buf, buf,
1615 (unsigned long)lengths[j], &bf_ks,
1618 print_result(D_CBC_BF, j, count, d);
1622 #ifndef OPENSSL_NO_CAST
1623 if (doit[D_CBC_CAST]) {
1624 for (j = 0; j < SIZE_NUM; j++) {
1625 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1627 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1628 CAST_cbc_encrypt(buf, buf,
1629 (unsigned long)lengths[j], &cast_ks,
1632 print_result(D_CBC_CAST, j, count, d);
1638 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1639 if (multiblock && evp_cipher) {
1641 (EVP_CIPHER_flags(evp_cipher) &
1642 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1643 BIO_printf(bio_err, "%s is not multi-block capable\n",
1644 OBJ_nid2ln(evp_cipher->nid));
1647 multiblock_speed(evp_cipher);
1652 for (j = 0; j < SIZE_NUM; j++) {
1657 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1659 * -O3 -fschedule-insns messes up an optimization here!
1660 * names[D_EVP] somehow becomes NULL
1662 print_message(names[D_EVP], save_count, lengths[j]);
1664 EVP_CIPHER_CTX_init(&ctx);
1666 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1668 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1669 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1673 for (count = 0, run = 1;
1674 COND(save_count * 4 * lengths[0] / lengths[j]);
1676 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1678 for (count = 0, run = 1;
1679 COND(save_count * 4 * lengths[0] / lengths[j]);
1681 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1683 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1685 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1687 EVP_CIPHER_CTX_cleanup(&ctx);
1690 names[D_EVP] = OBJ_nid2ln(evp_md->type);
1691 print_message(names[D_EVP], save_count, lengths[j]);
1694 for (count = 0, run = 1;
1695 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1696 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1700 print_result(D_EVP, j, count, d);
1704 RAND_bytes(buf, 36);
1705 #ifndef OPENSSL_NO_RSA
1706 for (j = 0; j < RSA_NUM; j++) {
1710 st = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1713 "RSA sign failure. No RSA sign will be done.\n");
1714 ERR_print_errors(bio_err);
1717 pkey_print_message("private", "rsa",
1718 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
1719 /* RSA_blinding_on(rsa_key[j],NULL); */
1721 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1722 st = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1723 &rsa_num, rsa_key[j]);
1725 BIO_printf(bio_err, "RSA sign failure\n");
1726 ERR_print_errors(bio_err);
1733 mr ? "+R1:%ld:%d:%.2f\n"
1734 : "%ld %d bit private RSA's in %.2fs\n",
1735 count, rsa_bits[j], d);
1736 rsa_results[j][0] = d / (double)count;
1740 st = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1743 "RSA verify failure. No RSA verify will be done.\n");
1744 ERR_print_errors(bio_err);
1747 pkey_print_message("public", "rsa",
1748 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
1750 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1751 st = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1752 rsa_num, rsa_key[j]);
1754 BIO_printf(bio_err, "RSA verify failure\n");
1755 ERR_print_errors(bio_err);
1762 mr ? "+R2:%ld:%d:%.2f\n"
1763 : "%ld %d bit public RSA's in %.2fs\n",
1764 count, rsa_bits[j], d);
1765 rsa_results[j][1] = d / (double)count;
1768 if (rsa_count <= 1) {
1769 /* if longer than 10s, don't do any more */
1770 for (j++; j < RSA_NUM; j++)
1776 RAND_bytes(buf, 20);
1777 #ifndef OPENSSL_NO_DSA
1778 if (RAND_status() != 1) {
1779 RAND_seed(rnd_seed, sizeof rnd_seed);
1782 for (j = 0; j < DSA_NUM; j++) {
1789 /* DSA_generate_key(dsa_key[j]); */
1790 /* DSA_sign_setup(dsa_key[j],NULL); */
1791 st = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
1794 "DSA sign failure. No DSA sign will be done.\n");
1795 ERR_print_errors(bio_err);
1798 pkey_print_message("sign", "dsa",
1799 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
1801 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
1802 st = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
1804 BIO_printf(bio_err, "DSA sign failure\n");
1805 ERR_print_errors(bio_err);
1812 mr ? "+R3:%ld:%d:%.2f\n"
1813 : "%ld %d bit DSA signs in %.2fs\n",
1814 count, dsa_bits[j], d);
1815 dsa_results[j][0] = d / (double)count;
1819 st = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
1822 "DSA verify failure. No DSA verify will be done.\n");
1823 ERR_print_errors(bio_err);
1826 pkey_print_message("verify", "dsa",
1827 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
1829 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
1830 st = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
1832 BIO_printf(bio_err, "DSA verify failure\n");
1833 ERR_print_errors(bio_err);
1840 mr ? "+R4:%ld:%d:%.2f\n"
1841 : "%ld %d bit DSA verify in %.2fs\n",
1842 count, dsa_bits[j], d);
1843 dsa_results[j][1] = d / (double)count;
1846 if (rsa_count <= 1) {
1847 /* if longer than 10s, don't do any more */
1848 for (j++; j < DSA_NUM; j++)
1856 #ifndef OPENSSL_NO_EC
1857 if (RAND_status() != 1) {
1858 RAND_seed(rnd_seed, sizeof rnd_seed);
1861 for (j = 0; j < EC_NUM; j++) {
1865 continue; /* Ignore Curve */
1866 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1867 if (ecdsa[j] == NULL) {
1868 BIO_printf(bio_err, "ECDSA failure.\n");
1869 ERR_print_errors(bio_err);
1872 EC_KEY_precompute_mult(ecdsa[j], NULL);
1873 /* Perform ECDSA signature test */
1874 EC_KEY_generate_key(ecdsa[j]);
1875 st = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
1878 "ECDSA sign failure. No ECDSA sign will be done.\n");
1879 ERR_print_errors(bio_err);
1882 pkey_print_message("sign", "ecdsa",
1884 test_curves_bits[j], ECDSA_SECONDS);
1887 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
1888 st = ECDSA_sign(0, buf, 20,
1889 ecdsasig, &ecdsasiglen, ecdsa[j]);
1891 BIO_printf(bio_err, "ECDSA sign failure\n");
1892 ERR_print_errors(bio_err);
1900 mr ? "+R5:%ld:%d:%.2f\n" :
1901 "%ld %d bit ECDSA signs in %.2fs \n",
1902 count, test_curves_bits[j], d);
1903 ecdsa_results[j][0] = d / (double)count;
1907 /* Perform ECDSA verification test */
1908 st = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
1911 "ECDSA verify failure. No ECDSA verify will be done.\n");
1912 ERR_print_errors(bio_err);
1915 pkey_print_message("verify", "ecdsa",
1917 test_curves_bits[j], ECDSA_SECONDS);
1919 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
1920 st = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1923 BIO_printf(bio_err, "ECDSA verify failure\n");
1924 ERR_print_errors(bio_err);
1931 mr ? "+R6:%ld:%d:%.2f\n"
1932 : "%ld %d bit ECDSA verify in %.2fs\n",
1933 count, test_curves_bits[j], d);
1934 ecdsa_results[j][1] = d / (double)count;
1937 if (rsa_count <= 1) {
1938 /* if longer than 10s, don't do any more */
1939 for (j++; j < EC_NUM; j++)
1948 #ifndef OPENSSL_NO_EC
1949 if (RAND_status() != 1) {
1950 RAND_seed(rnd_seed, sizeof rnd_seed);
1953 for (j = 0; j < EC_NUM; j++) {
1956 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1957 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1958 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
1959 BIO_printf(bio_err, "ECDH failure.\n");
1960 ERR_print_errors(bio_err);
1963 /* generate two ECDH key pairs */
1964 if (!EC_KEY_generate_key(ecdh_a[j]) ||
1965 !EC_KEY_generate_key(ecdh_b[j])) {
1966 BIO_printf(bio_err, "ECDH key generation failure.\n");
1967 ERR_print_errors(bio_err);
1971 * If field size is not more than 24 octets, then use SHA-1
1972 * hash of result; otherwise, use result (see section 4.8 of
1973 * draft-ietf-tls-ecc-03.txt).
1975 int field_size, outlen;
1976 void *(*kdf) (const void *in, size_t inlen, void *out,
1979 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
1980 if (field_size <= 24 * 8) {
1981 outlen = KDF1_SHA1_len;
1984 outlen = (field_size + 7) / 8;
1988 ECDH_compute_key(secret_a, outlen,
1989 EC_KEY_get0_public_key(ecdh_b[j]),
1992 ECDH_compute_key(secret_b, outlen,
1993 EC_KEY_get0_public_key(ecdh_a[j]),
1995 if (secret_size_a != secret_size_b)
2000 for (secret_idx = 0; (secret_idx < secret_size_a)
2001 && (ecdh_checks == 1); secret_idx++) {
2002 if (secret_a[secret_idx] != secret_b[secret_idx])
2006 if (ecdh_checks == 0) {
2007 BIO_printf(bio_err, "ECDH computations don't match.\n");
2008 ERR_print_errors(bio_err);
2012 pkey_print_message("", "ecdh",
2014 test_curves_bits[j], ECDH_SECONDS);
2016 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2017 ECDH_compute_key(secret_a, outlen,
2018 EC_KEY_get0_public_key(ecdh_b[j]),
2023 mr ? "+R7:%ld:%d:%.2f\n" :
2024 "%ld %d-bit ECDH ops in %.2fs\n", count,
2025 test_curves_bits[j], d);
2026 ecdh_results[j][0] = d / (double)count;
2031 if (rsa_count <= 1) {
2032 /* if longer than 10s, don't do any more */
2033 for (j++; j < EC_NUM; j++)
2044 printf("%s\n", SSLeay_version(SSLEAY_VERSION));
2045 printf("%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2047 printf("%s ", BN_options());
2048 #ifndef OPENSSL_NO_MD2
2049 printf("%s ", MD2_options());
2051 #ifndef OPENSSL_NO_RC4
2052 printf("%s ", RC4_options());
2054 #ifndef OPENSSL_NO_DES
2055 printf("%s ", DES_options());
2057 #ifndef OPENSSL_NO_AES
2058 printf("%s ", AES_options());
2060 #ifndef OPENSSL_NO_IDEA
2061 printf("%s ", idea_options());
2063 #ifndef OPENSSL_NO_BF
2064 printf("%s ", BF_options());
2066 printf("\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2074 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2077 for (j = 0; j < SIZE_NUM; j++)
2078 printf(mr ? ":%d" : "%7d bytes", lengths[j]);
2082 for (k = 0; k < ALGOR_NUM; k++) {
2086 printf("+F:%d:%s", k, names[k]);
2088 printf("%-13s", names[k]);
2089 for (j = 0; j < SIZE_NUM; j++) {
2090 if (results[k][j] > 10000 && !mr)
2091 printf(" %11.2fk", results[k][j] / 1e3);
2093 printf(mr ? ":%.2f" : " %11.2f ", results[k][j]);
2097 #ifndef OPENSSL_NO_RSA
2099 for (k = 0; k < RSA_NUM; k++) {
2103 printf("%18ssign verify sign/s verify/s\n", " ");
2107 printf("+F2:%u:%u:%f:%f\n",
2108 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2110 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2111 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2112 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2115 #ifndef OPENSSL_NO_DSA
2117 for (k = 0; k < DSA_NUM; k++) {
2121 printf("%18ssign verify sign/s verify/s\n", " ");
2125 printf("+F3:%u:%u:%f:%f\n",
2126 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2128 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2129 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2130 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2133 #ifndef OPENSSL_NO_EC
2135 for (k = 0; k < EC_NUM; k++) {
2139 printf("%30ssign verify sign/s verify/s\n", " ");
2144 printf("+F4:%u:%u:%f:%f\n",
2145 k, test_curves_bits[k],
2146 ecdsa_results[k][0], ecdsa_results[k][1]);
2148 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2149 test_curves_bits[k],
2150 test_curves_names[k],
2151 ecdsa_results[k][0], ecdsa_results[k][1],
2152 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2156 #ifndef OPENSSL_NO_EC
2158 for (k = 0; k < EC_NUM; k++) {
2162 printf("%30sop op/s\n", " ");
2166 printf("+F5:%u:%u:%f:%f\n",
2167 k, test_curves_bits[k],
2168 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2171 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2172 test_curves_bits[k],
2173 test_curves_names[k],
2174 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2181 ERR_print_errors(bio_err);
2182 OPENSSL_free(buf_malloc);
2183 OPENSSL_free(buf2_malloc);
2184 #ifndef OPENSSL_NO_RSA
2185 for (i = 0; i < RSA_NUM; i++)
2186 RSA_free(rsa_key[i]);
2188 #ifndef OPENSSL_NO_DSA
2189 for (i = 0; i < DSA_NUM; i++)
2190 DSA_free(dsa_key[i]);
2193 #ifndef OPENSSL_NO_EC
2194 for (i = 0; i < EC_NUM; i++) {
2195 EC_KEY_free(ecdsa[i]);
2196 EC_KEY_free(ecdh_a[i]);
2197 EC_KEY_free(ecdh_b[i]);
2203 static void print_message(const char *s, long num, int length)
2207 mr ? "+DT:%s:%d:%d\n"
2208 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2209 (void)BIO_flush(bio_err);
2213 mr ? "+DN:%s:%ld:%d\n"
2214 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2215 (void)BIO_flush(bio_err);
2219 static void pkey_print_message(const char *str, const char *str2, long num,
2224 mr ? "+DTP:%d:%s:%s:%d\n"
2225 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2226 (void)BIO_flush(bio_err);
2230 mr ? "+DNP:%ld:%d:%s:%s\n"
2231 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2232 (void)BIO_flush(bio_err);
2236 static void print_result(int alg, int run_no, int count, double time_used)
2239 mr ? "+R:%d:%s:%f\n"
2240 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2241 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2245 static char *sstrsep(char **string, const char *delim)
2248 char *token = *string;
2253 memset(isdelim, 0, sizeof isdelim);
2257 isdelim[(unsigned char)(*delim)] = 1;
2261 while (!isdelim[(unsigned char)(**string)]) {
2273 static int do_multi(int multi)
2278 static char sep[] = ":";
2280 fds = malloc(sizeof(*fds) * multi);
2281 for (n = 0; n < multi; ++n) {
2282 if (pipe(fd) == -1) {
2283 BIO_printf(bio_err, "pipe failure\n");
2287 (void)BIO_flush(bio_err);
2294 if (dup(fd[1]) == -1) {
2295 BIO_printf(bio_err, "dup failed\n");
2304 printf("Forked child %d\n", n);
2307 /* for now, assume the pipe is long enough to take all the output */
2308 for (n = 0; n < multi; ++n) {
2313 f = fdopen(fds[n], "r");
2314 while (fgets(buf, sizeof buf, f)) {
2315 p = strchr(buf, '\n');
2318 if (buf[0] != '+') {
2319 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2323 printf("Got: %s from %d\n", buf, n);
2324 if (strncmp(buf, "+F:", 3) == 0) {
2329 alg = atoi(sstrsep(&p, sep));
2331 for (j = 0; j < SIZE_NUM; ++j)
2332 results[alg][j] += atof(sstrsep(&p, sep));
2333 } else if (strncmp(buf, "+F2:", 4) == 0) {
2338 k = atoi(sstrsep(&p, sep));
2341 d = atof(sstrsep(&p, sep));
2343 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2345 rsa_results[k][0] = d;
2347 d = atof(sstrsep(&p, sep));
2349 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2351 rsa_results[k][1] = d;
2353 # ifndef OPENSSL_NO_DSA
2354 else if (strncmp(buf, "+F3:", 4) == 0) {
2359 k = atoi(sstrsep(&p, sep));
2362 d = atof(sstrsep(&p, sep));
2364 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2366 dsa_results[k][0] = d;
2368 d = atof(sstrsep(&p, sep));
2370 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2372 dsa_results[k][1] = d;
2375 # ifndef OPENSSL_NO_EC
2376 else if (strncmp(buf, "+F4:", 4) == 0) {
2381 k = atoi(sstrsep(&p, sep));
2384 d = atof(sstrsep(&p, sep));
2386 ecdsa_results[k][0] =
2387 1 / (1 / ecdsa_results[k][0] + 1 / d);
2389 ecdsa_results[k][0] = d;
2391 d = atof(sstrsep(&p, sep));
2393 ecdsa_results[k][1] =
2394 1 / (1 / ecdsa_results[k][1] + 1 / d);
2396 ecdsa_results[k][1] = d;
2400 # ifndef OPENSSL_NO_EC
2401 else if (strncmp(buf, "+F5:", 4) == 0) {
2406 k = atoi(sstrsep(&p, sep));
2409 d = atof(sstrsep(&p, sep));
2411 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2413 ecdh_results[k][0] = d;
2418 else if (strncmp(buf, "+H:", 3) == 0) {
2421 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
2431 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2433 static int mblengths[] =
2434 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2435 int j, count, num = OSSL_NELEM(lengths);
2436 const char *alg_name;
2437 unsigned char *inp, *out, no_key[32], no_iv[16];
2441 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
2442 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
2443 EVP_CIPHER_CTX_init(&ctx);
2444 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2445 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2447 alg_name = OBJ_nid2ln(evp_cipher->nid);
2449 for (j = 0; j < num; j++) {
2450 print_message(alg_name, 0, mblengths[j]);
2452 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2453 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
2454 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2455 size_t len = mblengths[j];
2458 memset(aad, 0, 8); /* avoid uninitialized values */
2459 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2460 aad[9] = 3; /* version */
2462 aad[11] = 0; /* length */
2464 mb_param.out = NULL;
2467 mb_param.interleave = 8;
2469 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2470 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2471 sizeof(mb_param), &mb_param);
2477 EVP_CIPHER_CTX_ctrl(&ctx,
2478 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2479 sizeof(mb_param), &mb_param);
2483 RAND_bytes(out, 16);
2487 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2488 EVP_CTRL_AEAD_TLS1_AAD,
2489 EVP_AEAD_TLS1_AAD_LEN, aad);
2490 EVP_Cipher(&ctx, out, inp, len + pad);
2494 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
2495 : "%d %s's in %.2fs\n", count, "evp", d);
2496 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2500 fprintf(stdout, "+H");
2501 for (j = 0; j < num; j++)
2502 fprintf(stdout, ":%d", mblengths[j]);
2503 fprintf(stdout, "\n");
2504 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2505 for (j = 0; j < num; j++)
2506 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2507 fprintf(stdout, "\n");
2510 "The 'numbers' are in 1000s of bytes per second processed.\n");
2511 fprintf(stdout, "type ");
2512 for (j = 0; j < num; j++)
2513 fprintf(stdout, "%7d bytes", mblengths[j]);
2514 fprintf(stdout, "\n");
2515 fprintf(stdout, "%-24s", alg_name);
2517 for (j = 0; j < num; j++) {
2518 if (results[D_EVP][j] > 10000)
2519 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2521 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2523 fprintf(stdout, "\n");