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 memset(DES_iv, 0, sizeof(DES_iv));
1390 memset(iv, 0, sizeof(iv));
1392 for (i = 0; i < ALGOR_NUM; i++)
1394 for (i = 0; i < RSA_NUM; i++)
1396 for (i = 0; i < DSA_NUM; i++)
1398 #ifndef OPENSSL_NO_EC
1399 for (i = 0; i < EC_NUM; i++)
1401 for (i = 0; i < EC_NUM; i++)
1407 prog = opt_init(argc, argv, speed_options);
1408 while ((o = opt_next()) != OPT_EOF) {
1413 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1416 opt_help(speed_options);
1423 evp_cipher = EVP_get_cipherbyname(opt_arg());
1424 if (evp_cipher == NULL)
1425 evp_md = EVP_get_digestbyname(opt_arg());
1426 if (evp_cipher == NULL && evp_md == NULL) {
1428 "%s: %s an unknown cipher or digest\n",
1439 * In a forked execution, an engine might need to be
1440 * initialised by each child process, not by the parent.
1441 * So store the name here and run setup_engine() later on.
1443 engine_id = opt_arg();
1447 multi = atoi(opt_arg());
1451 #ifndef OPENSSL_NO_ASYNC
1452 async_jobs = atoi(opt_arg());
1453 if (!ASYNC_is_capable()) {
1455 "%s: async_jobs specified but async not supported\n",
1462 if (!opt_int(opt_arg(), &misalign))
1464 if (misalign > MISALIGN) {
1466 "%s: Maximum offset is %d\n", prog, MISALIGN);
1478 argc = opt_num_rest();
1481 /* Remaining arguments are algorithms. */
1482 for ( ; *argv; argv++) {
1483 if (found(*argv, doit_choices, &i)) {
1487 #ifndef OPENSSL_NO_DES
1488 if (strcmp(*argv, "des") == 0) {
1489 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1493 if (strcmp(*argv, "sha") == 0) {
1494 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1497 #ifndef OPENSSL_NO_RSA
1499 if (strcmp(*argv, "openssl") == 0) {
1500 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1504 if (strcmp(*argv, "rsa") == 0) {
1505 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1506 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1507 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1508 rsa_doit[R_RSA_15360] = 1;
1511 if (found(*argv, rsa_choices, &i)) {
1516 #ifndef OPENSSL_NO_DSA
1517 if (strcmp(*argv, "dsa") == 0) {
1518 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1519 dsa_doit[R_DSA_2048] = 1;
1522 if (found(*argv, dsa_choices, &i)) {
1527 #ifndef OPENSSL_NO_AES
1528 if (strcmp(*argv, "aes") == 0) {
1529 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1530 doit[D_CBC_256_AES] = 1;
1534 #ifndef OPENSSL_NO_CAMELLIA
1535 if (strcmp(*argv, "camellia") == 0) {
1536 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1537 doit[D_CBC_256_CML] = 1;
1541 #ifndef OPENSSL_NO_EC
1542 if (strcmp(*argv, "ecdsa") == 0) {
1543 for (i = 0; i < EC_NUM; i++)
1547 if (found(*argv, ecdsa_choices, &i)) {
1551 if (strcmp(*argv, "ecdh") == 0) {
1552 for (i = 0; i < EC_NUM; i++)
1556 if (found(*argv, ecdh_choices, &i)) {
1561 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1565 /* Initialize the job pool if async mode is enabled */
1566 if (async_jobs > 0) {
1567 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1568 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1573 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1574 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1575 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1577 for (i = 0; i < loopargs_len; i++) {
1578 if (async_jobs > 0) {
1579 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1580 if (loopargs[i].wait_ctx == NULL) {
1581 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1586 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1587 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1588 /* Align the start of buffers on a 64 byte boundary */
1589 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1590 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1591 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1592 #ifndef OPENSSL_NO_EC
1593 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1594 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1599 if (multi && do_multi(multi))
1603 /* Initialize the engine after the fork */
1604 (void)setup_engine(engine_id, 0);
1606 /* No parameters; turn on everything. */
1607 if ((argc == 0) && !doit[D_EVP]) {
1608 for (i = 0; i < ALGOR_NUM; i++)
1611 for (i = 0; i < RSA_NUM; i++)
1613 for (i = 0; i < DSA_NUM; i++)
1615 #ifndef OPENSSL_NO_EC
1616 for (i = 0; i < EC_NUM; i++)
1618 for (i = 0; i < EC_NUM; i++)
1622 for (i = 0; i < ALGOR_NUM; i++)
1626 if (usertime == 0 && !mr)
1628 "You have chosen to measure elapsed time "
1629 "instead of user CPU time.\n");
1631 #ifndef OPENSSL_NO_RSA
1632 for (i = 0; i < loopargs_len; i++) {
1633 for (k = 0; k < RSA_NUM; k++) {
1634 const unsigned char *p;
1637 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1638 if (loopargs[i].rsa_key[k] == NULL) {
1639 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1646 #ifndef OPENSSL_NO_DSA
1647 for (i = 0; i < loopargs_len; i++) {
1648 loopargs[i].dsa_key[0] = get_dsa512();
1649 loopargs[i].dsa_key[1] = get_dsa1024();
1650 loopargs[i].dsa_key[2] = get_dsa2048();
1653 #ifndef OPENSSL_NO_DES
1654 DES_set_key_unchecked(&key, &sch);
1655 DES_set_key_unchecked(&key2, &sch2);
1656 DES_set_key_unchecked(&key3, &sch3);
1658 #ifndef OPENSSL_NO_AES
1659 AES_set_encrypt_key(key16, 128, &aes_ks1);
1660 AES_set_encrypt_key(key24, 192, &aes_ks2);
1661 AES_set_encrypt_key(key32, 256, &aes_ks3);
1663 #ifndef OPENSSL_NO_CAMELLIA
1664 Camellia_set_key(key16, 128, &camellia_ks1);
1665 Camellia_set_key(ckey24, 192, &camellia_ks2);
1666 Camellia_set_key(ckey32, 256, &camellia_ks3);
1668 #ifndef OPENSSL_NO_IDEA
1669 idea_set_encrypt_key(key16, &idea_ks);
1671 #ifndef OPENSSL_NO_SEED
1672 SEED_set_key(key16, &seed_ks);
1674 #ifndef OPENSSL_NO_RC4
1675 RC4_set_key(&rc4_ks, 16, key16);
1677 #ifndef OPENSSL_NO_RC2
1678 RC2_set_key(&rc2_ks, 16, key16, 128);
1680 #ifndef OPENSSL_NO_RC5
1681 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1683 #ifndef OPENSSL_NO_BF
1684 BF_set_key(&bf_ks, 16, key16);
1686 #ifndef OPENSSL_NO_CAST
1687 CAST_set_key(&cast_ks, 16, key16);
1689 #ifndef OPENSSL_NO_RSA
1690 memset(rsa_c, 0, sizeof(rsa_c));
1693 # ifndef OPENSSL_NO_DES
1694 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1700 for (it = count; it; it--)
1701 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1702 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1706 c[D_MD2][0] = count / 10;
1707 c[D_MDC2][0] = count / 10;
1708 c[D_MD4][0] = count;
1709 c[D_MD5][0] = count;
1710 c[D_HMAC][0] = count;
1711 c[D_SHA1][0] = count;
1712 c[D_RMD160][0] = count;
1713 c[D_RC4][0] = count * 5;
1714 c[D_CBC_DES][0] = count;
1715 c[D_EDE3_DES][0] = count / 3;
1716 c[D_CBC_IDEA][0] = count;
1717 c[D_CBC_SEED][0] = count;
1718 c[D_CBC_RC2][0] = count;
1719 c[D_CBC_RC5][0] = count;
1720 c[D_CBC_BF][0] = count;
1721 c[D_CBC_CAST][0] = count;
1722 c[D_CBC_128_AES][0] = count;
1723 c[D_CBC_192_AES][0] = count;
1724 c[D_CBC_256_AES][0] = count;
1725 c[D_CBC_128_CML][0] = count;
1726 c[D_CBC_192_CML][0] = count;
1727 c[D_CBC_256_CML][0] = count;
1728 c[D_SHA256][0] = count;
1729 c[D_SHA512][0] = count;
1730 c[D_WHIRLPOOL][0] = count;
1731 c[D_IGE_128_AES][0] = count;
1732 c[D_IGE_192_AES][0] = count;
1733 c[D_IGE_256_AES][0] = count;
1734 c[D_GHASH][0] = count;
1736 for (i = 1; i < SIZE_NUM; i++) {
1739 l0 = (long)lengths[0];
1740 l1 = (long)lengths[i];
1742 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1743 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1744 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1745 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1746 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1747 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1748 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1749 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1750 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1751 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1752 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1754 l0 = (long)lengths[i - 1];
1756 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1757 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1758 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1759 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1760 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1761 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1762 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1763 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1764 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1765 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1766 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1767 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1768 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1769 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1770 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1771 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1772 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1773 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1776 # ifndef OPENSSL_NO_RSA
1777 rsa_c[R_RSA_512][0] = count / 2000;
1778 rsa_c[R_RSA_512][1] = count / 400;
1779 for (i = 1; i < RSA_NUM; i++) {
1780 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1781 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1782 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1785 if (rsa_c[i][0] == 0) {
1793 # ifndef OPENSSL_NO_DSA
1794 dsa_c[R_DSA_512][0] = count / 1000;
1795 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1796 for (i = 1; i < DSA_NUM; i++) {
1797 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1798 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1799 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1802 if (dsa_c[i] == 0) {
1810 # ifndef OPENSSL_NO_EC
1811 ecdsa_c[R_EC_P160][0] = count / 1000;
1812 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1813 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1814 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1815 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1816 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1819 if (ecdsa_c[i] == 0) {
1825 ecdsa_c[R_EC_K163][0] = count / 1000;
1826 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1827 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1828 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1829 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1830 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1833 if (ecdsa_c[i] == 0) {
1839 ecdsa_c[R_EC_B163][0] = count / 1000;
1840 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1841 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1842 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1843 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1844 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1847 if (ecdsa_c[i] == 0) {
1854 ecdh_c[R_EC_P160][0] = count / 1000;
1855 ecdh_c[R_EC_P160][1] = count / 1000;
1856 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1857 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1858 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1859 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1862 if (ecdh_c[i] == 0) {
1868 ecdh_c[R_EC_K163][0] = count / 1000;
1869 ecdh_c[R_EC_K163][1] = count / 1000;
1870 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1871 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1872 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1873 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1876 if (ecdh_c[i] == 0) {
1882 ecdh_c[R_EC_B163][0] = count / 1000;
1883 ecdh_c[R_EC_B163][1] = count / 1000;
1884 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1885 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1886 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1887 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1890 if (ecdh_c[i] == 0) {
1899 /* not worth fixing */
1900 # error "You cannot disable DES on systems without SIGALRM."
1901 # endif /* OPENSSL_NO_DES */
1904 signal(SIGALRM, sig_done);
1906 #endif /* SIGALRM */
1908 #ifndef OPENSSL_NO_MD2
1910 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1911 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1913 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1915 print_result(D_MD2, testnum, count, d);
1919 #ifndef OPENSSL_NO_MDC2
1921 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1922 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1924 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1926 print_result(D_MDC2, testnum, count, d);
1931 #ifndef OPENSSL_NO_MD4
1933 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1934 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1936 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1938 print_result(D_MD4, testnum, count, d);
1943 #ifndef OPENSSL_NO_MD5
1945 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1946 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1948 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1950 print_result(D_MD5, testnum, count, d);
1955 #ifndef OPENSSL_NO_MD5
1957 for (i = 0; i < loopargs_len; i++) {
1958 loopargs[i].hctx = HMAC_CTX_new();
1959 if (loopargs[i].hctx == NULL) {
1960 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1964 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1965 16, EVP_md5(), NULL);
1967 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1968 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1970 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1972 print_result(D_HMAC, testnum, count, d);
1974 for (i = 0; i < loopargs_len; i++) {
1975 HMAC_CTX_free(loopargs[i].hctx);
1980 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1981 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1983 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1985 print_result(D_SHA1, testnum, count, d);
1988 if (doit[D_SHA256]) {
1989 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1990 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1992 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1994 print_result(D_SHA256, testnum, count, d);
1997 if (doit[D_SHA512]) {
1998 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1999 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
2001 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2003 print_result(D_SHA512, testnum, count, d);
2007 #ifndef OPENSSL_NO_WHIRLPOOL
2008 if (doit[D_WHIRLPOOL]) {
2009 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2010 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
2012 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2014 print_result(D_WHIRLPOOL, testnum, count, d);
2019 #ifndef OPENSSL_NO_RMD160
2020 if (doit[D_RMD160]) {
2021 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2022 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2024 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2026 print_result(D_RMD160, testnum, count, d);
2030 #ifndef OPENSSL_NO_RC4
2032 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2033 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2035 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2037 print_result(D_RC4, testnum, count, d);
2041 #ifndef OPENSSL_NO_DES
2042 if (doit[D_CBC_DES]) {
2043 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2044 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2046 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2048 print_result(D_CBC_DES, testnum, count, d);
2052 if (doit[D_EDE3_DES]) {
2053 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2054 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2056 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2058 print_result(D_EDE3_DES, testnum, count, d);
2062 #ifndef OPENSSL_NO_AES
2063 if (doit[D_CBC_128_AES]) {
2064 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2065 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2068 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2070 print_result(D_CBC_128_AES, testnum, count, d);
2073 if (doit[D_CBC_192_AES]) {
2074 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2075 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2078 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2080 print_result(D_CBC_192_AES, testnum, count, d);
2083 if (doit[D_CBC_256_AES]) {
2084 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2085 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2088 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2090 print_result(D_CBC_256_AES, testnum, count, d);
2094 if (doit[D_IGE_128_AES]) {
2095 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2096 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2099 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2101 print_result(D_IGE_128_AES, testnum, count, d);
2104 if (doit[D_IGE_192_AES]) {
2105 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2106 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2109 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2111 print_result(D_IGE_192_AES, testnum, count, d);
2114 if (doit[D_IGE_256_AES]) {
2115 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2116 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2119 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2121 print_result(D_IGE_256_AES, testnum, count, d);
2124 if (doit[D_GHASH]) {
2125 for (i = 0; i < loopargs_len; i++) {
2126 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2127 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2130 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2131 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2133 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2135 print_result(D_GHASH, testnum, count, d);
2137 for (i = 0; i < loopargs_len; i++)
2138 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2141 #ifndef OPENSSL_NO_CAMELLIA
2142 if (doit[D_CBC_128_CML]) {
2143 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2144 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2146 if (async_jobs > 0) {
2147 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2151 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2152 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2153 (unsigned long)lengths[testnum], &camellia_ks1,
2154 iv, CAMELLIA_ENCRYPT);
2156 print_result(D_CBC_128_CML, testnum, count, d);
2159 if (doit[D_CBC_192_CML]) {
2160 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2161 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2163 if (async_jobs > 0) {
2164 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2168 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2169 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2170 (unsigned long)lengths[testnum], &camellia_ks2,
2171 iv, CAMELLIA_ENCRYPT);
2173 print_result(D_CBC_192_CML, testnum, count, d);
2176 if (doit[D_CBC_256_CML]) {
2177 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2178 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2180 if (async_jobs > 0) {
2181 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2185 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2186 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2187 (unsigned long)lengths[testnum], &camellia_ks3,
2188 iv, CAMELLIA_ENCRYPT);
2190 print_result(D_CBC_256_CML, testnum, count, d);
2194 #ifndef OPENSSL_NO_IDEA
2195 if (doit[D_CBC_IDEA]) {
2196 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2197 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2198 if (async_jobs > 0) {
2199 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2203 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2204 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2205 (unsigned long)lengths[testnum], &idea_ks,
2208 print_result(D_CBC_IDEA, testnum, count, d);
2212 #ifndef OPENSSL_NO_SEED
2213 if (doit[D_CBC_SEED]) {
2214 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2215 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2216 if (async_jobs > 0) {
2217 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2221 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2222 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2223 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2225 print_result(D_CBC_SEED, testnum, count, d);
2229 #ifndef OPENSSL_NO_RC2
2230 if (doit[D_CBC_RC2]) {
2231 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2232 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2233 if (async_jobs > 0) {
2234 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2238 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2239 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2240 (unsigned long)lengths[testnum], &rc2_ks,
2243 print_result(D_CBC_RC2, testnum, count, d);
2247 #ifndef OPENSSL_NO_RC5
2248 if (doit[D_CBC_RC5]) {
2249 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2250 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2251 if (async_jobs > 0) {
2252 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2256 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2257 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2258 (unsigned long)lengths[testnum], &rc5_ks,
2261 print_result(D_CBC_RC5, testnum, count, d);
2265 #ifndef OPENSSL_NO_BF
2266 if (doit[D_CBC_BF]) {
2267 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2268 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2269 if (async_jobs > 0) {
2270 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2274 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2275 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2276 (unsigned long)lengths[testnum], &bf_ks,
2279 print_result(D_CBC_BF, testnum, count, d);
2283 #ifndef OPENSSL_NO_CAST
2284 if (doit[D_CBC_CAST]) {
2285 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2286 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2287 if (async_jobs > 0) {
2288 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2292 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2293 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2294 (unsigned long)lengths[testnum], &cast_ks,
2297 print_result(D_CBC_CAST, testnum, count, d);
2303 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2304 if (multiblock && evp_cipher) {
2306 (EVP_CIPHER_flags(evp_cipher) &
2307 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2308 BIO_printf(bio_err, "%s is not multi-block capable\n",
2309 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2312 if (async_jobs > 0) {
2313 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2316 multiblock_speed(evp_cipher);
2321 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2324 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2326 * -O3 -fschedule-insns messes up an optimization here!
2327 * names[D_EVP] somehow becomes NULL
2329 print_message(names[D_EVP], save_count, lengths[testnum]);
2331 for (k = 0; k < loopargs_len; k++) {
2332 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2334 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2336 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2337 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2341 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2343 for (k = 0; k < loopargs_len; k++) {
2344 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2348 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2349 print_message(names[D_EVP], save_count, lengths[testnum]);
2351 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2354 print_result(D_EVP, testnum, count, d);
2358 for (i = 0; i < loopargs_len; i++)
2359 RAND_bytes(loopargs[i].buf, 36);
2361 #ifndef OPENSSL_NO_RSA
2362 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2364 if (!rsa_doit[testnum])
2366 for (i = 0; i < loopargs_len; i++) {
2367 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2368 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2374 "RSA sign failure. No RSA sign will be done.\n");
2375 ERR_print_errors(bio_err);
2378 pkey_print_message("private", "rsa",
2379 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2380 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2382 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2385 mr ? "+R1:%ld:%d:%.2f\n"
2386 : "%ld %d bit private RSA's in %.2fs\n",
2387 count, rsa_bits[testnum], d);
2388 rsa_results[testnum][0] = d / (double)count;
2392 for (i = 0; i < loopargs_len; i++) {
2393 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2394 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2400 "RSA verify failure. No RSA verify will be done.\n");
2401 ERR_print_errors(bio_err);
2402 rsa_doit[testnum] = 0;
2404 pkey_print_message("public", "rsa",
2405 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2407 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2410 mr ? "+R2:%ld:%d:%.2f\n"
2411 : "%ld %d bit public RSA's in %.2fs\n",
2412 count, rsa_bits[testnum], d);
2413 rsa_results[testnum][1] = d / (double)count;
2416 if (rsa_count <= 1) {
2417 /* if longer than 10s, don't do any more */
2418 for (testnum++; testnum < RSA_NUM; testnum++)
2419 rsa_doit[testnum] = 0;
2424 for (i = 0; i < loopargs_len; i++)
2425 RAND_bytes(loopargs[i].buf, 36);
2427 #ifndef OPENSSL_NO_DSA
2428 if (RAND_status() != 1) {
2429 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;
2498 #ifndef OPENSSL_NO_EC
2499 if (RAND_status() != 1) {
2500 RAND_seed(rnd_seed, sizeof rnd_seed);
2503 for (testnum = 0; testnum < EC_NUM; testnum++) {
2506 if (!ecdsa_doit[testnum])
2507 continue; /* Ignore Curve */
2508 for (i = 0; i < loopargs_len; i++) {
2509 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2510 if (loopargs[i].ecdsa[testnum] == NULL) {
2516 BIO_printf(bio_err, "ECDSA failure.\n");
2517 ERR_print_errors(bio_err);
2520 for (i = 0; i < loopargs_len; i++) {
2521 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2522 /* Perform ECDSA signature test */
2523 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2524 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2525 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2531 "ECDSA sign failure. No ECDSA sign will be done.\n");
2532 ERR_print_errors(bio_err);
2535 pkey_print_message("sign", "ecdsa",
2536 ecdsa_c[testnum][0],
2537 test_curves_bits[testnum], ECDSA_SECONDS);
2539 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2543 mr ? "+R5:%ld:%d:%.2f\n" :
2544 "%ld %d bit ECDSA signs in %.2fs \n",
2545 count, test_curves_bits[testnum], d);
2546 ecdsa_results[testnum][0] = d / (double)count;
2550 /* Perform ECDSA verification test */
2551 for (i = 0; i < loopargs_len; i++) {
2552 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2553 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2559 "ECDSA verify failure. No ECDSA verify will be done.\n");
2560 ERR_print_errors(bio_err);
2561 ecdsa_doit[testnum] = 0;
2563 pkey_print_message("verify", "ecdsa",
2564 ecdsa_c[testnum][1],
2565 test_curves_bits[testnum], ECDSA_SECONDS);
2567 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2570 mr ? "+R6:%ld:%d:%.2f\n"
2571 : "%ld %d bit ECDSA verify in %.2fs\n",
2572 count, test_curves_bits[testnum], d);
2573 ecdsa_results[testnum][1] = d / (double)count;
2576 if (rsa_count <= 1) {
2577 /* if longer than 10s, don't do any more */
2578 for (testnum++; testnum < EC_NUM; testnum++)
2579 ecdsa_doit[testnum] = 0;
2587 #ifndef OPENSSL_NO_EC
2588 if (RAND_status() != 1) {
2589 RAND_seed(rnd_seed, sizeof rnd_seed);
2592 for (testnum = 0; testnum < EC_NUM; testnum++) {
2593 if (!ecdh_doit[testnum])
2595 for (i = 0; i < loopargs_len; i++) {
2596 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2597 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2598 if (loopargs[i].ecdh_a[testnum] == NULL ||
2599 loopargs[i].ecdh_b[testnum] == NULL) {
2604 if (ecdh_checks == 0) {
2605 BIO_printf(bio_err, "ECDH failure.\n");
2606 ERR_print_errors(bio_err);
2609 for (i = 0; i < loopargs_len; i++) {
2610 /* generate two ECDH key pairs */
2611 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2612 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2613 BIO_printf(bio_err, "ECDH key generation failure.\n");
2614 ERR_print_errors(bio_err);
2619 * If field size is not more than 24 octets, then use SHA-1
2620 * hash of result; otherwise, use result (see section 4.8 of
2621 * draft-ietf-tls-ecc-03.txt).
2625 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2626 if (field_size <= 24 * 8) {
2627 outlen = KDF1_SHA1_len;
2630 outlen = (field_size + 7) / 8;
2634 ECDH_compute_key(loopargs[i].secret_a, outlen,
2635 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2636 loopargs[i].ecdh_a[testnum], kdf);
2638 ECDH_compute_key(loopargs[i].secret_b, outlen,
2639 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2640 loopargs[i].ecdh_b[testnum], kdf);
2641 if (secret_size_a != secret_size_b)
2646 for (secret_idx = 0; (secret_idx < secret_size_a)
2647 && (ecdh_checks == 1); secret_idx++) {
2648 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2652 if (ecdh_checks == 0) {
2653 BIO_printf(bio_err, "ECDH computations don't match.\n");
2654 ERR_print_errors(bio_err);
2659 if (ecdh_checks != 0) {
2660 pkey_print_message("", "ecdh",
2662 test_curves_bits[testnum], ECDH_SECONDS);
2664 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2667 mr ? "+R7:%ld:%d:%.2f\n" :
2668 "%ld %d-bit ECDH ops in %.2fs\n", count,
2669 test_curves_bits[testnum], d);
2670 ecdh_results[testnum][0] = d / (double)count;
2676 if (rsa_count <= 1) {
2677 /* if longer than 10s, don't do any more */
2678 for (testnum++; testnum < EC_NUM; testnum++)
2679 ecdh_doit[testnum] = 0;
2689 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2690 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2692 printf("%s ", BN_options());
2693 #ifndef OPENSSL_NO_MD2
2694 printf("%s ", MD2_options());
2696 #ifndef OPENSSL_NO_RC4
2697 printf("%s ", RC4_options());
2699 #ifndef OPENSSL_NO_DES
2700 printf("%s ", DES_options());
2702 #ifndef OPENSSL_NO_AES
2703 printf("%s ", AES_options());
2705 #ifndef OPENSSL_NO_IDEA
2706 printf("%s ", idea_options());
2708 #ifndef OPENSSL_NO_BF
2709 printf("%s ", BF_options());
2711 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2719 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2722 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2723 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2727 for (k = 0; k < ALGOR_NUM; k++) {
2731 printf("+F:%d:%s", k, names[k]);
2733 printf("%-13s", names[k]);
2734 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2735 if (results[k][testnum] > 10000 && !mr)
2736 printf(" %11.2fk", results[k][testnum] / 1e3);
2738 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2742 #ifndef OPENSSL_NO_RSA
2744 for (k = 0; k < RSA_NUM; k++) {
2747 if (testnum && !mr) {
2748 printf("%18ssign verify sign/s verify/s\n", " ");
2752 printf("+F2:%u:%u:%f:%f\n",
2753 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2755 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2756 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2757 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2760 #ifndef OPENSSL_NO_DSA
2762 for (k = 0; k < DSA_NUM; k++) {
2765 if (testnum && !mr) {
2766 printf("%18ssign verify sign/s verify/s\n", " ");
2770 printf("+F3:%u:%u:%f:%f\n",
2771 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2773 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2774 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2775 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2778 #ifndef OPENSSL_NO_EC
2780 for (k = 0; k < EC_NUM; k++) {
2783 if (testnum && !mr) {
2784 printf("%30ssign verify sign/s verify/s\n", " ");
2789 printf("+F4:%u:%u:%f:%f\n",
2790 k, test_curves_bits[k],
2791 ecdsa_results[k][0], ecdsa_results[k][1]);
2793 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2794 test_curves_bits[k],
2795 test_curves_names[k],
2796 ecdsa_results[k][0], ecdsa_results[k][1],
2797 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2801 #ifndef OPENSSL_NO_EC
2803 for (k = 0; k < EC_NUM; k++) {
2806 if (testnum && !mr) {
2807 printf("%30sop op/s\n", " ");
2811 printf("+F5:%u:%u:%f:%f\n",
2812 k, test_curves_bits[k],
2813 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2816 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2817 test_curves_bits[k],
2818 test_curves_names[k],
2819 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2826 ERR_print_errors(bio_err);
2827 for (i = 0; i < loopargs_len; i++) {
2828 OPENSSL_free(loopargs[i].buf_malloc);
2829 OPENSSL_free(loopargs[i].buf2_malloc);
2830 OPENSSL_free(loopargs[i].siglen);
2832 #ifndef OPENSSL_NO_RSA
2833 for (i = 0; i < loopargs_len; i++) {
2834 for (k = 0; k < RSA_NUM; k++)
2835 RSA_free(loopargs[i].rsa_key[k]);
2838 #ifndef OPENSSL_NO_DSA
2839 for (i = 0; i < loopargs_len; i++) {
2840 for (k = 0; k < DSA_NUM; k++)
2841 DSA_free(loopargs[i].dsa_key[k]);
2845 #ifndef OPENSSL_NO_EC
2846 for (i = 0; i < loopargs_len; i++) {
2847 for (k = 0; k < EC_NUM; k++) {
2848 EC_KEY_free(loopargs[i].ecdsa[k]);
2849 EC_KEY_free(loopargs[i].ecdh_a[k]);
2850 EC_KEY_free(loopargs[i].ecdh_b[k]);
2852 OPENSSL_free(loopargs[i].secret_a);
2853 OPENSSL_free(loopargs[i].secret_b);
2856 if (async_jobs > 0) {
2857 for (i = 0; i < loopargs_len; i++)
2858 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2860 ASYNC_cleanup_thread();
2862 OPENSSL_free(loopargs);
2866 static void print_message(const char *s, long num, int length)
2870 mr ? "+DT:%s:%d:%d\n"
2871 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2872 (void)BIO_flush(bio_err);
2876 mr ? "+DN:%s:%ld:%d\n"
2877 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2878 (void)BIO_flush(bio_err);
2882 static void pkey_print_message(const char *str, const char *str2, long num,
2887 mr ? "+DTP:%d:%s:%s:%d\n"
2888 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2889 (void)BIO_flush(bio_err);
2893 mr ? "+DNP:%ld:%d:%s:%s\n"
2894 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2895 (void)BIO_flush(bio_err);
2899 static void print_result(int alg, int run_no, int count, double time_used)
2902 mr ? "+R:%d:%s:%f\n"
2903 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2904 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2908 static char *sstrsep(char **string, const char *delim)
2911 char *token = *string;
2916 memset(isdelim, 0, sizeof isdelim);
2920 isdelim[(unsigned char)(*delim)] = 1;
2924 while (!isdelim[(unsigned char)(**string)]) {
2936 static int do_multi(int multi)
2941 static char sep[] = ":";
2943 fds = malloc(sizeof(*fds) * multi);
2944 for (n = 0; n < multi; ++n) {
2945 if (pipe(fd) == -1) {
2946 BIO_printf(bio_err, "pipe failure\n");
2950 (void)BIO_flush(bio_err);
2957 if (dup(fd[1]) == -1) {
2958 BIO_printf(bio_err, "dup failed\n");
2967 printf("Forked child %d\n", n);
2970 /* for now, assume the pipe is long enough to take all the output */
2971 for (n = 0; n < multi; ++n) {
2976 f = fdopen(fds[n], "r");
2977 while (fgets(buf, sizeof buf, f)) {
2978 p = strchr(buf, '\n');
2981 if (buf[0] != '+') {
2982 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2986 printf("Got: %s from %d\n", buf, n);
2987 if (strncmp(buf, "+F:", 3) == 0) {
2992 alg = atoi(sstrsep(&p, sep));
2994 for (j = 0; j < SIZE_NUM; ++j)
2995 results[alg][j] += atof(sstrsep(&p, sep));
2996 } else if (strncmp(buf, "+F2:", 4) == 0) {
3001 k = atoi(sstrsep(&p, sep));
3004 d = atof(sstrsep(&p, sep));
3006 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
3008 rsa_results[k][0] = d;
3010 d = atof(sstrsep(&p, sep));
3012 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3014 rsa_results[k][1] = d;
3016 # ifndef OPENSSL_NO_DSA
3017 else if (strncmp(buf, "+F3:", 4) == 0) {
3022 k = atoi(sstrsep(&p, sep));
3025 d = atof(sstrsep(&p, sep));
3027 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3029 dsa_results[k][0] = d;
3031 d = atof(sstrsep(&p, sep));
3033 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3035 dsa_results[k][1] = d;
3038 # ifndef OPENSSL_NO_EC
3039 else if (strncmp(buf, "+F4:", 4) == 0) {
3044 k = atoi(sstrsep(&p, sep));
3047 d = atof(sstrsep(&p, sep));
3049 ecdsa_results[k][0] =
3050 1 / (1 / ecdsa_results[k][0] + 1 / d);
3052 ecdsa_results[k][0] = d;
3054 d = atof(sstrsep(&p, sep));
3056 ecdsa_results[k][1] =
3057 1 / (1 / ecdsa_results[k][1] + 1 / d);
3059 ecdsa_results[k][1] = d;
3063 # ifndef OPENSSL_NO_EC
3064 else if (strncmp(buf, "+F5:", 4) == 0) {
3069 k = atoi(sstrsep(&p, sep));
3072 d = atof(sstrsep(&p, sep));
3074 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3076 ecdh_results[k][0] = d;
3081 else if (strncmp(buf, "+H:", 3) == 0) {
3084 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3094 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3096 static int mblengths[] =
3097 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3098 int j, count, num = OSSL_NELEM(mblengths);
3099 const char *alg_name;
3100 unsigned char *inp, *out, no_key[32], no_iv[16];
3101 EVP_CIPHER_CTX *ctx;
3104 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3105 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3106 ctx = EVP_CIPHER_CTX_new();
3107 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3108 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3110 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3112 for (j = 0; j < num; j++) {
3113 print_message(alg_name, 0, mblengths[j]);
3115 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3116 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3117 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3118 size_t len = mblengths[j];
3121 memset(aad, 0, 8); /* avoid uninitialized values */
3122 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3123 aad[9] = 3; /* version */
3125 aad[11] = 0; /* length */
3127 mb_param.out = NULL;
3130 mb_param.interleave = 8;
3132 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3133 sizeof(mb_param), &mb_param);
3139 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3140 sizeof(mb_param), &mb_param);
3144 RAND_bytes(out, 16);
3148 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3149 EVP_AEAD_TLS1_AAD_LEN, aad);
3150 EVP_Cipher(ctx, out, inp, len + pad);
3154 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3155 : "%d %s's in %.2fs\n", count, "evp", d);
3156 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3160 fprintf(stdout, "+H");
3161 for (j = 0; j < num; j++)
3162 fprintf(stdout, ":%d", mblengths[j]);
3163 fprintf(stdout, "\n");
3164 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3165 for (j = 0; j < num; j++)
3166 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3167 fprintf(stdout, "\n");
3170 "The 'numbers' are in 1000s of bytes per second processed.\n");
3171 fprintf(stdout, "type ");
3172 for (j = 0; j < num; j++)
3173 fprintf(stdout, "%7d bytes", mblengths[j]);
3174 fprintf(stdout, "\n");
3175 fprintf(stdout, "%-24s", alg_name);
3177 for (j = 0; j < num; j++) {
3178 if (results[D_EVP][j] > 10000)
3179 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3181 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3183 fprintf(stdout, "\n");
3188 EVP_CIPHER_CTX_free(ctx);