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 #include <openssl/aes.h>
103 #ifndef OPENSSL_NO_CAMELLIA
104 # include <openssl/camellia.h>
106 #ifndef OPENSSL_NO_MD2
107 # include <openssl/md2.h>
109 #ifndef OPENSSL_NO_MDC2
110 # include <openssl/mdc2.h>
112 #ifndef OPENSSL_NO_MD4
113 # include <openssl/md4.h>
115 #ifndef OPENSSL_NO_MD5
116 # include <openssl/md5.h>
118 #include <openssl/hmac.h>
119 #include <openssl/sha.h>
120 #ifndef OPENSSL_NO_RMD160
121 # include <openssl/ripemd.h>
123 #ifndef OPENSSL_NO_WHIRLPOOL
124 # include <openssl/whrlpool.h>
126 #ifndef OPENSSL_NO_RC4
127 # include <openssl/rc4.h>
129 #ifndef OPENSSL_NO_RC5
130 # include <openssl/rc5.h>
132 #ifndef OPENSSL_NO_RC2
133 # include <openssl/rc2.h>
135 #ifndef OPENSSL_NO_IDEA
136 # include <openssl/idea.h>
138 #ifndef OPENSSL_NO_SEED
139 # include <openssl/seed.h>
141 #ifndef OPENSSL_NO_BF
142 # include <openssl/blowfish.h>
144 #ifndef OPENSSL_NO_CAST
145 # include <openssl/cast.h>
147 #ifndef OPENSSL_NO_RSA
148 # include <openssl/rsa.h>
149 # include "./testrsa.h"
151 #include <openssl/x509.h>
152 #ifndef OPENSSL_NO_DSA
153 # include <openssl/dsa.h>
154 # include "./testdsa.h"
156 #ifndef OPENSSL_NO_EC
157 # include <openssl/ec.h>
159 #include <openssl/modes.h>
162 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
176 #define BUFSIZE (1024*16+1)
177 #define MAX_MISALIGNMENT 63
186 #define MAX_ECDH_SIZE 256
189 static volatile int run = 0;
192 static int usertime = 1;
194 typedef struct loopargs_st {
195 ASYNC_JOB *inprogress_job;
196 ASYNC_WAIT_CTX *wait_ctx;
199 unsigned char *buf_malloc;
200 unsigned char *buf2_malloc;
201 unsigned int *siglen;
202 #ifndef OPENSSL_NO_RSA
203 RSA *rsa_key[RSA_NUM];
205 #ifndef OPENSSL_NO_DSA
206 DSA *dsa_key[DSA_NUM];
208 #ifndef OPENSSL_NO_EC
209 EC_KEY *ecdsa[EC_NUM];
210 EC_KEY *ecdh_a[EC_NUM];
211 EC_KEY *ecdh_b[EC_NUM];
212 unsigned char *secret_a;
213 unsigned char *secret_b;
217 GCM128_CONTEXT *gcm_ctx;
220 #ifndef OPENSSL_NO_MD2
221 static int EVP_Digest_MD2_loop(void *args);
224 #ifndef OPENSSL_NO_MDC2
225 static int EVP_Digest_MDC2_loop(void *args);
227 #ifndef OPENSSL_NO_MD4
228 static int EVP_Digest_MD4_loop(void *args);
230 #ifndef OPENSSL_NO_MD5
231 static int MD5_loop(void *args);
232 static int HMAC_loop(void *args);
234 static int SHA1_loop(void *args);
235 static int SHA256_loop(void *args);
236 static int SHA512_loop(void *args);
237 #ifndef OPENSSL_NO_WHIRLPOOL
238 static int WHIRLPOOL_loop(void *args);
240 #ifndef OPENSSL_NO_RMD160
241 static int EVP_Digest_RMD160_loop(void *args);
243 #ifndef OPENSSL_NO_RC4
244 static int RC4_loop(void *args);
246 #ifndef OPENSSL_NO_DES
247 static int DES_ncbc_encrypt_loop(void *args);
248 static int DES_ede3_cbc_encrypt_loop(void *args);
250 static int AES_cbc_128_encrypt_loop(void *args);
251 static int AES_cbc_192_encrypt_loop(void *args);
252 static int AES_ige_128_encrypt_loop(void *args);
253 static int AES_cbc_256_encrypt_loop(void *args);
254 static int AES_ige_192_encrypt_loop(void *args);
255 static int AES_ige_256_encrypt_loop(void *args);
256 static int CRYPTO_gcm128_aad_loop(void *args);
257 static int EVP_Update_loop(void *args);
258 static int EVP_Digest_loop(void *args);
259 #ifndef OPENSSL_NO_RSA
260 static int RSA_sign_loop(void *args);
261 static int RSA_verify_loop(void *args);
263 #ifndef OPENSSL_NO_DSA
264 static int DSA_sign_loop(void *args);
265 static int DSA_verify_loop(void *args);
267 #ifndef OPENSSL_NO_EC
268 static int ECDSA_sign_loop(void *args);
269 static int ECDSA_verify_loop(void *args);
270 static int ECDH_compute_key_loop(void *args);
272 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
274 static double Time_F(int s);
275 static void print_message(const char *s, long num, int length);
276 static void pkey_print_message(const char *str, const char *str2,
277 long num, int bits, int sec);
278 static void print_result(int alg, int run_no, int count, double time_used);
280 static int do_multi(int multi);
283 static const char *names[ALGOR_NUM] = {
284 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
285 "des cbc", "des ede3", "idea cbc", "seed cbc",
286 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
287 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
288 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
289 "evp", "sha256", "sha512", "whirlpool",
290 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
293 static double results[ALGOR_NUM][SIZE_NUM];
294 static int lengths[SIZE_NUM] = {
295 16, 64, 256, 1024, 8 * 1024, 16 * 1024
298 #ifndef OPENSSL_NO_RSA
299 static double rsa_results[RSA_NUM][2];
301 #ifndef OPENSSL_NO_DSA
302 static double dsa_results[DSA_NUM][2];
304 #ifndef OPENSSL_NO_EC
305 static double ecdsa_results[EC_NUM][2];
306 static double ecdh_results[EC_NUM][1];
309 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
310 static const char rnd_seed[] =
311 "string to make the random number generator think it has entropy";
315 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
316 # define SIGRETTYPE void
318 # define SIGRETTYPE int
321 static SIGRETTYPE sig_done(int sig);
322 static SIGRETTYPE sig_done(int sig)
324 signal(SIGALRM, sig_done);
334 # if !defined(SIGALRM)
337 static unsigned int lapse, schlock;
338 static void alarm_win32(unsigned int secs)
343 # define alarm alarm_win32
345 static DWORD WINAPI sleepy(VOID * arg)
353 static double Time_F(int s)
360 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
362 DWORD err = GetLastError();
363 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
367 Sleep(0); /* scheduler spinlock */
368 ret = app_tminterval(s, usertime);
370 ret = app_tminterval(s, usertime);
372 TerminateThread(thr, 0);
380 static double Time_F(int s)
382 double ret = app_tminterval(s, usertime);
389 #ifndef OPENSSL_NO_EC
390 static const int KDF1_SHA1_len = 20;
391 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
394 if (*outlen < SHA_DIGEST_LENGTH)
396 *outlen = SHA_DIGEST_LENGTH;
397 return SHA1(in, inlen, out);
399 #endif /* OPENSSL_NO_EC */
401 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
403 static int found(const char *name, const OPT_PAIR * pairs, int *result)
405 for (; pairs->name; pairs++)
406 if (strcmp(name, pairs->name) == 0) {
407 *result = pairs->retval;
413 typedef enum OPTION_choice {
414 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
415 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
416 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
419 OPTIONS speed_options[] = {
420 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
421 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
422 {"help", OPT_HELP, '-', "Display this summary"},
423 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
424 {"decrypt", OPT_DECRYPT, '-',
425 "Time decryption instead of encryption (only EVP)"},
426 {"mr", OPT_MR, '-', "Produce machine readable output"},
428 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
429 {"elapsed", OPT_ELAPSED, '-',
430 "Measure time in real time instead of CPU user time"},
432 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
434 #ifndef OPENSSL_NO_ASYNC
435 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
437 #ifndef OPENSSL_NO_ENGINE
438 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
453 #define D_CBC_IDEA 10
454 #define D_CBC_SEED 11
458 #define D_CBC_CAST 15
459 #define D_CBC_128_AES 16
460 #define D_CBC_192_AES 17
461 #define D_CBC_256_AES 18
462 #define D_CBC_128_CML 19
463 #define D_CBC_192_CML 20
464 #define D_CBC_256_CML 21
468 #define D_WHIRLPOOL 25
469 #define D_IGE_128_AES 26
470 #define D_IGE_192_AES 27
471 #define D_IGE_256_AES 28
473 static OPT_PAIR doit_choices[] = {
474 #ifndef OPENSSL_NO_MD2
477 #ifndef OPENSSL_NO_MDC2
480 #ifndef OPENSSL_NO_MD4
483 #ifndef OPENSSL_NO_MD5
486 #ifndef OPENSSL_NO_MD5
490 {"sha256", D_SHA256},
491 {"sha512", D_SHA512},
492 #ifndef OPENSSL_NO_WHIRLPOOL
493 {"whirlpool", D_WHIRLPOOL},
495 #ifndef OPENSSL_NO_RMD160
496 {"ripemd", D_RMD160},
497 {"rmd160", D_RMD160},
498 {"ripemd160", D_RMD160},
500 #ifndef OPENSSL_NO_RC4
503 #ifndef OPENSSL_NO_DES
504 {"des-cbc", D_CBC_DES},
505 {"des-ede3", D_EDE3_DES},
507 {"aes-128-cbc", D_CBC_128_AES},
508 {"aes-192-cbc", D_CBC_192_AES},
509 {"aes-256-cbc", D_CBC_256_AES},
510 {"aes-128-ige", D_IGE_128_AES},
511 {"aes-192-ige", D_IGE_192_AES},
512 {"aes-256-ige", D_IGE_256_AES},
513 #ifndef OPENSSL_NO_RC2
514 {"rc2-cbc", D_CBC_RC2},
517 #ifndef OPENSSL_NO_RC5
518 {"rc5-cbc", D_CBC_RC5},
521 #ifndef OPENSSL_NO_IDEA
522 {"idea-cbc", D_CBC_IDEA},
523 {"idea", D_CBC_IDEA},
525 #ifndef OPENSSL_NO_SEED
526 {"seed-cbc", D_CBC_SEED},
527 {"seed", D_CBC_SEED},
529 #ifndef OPENSSL_NO_BF
530 {"bf-cbc", D_CBC_BF},
531 {"blowfish", D_CBC_BF},
534 #ifndef OPENSSL_NO_CAST
535 {"cast-cbc", D_CBC_CAST},
536 {"cast", D_CBC_CAST},
537 {"cast5", D_CBC_CAST},
543 #ifndef OPENSSL_NO_DSA
545 # define R_DSA_1024 1
546 # define R_DSA_2048 2
547 static OPT_PAIR dsa_choices[] = {
548 {"dsa512", R_DSA_512},
549 {"dsa1024", R_DSA_1024},
550 {"dsa2048", R_DSA_2048},
561 #define R_RSA_15360 6
562 static OPT_PAIR rsa_choices[] = {
563 {"rsa512", R_RSA_512},
564 {"rsa1024", R_RSA_1024},
565 {"rsa2048", R_RSA_2048},
566 {"rsa3072", R_RSA_3072},
567 {"rsa4096", R_RSA_4096},
568 {"rsa7680", R_RSA_7680},
569 {"rsa15360", R_RSA_15360},
589 #define R_EC_X25519 16
590 #ifndef OPENSSL_NO_EC
591 static OPT_PAIR ecdsa_choices[] = {
592 {"ecdsap160", R_EC_P160},
593 {"ecdsap192", R_EC_P192},
594 {"ecdsap224", R_EC_P224},
595 {"ecdsap256", R_EC_P256},
596 {"ecdsap384", R_EC_P384},
597 {"ecdsap521", R_EC_P521},
598 {"ecdsak163", R_EC_K163},
599 {"ecdsak233", R_EC_K233},
600 {"ecdsak283", R_EC_K283},
601 {"ecdsak409", R_EC_K409},
602 {"ecdsak571", R_EC_K571},
603 {"ecdsab163", R_EC_B163},
604 {"ecdsab233", R_EC_B233},
605 {"ecdsab283", R_EC_B283},
606 {"ecdsab409", R_EC_B409},
607 {"ecdsab571", R_EC_B571},
610 static OPT_PAIR ecdh_choices[] = {
611 {"ecdhp160", R_EC_P160},
612 {"ecdhp192", R_EC_P192},
613 {"ecdhp224", R_EC_P224},
614 {"ecdhp256", R_EC_P256},
615 {"ecdhp384", R_EC_P384},
616 {"ecdhp521", R_EC_P521},
617 {"ecdhk163", R_EC_K163},
618 {"ecdhk233", R_EC_K233},
619 {"ecdhk283", R_EC_K283},
620 {"ecdhk409", R_EC_K409},
621 {"ecdhk571", R_EC_K571},
622 {"ecdhb163", R_EC_B163},
623 {"ecdhb233", R_EC_B233},
624 {"ecdhb283", R_EC_B283},
625 {"ecdhb409", R_EC_B409},
626 {"ecdhb571", R_EC_B571},
627 {"ecdhx25519", R_EC_X25519},
633 # define COND(d) (count < (d))
634 # define COUNT(d) (d)
636 # define COND(c) (run && count<0x7fffffff)
637 # define COUNT(d) (count)
641 static char *engine_id = NULL;
644 #ifndef OPENSSL_NO_MD2
645 static int EVP_Digest_MD2_loop(void *args)
647 loopargs_t *tempargs = (loopargs_t *)args;
648 unsigned char *buf = tempargs->buf;
649 unsigned char md2[MD2_DIGEST_LENGTH];
651 for (count = 0; COND(c[D_MD2][testnum]); count++)
652 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
658 #ifndef OPENSSL_NO_MDC2
659 static int EVP_Digest_MDC2_loop(void *args)
661 loopargs_t *tempargs = (loopargs_t *)args;
662 unsigned char *buf = tempargs->buf;
663 unsigned char mdc2[MDC2_DIGEST_LENGTH];
665 for (count = 0; COND(c[D_MDC2][testnum]); count++)
666 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
672 #ifndef OPENSSL_NO_MD4
673 static int EVP_Digest_MD4_loop(void *args)
675 loopargs_t *tempargs = (loopargs_t *)args;
676 unsigned char *buf = tempargs->buf;
677 unsigned char md4[MD4_DIGEST_LENGTH];
679 for (count = 0; COND(c[D_MD4][testnum]); count++)
680 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
681 NULL, EVP_md4(), NULL);
686 #ifndef OPENSSL_NO_MD5
687 static int MD5_loop(void *args)
689 loopargs_t *tempargs = (loopargs_t *)args;
690 unsigned char *buf = tempargs->buf;
691 unsigned char md5[MD5_DIGEST_LENGTH];
693 for (count = 0; COND(c[D_MD5][testnum]); count++)
694 MD5(buf, lengths[testnum], md5);
698 static int HMAC_loop(void *args)
700 loopargs_t *tempargs = (loopargs_t *)args;
701 unsigned char *buf = tempargs->buf;
702 HMAC_CTX *hctx = tempargs->hctx;
703 unsigned char hmac[MD5_DIGEST_LENGTH];
705 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
706 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
707 HMAC_Update(hctx, buf, lengths[testnum]);
708 HMAC_Final(hctx, &(hmac[0]), NULL);
714 static int SHA1_loop(void *args)
716 loopargs_t *tempargs = (loopargs_t *)args;
717 unsigned char *buf = tempargs->buf;
718 unsigned char sha[SHA_DIGEST_LENGTH];
720 for (count = 0; COND(c[D_SHA1][testnum]); count++)
721 SHA1(buf, lengths[testnum], sha);
725 static int SHA256_loop(void *args)
727 loopargs_t *tempargs = (loopargs_t *)args;
728 unsigned char *buf = tempargs->buf;
729 unsigned char sha256[SHA256_DIGEST_LENGTH];
731 for (count = 0; COND(c[D_SHA256][testnum]); count++)
732 SHA256(buf, lengths[testnum], sha256);
736 static int SHA512_loop(void *args)
738 loopargs_t *tempargs = (loopargs_t *)args;
739 unsigned char *buf = tempargs->buf;
740 unsigned char sha512[SHA512_DIGEST_LENGTH];
742 for (count = 0; COND(c[D_SHA512][testnum]); count++)
743 SHA512(buf, lengths[testnum], sha512);
747 #ifndef OPENSSL_NO_WHIRLPOOL
748 static int WHIRLPOOL_loop(void *args)
750 loopargs_t *tempargs = (loopargs_t *)args;
751 unsigned char *buf = tempargs->buf;
752 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
754 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
755 WHIRLPOOL(buf, lengths[testnum], whirlpool);
760 #ifndef OPENSSL_NO_RMD160
761 static int EVP_Digest_RMD160_loop(void *args)
763 loopargs_t *tempargs = (loopargs_t *)args;
764 unsigned char *buf = tempargs->buf;
765 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
767 for (count = 0; COND(c[D_RMD160][testnum]); count++)
768 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
769 EVP_ripemd160(), NULL);
774 #ifndef OPENSSL_NO_RC4
775 static RC4_KEY rc4_ks;
776 static int RC4_loop(void *args)
778 loopargs_t *tempargs = (loopargs_t *)args;
779 unsigned char *buf = tempargs->buf;
781 for (count = 0; COND(c[D_RC4][testnum]); count++)
782 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
787 #ifndef OPENSSL_NO_DES
788 static unsigned char DES_iv[8];
789 static DES_key_schedule sch;
790 static DES_key_schedule sch2;
791 static DES_key_schedule sch3;
792 static int DES_ncbc_encrypt_loop(void *args)
794 loopargs_t *tempargs = (loopargs_t *)args;
795 unsigned char *buf = tempargs->buf;
797 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
798 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
799 &DES_iv, DES_ENCRYPT);
803 static int DES_ede3_cbc_encrypt_loop(void *args)
805 loopargs_t *tempargs = (loopargs_t *)args;
806 unsigned char *buf = tempargs->buf;
808 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
809 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
811 &DES_iv, DES_ENCRYPT);
816 #define MAX_BLOCK_SIZE 128
818 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
819 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
820 static int AES_cbc_128_encrypt_loop(void *args)
822 loopargs_t *tempargs = (loopargs_t *)args;
823 unsigned char *buf = tempargs->buf;
825 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
826 AES_cbc_encrypt(buf, buf,
827 (unsigned long)lengths[testnum], &aes_ks1,
832 static int AES_cbc_192_encrypt_loop(void *args)
834 loopargs_t *tempargs = (loopargs_t *)args;
835 unsigned char *buf = tempargs->buf;
837 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
838 AES_cbc_encrypt(buf, buf,
839 (unsigned long)lengths[testnum], &aes_ks2,
844 static int AES_cbc_256_encrypt_loop(void *args)
846 loopargs_t *tempargs = (loopargs_t *)args;
847 unsigned char *buf = tempargs->buf;
849 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
850 AES_cbc_encrypt(buf, buf,
851 (unsigned long)lengths[testnum], &aes_ks3,
856 static int AES_ige_128_encrypt_loop(void *args)
858 loopargs_t *tempargs = (loopargs_t *)args;
859 unsigned char *buf = tempargs->buf;
860 unsigned char *buf2 = tempargs->buf2;
862 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
863 AES_ige_encrypt(buf, buf2,
864 (unsigned long)lengths[testnum], &aes_ks1,
869 static int AES_ige_192_encrypt_loop(void *args)
871 loopargs_t *tempargs = (loopargs_t *)args;
872 unsigned char *buf = tempargs->buf;
873 unsigned char *buf2 = tempargs->buf2;
875 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
876 AES_ige_encrypt(buf, buf2,
877 (unsigned long)lengths[testnum], &aes_ks2,
882 static int AES_ige_256_encrypt_loop(void *args)
884 loopargs_t *tempargs = (loopargs_t *)args;
885 unsigned char *buf = tempargs->buf;
886 unsigned char *buf2 = tempargs->buf2;
888 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
889 AES_ige_encrypt(buf, buf2,
890 (unsigned long)lengths[testnum], &aes_ks3,
895 static int CRYPTO_gcm128_aad_loop(void *args)
897 loopargs_t *tempargs = (loopargs_t *)args;
898 unsigned char *buf = tempargs->buf;
899 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
901 for (count = 0; COND(c[D_GHASH][testnum]); count++)
902 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
906 static int decrypt = 0;
907 static int EVP_Update_loop(void *args)
909 loopargs_t *tempargs = (loopargs_t *)args;
910 unsigned char *buf = tempargs->buf;
911 EVP_CIPHER_CTX *ctx = tempargs->ctx;
915 COND(save_count * 4 * lengths[0] / lengths[testnum]);
917 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
920 COND(save_count * 4 * lengths[0] / lengths[testnum]);
922 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
924 EVP_DecryptFinal_ex(ctx, buf, &outl);
926 EVP_EncryptFinal_ex(ctx, buf, &outl);
930 static const EVP_MD *evp_md = NULL;
931 static int EVP_Digest_loop(void *args)
933 loopargs_t *tempargs = (loopargs_t *)args;
934 unsigned char *buf = tempargs->buf;
935 unsigned char md[EVP_MAX_MD_SIZE];
938 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
939 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
944 #ifndef OPENSSL_NO_RSA
945 static long rsa_c[RSA_NUM][2];
947 static int RSA_sign_loop(void *args)
949 loopargs_t *tempargs = (loopargs_t *)args;
950 unsigned char *buf = tempargs->buf;
951 unsigned char *buf2 = tempargs->buf2;
952 unsigned int *rsa_num = tempargs->siglen;
953 RSA **rsa_key = tempargs->rsa_key;
955 for (count = 0; COND(rsa_c[testnum][0]); count++) {
956 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
958 BIO_printf(bio_err, "RSA sign failure\n");
959 ERR_print_errors(bio_err);
967 static int RSA_verify_loop(void *args)
969 loopargs_t *tempargs = (loopargs_t *)args;
970 unsigned char *buf = tempargs->buf;
971 unsigned char *buf2 = tempargs->buf2;
972 unsigned int rsa_num = *(tempargs->siglen);
973 RSA **rsa_key = tempargs->rsa_key;
975 for (count = 0; COND(rsa_c[testnum][1]); count++) {
976 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
978 BIO_printf(bio_err, "RSA verify failure\n");
979 ERR_print_errors(bio_err);
988 #ifndef OPENSSL_NO_DSA
989 static long dsa_c[DSA_NUM][2];
990 static int DSA_sign_loop(void *args)
992 loopargs_t *tempargs = (loopargs_t *)args;
993 unsigned char *buf = tempargs->buf;
994 unsigned char *buf2 = tempargs->buf2;
995 DSA **dsa_key = tempargs->dsa_key;
996 unsigned int *siglen = tempargs->siglen;
998 for (count = 0; COND(dsa_c[testnum][0]); count++) {
999 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1001 BIO_printf(bio_err, "DSA sign failure\n");
1002 ERR_print_errors(bio_err);
1010 static int DSA_verify_loop(void *args)
1012 loopargs_t *tempargs = (loopargs_t *)args;
1013 unsigned char *buf = tempargs->buf;
1014 unsigned char *buf2 = tempargs->buf2;
1015 DSA **dsa_key = tempargs->dsa_key;
1016 unsigned int siglen = *(tempargs->siglen);
1018 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1019 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1021 BIO_printf(bio_err, "DSA verify failure\n");
1022 ERR_print_errors(bio_err);
1031 #ifndef OPENSSL_NO_EC
1032 static long ecdsa_c[EC_NUM][2];
1033 static int ECDSA_sign_loop(void *args)
1035 loopargs_t *tempargs = (loopargs_t *)args;
1036 unsigned char *buf = tempargs->buf;
1037 EC_KEY **ecdsa = tempargs->ecdsa;
1038 unsigned char *ecdsasig = tempargs->buf2;
1039 unsigned int *ecdsasiglen = tempargs->siglen;
1041 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1042 ret = ECDSA_sign(0, buf, 20,
1043 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1045 BIO_printf(bio_err, "ECDSA sign failure\n");
1046 ERR_print_errors(bio_err);
1054 static int ECDSA_verify_loop(void *args)
1056 loopargs_t *tempargs = (loopargs_t *)args;
1057 unsigned char *buf = tempargs->buf;
1058 EC_KEY **ecdsa = tempargs->ecdsa;
1059 unsigned char *ecdsasig = tempargs->buf2;
1060 unsigned int ecdsasiglen = *(tempargs->siglen);
1062 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1063 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1066 BIO_printf(bio_err, "ECDSA verify failure\n");
1067 ERR_print_errors(bio_err);
1076 static void *(*kdf) (const void *in, size_t inlen, void *out,
1079 static int ECDH_compute_key_loop(void *args)
1081 loopargs_t *tempargs = (loopargs_t *)args;
1082 EC_KEY **ecdh_a = tempargs->ecdh_a;
1083 EC_KEY **ecdh_b = tempargs->ecdh_b;
1084 unsigned char *secret_a = tempargs->secret_a;
1086 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1087 ECDH_compute_key(secret_a, outlen,
1088 EC_KEY_get0_public_key(ecdh_b[testnum]),
1089 ecdh_a[testnum], kdf);
1096 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1098 int job_op_count = 0;
1099 int total_op_count = 0;
1100 int num_inprogress = 0;
1103 OSSL_ASYNC_FD job_fd = 0;
1104 size_t num_job_fds = 0;
1108 if (async_jobs == 0) {
1109 return loop_function((void *)loopargs);
1113 for (i = 0; i < async_jobs && !error; i++) {
1114 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1115 &job_op_count, loop_function,
1116 (void *)(loopargs + i), sizeof(loopargs_t))) {
1121 if (job_op_count == -1) {
1124 total_op_count += job_op_count;
1129 BIO_printf(bio_err, "Failure in the job\n");
1130 ERR_print_errors(bio_err);
1136 while (num_inprogress > 0) {
1137 #if defined(OPENSSL_SYS_WINDOWS)
1139 #elif defined(OPENSSL_SYS_UNIX)
1140 int select_result = 0;
1141 OSSL_ASYNC_FD max_fd = 0;
1144 FD_ZERO(&waitfdset);
1146 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1147 if (loopargs[i].inprogress_job == NULL)
1150 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1151 || num_job_fds > 1) {
1152 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1153 ERR_print_errors(bio_err);
1157 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1158 FD_SET(job_fd, &waitfdset);
1159 if (job_fd > max_fd)
1163 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1165 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1166 "Decrease the value of async_jobs\n",
1167 max_fd, FD_SETSIZE);
1168 ERR_print_errors(bio_err);
1173 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1174 if (select_result == -1 && errno == EINTR)
1177 if (select_result == -1) {
1178 BIO_printf(bio_err, "Failure in the select\n");
1179 ERR_print_errors(bio_err);
1184 if (select_result == 0)
1188 for (i = 0; i < async_jobs; i++) {
1189 if (loopargs[i].inprogress_job == NULL)
1192 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1193 || num_job_fds > 1) {
1194 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1195 ERR_print_errors(bio_err);
1199 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1201 #if defined(OPENSSL_SYS_UNIX)
1202 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1204 #elif defined(OPENSSL_SYS_WINDOWS)
1205 if (num_job_fds == 1 &&
1206 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1210 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1211 &job_op_count, loop_function, (void *)(loopargs + i),
1212 sizeof(loopargs_t))) {
1216 if (job_op_count == -1) {
1219 total_op_count += job_op_count;
1222 loopargs[i].inprogress_job = NULL;
1227 loopargs[i].inprogress_job = NULL;
1228 BIO_printf(bio_err, "Failure in the job\n");
1229 ERR_print_errors(bio_err);
1236 return error ? -1 : total_op_count;
1239 int speed_main(int argc, char **argv)
1241 loopargs_t *loopargs = NULL;
1242 int loopargs_len = 0;
1244 const EVP_CIPHER *evp_cipher = NULL;
1247 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1248 #ifndef OPENSSL_NO_DSA
1249 int dsa_doit[DSA_NUM];
1251 int rsa_doit[RSA_NUM];
1252 int ret = 1, i, k, misalign = 0;
1253 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
1258 /* What follows are the buffers and key material. */
1259 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1262 #ifndef OPENSSL_NO_RC5
1265 #ifndef OPENSSL_NO_RC2
1268 #ifndef OPENSSL_NO_IDEA
1269 IDEA_KEY_SCHEDULE idea_ks;
1271 #ifndef OPENSSL_NO_SEED
1272 SEED_KEY_SCHEDULE seed_ks;
1274 #ifndef OPENSSL_NO_BF
1277 #ifndef OPENSSL_NO_CAST
1280 static const unsigned char key16[16] = {
1281 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1282 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1284 static const unsigned char key24[24] = {
1285 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1286 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1287 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1289 static const unsigned char key32[32] = {
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,
1293 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1295 #ifndef OPENSSL_NO_CAMELLIA
1296 static const unsigned char ckey24[24] = {
1297 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1298 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1299 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1301 static const unsigned char ckey32[32] = {
1302 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1303 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1304 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1305 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1307 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1309 #ifndef OPENSSL_NO_DES
1310 static DES_cblock key = {
1311 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1313 static DES_cblock key2 = {
1314 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1316 static DES_cblock key3 = {
1317 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1320 #ifndef OPENSSL_NO_RSA
1321 static unsigned int rsa_bits[RSA_NUM] = {
1322 512, 1024, 2048, 3072, 4096, 7680, 15360
1324 static unsigned char *rsa_data[RSA_NUM] = {
1325 test512, test1024, test2048, test3072, test4096, test7680, test15360
1327 static int rsa_data_length[RSA_NUM] = {
1328 sizeof(test512), sizeof(test1024),
1329 sizeof(test2048), sizeof(test3072),
1330 sizeof(test4096), sizeof(test7680),
1334 #ifndef OPENSSL_NO_DSA
1335 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1337 #ifndef OPENSSL_NO_EC
1339 * We only test over the following curves as they are representative, To
1340 * add tests over more curves, simply add the curve NID and curve name to
1341 * the following arrays and increase the EC_NUM value accordingly.
1343 static unsigned int test_curves[EC_NUM] = {
1345 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1346 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1348 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1349 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1350 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1355 static const char *test_curves_names[EC_NUM] = {
1357 "secp160r1", "nistp192", "nistp224",
1358 "nistp256", "nistp384", "nistp521",
1360 "nistk163", "nistk233", "nistk283",
1361 "nistk409", "nistk571", "nistb163",
1362 "nistb233", "nistb283", "nistb409",
1367 static int test_curves_bits[EC_NUM] = {
1373 571, 253 /* X25519 */
1376 #ifndef OPENSSL_NO_EC
1377 int ecdsa_doit[EC_NUM];
1378 int secret_size_a, secret_size_b;
1379 int ecdh_checks = 1;
1381 long ecdh_c[EC_NUM][2];
1382 int ecdh_doit[EC_NUM];
1385 memset(results, 0, sizeof(results));
1387 memset(c, 0, sizeof(c));
1388 #ifndef OPENSSL_NO_DES
1389 memset(DES_iv, 0, sizeof(DES_iv));
1391 memset(iv, 0, sizeof(iv));
1393 for (i = 0; i < ALGOR_NUM; i++)
1395 for (i = 0; i < RSA_NUM; i++)
1397 #ifndef OPENSSL_NO_DSA
1398 for (i = 0; i < DSA_NUM; i++)
1401 #ifndef OPENSSL_NO_EC
1402 for (i = 0; i < EC_NUM; i++)
1404 for (i = 0; i < EC_NUM; i++)
1410 prog = opt_init(argc, argv, speed_options);
1411 while ((o = opt_next()) != OPT_EOF) {
1416 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1419 opt_help(speed_options);
1426 evp_cipher = EVP_get_cipherbyname(opt_arg());
1427 if (evp_cipher == NULL)
1428 evp_md = EVP_get_digestbyname(opt_arg());
1429 if (evp_cipher == NULL && evp_md == NULL) {
1431 "%s: %s an unknown cipher or digest\n",
1442 * In a forked execution, an engine might need to be
1443 * initialised by each child process, not by the parent.
1444 * So store the name here and run setup_engine() later on.
1446 engine_id = opt_arg();
1450 multi = atoi(opt_arg());
1454 #ifndef OPENSSL_NO_ASYNC
1455 async_jobs = atoi(opt_arg());
1456 if (!ASYNC_is_capable()) {
1458 "%s: async_jobs specified but async not supported\n",
1465 if (!opt_int(opt_arg(), &misalign))
1467 if (misalign > MISALIGN) {
1469 "%s: Maximum offset is %d\n", prog, MISALIGN);
1481 argc = opt_num_rest();
1484 /* Remaining arguments are algorithms. */
1485 for ( ; *argv; argv++) {
1486 if (found(*argv, doit_choices, &i)) {
1490 #ifndef OPENSSL_NO_DES
1491 if (strcmp(*argv, "des") == 0) {
1492 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1496 if (strcmp(*argv, "sha") == 0) {
1497 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1500 #ifndef OPENSSL_NO_RSA
1502 if (strcmp(*argv, "openssl") == 0) {
1503 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1507 if (strcmp(*argv, "rsa") == 0) {
1508 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1509 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1510 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1511 rsa_doit[R_RSA_15360] = 1;
1514 if (found(*argv, rsa_choices, &i)) {
1519 #ifndef OPENSSL_NO_DSA
1520 if (strcmp(*argv, "dsa") == 0) {
1521 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1522 dsa_doit[R_DSA_2048] = 1;
1525 if (found(*argv, dsa_choices, &i)) {
1530 if (strcmp(*argv, "aes") == 0) {
1531 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1532 doit[D_CBC_256_AES] = 1;
1535 #ifndef OPENSSL_NO_CAMELLIA
1536 if (strcmp(*argv, "camellia") == 0) {
1537 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1538 doit[D_CBC_256_CML] = 1;
1542 #ifndef OPENSSL_NO_EC
1543 if (strcmp(*argv, "ecdsa") == 0) {
1544 for (i = 0; i < EC_NUM; i++)
1548 if (found(*argv, ecdsa_choices, &i)) {
1552 if (strcmp(*argv, "ecdh") == 0) {
1553 for (i = 0; i < EC_NUM; i++)
1557 if (found(*argv, ecdh_choices, &i)) {
1562 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1566 /* Initialize the job pool if async mode is enabled */
1567 if (async_jobs > 0) {
1568 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1569 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1574 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1575 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1576 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1578 for (i = 0; i < loopargs_len; i++) {
1579 if (async_jobs > 0) {
1580 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1581 if (loopargs[i].wait_ctx == NULL) {
1582 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1587 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1588 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1589 /* Align the start of buffers on a 64 byte boundary */
1590 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1591 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1592 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1593 #ifndef OPENSSL_NO_EC
1594 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1595 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1600 if (multi && do_multi(multi))
1604 /* Initialize the engine after the fork */
1605 (void)setup_engine(engine_id, 0);
1607 /* No parameters; turn on everything. */
1608 if ((argc == 0) && !doit[D_EVP]) {
1609 for (i = 0; i < ALGOR_NUM; i++)
1612 for (i = 0; i < RSA_NUM; i++)
1614 #ifndef OPENSSL_NO_DSA
1615 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 AES_set_encrypt_key(key16, 128, &aes_ks1);
1662 AES_set_encrypt_key(key24, 192, &aes_ks2);
1663 AES_set_encrypt_key(key32, 256, &aes_ks3);
1664 #ifndef OPENSSL_NO_CAMELLIA
1665 Camellia_set_key(key16, 128, &camellia_ks1);
1666 Camellia_set_key(ckey24, 192, &camellia_ks2);
1667 Camellia_set_key(ckey32, 256, &camellia_ks3);
1669 #ifndef OPENSSL_NO_IDEA
1670 IDEA_set_encrypt_key(key16, &idea_ks);
1672 #ifndef OPENSSL_NO_SEED
1673 SEED_set_key(key16, &seed_ks);
1675 #ifndef OPENSSL_NO_RC4
1676 RC4_set_key(&rc4_ks, 16, key16);
1678 #ifndef OPENSSL_NO_RC2
1679 RC2_set_key(&rc2_ks, 16, key16, 128);
1681 #ifndef OPENSSL_NO_RC5
1682 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1684 #ifndef OPENSSL_NO_BF
1685 BF_set_key(&bf_ks, 16, key16);
1687 #ifndef OPENSSL_NO_CAST
1688 CAST_set_key(&cast_ks, 16, key16);
1690 #ifndef OPENSSL_NO_RSA
1691 memset(rsa_c, 0, sizeof(rsa_c));
1694 # ifndef OPENSSL_NO_DES
1695 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1701 for (it = count; it; it--)
1702 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1703 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1707 c[D_MD2][0] = count / 10;
1708 c[D_MDC2][0] = count / 10;
1709 c[D_MD4][0] = count;
1710 c[D_MD5][0] = count;
1711 c[D_HMAC][0] = count;
1712 c[D_SHA1][0] = count;
1713 c[D_RMD160][0] = count;
1714 c[D_RC4][0] = count * 5;
1715 c[D_CBC_DES][0] = count;
1716 c[D_EDE3_DES][0] = count / 3;
1717 c[D_CBC_IDEA][0] = count;
1718 c[D_CBC_SEED][0] = count;
1719 c[D_CBC_RC2][0] = count;
1720 c[D_CBC_RC5][0] = count;
1721 c[D_CBC_BF][0] = count;
1722 c[D_CBC_CAST][0] = count;
1723 c[D_CBC_128_AES][0] = count;
1724 c[D_CBC_192_AES][0] = count;
1725 c[D_CBC_256_AES][0] = count;
1726 c[D_CBC_128_CML][0] = count;
1727 c[D_CBC_192_CML][0] = count;
1728 c[D_CBC_256_CML][0] = count;
1729 c[D_SHA256][0] = count;
1730 c[D_SHA512][0] = count;
1731 c[D_WHIRLPOOL][0] = count;
1732 c[D_IGE_128_AES][0] = count;
1733 c[D_IGE_192_AES][0] = count;
1734 c[D_IGE_256_AES][0] = count;
1735 c[D_GHASH][0] = count;
1737 for (i = 1; i < SIZE_NUM; i++) {
1740 l0 = (long)lengths[0];
1741 l1 = (long)lengths[i];
1743 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1744 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1745 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1746 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1747 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1748 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1749 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1750 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1751 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1752 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1753 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1755 l0 = (long)lengths[i - 1];
1757 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1758 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1759 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1760 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1761 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1762 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1763 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1764 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1765 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1766 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1767 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1768 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1769 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1770 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1771 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1772 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1773 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1774 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1777 # ifndef OPENSSL_NO_RSA
1778 rsa_c[R_RSA_512][0] = count / 2000;
1779 rsa_c[R_RSA_512][1] = count / 400;
1780 for (i = 1; i < RSA_NUM; i++) {
1781 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1782 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1783 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1786 if (rsa_c[i][0] == 0) {
1794 # ifndef OPENSSL_NO_DSA
1795 dsa_c[R_DSA_512][0] = count / 1000;
1796 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1797 for (i = 1; i < DSA_NUM; i++) {
1798 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1799 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1800 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1803 if (dsa_c[i] == 0) {
1811 # ifndef OPENSSL_NO_EC
1812 ecdsa_c[R_EC_P160][0] = count / 1000;
1813 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1814 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1815 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1816 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1817 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1820 if (ecdsa_c[i] == 0) {
1826 ecdsa_c[R_EC_K163][0] = count / 1000;
1827 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1828 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1829 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1830 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1831 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1834 if (ecdsa_c[i] == 0) {
1840 ecdsa_c[R_EC_B163][0] = count / 1000;
1841 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1842 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1843 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1844 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1845 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1848 if (ecdsa_c[i] == 0) {
1855 ecdh_c[R_EC_P160][0] = count / 1000;
1856 ecdh_c[R_EC_P160][1] = count / 1000;
1857 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1858 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1859 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1860 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1863 if (ecdh_c[i] == 0) {
1869 ecdh_c[R_EC_K163][0] = count / 1000;
1870 ecdh_c[R_EC_K163][1] = count / 1000;
1871 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1872 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1873 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1874 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1877 if (ecdh_c[i] == 0) {
1883 ecdh_c[R_EC_B163][0] = count / 1000;
1884 ecdh_c[R_EC_B163][1] = count / 1000;
1885 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1886 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1887 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1888 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1891 if (ecdh_c[i] == 0) {
1900 /* not worth fixing */
1901 # error "You cannot disable DES on systems without SIGALRM."
1902 # endif /* OPENSSL_NO_DES */
1905 signal(SIGALRM, sig_done);
1907 #endif /* SIGALRM */
1909 #ifndef OPENSSL_NO_MD2
1911 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1912 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1914 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1916 print_result(D_MD2, testnum, count, d);
1920 #ifndef OPENSSL_NO_MDC2
1922 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1923 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1925 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1927 print_result(D_MDC2, testnum, count, d);
1932 #ifndef OPENSSL_NO_MD4
1934 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1935 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1937 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1939 print_result(D_MD4, testnum, count, d);
1944 #ifndef OPENSSL_NO_MD5
1946 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1947 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1949 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1951 print_result(D_MD5, testnum, count, d);
1956 #ifndef OPENSSL_NO_MD5
1958 for (i = 0; i < loopargs_len; i++) {
1959 loopargs[i].hctx = HMAC_CTX_new();
1960 if (loopargs[i].hctx == NULL) {
1961 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1965 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1966 16, EVP_md5(), NULL);
1968 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1969 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1971 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1973 print_result(D_HMAC, testnum, count, d);
1975 for (i = 0; i < loopargs_len; i++) {
1976 HMAC_CTX_free(loopargs[i].hctx);
1981 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1982 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1984 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1986 print_result(D_SHA1, testnum, count, d);
1989 if (doit[D_SHA256]) {
1990 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1991 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1993 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1995 print_result(D_SHA256, testnum, count, d);
1998 if (doit[D_SHA512]) {
1999 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2000 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
2002 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2004 print_result(D_SHA512, testnum, count, d);
2008 #ifndef OPENSSL_NO_WHIRLPOOL
2009 if (doit[D_WHIRLPOOL]) {
2010 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2011 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
2013 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2015 print_result(D_WHIRLPOOL, testnum, count, d);
2020 #ifndef OPENSSL_NO_RMD160
2021 if (doit[D_RMD160]) {
2022 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2023 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2025 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2027 print_result(D_RMD160, testnum, count, d);
2031 #ifndef OPENSSL_NO_RC4
2033 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2034 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2036 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2038 print_result(D_RC4, testnum, count, d);
2042 #ifndef OPENSSL_NO_DES
2043 if (doit[D_CBC_DES]) {
2044 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2045 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2047 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2049 print_result(D_CBC_DES, testnum, count, d);
2053 if (doit[D_EDE3_DES]) {
2054 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2055 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2057 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2059 print_result(D_EDE3_DES, testnum, count, d);
2064 if (doit[D_CBC_128_AES]) {
2065 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2066 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2069 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2071 print_result(D_CBC_128_AES, testnum, count, d);
2074 if (doit[D_CBC_192_AES]) {
2075 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2076 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2079 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2081 print_result(D_CBC_192_AES, testnum, count, d);
2084 if (doit[D_CBC_256_AES]) {
2085 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2086 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2089 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2091 print_result(D_CBC_256_AES, testnum, count, d);
2095 if (doit[D_IGE_128_AES]) {
2096 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2097 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2100 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2102 print_result(D_IGE_128_AES, testnum, count, d);
2105 if (doit[D_IGE_192_AES]) {
2106 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2107 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2110 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2112 print_result(D_IGE_192_AES, testnum, count, d);
2115 if (doit[D_IGE_256_AES]) {
2116 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2117 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2120 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2122 print_result(D_IGE_256_AES, testnum, count, d);
2125 if (doit[D_GHASH]) {
2126 for (i = 0; i < loopargs_len; i++) {
2127 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2128 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2131 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2132 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2134 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2136 print_result(D_GHASH, testnum, count, d);
2138 for (i = 0; i < loopargs_len; i++)
2139 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2142 #ifndef OPENSSL_NO_CAMELLIA
2143 if (doit[D_CBC_128_CML]) {
2144 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2145 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2147 if (async_jobs > 0) {
2148 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2152 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2153 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2154 (unsigned long)lengths[testnum], &camellia_ks1,
2155 iv, CAMELLIA_ENCRYPT);
2157 print_result(D_CBC_128_CML, testnum, count, d);
2160 if (doit[D_CBC_192_CML]) {
2161 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2162 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2164 if (async_jobs > 0) {
2165 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2169 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2170 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2171 (unsigned long)lengths[testnum], &camellia_ks2,
2172 iv, CAMELLIA_ENCRYPT);
2174 print_result(D_CBC_192_CML, testnum, count, d);
2177 if (doit[D_CBC_256_CML]) {
2178 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2179 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2181 if (async_jobs > 0) {
2182 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2186 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2187 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2188 (unsigned long)lengths[testnum], &camellia_ks3,
2189 iv, CAMELLIA_ENCRYPT);
2191 print_result(D_CBC_256_CML, testnum, count, d);
2195 #ifndef OPENSSL_NO_IDEA
2196 if (doit[D_CBC_IDEA]) {
2197 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2198 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2199 if (async_jobs > 0) {
2200 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2204 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2205 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2206 (unsigned long)lengths[testnum], &idea_ks,
2209 print_result(D_CBC_IDEA, testnum, count, d);
2213 #ifndef OPENSSL_NO_SEED
2214 if (doit[D_CBC_SEED]) {
2215 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2216 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2217 if (async_jobs > 0) {
2218 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2222 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2223 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2224 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2226 print_result(D_CBC_SEED, testnum, count, d);
2230 #ifndef OPENSSL_NO_RC2
2231 if (doit[D_CBC_RC2]) {
2232 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2233 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2234 if (async_jobs > 0) {
2235 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2239 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2240 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2241 (unsigned long)lengths[testnum], &rc2_ks,
2244 print_result(D_CBC_RC2, testnum, count, d);
2248 #ifndef OPENSSL_NO_RC5
2249 if (doit[D_CBC_RC5]) {
2250 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2251 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2252 if (async_jobs > 0) {
2253 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2257 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2258 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2259 (unsigned long)lengths[testnum], &rc5_ks,
2262 print_result(D_CBC_RC5, testnum, count, d);
2266 #ifndef OPENSSL_NO_BF
2267 if (doit[D_CBC_BF]) {
2268 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2269 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2270 if (async_jobs > 0) {
2271 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2275 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2276 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2277 (unsigned long)lengths[testnum], &bf_ks,
2280 print_result(D_CBC_BF, testnum, count, d);
2284 #ifndef OPENSSL_NO_CAST
2285 if (doit[D_CBC_CAST]) {
2286 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2287 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2288 if (async_jobs > 0) {
2289 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2293 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2294 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2295 (unsigned long)lengths[testnum], &cast_ks,
2298 print_result(D_CBC_CAST, testnum, count, d);
2304 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2305 if (multiblock && evp_cipher) {
2307 (EVP_CIPHER_flags(evp_cipher) &
2308 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2309 BIO_printf(bio_err, "%s is not multi-block capable\n",
2310 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2313 if (async_jobs > 0) {
2314 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2317 multiblock_speed(evp_cipher);
2322 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2325 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2327 * -O3 -fschedule-insns messes up an optimization here!
2328 * names[D_EVP] somehow becomes NULL
2330 print_message(names[D_EVP], save_count, lengths[testnum]);
2332 for (k = 0; k < loopargs_len; k++) {
2333 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2335 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2337 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2338 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2342 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2344 for (k = 0; k < loopargs_len; k++) {
2345 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2349 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2350 print_message(names[D_EVP], save_count, lengths[testnum]);
2352 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2355 print_result(D_EVP, testnum, count, d);
2359 for (i = 0; i < loopargs_len; i++)
2360 RAND_bytes(loopargs[i].buf, 36);
2362 #ifndef OPENSSL_NO_RSA
2363 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2365 if (!rsa_doit[testnum])
2367 for (i = 0; i < loopargs_len; i++) {
2368 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2369 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2375 "RSA sign failure. No RSA sign will be done.\n");
2376 ERR_print_errors(bio_err);
2379 pkey_print_message("private", "rsa",
2380 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2381 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2383 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2386 mr ? "+R1:%ld:%d:%.2f\n"
2387 : "%ld %d bit private RSA's in %.2fs\n",
2388 count, rsa_bits[testnum], d);
2389 rsa_results[testnum][0] = d / (double)count;
2393 for (i = 0; i < loopargs_len; i++) {
2394 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2395 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2401 "RSA verify failure. No RSA verify will be done.\n");
2402 ERR_print_errors(bio_err);
2403 rsa_doit[testnum] = 0;
2405 pkey_print_message("public", "rsa",
2406 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2408 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2411 mr ? "+R2:%ld:%d:%.2f\n"
2412 : "%ld %d bit public RSA's in %.2fs\n",
2413 count, rsa_bits[testnum], d);
2414 rsa_results[testnum][1] = d / (double)count;
2417 if (rsa_count <= 1) {
2418 /* if longer than 10s, don't do any more */
2419 for (testnum++; testnum < RSA_NUM; testnum++)
2420 rsa_doit[testnum] = 0;
2425 for (i = 0; i < loopargs_len; i++)
2426 RAND_bytes(loopargs[i].buf, 36);
2428 #ifndef OPENSSL_NO_DSA
2429 if (RAND_status() != 1) {
2430 RAND_seed(rnd_seed, sizeof rnd_seed);
2432 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2434 if (!dsa_doit[testnum])
2437 /* DSA_generate_key(dsa_key[testnum]); */
2438 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2439 for (i = 0; i < loopargs_len; i++) {
2440 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2441 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2447 "DSA sign failure. No DSA sign will be done.\n");
2448 ERR_print_errors(bio_err);
2451 pkey_print_message("sign", "dsa",
2452 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2454 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2457 mr ? "+R3:%ld:%d:%.2f\n"
2458 : "%ld %d bit DSA signs in %.2fs\n",
2459 count, dsa_bits[testnum], d);
2460 dsa_results[testnum][0] = d / (double)count;
2464 for (i = 0; i < loopargs_len; i++) {
2465 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2466 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2472 "DSA verify failure. No DSA verify will be done.\n");
2473 ERR_print_errors(bio_err);
2474 dsa_doit[testnum] = 0;
2476 pkey_print_message("verify", "dsa",
2477 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2479 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2482 mr ? "+R4:%ld:%d:%.2f\n"
2483 : "%ld %d bit DSA verify in %.2fs\n",
2484 count, dsa_bits[testnum], d);
2485 dsa_results[testnum][1] = d / (double)count;
2488 if (rsa_count <= 1) {
2489 /* if longer than 10s, don't do any more */
2490 for (testnum++; testnum < DSA_NUM; testnum++)
2491 dsa_doit[testnum] = 0;
2496 #ifndef OPENSSL_NO_EC
2497 if (RAND_status() != 1) {
2498 RAND_seed(rnd_seed, sizeof rnd_seed);
2500 for (testnum = 0; testnum < EC_NUM; testnum++) {
2503 if (!ecdsa_doit[testnum])
2504 continue; /* Ignore Curve */
2505 for (i = 0; i < loopargs_len; i++) {
2506 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2507 if (loopargs[i].ecdsa[testnum] == NULL) {
2513 BIO_printf(bio_err, "ECDSA failure.\n");
2514 ERR_print_errors(bio_err);
2517 for (i = 0; i < loopargs_len; i++) {
2518 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2519 /* Perform ECDSA signature test */
2520 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2521 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2522 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2528 "ECDSA sign failure. No ECDSA sign will be done.\n");
2529 ERR_print_errors(bio_err);
2532 pkey_print_message("sign", "ecdsa",
2533 ecdsa_c[testnum][0],
2534 test_curves_bits[testnum], ECDSA_SECONDS);
2536 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2540 mr ? "+R5:%ld:%d:%.2f\n" :
2541 "%ld %d bit ECDSA signs in %.2fs \n",
2542 count, test_curves_bits[testnum], d);
2543 ecdsa_results[testnum][0] = d / (double)count;
2547 /* Perform ECDSA verification test */
2548 for (i = 0; i < loopargs_len; i++) {
2549 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2550 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2556 "ECDSA verify failure. No ECDSA verify will be done.\n");
2557 ERR_print_errors(bio_err);
2558 ecdsa_doit[testnum] = 0;
2560 pkey_print_message("verify", "ecdsa",
2561 ecdsa_c[testnum][1],
2562 test_curves_bits[testnum], ECDSA_SECONDS);
2564 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2567 mr ? "+R6:%ld:%d:%.2f\n"
2568 : "%ld %d bit ECDSA verify in %.2fs\n",
2569 count, test_curves_bits[testnum], d);
2570 ecdsa_results[testnum][1] = d / (double)count;
2573 if (rsa_count <= 1) {
2574 /* if longer than 10s, don't do any more */
2575 for (testnum++; testnum < EC_NUM; testnum++)
2576 ecdsa_doit[testnum] = 0;
2582 #ifndef OPENSSL_NO_EC
2583 if (RAND_status() != 1) {
2584 RAND_seed(rnd_seed, sizeof rnd_seed);
2586 for (testnum = 0; testnum < EC_NUM; testnum++) {
2587 if (!ecdh_doit[testnum])
2589 for (i = 0; i < loopargs_len; i++) {
2590 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2591 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2592 if (loopargs[i].ecdh_a[testnum] == NULL ||
2593 loopargs[i].ecdh_b[testnum] == NULL) {
2598 if (ecdh_checks == 0) {
2599 BIO_printf(bio_err, "ECDH failure.\n");
2600 ERR_print_errors(bio_err);
2603 for (i = 0; i < loopargs_len; i++) {
2604 /* generate two ECDH key pairs */
2605 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2606 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2607 BIO_printf(bio_err, "ECDH key generation failure.\n");
2608 ERR_print_errors(bio_err);
2613 * If field size is not more than 24 octets, then use SHA-1
2614 * hash of result; otherwise, use result (see section 4.8 of
2615 * draft-ietf-tls-ecc-03.txt).
2619 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2620 if (field_size <= 24 * 8) {
2621 outlen = KDF1_SHA1_len;
2624 outlen = (field_size + 7) / 8;
2628 ECDH_compute_key(loopargs[i].secret_a, outlen,
2629 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2630 loopargs[i].ecdh_a[testnum], kdf);
2632 ECDH_compute_key(loopargs[i].secret_b, outlen,
2633 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2634 loopargs[i].ecdh_b[testnum], kdf);
2635 if (secret_size_a != secret_size_b)
2640 for (secret_idx = 0; (secret_idx < secret_size_a)
2641 && (ecdh_checks == 1); secret_idx++) {
2642 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2646 if (ecdh_checks == 0) {
2647 BIO_printf(bio_err, "ECDH computations don't match.\n");
2648 ERR_print_errors(bio_err);
2653 if (ecdh_checks != 0) {
2654 pkey_print_message("", "ecdh",
2656 test_curves_bits[testnum], ECDH_SECONDS);
2658 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2661 mr ? "+R7:%ld:%d:%.2f\n" :
2662 "%ld %d-bit ECDH ops in %.2fs\n", count,
2663 test_curves_bits[testnum], d);
2664 ecdh_results[testnum][0] = d / (double)count;
2670 if (rsa_count <= 1) {
2671 /* if longer than 10s, don't do any more */
2672 for (testnum++; testnum < EC_NUM; testnum++)
2673 ecdh_doit[testnum] = 0;
2681 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2682 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2684 printf("%s ", BN_options());
2685 #ifndef OPENSSL_NO_MD2
2686 printf("%s ", MD2_options());
2688 #ifndef OPENSSL_NO_RC4
2689 printf("%s ", RC4_options());
2691 #ifndef OPENSSL_NO_DES
2692 printf("%s ", DES_options());
2694 printf("%s ", AES_options());
2695 #ifndef OPENSSL_NO_IDEA
2696 printf("%s ", IDEA_options());
2698 #ifndef OPENSSL_NO_BF
2699 printf("%s ", BF_options());
2701 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2709 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2712 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2713 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2717 for (k = 0; k < ALGOR_NUM; k++) {
2721 printf("+F:%d:%s", k, names[k]);
2723 printf("%-13s", names[k]);
2724 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2725 if (results[k][testnum] > 10000 && !mr)
2726 printf(" %11.2fk", results[k][testnum] / 1e3);
2728 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2732 #ifndef OPENSSL_NO_RSA
2734 for (k = 0; k < RSA_NUM; k++) {
2737 if (testnum && !mr) {
2738 printf("%18ssign verify sign/s verify/s\n", " ");
2742 printf("+F2:%u:%u:%f:%f\n",
2743 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2745 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2746 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2747 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2750 #ifndef OPENSSL_NO_DSA
2752 for (k = 0; k < DSA_NUM; k++) {
2755 if (testnum && !mr) {
2756 printf("%18ssign verify sign/s verify/s\n", " ");
2760 printf("+F3:%u:%u:%f:%f\n",
2761 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2763 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2764 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2765 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2768 #ifndef OPENSSL_NO_EC
2770 for (k = 0; k < EC_NUM; k++) {
2773 if (testnum && !mr) {
2774 printf("%30ssign verify sign/s verify/s\n", " ");
2779 printf("+F4:%u:%u:%f:%f\n",
2780 k, test_curves_bits[k],
2781 ecdsa_results[k][0], ecdsa_results[k][1]);
2783 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2784 test_curves_bits[k],
2785 test_curves_names[k],
2786 ecdsa_results[k][0], ecdsa_results[k][1],
2787 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2791 #ifndef OPENSSL_NO_EC
2793 for (k = 0; k < EC_NUM; k++) {
2796 if (testnum && !mr) {
2797 printf("%30sop op/s\n", " ");
2801 printf("+F5:%u:%u:%f:%f\n",
2802 k, test_curves_bits[k],
2803 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2806 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2807 test_curves_bits[k],
2808 test_curves_names[k],
2809 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2816 ERR_print_errors(bio_err);
2817 for (i = 0; i < loopargs_len; i++) {
2818 OPENSSL_free(loopargs[i].buf_malloc);
2819 OPENSSL_free(loopargs[i].buf2_malloc);
2820 OPENSSL_free(loopargs[i].siglen);
2822 #ifndef OPENSSL_NO_RSA
2823 for (i = 0; i < loopargs_len; i++) {
2824 for (k = 0; k < RSA_NUM; k++)
2825 RSA_free(loopargs[i].rsa_key[k]);
2828 #ifndef OPENSSL_NO_DSA
2829 for (i = 0; i < loopargs_len; i++) {
2830 for (k = 0; k < DSA_NUM; k++)
2831 DSA_free(loopargs[i].dsa_key[k]);
2835 #ifndef OPENSSL_NO_EC
2836 for (i = 0; i < loopargs_len; i++) {
2837 for (k = 0; k < EC_NUM; k++) {
2838 EC_KEY_free(loopargs[i].ecdsa[k]);
2839 EC_KEY_free(loopargs[i].ecdh_a[k]);
2840 EC_KEY_free(loopargs[i].ecdh_b[k]);
2842 OPENSSL_free(loopargs[i].secret_a);
2843 OPENSSL_free(loopargs[i].secret_b);
2846 if (async_jobs > 0) {
2847 for (i = 0; i < loopargs_len; i++)
2848 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2850 ASYNC_cleanup_thread();
2852 OPENSSL_free(loopargs);
2856 static void print_message(const char *s, long num, int length)
2860 mr ? "+DT:%s:%d:%d\n"
2861 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2862 (void)BIO_flush(bio_err);
2866 mr ? "+DN:%s:%ld:%d\n"
2867 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2868 (void)BIO_flush(bio_err);
2872 static void pkey_print_message(const char *str, const char *str2, long num,
2877 mr ? "+DTP:%d:%s:%s:%d\n"
2878 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2879 (void)BIO_flush(bio_err);
2883 mr ? "+DNP:%ld:%d:%s:%s\n"
2884 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2885 (void)BIO_flush(bio_err);
2889 static void print_result(int alg, int run_no, int count, double time_used)
2892 mr ? "+R:%d:%s:%f\n"
2893 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2894 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2898 static char *sstrsep(char **string, const char *delim)
2901 char *token = *string;
2906 memset(isdelim, 0, sizeof isdelim);
2910 isdelim[(unsigned char)(*delim)] = 1;
2914 while (!isdelim[(unsigned char)(**string)]) {
2926 static int do_multi(int multi)
2931 static char sep[] = ":";
2933 fds = malloc(sizeof(*fds) * multi);
2934 for (n = 0; n < multi; ++n) {
2935 if (pipe(fd) == -1) {
2936 BIO_printf(bio_err, "pipe failure\n");
2940 (void)BIO_flush(bio_err);
2947 if (dup(fd[1]) == -1) {
2948 BIO_printf(bio_err, "dup failed\n");
2957 printf("Forked child %d\n", n);
2960 /* for now, assume the pipe is long enough to take all the output */
2961 for (n = 0; n < multi; ++n) {
2966 f = fdopen(fds[n], "r");
2967 while (fgets(buf, sizeof buf, f)) {
2968 p = strchr(buf, '\n');
2971 if (buf[0] != '+') {
2972 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2976 printf("Got: %s from %d\n", buf, n);
2977 if (strncmp(buf, "+F:", 3) == 0) {
2982 alg = atoi(sstrsep(&p, sep));
2984 for (j = 0; j < SIZE_NUM; ++j)
2985 results[alg][j] += atof(sstrsep(&p, sep));
2986 } else if (strncmp(buf, "+F2:", 4) == 0) {
2991 k = atoi(sstrsep(&p, sep));
2994 d = atof(sstrsep(&p, sep));
2996 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2998 rsa_results[k][0] = d;
3000 d = atof(sstrsep(&p, sep));
3002 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3004 rsa_results[k][1] = d;
3006 # ifndef OPENSSL_NO_DSA
3007 else if (strncmp(buf, "+F3:", 4) == 0) {
3012 k = atoi(sstrsep(&p, sep));
3015 d = atof(sstrsep(&p, sep));
3017 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3019 dsa_results[k][0] = d;
3021 d = atof(sstrsep(&p, sep));
3023 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3025 dsa_results[k][1] = d;
3028 # ifndef OPENSSL_NO_EC
3029 else if (strncmp(buf, "+F4:", 4) == 0) {
3034 k = atoi(sstrsep(&p, sep));
3037 d = atof(sstrsep(&p, sep));
3039 ecdsa_results[k][0] =
3040 1 / (1 / ecdsa_results[k][0] + 1 / d);
3042 ecdsa_results[k][0] = d;
3044 d = atof(sstrsep(&p, sep));
3046 ecdsa_results[k][1] =
3047 1 / (1 / ecdsa_results[k][1] + 1 / d);
3049 ecdsa_results[k][1] = d;
3053 # ifndef OPENSSL_NO_EC
3054 else if (strncmp(buf, "+F5:", 4) == 0) {
3059 k = atoi(sstrsep(&p, sep));
3062 d = atof(sstrsep(&p, sep));
3064 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3066 ecdh_results[k][0] = d;
3071 else if (strncmp(buf, "+H:", 3) == 0) {
3074 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3084 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3086 static int mblengths[] =
3087 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3088 int j, count, num = OSSL_NELEM(mblengths);
3089 const char *alg_name;
3090 unsigned char *inp, *out, no_key[32], no_iv[16];
3091 EVP_CIPHER_CTX *ctx;
3094 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3095 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3096 ctx = EVP_CIPHER_CTX_new();
3097 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3098 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3100 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3102 for (j = 0; j < num; j++) {
3103 print_message(alg_name, 0, mblengths[j]);
3105 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3106 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3107 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3108 size_t len = mblengths[j];
3111 memset(aad, 0, 8); /* avoid uninitialized values */
3112 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3113 aad[9] = 3; /* version */
3115 aad[11] = 0; /* length */
3117 mb_param.out = NULL;
3120 mb_param.interleave = 8;
3122 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3123 sizeof(mb_param), &mb_param);
3129 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3130 sizeof(mb_param), &mb_param);
3134 RAND_bytes(out, 16);
3138 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3139 EVP_AEAD_TLS1_AAD_LEN, aad);
3140 EVP_Cipher(ctx, out, inp, len + pad);
3144 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3145 : "%d %s's in %.2fs\n", count, "evp", d);
3146 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3150 fprintf(stdout, "+H");
3151 for (j = 0; j < num; j++)
3152 fprintf(stdout, ":%d", mblengths[j]);
3153 fprintf(stdout, "\n");
3154 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3155 for (j = 0; j < num; j++)
3156 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3157 fprintf(stdout, "\n");
3160 "The 'numbers' are in 1000s of bytes per second processed.\n");
3161 fprintf(stdout, "type ");
3162 for (j = 0; j < num; j++)
3163 fprintf(stdout, "%7d bytes", mblengths[j]);
3164 fprintf(stdout, "\n");
3165 fprintf(stdout, "%-24s", alg_name);
3167 for (j = 0; j < num; j++) {
3168 if (results[D_EVP][j] > 10000)
3169 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3171 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3173 fprintf(stdout, "\n");
3178 EVP_CIPHER_CTX_free(ctx);