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 #include <openssl/async.h>
90 #if !defined(OPENSSL_SYS_MSDOS)
91 # include OPENSSL_UNISTD
94 #ifndef OPENSSL_SYS_NETWARE
102 #if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
106 #if !defined(OPENSSL_NO_ASYNC)
107 # if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
108 # if _POSIX_VERSION >= 200112L
111 # elif defined(_WIN32) || defined(__CYGWIN__)
116 #if !defined(ASYNC_POSIX) && !defined(ASYNC_WIN)
120 #include <openssl/bn.h>
121 #ifndef OPENSSL_NO_DES
122 # include <openssl/des.h>
124 #ifndef OPENSSL_NO_AES
125 # include <openssl/aes.h>
127 #ifndef OPENSSL_NO_CAMELLIA
128 # include <openssl/camellia.h>
130 #ifndef OPENSSL_NO_MD2
131 # include <openssl/md2.h>
133 #ifndef OPENSSL_NO_MDC2
134 # include <openssl/mdc2.h>
136 #ifndef OPENSSL_NO_MD4
137 # include <openssl/md4.h>
139 #ifndef OPENSSL_NO_MD5
140 # include <openssl/md5.h>
142 #include <openssl/hmac.h>
143 #include <openssl/sha.h>
144 #ifndef OPENSSL_NO_RMD160
145 # include <openssl/ripemd.h>
147 #ifndef OPENSSL_NO_WHIRLPOOL
148 # include <openssl/whrlpool.h>
150 #ifndef OPENSSL_NO_RC4
151 # include <openssl/rc4.h>
153 #ifndef OPENSSL_NO_RC5
154 # include <openssl/rc5.h>
156 #ifndef OPENSSL_NO_RC2
157 # include <openssl/rc2.h>
159 #ifndef OPENSSL_NO_IDEA
160 # include <openssl/idea.h>
162 #ifndef OPENSSL_NO_SEED
163 # include <openssl/seed.h>
165 #ifndef OPENSSL_NO_BF
166 # include <openssl/blowfish.h>
168 #ifndef OPENSSL_NO_CAST
169 # include <openssl/cast.h>
171 #ifndef OPENSSL_NO_RSA
172 # include <openssl/rsa.h>
173 # include "./testrsa.h"
175 #include <openssl/x509.h>
176 #ifndef OPENSSL_NO_DSA
177 # include <openssl/dsa.h>
178 # include "./testdsa.h"
180 #ifndef OPENSSL_NO_EC
181 # include <openssl/ec.h>
183 #include <openssl/modes.h>
186 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
200 #define BUFSIZE (1024*16+1)
201 #define MAX_MISALIGNMENT 63
210 #define MAX_ECDH_SIZE 256
213 static volatile int run = 0;
216 static int usertime = 1;
218 typedef struct loopargs_st {
219 ASYNC_JOB *inprogress_job;
222 unsigned char *buf_malloc;
223 unsigned char *buf2_malloc;
224 unsigned int *siglen;
225 #ifndef OPENSSL_NO_RSA
226 RSA *rsa_key[RSA_NUM];
228 #ifndef OPENSSL_NO_DSA
229 DSA *dsa_key[DSA_NUM];
231 #ifndef OPENSSL_NO_EC
232 EC_KEY *ecdsa[EC_NUM];
233 EC_KEY *ecdh_a[EC_NUM];
234 EC_KEY *ecdh_b[EC_NUM];
235 unsigned char *secret_a;
236 unsigned char *secret_b;
240 GCM128_CONTEXT *gcm_ctx;
243 #ifndef OPENSSL_NO_MD2
244 static int EVP_Digest_MD2_loop(void *args);
247 #ifndef OPENSSL_NO_MDC2
248 static int EVP_Digest_MDC2_loop(void *args);
250 #ifndef OPENSSL_NO_MD4
251 static int EVP_Digest_MD4_loop(void *args);
253 #ifndef OPENSSL_NO_MD5
254 static int MD5_loop(void *args);
255 static int HMAC_loop(void *args);
257 static int SHA1_loop(void *args);
258 static int SHA256_loop(void *args);
259 static int SHA512_loop(void *args);
260 #ifndef OPENSSL_NO_WHIRLPOOL
261 static int WHIRLPOOL_loop(void *args);
263 #ifndef OPENSSL_NO_RMD160
264 static int EVP_Digest_RMD160_loop(void *args);
266 #ifndef OPENSSL_NO_RC4
267 static int RC4_loop(void *args);
269 #ifndef OPENSSL_NO_DES
270 static int DES_ncbc_encrypt_loop(void *args);
271 static int DES_ede3_cbc_encrypt_loop(void *args);
273 #ifndef OPENSSL_NO_AES
274 static int AES_cbc_128_encrypt_loop(void *args);
275 static int AES_cbc_192_encrypt_loop(void *args);
276 static int AES_ige_128_encrypt_loop(void *args);
277 static int AES_cbc_256_encrypt_loop(void *args);
278 static int AES_ige_192_encrypt_loop(void *args);
279 static int AES_ige_256_encrypt_loop(void *args);
280 static int CRYPTO_gcm128_aad_loop(void *args);
282 static int EVP_Update_loop(void *args);
283 static int EVP_Digest_loop(void *args);
284 #ifndef OPENSSL_NO_RSA
285 static int RSA_sign_loop(void *args);
286 static int RSA_verify_loop(void *args);
288 #ifndef OPENSSL_NO_DSA
289 static int DSA_sign_loop(void *args);
290 static int DSA_verify_loop(void *args);
292 #ifndef OPENSSL_NO_EC
293 static int ECDSA_sign_loop(void *args);
294 static int ECDSA_verify_loop(void *args);
295 static int ECDH_compute_key_loop(void *args);
297 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
299 static double Time_F(int s);
300 static void print_message(const char *s, long num, int length);
301 static void pkey_print_message(const char *str, const char *str2,
302 long num, int bits, int sec);
303 static void print_result(int alg, int run_no, int count, double time_used);
305 static int do_multi(int multi);
308 static const char *names[ALGOR_NUM] = {
309 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
310 "des cbc", "des ede3", "idea cbc", "seed cbc",
311 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
312 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
313 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
314 "evp", "sha256", "sha512", "whirlpool",
315 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
318 static double results[ALGOR_NUM][SIZE_NUM];
319 static int lengths[SIZE_NUM] = {
320 16, 64, 256, 1024, 8 * 1024, 16 * 1024
323 #ifndef OPENSSL_NO_RSA
324 static double rsa_results[RSA_NUM][2];
326 #ifndef OPENSSL_NO_DSA
327 static double dsa_results[DSA_NUM][2];
329 #ifndef OPENSSL_NO_EC
330 static double ecdsa_results[EC_NUM][2];
331 static double ecdh_results[EC_NUM][1];
334 #if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
335 static const char rnd_seed[] =
336 "string to make the random number generator think it has entropy";
337 static int rnd_fake = 0;
341 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
342 # define SIGRETTYPE void
344 # define SIGRETTYPE int
347 static SIGRETTYPE sig_done(int sig);
348 static SIGRETTYPE sig_done(int sig)
350 signal(SIGALRM, sig_done);
360 # if !defined(SIGALRM)
363 static unsigned int lapse, schlock;
364 static void alarm_win32(unsigned int secs)
369 # define alarm alarm_win32
371 static DWORD WINAPI sleepy(VOID * arg)
379 static double Time_F(int s)
386 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
388 DWORD err = GetLastError();
389 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
393 Sleep(0); /* scheduler spinlock */
394 ret = app_tminterval(s, usertime);
396 ret = app_tminterval(s, usertime);
398 TerminateThread(thr, 0);
406 static double Time_F(int s)
408 double ret = app_tminterval(s, usertime);
415 #ifndef OPENSSL_NO_EC
416 static const int KDF1_SHA1_len = 20;
417 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
420 if (*outlen < SHA_DIGEST_LENGTH)
422 *outlen = SHA_DIGEST_LENGTH;
423 return SHA1(in, inlen, out);
425 #endif /* OPENSSL_NO_EC */
427 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
429 static int found(const char *name, const OPT_PAIR * pairs, int *result)
431 for (; pairs->name; pairs++)
432 if (strcmp(name, pairs->name) == 0) {
433 *result = pairs->retval;
439 typedef enum OPTION_choice {
440 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
441 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
442 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
445 OPTIONS speed_options[] = {
446 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
447 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
448 {"help", OPT_HELP, '-', "Display this summary"},
449 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
450 {"decrypt", OPT_DECRYPT, '-',
451 "Time decryption instead of encryption (only EVP)"},
452 {"mr", OPT_MR, '-', "Produce machine readable output"},
454 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
455 {"elapsed", OPT_ELAPSED, '-',
456 "Measure time in real time instead of CPU user time"},
458 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
461 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
463 #ifndef OPENSSL_NO_ENGINE
464 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
479 #define D_CBC_IDEA 10
480 #define D_CBC_SEED 11
484 #define D_CBC_CAST 15
485 #define D_CBC_128_AES 16
486 #define D_CBC_192_AES 17
487 #define D_CBC_256_AES 18
488 #define D_CBC_128_CML 19
489 #define D_CBC_192_CML 20
490 #define D_CBC_256_CML 21
494 #define D_WHIRLPOOL 25
495 #define D_IGE_128_AES 26
496 #define D_IGE_192_AES 27
497 #define D_IGE_256_AES 28
499 static OPT_PAIR doit_choices[] = {
500 #ifndef OPENSSL_NO_MD2
503 #ifndef OPENSSL_NO_MDC2
506 #ifndef OPENSSL_NO_MD4
509 #ifndef OPENSSL_NO_MD5
512 #ifndef OPENSSL_NO_MD5
516 {"sha256", D_SHA256},
517 {"sha512", D_SHA512},
518 #ifndef OPENSSL_NO_WHIRLPOOL
519 {"whirlpool", D_WHIRLPOOL},
521 #ifndef OPENSSL_NO_RMD160
522 {"ripemd", D_RMD160},
523 {"rmd160", D_RMD160},
524 {"ripemd160", D_RMD160},
526 #ifndef OPENSSL_NO_RC4
529 #ifndef OPENSSL_NO_DES
530 {"des-cbc", D_CBC_DES},
531 {"des-ede3", D_EDE3_DES},
533 #ifndef OPENSSL_NO_AES
534 {"aes-128-cbc", D_CBC_128_AES},
535 {"aes-192-cbc", D_CBC_192_AES},
536 {"aes-256-cbc", D_CBC_256_AES},
537 {"aes-128-ige", D_IGE_128_AES},
538 {"aes-192-ige", D_IGE_192_AES},
539 {"aes-256-ige", D_IGE_256_AES},
541 #ifndef OPENSSL_NO_RC2
542 {"rc2-cbc", D_CBC_RC2},
545 #ifndef OPENSSL_NO_RC5
546 {"rc5-cbc", D_CBC_RC5},
549 #ifndef OPENSSL_NO_IDEA
550 {"idea-cbc", D_CBC_IDEA},
551 {"idea", D_CBC_IDEA},
553 #ifndef OPENSSL_NO_SEED
554 {"seed-cbc", D_CBC_SEED},
555 {"seed", D_CBC_SEED},
557 #ifndef OPENSSL_NO_BF
558 {"bf-cbc", D_CBC_BF},
559 {"blowfish", D_CBC_BF},
562 #ifndef OPENSSL_NO_CAST
563 {"cast-cbc", D_CBC_CAST},
564 {"cast", D_CBC_CAST},
565 {"cast5", D_CBC_CAST},
574 static OPT_PAIR dsa_choices[] = {
575 {"dsa512", R_DSA_512},
576 {"dsa1024", R_DSA_1024},
577 {"dsa2048", R_DSA_2048},
587 #define R_RSA_15360 6
588 static OPT_PAIR rsa_choices[] = {
589 {"rsa512", R_RSA_512},
590 {"rsa1024", R_RSA_1024},
591 {"rsa2048", R_RSA_2048},
592 {"rsa3072", R_RSA_3072},
593 {"rsa4096", R_RSA_4096},
594 {"rsa7680", R_RSA_7680},
595 {"rsa15360", R_RSA_15360},
615 #define R_EC_X25519 16
616 #ifndef OPENSSL_NO_EC
617 static OPT_PAIR ecdsa_choices[] = {
618 {"ecdsap160", R_EC_P160},
619 {"ecdsap192", R_EC_P192},
620 {"ecdsap224", R_EC_P224},
621 {"ecdsap256", R_EC_P256},
622 {"ecdsap384", R_EC_P384},
623 {"ecdsap521", R_EC_P521},
624 {"ecdsak163", R_EC_K163},
625 {"ecdsak233", R_EC_K233},
626 {"ecdsak283", R_EC_K283},
627 {"ecdsak409", R_EC_K409},
628 {"ecdsak571", R_EC_K571},
629 {"ecdsab163", R_EC_B163},
630 {"ecdsab233", R_EC_B233},
631 {"ecdsab283", R_EC_B283},
632 {"ecdsab409", R_EC_B409},
633 {"ecdsab571", R_EC_B571},
636 static OPT_PAIR ecdh_choices[] = {
637 {"ecdhp160", R_EC_P160},
638 {"ecdhp192", R_EC_P192},
639 {"ecdhp224", R_EC_P224},
640 {"ecdhp256", R_EC_P256},
641 {"ecdhp384", R_EC_P384},
642 {"ecdhp521", R_EC_P521},
643 {"ecdhk163", R_EC_K163},
644 {"ecdhk233", R_EC_K233},
645 {"ecdhk283", R_EC_K283},
646 {"ecdhk409", R_EC_K409},
647 {"ecdhk571", R_EC_K571},
648 {"ecdhb163", R_EC_B163},
649 {"ecdhb233", R_EC_B233},
650 {"ecdhb283", R_EC_B283},
651 {"ecdhb409", R_EC_B409},
652 {"ecdhb571", R_EC_B571},
653 {"ecdhx25519", R_EC_X25519},
659 # define COND(d) (count < (d))
660 # define COUNT(d) (d)
662 # define COND(c) (run && count<0x7fffffff)
663 # define COUNT(d) (count)
667 static char *engine_id = NULL;
670 #ifndef OPENSSL_NO_MD2
671 static int EVP_Digest_MD2_loop(void *args)
673 loopargs_t *tempargs = (loopargs_t *)args;
674 unsigned char *buf = tempargs->buf;
675 unsigned char md2[MD2_DIGEST_LENGTH];
677 for (count = 0; COND(c[D_MD2][testnum]); count++)
678 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
684 #ifndef OPENSSL_NO_MDC2
685 static int EVP_Digest_MDC2_loop(void *args)
687 loopargs_t *tempargs = (loopargs_t *)args;
688 unsigned char *buf = tempargs->buf;
689 unsigned char mdc2[MDC2_DIGEST_LENGTH];
691 for (count = 0; COND(c[D_MDC2][testnum]); count++)
692 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
698 #ifndef OPENSSL_NO_MD4
699 static int EVP_Digest_MD4_loop(void *args)
701 loopargs_t *tempargs = (loopargs_t *)args;
702 unsigned char *buf = tempargs->buf;
703 unsigned char md4[MD4_DIGEST_LENGTH];
705 for (count = 0; COND(c[D_MD4][testnum]); count++)
706 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
707 NULL, EVP_md4(), NULL);
712 #ifndef OPENSSL_NO_MD5
713 static int MD5_loop(void *args)
715 loopargs_t *tempargs = (loopargs_t *)args;
716 unsigned char *buf = tempargs->buf;
717 unsigned char md5[MD5_DIGEST_LENGTH];
719 for (count = 0; COND(c[D_MD5][testnum]); count++)
720 MD5(buf, lengths[testnum], md5);
724 static int HMAC_loop(void *args)
726 loopargs_t *tempargs = (loopargs_t *)args;
727 unsigned char *buf = tempargs->buf;
728 HMAC_CTX *hctx = tempargs->hctx;
729 unsigned char hmac[MD5_DIGEST_LENGTH];
731 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
732 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
733 HMAC_Update(hctx, buf, lengths[testnum]);
734 HMAC_Final(hctx, &(hmac[0]), NULL);
740 static int SHA1_loop(void *args)
742 loopargs_t *tempargs = (loopargs_t *)args;
743 unsigned char *buf = tempargs->buf;
744 unsigned char sha[SHA_DIGEST_LENGTH];
746 for (count = 0; COND(c[D_SHA1][testnum]); count++)
747 SHA1(buf, lengths[testnum], sha);
751 static int SHA256_loop(void *args)
753 loopargs_t *tempargs = (loopargs_t *)args;
754 unsigned char *buf = tempargs->buf;
755 unsigned char sha256[SHA256_DIGEST_LENGTH];
757 for (count = 0; COND(c[D_SHA256][testnum]); count++)
758 SHA256(buf, lengths[testnum], sha256);
762 static int SHA512_loop(void *args)
764 loopargs_t *tempargs = (loopargs_t *)args;
765 unsigned char *buf = tempargs->buf;
766 unsigned char sha512[SHA512_DIGEST_LENGTH];
768 for (count = 0; COND(c[D_SHA512][testnum]); count++)
769 SHA512(buf, lengths[testnum], sha512);
773 #ifndef OPENSSL_NO_WHIRLPOOL
774 static int WHIRLPOOL_loop(void *args)
776 loopargs_t *tempargs = (loopargs_t *)args;
777 unsigned char *buf = tempargs->buf;
778 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
780 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
781 WHIRLPOOL(buf, lengths[testnum], whirlpool);
786 #ifndef OPENSSL_NO_RMD160
787 static int EVP_Digest_RMD160_loop(void *args)
789 loopargs_t *tempargs = (loopargs_t *)args;
790 unsigned char *buf = tempargs->buf;
791 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
793 for (count = 0; COND(c[D_RMD160][testnum]); count++)
794 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
795 EVP_ripemd160(), NULL);
800 #ifndef OPENSSL_NO_RC4
801 static RC4_KEY rc4_ks;
802 static int RC4_loop(void *args)
804 loopargs_t *tempargs = (loopargs_t *)args;
805 unsigned char *buf = tempargs->buf;
807 for (count = 0; COND(c[D_RC4][testnum]); count++)
808 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
813 #ifndef OPENSSL_NO_DES
814 static unsigned char DES_iv[8];
815 static DES_key_schedule sch;
816 static DES_key_schedule sch2;
817 static DES_key_schedule sch3;
818 static int DES_ncbc_encrypt_loop(void *args)
820 loopargs_t *tempargs = (loopargs_t *)args;
821 unsigned char *buf = tempargs->buf;
823 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
824 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
825 &DES_iv, DES_ENCRYPT);
829 static int DES_ede3_cbc_encrypt_loop(void *args)
831 loopargs_t *tempargs = (loopargs_t *)args;
832 unsigned char *buf = tempargs->buf;
834 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
835 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
837 &DES_iv, DES_ENCRYPT);
842 #ifndef OPENSSL_NO_AES
843 # define MAX_BLOCK_SIZE 128
845 # define MAX_BLOCK_SIZE 64
848 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
849 #ifndef OPENSSL_NO_AES
850 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
851 static int AES_cbc_128_encrypt_loop(void *args)
853 loopargs_t *tempargs = (loopargs_t *)args;
854 unsigned char *buf = tempargs->buf;
856 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
857 AES_cbc_encrypt(buf, buf,
858 (unsigned long)lengths[testnum], &aes_ks1,
863 static int AES_cbc_192_encrypt_loop(void *args)
865 loopargs_t *tempargs = (loopargs_t *)args;
866 unsigned char *buf = tempargs->buf;
868 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
869 AES_cbc_encrypt(buf, buf,
870 (unsigned long)lengths[testnum], &aes_ks2,
875 static int AES_cbc_256_encrypt_loop(void *args)
877 loopargs_t *tempargs = (loopargs_t *)args;
878 unsigned char *buf = tempargs->buf;
880 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
881 AES_cbc_encrypt(buf, buf,
882 (unsigned long)lengths[testnum], &aes_ks3,
887 static int AES_ige_128_encrypt_loop(void *args)
889 loopargs_t *tempargs = (loopargs_t *)args;
890 unsigned char *buf = tempargs->buf;
891 unsigned char *buf2 = tempargs->buf2;
893 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
894 AES_ige_encrypt(buf, buf2,
895 (unsigned long)lengths[testnum], &aes_ks1,
900 static int AES_ige_192_encrypt_loop(void *args)
902 loopargs_t *tempargs = (loopargs_t *)args;
903 unsigned char *buf = tempargs->buf;
904 unsigned char *buf2 = tempargs->buf2;
906 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
907 AES_ige_encrypt(buf, buf2,
908 (unsigned long)lengths[testnum], &aes_ks2,
913 static int AES_ige_256_encrypt_loop(void *args)
915 loopargs_t *tempargs = (loopargs_t *)args;
916 unsigned char *buf = tempargs->buf;
917 unsigned char *buf2 = tempargs->buf2;
919 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
920 AES_ige_encrypt(buf, buf2,
921 (unsigned long)lengths[testnum], &aes_ks3,
926 static int CRYPTO_gcm128_aad_loop(void *args)
928 loopargs_t *tempargs = (loopargs_t *)args;
929 unsigned char *buf = tempargs->buf;
930 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
932 for (count = 0; COND(c[D_GHASH][testnum]); count++)
933 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
939 static int decrypt = 0;
940 static int EVP_Update_loop(void *args)
942 loopargs_t *tempargs = (loopargs_t *)args;
943 unsigned char *buf = tempargs->buf;
944 EVP_CIPHER_CTX *ctx = tempargs->ctx;
948 COND(save_count * 4 * lengths[0] / lengths[testnum]);
950 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
953 COND(save_count * 4 * lengths[0] / lengths[testnum]);
955 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
957 EVP_DecryptFinal_ex(ctx, buf, &outl);
959 EVP_EncryptFinal_ex(ctx, buf, &outl);
963 static const EVP_MD *evp_md = NULL;
964 static int EVP_Digest_loop(void *args)
966 loopargs_t *tempargs = (loopargs_t *)args;
967 unsigned char *buf = tempargs->buf;
968 unsigned char md[EVP_MAX_MD_SIZE];
971 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
972 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
977 #ifndef OPENSSL_NO_RSA
978 static long rsa_c[RSA_NUM][2];
980 static int RSA_sign_loop(void *args)
982 loopargs_t *tempargs = (loopargs_t *)args;
983 unsigned char *buf = tempargs->buf;
984 unsigned char *buf2 = tempargs->buf2;
985 unsigned int *rsa_num = tempargs->siglen;
986 RSA **rsa_key = tempargs->rsa_key;
988 for (count = 0; COND(rsa_c[testnum][0]); count++) {
989 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
991 BIO_printf(bio_err, "RSA sign failure\n");
992 ERR_print_errors(bio_err);
1000 static int RSA_verify_loop(void *args)
1002 loopargs_t *tempargs = (loopargs_t *)args;
1003 unsigned char *buf = tempargs->buf;
1004 unsigned char *buf2 = tempargs->buf2;
1005 unsigned int rsa_num = *(tempargs->siglen);
1006 RSA **rsa_key = tempargs->rsa_key;
1008 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1009 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1011 BIO_printf(bio_err, "RSA verify failure\n");
1012 ERR_print_errors(bio_err);
1021 #ifndef OPENSSL_NO_DSA
1022 static long dsa_c[DSA_NUM][2];
1023 static int DSA_sign_loop(void *args)
1025 loopargs_t *tempargs = (loopargs_t *)args;
1026 unsigned char *buf = tempargs->buf;
1027 unsigned char *buf2 = tempargs->buf2;
1028 DSA **dsa_key = tempargs->dsa_key;
1029 unsigned int *siglen = tempargs->siglen;
1031 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1032 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1034 BIO_printf(bio_err, "DSA sign failure\n");
1035 ERR_print_errors(bio_err);
1043 static int DSA_verify_loop(void *args)
1045 loopargs_t *tempargs = (loopargs_t *)args;
1046 unsigned char *buf = tempargs->buf;
1047 unsigned char *buf2 = tempargs->buf2;
1048 DSA **dsa_key = tempargs->dsa_key;
1049 unsigned int siglen = *(tempargs->siglen);
1051 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1052 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1054 BIO_printf(bio_err, "DSA verify failure\n");
1055 ERR_print_errors(bio_err);
1064 #ifndef OPENSSL_NO_EC
1065 static long ecdsa_c[EC_NUM][2];
1066 static int ECDSA_sign_loop(void *args)
1068 loopargs_t *tempargs = (loopargs_t *)args;
1069 unsigned char *buf = tempargs->buf;
1070 EC_KEY **ecdsa = tempargs->ecdsa;
1071 unsigned char *ecdsasig = tempargs->buf2;
1072 unsigned int *ecdsasiglen = tempargs->siglen;
1074 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1075 ret = ECDSA_sign(0, buf, 20,
1076 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1078 BIO_printf(bio_err, "ECDSA sign failure\n");
1079 ERR_print_errors(bio_err);
1087 static int ECDSA_verify_loop(void *args)
1089 loopargs_t *tempargs = (loopargs_t *)args;
1090 unsigned char *buf = tempargs->buf;
1091 EC_KEY **ecdsa = tempargs->ecdsa;
1092 unsigned char *ecdsasig = tempargs->buf2;
1093 unsigned int ecdsasiglen = *(tempargs->siglen);
1095 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1096 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1099 BIO_printf(bio_err, "ECDSA verify failure\n");
1100 ERR_print_errors(bio_err);
1109 static void *(*kdf) (const void *in, size_t inlen, void *out,
1112 static int ECDH_compute_key_loop(void *args)
1114 loopargs_t *tempargs = (loopargs_t *)args;
1115 EC_KEY **ecdh_a = tempargs->ecdh_a;
1116 EC_KEY **ecdh_b = tempargs->ecdh_b;
1117 unsigned char *secret_a = tempargs->secret_a;
1119 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1120 ECDH_compute_key(secret_a, outlen,
1121 EC_KEY_get0_public_key(ecdh_b[testnum]),
1122 ecdh_a[testnum], kdf);
1129 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1131 int job_op_count = 0;
1132 int total_op_count = 0;
1133 int num_inprogress = 0;
1139 if (async_jobs == 0) {
1140 return loop_function((void *)loopargs);
1143 for (i = 0; i < async_jobs && !error; i++) {
1144 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), &job_op_count,
1145 loop_function, (void *)(loopargs + i), sizeof(loopargs_t))) {
1150 if (job_op_count == -1) {
1153 total_op_count += job_op_count;
1158 BIO_printf(bio_err, "Failure in the job\n");
1159 ERR_print_errors(bio_err);
1165 while (num_inprogress > 0) {
1166 OSSL_ASYNC_FD job_fd = 0;
1167 #if defined(ASYNC_POSIX)
1168 OSSL_ASYNC_FD max_fd = 0;
1169 int select_result = 0;
1171 struct timeval select_timeout;
1172 FD_ZERO(&waitfdset);
1173 select_timeout.tv_sec=0;
1174 select_timeout.tv_usec=0;
1176 for (i = 0; i < async_jobs; i++) {
1177 if (loopargs[i].inprogress_job != NULL) {
1178 job_fd = ASYNC_get_wait_fd(loopargs[i].inprogress_job);
1179 FD_SET(job_fd, &waitfdset);
1180 if (job_fd > max_fd)
1184 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, &select_timeout);
1186 if (select_result == -1 && errno == EINTR)
1189 if (select_result == -1) {
1190 BIO_printf(bio_err, "Failure in the select\n");
1191 ERR_print_errors(bio_err);
1196 if (select_result == 0)
1199 #elif defined(ASYNC_WIN)
1203 for (i = 0; i < async_jobs; i++) {
1204 if (loopargs[i].inprogress_job == NULL)
1207 job_fd = ASYNC_get_wait_fd(loopargs[i].inprogress_job);
1209 #if defined(ASYNC_POSIX)
1210 if (!FD_ISSET(job_fd, &waitfdset))
1212 #elif defined(ASYNC_WIN)
1213 if (!PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1217 switch (ASYNC_start_job(&(loopargs[i].inprogress_job),
1218 &job_op_count, loop_function, (void *)(loopargs + i),
1219 sizeof(loopargs_t))) {
1223 if (job_op_count == -1) {
1226 total_op_count += job_op_count;
1229 loopargs[i].inprogress_job = NULL;
1234 loopargs[i].inprogress_job = NULL;
1235 BIO_printf(bio_err, "Failure in the job\n");
1236 ERR_print_errors(bio_err);
1243 return error ? -1 : total_op_count;
1246 int speed_main(int argc, char **argv)
1248 loopargs_t *loopargs = NULL;
1249 int loopargs_len = 0;
1251 const EVP_CIPHER *evp_cipher = NULL;
1254 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1255 int dsa_doit[DSA_NUM], rsa_doit[RSA_NUM];
1256 int ret = 1, i, k, misalign = 0;
1257 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
1262 /* What follows are the buffers and key material. */
1263 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1266 #ifndef OPENSSL_NO_RC5
1269 #ifndef OPENSSL_NO_RC2
1272 #ifndef OPENSSL_NO_IDEA
1273 IDEA_KEY_SCHEDULE idea_ks;
1275 #ifndef OPENSSL_NO_SEED
1276 SEED_KEY_SCHEDULE seed_ks;
1278 #ifndef OPENSSL_NO_BF
1281 #ifndef OPENSSL_NO_CAST
1284 static const unsigned char key16[16] = {
1285 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1286 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1288 #ifndef OPENSSL_NO_AES
1289 static const unsigned char key24[24] = {
1290 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1291 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1292 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1294 static const unsigned char key32[32] = {
1295 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1296 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1297 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1298 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1301 #ifndef OPENSSL_NO_CAMELLIA
1302 static const unsigned char ckey24[24] = {
1303 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1304 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1305 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1307 static const unsigned char ckey32[32] = {
1308 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1309 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1310 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1311 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1313 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1315 #ifndef OPENSSL_NO_DES
1316 static DES_cblock key = {
1317 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1319 static DES_cblock key2 = {
1320 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1322 static DES_cblock key3 = {
1323 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1326 #ifndef OPENSSL_NO_RSA
1327 static unsigned int rsa_bits[RSA_NUM] = {
1328 512, 1024, 2048, 3072, 4096, 7680, 15360
1330 static unsigned char *rsa_data[RSA_NUM] = {
1331 test512, test1024, test2048, test3072, test4096, test7680, test15360
1333 static int rsa_data_length[RSA_NUM] = {
1334 sizeof(test512), sizeof(test1024),
1335 sizeof(test2048), sizeof(test3072),
1336 sizeof(test4096), sizeof(test7680),
1340 #ifndef OPENSSL_NO_DSA
1341 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1343 #ifndef OPENSSL_NO_EC
1345 * We only test over the following curves as they are representative, To
1346 * add tests over more curves, simply add the curve NID and curve name to
1347 * the following arrays and increase the EC_NUM value accordingly.
1349 static unsigned int test_curves[EC_NUM] = {
1351 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1352 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1354 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1355 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1356 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1361 static const char *test_curves_names[EC_NUM] = {
1363 "secp160r1", "nistp192", "nistp224",
1364 "nistp256", "nistp384", "nistp521",
1366 "nistk163", "nistk233", "nistk283",
1367 "nistk409", "nistk571", "nistb163",
1368 "nistb233", "nistb283", "nistb409",
1373 static int test_curves_bits[EC_NUM] = {
1379 571, 253 /* X25519 */
1382 #ifndef OPENSSL_NO_EC
1383 int ecdsa_doit[EC_NUM];
1384 int secret_size_a, secret_size_b;
1385 int ecdh_checks = 1;
1387 long ecdh_c[EC_NUM][2];
1388 int ecdh_doit[EC_NUM];
1391 memset(results, 0, sizeof(results));
1393 memset(c, 0, sizeof(c));
1394 memset(DES_iv, 0, sizeof(DES_iv));
1395 memset(iv, 0, sizeof(iv));
1397 for (i = 0; i < ALGOR_NUM; i++)
1399 for (i = 0; i < RSA_NUM; i++)
1401 for (i = 0; i < DSA_NUM; i++)
1403 #ifndef OPENSSL_NO_EC
1404 for (i = 0; i < EC_NUM; i++)
1406 for (i = 0; i < EC_NUM; i++)
1412 prog = opt_init(argc, argv, speed_options);
1413 while ((o = opt_next()) != OPT_EOF) {
1418 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1421 opt_help(speed_options);
1428 evp_cipher = EVP_get_cipherbyname(opt_arg());
1429 if (evp_cipher == NULL)
1430 evp_md = EVP_get_digestbyname(opt_arg());
1431 if (evp_cipher == NULL && evp_md == NULL) {
1433 "%s: %s an unknown cipher or digest\n",
1444 * In a forked execution, an engine might need to be
1445 * initialised by each child process, not by the parent.
1446 * So store the name here and run setup_engine() later on.
1448 engine_id = opt_arg();
1452 multi = atoi(opt_arg());
1457 async_jobs = atoi(opt_arg());
1461 if (!opt_int(opt_arg(), &misalign))
1463 if (misalign > MISALIGN) {
1465 "%s: Maximum offset is %d\n", prog, MISALIGN);
1477 argc = opt_num_rest();
1480 /* Remaining arguments are algorithms. */
1481 for ( ; *argv; argv++) {
1482 if (found(*argv, doit_choices, &i)) {
1486 #ifndef OPENSSL_NO_DES
1487 if (strcmp(*argv, "des") == 0) {
1488 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1492 if (strcmp(*argv, "sha") == 0) {
1493 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1496 #ifndef OPENSSL_NO_RSA
1498 if (strcmp(*argv, "openssl") == 0) {
1499 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1503 if (strcmp(*argv, "rsa") == 0) {
1504 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1505 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1506 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1507 rsa_doit[R_RSA_15360] = 1;
1510 if (found(*argv, rsa_choices, &i)) {
1515 #ifndef OPENSSL_NO_DSA
1516 if (strcmp(*argv, "dsa") == 0) {
1517 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1518 dsa_doit[R_DSA_2048] = 1;
1521 if (found(*argv, dsa_choices, &i)) {
1526 #ifndef OPENSSL_NO_AES
1527 if (strcmp(*argv, "aes") == 0) {
1528 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1529 doit[D_CBC_256_AES] = 1;
1533 #ifndef OPENSSL_NO_CAMELLIA
1534 if (strcmp(*argv, "camellia") == 0) {
1535 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1536 doit[D_CBC_256_CML] = 1;
1540 #ifndef OPENSSL_NO_EC
1541 if (strcmp(*argv, "ecdsa") == 0) {
1542 for (i = 0; i < EC_NUM; i++)
1546 if (found(*argv, ecdsa_choices, &i)) {
1550 if (strcmp(*argv, "ecdh") == 0) {
1551 for (i = 0; i < EC_NUM; i++)
1555 if (found(*argv, ecdh_choices, &i)) {
1560 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1564 /* Initialize the job pool if async mode is enabled */
1565 if (async_jobs > 0) {
1566 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1567 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1572 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1573 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1574 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1576 for (i = 0; i < loopargs_len; i++) {
1577 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1578 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1579 /* Align the start of buffers on a 64 byte boundary */
1580 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1581 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1582 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1583 #ifndef OPENSSL_NO_DSA
1584 memset(loopargs[i].dsa_key, 0, sizeof(loopargs[i].dsa_key));
1586 #ifndef OPENSSL_NO_RSA
1587 memset(loopargs[i].rsa_key, 0, sizeof(loopargs[i].rsa_key));
1588 for (k = 0; k < RSA_NUM; k++)
1589 loopargs[i].rsa_key[k] = NULL;
1591 #ifndef OPENSSL_NO_EC
1592 for (k = 0; k < EC_NUM; k++)
1593 loopargs[i].ecdsa[k] = NULL;
1594 for (k = 0; k < EC_NUM; k++)
1595 loopargs[i].ecdh_a[k] = loopargs[i].ecdh_b[k] = NULL;
1596 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1597 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1602 if (multi && do_multi(multi))
1606 /* Initialize the engine after the fork */
1607 (void)setup_engine(engine_id, 0);
1609 /* No parameters; turn on everything. */
1610 if ((argc == 0) && !doit[D_EVP]) {
1611 for (i = 0; i < ALGOR_NUM; i++)
1614 for (i = 0; i < RSA_NUM; i++)
1616 for (i = 0; i < DSA_NUM; i++)
1618 #ifndef OPENSSL_NO_EC
1619 for (i = 0; i < EC_NUM; i++)
1621 for (i = 0; i < EC_NUM; i++)
1625 for (i = 0; i < ALGOR_NUM; i++)
1629 if (usertime == 0 && !mr)
1631 "You have chosen to measure elapsed time "
1632 "instead of user CPU time.\n");
1634 #ifndef OPENSSL_NO_RSA
1635 for (i = 0; i < loopargs_len; i++) {
1636 for (k = 0; k < RSA_NUM; k++) {
1637 const unsigned char *p;
1640 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1641 if (loopargs[i].rsa_key[k] == NULL) {
1642 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1649 #ifndef OPENSSL_NO_DSA
1650 for (i = 0; i < loopargs_len; i++) {
1651 loopargs[i].dsa_key[0] = get_dsa512();
1652 loopargs[i].dsa_key[1] = get_dsa1024();
1653 loopargs[i].dsa_key[2] = get_dsa2048();
1656 #ifndef OPENSSL_NO_DES
1657 DES_set_key_unchecked(&key, &sch);
1658 DES_set_key_unchecked(&key2, &sch2);
1659 DES_set_key_unchecked(&key3, &sch3);
1661 #ifndef OPENSSL_NO_AES
1662 AES_set_encrypt_key(key16, 128, &aes_ks1);
1663 AES_set_encrypt_key(key24, 192, &aes_ks2);
1664 AES_set_encrypt_key(key32, 256, &aes_ks3);
1666 #ifndef OPENSSL_NO_CAMELLIA
1667 Camellia_set_key(key16, 128, &camellia_ks1);
1668 Camellia_set_key(ckey24, 192, &camellia_ks2);
1669 Camellia_set_key(ckey32, 256, &camellia_ks3);
1671 #ifndef OPENSSL_NO_IDEA
1672 idea_set_encrypt_key(key16, &idea_ks);
1674 #ifndef OPENSSL_NO_SEED
1675 SEED_set_key(key16, &seed_ks);
1677 #ifndef OPENSSL_NO_RC4
1678 RC4_set_key(&rc4_ks, 16, key16);
1680 #ifndef OPENSSL_NO_RC2
1681 RC2_set_key(&rc2_ks, 16, key16, 128);
1683 #ifndef OPENSSL_NO_RC5
1684 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1686 #ifndef OPENSSL_NO_BF
1687 BF_set_key(&bf_ks, 16, key16);
1689 #ifndef OPENSSL_NO_CAST
1690 CAST_set_key(&cast_ks, 16, key16);
1692 #ifndef OPENSSL_NO_RSA
1693 memset(rsa_c, 0, sizeof(rsa_c));
1696 # ifndef OPENSSL_NO_DES
1697 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1703 for (it = count; it; it--)
1704 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1705 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1709 c[D_MD2][0] = count / 10;
1710 c[D_MDC2][0] = count / 10;
1711 c[D_MD4][0] = count;
1712 c[D_MD5][0] = count;
1713 c[D_HMAC][0] = count;
1714 c[D_SHA1][0] = count;
1715 c[D_RMD160][0] = count;
1716 c[D_RC4][0] = count * 5;
1717 c[D_CBC_DES][0] = count;
1718 c[D_EDE3_DES][0] = count / 3;
1719 c[D_CBC_IDEA][0] = count;
1720 c[D_CBC_SEED][0] = count;
1721 c[D_CBC_RC2][0] = count;
1722 c[D_CBC_RC5][0] = count;
1723 c[D_CBC_BF][0] = count;
1724 c[D_CBC_CAST][0] = count;
1725 c[D_CBC_128_AES][0] = count;
1726 c[D_CBC_192_AES][0] = count;
1727 c[D_CBC_256_AES][0] = count;
1728 c[D_CBC_128_CML][0] = count;
1729 c[D_CBC_192_CML][0] = count;
1730 c[D_CBC_256_CML][0] = count;
1731 c[D_SHA256][0] = count;
1732 c[D_SHA512][0] = count;
1733 c[D_WHIRLPOOL][0] = count;
1734 c[D_IGE_128_AES][0] = count;
1735 c[D_IGE_192_AES][0] = count;
1736 c[D_IGE_256_AES][0] = count;
1737 c[D_GHASH][0] = count;
1739 for (i = 1; i < SIZE_NUM; i++) {
1742 l0 = (long)lengths[0];
1743 l1 = (long)lengths[i];
1745 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1746 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1747 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1748 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1749 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1750 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1751 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1752 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1753 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1754 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1755 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1757 l0 = (long)lengths[i - 1];
1759 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1760 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1761 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1762 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1763 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1764 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1765 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1766 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1767 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1768 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1769 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1770 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1771 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1772 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1773 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1774 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1775 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1776 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1779 # ifndef OPENSSL_NO_RSA
1780 rsa_c[R_RSA_512][0] = count / 2000;
1781 rsa_c[R_RSA_512][1] = count / 400;
1782 for (i = 1; i < RSA_NUM; i++) {
1783 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1784 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1785 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1788 if (rsa_c[i][0] == 0) {
1796 # ifndef OPENSSL_NO_DSA
1797 dsa_c[R_DSA_512][0] = count / 1000;
1798 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1799 for (i = 1; i < DSA_NUM; i++) {
1800 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1801 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1802 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1805 if (dsa_c[i] == 0) {
1813 # ifndef OPENSSL_NO_EC
1814 ecdsa_c[R_EC_P160][0] = count / 1000;
1815 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1816 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1817 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1818 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1819 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1822 if (ecdsa_c[i] == 0) {
1828 ecdsa_c[R_EC_K163][0] = count / 1000;
1829 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1830 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1831 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1832 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1833 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1836 if (ecdsa_c[i] == 0) {
1842 ecdsa_c[R_EC_B163][0] = count / 1000;
1843 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1844 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1845 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1846 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1847 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1850 if (ecdsa_c[i] == 0) {
1857 ecdh_c[R_EC_P160][0] = count / 1000;
1858 ecdh_c[R_EC_P160][1] = count / 1000;
1859 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1860 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1861 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1862 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1865 if (ecdh_c[i] == 0) {
1871 ecdh_c[R_EC_K163][0] = count / 1000;
1872 ecdh_c[R_EC_K163][1] = count / 1000;
1873 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1874 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1875 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1876 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1879 if (ecdh_c[i] == 0) {
1885 ecdh_c[R_EC_B163][0] = count / 1000;
1886 ecdh_c[R_EC_B163][1] = count / 1000;
1887 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1888 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1889 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1890 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1893 if (ecdh_c[i] == 0) {
1902 /* not worth fixing */
1903 # error "You cannot disable DES on systems without SIGALRM."
1904 # endif /* OPENSSL_NO_DES */
1907 signal(SIGALRM, sig_done);
1909 #endif /* SIGALRM */
1911 #ifndef OPENSSL_NO_MD2
1913 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1914 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1916 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1918 print_result(D_MD2, testnum, count, d);
1922 #ifndef OPENSSL_NO_MDC2
1924 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1925 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1927 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1929 print_result(D_MDC2, testnum, count, d);
1934 #ifndef OPENSSL_NO_MD4
1936 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1937 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1939 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1941 print_result(D_MD4, testnum, count, d);
1946 #ifndef OPENSSL_NO_MD5
1948 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1949 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1951 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1953 print_result(D_MD5, testnum, count, d);
1958 #ifndef OPENSSL_NO_MD5
1960 for (i = 0; i < loopargs_len; i++) {
1961 loopargs[i].hctx = HMAC_CTX_new();
1962 if (loopargs[i].hctx == NULL) {
1963 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1967 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1968 16, EVP_md5(), NULL);
1970 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1971 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1973 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1975 print_result(D_HMAC, testnum, count, d);
1977 for (i = 0; i < loopargs_len; i++) {
1978 HMAC_CTX_free(loopargs[i].hctx);
1983 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1984 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1986 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1988 print_result(D_SHA1, testnum, count, d);
1991 if (doit[D_SHA256]) {
1992 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1993 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1995 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1997 print_result(D_SHA256, testnum, count, d);
2000 if (doit[D_SHA512]) {
2001 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2002 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
2004 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2006 print_result(D_SHA512, testnum, count, d);
2010 #ifndef OPENSSL_NO_WHIRLPOOL
2011 if (doit[D_WHIRLPOOL]) {
2012 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2013 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
2015 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2017 print_result(D_WHIRLPOOL, testnum, count, d);
2022 #ifndef OPENSSL_NO_RMD160
2023 if (doit[D_RMD160]) {
2024 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2025 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2027 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2029 print_result(D_RMD160, testnum, count, d);
2033 #ifndef OPENSSL_NO_RC4
2035 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2036 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2038 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2040 print_result(D_RC4, testnum, count, d);
2044 #ifndef OPENSSL_NO_DES
2045 if (doit[D_CBC_DES]) {
2046 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2047 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2049 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2051 print_result(D_CBC_DES, testnum, count, d);
2055 if (doit[D_EDE3_DES]) {
2056 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2057 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2059 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2061 print_result(D_EDE3_DES, testnum, count, d);
2065 #ifndef OPENSSL_NO_AES
2066 if (doit[D_CBC_128_AES]) {
2067 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2068 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2071 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2073 print_result(D_CBC_128_AES, testnum, count, d);
2076 if (doit[D_CBC_192_AES]) {
2077 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2078 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2081 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2083 print_result(D_CBC_192_AES, testnum, count, d);
2086 if (doit[D_CBC_256_AES]) {
2087 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2088 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2091 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2093 print_result(D_CBC_256_AES, testnum, count, d);
2097 if (doit[D_IGE_128_AES]) {
2098 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2099 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2102 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2104 print_result(D_IGE_128_AES, testnum, count, d);
2107 if (doit[D_IGE_192_AES]) {
2108 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2109 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2112 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2114 print_result(D_IGE_192_AES, testnum, count, d);
2117 if (doit[D_IGE_256_AES]) {
2118 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2119 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2122 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2124 print_result(D_IGE_256_AES, testnum, count, d);
2127 if (doit[D_GHASH]) {
2128 for (i = 0; i < loopargs_len; i++) {
2129 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2130 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2133 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2134 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2136 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2138 print_result(D_GHASH, testnum, count, d);
2140 for (i = 0; i < loopargs_len; i++)
2141 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2144 #ifndef OPENSSL_NO_CAMELLIA
2145 if (doit[D_CBC_128_CML]) {
2146 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2147 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2149 if (async_jobs > 0) {
2150 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2154 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2155 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2156 (unsigned long)lengths[testnum], &camellia_ks1,
2157 iv, CAMELLIA_ENCRYPT);
2159 print_result(D_CBC_128_CML, testnum, count, d);
2162 if (doit[D_CBC_192_CML]) {
2163 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2164 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2166 if (async_jobs > 0) {
2167 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2171 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2172 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2173 (unsigned long)lengths[testnum], &camellia_ks2,
2174 iv, CAMELLIA_ENCRYPT);
2176 print_result(D_CBC_192_CML, testnum, count, d);
2179 if (doit[D_CBC_256_CML]) {
2180 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2181 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2183 if (async_jobs > 0) {
2184 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2188 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2189 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2190 (unsigned long)lengths[testnum], &camellia_ks3,
2191 iv, CAMELLIA_ENCRYPT);
2193 print_result(D_CBC_256_CML, testnum, count, d);
2197 #ifndef OPENSSL_NO_IDEA
2198 if (doit[D_CBC_IDEA]) {
2199 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2200 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2201 if (async_jobs > 0) {
2202 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2206 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2207 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2208 (unsigned long)lengths[testnum], &idea_ks,
2211 print_result(D_CBC_IDEA, testnum, count, d);
2215 #ifndef OPENSSL_NO_SEED
2216 if (doit[D_CBC_SEED]) {
2217 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2218 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2219 if (async_jobs > 0) {
2220 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2224 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2225 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2226 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2228 print_result(D_CBC_SEED, testnum, count, d);
2232 #ifndef OPENSSL_NO_RC2
2233 if (doit[D_CBC_RC2]) {
2234 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2235 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2236 if (async_jobs > 0) {
2237 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2241 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2242 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2243 (unsigned long)lengths[testnum], &rc2_ks,
2246 print_result(D_CBC_RC2, testnum, count, d);
2250 #ifndef OPENSSL_NO_RC5
2251 if (doit[D_CBC_RC5]) {
2252 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2253 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2254 if (async_jobs > 0) {
2255 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2259 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2260 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2261 (unsigned long)lengths[testnum], &rc5_ks,
2264 print_result(D_CBC_RC5, testnum, count, d);
2268 #ifndef OPENSSL_NO_BF
2269 if (doit[D_CBC_BF]) {
2270 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2271 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2272 if (async_jobs > 0) {
2273 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2277 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2278 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2279 (unsigned long)lengths[testnum], &bf_ks,
2282 print_result(D_CBC_BF, testnum, count, d);
2286 #ifndef OPENSSL_NO_CAST
2287 if (doit[D_CBC_CAST]) {
2288 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2289 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2290 if (async_jobs > 0) {
2291 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2295 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2296 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2297 (unsigned long)lengths[testnum], &cast_ks,
2300 print_result(D_CBC_CAST, testnum, count, d);
2306 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2307 if (multiblock && evp_cipher) {
2309 (EVP_CIPHER_flags(evp_cipher) &
2310 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2311 BIO_printf(bio_err, "%s is not multi-block capable\n",
2312 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2315 if (async_jobs > 0) {
2316 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2319 multiblock_speed(evp_cipher);
2324 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2327 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2329 * -O3 -fschedule-insns messes up an optimization here!
2330 * names[D_EVP] somehow becomes NULL
2332 print_message(names[D_EVP], save_count, lengths[testnum]);
2334 for (k = 0; k < loopargs_len; k++) {
2335 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2337 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2339 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2340 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2344 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2346 for (k = 0; k < loopargs_len; k++) {
2347 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2351 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2352 print_message(names[D_EVP], save_count, lengths[testnum]);
2354 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2357 print_result(D_EVP, testnum, count, d);
2361 for (i = 0; i < loopargs_len; i++)
2362 RAND_bytes(loopargs[i].buf, 36);
2364 #ifndef OPENSSL_NO_RSA
2365 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2367 if (!rsa_doit[testnum])
2369 for (i = 0; i < loopargs_len; i++) {
2370 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2371 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2377 "RSA sign failure. No RSA sign will be done.\n");
2378 ERR_print_errors(bio_err);
2381 pkey_print_message("private", "rsa",
2382 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2383 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2385 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2388 mr ? "+R1:%ld:%d:%.2f\n"
2389 : "%ld %d bit private RSA's in %.2fs\n",
2390 count, rsa_bits[testnum], d);
2391 rsa_results[testnum][0] = d / (double)count;
2395 for (i = 0; i < loopargs_len; i++) {
2396 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2397 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2403 "RSA verify failure. No RSA verify will be done.\n");
2404 ERR_print_errors(bio_err);
2405 rsa_doit[testnum] = 0;
2407 pkey_print_message("public", "rsa",
2408 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2410 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2413 mr ? "+R2:%ld:%d:%.2f\n"
2414 : "%ld %d bit public RSA's in %.2fs\n",
2415 count, rsa_bits[testnum], d);
2416 rsa_results[testnum][1] = d / (double)count;
2419 if (rsa_count <= 1) {
2420 /* if longer than 10s, don't do any more */
2421 for (testnum++; testnum < RSA_NUM; testnum++)
2422 rsa_doit[testnum] = 0;
2427 for (i = 0; i < loopargs_len; i++)
2428 RAND_bytes(loopargs[i].buf, 36);
2430 #ifndef OPENSSL_NO_DSA
2431 if (RAND_status() != 1) {
2432 RAND_seed(rnd_seed, sizeof rnd_seed);
2435 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2437 if (!dsa_doit[testnum])
2440 /* DSA_generate_key(dsa_key[testnum]); */
2441 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2442 for (i = 0; i < loopargs_len; i++) {
2443 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2444 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2450 "DSA sign failure. No DSA sign will be done.\n");
2451 ERR_print_errors(bio_err);
2454 pkey_print_message("sign", "dsa",
2455 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2457 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2460 mr ? "+R3:%ld:%d:%.2f\n"
2461 : "%ld %d bit DSA signs in %.2fs\n",
2462 count, dsa_bits[testnum], d);
2463 dsa_results[testnum][0] = d / (double)count;
2467 for (i = 0; i < loopargs_len; i++) {
2468 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2469 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2475 "DSA verify failure. No DSA verify will be done.\n");
2476 ERR_print_errors(bio_err);
2477 dsa_doit[testnum] = 0;
2479 pkey_print_message("verify", "dsa",
2480 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2482 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2485 mr ? "+R4:%ld:%d:%.2f\n"
2486 : "%ld %d bit DSA verify in %.2fs\n",
2487 count, dsa_bits[testnum], d);
2488 dsa_results[testnum][1] = d / (double)count;
2491 if (rsa_count <= 1) {
2492 /* if longer than 10s, don't do any more */
2493 for (testnum++; testnum < DSA_NUM; testnum++)
2494 dsa_doit[testnum] = 0;
2501 #ifndef OPENSSL_NO_EC
2502 if (RAND_status() != 1) {
2503 RAND_seed(rnd_seed, sizeof rnd_seed);
2506 for (testnum = 0; testnum < EC_NUM; testnum++) {
2509 if (!ecdsa_doit[testnum])
2510 continue; /* Ignore Curve */
2511 for (i = 0; i < loopargs_len; i++) {
2512 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2513 if (loopargs[i].ecdsa[testnum] == NULL) {
2519 BIO_printf(bio_err, "ECDSA failure.\n");
2520 ERR_print_errors(bio_err);
2523 for (i = 0; i < loopargs_len; i++) {
2524 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2525 /* Perform ECDSA signature test */
2526 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2527 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2528 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2534 "ECDSA sign failure. No ECDSA sign will be done.\n");
2535 ERR_print_errors(bio_err);
2538 pkey_print_message("sign", "ecdsa",
2539 ecdsa_c[testnum][0],
2540 test_curves_bits[testnum], ECDSA_SECONDS);
2542 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2546 mr ? "+R5:%ld:%d:%.2f\n" :
2547 "%ld %d bit ECDSA signs in %.2fs \n",
2548 count, test_curves_bits[testnum], d);
2549 ecdsa_results[testnum][0] = d / (double)count;
2553 /* Perform ECDSA verification test */
2554 for (i = 0; i < loopargs_len; i++) {
2555 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2556 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2562 "ECDSA verify failure. No ECDSA verify will be done.\n");
2563 ERR_print_errors(bio_err);
2564 ecdsa_doit[testnum] = 0;
2566 pkey_print_message("verify", "ecdsa",
2567 ecdsa_c[testnum][1],
2568 test_curves_bits[testnum], ECDSA_SECONDS);
2570 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2573 mr ? "+R6:%ld:%d:%.2f\n"
2574 : "%ld %d bit ECDSA verify in %.2fs\n",
2575 count, test_curves_bits[testnum], d);
2576 ecdsa_results[testnum][1] = d / (double)count;
2579 if (rsa_count <= 1) {
2580 /* if longer than 10s, don't do any more */
2581 for (testnum++; testnum < EC_NUM; testnum++)
2582 ecdsa_doit[testnum] = 0;
2590 #ifndef OPENSSL_NO_EC
2591 if (RAND_status() != 1) {
2592 RAND_seed(rnd_seed, sizeof rnd_seed);
2595 for (testnum = 0; testnum < EC_NUM; testnum++) {
2596 if (!ecdh_doit[testnum])
2598 for (i = 0; i < loopargs_len; i++) {
2599 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2600 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2601 if (loopargs[i].ecdh_a[testnum] == NULL ||
2602 loopargs[i].ecdh_b[testnum] == NULL) {
2607 if (ecdh_checks == 0) {
2608 BIO_printf(bio_err, "ECDH failure.\n");
2609 ERR_print_errors(bio_err);
2612 for (i = 0; i < loopargs_len; i++) {
2613 /* generate two ECDH key pairs */
2614 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2615 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2616 BIO_printf(bio_err, "ECDH key generation failure.\n");
2617 ERR_print_errors(bio_err);
2622 * If field size is not more than 24 octets, then use SHA-1
2623 * hash of result; otherwise, use result (see section 4.8 of
2624 * draft-ietf-tls-ecc-03.txt).
2628 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2629 if (field_size <= 24 * 8) {
2630 outlen = KDF1_SHA1_len;
2633 outlen = (field_size + 7) / 8;
2637 ECDH_compute_key(loopargs[i].secret_a, outlen,
2638 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2639 loopargs[i].ecdh_a[testnum], kdf);
2641 ECDH_compute_key(loopargs[i].secret_b, outlen,
2642 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2643 loopargs[i].ecdh_b[testnum], kdf);
2644 if (secret_size_a != secret_size_b)
2649 for (secret_idx = 0; (secret_idx < secret_size_a)
2650 && (ecdh_checks == 1); secret_idx++) {
2651 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2655 if (ecdh_checks == 0) {
2656 BIO_printf(bio_err, "ECDH computations don't match.\n");
2657 ERR_print_errors(bio_err);
2662 if (ecdh_checks != 0) {
2663 pkey_print_message("", "ecdh",
2665 test_curves_bits[testnum], ECDH_SECONDS);
2667 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2670 mr ? "+R7:%ld:%d:%.2f\n" :
2671 "%ld %d-bit ECDH ops in %.2fs\n", count,
2672 test_curves_bits[testnum], d);
2673 ecdh_results[testnum][0] = d / (double)count;
2679 if (rsa_count <= 1) {
2680 /* if longer than 10s, don't do any more */
2681 for (testnum++; testnum < EC_NUM; testnum++)
2682 ecdh_doit[testnum] = 0;
2692 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2693 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2695 printf("%s ", BN_options());
2696 #ifndef OPENSSL_NO_MD2
2697 printf("%s ", MD2_options());
2699 #ifndef OPENSSL_NO_RC4
2700 printf("%s ", RC4_options());
2702 #ifndef OPENSSL_NO_DES
2703 printf("%s ", DES_options());
2705 #ifndef OPENSSL_NO_AES
2706 printf("%s ", AES_options());
2708 #ifndef OPENSSL_NO_IDEA
2709 printf("%s ", idea_options());
2711 #ifndef OPENSSL_NO_BF
2712 printf("%s ", BF_options());
2714 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2722 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2725 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2726 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2730 for (k = 0; k < ALGOR_NUM; k++) {
2734 printf("+F:%d:%s", k, names[k]);
2736 printf("%-13s", names[k]);
2737 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2738 if (results[k][testnum] > 10000 && !mr)
2739 printf(" %11.2fk", results[k][testnum] / 1e3);
2741 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2745 #ifndef OPENSSL_NO_RSA
2747 for (k = 0; k < RSA_NUM; k++) {
2750 if (testnum && !mr) {
2751 printf("%18ssign verify sign/s verify/s\n", " ");
2755 printf("+F2:%u:%u:%f:%f\n",
2756 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2758 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2759 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2760 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2763 #ifndef OPENSSL_NO_DSA
2765 for (k = 0; k < DSA_NUM; k++) {
2768 if (testnum && !mr) {
2769 printf("%18ssign verify sign/s verify/s\n", " ");
2773 printf("+F3:%u:%u:%f:%f\n",
2774 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2776 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2777 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2778 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2781 #ifndef OPENSSL_NO_EC
2783 for (k = 0; k < EC_NUM; k++) {
2786 if (testnum && !mr) {
2787 printf("%30ssign verify sign/s verify/s\n", " ");
2792 printf("+F4:%u:%u:%f:%f\n",
2793 k, test_curves_bits[k],
2794 ecdsa_results[k][0], ecdsa_results[k][1]);
2796 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2797 test_curves_bits[k],
2798 test_curves_names[k],
2799 ecdsa_results[k][0], ecdsa_results[k][1],
2800 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2804 #ifndef OPENSSL_NO_EC
2806 for (k = 0; k < EC_NUM; k++) {
2809 if (testnum && !mr) {
2810 printf("%30sop op/s\n", " ");
2814 printf("+F5:%u:%u:%f:%f\n",
2815 k, test_curves_bits[k],
2816 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2819 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2820 test_curves_bits[k],
2821 test_curves_names[k],
2822 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2829 ERR_print_errors(bio_err);
2830 for (i = 0; i < loopargs_len; i++) {
2831 if (loopargs[i].buf_malloc != NULL)
2832 OPENSSL_free(loopargs[i].buf_malloc);
2833 if (loopargs[i].buf2_malloc != NULL)
2834 OPENSSL_free(loopargs[i].buf2_malloc);
2835 if (loopargs[i].siglen != NULL)
2836 OPENSSL_free(loopargs[i].siglen);
2838 if (loopargs != NULL)
2839 OPENSSL_free(loopargs);
2840 #ifndef OPENSSL_NO_RSA
2841 for (i = 0; i < loopargs_len; i++) {
2842 for (k = 0; k < RSA_NUM; k++)
2843 RSA_free(loopargs[i].rsa_key[k]);
2846 #ifndef OPENSSL_NO_DSA
2847 for (i = 0; i < loopargs_len; i++) {
2848 for (k = 0; k < DSA_NUM; k++)
2849 DSA_free(loopargs[i].dsa_key[k]);
2853 #ifndef OPENSSL_NO_EC
2854 for (i = 0; i < loopargs_len; i++) {
2855 for (k = 0; k < EC_NUM; k++) {
2856 EC_KEY_free(loopargs[i].ecdsa[k]);
2857 EC_KEY_free(loopargs[i].ecdh_a[k]);
2858 EC_KEY_free(loopargs[i].ecdh_b[k]);
2860 if (loopargs[i].secret_a)
2861 OPENSSL_free(loopargs[i].secret_a);
2862 if (loopargs[i].secret_b)
2863 OPENSSL_free(loopargs[i].secret_b);
2867 ASYNC_cleanup_thread();
2871 static void print_message(const char *s, long num, int length)
2875 mr ? "+DT:%s:%d:%d\n"
2876 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2877 (void)BIO_flush(bio_err);
2881 mr ? "+DN:%s:%ld:%d\n"
2882 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2883 (void)BIO_flush(bio_err);
2887 static void pkey_print_message(const char *str, const char *str2, long num,
2892 mr ? "+DTP:%d:%s:%s:%d\n"
2893 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2894 (void)BIO_flush(bio_err);
2898 mr ? "+DNP:%ld:%d:%s:%s\n"
2899 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2900 (void)BIO_flush(bio_err);
2904 static void print_result(int alg, int run_no, int count, double time_used)
2907 mr ? "+R:%d:%s:%f\n"
2908 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2909 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2913 static char *sstrsep(char **string, const char *delim)
2916 char *token = *string;
2921 memset(isdelim, 0, sizeof isdelim);
2925 isdelim[(unsigned char)(*delim)] = 1;
2929 while (!isdelim[(unsigned char)(**string)]) {
2941 static int do_multi(int multi)
2946 static char sep[] = ":";
2948 fds = malloc(sizeof(*fds) * multi);
2949 for (n = 0; n < multi; ++n) {
2950 if (pipe(fd) == -1) {
2951 BIO_printf(bio_err, "pipe failure\n");
2955 (void)BIO_flush(bio_err);
2962 if (dup(fd[1]) == -1) {
2963 BIO_printf(bio_err, "dup failed\n");
2972 printf("Forked child %d\n", n);
2975 /* for now, assume the pipe is long enough to take all the output */
2976 for (n = 0; n < multi; ++n) {
2981 f = fdopen(fds[n], "r");
2982 while (fgets(buf, sizeof buf, f)) {
2983 p = strchr(buf, '\n');
2986 if (buf[0] != '+') {
2987 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2991 printf("Got: %s from %d\n", buf, n);
2992 if (strncmp(buf, "+F:", 3) == 0) {
2997 alg = atoi(sstrsep(&p, sep));
2999 for (j = 0; j < SIZE_NUM; ++j)
3000 results[alg][j] += atof(sstrsep(&p, sep));
3001 } else if (strncmp(buf, "+F2:", 4) == 0) {
3006 k = atoi(sstrsep(&p, sep));
3009 d = atof(sstrsep(&p, sep));
3011 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
3013 rsa_results[k][0] = d;
3015 d = atof(sstrsep(&p, sep));
3017 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3019 rsa_results[k][1] = d;
3021 # ifndef OPENSSL_NO_DSA
3022 else if (strncmp(buf, "+F3:", 4) == 0) {
3027 k = atoi(sstrsep(&p, sep));
3030 d = atof(sstrsep(&p, sep));
3032 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3034 dsa_results[k][0] = d;
3036 d = atof(sstrsep(&p, sep));
3038 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3040 dsa_results[k][1] = d;
3043 # ifndef OPENSSL_NO_EC
3044 else if (strncmp(buf, "+F4:", 4) == 0) {
3049 k = atoi(sstrsep(&p, sep));
3052 d = atof(sstrsep(&p, sep));
3054 ecdsa_results[k][0] =
3055 1 / (1 / ecdsa_results[k][0] + 1 / d);
3057 ecdsa_results[k][0] = d;
3059 d = atof(sstrsep(&p, sep));
3061 ecdsa_results[k][1] =
3062 1 / (1 / ecdsa_results[k][1] + 1 / d);
3064 ecdsa_results[k][1] = d;
3068 # ifndef OPENSSL_NO_EC
3069 else if (strncmp(buf, "+F5:", 4) == 0) {
3074 k = atoi(sstrsep(&p, sep));
3077 d = atof(sstrsep(&p, sep));
3079 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3081 ecdh_results[k][0] = d;
3086 else if (strncmp(buf, "+H:", 3) == 0) {
3089 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3099 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3101 static int mblengths[] =
3102 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3103 int j, count, num = OSSL_NELEM(mblengths);
3104 const char *alg_name;
3105 unsigned char *inp, *out, no_key[32], no_iv[16];
3106 EVP_CIPHER_CTX *ctx;
3109 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3110 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3111 ctx = EVP_CIPHER_CTX_new();
3112 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3113 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3115 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3117 for (j = 0; j < num; j++) {
3118 print_message(alg_name, 0, mblengths[j]);
3120 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3121 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3122 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3123 size_t len = mblengths[j];
3126 memset(aad, 0, 8); /* avoid uninitialized values */
3127 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3128 aad[9] = 3; /* version */
3130 aad[11] = 0; /* length */
3132 mb_param.out = NULL;
3135 mb_param.interleave = 8;
3137 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3138 sizeof(mb_param), &mb_param);
3144 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3145 sizeof(mb_param), &mb_param);
3149 RAND_bytes(out, 16);
3153 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3154 EVP_AEAD_TLS1_AAD_LEN, aad);
3155 EVP_Cipher(ctx, out, inp, len + pad);
3159 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3160 : "%d %s's in %.2fs\n", count, "evp", d);
3161 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3165 fprintf(stdout, "+H");
3166 for (j = 0; j < num; j++)
3167 fprintf(stdout, ":%d", mblengths[j]);
3168 fprintf(stdout, "\n");
3169 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3170 for (j = 0; j < num; j++)
3171 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3172 fprintf(stdout, "\n");
3175 "The 'numbers' are in 1000s of bytes per second processed.\n");
3176 fprintf(stdout, "type ");
3177 for (j = 0; j < num; j++)
3178 fprintf(stdout, "%7d bytes", mblengths[j]);
3179 fprintf(stdout, "\n");
3180 fprintf(stdout, "%-24s", alg_name);
3182 for (j = 0; j < num; j++) {
3183 if (results[D_EVP][j] > 10000)
3184 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3186 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3188 fprintf(stdout, "\n");
3193 EVP_CIPHER_CTX_free(ctx);