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
98 #include <openssl/bn.h>
99 #ifndef OPENSSL_NO_DES
100 # include <openssl/des.h>
102 #ifndef OPENSSL_NO_AES
103 # include <openssl/aes.h>
105 #ifndef OPENSSL_NO_CAMELLIA
106 # include <openssl/camellia.h>
108 #ifndef OPENSSL_NO_MD2
109 # include <openssl/md2.h>
111 #ifndef OPENSSL_NO_MDC2
112 # include <openssl/mdc2.h>
114 #ifndef OPENSSL_NO_MD4
115 # include <openssl/md4.h>
117 #ifndef OPENSSL_NO_MD5
118 # include <openssl/md5.h>
120 #include <openssl/hmac.h>
121 #include <openssl/sha.h>
122 #ifndef OPENSSL_NO_RMD160
123 # include <openssl/ripemd.h>
125 #ifndef OPENSSL_NO_WHIRLPOOL
126 # include <openssl/whrlpool.h>
128 #ifndef OPENSSL_NO_RC4
129 # include <openssl/rc4.h>
131 #ifndef OPENSSL_NO_RC5
132 # include <openssl/rc5.h>
134 #ifndef OPENSSL_NO_RC2
135 # include <openssl/rc2.h>
137 #ifndef OPENSSL_NO_IDEA
138 # include <openssl/idea.h>
140 #ifndef OPENSSL_NO_SEED
141 # include <openssl/seed.h>
143 #ifndef OPENSSL_NO_BF
144 # include <openssl/blowfish.h>
146 #ifndef OPENSSL_NO_CAST
147 # include <openssl/cast.h>
149 #ifndef OPENSSL_NO_RSA
150 # include <openssl/rsa.h>
151 # include "./testrsa.h"
153 #include <openssl/x509.h>
154 #ifndef OPENSSL_NO_DSA
155 # include <openssl/dsa.h>
156 # include "./testdsa.h"
158 #ifndef OPENSSL_NO_EC
159 # include <openssl/ec.h>
161 #include <openssl/modes.h>
164 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
178 #define BUFSIZE (1024*16+1)
179 #define MAX_MISALIGNMENT 63
188 #define MAX_ECDH_SIZE 256
191 static volatile int run = 0;
194 static int usertime = 1;
196 typedef struct loopargs_st {
197 ASYNC_JOB *inprogress_job;
198 ASYNC_WAIT_CTX *wait_ctx;
201 unsigned char *buf_malloc;
202 unsigned char *buf2_malloc;
203 unsigned int *siglen;
204 #ifndef OPENSSL_NO_RSA
205 RSA *rsa_key[RSA_NUM];
207 #ifndef OPENSSL_NO_DSA
208 DSA *dsa_key[DSA_NUM];
210 #ifndef OPENSSL_NO_EC
211 EC_KEY *ecdsa[EC_NUM];
212 EC_KEY *ecdh_a[EC_NUM];
213 EC_KEY *ecdh_b[EC_NUM];
214 unsigned char *secret_a;
215 unsigned char *secret_b;
219 GCM128_CONTEXT *gcm_ctx;
222 #ifndef OPENSSL_NO_MD2
223 static int EVP_Digest_MD2_loop(void *args);
226 #ifndef OPENSSL_NO_MDC2
227 static int EVP_Digest_MDC2_loop(void *args);
229 #ifndef OPENSSL_NO_MD4
230 static int EVP_Digest_MD4_loop(void *args);
232 #ifndef OPENSSL_NO_MD5
233 static int MD5_loop(void *args);
234 static int HMAC_loop(void *args);
236 static int SHA1_loop(void *args);
237 static int SHA256_loop(void *args);
238 static int SHA512_loop(void *args);
239 #ifndef OPENSSL_NO_WHIRLPOOL
240 static int WHIRLPOOL_loop(void *args);
242 #ifndef OPENSSL_NO_RMD160
243 static int EVP_Digest_RMD160_loop(void *args);
245 #ifndef OPENSSL_NO_RC4
246 static int RC4_loop(void *args);
248 #ifndef OPENSSL_NO_DES
249 static int DES_ncbc_encrypt_loop(void *args);
250 static int DES_ede3_cbc_encrypt_loop(void *args);
252 #ifndef OPENSSL_NO_AES
253 static int AES_cbc_128_encrypt_loop(void *args);
254 static int AES_cbc_192_encrypt_loop(void *args);
255 static int AES_ige_128_encrypt_loop(void *args);
256 static int AES_cbc_256_encrypt_loop(void *args);
257 static int AES_ige_192_encrypt_loop(void *args);
258 static int AES_ige_256_encrypt_loop(void *args);
259 static int CRYPTO_gcm128_aad_loop(void *args);
261 static int EVP_Update_loop(void *args);
262 static int EVP_Digest_loop(void *args);
263 #ifndef OPENSSL_NO_RSA
264 static int RSA_sign_loop(void *args);
265 static int RSA_verify_loop(void *args);
267 #ifndef OPENSSL_NO_DSA
268 static int DSA_sign_loop(void *args);
269 static int DSA_verify_loop(void *args);
271 #ifndef OPENSSL_NO_EC
272 static int ECDSA_sign_loop(void *args);
273 static int ECDSA_verify_loop(void *args);
274 static int ECDH_compute_key_loop(void *args);
276 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
278 static double Time_F(int s);
279 static void print_message(const char *s, long num, int length);
280 static void pkey_print_message(const char *str, const char *str2,
281 long num, int bits, int sec);
282 static void print_result(int alg, int run_no, int count, double time_used);
284 static int do_multi(int multi);
287 static const char *names[ALGOR_NUM] = {
288 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
289 "des cbc", "des ede3", "idea cbc", "seed cbc",
290 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
291 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
292 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
293 "evp", "sha256", "sha512", "whirlpool",
294 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
297 static double results[ALGOR_NUM][SIZE_NUM];
298 static int lengths[SIZE_NUM] = {
299 16, 64, 256, 1024, 8 * 1024, 16 * 1024
302 #ifndef OPENSSL_NO_RSA
303 static double rsa_results[RSA_NUM][2];
305 #ifndef OPENSSL_NO_DSA
306 static double dsa_results[DSA_NUM][2];
308 #ifndef OPENSSL_NO_EC
309 static double ecdsa_results[EC_NUM][2];
310 static double ecdh_results[EC_NUM][1];
313 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
314 static const char rnd_seed[] =
315 "string to make the random number generator think it has entropy";
319 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
320 # define SIGRETTYPE void
322 # define SIGRETTYPE int
325 static SIGRETTYPE sig_done(int sig);
326 static SIGRETTYPE sig_done(int sig)
328 signal(SIGALRM, sig_done);
338 # if !defined(SIGALRM)
341 static unsigned int lapse, schlock;
342 static void alarm_win32(unsigned int secs)
347 # define alarm alarm_win32
349 static DWORD WINAPI sleepy(VOID * arg)
357 static double Time_F(int s)
364 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
366 DWORD err = GetLastError();
367 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
371 Sleep(0); /* scheduler spinlock */
372 ret = app_tminterval(s, usertime);
374 ret = app_tminterval(s, usertime);
376 TerminateThread(thr, 0);
384 static double Time_F(int s)
386 double ret = app_tminterval(s, usertime);
393 #ifndef OPENSSL_NO_EC
394 static const int KDF1_SHA1_len = 20;
395 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
398 if (*outlen < SHA_DIGEST_LENGTH)
400 *outlen = SHA_DIGEST_LENGTH;
401 return SHA1(in, inlen, out);
403 #endif /* OPENSSL_NO_EC */
405 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
407 static int found(const char *name, const OPT_PAIR * pairs, int *result)
409 for (; pairs->name; pairs++)
410 if (strcmp(name, pairs->name) == 0) {
411 *result = pairs->retval;
417 typedef enum OPTION_choice {
418 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
419 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
420 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
423 OPTIONS speed_options[] = {
424 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
425 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
426 {"help", OPT_HELP, '-', "Display this summary"},
427 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
428 {"decrypt", OPT_DECRYPT, '-',
429 "Time decryption instead of encryption (only EVP)"},
430 {"mr", OPT_MR, '-', "Produce machine readable output"},
432 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
433 {"elapsed", OPT_ELAPSED, '-',
434 "Measure time in real time instead of CPU user time"},
436 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
438 #ifndef OPENSSL_NO_ASYNC
439 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
441 #ifndef OPENSSL_NO_ENGINE
442 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
457 #define D_CBC_IDEA 10
458 #define D_CBC_SEED 11
462 #define D_CBC_CAST 15
463 #define D_CBC_128_AES 16
464 #define D_CBC_192_AES 17
465 #define D_CBC_256_AES 18
466 #define D_CBC_128_CML 19
467 #define D_CBC_192_CML 20
468 #define D_CBC_256_CML 21
472 #define D_WHIRLPOOL 25
473 #define D_IGE_128_AES 26
474 #define D_IGE_192_AES 27
475 #define D_IGE_256_AES 28
477 static OPT_PAIR doit_choices[] = {
478 #ifndef OPENSSL_NO_MD2
481 #ifndef OPENSSL_NO_MDC2
484 #ifndef OPENSSL_NO_MD4
487 #ifndef OPENSSL_NO_MD5
490 #ifndef OPENSSL_NO_MD5
494 {"sha256", D_SHA256},
495 {"sha512", D_SHA512},
496 #ifndef OPENSSL_NO_WHIRLPOOL
497 {"whirlpool", D_WHIRLPOOL},
499 #ifndef OPENSSL_NO_RMD160
500 {"ripemd", D_RMD160},
501 {"rmd160", D_RMD160},
502 {"ripemd160", D_RMD160},
504 #ifndef OPENSSL_NO_RC4
507 #ifndef OPENSSL_NO_DES
508 {"des-cbc", D_CBC_DES},
509 {"des-ede3", D_EDE3_DES},
511 #ifndef OPENSSL_NO_AES
512 {"aes-128-cbc", D_CBC_128_AES},
513 {"aes-192-cbc", D_CBC_192_AES},
514 {"aes-256-cbc", D_CBC_256_AES},
515 {"aes-128-ige", D_IGE_128_AES},
516 {"aes-192-ige", D_IGE_192_AES},
517 {"aes-256-ige", D_IGE_256_AES},
519 #ifndef OPENSSL_NO_RC2
520 {"rc2-cbc", D_CBC_RC2},
523 #ifndef OPENSSL_NO_RC5
524 {"rc5-cbc", D_CBC_RC5},
527 #ifndef OPENSSL_NO_IDEA
528 {"idea-cbc", D_CBC_IDEA},
529 {"idea", D_CBC_IDEA},
531 #ifndef OPENSSL_NO_SEED
532 {"seed-cbc", D_CBC_SEED},
533 {"seed", D_CBC_SEED},
535 #ifndef OPENSSL_NO_BF
536 {"bf-cbc", D_CBC_BF},
537 {"blowfish", D_CBC_BF},
540 #ifndef OPENSSL_NO_CAST
541 {"cast-cbc", D_CBC_CAST},
542 {"cast", D_CBC_CAST},
543 {"cast5", D_CBC_CAST},
549 #ifndef OPENSSL_NO_DSA
551 # define R_DSA_1024 1
552 # define R_DSA_2048 2
553 static OPT_PAIR dsa_choices[] = {
554 {"dsa512", R_DSA_512},
555 {"dsa1024", R_DSA_1024},
556 {"dsa2048", R_DSA_2048},
567 #define R_RSA_15360 6
568 static OPT_PAIR rsa_choices[] = {
569 {"rsa512", R_RSA_512},
570 {"rsa1024", R_RSA_1024},
571 {"rsa2048", R_RSA_2048},
572 {"rsa3072", R_RSA_3072},
573 {"rsa4096", R_RSA_4096},
574 {"rsa7680", R_RSA_7680},
575 {"rsa15360", R_RSA_15360},
595 #define R_EC_X25519 16
596 #ifndef OPENSSL_NO_EC
597 static OPT_PAIR ecdsa_choices[] = {
598 {"ecdsap160", R_EC_P160},
599 {"ecdsap192", R_EC_P192},
600 {"ecdsap224", R_EC_P224},
601 {"ecdsap256", R_EC_P256},
602 {"ecdsap384", R_EC_P384},
603 {"ecdsap521", R_EC_P521},
604 {"ecdsak163", R_EC_K163},
605 {"ecdsak233", R_EC_K233},
606 {"ecdsak283", R_EC_K283},
607 {"ecdsak409", R_EC_K409},
608 {"ecdsak571", R_EC_K571},
609 {"ecdsab163", R_EC_B163},
610 {"ecdsab233", R_EC_B233},
611 {"ecdsab283", R_EC_B283},
612 {"ecdsab409", R_EC_B409},
613 {"ecdsab571", R_EC_B571},
616 static OPT_PAIR ecdh_choices[] = {
617 {"ecdhp160", R_EC_P160},
618 {"ecdhp192", R_EC_P192},
619 {"ecdhp224", R_EC_P224},
620 {"ecdhp256", R_EC_P256},
621 {"ecdhp384", R_EC_P384},
622 {"ecdhp521", R_EC_P521},
623 {"ecdhk163", R_EC_K163},
624 {"ecdhk233", R_EC_K233},
625 {"ecdhk283", R_EC_K283},
626 {"ecdhk409", R_EC_K409},
627 {"ecdhk571", R_EC_K571},
628 {"ecdhb163", R_EC_B163},
629 {"ecdhb233", R_EC_B233},
630 {"ecdhb283", R_EC_B283},
631 {"ecdhb409", R_EC_B409},
632 {"ecdhb571", R_EC_B571},
633 {"ecdhx25519", R_EC_X25519},
639 # define COND(d) (count < (d))
640 # define COUNT(d) (d)
642 # define COND(c) (run && count<0x7fffffff)
643 # define COUNT(d) (count)
647 static char *engine_id = NULL;
650 #ifndef OPENSSL_NO_MD2
651 static int EVP_Digest_MD2_loop(void *args)
653 loopargs_t *tempargs = (loopargs_t *)args;
654 unsigned char *buf = tempargs->buf;
655 unsigned char md2[MD2_DIGEST_LENGTH];
657 for (count = 0; COND(c[D_MD2][testnum]); count++)
658 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
664 #ifndef OPENSSL_NO_MDC2
665 static int EVP_Digest_MDC2_loop(void *args)
667 loopargs_t *tempargs = (loopargs_t *)args;
668 unsigned char *buf = tempargs->buf;
669 unsigned char mdc2[MDC2_DIGEST_LENGTH];
671 for (count = 0; COND(c[D_MDC2][testnum]); count++)
672 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
678 #ifndef OPENSSL_NO_MD4
679 static int EVP_Digest_MD4_loop(void *args)
681 loopargs_t *tempargs = (loopargs_t *)args;
682 unsigned char *buf = tempargs->buf;
683 unsigned char md4[MD4_DIGEST_LENGTH];
685 for (count = 0; COND(c[D_MD4][testnum]); count++)
686 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
687 NULL, EVP_md4(), NULL);
692 #ifndef OPENSSL_NO_MD5
693 static int MD5_loop(void *args)
695 loopargs_t *tempargs = (loopargs_t *)args;
696 unsigned char *buf = tempargs->buf;
697 unsigned char md5[MD5_DIGEST_LENGTH];
699 for (count = 0; COND(c[D_MD5][testnum]); count++)
700 MD5(buf, lengths[testnum], md5);
704 static int HMAC_loop(void *args)
706 loopargs_t *tempargs = (loopargs_t *)args;
707 unsigned char *buf = tempargs->buf;
708 HMAC_CTX *hctx = tempargs->hctx;
709 unsigned char hmac[MD5_DIGEST_LENGTH];
711 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
712 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
713 HMAC_Update(hctx, buf, lengths[testnum]);
714 HMAC_Final(hctx, &(hmac[0]), NULL);
720 static int SHA1_loop(void *args)
722 loopargs_t *tempargs = (loopargs_t *)args;
723 unsigned char *buf = tempargs->buf;
724 unsigned char sha[SHA_DIGEST_LENGTH];
726 for (count = 0; COND(c[D_SHA1][testnum]); count++)
727 SHA1(buf, lengths[testnum], sha);
731 static int SHA256_loop(void *args)
733 loopargs_t *tempargs = (loopargs_t *)args;
734 unsigned char *buf = tempargs->buf;
735 unsigned char sha256[SHA256_DIGEST_LENGTH];
737 for (count = 0; COND(c[D_SHA256][testnum]); count++)
738 SHA256(buf, lengths[testnum], sha256);
742 static int SHA512_loop(void *args)
744 loopargs_t *tempargs = (loopargs_t *)args;
745 unsigned char *buf = tempargs->buf;
746 unsigned char sha512[SHA512_DIGEST_LENGTH];
748 for (count = 0; COND(c[D_SHA512][testnum]); count++)
749 SHA512(buf, lengths[testnum], sha512);
753 #ifndef OPENSSL_NO_WHIRLPOOL
754 static int WHIRLPOOL_loop(void *args)
756 loopargs_t *tempargs = (loopargs_t *)args;
757 unsigned char *buf = tempargs->buf;
758 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
760 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
761 WHIRLPOOL(buf, lengths[testnum], whirlpool);
766 #ifndef OPENSSL_NO_RMD160
767 static int EVP_Digest_RMD160_loop(void *args)
769 loopargs_t *tempargs = (loopargs_t *)args;
770 unsigned char *buf = tempargs->buf;
771 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
773 for (count = 0; COND(c[D_RMD160][testnum]); count++)
774 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
775 EVP_ripemd160(), NULL);
780 #ifndef OPENSSL_NO_RC4
781 static RC4_KEY rc4_ks;
782 static int RC4_loop(void *args)
784 loopargs_t *tempargs = (loopargs_t *)args;
785 unsigned char *buf = tempargs->buf;
787 for (count = 0; COND(c[D_RC4][testnum]); count++)
788 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
793 #ifndef OPENSSL_NO_DES
794 static unsigned char DES_iv[8];
795 static DES_key_schedule sch;
796 static DES_key_schedule sch2;
797 static DES_key_schedule sch3;
798 static int DES_ncbc_encrypt_loop(void *args)
800 loopargs_t *tempargs = (loopargs_t *)args;
801 unsigned char *buf = tempargs->buf;
803 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
804 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
805 &DES_iv, DES_ENCRYPT);
809 static int DES_ede3_cbc_encrypt_loop(void *args)
811 loopargs_t *tempargs = (loopargs_t *)args;
812 unsigned char *buf = tempargs->buf;
814 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
815 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
817 &DES_iv, DES_ENCRYPT);
822 #ifndef OPENSSL_NO_AES
823 # define MAX_BLOCK_SIZE 128
825 # define MAX_BLOCK_SIZE 64
828 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
829 #ifndef OPENSSL_NO_AES
830 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
831 static int AES_cbc_128_encrypt_loop(void *args)
833 loopargs_t *tempargs = (loopargs_t *)args;
834 unsigned char *buf = tempargs->buf;
836 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
837 AES_cbc_encrypt(buf, buf,
838 (unsigned long)lengths[testnum], &aes_ks1,
843 static int AES_cbc_192_encrypt_loop(void *args)
845 loopargs_t *tempargs = (loopargs_t *)args;
846 unsigned char *buf = tempargs->buf;
848 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
849 AES_cbc_encrypt(buf, buf,
850 (unsigned long)lengths[testnum], &aes_ks2,
855 static int AES_cbc_256_encrypt_loop(void *args)
857 loopargs_t *tempargs = (loopargs_t *)args;
858 unsigned char *buf = tempargs->buf;
860 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
861 AES_cbc_encrypt(buf, buf,
862 (unsigned long)lengths[testnum], &aes_ks3,
867 static int AES_ige_128_encrypt_loop(void *args)
869 loopargs_t *tempargs = (loopargs_t *)args;
870 unsigned char *buf = tempargs->buf;
871 unsigned char *buf2 = tempargs->buf2;
873 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
874 AES_ige_encrypt(buf, buf2,
875 (unsigned long)lengths[testnum], &aes_ks1,
880 static int AES_ige_192_encrypt_loop(void *args)
882 loopargs_t *tempargs = (loopargs_t *)args;
883 unsigned char *buf = tempargs->buf;
884 unsigned char *buf2 = tempargs->buf2;
886 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
887 AES_ige_encrypt(buf, buf2,
888 (unsigned long)lengths[testnum], &aes_ks2,
893 static int AES_ige_256_encrypt_loop(void *args)
895 loopargs_t *tempargs = (loopargs_t *)args;
896 unsigned char *buf = tempargs->buf;
897 unsigned char *buf2 = tempargs->buf2;
899 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
900 AES_ige_encrypt(buf, buf2,
901 (unsigned long)lengths[testnum], &aes_ks3,
906 static int CRYPTO_gcm128_aad_loop(void *args)
908 loopargs_t *tempargs = (loopargs_t *)args;
909 unsigned char *buf = tempargs->buf;
910 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
912 for (count = 0; COND(c[D_GHASH][testnum]); count++)
913 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
919 static int decrypt = 0;
920 static int EVP_Update_loop(void *args)
922 loopargs_t *tempargs = (loopargs_t *)args;
923 unsigned char *buf = tempargs->buf;
924 EVP_CIPHER_CTX *ctx = tempargs->ctx;
928 COND(save_count * 4 * lengths[0] / lengths[testnum]);
930 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
933 COND(save_count * 4 * lengths[0] / lengths[testnum]);
935 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
937 EVP_DecryptFinal_ex(ctx, buf, &outl);
939 EVP_EncryptFinal_ex(ctx, buf, &outl);
943 static const EVP_MD *evp_md = NULL;
944 static int EVP_Digest_loop(void *args)
946 loopargs_t *tempargs = (loopargs_t *)args;
947 unsigned char *buf = tempargs->buf;
948 unsigned char md[EVP_MAX_MD_SIZE];
951 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
952 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
957 #ifndef OPENSSL_NO_RSA
958 static long rsa_c[RSA_NUM][2];
960 static int RSA_sign_loop(void *args)
962 loopargs_t *tempargs = (loopargs_t *)args;
963 unsigned char *buf = tempargs->buf;
964 unsigned char *buf2 = tempargs->buf2;
965 unsigned int *rsa_num = tempargs->siglen;
966 RSA **rsa_key = tempargs->rsa_key;
968 for (count = 0; COND(rsa_c[testnum][0]); count++) {
969 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
971 BIO_printf(bio_err, "RSA sign failure\n");
972 ERR_print_errors(bio_err);
980 static int RSA_verify_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][1]); count++) {
989 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
991 BIO_printf(bio_err, "RSA verify failure\n");
992 ERR_print_errors(bio_err);
1001 #ifndef OPENSSL_NO_DSA
1002 static long dsa_c[DSA_NUM][2];
1003 static int DSA_sign_loop(void *args)
1005 loopargs_t *tempargs = (loopargs_t *)args;
1006 unsigned char *buf = tempargs->buf;
1007 unsigned char *buf2 = tempargs->buf2;
1008 DSA **dsa_key = tempargs->dsa_key;
1009 unsigned int *siglen = tempargs->siglen;
1011 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1012 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1014 BIO_printf(bio_err, "DSA sign failure\n");
1015 ERR_print_errors(bio_err);
1023 static int DSA_verify_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][1]); count++) {
1032 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1034 BIO_printf(bio_err, "DSA verify failure\n");
1035 ERR_print_errors(bio_err);
1044 #ifndef OPENSSL_NO_EC
1045 static long ecdsa_c[EC_NUM][2];
1046 static int ECDSA_sign_loop(void *args)
1048 loopargs_t *tempargs = (loopargs_t *)args;
1049 unsigned char *buf = tempargs->buf;
1050 EC_KEY **ecdsa = tempargs->ecdsa;
1051 unsigned char *ecdsasig = tempargs->buf2;
1052 unsigned int *ecdsasiglen = tempargs->siglen;
1054 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1055 ret = ECDSA_sign(0, buf, 20,
1056 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1058 BIO_printf(bio_err, "ECDSA sign failure\n");
1059 ERR_print_errors(bio_err);
1067 static int ECDSA_verify_loop(void *args)
1069 loopargs_t *tempargs = (loopargs_t *)args;
1070 unsigned char *buf = tempargs->buf;
1071 EC_KEY **ecdsa = tempargs->ecdsa;
1072 unsigned char *ecdsasig = tempargs->buf2;
1073 unsigned int ecdsasiglen = *(tempargs->siglen);
1075 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1076 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1079 BIO_printf(bio_err, "ECDSA verify failure\n");
1080 ERR_print_errors(bio_err);
1089 static void *(*kdf) (const void *in, size_t inlen, void *out,
1092 static int ECDH_compute_key_loop(void *args)
1094 loopargs_t *tempargs = (loopargs_t *)args;
1095 EC_KEY **ecdh_a = tempargs->ecdh_a;
1096 EC_KEY **ecdh_b = tempargs->ecdh_b;
1097 unsigned char *secret_a = tempargs->secret_a;
1099 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1100 ECDH_compute_key(secret_a, outlen,
1101 EC_KEY_get0_public_key(ecdh_b[testnum]),
1102 ecdh_a[testnum], kdf);
1109 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1111 int job_op_count = 0;
1112 int total_op_count = 0;
1113 int num_inprogress = 0;
1116 OSSL_ASYNC_FD job_fd = 0;
1117 size_t num_job_fds = 0;
1121 if (async_jobs == 0) {
1122 return loop_function((void *)loopargs);
1126 for (i = 0; i < async_jobs && !error; i++) {
1127 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1128 &job_op_count, loop_function,
1129 (void *)(loopargs + i), sizeof(loopargs_t))) {
1134 if (job_op_count == -1) {
1137 total_op_count += job_op_count;
1142 BIO_printf(bio_err, "Failure in the job\n");
1143 ERR_print_errors(bio_err);
1149 while (num_inprogress > 0) {
1150 #if defined(OPENSSL_SYS_WINDOWS)
1152 #elif defined(OPENSSL_SYS_UNIX)
1153 int select_result = 0;
1154 OSSL_ASYNC_FD max_fd = 0;
1157 FD_ZERO(&waitfdset);
1159 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1160 if (loopargs[i].inprogress_job == NULL)
1163 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1164 || num_job_fds > 1) {
1165 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1166 ERR_print_errors(bio_err);
1170 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1171 FD_SET(job_fd, &waitfdset);
1172 if (job_fd > max_fd)
1176 if (max_fd >= FD_SETSIZE) {
1178 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1179 "Decrease the value of async_jobs\n",
1180 max_fd, FD_SETSIZE);
1181 ERR_print_errors(bio_err);
1186 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1187 if (select_result == -1 && errno == EINTR)
1190 if (select_result == -1) {
1191 BIO_printf(bio_err, "Failure in the select\n");
1192 ERR_print_errors(bio_err);
1197 if (select_result == 0)
1201 for (i = 0; i < async_jobs; i++) {
1202 if (loopargs[i].inprogress_job == NULL)
1205 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1206 || num_job_fds > 1) {
1207 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1208 ERR_print_errors(bio_err);
1212 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1214 #if defined(OPENSSL_SYS_UNIX)
1215 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1217 #elif defined(OPENSSL_SYS_WINDOWS)
1218 if (num_job_fds == 1 &&
1219 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1223 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1224 &job_op_count, loop_function, (void *)(loopargs + i),
1225 sizeof(loopargs_t))) {
1229 if (job_op_count == -1) {
1232 total_op_count += job_op_count;
1235 loopargs[i].inprogress_job = NULL;
1240 loopargs[i].inprogress_job = NULL;
1241 BIO_printf(bio_err, "Failure in the job\n");
1242 ERR_print_errors(bio_err);
1249 return error ? -1 : total_op_count;
1252 int speed_main(int argc, char **argv)
1254 loopargs_t *loopargs = NULL;
1255 int loopargs_len = 0;
1257 const EVP_CIPHER *evp_cipher = NULL;
1260 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1261 #ifndef OPENSSL_NO_DSA
1262 int dsa_doit[DSA_NUM];
1264 int rsa_doit[RSA_NUM];
1265 int ret = 1, i, k, misalign = 0;
1266 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
1271 /* What follows are the buffers and key material. */
1272 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1275 #ifndef OPENSSL_NO_RC5
1278 #ifndef OPENSSL_NO_RC2
1281 #ifndef OPENSSL_NO_IDEA
1282 IDEA_KEY_SCHEDULE idea_ks;
1284 #ifndef OPENSSL_NO_SEED
1285 SEED_KEY_SCHEDULE seed_ks;
1287 #ifndef OPENSSL_NO_BF
1290 #ifndef OPENSSL_NO_CAST
1293 static const unsigned char key16[16] = {
1294 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1295 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1297 #ifndef OPENSSL_NO_AES
1298 static const unsigned char key24[24] = {
1299 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1300 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1301 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1303 static const unsigned char key32[32] = {
1304 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1305 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1306 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1307 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1310 #ifndef OPENSSL_NO_CAMELLIA
1311 static const unsigned char ckey24[24] = {
1312 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1313 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1314 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1316 static const unsigned char ckey32[32] = {
1317 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1318 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1319 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1320 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1322 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1324 #ifndef OPENSSL_NO_DES
1325 static DES_cblock key = {
1326 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1328 static DES_cblock key2 = {
1329 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1331 static DES_cblock key3 = {
1332 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1335 #ifndef OPENSSL_NO_RSA
1336 static unsigned int rsa_bits[RSA_NUM] = {
1337 512, 1024, 2048, 3072, 4096, 7680, 15360
1339 static unsigned char *rsa_data[RSA_NUM] = {
1340 test512, test1024, test2048, test3072, test4096, test7680, test15360
1342 static int rsa_data_length[RSA_NUM] = {
1343 sizeof(test512), sizeof(test1024),
1344 sizeof(test2048), sizeof(test3072),
1345 sizeof(test4096), sizeof(test7680),
1349 #ifndef OPENSSL_NO_DSA
1350 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1352 #ifndef OPENSSL_NO_EC
1354 * We only test over the following curves as they are representative, To
1355 * add tests over more curves, simply add the curve NID and curve name to
1356 * the following arrays and increase the EC_NUM value accordingly.
1358 static unsigned int test_curves[EC_NUM] = {
1360 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1361 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1363 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1364 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1365 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1370 static const char *test_curves_names[EC_NUM] = {
1372 "secp160r1", "nistp192", "nistp224",
1373 "nistp256", "nistp384", "nistp521",
1375 "nistk163", "nistk233", "nistk283",
1376 "nistk409", "nistk571", "nistb163",
1377 "nistb233", "nistb283", "nistb409",
1382 static int test_curves_bits[EC_NUM] = {
1388 571, 253 /* X25519 */
1391 #ifndef OPENSSL_NO_EC
1392 int ecdsa_doit[EC_NUM];
1393 int secret_size_a, secret_size_b;
1394 int ecdh_checks = 1;
1396 long ecdh_c[EC_NUM][2];
1397 int ecdh_doit[EC_NUM];
1400 memset(results, 0, sizeof(results));
1402 memset(c, 0, sizeof(c));
1403 #ifndef OPENSSL_NO_DES
1404 memset(DES_iv, 0, sizeof(DES_iv));
1406 memset(iv, 0, sizeof(iv));
1408 for (i = 0; i < ALGOR_NUM; i++)
1410 for (i = 0; i < RSA_NUM; i++)
1412 #ifndef OPENSSL_NO_DSA
1413 for (i = 0; i < DSA_NUM; i++)
1416 #ifndef OPENSSL_NO_EC
1417 for (i = 0; i < EC_NUM; i++)
1419 for (i = 0; i < EC_NUM; i++)
1425 prog = opt_init(argc, argv, speed_options);
1426 while ((o = opt_next()) != OPT_EOF) {
1431 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1434 opt_help(speed_options);
1441 evp_cipher = EVP_get_cipherbyname(opt_arg());
1442 if (evp_cipher == NULL)
1443 evp_md = EVP_get_digestbyname(opt_arg());
1444 if (evp_cipher == NULL && evp_md == NULL) {
1446 "%s: %s an unknown cipher or digest\n",
1457 * In a forked execution, an engine might need to be
1458 * initialised by each child process, not by the parent.
1459 * So store the name here and run setup_engine() later on.
1461 engine_id = opt_arg();
1465 multi = atoi(opt_arg());
1469 #ifndef OPENSSL_NO_ASYNC
1470 async_jobs = atoi(opt_arg());
1471 if (!ASYNC_is_capable()) {
1473 "%s: async_jobs specified but async not supported\n",
1480 if (!opt_int(opt_arg(), &misalign))
1482 if (misalign > MISALIGN) {
1484 "%s: Maximum offset is %d\n", prog, MISALIGN);
1496 argc = opt_num_rest();
1499 /* Remaining arguments are algorithms. */
1500 for ( ; *argv; argv++) {
1501 if (found(*argv, doit_choices, &i)) {
1505 #ifndef OPENSSL_NO_DES
1506 if (strcmp(*argv, "des") == 0) {
1507 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1511 if (strcmp(*argv, "sha") == 0) {
1512 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1515 #ifndef OPENSSL_NO_RSA
1517 if (strcmp(*argv, "openssl") == 0) {
1518 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1522 if (strcmp(*argv, "rsa") == 0) {
1523 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1524 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1525 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1526 rsa_doit[R_RSA_15360] = 1;
1529 if (found(*argv, rsa_choices, &i)) {
1534 #ifndef OPENSSL_NO_DSA
1535 if (strcmp(*argv, "dsa") == 0) {
1536 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1537 dsa_doit[R_DSA_2048] = 1;
1540 if (found(*argv, dsa_choices, &i)) {
1545 #ifndef OPENSSL_NO_AES
1546 if (strcmp(*argv, "aes") == 0) {
1547 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1548 doit[D_CBC_256_AES] = 1;
1552 #ifndef OPENSSL_NO_CAMELLIA
1553 if (strcmp(*argv, "camellia") == 0) {
1554 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1555 doit[D_CBC_256_CML] = 1;
1559 #ifndef OPENSSL_NO_EC
1560 if (strcmp(*argv, "ecdsa") == 0) {
1561 for (i = 0; i < EC_NUM; i++)
1565 if (found(*argv, ecdsa_choices, &i)) {
1569 if (strcmp(*argv, "ecdh") == 0) {
1570 for (i = 0; i < EC_NUM; i++)
1574 if (found(*argv, ecdh_choices, &i)) {
1579 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1583 /* Initialize the job pool if async mode is enabled */
1584 if (async_jobs > 0) {
1585 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1586 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1591 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1592 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1593 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1595 for (i = 0; i < loopargs_len; i++) {
1596 if (async_jobs > 0) {
1597 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1598 if (loopargs[i].wait_ctx == NULL) {
1599 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1604 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1605 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1606 /* Align the start of buffers on a 64 byte boundary */
1607 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1608 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1609 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1610 #ifndef OPENSSL_NO_EC
1611 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1612 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1617 if (multi && do_multi(multi))
1621 /* Initialize the engine after the fork */
1622 (void)setup_engine(engine_id, 0);
1624 /* No parameters; turn on everything. */
1625 if ((argc == 0) && !doit[D_EVP]) {
1626 for (i = 0; i < ALGOR_NUM; i++)
1629 for (i = 0; i < RSA_NUM; i++)
1631 #ifndef OPENSSL_NO_DSA
1632 for (i = 0; i < DSA_NUM; i++)
1635 #ifndef OPENSSL_NO_EC
1636 for (i = 0; i < EC_NUM; i++)
1638 for (i = 0; i < EC_NUM; i++)
1642 for (i = 0; i < ALGOR_NUM; i++)
1646 if (usertime == 0 && !mr)
1648 "You have chosen to measure elapsed time "
1649 "instead of user CPU time.\n");
1651 #ifndef OPENSSL_NO_RSA
1652 for (i = 0; i < loopargs_len; i++) {
1653 for (k = 0; k < RSA_NUM; k++) {
1654 const unsigned char *p;
1657 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1658 if (loopargs[i].rsa_key[k] == NULL) {
1659 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1666 #ifndef OPENSSL_NO_DSA
1667 for (i = 0; i < loopargs_len; i++) {
1668 loopargs[i].dsa_key[0] = get_dsa512();
1669 loopargs[i].dsa_key[1] = get_dsa1024();
1670 loopargs[i].dsa_key[2] = get_dsa2048();
1673 #ifndef OPENSSL_NO_DES
1674 DES_set_key_unchecked(&key, &sch);
1675 DES_set_key_unchecked(&key2, &sch2);
1676 DES_set_key_unchecked(&key3, &sch3);
1678 #ifndef OPENSSL_NO_AES
1679 AES_set_encrypt_key(key16, 128, &aes_ks1);
1680 AES_set_encrypt_key(key24, 192, &aes_ks2);
1681 AES_set_encrypt_key(key32, 256, &aes_ks3);
1683 #ifndef OPENSSL_NO_CAMELLIA
1684 Camellia_set_key(key16, 128, &camellia_ks1);
1685 Camellia_set_key(ckey24, 192, &camellia_ks2);
1686 Camellia_set_key(ckey32, 256, &camellia_ks3);
1688 #ifndef OPENSSL_NO_IDEA
1689 idea_set_encrypt_key(key16, &idea_ks);
1691 #ifndef OPENSSL_NO_SEED
1692 SEED_set_key(key16, &seed_ks);
1694 #ifndef OPENSSL_NO_RC4
1695 RC4_set_key(&rc4_ks, 16, key16);
1697 #ifndef OPENSSL_NO_RC2
1698 RC2_set_key(&rc2_ks, 16, key16, 128);
1700 #ifndef OPENSSL_NO_RC5
1701 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1703 #ifndef OPENSSL_NO_BF
1704 BF_set_key(&bf_ks, 16, key16);
1706 #ifndef OPENSSL_NO_CAST
1707 CAST_set_key(&cast_ks, 16, key16);
1709 #ifndef OPENSSL_NO_RSA
1710 memset(rsa_c, 0, sizeof(rsa_c));
1713 # ifndef OPENSSL_NO_DES
1714 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1720 for (it = count; it; it--)
1721 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1722 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1726 c[D_MD2][0] = count / 10;
1727 c[D_MDC2][0] = count / 10;
1728 c[D_MD4][0] = count;
1729 c[D_MD5][0] = count;
1730 c[D_HMAC][0] = count;
1731 c[D_SHA1][0] = count;
1732 c[D_RMD160][0] = count;
1733 c[D_RC4][0] = count * 5;
1734 c[D_CBC_DES][0] = count;
1735 c[D_EDE3_DES][0] = count / 3;
1736 c[D_CBC_IDEA][0] = count;
1737 c[D_CBC_SEED][0] = count;
1738 c[D_CBC_RC2][0] = count;
1739 c[D_CBC_RC5][0] = count;
1740 c[D_CBC_BF][0] = count;
1741 c[D_CBC_CAST][0] = count;
1742 c[D_CBC_128_AES][0] = count;
1743 c[D_CBC_192_AES][0] = count;
1744 c[D_CBC_256_AES][0] = count;
1745 c[D_CBC_128_CML][0] = count;
1746 c[D_CBC_192_CML][0] = count;
1747 c[D_CBC_256_CML][0] = count;
1748 c[D_SHA256][0] = count;
1749 c[D_SHA512][0] = count;
1750 c[D_WHIRLPOOL][0] = count;
1751 c[D_IGE_128_AES][0] = count;
1752 c[D_IGE_192_AES][0] = count;
1753 c[D_IGE_256_AES][0] = count;
1754 c[D_GHASH][0] = count;
1756 for (i = 1; i < SIZE_NUM; i++) {
1759 l0 = (long)lengths[0];
1760 l1 = (long)lengths[i];
1762 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1763 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1764 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1765 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1766 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1767 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1768 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1769 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1770 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1771 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1772 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1774 l0 = (long)lengths[i - 1];
1776 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1777 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1778 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1779 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1780 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1781 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1782 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1783 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1784 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1785 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1786 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1787 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1788 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1789 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1790 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1791 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1792 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1793 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1796 # ifndef OPENSSL_NO_RSA
1797 rsa_c[R_RSA_512][0] = count / 2000;
1798 rsa_c[R_RSA_512][1] = count / 400;
1799 for (i = 1; i < RSA_NUM; i++) {
1800 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1801 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1802 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1805 if (rsa_c[i][0] == 0) {
1813 # ifndef OPENSSL_NO_DSA
1814 dsa_c[R_DSA_512][0] = count / 1000;
1815 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1816 for (i = 1; i < DSA_NUM; i++) {
1817 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1818 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1819 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1822 if (dsa_c[i] == 0) {
1830 # ifndef OPENSSL_NO_EC
1831 ecdsa_c[R_EC_P160][0] = count / 1000;
1832 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1833 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1834 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1835 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1836 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1839 if (ecdsa_c[i] == 0) {
1845 ecdsa_c[R_EC_K163][0] = count / 1000;
1846 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1847 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1848 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1849 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1850 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1853 if (ecdsa_c[i] == 0) {
1859 ecdsa_c[R_EC_B163][0] = count / 1000;
1860 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1861 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1862 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1863 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1864 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1867 if (ecdsa_c[i] == 0) {
1874 ecdh_c[R_EC_P160][0] = count / 1000;
1875 ecdh_c[R_EC_P160][1] = count / 1000;
1876 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1877 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1878 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1879 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1882 if (ecdh_c[i] == 0) {
1888 ecdh_c[R_EC_K163][0] = count / 1000;
1889 ecdh_c[R_EC_K163][1] = count / 1000;
1890 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1891 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1892 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1893 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1896 if (ecdh_c[i] == 0) {
1902 ecdh_c[R_EC_B163][0] = count / 1000;
1903 ecdh_c[R_EC_B163][1] = count / 1000;
1904 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1905 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1906 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1907 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1910 if (ecdh_c[i] == 0) {
1919 /* not worth fixing */
1920 # error "You cannot disable DES on systems without SIGALRM."
1921 # endif /* OPENSSL_NO_DES */
1924 signal(SIGALRM, sig_done);
1926 #endif /* SIGALRM */
1928 #ifndef OPENSSL_NO_MD2
1930 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1931 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1933 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1935 print_result(D_MD2, testnum, count, d);
1939 #ifndef OPENSSL_NO_MDC2
1941 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1942 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1944 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1946 print_result(D_MDC2, testnum, count, d);
1951 #ifndef OPENSSL_NO_MD4
1953 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1954 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1956 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1958 print_result(D_MD4, testnum, count, d);
1963 #ifndef OPENSSL_NO_MD5
1965 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1966 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1968 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1970 print_result(D_MD5, testnum, count, d);
1975 #ifndef OPENSSL_NO_MD5
1977 for (i = 0; i < loopargs_len; i++) {
1978 loopargs[i].hctx = HMAC_CTX_new();
1979 if (loopargs[i].hctx == NULL) {
1980 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1984 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1985 16, EVP_md5(), NULL);
1987 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1988 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1990 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1992 print_result(D_HMAC, testnum, count, d);
1994 for (i = 0; i < loopargs_len; i++) {
1995 HMAC_CTX_free(loopargs[i].hctx);
2000 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2001 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
2003 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2005 print_result(D_SHA1, testnum, count, d);
2008 if (doit[D_SHA256]) {
2009 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2010 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
2012 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2014 print_result(D_SHA256, testnum, count, d);
2017 if (doit[D_SHA512]) {
2018 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2019 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
2021 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2023 print_result(D_SHA512, testnum, count, d);
2027 #ifndef OPENSSL_NO_WHIRLPOOL
2028 if (doit[D_WHIRLPOOL]) {
2029 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2030 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
2032 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2034 print_result(D_WHIRLPOOL, testnum, count, d);
2039 #ifndef OPENSSL_NO_RMD160
2040 if (doit[D_RMD160]) {
2041 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2042 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2044 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2046 print_result(D_RMD160, testnum, count, d);
2050 #ifndef OPENSSL_NO_RC4
2052 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2053 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2055 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2057 print_result(D_RC4, testnum, count, d);
2061 #ifndef OPENSSL_NO_DES
2062 if (doit[D_CBC_DES]) {
2063 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2064 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2066 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2068 print_result(D_CBC_DES, testnum, count, d);
2072 if (doit[D_EDE3_DES]) {
2073 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2074 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2076 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2078 print_result(D_EDE3_DES, testnum, count, d);
2082 #ifndef OPENSSL_NO_AES
2083 if (doit[D_CBC_128_AES]) {
2084 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2085 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2088 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2090 print_result(D_CBC_128_AES, testnum, count, d);
2093 if (doit[D_CBC_192_AES]) {
2094 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2095 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2098 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2100 print_result(D_CBC_192_AES, testnum, count, d);
2103 if (doit[D_CBC_256_AES]) {
2104 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2105 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2108 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2110 print_result(D_CBC_256_AES, testnum, count, d);
2114 if (doit[D_IGE_128_AES]) {
2115 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2116 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2119 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2121 print_result(D_IGE_128_AES, testnum, count, d);
2124 if (doit[D_IGE_192_AES]) {
2125 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2126 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2129 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2131 print_result(D_IGE_192_AES, testnum, count, d);
2134 if (doit[D_IGE_256_AES]) {
2135 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2136 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2139 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2141 print_result(D_IGE_256_AES, testnum, count, d);
2144 if (doit[D_GHASH]) {
2145 for (i = 0; i < loopargs_len; i++) {
2146 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2147 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2150 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2151 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2153 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2155 print_result(D_GHASH, testnum, count, d);
2157 for (i = 0; i < loopargs_len; i++)
2158 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2161 #ifndef OPENSSL_NO_CAMELLIA
2162 if (doit[D_CBC_128_CML]) {
2163 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2164 print_message(names[D_CBC_128_CML], c[D_CBC_128_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_128_CML][testnum]); count++)
2172 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2173 (unsigned long)lengths[testnum], &camellia_ks1,
2174 iv, CAMELLIA_ENCRYPT);
2176 print_result(D_CBC_128_CML, testnum, count, d);
2179 if (doit[D_CBC_192_CML]) {
2180 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2181 print_message(names[D_CBC_192_CML], c[D_CBC_192_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_192_CML][testnum]); count++)
2189 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2190 (unsigned long)lengths[testnum], &camellia_ks2,
2191 iv, CAMELLIA_ENCRYPT);
2193 print_result(D_CBC_192_CML, testnum, count, d);
2196 if (doit[D_CBC_256_CML]) {
2197 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2198 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2200 if (async_jobs > 0) {
2201 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2205 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2206 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2207 (unsigned long)lengths[testnum], &camellia_ks3,
2208 iv, CAMELLIA_ENCRYPT);
2210 print_result(D_CBC_256_CML, testnum, count, d);
2214 #ifndef OPENSSL_NO_IDEA
2215 if (doit[D_CBC_IDEA]) {
2216 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2217 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2218 if (async_jobs > 0) {
2219 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2223 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2224 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2225 (unsigned long)lengths[testnum], &idea_ks,
2228 print_result(D_CBC_IDEA, testnum, count, d);
2232 #ifndef OPENSSL_NO_SEED
2233 if (doit[D_CBC_SEED]) {
2234 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2235 print_message(names[D_CBC_SEED], c[D_CBC_SEED][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_SEED][testnum]); count++)
2242 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2243 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2245 print_result(D_CBC_SEED, testnum, count, d);
2249 #ifndef OPENSSL_NO_RC2
2250 if (doit[D_CBC_RC2]) {
2251 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2252 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2253 if (async_jobs > 0) {
2254 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2258 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2259 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2260 (unsigned long)lengths[testnum], &rc2_ks,
2263 print_result(D_CBC_RC2, testnum, count, d);
2267 #ifndef OPENSSL_NO_RC5
2268 if (doit[D_CBC_RC5]) {
2269 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2270 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2271 if (async_jobs > 0) {
2272 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2276 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2277 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2278 (unsigned long)lengths[testnum], &rc5_ks,
2281 print_result(D_CBC_RC5, testnum, count, d);
2285 #ifndef OPENSSL_NO_BF
2286 if (doit[D_CBC_BF]) {
2287 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2288 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2289 if (async_jobs > 0) {
2290 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2294 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2295 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2296 (unsigned long)lengths[testnum], &bf_ks,
2299 print_result(D_CBC_BF, testnum, count, d);
2303 #ifndef OPENSSL_NO_CAST
2304 if (doit[D_CBC_CAST]) {
2305 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2306 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2307 if (async_jobs > 0) {
2308 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2312 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2313 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2314 (unsigned long)lengths[testnum], &cast_ks,
2317 print_result(D_CBC_CAST, testnum, count, d);
2323 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2324 if (multiblock && evp_cipher) {
2326 (EVP_CIPHER_flags(evp_cipher) &
2327 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2328 BIO_printf(bio_err, "%s is not multi-block capable\n",
2329 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2332 if (async_jobs > 0) {
2333 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2336 multiblock_speed(evp_cipher);
2341 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2344 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2346 * -O3 -fschedule-insns messes up an optimization here!
2347 * names[D_EVP] somehow becomes NULL
2349 print_message(names[D_EVP], save_count, lengths[testnum]);
2351 for (k = 0; k < loopargs_len; k++) {
2352 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2354 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2356 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2357 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2361 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2363 for (k = 0; k < loopargs_len; k++) {
2364 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2368 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2369 print_message(names[D_EVP], save_count, lengths[testnum]);
2371 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2374 print_result(D_EVP, testnum, count, d);
2378 for (i = 0; i < loopargs_len; i++)
2379 RAND_bytes(loopargs[i].buf, 36);
2381 #ifndef OPENSSL_NO_RSA
2382 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2384 if (!rsa_doit[testnum])
2386 for (i = 0; i < loopargs_len; i++) {
2387 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2388 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2394 "RSA sign failure. No RSA sign will be done.\n");
2395 ERR_print_errors(bio_err);
2398 pkey_print_message("private", "rsa",
2399 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2400 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2402 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2405 mr ? "+R1:%ld:%d:%.2f\n"
2406 : "%ld %d bit private RSA's in %.2fs\n",
2407 count, rsa_bits[testnum], d);
2408 rsa_results[testnum][0] = d / (double)count;
2412 for (i = 0; i < loopargs_len; i++) {
2413 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2414 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2420 "RSA verify failure. No RSA verify will be done.\n");
2421 ERR_print_errors(bio_err);
2422 rsa_doit[testnum] = 0;
2424 pkey_print_message("public", "rsa",
2425 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2427 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2430 mr ? "+R2:%ld:%d:%.2f\n"
2431 : "%ld %d bit public RSA's in %.2fs\n",
2432 count, rsa_bits[testnum], d);
2433 rsa_results[testnum][1] = d / (double)count;
2436 if (rsa_count <= 1) {
2437 /* if longer than 10s, don't do any more */
2438 for (testnum++; testnum < RSA_NUM; testnum++)
2439 rsa_doit[testnum] = 0;
2444 for (i = 0; i < loopargs_len; i++)
2445 RAND_bytes(loopargs[i].buf, 36);
2447 #ifndef OPENSSL_NO_DSA
2448 if (RAND_status() != 1) {
2449 RAND_seed(rnd_seed, sizeof rnd_seed);
2451 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2453 if (!dsa_doit[testnum])
2456 /* DSA_generate_key(dsa_key[testnum]); */
2457 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2458 for (i = 0; i < loopargs_len; i++) {
2459 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2460 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2466 "DSA sign failure. No DSA sign will be done.\n");
2467 ERR_print_errors(bio_err);
2470 pkey_print_message("sign", "dsa",
2471 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2473 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2476 mr ? "+R3:%ld:%d:%.2f\n"
2477 : "%ld %d bit DSA signs in %.2fs\n",
2478 count, dsa_bits[testnum], d);
2479 dsa_results[testnum][0] = d / (double)count;
2483 for (i = 0; i < loopargs_len; i++) {
2484 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2485 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2491 "DSA verify failure. No DSA verify will be done.\n");
2492 ERR_print_errors(bio_err);
2493 dsa_doit[testnum] = 0;
2495 pkey_print_message("verify", "dsa",
2496 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2498 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2501 mr ? "+R4:%ld:%d:%.2f\n"
2502 : "%ld %d bit DSA verify in %.2fs\n",
2503 count, dsa_bits[testnum], d);
2504 dsa_results[testnum][1] = d / (double)count;
2507 if (rsa_count <= 1) {
2508 /* if longer than 10s, don't do any more */
2509 for (testnum++; testnum < DSA_NUM; testnum++)
2510 dsa_doit[testnum] = 0;
2515 #ifndef OPENSSL_NO_EC
2516 if (RAND_status() != 1) {
2517 RAND_seed(rnd_seed, sizeof rnd_seed);
2519 for (testnum = 0; testnum < EC_NUM; testnum++) {
2522 if (!ecdsa_doit[testnum])
2523 continue; /* Ignore Curve */
2524 for (i = 0; i < loopargs_len; i++) {
2525 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2526 if (loopargs[i].ecdsa[testnum] == NULL) {
2532 BIO_printf(bio_err, "ECDSA failure.\n");
2533 ERR_print_errors(bio_err);
2536 for (i = 0; i < loopargs_len; i++) {
2537 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2538 /* Perform ECDSA signature test */
2539 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2540 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2541 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2547 "ECDSA sign failure. No ECDSA sign will be done.\n");
2548 ERR_print_errors(bio_err);
2551 pkey_print_message("sign", "ecdsa",
2552 ecdsa_c[testnum][0],
2553 test_curves_bits[testnum], ECDSA_SECONDS);
2555 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2559 mr ? "+R5:%ld:%d:%.2f\n" :
2560 "%ld %d bit ECDSA signs in %.2fs \n",
2561 count, test_curves_bits[testnum], d);
2562 ecdsa_results[testnum][0] = d / (double)count;
2566 /* Perform ECDSA verification test */
2567 for (i = 0; i < loopargs_len; i++) {
2568 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2569 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2575 "ECDSA verify failure. No ECDSA verify will be done.\n");
2576 ERR_print_errors(bio_err);
2577 ecdsa_doit[testnum] = 0;
2579 pkey_print_message("verify", "ecdsa",
2580 ecdsa_c[testnum][1],
2581 test_curves_bits[testnum], ECDSA_SECONDS);
2583 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2586 mr ? "+R6:%ld:%d:%.2f\n"
2587 : "%ld %d bit ECDSA verify in %.2fs\n",
2588 count, test_curves_bits[testnum], d);
2589 ecdsa_results[testnum][1] = d / (double)count;
2592 if (rsa_count <= 1) {
2593 /* if longer than 10s, don't do any more */
2594 for (testnum++; testnum < EC_NUM; testnum++)
2595 ecdsa_doit[testnum] = 0;
2601 #ifndef OPENSSL_NO_EC
2602 if (RAND_status() != 1) {
2603 RAND_seed(rnd_seed, sizeof rnd_seed);
2605 for (testnum = 0; testnum < EC_NUM; testnum++) {
2606 if (!ecdh_doit[testnum])
2608 for (i = 0; i < loopargs_len; i++) {
2609 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2610 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2611 if (loopargs[i].ecdh_a[testnum] == NULL ||
2612 loopargs[i].ecdh_b[testnum] == NULL) {
2617 if (ecdh_checks == 0) {
2618 BIO_printf(bio_err, "ECDH failure.\n");
2619 ERR_print_errors(bio_err);
2622 for (i = 0; i < loopargs_len; i++) {
2623 /* generate two ECDH key pairs */
2624 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2625 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2626 BIO_printf(bio_err, "ECDH key generation failure.\n");
2627 ERR_print_errors(bio_err);
2632 * If field size is not more than 24 octets, then use SHA-1
2633 * hash of result; otherwise, use result (see section 4.8 of
2634 * draft-ietf-tls-ecc-03.txt).
2638 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2639 if (field_size <= 24 * 8) {
2640 outlen = KDF1_SHA1_len;
2643 outlen = (field_size + 7) / 8;
2647 ECDH_compute_key(loopargs[i].secret_a, outlen,
2648 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2649 loopargs[i].ecdh_a[testnum], kdf);
2651 ECDH_compute_key(loopargs[i].secret_b, outlen,
2652 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2653 loopargs[i].ecdh_b[testnum], kdf);
2654 if (secret_size_a != secret_size_b)
2659 for (secret_idx = 0; (secret_idx < secret_size_a)
2660 && (ecdh_checks == 1); secret_idx++) {
2661 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2665 if (ecdh_checks == 0) {
2666 BIO_printf(bio_err, "ECDH computations don't match.\n");
2667 ERR_print_errors(bio_err);
2672 if (ecdh_checks != 0) {
2673 pkey_print_message("", "ecdh",
2675 test_curves_bits[testnum], ECDH_SECONDS);
2677 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2680 mr ? "+R7:%ld:%d:%.2f\n" :
2681 "%ld %d-bit ECDH ops in %.2fs\n", count,
2682 test_curves_bits[testnum], d);
2683 ecdh_results[testnum][0] = d / (double)count;
2689 if (rsa_count <= 1) {
2690 /* if longer than 10s, don't do any more */
2691 for (testnum++; testnum < EC_NUM; testnum++)
2692 ecdh_doit[testnum] = 0;
2700 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2701 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2703 printf("%s ", BN_options());
2704 #ifndef OPENSSL_NO_MD2
2705 printf("%s ", MD2_options());
2707 #ifndef OPENSSL_NO_RC4
2708 printf("%s ", RC4_options());
2710 #ifndef OPENSSL_NO_DES
2711 printf("%s ", DES_options());
2713 #ifndef OPENSSL_NO_AES
2714 printf("%s ", AES_options());
2716 #ifndef OPENSSL_NO_IDEA
2717 printf("%s ", idea_options());
2719 #ifndef OPENSSL_NO_BF
2720 printf("%s ", BF_options());
2722 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2730 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2733 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2734 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2738 for (k = 0; k < ALGOR_NUM; k++) {
2742 printf("+F:%d:%s", k, names[k]);
2744 printf("%-13s", names[k]);
2745 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2746 if (results[k][testnum] > 10000 && !mr)
2747 printf(" %11.2fk", results[k][testnum] / 1e3);
2749 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2753 #ifndef OPENSSL_NO_RSA
2755 for (k = 0; k < RSA_NUM; k++) {
2758 if (testnum && !mr) {
2759 printf("%18ssign verify sign/s verify/s\n", " ");
2763 printf("+F2:%u:%u:%f:%f\n",
2764 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2766 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2767 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2768 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2771 #ifndef OPENSSL_NO_DSA
2773 for (k = 0; k < DSA_NUM; k++) {
2776 if (testnum && !mr) {
2777 printf("%18ssign verify sign/s verify/s\n", " ");
2781 printf("+F3:%u:%u:%f:%f\n",
2782 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2784 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2785 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2786 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2789 #ifndef OPENSSL_NO_EC
2791 for (k = 0; k < EC_NUM; k++) {
2794 if (testnum && !mr) {
2795 printf("%30ssign verify sign/s verify/s\n", " ");
2800 printf("+F4:%u:%u:%f:%f\n",
2801 k, test_curves_bits[k],
2802 ecdsa_results[k][0], ecdsa_results[k][1]);
2804 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2805 test_curves_bits[k],
2806 test_curves_names[k],
2807 ecdsa_results[k][0], ecdsa_results[k][1],
2808 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2812 #ifndef OPENSSL_NO_EC
2814 for (k = 0; k < EC_NUM; k++) {
2817 if (testnum && !mr) {
2818 printf("%30sop op/s\n", " ");
2822 printf("+F5:%u:%u:%f:%f\n",
2823 k, test_curves_bits[k],
2824 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2827 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2828 test_curves_bits[k],
2829 test_curves_names[k],
2830 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2837 ERR_print_errors(bio_err);
2838 for (i = 0; i < loopargs_len; i++) {
2839 OPENSSL_free(loopargs[i].buf_malloc);
2840 OPENSSL_free(loopargs[i].buf2_malloc);
2841 OPENSSL_free(loopargs[i].siglen);
2843 #ifndef OPENSSL_NO_RSA
2844 for (i = 0; i < loopargs_len; i++) {
2845 for (k = 0; k < RSA_NUM; k++)
2846 RSA_free(loopargs[i].rsa_key[k]);
2849 #ifndef OPENSSL_NO_DSA
2850 for (i = 0; i < loopargs_len; i++) {
2851 for (k = 0; k < DSA_NUM; k++)
2852 DSA_free(loopargs[i].dsa_key[k]);
2856 #ifndef OPENSSL_NO_EC
2857 for (i = 0; i < loopargs_len; i++) {
2858 for (k = 0; k < EC_NUM; k++) {
2859 EC_KEY_free(loopargs[i].ecdsa[k]);
2860 EC_KEY_free(loopargs[i].ecdh_a[k]);
2861 EC_KEY_free(loopargs[i].ecdh_b[k]);
2863 OPENSSL_free(loopargs[i].secret_a);
2864 OPENSSL_free(loopargs[i].secret_b);
2867 if (async_jobs > 0) {
2868 for (i = 0; i < loopargs_len; i++)
2869 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2871 ASYNC_cleanup_thread();
2873 OPENSSL_free(loopargs);
2877 static void print_message(const char *s, long num, int length)
2881 mr ? "+DT:%s:%d:%d\n"
2882 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2883 (void)BIO_flush(bio_err);
2887 mr ? "+DN:%s:%ld:%d\n"
2888 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2889 (void)BIO_flush(bio_err);
2893 static void pkey_print_message(const char *str, const char *str2, long num,
2898 mr ? "+DTP:%d:%s:%s:%d\n"
2899 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2900 (void)BIO_flush(bio_err);
2904 mr ? "+DNP:%ld:%d:%s:%s\n"
2905 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2906 (void)BIO_flush(bio_err);
2910 static void print_result(int alg, int run_no, int count, double time_used)
2913 mr ? "+R:%d:%s:%f\n"
2914 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2915 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2919 static char *sstrsep(char **string, const char *delim)
2922 char *token = *string;
2927 memset(isdelim, 0, sizeof isdelim);
2931 isdelim[(unsigned char)(*delim)] = 1;
2935 while (!isdelim[(unsigned char)(**string)]) {
2947 static int do_multi(int multi)
2952 static char sep[] = ":";
2954 fds = malloc(sizeof(*fds) * multi);
2955 for (n = 0; n < multi; ++n) {
2956 if (pipe(fd) == -1) {
2957 BIO_printf(bio_err, "pipe failure\n");
2961 (void)BIO_flush(bio_err);
2968 if (dup(fd[1]) == -1) {
2969 BIO_printf(bio_err, "dup failed\n");
2978 printf("Forked child %d\n", n);
2981 /* for now, assume the pipe is long enough to take all the output */
2982 for (n = 0; n < multi; ++n) {
2987 f = fdopen(fds[n], "r");
2988 while (fgets(buf, sizeof buf, f)) {
2989 p = strchr(buf, '\n');
2992 if (buf[0] != '+') {
2993 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2997 printf("Got: %s from %d\n", buf, n);
2998 if (strncmp(buf, "+F:", 3) == 0) {
3003 alg = atoi(sstrsep(&p, sep));
3005 for (j = 0; j < SIZE_NUM; ++j)
3006 results[alg][j] += atof(sstrsep(&p, sep));
3007 } else if (strncmp(buf, "+F2:", 4) == 0) {
3012 k = atoi(sstrsep(&p, sep));
3015 d = atof(sstrsep(&p, sep));
3017 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
3019 rsa_results[k][0] = d;
3021 d = atof(sstrsep(&p, sep));
3023 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3025 rsa_results[k][1] = d;
3027 # ifndef OPENSSL_NO_DSA
3028 else if (strncmp(buf, "+F3:", 4) == 0) {
3033 k = atoi(sstrsep(&p, sep));
3036 d = atof(sstrsep(&p, sep));
3038 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3040 dsa_results[k][0] = d;
3042 d = atof(sstrsep(&p, sep));
3044 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3046 dsa_results[k][1] = d;
3049 # ifndef OPENSSL_NO_EC
3050 else if (strncmp(buf, "+F4:", 4) == 0) {
3055 k = atoi(sstrsep(&p, sep));
3058 d = atof(sstrsep(&p, sep));
3060 ecdsa_results[k][0] =
3061 1 / (1 / ecdsa_results[k][0] + 1 / d);
3063 ecdsa_results[k][0] = d;
3065 d = atof(sstrsep(&p, sep));
3067 ecdsa_results[k][1] =
3068 1 / (1 / ecdsa_results[k][1] + 1 / d);
3070 ecdsa_results[k][1] = d;
3074 # ifndef OPENSSL_NO_EC
3075 else if (strncmp(buf, "+F5:", 4) == 0) {
3080 k = atoi(sstrsep(&p, sep));
3083 d = atof(sstrsep(&p, sep));
3085 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3087 ecdh_results[k][0] = d;
3092 else if (strncmp(buf, "+H:", 3) == 0) {
3095 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3105 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3107 static int mblengths[] =
3108 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3109 int j, count, num = OSSL_NELEM(mblengths);
3110 const char *alg_name;
3111 unsigned char *inp, *out, no_key[32], no_iv[16];
3112 EVP_CIPHER_CTX *ctx;
3115 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3116 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3117 ctx = EVP_CIPHER_CTX_new();
3118 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3119 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3121 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3123 for (j = 0; j < num; j++) {
3124 print_message(alg_name, 0, mblengths[j]);
3126 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3127 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3128 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3129 size_t len = mblengths[j];
3132 memset(aad, 0, 8); /* avoid uninitialized values */
3133 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3134 aad[9] = 3; /* version */
3136 aad[11] = 0; /* length */
3138 mb_param.out = NULL;
3141 mb_param.interleave = 8;
3143 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3144 sizeof(mb_param), &mb_param);
3150 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3151 sizeof(mb_param), &mb_param);
3155 RAND_bytes(out, 16);
3159 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3160 EVP_AEAD_TLS1_AAD_LEN, aad);
3161 EVP_Cipher(ctx, out, inp, len + pad);
3165 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3166 : "%d %s's in %.2fs\n", count, "evp", d);
3167 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3171 fprintf(stdout, "+H");
3172 for (j = 0; j < num; j++)
3173 fprintf(stdout, ":%d", mblengths[j]);
3174 fprintf(stdout, "\n");
3175 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3176 for (j = 0; j < num; j++)
3177 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3178 fprintf(stdout, "\n");
3181 "The 'numbers' are in 1000s of bytes per second processed.\n");
3182 fprintf(stdout, "type ");
3183 for (j = 0; j < num; j++)
3184 fprintf(stdout, "%7d bytes", mblengths[j]);
3185 fprintf(stdout, "\n");
3186 fprintf(stdout, "%-24s", alg_name);
3188 for (j = 0; j < num; j++) {
3189 if (results[D_EVP][j] > 10000)
3190 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3192 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3194 fprintf(stdout, "\n");
3199 EVP_CIPHER_CTX_free(ctx);