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";
316 static int rnd_fake = 0;
320 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
321 # define SIGRETTYPE void
323 # define SIGRETTYPE int
326 static SIGRETTYPE sig_done(int sig);
327 static SIGRETTYPE sig_done(int sig)
329 signal(SIGALRM, sig_done);
339 # if !defined(SIGALRM)
342 static unsigned int lapse, schlock;
343 static void alarm_win32(unsigned int secs)
348 # define alarm alarm_win32
350 static DWORD WINAPI sleepy(VOID * arg)
358 static double Time_F(int s)
365 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
367 DWORD err = GetLastError();
368 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
372 Sleep(0); /* scheduler spinlock */
373 ret = app_tminterval(s, usertime);
375 ret = app_tminterval(s, usertime);
377 TerminateThread(thr, 0);
385 static double Time_F(int s)
387 double ret = app_tminterval(s, usertime);
394 #ifndef OPENSSL_NO_EC
395 static const int KDF1_SHA1_len = 20;
396 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
399 if (*outlen < SHA_DIGEST_LENGTH)
401 *outlen = SHA_DIGEST_LENGTH;
402 return SHA1(in, inlen, out);
404 #endif /* OPENSSL_NO_EC */
406 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
408 static int found(const char *name, const OPT_PAIR * pairs, int *result)
410 for (; pairs->name; pairs++)
411 if (strcmp(name, pairs->name) == 0) {
412 *result = pairs->retval;
418 typedef enum OPTION_choice {
419 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
420 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
421 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
424 OPTIONS speed_options[] = {
425 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
426 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
427 {"help", OPT_HELP, '-', "Display this summary"},
428 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
429 {"decrypt", OPT_DECRYPT, '-',
430 "Time decryption instead of encryption (only EVP)"},
431 {"mr", OPT_MR, '-', "Produce machine readable output"},
433 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
434 {"elapsed", OPT_ELAPSED, '-',
435 "Measure time in real time instead of CPU user time"},
437 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
439 #ifndef OPENSSL_NO_ASYNC
440 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
442 #ifndef OPENSSL_NO_ENGINE
443 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
458 #define D_CBC_IDEA 10
459 #define D_CBC_SEED 11
463 #define D_CBC_CAST 15
464 #define D_CBC_128_AES 16
465 #define D_CBC_192_AES 17
466 #define D_CBC_256_AES 18
467 #define D_CBC_128_CML 19
468 #define D_CBC_192_CML 20
469 #define D_CBC_256_CML 21
473 #define D_WHIRLPOOL 25
474 #define D_IGE_128_AES 26
475 #define D_IGE_192_AES 27
476 #define D_IGE_256_AES 28
478 static OPT_PAIR doit_choices[] = {
479 #ifndef OPENSSL_NO_MD2
482 #ifndef OPENSSL_NO_MDC2
485 #ifndef OPENSSL_NO_MD4
488 #ifndef OPENSSL_NO_MD5
491 #ifndef OPENSSL_NO_MD5
495 {"sha256", D_SHA256},
496 {"sha512", D_SHA512},
497 #ifndef OPENSSL_NO_WHIRLPOOL
498 {"whirlpool", D_WHIRLPOOL},
500 #ifndef OPENSSL_NO_RMD160
501 {"ripemd", D_RMD160},
502 {"rmd160", D_RMD160},
503 {"ripemd160", D_RMD160},
505 #ifndef OPENSSL_NO_RC4
508 #ifndef OPENSSL_NO_DES
509 {"des-cbc", D_CBC_DES},
510 {"des-ede3", D_EDE3_DES},
512 #ifndef OPENSSL_NO_AES
513 {"aes-128-cbc", D_CBC_128_AES},
514 {"aes-192-cbc", D_CBC_192_AES},
515 {"aes-256-cbc", D_CBC_256_AES},
516 {"aes-128-ige", D_IGE_128_AES},
517 {"aes-192-ige", D_IGE_192_AES},
518 {"aes-256-ige", D_IGE_256_AES},
520 #ifndef OPENSSL_NO_RC2
521 {"rc2-cbc", D_CBC_RC2},
524 #ifndef OPENSSL_NO_RC5
525 {"rc5-cbc", D_CBC_RC5},
528 #ifndef OPENSSL_NO_IDEA
529 {"idea-cbc", D_CBC_IDEA},
530 {"idea", D_CBC_IDEA},
532 #ifndef OPENSSL_NO_SEED
533 {"seed-cbc", D_CBC_SEED},
534 {"seed", D_CBC_SEED},
536 #ifndef OPENSSL_NO_BF
537 {"bf-cbc", D_CBC_BF},
538 {"blowfish", D_CBC_BF},
541 #ifndef OPENSSL_NO_CAST
542 {"cast-cbc", D_CBC_CAST},
543 {"cast", D_CBC_CAST},
544 {"cast5", D_CBC_CAST},
553 static OPT_PAIR dsa_choices[] = {
554 {"dsa512", R_DSA_512},
555 {"dsa1024", R_DSA_1024},
556 {"dsa2048", R_DSA_2048},
566 #define R_RSA_15360 6
567 static OPT_PAIR rsa_choices[] = {
568 {"rsa512", R_RSA_512},
569 {"rsa1024", R_RSA_1024},
570 {"rsa2048", R_RSA_2048},
571 {"rsa3072", R_RSA_3072},
572 {"rsa4096", R_RSA_4096},
573 {"rsa7680", R_RSA_7680},
574 {"rsa15360", R_RSA_15360},
594 #define R_EC_X25519 16
595 #ifndef OPENSSL_NO_EC
596 static OPT_PAIR ecdsa_choices[] = {
597 {"ecdsap160", R_EC_P160},
598 {"ecdsap192", R_EC_P192},
599 {"ecdsap224", R_EC_P224},
600 {"ecdsap256", R_EC_P256},
601 {"ecdsap384", R_EC_P384},
602 {"ecdsap521", R_EC_P521},
603 {"ecdsak163", R_EC_K163},
604 {"ecdsak233", R_EC_K233},
605 {"ecdsak283", R_EC_K283},
606 {"ecdsak409", R_EC_K409},
607 {"ecdsak571", R_EC_K571},
608 {"ecdsab163", R_EC_B163},
609 {"ecdsab233", R_EC_B233},
610 {"ecdsab283", R_EC_B283},
611 {"ecdsab409", R_EC_B409},
612 {"ecdsab571", R_EC_B571},
615 static OPT_PAIR ecdh_choices[] = {
616 {"ecdhp160", R_EC_P160},
617 {"ecdhp192", R_EC_P192},
618 {"ecdhp224", R_EC_P224},
619 {"ecdhp256", R_EC_P256},
620 {"ecdhp384", R_EC_P384},
621 {"ecdhp521", R_EC_P521},
622 {"ecdhk163", R_EC_K163},
623 {"ecdhk233", R_EC_K233},
624 {"ecdhk283", R_EC_K283},
625 {"ecdhk409", R_EC_K409},
626 {"ecdhk571", R_EC_K571},
627 {"ecdhb163", R_EC_B163},
628 {"ecdhb233", R_EC_B233},
629 {"ecdhb283", R_EC_B283},
630 {"ecdhb409", R_EC_B409},
631 {"ecdhb571", R_EC_B571},
632 {"ecdhx25519", R_EC_X25519},
638 # define COND(d) (count < (d))
639 # define COUNT(d) (d)
641 # define COND(c) (run && count<0x7fffffff)
642 # define COUNT(d) (count)
646 static char *engine_id = NULL;
649 #ifndef OPENSSL_NO_MD2
650 static int EVP_Digest_MD2_loop(void *args)
652 loopargs_t *tempargs = (loopargs_t *)args;
653 unsigned char *buf = tempargs->buf;
654 unsigned char md2[MD2_DIGEST_LENGTH];
656 for (count = 0; COND(c[D_MD2][testnum]); count++)
657 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
663 #ifndef OPENSSL_NO_MDC2
664 static int EVP_Digest_MDC2_loop(void *args)
666 loopargs_t *tempargs = (loopargs_t *)args;
667 unsigned char *buf = tempargs->buf;
668 unsigned char mdc2[MDC2_DIGEST_LENGTH];
670 for (count = 0; COND(c[D_MDC2][testnum]); count++)
671 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
677 #ifndef OPENSSL_NO_MD4
678 static int EVP_Digest_MD4_loop(void *args)
680 loopargs_t *tempargs = (loopargs_t *)args;
681 unsigned char *buf = tempargs->buf;
682 unsigned char md4[MD4_DIGEST_LENGTH];
684 for (count = 0; COND(c[D_MD4][testnum]); count++)
685 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
686 NULL, EVP_md4(), NULL);
691 #ifndef OPENSSL_NO_MD5
692 static int MD5_loop(void *args)
694 loopargs_t *tempargs = (loopargs_t *)args;
695 unsigned char *buf = tempargs->buf;
696 unsigned char md5[MD5_DIGEST_LENGTH];
698 for (count = 0; COND(c[D_MD5][testnum]); count++)
699 MD5(buf, lengths[testnum], md5);
703 static int HMAC_loop(void *args)
705 loopargs_t *tempargs = (loopargs_t *)args;
706 unsigned char *buf = tempargs->buf;
707 HMAC_CTX *hctx = tempargs->hctx;
708 unsigned char hmac[MD5_DIGEST_LENGTH];
710 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
711 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
712 HMAC_Update(hctx, buf, lengths[testnum]);
713 HMAC_Final(hctx, &(hmac[0]), NULL);
719 static int SHA1_loop(void *args)
721 loopargs_t *tempargs = (loopargs_t *)args;
722 unsigned char *buf = tempargs->buf;
723 unsigned char sha[SHA_DIGEST_LENGTH];
725 for (count = 0; COND(c[D_SHA1][testnum]); count++)
726 SHA1(buf, lengths[testnum], sha);
730 static int SHA256_loop(void *args)
732 loopargs_t *tempargs = (loopargs_t *)args;
733 unsigned char *buf = tempargs->buf;
734 unsigned char sha256[SHA256_DIGEST_LENGTH];
736 for (count = 0; COND(c[D_SHA256][testnum]); count++)
737 SHA256(buf, lengths[testnum], sha256);
741 static int SHA512_loop(void *args)
743 loopargs_t *tempargs = (loopargs_t *)args;
744 unsigned char *buf = tempargs->buf;
745 unsigned char sha512[SHA512_DIGEST_LENGTH];
747 for (count = 0; COND(c[D_SHA512][testnum]); count++)
748 SHA512(buf, lengths[testnum], sha512);
752 #ifndef OPENSSL_NO_WHIRLPOOL
753 static int WHIRLPOOL_loop(void *args)
755 loopargs_t *tempargs = (loopargs_t *)args;
756 unsigned char *buf = tempargs->buf;
757 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
759 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
760 WHIRLPOOL(buf, lengths[testnum], whirlpool);
765 #ifndef OPENSSL_NO_RMD160
766 static int EVP_Digest_RMD160_loop(void *args)
768 loopargs_t *tempargs = (loopargs_t *)args;
769 unsigned char *buf = tempargs->buf;
770 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
772 for (count = 0; COND(c[D_RMD160][testnum]); count++)
773 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
774 EVP_ripemd160(), NULL);
779 #ifndef OPENSSL_NO_RC4
780 static RC4_KEY rc4_ks;
781 static int RC4_loop(void *args)
783 loopargs_t *tempargs = (loopargs_t *)args;
784 unsigned char *buf = tempargs->buf;
786 for (count = 0; COND(c[D_RC4][testnum]); count++)
787 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
792 #ifndef OPENSSL_NO_DES
793 static unsigned char DES_iv[8];
794 static DES_key_schedule sch;
795 static DES_key_schedule sch2;
796 static DES_key_schedule sch3;
797 static int DES_ncbc_encrypt_loop(void *args)
799 loopargs_t *tempargs = (loopargs_t *)args;
800 unsigned char *buf = tempargs->buf;
802 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
803 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
804 &DES_iv, DES_ENCRYPT);
808 static int DES_ede3_cbc_encrypt_loop(void *args)
810 loopargs_t *tempargs = (loopargs_t *)args;
811 unsigned char *buf = tempargs->buf;
813 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
814 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
816 &DES_iv, DES_ENCRYPT);
821 #ifndef OPENSSL_NO_AES
822 # define MAX_BLOCK_SIZE 128
824 # define MAX_BLOCK_SIZE 64
827 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
828 #ifndef OPENSSL_NO_AES
829 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
830 static int AES_cbc_128_encrypt_loop(void *args)
832 loopargs_t *tempargs = (loopargs_t *)args;
833 unsigned char *buf = tempargs->buf;
835 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
836 AES_cbc_encrypt(buf, buf,
837 (unsigned long)lengths[testnum], &aes_ks1,
842 static int AES_cbc_192_encrypt_loop(void *args)
844 loopargs_t *tempargs = (loopargs_t *)args;
845 unsigned char *buf = tempargs->buf;
847 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
848 AES_cbc_encrypt(buf, buf,
849 (unsigned long)lengths[testnum], &aes_ks2,
854 static int AES_cbc_256_encrypt_loop(void *args)
856 loopargs_t *tempargs = (loopargs_t *)args;
857 unsigned char *buf = tempargs->buf;
859 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
860 AES_cbc_encrypt(buf, buf,
861 (unsigned long)lengths[testnum], &aes_ks3,
866 static int AES_ige_128_encrypt_loop(void *args)
868 loopargs_t *tempargs = (loopargs_t *)args;
869 unsigned char *buf = tempargs->buf;
870 unsigned char *buf2 = tempargs->buf2;
872 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
873 AES_ige_encrypt(buf, buf2,
874 (unsigned long)lengths[testnum], &aes_ks1,
879 static int AES_ige_192_encrypt_loop(void *args)
881 loopargs_t *tempargs = (loopargs_t *)args;
882 unsigned char *buf = tempargs->buf;
883 unsigned char *buf2 = tempargs->buf2;
885 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
886 AES_ige_encrypt(buf, buf2,
887 (unsigned long)lengths[testnum], &aes_ks2,
892 static int AES_ige_256_encrypt_loop(void *args)
894 loopargs_t *tempargs = (loopargs_t *)args;
895 unsigned char *buf = tempargs->buf;
896 unsigned char *buf2 = tempargs->buf2;
898 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
899 AES_ige_encrypt(buf, buf2,
900 (unsigned long)lengths[testnum], &aes_ks3,
905 static int CRYPTO_gcm128_aad_loop(void *args)
907 loopargs_t *tempargs = (loopargs_t *)args;
908 unsigned char *buf = tempargs->buf;
909 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
911 for (count = 0; COND(c[D_GHASH][testnum]); count++)
912 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
918 static int decrypt = 0;
919 static int EVP_Update_loop(void *args)
921 loopargs_t *tempargs = (loopargs_t *)args;
922 unsigned char *buf = tempargs->buf;
923 EVP_CIPHER_CTX *ctx = tempargs->ctx;
927 COND(save_count * 4 * lengths[0] / lengths[testnum]);
929 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
932 COND(save_count * 4 * lengths[0] / lengths[testnum]);
934 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
936 EVP_DecryptFinal_ex(ctx, buf, &outl);
938 EVP_EncryptFinal_ex(ctx, buf, &outl);
942 static const EVP_MD *evp_md = NULL;
943 static int EVP_Digest_loop(void *args)
945 loopargs_t *tempargs = (loopargs_t *)args;
946 unsigned char *buf = tempargs->buf;
947 unsigned char md[EVP_MAX_MD_SIZE];
950 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
951 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
956 #ifndef OPENSSL_NO_RSA
957 static long rsa_c[RSA_NUM][2];
959 static int RSA_sign_loop(void *args)
961 loopargs_t *tempargs = (loopargs_t *)args;
962 unsigned char *buf = tempargs->buf;
963 unsigned char *buf2 = tempargs->buf2;
964 unsigned int *rsa_num = tempargs->siglen;
965 RSA **rsa_key = tempargs->rsa_key;
967 for (count = 0; COND(rsa_c[testnum][0]); count++) {
968 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
970 BIO_printf(bio_err, "RSA sign failure\n");
971 ERR_print_errors(bio_err);
979 static int RSA_verify_loop(void *args)
981 loopargs_t *tempargs = (loopargs_t *)args;
982 unsigned char *buf = tempargs->buf;
983 unsigned char *buf2 = tempargs->buf2;
984 unsigned int rsa_num = *(tempargs->siglen);
985 RSA **rsa_key = tempargs->rsa_key;
987 for (count = 0; COND(rsa_c[testnum][1]); count++) {
988 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
990 BIO_printf(bio_err, "RSA verify failure\n");
991 ERR_print_errors(bio_err);
1000 #ifndef OPENSSL_NO_DSA
1001 static long dsa_c[DSA_NUM][2];
1002 static int DSA_sign_loop(void *args)
1004 loopargs_t *tempargs = (loopargs_t *)args;
1005 unsigned char *buf = tempargs->buf;
1006 unsigned char *buf2 = tempargs->buf2;
1007 DSA **dsa_key = tempargs->dsa_key;
1008 unsigned int *siglen = tempargs->siglen;
1010 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1011 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1013 BIO_printf(bio_err, "DSA sign failure\n");
1014 ERR_print_errors(bio_err);
1022 static int DSA_verify_loop(void *args)
1024 loopargs_t *tempargs = (loopargs_t *)args;
1025 unsigned char *buf = tempargs->buf;
1026 unsigned char *buf2 = tempargs->buf2;
1027 DSA **dsa_key = tempargs->dsa_key;
1028 unsigned int siglen = *(tempargs->siglen);
1030 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1031 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1033 BIO_printf(bio_err, "DSA verify failure\n");
1034 ERR_print_errors(bio_err);
1043 #ifndef OPENSSL_NO_EC
1044 static long ecdsa_c[EC_NUM][2];
1045 static int ECDSA_sign_loop(void *args)
1047 loopargs_t *tempargs = (loopargs_t *)args;
1048 unsigned char *buf = tempargs->buf;
1049 EC_KEY **ecdsa = tempargs->ecdsa;
1050 unsigned char *ecdsasig = tempargs->buf2;
1051 unsigned int *ecdsasiglen = tempargs->siglen;
1053 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1054 ret = ECDSA_sign(0, buf, 20,
1055 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1057 BIO_printf(bio_err, "ECDSA sign failure\n");
1058 ERR_print_errors(bio_err);
1066 static int ECDSA_verify_loop(void *args)
1068 loopargs_t *tempargs = (loopargs_t *)args;
1069 unsigned char *buf = tempargs->buf;
1070 EC_KEY **ecdsa = tempargs->ecdsa;
1071 unsigned char *ecdsasig = tempargs->buf2;
1072 unsigned int ecdsasiglen = *(tempargs->siglen);
1074 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1075 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1078 BIO_printf(bio_err, "ECDSA verify failure\n");
1079 ERR_print_errors(bio_err);
1088 static void *(*kdf) (const void *in, size_t inlen, void *out,
1091 static int ECDH_compute_key_loop(void *args)
1093 loopargs_t *tempargs = (loopargs_t *)args;
1094 EC_KEY **ecdh_a = tempargs->ecdh_a;
1095 EC_KEY **ecdh_b = tempargs->ecdh_b;
1096 unsigned char *secret_a = tempargs->secret_a;
1098 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1099 ECDH_compute_key(secret_a, outlen,
1100 EC_KEY_get0_public_key(ecdh_b[testnum]),
1101 ecdh_a[testnum], kdf);
1108 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1110 int job_op_count = 0;
1111 int total_op_count = 0;
1112 int num_inprogress = 0;
1115 OSSL_ASYNC_FD job_fd = 0;
1116 size_t num_job_fds = 0;
1120 if (async_jobs == 0) {
1121 return loop_function((void *)loopargs);
1125 for (i = 0; i < async_jobs && !error; i++) {
1126 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1127 &job_op_count, loop_function,
1128 (void *)(loopargs + i), sizeof(loopargs_t))) {
1133 if (job_op_count == -1) {
1136 total_op_count += job_op_count;
1141 BIO_printf(bio_err, "Failure in the job\n");
1142 ERR_print_errors(bio_err);
1148 while (num_inprogress > 0) {
1149 #if defined(OPENSSL_SYS_WINDOWS)
1151 #elif defined(OPENSSL_SYS_UNIX)
1152 int select_result = 0;
1153 OSSL_ASYNC_FD max_fd = 0;
1156 FD_ZERO(&waitfdset);
1158 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1159 if (loopargs[i].inprogress_job == NULL)
1162 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1163 || num_job_fds > 1) {
1164 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1165 ERR_print_errors(bio_err);
1169 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1170 FD_SET(job_fd, &waitfdset);
1171 if (job_fd > max_fd)
1175 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1176 if (select_result == -1 && errno == EINTR)
1179 if (select_result == -1) {
1180 BIO_printf(bio_err, "Failure in the select\n");
1181 ERR_print_errors(bio_err);
1186 if (select_result == 0)
1190 for (i = 0; i < async_jobs; i++) {
1191 if (loopargs[i].inprogress_job == NULL)
1194 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1195 || num_job_fds > 1) {
1196 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1197 ERR_print_errors(bio_err);
1201 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1203 #if defined(OPENSSL_SYS_UNIX)
1204 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1206 #elif defined(OPENSSL_SYS_WINDOWS)
1207 if (num_job_fds == 1 &&
1208 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1212 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1213 &job_op_count, loop_function, (void *)(loopargs + i),
1214 sizeof(loopargs_t))) {
1218 if (job_op_count == -1) {
1221 total_op_count += job_op_count;
1224 loopargs[i].inprogress_job = NULL;
1229 loopargs[i].inprogress_job = NULL;
1230 BIO_printf(bio_err, "Failure in the job\n");
1231 ERR_print_errors(bio_err);
1238 return error ? -1 : total_op_count;
1241 int speed_main(int argc, char **argv)
1243 loopargs_t *loopargs = NULL;
1244 int loopargs_len = 0;
1246 const EVP_CIPHER *evp_cipher = NULL;
1249 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1250 int dsa_doit[DSA_NUM], rsa_doit[RSA_NUM];
1251 int ret = 1, i, k, misalign = 0;
1252 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
1257 /* What follows are the buffers and key material. */
1258 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1261 #ifndef OPENSSL_NO_RC5
1264 #ifndef OPENSSL_NO_RC2
1267 #ifndef OPENSSL_NO_IDEA
1268 IDEA_KEY_SCHEDULE idea_ks;
1270 #ifndef OPENSSL_NO_SEED
1271 SEED_KEY_SCHEDULE seed_ks;
1273 #ifndef OPENSSL_NO_BF
1276 #ifndef OPENSSL_NO_CAST
1279 static const unsigned char key16[16] = {
1280 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1281 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1283 #ifndef OPENSSL_NO_AES
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
1296 #ifndef OPENSSL_NO_CAMELLIA
1297 static const unsigned char ckey24[24] = {
1298 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1299 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1300 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1302 static const unsigned char ckey32[32] = {
1303 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1304 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1305 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1306 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1308 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1310 #ifndef OPENSSL_NO_DES
1311 static DES_cblock key = {
1312 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1314 static DES_cblock key2 = {
1315 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1317 static DES_cblock key3 = {
1318 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1321 #ifndef OPENSSL_NO_RSA
1322 static unsigned int rsa_bits[RSA_NUM] = {
1323 512, 1024, 2048, 3072, 4096, 7680, 15360
1325 static unsigned char *rsa_data[RSA_NUM] = {
1326 test512, test1024, test2048, test3072, test4096, test7680, test15360
1328 static int rsa_data_length[RSA_NUM] = {
1329 sizeof(test512), sizeof(test1024),
1330 sizeof(test2048), sizeof(test3072),
1331 sizeof(test4096), sizeof(test7680),
1335 #ifndef OPENSSL_NO_DSA
1336 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1338 #ifndef OPENSSL_NO_EC
1340 * We only test over the following curves as they are representative, To
1341 * add tests over more curves, simply add the curve NID and curve name to
1342 * the following arrays and increase the EC_NUM value accordingly.
1344 static unsigned int test_curves[EC_NUM] = {
1346 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1347 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1349 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1350 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1351 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1356 static const char *test_curves_names[EC_NUM] = {
1358 "secp160r1", "nistp192", "nistp224",
1359 "nistp256", "nistp384", "nistp521",
1361 "nistk163", "nistk233", "nistk283",
1362 "nistk409", "nistk571", "nistb163",
1363 "nistb233", "nistb283", "nistb409",
1368 static int test_curves_bits[EC_NUM] = {
1374 571, 253 /* X25519 */
1377 #ifndef OPENSSL_NO_EC
1378 int ecdsa_doit[EC_NUM];
1379 int secret_size_a, secret_size_b;
1380 int ecdh_checks = 1;
1382 long ecdh_c[EC_NUM][2];
1383 int ecdh_doit[EC_NUM];
1386 memset(results, 0, sizeof(results));
1388 memset(c, 0, sizeof(c));
1389 #ifndef OPENSSL_NO_DES
1390 memset(DES_iv, 0, sizeof(DES_iv));
1392 memset(iv, 0, sizeof(iv));
1394 for (i = 0; i < ALGOR_NUM; i++)
1396 for (i = 0; i < RSA_NUM; i++)
1398 for (i = 0; i < DSA_NUM; i++)
1400 #ifndef OPENSSL_NO_EC
1401 for (i = 0; i < EC_NUM; i++)
1403 for (i = 0; i < EC_NUM; i++)
1409 prog = opt_init(argc, argv, speed_options);
1410 while ((o = opt_next()) != OPT_EOF) {
1415 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1418 opt_help(speed_options);
1425 evp_cipher = EVP_get_cipherbyname(opt_arg());
1426 if (evp_cipher == NULL)
1427 evp_md = EVP_get_digestbyname(opt_arg());
1428 if (evp_cipher == NULL && evp_md == NULL) {
1430 "%s: %s an unknown cipher or digest\n",
1441 * In a forked execution, an engine might need to be
1442 * initialised by each child process, not by the parent.
1443 * So store the name here and run setup_engine() later on.
1445 engine_id = opt_arg();
1449 multi = atoi(opt_arg());
1453 #ifndef OPENSSL_NO_ASYNC
1454 async_jobs = atoi(opt_arg());
1455 if (!ASYNC_is_capable()) {
1457 "%s: async_jobs specified but async not supported\n",
1464 if (!opt_int(opt_arg(), &misalign))
1466 if (misalign > MISALIGN) {
1468 "%s: Maximum offset is %d\n", prog, MISALIGN);
1480 argc = opt_num_rest();
1483 /* Remaining arguments are algorithms. */
1484 for ( ; *argv; argv++) {
1485 if (found(*argv, doit_choices, &i)) {
1489 #ifndef OPENSSL_NO_DES
1490 if (strcmp(*argv, "des") == 0) {
1491 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1495 if (strcmp(*argv, "sha") == 0) {
1496 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1499 #ifndef OPENSSL_NO_RSA
1501 if (strcmp(*argv, "openssl") == 0) {
1502 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1506 if (strcmp(*argv, "rsa") == 0) {
1507 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1508 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1509 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1510 rsa_doit[R_RSA_15360] = 1;
1513 if (found(*argv, rsa_choices, &i)) {
1518 #ifndef OPENSSL_NO_DSA
1519 if (strcmp(*argv, "dsa") == 0) {
1520 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1521 dsa_doit[R_DSA_2048] = 1;
1524 if (found(*argv, dsa_choices, &i)) {
1529 #ifndef OPENSSL_NO_AES
1530 if (strcmp(*argv, "aes") == 0) {
1531 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1532 doit[D_CBC_256_AES] = 1;
1536 #ifndef OPENSSL_NO_CAMELLIA
1537 if (strcmp(*argv, "camellia") == 0) {
1538 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1539 doit[D_CBC_256_CML] = 1;
1543 #ifndef OPENSSL_NO_EC
1544 if (strcmp(*argv, "ecdsa") == 0) {
1545 for (i = 0; i < EC_NUM; i++)
1549 if (found(*argv, ecdsa_choices, &i)) {
1553 if (strcmp(*argv, "ecdh") == 0) {
1554 for (i = 0; i < EC_NUM; i++)
1558 if (found(*argv, ecdh_choices, &i)) {
1563 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1567 /* Initialize the job pool if async mode is enabled */
1568 if (async_jobs > 0) {
1569 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1570 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1575 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1576 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1577 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1579 for (i = 0; i < loopargs_len; i++) {
1580 if (async_jobs > 0) {
1581 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1582 if (loopargs[i].wait_ctx == NULL) {
1583 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1588 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1589 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1590 /* Align the start of buffers on a 64 byte boundary */
1591 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1592 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1593 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1594 #ifndef OPENSSL_NO_EC
1595 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1596 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1601 if (multi && do_multi(multi))
1605 /* Initialize the engine after the fork */
1606 (void)setup_engine(engine_id, 0);
1608 /* No parameters; turn on everything. */
1609 if ((argc == 0) && !doit[D_EVP]) {
1610 for (i = 0; i < ALGOR_NUM; i++)
1613 for (i = 0; i < RSA_NUM; i++)
1615 for (i = 0; i < DSA_NUM; i++)
1617 #ifndef OPENSSL_NO_EC
1618 for (i = 0; i < EC_NUM; i++)
1620 for (i = 0; i < EC_NUM; i++)
1624 for (i = 0; i < ALGOR_NUM; i++)
1628 if (usertime == 0 && !mr)
1630 "You have chosen to measure elapsed time "
1631 "instead of user CPU time.\n");
1633 #ifndef OPENSSL_NO_RSA
1634 for (i = 0; i < loopargs_len; i++) {
1635 for (k = 0; k < RSA_NUM; k++) {
1636 const unsigned char *p;
1639 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1640 if (loopargs[i].rsa_key[k] == NULL) {
1641 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1648 #ifndef OPENSSL_NO_DSA
1649 for (i = 0; i < loopargs_len; i++) {
1650 loopargs[i].dsa_key[0] = get_dsa512();
1651 loopargs[i].dsa_key[1] = get_dsa1024();
1652 loopargs[i].dsa_key[2] = get_dsa2048();
1655 #ifndef OPENSSL_NO_DES
1656 DES_set_key_unchecked(&key, &sch);
1657 DES_set_key_unchecked(&key2, &sch2);
1658 DES_set_key_unchecked(&key3, &sch3);
1660 #ifndef OPENSSL_NO_AES
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);
1665 #ifndef OPENSSL_NO_CAMELLIA
1666 Camellia_set_key(key16, 128, &camellia_ks1);
1667 Camellia_set_key(ckey24, 192, &camellia_ks2);
1668 Camellia_set_key(ckey32, 256, &camellia_ks3);
1670 #ifndef OPENSSL_NO_IDEA
1671 idea_set_encrypt_key(key16, &idea_ks);
1673 #ifndef OPENSSL_NO_SEED
1674 SEED_set_key(key16, &seed_ks);
1676 #ifndef OPENSSL_NO_RC4
1677 RC4_set_key(&rc4_ks, 16, key16);
1679 #ifndef OPENSSL_NO_RC2
1680 RC2_set_key(&rc2_ks, 16, key16, 128);
1682 #ifndef OPENSSL_NO_RC5
1683 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1685 #ifndef OPENSSL_NO_BF
1686 BF_set_key(&bf_ks, 16, key16);
1688 #ifndef OPENSSL_NO_CAST
1689 CAST_set_key(&cast_ks, 16, key16);
1691 #ifndef OPENSSL_NO_RSA
1692 memset(rsa_c, 0, sizeof(rsa_c));
1695 # ifndef OPENSSL_NO_DES
1696 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1702 for (it = count; it; it--)
1703 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1704 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1708 c[D_MD2][0] = count / 10;
1709 c[D_MDC2][0] = count / 10;
1710 c[D_MD4][0] = count;
1711 c[D_MD5][0] = count;
1712 c[D_HMAC][0] = count;
1713 c[D_SHA1][0] = count;
1714 c[D_RMD160][0] = count;
1715 c[D_RC4][0] = count * 5;
1716 c[D_CBC_DES][0] = count;
1717 c[D_EDE3_DES][0] = count / 3;
1718 c[D_CBC_IDEA][0] = count;
1719 c[D_CBC_SEED][0] = count;
1720 c[D_CBC_RC2][0] = count;
1721 c[D_CBC_RC5][0] = count;
1722 c[D_CBC_BF][0] = count;
1723 c[D_CBC_CAST][0] = count;
1724 c[D_CBC_128_AES][0] = count;
1725 c[D_CBC_192_AES][0] = count;
1726 c[D_CBC_256_AES][0] = count;
1727 c[D_CBC_128_CML][0] = count;
1728 c[D_CBC_192_CML][0] = count;
1729 c[D_CBC_256_CML][0] = count;
1730 c[D_SHA256][0] = count;
1731 c[D_SHA512][0] = count;
1732 c[D_WHIRLPOOL][0] = count;
1733 c[D_IGE_128_AES][0] = count;
1734 c[D_IGE_192_AES][0] = count;
1735 c[D_IGE_256_AES][0] = count;
1736 c[D_GHASH][0] = count;
1738 for (i = 1; i < SIZE_NUM; i++) {
1741 l0 = (long)lengths[0];
1742 l1 = (long)lengths[i];
1744 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1745 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1746 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1747 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1748 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1749 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1750 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1751 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1752 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1753 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1754 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1756 l0 = (long)lengths[i - 1];
1758 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1759 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1760 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1761 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1762 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1763 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1764 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1765 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1766 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1767 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1768 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1769 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1770 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1771 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1772 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1773 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1774 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1775 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1778 # ifndef OPENSSL_NO_RSA
1779 rsa_c[R_RSA_512][0] = count / 2000;
1780 rsa_c[R_RSA_512][1] = count / 400;
1781 for (i = 1; i < RSA_NUM; i++) {
1782 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1783 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1784 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1787 if (rsa_c[i][0] == 0) {
1795 # ifndef OPENSSL_NO_DSA
1796 dsa_c[R_DSA_512][0] = count / 1000;
1797 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1798 for (i = 1; i < DSA_NUM; i++) {
1799 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1800 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1801 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1804 if (dsa_c[i] == 0) {
1812 # ifndef OPENSSL_NO_EC
1813 ecdsa_c[R_EC_P160][0] = count / 1000;
1814 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1815 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1816 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1817 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1818 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1821 if (ecdsa_c[i] == 0) {
1827 ecdsa_c[R_EC_K163][0] = count / 1000;
1828 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1829 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1830 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1831 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1832 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1835 if (ecdsa_c[i] == 0) {
1841 ecdsa_c[R_EC_B163][0] = count / 1000;
1842 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1843 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1844 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1845 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1846 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1849 if (ecdsa_c[i] == 0) {
1856 ecdh_c[R_EC_P160][0] = count / 1000;
1857 ecdh_c[R_EC_P160][1] = count / 1000;
1858 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1859 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1860 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1861 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1864 if (ecdh_c[i] == 0) {
1870 ecdh_c[R_EC_K163][0] = count / 1000;
1871 ecdh_c[R_EC_K163][1] = count / 1000;
1872 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1873 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1874 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1875 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1878 if (ecdh_c[i] == 0) {
1884 ecdh_c[R_EC_B163][0] = count / 1000;
1885 ecdh_c[R_EC_B163][1] = count / 1000;
1886 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1887 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1888 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1889 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1892 if (ecdh_c[i] == 0) {
1901 /* not worth fixing */
1902 # error "You cannot disable DES on systems without SIGALRM."
1903 # endif /* OPENSSL_NO_DES */
1906 signal(SIGALRM, sig_done);
1908 #endif /* SIGALRM */
1910 #ifndef OPENSSL_NO_MD2
1912 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1913 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1915 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1917 print_result(D_MD2, testnum, count, d);
1921 #ifndef OPENSSL_NO_MDC2
1923 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1924 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1926 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1928 print_result(D_MDC2, testnum, count, d);
1933 #ifndef OPENSSL_NO_MD4
1935 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1936 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1938 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1940 print_result(D_MD4, testnum, count, d);
1945 #ifndef OPENSSL_NO_MD5
1947 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1948 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1950 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1952 print_result(D_MD5, testnum, count, d);
1957 #ifndef OPENSSL_NO_MD5
1959 for (i = 0; i < loopargs_len; i++) {
1960 loopargs[i].hctx = HMAC_CTX_new();
1961 if (loopargs[i].hctx == NULL) {
1962 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1966 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1967 16, EVP_md5(), NULL);
1969 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1970 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1972 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1974 print_result(D_HMAC, testnum, count, d);
1976 for (i = 0; i < loopargs_len; i++) {
1977 HMAC_CTX_free(loopargs[i].hctx);
1982 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1983 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1985 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1987 print_result(D_SHA1, testnum, count, d);
1990 if (doit[D_SHA256]) {
1991 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1992 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1994 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1996 print_result(D_SHA256, testnum, count, d);
1999 if (doit[D_SHA512]) {
2000 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2001 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
2003 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2005 print_result(D_SHA512, testnum, count, d);
2009 #ifndef OPENSSL_NO_WHIRLPOOL
2010 if (doit[D_WHIRLPOOL]) {
2011 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2012 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
2014 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2016 print_result(D_WHIRLPOOL, testnum, count, d);
2021 #ifndef OPENSSL_NO_RMD160
2022 if (doit[D_RMD160]) {
2023 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2024 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2026 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2028 print_result(D_RMD160, testnum, count, d);
2032 #ifndef OPENSSL_NO_RC4
2034 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2035 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2037 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2039 print_result(D_RC4, testnum, count, d);
2043 #ifndef OPENSSL_NO_DES
2044 if (doit[D_CBC_DES]) {
2045 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2046 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2048 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2050 print_result(D_CBC_DES, testnum, count, d);
2054 if (doit[D_EDE3_DES]) {
2055 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2056 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2058 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2060 print_result(D_EDE3_DES, testnum, count, d);
2064 #ifndef OPENSSL_NO_AES
2065 if (doit[D_CBC_128_AES]) {
2066 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2067 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2070 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2072 print_result(D_CBC_128_AES, testnum, count, d);
2075 if (doit[D_CBC_192_AES]) {
2076 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2077 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2080 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2082 print_result(D_CBC_192_AES, testnum, count, d);
2085 if (doit[D_CBC_256_AES]) {
2086 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2087 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2090 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2092 print_result(D_CBC_256_AES, testnum, count, d);
2096 if (doit[D_IGE_128_AES]) {
2097 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2098 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2101 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2103 print_result(D_IGE_128_AES, testnum, count, d);
2106 if (doit[D_IGE_192_AES]) {
2107 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2108 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2111 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2113 print_result(D_IGE_192_AES, testnum, count, d);
2116 if (doit[D_IGE_256_AES]) {
2117 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2118 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2121 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2123 print_result(D_IGE_256_AES, testnum, count, d);
2126 if (doit[D_GHASH]) {
2127 for (i = 0; i < loopargs_len; i++) {
2128 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2129 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2132 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2133 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2135 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2137 print_result(D_GHASH, testnum, count, d);
2139 for (i = 0; i < loopargs_len; i++)
2140 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2143 #ifndef OPENSSL_NO_CAMELLIA
2144 if (doit[D_CBC_128_CML]) {
2145 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2146 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2148 if (async_jobs > 0) {
2149 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2153 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2154 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2155 (unsigned long)lengths[testnum], &camellia_ks1,
2156 iv, CAMELLIA_ENCRYPT);
2158 print_result(D_CBC_128_CML, testnum, count, d);
2161 if (doit[D_CBC_192_CML]) {
2162 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2163 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2165 if (async_jobs > 0) {
2166 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2170 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2171 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2172 (unsigned long)lengths[testnum], &camellia_ks2,
2173 iv, CAMELLIA_ENCRYPT);
2175 print_result(D_CBC_192_CML, testnum, count, d);
2178 if (doit[D_CBC_256_CML]) {
2179 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2180 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2182 if (async_jobs > 0) {
2183 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2187 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2188 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2189 (unsigned long)lengths[testnum], &camellia_ks3,
2190 iv, CAMELLIA_ENCRYPT);
2192 print_result(D_CBC_256_CML, testnum, count, d);
2196 #ifndef OPENSSL_NO_IDEA
2197 if (doit[D_CBC_IDEA]) {
2198 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2199 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[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_IDEA][testnum]); count++)
2206 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2207 (unsigned long)lengths[testnum], &idea_ks,
2210 print_result(D_CBC_IDEA, testnum, count, d);
2214 #ifndef OPENSSL_NO_SEED
2215 if (doit[D_CBC_SEED]) {
2216 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2217 print_message(names[D_CBC_SEED], c[D_CBC_SEED][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_SEED][testnum]); count++)
2224 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2225 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2227 print_result(D_CBC_SEED, testnum, count, d);
2231 #ifndef OPENSSL_NO_RC2
2232 if (doit[D_CBC_RC2]) {
2233 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2234 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2235 if (async_jobs > 0) {
2236 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2240 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2241 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2242 (unsigned long)lengths[testnum], &rc2_ks,
2245 print_result(D_CBC_RC2, testnum, count, d);
2249 #ifndef OPENSSL_NO_RC5
2250 if (doit[D_CBC_RC5]) {
2251 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2252 print_message(names[D_CBC_RC5], c[D_CBC_RC5][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_RC5][testnum]); count++)
2259 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2260 (unsigned long)lengths[testnum], &rc5_ks,
2263 print_result(D_CBC_RC5, testnum, count, d);
2267 #ifndef OPENSSL_NO_BF
2268 if (doit[D_CBC_BF]) {
2269 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2270 print_message(names[D_CBC_BF], c[D_CBC_BF][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_BF][testnum]); count++)
2277 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2278 (unsigned long)lengths[testnum], &bf_ks,
2281 print_result(D_CBC_BF, testnum, count, d);
2285 #ifndef OPENSSL_NO_CAST
2286 if (doit[D_CBC_CAST]) {
2287 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2288 print_message(names[D_CBC_CAST], c[D_CBC_CAST][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_CAST][testnum]); count++)
2295 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2296 (unsigned long)lengths[testnum], &cast_ks,
2299 print_result(D_CBC_CAST, testnum, count, d);
2305 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2306 if (multiblock && evp_cipher) {
2308 (EVP_CIPHER_flags(evp_cipher) &
2309 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2310 BIO_printf(bio_err, "%s is not multi-block capable\n",
2311 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2314 if (async_jobs > 0) {
2315 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2318 multiblock_speed(evp_cipher);
2323 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2326 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2328 * -O3 -fschedule-insns messes up an optimization here!
2329 * names[D_EVP] somehow becomes NULL
2331 print_message(names[D_EVP], save_count, lengths[testnum]);
2333 for (k = 0; k < loopargs_len; k++) {
2334 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2336 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2338 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2339 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2343 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2345 for (k = 0; k < loopargs_len; k++) {
2346 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2350 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2351 print_message(names[D_EVP], save_count, lengths[testnum]);
2353 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2356 print_result(D_EVP, testnum, count, d);
2360 for (i = 0; i < loopargs_len; i++)
2361 RAND_bytes(loopargs[i].buf, 36);
2363 #ifndef OPENSSL_NO_RSA
2364 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2366 if (!rsa_doit[testnum])
2368 for (i = 0; i < loopargs_len; i++) {
2369 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2370 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2376 "RSA sign failure. No RSA sign will be done.\n");
2377 ERR_print_errors(bio_err);
2380 pkey_print_message("private", "rsa",
2381 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2382 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2384 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2387 mr ? "+R1:%ld:%d:%.2f\n"
2388 : "%ld %d bit private RSA's in %.2fs\n",
2389 count, rsa_bits[testnum], d);
2390 rsa_results[testnum][0] = d / (double)count;
2394 for (i = 0; i < loopargs_len; i++) {
2395 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2396 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2402 "RSA verify failure. No RSA verify will be done.\n");
2403 ERR_print_errors(bio_err);
2404 rsa_doit[testnum] = 0;
2406 pkey_print_message("public", "rsa",
2407 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2409 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2412 mr ? "+R2:%ld:%d:%.2f\n"
2413 : "%ld %d bit public RSA's in %.2fs\n",
2414 count, rsa_bits[testnum], d);
2415 rsa_results[testnum][1] = d / (double)count;
2418 if (rsa_count <= 1) {
2419 /* if longer than 10s, don't do any more */
2420 for (testnum++; testnum < RSA_NUM; testnum++)
2421 rsa_doit[testnum] = 0;
2426 for (i = 0; i < loopargs_len; i++)
2427 RAND_bytes(loopargs[i].buf, 36);
2429 #ifndef OPENSSL_NO_DSA
2430 if (RAND_status() != 1) {
2431 RAND_seed(rnd_seed, sizeof rnd_seed);
2434 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2436 if (!dsa_doit[testnum])
2439 /* DSA_generate_key(dsa_key[testnum]); */
2440 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2441 for (i = 0; i < loopargs_len; i++) {
2442 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2443 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2449 "DSA sign failure. No DSA sign will be done.\n");
2450 ERR_print_errors(bio_err);
2453 pkey_print_message("sign", "dsa",
2454 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2456 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2459 mr ? "+R3:%ld:%d:%.2f\n"
2460 : "%ld %d bit DSA signs in %.2fs\n",
2461 count, dsa_bits[testnum], d);
2462 dsa_results[testnum][0] = d / (double)count;
2466 for (i = 0; i < loopargs_len; i++) {
2467 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2468 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2474 "DSA verify failure. No DSA verify will be done.\n");
2475 ERR_print_errors(bio_err);
2476 dsa_doit[testnum] = 0;
2478 pkey_print_message("verify", "dsa",
2479 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2481 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2484 mr ? "+R4:%ld:%d:%.2f\n"
2485 : "%ld %d bit DSA verify in %.2fs\n",
2486 count, dsa_bits[testnum], d);
2487 dsa_results[testnum][1] = d / (double)count;
2490 if (rsa_count <= 1) {
2491 /* if longer than 10s, don't do any more */
2492 for (testnum++; testnum < DSA_NUM; testnum++)
2493 dsa_doit[testnum] = 0;
2500 #ifndef OPENSSL_NO_EC
2501 if (RAND_status() != 1) {
2502 RAND_seed(rnd_seed, sizeof rnd_seed);
2505 for (testnum = 0; testnum < EC_NUM; testnum++) {
2508 if (!ecdsa_doit[testnum])
2509 continue; /* Ignore Curve */
2510 for (i = 0; i < loopargs_len; i++) {
2511 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2512 if (loopargs[i].ecdsa[testnum] == NULL) {
2518 BIO_printf(bio_err, "ECDSA failure.\n");
2519 ERR_print_errors(bio_err);
2522 for (i = 0; i < loopargs_len; i++) {
2523 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2524 /* Perform ECDSA signature test */
2525 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2526 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2527 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2533 "ECDSA sign failure. No ECDSA sign will be done.\n");
2534 ERR_print_errors(bio_err);
2537 pkey_print_message("sign", "ecdsa",
2538 ecdsa_c[testnum][0],
2539 test_curves_bits[testnum], ECDSA_SECONDS);
2541 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2545 mr ? "+R5:%ld:%d:%.2f\n" :
2546 "%ld %d bit ECDSA signs in %.2fs \n",
2547 count, test_curves_bits[testnum], d);
2548 ecdsa_results[testnum][0] = d / (double)count;
2552 /* Perform ECDSA verification test */
2553 for (i = 0; i < loopargs_len; i++) {
2554 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2555 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2561 "ECDSA verify failure. No ECDSA verify will be done.\n");
2562 ERR_print_errors(bio_err);
2563 ecdsa_doit[testnum] = 0;
2565 pkey_print_message("verify", "ecdsa",
2566 ecdsa_c[testnum][1],
2567 test_curves_bits[testnum], ECDSA_SECONDS);
2569 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2572 mr ? "+R6:%ld:%d:%.2f\n"
2573 : "%ld %d bit ECDSA verify in %.2fs\n",
2574 count, test_curves_bits[testnum], d);
2575 ecdsa_results[testnum][1] = d / (double)count;
2578 if (rsa_count <= 1) {
2579 /* if longer than 10s, don't do any more */
2580 for (testnum++; testnum < EC_NUM; testnum++)
2581 ecdsa_doit[testnum] = 0;
2589 #ifndef OPENSSL_NO_EC
2590 if (RAND_status() != 1) {
2591 RAND_seed(rnd_seed, sizeof rnd_seed);
2594 for (testnum = 0; testnum < EC_NUM; testnum++) {
2595 if (!ecdh_doit[testnum])
2597 for (i = 0; i < loopargs_len; i++) {
2598 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2599 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2600 if (loopargs[i].ecdh_a[testnum] == NULL ||
2601 loopargs[i].ecdh_b[testnum] == NULL) {
2606 if (ecdh_checks == 0) {
2607 BIO_printf(bio_err, "ECDH failure.\n");
2608 ERR_print_errors(bio_err);
2611 for (i = 0; i < loopargs_len; i++) {
2612 /* generate two ECDH key pairs */
2613 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2614 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2615 BIO_printf(bio_err, "ECDH key generation failure.\n");
2616 ERR_print_errors(bio_err);
2621 * If field size is not more than 24 octets, then use SHA-1
2622 * hash of result; otherwise, use result (see section 4.8 of
2623 * draft-ietf-tls-ecc-03.txt).
2627 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2628 if (field_size <= 24 * 8) {
2629 outlen = KDF1_SHA1_len;
2632 outlen = (field_size + 7) / 8;
2636 ECDH_compute_key(loopargs[i].secret_a, outlen,
2637 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2638 loopargs[i].ecdh_a[testnum], kdf);
2640 ECDH_compute_key(loopargs[i].secret_b, outlen,
2641 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2642 loopargs[i].ecdh_b[testnum], kdf);
2643 if (secret_size_a != secret_size_b)
2648 for (secret_idx = 0; (secret_idx < secret_size_a)
2649 && (ecdh_checks == 1); secret_idx++) {
2650 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2654 if (ecdh_checks == 0) {
2655 BIO_printf(bio_err, "ECDH computations don't match.\n");
2656 ERR_print_errors(bio_err);
2661 if (ecdh_checks != 0) {
2662 pkey_print_message("", "ecdh",
2664 test_curves_bits[testnum], ECDH_SECONDS);
2666 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2669 mr ? "+R7:%ld:%d:%.2f\n" :
2670 "%ld %d-bit ECDH ops in %.2fs\n", count,
2671 test_curves_bits[testnum], d);
2672 ecdh_results[testnum][0] = d / (double)count;
2678 if (rsa_count <= 1) {
2679 /* if longer than 10s, don't do any more */
2680 for (testnum++; testnum < EC_NUM; testnum++)
2681 ecdh_doit[testnum] = 0;
2691 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2692 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2694 printf("%s ", BN_options());
2695 #ifndef OPENSSL_NO_MD2
2696 printf("%s ", MD2_options());
2698 #ifndef OPENSSL_NO_RC4
2699 printf("%s ", RC4_options());
2701 #ifndef OPENSSL_NO_DES
2702 printf("%s ", DES_options());
2704 #ifndef OPENSSL_NO_AES
2705 printf("%s ", AES_options());
2707 #ifndef OPENSSL_NO_IDEA
2708 printf("%s ", idea_options());
2710 #ifndef OPENSSL_NO_BF
2711 printf("%s ", BF_options());
2713 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2721 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2724 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2725 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2729 for (k = 0; k < ALGOR_NUM; k++) {
2733 printf("+F:%d:%s", k, names[k]);
2735 printf("%-13s", names[k]);
2736 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2737 if (results[k][testnum] > 10000 && !mr)
2738 printf(" %11.2fk", results[k][testnum] / 1e3);
2740 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2744 #ifndef OPENSSL_NO_RSA
2746 for (k = 0; k < RSA_NUM; k++) {
2749 if (testnum && !mr) {
2750 printf("%18ssign verify sign/s verify/s\n", " ");
2754 printf("+F2:%u:%u:%f:%f\n",
2755 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2757 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2758 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2759 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2762 #ifndef OPENSSL_NO_DSA
2764 for (k = 0; k < DSA_NUM; k++) {
2767 if (testnum && !mr) {
2768 printf("%18ssign verify sign/s verify/s\n", " ");
2772 printf("+F3:%u:%u:%f:%f\n",
2773 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2775 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2776 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2777 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2780 #ifndef OPENSSL_NO_EC
2782 for (k = 0; k < EC_NUM; k++) {
2785 if (testnum && !mr) {
2786 printf("%30ssign verify sign/s verify/s\n", " ");
2791 printf("+F4:%u:%u:%f:%f\n",
2792 k, test_curves_bits[k],
2793 ecdsa_results[k][0], ecdsa_results[k][1]);
2795 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2796 test_curves_bits[k],
2797 test_curves_names[k],
2798 ecdsa_results[k][0], ecdsa_results[k][1],
2799 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2803 #ifndef OPENSSL_NO_EC
2805 for (k = 0; k < EC_NUM; k++) {
2808 if (testnum && !mr) {
2809 printf("%30sop op/s\n", " ");
2813 printf("+F5:%u:%u:%f:%f\n",
2814 k, test_curves_bits[k],
2815 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2818 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2819 test_curves_bits[k],
2820 test_curves_names[k],
2821 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2828 ERR_print_errors(bio_err);
2829 for (i = 0; i < loopargs_len; i++) {
2830 OPENSSL_free(loopargs[i].buf_malloc);
2831 OPENSSL_free(loopargs[i].buf2_malloc);
2832 OPENSSL_free(loopargs[i].siglen);
2834 #ifndef OPENSSL_NO_RSA
2835 for (i = 0; i < loopargs_len; i++) {
2836 for (k = 0; k < RSA_NUM; k++)
2837 RSA_free(loopargs[i].rsa_key[k]);
2840 #ifndef OPENSSL_NO_DSA
2841 for (i = 0; i < loopargs_len; i++) {
2842 for (k = 0; k < DSA_NUM; k++)
2843 DSA_free(loopargs[i].dsa_key[k]);
2847 #ifndef OPENSSL_NO_EC
2848 for (i = 0; i < loopargs_len; i++) {
2849 for (k = 0; k < EC_NUM; k++) {
2850 EC_KEY_free(loopargs[i].ecdsa[k]);
2851 EC_KEY_free(loopargs[i].ecdh_a[k]);
2852 EC_KEY_free(loopargs[i].ecdh_b[k]);
2854 OPENSSL_free(loopargs[i].secret_a);
2855 OPENSSL_free(loopargs[i].secret_b);
2858 if (async_jobs > 0) {
2859 for (i = 0; i < loopargs_len; i++)
2860 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2862 ASYNC_cleanup_thread();
2864 OPENSSL_free(loopargs);
2868 static void print_message(const char *s, long num, int length)
2872 mr ? "+DT:%s:%d:%d\n"
2873 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2874 (void)BIO_flush(bio_err);
2878 mr ? "+DN:%s:%ld:%d\n"
2879 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2880 (void)BIO_flush(bio_err);
2884 static void pkey_print_message(const char *str, const char *str2, long num,
2889 mr ? "+DTP:%d:%s:%s:%d\n"
2890 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2891 (void)BIO_flush(bio_err);
2895 mr ? "+DNP:%ld:%d:%s:%s\n"
2896 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2897 (void)BIO_flush(bio_err);
2901 static void print_result(int alg, int run_no, int count, double time_used)
2904 mr ? "+R:%d:%s:%f\n"
2905 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2906 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2910 static char *sstrsep(char **string, const char *delim)
2913 char *token = *string;
2918 memset(isdelim, 0, sizeof isdelim);
2922 isdelim[(unsigned char)(*delim)] = 1;
2926 while (!isdelim[(unsigned char)(**string)]) {
2938 static int do_multi(int multi)
2943 static char sep[] = ":";
2945 fds = malloc(sizeof(*fds) * multi);
2946 for (n = 0; n < multi; ++n) {
2947 if (pipe(fd) == -1) {
2948 BIO_printf(bio_err, "pipe failure\n");
2952 (void)BIO_flush(bio_err);
2959 if (dup(fd[1]) == -1) {
2960 BIO_printf(bio_err, "dup failed\n");
2969 printf("Forked child %d\n", n);
2972 /* for now, assume the pipe is long enough to take all the output */
2973 for (n = 0; n < multi; ++n) {
2978 f = fdopen(fds[n], "r");
2979 while (fgets(buf, sizeof buf, f)) {
2980 p = strchr(buf, '\n');
2983 if (buf[0] != '+') {
2984 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2988 printf("Got: %s from %d\n", buf, n);
2989 if (strncmp(buf, "+F:", 3) == 0) {
2994 alg = atoi(sstrsep(&p, sep));
2996 for (j = 0; j < SIZE_NUM; ++j)
2997 results[alg][j] += atof(sstrsep(&p, sep));
2998 } else if (strncmp(buf, "+F2:", 4) == 0) {
3003 k = atoi(sstrsep(&p, sep));
3006 d = atof(sstrsep(&p, sep));
3008 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
3010 rsa_results[k][0] = d;
3012 d = atof(sstrsep(&p, sep));
3014 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3016 rsa_results[k][1] = d;
3018 # ifndef OPENSSL_NO_DSA
3019 else if (strncmp(buf, "+F3:", 4) == 0) {
3024 k = atoi(sstrsep(&p, sep));
3027 d = atof(sstrsep(&p, sep));
3029 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3031 dsa_results[k][0] = d;
3033 d = atof(sstrsep(&p, sep));
3035 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3037 dsa_results[k][1] = d;
3040 # ifndef OPENSSL_NO_EC
3041 else if (strncmp(buf, "+F4:", 4) == 0) {
3046 k = atoi(sstrsep(&p, sep));
3049 d = atof(sstrsep(&p, sep));
3051 ecdsa_results[k][0] =
3052 1 / (1 / ecdsa_results[k][0] + 1 / d);
3054 ecdsa_results[k][0] = d;
3056 d = atof(sstrsep(&p, sep));
3058 ecdsa_results[k][1] =
3059 1 / (1 / ecdsa_results[k][1] + 1 / d);
3061 ecdsa_results[k][1] = d;
3065 # ifndef OPENSSL_NO_EC
3066 else if (strncmp(buf, "+F5:", 4) == 0) {
3071 k = atoi(sstrsep(&p, sep));
3074 d = atof(sstrsep(&p, sep));
3076 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3078 ecdh_results[k][0] = d;
3083 else if (strncmp(buf, "+H:", 3) == 0) {
3086 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3096 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3098 static int mblengths[] =
3099 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3100 int j, count, num = OSSL_NELEM(mblengths);
3101 const char *alg_name;
3102 unsigned char *inp, *out, no_key[32], no_iv[16];
3103 EVP_CIPHER_CTX *ctx;
3106 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3107 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3108 ctx = EVP_CIPHER_CTX_new();
3109 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3110 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3112 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3114 for (j = 0; j < num; j++) {
3115 print_message(alg_name, 0, mblengths[j]);
3117 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3118 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3119 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3120 size_t len = mblengths[j];
3123 memset(aad, 0, 8); /* avoid uninitialized values */
3124 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3125 aad[9] = 3; /* version */
3127 aad[11] = 0; /* length */
3129 mb_param.out = NULL;
3132 mb_param.interleave = 8;
3134 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3135 sizeof(mb_param), &mb_param);
3141 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3142 sizeof(mb_param), &mb_param);
3146 RAND_bytes(out, 16);
3150 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3151 EVP_AEAD_TLS1_AAD_LEN, aad);
3152 EVP_Cipher(ctx, out, inp, len + pad);
3156 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3157 : "%d %s's in %.2fs\n", count, "evp", d);
3158 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3162 fprintf(stdout, "+H");
3163 for (j = 0; j < num; j++)
3164 fprintf(stdout, ":%d", mblengths[j]);
3165 fprintf(stdout, "\n");
3166 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3167 for (j = 0; j < num; j++)
3168 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3169 fprintf(stdout, "\n");
3172 "The 'numbers' are in 1000s of bytes per second processed.\n");
3173 fprintf(stdout, "type ");
3174 for (j = 0; j < num; j++)
3175 fprintf(stdout, "%7d bytes", mblengths[j]);
3176 fprintf(stdout, "\n");
3177 fprintf(stdout, "%-24s", alg_name);
3179 for (j = 0; j < num; j++) {
3180 if (results[D_EVP][j] > 10000)
3181 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3183 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3185 fprintf(stdout, "\n");
3190 EVP_CIPHER_CTX_free(ctx);