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},
550 #ifndef OPENSSL_NO_DSA
552 # define R_DSA_1024 1
553 # define R_DSA_2048 2
554 static OPT_PAIR dsa_choices[] = {
555 {"dsa512", R_DSA_512},
556 {"dsa1024", R_DSA_1024},
557 {"dsa2048", R_DSA_2048},
568 #define R_RSA_15360 6
569 static OPT_PAIR rsa_choices[] = {
570 {"rsa512", R_RSA_512},
571 {"rsa1024", R_RSA_1024},
572 {"rsa2048", R_RSA_2048},
573 {"rsa3072", R_RSA_3072},
574 {"rsa4096", R_RSA_4096},
575 {"rsa7680", R_RSA_7680},
576 {"rsa15360", R_RSA_15360},
596 #define R_EC_X25519 16
597 #ifndef OPENSSL_NO_EC
598 static OPT_PAIR ecdsa_choices[] = {
599 {"ecdsap160", R_EC_P160},
600 {"ecdsap192", R_EC_P192},
601 {"ecdsap224", R_EC_P224},
602 {"ecdsap256", R_EC_P256},
603 {"ecdsap384", R_EC_P384},
604 {"ecdsap521", R_EC_P521},
605 {"ecdsak163", R_EC_K163},
606 {"ecdsak233", R_EC_K233},
607 {"ecdsak283", R_EC_K283},
608 {"ecdsak409", R_EC_K409},
609 {"ecdsak571", R_EC_K571},
610 {"ecdsab163", R_EC_B163},
611 {"ecdsab233", R_EC_B233},
612 {"ecdsab283", R_EC_B283},
613 {"ecdsab409", R_EC_B409},
614 {"ecdsab571", R_EC_B571},
617 static OPT_PAIR ecdh_choices[] = {
618 {"ecdhp160", R_EC_P160},
619 {"ecdhp192", R_EC_P192},
620 {"ecdhp224", R_EC_P224},
621 {"ecdhp256", R_EC_P256},
622 {"ecdhp384", R_EC_P384},
623 {"ecdhp521", R_EC_P521},
624 {"ecdhk163", R_EC_K163},
625 {"ecdhk233", R_EC_K233},
626 {"ecdhk283", R_EC_K283},
627 {"ecdhk409", R_EC_K409},
628 {"ecdhk571", R_EC_K571},
629 {"ecdhb163", R_EC_B163},
630 {"ecdhb233", R_EC_B233},
631 {"ecdhb283", R_EC_B283},
632 {"ecdhb409", R_EC_B409},
633 {"ecdhb571", R_EC_B571},
634 {"ecdhx25519", R_EC_X25519},
640 # define COND(d) (count < (d))
641 # define COUNT(d) (d)
643 # define COND(c) (run && count<0x7fffffff)
644 # define COUNT(d) (count)
648 static char *engine_id = NULL;
651 #ifndef OPENSSL_NO_MD2
652 static int EVP_Digest_MD2_loop(void *args)
654 loopargs_t *tempargs = (loopargs_t *)args;
655 unsigned char *buf = tempargs->buf;
656 unsigned char md2[MD2_DIGEST_LENGTH];
658 for (count = 0; COND(c[D_MD2][testnum]); count++)
659 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
665 #ifndef OPENSSL_NO_MDC2
666 static int EVP_Digest_MDC2_loop(void *args)
668 loopargs_t *tempargs = (loopargs_t *)args;
669 unsigned char *buf = tempargs->buf;
670 unsigned char mdc2[MDC2_DIGEST_LENGTH];
672 for (count = 0; COND(c[D_MDC2][testnum]); count++)
673 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
679 #ifndef OPENSSL_NO_MD4
680 static int EVP_Digest_MD4_loop(void *args)
682 loopargs_t *tempargs = (loopargs_t *)args;
683 unsigned char *buf = tempargs->buf;
684 unsigned char md4[MD4_DIGEST_LENGTH];
686 for (count = 0; COND(c[D_MD4][testnum]); count++)
687 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
688 NULL, EVP_md4(), NULL);
693 #ifndef OPENSSL_NO_MD5
694 static int MD5_loop(void *args)
696 loopargs_t *tempargs = (loopargs_t *)args;
697 unsigned char *buf = tempargs->buf;
698 unsigned char md5[MD5_DIGEST_LENGTH];
700 for (count = 0; COND(c[D_MD5][testnum]); count++)
701 MD5(buf, lengths[testnum], md5);
705 static int HMAC_loop(void *args)
707 loopargs_t *tempargs = (loopargs_t *)args;
708 unsigned char *buf = tempargs->buf;
709 HMAC_CTX *hctx = tempargs->hctx;
710 unsigned char hmac[MD5_DIGEST_LENGTH];
712 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
713 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
714 HMAC_Update(hctx, buf, lengths[testnum]);
715 HMAC_Final(hctx, &(hmac[0]), NULL);
721 static int SHA1_loop(void *args)
723 loopargs_t *tempargs = (loopargs_t *)args;
724 unsigned char *buf = tempargs->buf;
725 unsigned char sha[SHA_DIGEST_LENGTH];
727 for (count = 0; COND(c[D_SHA1][testnum]); count++)
728 SHA1(buf, lengths[testnum], sha);
732 static int SHA256_loop(void *args)
734 loopargs_t *tempargs = (loopargs_t *)args;
735 unsigned char *buf = tempargs->buf;
736 unsigned char sha256[SHA256_DIGEST_LENGTH];
738 for (count = 0; COND(c[D_SHA256][testnum]); count++)
739 SHA256(buf, lengths[testnum], sha256);
743 static int SHA512_loop(void *args)
745 loopargs_t *tempargs = (loopargs_t *)args;
746 unsigned char *buf = tempargs->buf;
747 unsigned char sha512[SHA512_DIGEST_LENGTH];
749 for (count = 0; COND(c[D_SHA512][testnum]); count++)
750 SHA512(buf, lengths[testnum], sha512);
754 #ifndef OPENSSL_NO_WHIRLPOOL
755 static int WHIRLPOOL_loop(void *args)
757 loopargs_t *tempargs = (loopargs_t *)args;
758 unsigned char *buf = tempargs->buf;
759 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
761 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
762 WHIRLPOOL(buf, lengths[testnum], whirlpool);
767 #ifndef OPENSSL_NO_RMD160
768 static int EVP_Digest_RMD160_loop(void *args)
770 loopargs_t *tempargs = (loopargs_t *)args;
771 unsigned char *buf = tempargs->buf;
772 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
774 for (count = 0; COND(c[D_RMD160][testnum]); count++)
775 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
776 EVP_ripemd160(), NULL);
781 #ifndef OPENSSL_NO_RC4
782 static RC4_KEY rc4_ks;
783 static int RC4_loop(void *args)
785 loopargs_t *tempargs = (loopargs_t *)args;
786 unsigned char *buf = tempargs->buf;
788 for (count = 0; COND(c[D_RC4][testnum]); count++)
789 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
794 #ifndef OPENSSL_NO_DES
795 static unsigned char DES_iv[8];
796 static DES_key_schedule sch;
797 static DES_key_schedule sch2;
798 static DES_key_schedule sch3;
799 static int DES_ncbc_encrypt_loop(void *args)
801 loopargs_t *tempargs = (loopargs_t *)args;
802 unsigned char *buf = tempargs->buf;
804 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
805 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
806 &DES_iv, DES_ENCRYPT);
810 static int DES_ede3_cbc_encrypt_loop(void *args)
812 loopargs_t *tempargs = (loopargs_t *)args;
813 unsigned char *buf = tempargs->buf;
815 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
816 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
818 &DES_iv, DES_ENCRYPT);
823 #ifndef OPENSSL_NO_AES
824 # define MAX_BLOCK_SIZE 128
826 # define MAX_BLOCK_SIZE 64
829 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
830 #ifndef OPENSSL_NO_AES
831 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
832 static int AES_cbc_128_encrypt_loop(void *args)
834 loopargs_t *tempargs = (loopargs_t *)args;
835 unsigned char *buf = tempargs->buf;
837 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
838 AES_cbc_encrypt(buf, buf,
839 (unsigned long)lengths[testnum], &aes_ks1,
844 static int AES_cbc_192_encrypt_loop(void *args)
846 loopargs_t *tempargs = (loopargs_t *)args;
847 unsigned char *buf = tempargs->buf;
849 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
850 AES_cbc_encrypt(buf, buf,
851 (unsigned long)lengths[testnum], &aes_ks2,
856 static int AES_cbc_256_encrypt_loop(void *args)
858 loopargs_t *tempargs = (loopargs_t *)args;
859 unsigned char *buf = tempargs->buf;
861 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
862 AES_cbc_encrypt(buf, buf,
863 (unsigned long)lengths[testnum], &aes_ks3,
868 static int AES_ige_128_encrypt_loop(void *args)
870 loopargs_t *tempargs = (loopargs_t *)args;
871 unsigned char *buf = tempargs->buf;
872 unsigned char *buf2 = tempargs->buf2;
874 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
875 AES_ige_encrypt(buf, buf2,
876 (unsigned long)lengths[testnum], &aes_ks1,
881 static int AES_ige_192_encrypt_loop(void *args)
883 loopargs_t *tempargs = (loopargs_t *)args;
884 unsigned char *buf = tempargs->buf;
885 unsigned char *buf2 = tempargs->buf2;
887 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
888 AES_ige_encrypt(buf, buf2,
889 (unsigned long)lengths[testnum], &aes_ks2,
894 static int AES_ige_256_encrypt_loop(void *args)
896 loopargs_t *tempargs = (loopargs_t *)args;
897 unsigned char *buf = tempargs->buf;
898 unsigned char *buf2 = tempargs->buf2;
900 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
901 AES_ige_encrypt(buf, buf2,
902 (unsigned long)lengths[testnum], &aes_ks3,
907 static int CRYPTO_gcm128_aad_loop(void *args)
909 loopargs_t *tempargs = (loopargs_t *)args;
910 unsigned char *buf = tempargs->buf;
911 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
913 for (count = 0; COND(c[D_GHASH][testnum]); count++)
914 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
920 static int decrypt = 0;
921 static int EVP_Update_loop(void *args)
923 loopargs_t *tempargs = (loopargs_t *)args;
924 unsigned char *buf = tempargs->buf;
925 EVP_CIPHER_CTX *ctx = tempargs->ctx;
929 COND(save_count * 4 * lengths[0] / lengths[testnum]);
931 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
934 COND(save_count * 4 * lengths[0] / lengths[testnum]);
936 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
938 EVP_DecryptFinal_ex(ctx, buf, &outl);
940 EVP_EncryptFinal_ex(ctx, buf, &outl);
944 static const EVP_MD *evp_md = NULL;
945 static int EVP_Digest_loop(void *args)
947 loopargs_t *tempargs = (loopargs_t *)args;
948 unsigned char *buf = tempargs->buf;
949 unsigned char md[EVP_MAX_MD_SIZE];
952 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
953 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
958 #ifndef OPENSSL_NO_RSA
959 static long rsa_c[RSA_NUM][2];
961 static int RSA_sign_loop(void *args)
963 loopargs_t *tempargs = (loopargs_t *)args;
964 unsigned char *buf = tempargs->buf;
965 unsigned char *buf2 = tempargs->buf2;
966 unsigned int *rsa_num = tempargs->siglen;
967 RSA **rsa_key = tempargs->rsa_key;
969 for (count = 0; COND(rsa_c[testnum][0]); count++) {
970 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
972 BIO_printf(bio_err, "RSA sign failure\n");
973 ERR_print_errors(bio_err);
981 static int RSA_verify_loop(void *args)
983 loopargs_t *tempargs = (loopargs_t *)args;
984 unsigned char *buf = tempargs->buf;
985 unsigned char *buf2 = tempargs->buf2;
986 unsigned int rsa_num = *(tempargs->siglen);
987 RSA **rsa_key = tempargs->rsa_key;
989 for (count = 0; COND(rsa_c[testnum][1]); count++) {
990 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
992 BIO_printf(bio_err, "RSA verify failure\n");
993 ERR_print_errors(bio_err);
1002 #ifndef OPENSSL_NO_DSA
1003 static long dsa_c[DSA_NUM][2];
1004 static int DSA_sign_loop(void *args)
1006 loopargs_t *tempargs = (loopargs_t *)args;
1007 unsigned char *buf = tempargs->buf;
1008 unsigned char *buf2 = tempargs->buf2;
1009 DSA **dsa_key = tempargs->dsa_key;
1010 unsigned int *siglen = tempargs->siglen;
1012 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1013 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1015 BIO_printf(bio_err, "DSA sign failure\n");
1016 ERR_print_errors(bio_err);
1024 static int DSA_verify_loop(void *args)
1026 loopargs_t *tempargs = (loopargs_t *)args;
1027 unsigned char *buf = tempargs->buf;
1028 unsigned char *buf2 = tempargs->buf2;
1029 DSA **dsa_key = tempargs->dsa_key;
1030 unsigned int siglen = *(tempargs->siglen);
1032 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1033 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1035 BIO_printf(bio_err, "DSA verify failure\n");
1036 ERR_print_errors(bio_err);
1045 #ifndef OPENSSL_NO_EC
1046 static long ecdsa_c[EC_NUM][2];
1047 static int ECDSA_sign_loop(void *args)
1049 loopargs_t *tempargs = (loopargs_t *)args;
1050 unsigned char *buf = tempargs->buf;
1051 EC_KEY **ecdsa = tempargs->ecdsa;
1052 unsigned char *ecdsasig = tempargs->buf2;
1053 unsigned int *ecdsasiglen = tempargs->siglen;
1055 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1056 ret = ECDSA_sign(0, buf, 20,
1057 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1059 BIO_printf(bio_err, "ECDSA sign failure\n");
1060 ERR_print_errors(bio_err);
1068 static int ECDSA_verify_loop(void *args)
1070 loopargs_t *tempargs = (loopargs_t *)args;
1071 unsigned char *buf = tempargs->buf;
1072 EC_KEY **ecdsa = tempargs->ecdsa;
1073 unsigned char *ecdsasig = tempargs->buf2;
1074 unsigned int ecdsasiglen = *(tempargs->siglen);
1076 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1077 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1080 BIO_printf(bio_err, "ECDSA verify failure\n");
1081 ERR_print_errors(bio_err);
1090 static void *(*kdf) (const void *in, size_t inlen, void *out,
1093 static int ECDH_compute_key_loop(void *args)
1095 loopargs_t *tempargs = (loopargs_t *)args;
1096 EC_KEY **ecdh_a = tempargs->ecdh_a;
1097 EC_KEY **ecdh_b = tempargs->ecdh_b;
1098 unsigned char *secret_a = tempargs->secret_a;
1100 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1101 ECDH_compute_key(secret_a, outlen,
1102 EC_KEY_get0_public_key(ecdh_b[testnum]),
1103 ecdh_a[testnum], kdf);
1110 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1112 int job_op_count = 0;
1113 int total_op_count = 0;
1114 int num_inprogress = 0;
1117 OSSL_ASYNC_FD job_fd = 0;
1118 size_t num_job_fds = 0;
1122 if (async_jobs == 0) {
1123 return loop_function((void *)loopargs);
1127 for (i = 0; i < async_jobs && !error; i++) {
1128 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1129 &job_op_count, loop_function,
1130 (void *)(loopargs + i), sizeof(loopargs_t))) {
1135 if (job_op_count == -1) {
1138 total_op_count += job_op_count;
1143 BIO_printf(bio_err, "Failure in the job\n");
1144 ERR_print_errors(bio_err);
1150 while (num_inprogress > 0) {
1151 #if defined(OPENSSL_SYS_WINDOWS)
1153 #elif defined(OPENSSL_SYS_UNIX)
1154 int select_result = 0;
1155 OSSL_ASYNC_FD max_fd = 0;
1158 FD_ZERO(&waitfdset);
1160 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1161 if (loopargs[i].inprogress_job == NULL)
1164 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1165 || num_job_fds > 1) {
1166 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1167 ERR_print_errors(bio_err);
1171 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1172 FD_SET(job_fd, &waitfdset);
1173 if (job_fd > max_fd)
1177 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1178 if (select_result == -1 && errno == EINTR)
1181 if (select_result == -1) {
1182 BIO_printf(bio_err, "Failure in the select\n");
1183 ERR_print_errors(bio_err);
1188 if (select_result == 0)
1192 for (i = 0; i < async_jobs; i++) {
1193 if (loopargs[i].inprogress_job == NULL)
1196 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1197 || num_job_fds > 1) {
1198 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1199 ERR_print_errors(bio_err);
1203 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1205 #if defined(OPENSSL_SYS_UNIX)
1206 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1208 #elif defined(OPENSSL_SYS_WINDOWS)
1209 if (num_job_fds == 1 &&
1210 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1214 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1215 &job_op_count, loop_function, (void *)(loopargs + i),
1216 sizeof(loopargs_t))) {
1220 if (job_op_count == -1) {
1223 total_op_count += job_op_count;
1226 loopargs[i].inprogress_job = NULL;
1231 loopargs[i].inprogress_job = NULL;
1232 BIO_printf(bio_err, "Failure in the job\n");
1233 ERR_print_errors(bio_err);
1240 return error ? -1 : total_op_count;
1243 int speed_main(int argc, char **argv)
1245 loopargs_t *loopargs = NULL;
1246 int loopargs_len = 0;
1248 const EVP_CIPHER *evp_cipher = NULL;
1251 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1252 #ifndef OPENSSL_NO_DSA
1253 int dsa_doit[DSA_NUM];
1255 int rsa_doit[RSA_NUM];
1256 int ret = 1, i, k, misalign = 0;
1257 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
1262 /* What follows are the buffers and key material. */
1263 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1266 #ifndef OPENSSL_NO_RC5
1269 #ifndef OPENSSL_NO_RC2
1272 #ifndef OPENSSL_NO_IDEA
1273 IDEA_KEY_SCHEDULE idea_ks;
1275 #ifndef OPENSSL_NO_SEED
1276 SEED_KEY_SCHEDULE seed_ks;
1278 #ifndef OPENSSL_NO_BF
1281 #ifndef OPENSSL_NO_CAST
1284 static const unsigned char key16[16] = {
1285 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1286 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1288 #ifndef OPENSSL_NO_AES
1289 static const unsigned char key24[24] = {
1290 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1291 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1292 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1294 static const unsigned char key32[32] = {
1295 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1296 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1297 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1298 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1301 #ifndef OPENSSL_NO_CAMELLIA
1302 static const unsigned char ckey24[24] = {
1303 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1304 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1305 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1307 static const unsigned char ckey32[32] = {
1308 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1309 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1310 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1311 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1313 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1315 #ifndef OPENSSL_NO_DES
1316 static DES_cblock key = {
1317 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1319 static DES_cblock key2 = {
1320 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1322 static DES_cblock key3 = {
1323 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1326 #ifndef OPENSSL_NO_RSA
1327 static unsigned int rsa_bits[RSA_NUM] = {
1328 512, 1024, 2048, 3072, 4096, 7680, 15360
1330 static unsigned char *rsa_data[RSA_NUM] = {
1331 test512, test1024, test2048, test3072, test4096, test7680, test15360
1333 static int rsa_data_length[RSA_NUM] = {
1334 sizeof(test512), sizeof(test1024),
1335 sizeof(test2048), sizeof(test3072),
1336 sizeof(test4096), sizeof(test7680),
1340 #ifndef OPENSSL_NO_DSA
1341 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1343 #ifndef OPENSSL_NO_EC
1345 * We only test over the following curves as they are representative, To
1346 * add tests over more curves, simply add the curve NID and curve name to
1347 * the following arrays and increase the EC_NUM value accordingly.
1349 static unsigned int test_curves[EC_NUM] = {
1351 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1352 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1354 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1355 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1356 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1361 static const char *test_curves_names[EC_NUM] = {
1363 "secp160r1", "nistp192", "nistp224",
1364 "nistp256", "nistp384", "nistp521",
1366 "nistk163", "nistk233", "nistk283",
1367 "nistk409", "nistk571", "nistb163",
1368 "nistb233", "nistb283", "nistb409",
1373 static int test_curves_bits[EC_NUM] = {
1379 571, 253 /* X25519 */
1382 #ifndef OPENSSL_NO_EC
1383 int ecdsa_doit[EC_NUM];
1384 int secret_size_a, secret_size_b;
1385 int ecdh_checks = 1;
1387 long ecdh_c[EC_NUM][2];
1388 int ecdh_doit[EC_NUM];
1391 memset(results, 0, sizeof(results));
1393 memset(c, 0, sizeof(c));
1394 #ifndef OPENSSL_NO_DES
1395 memset(DES_iv, 0, sizeof(DES_iv));
1397 memset(iv, 0, sizeof(iv));
1399 for (i = 0; i < ALGOR_NUM; i++)
1401 for (i = 0; i < RSA_NUM; i++)
1403 #ifndef OPENSSL_NO_DSA
1404 for (i = 0; i < DSA_NUM; i++)
1407 #ifndef OPENSSL_NO_EC
1408 for (i = 0; i < EC_NUM; i++)
1410 for (i = 0; i < EC_NUM; i++)
1416 prog = opt_init(argc, argv, speed_options);
1417 while ((o = opt_next()) != OPT_EOF) {
1422 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1425 opt_help(speed_options);
1432 evp_cipher = EVP_get_cipherbyname(opt_arg());
1433 if (evp_cipher == NULL)
1434 evp_md = EVP_get_digestbyname(opt_arg());
1435 if (evp_cipher == NULL && evp_md == NULL) {
1437 "%s: %s an unknown cipher or digest\n",
1448 * In a forked execution, an engine might need to be
1449 * initialised by each child process, not by the parent.
1450 * So store the name here and run setup_engine() later on.
1452 engine_id = opt_arg();
1456 multi = atoi(opt_arg());
1460 #ifndef OPENSSL_NO_ASYNC
1461 async_jobs = atoi(opt_arg());
1462 if (!ASYNC_is_capable()) {
1464 "%s: async_jobs specified but async not supported\n",
1471 if (!opt_int(opt_arg(), &misalign))
1473 if (misalign > MISALIGN) {
1475 "%s: Maximum offset is %d\n", prog, MISALIGN);
1487 argc = opt_num_rest();
1490 /* Remaining arguments are algorithms. */
1491 for ( ; *argv; argv++) {
1492 if (found(*argv, doit_choices, &i)) {
1496 #ifndef OPENSSL_NO_DES
1497 if (strcmp(*argv, "des") == 0) {
1498 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1502 if (strcmp(*argv, "sha") == 0) {
1503 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1506 #ifndef OPENSSL_NO_RSA
1508 if (strcmp(*argv, "openssl") == 0) {
1509 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1513 if (strcmp(*argv, "rsa") == 0) {
1514 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1515 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1516 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1517 rsa_doit[R_RSA_15360] = 1;
1520 if (found(*argv, rsa_choices, &i)) {
1525 #ifndef OPENSSL_NO_DSA
1526 if (strcmp(*argv, "dsa") == 0) {
1527 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1528 dsa_doit[R_DSA_2048] = 1;
1531 if (found(*argv, dsa_choices, &i)) {
1536 #ifndef OPENSSL_NO_AES
1537 if (strcmp(*argv, "aes") == 0) {
1538 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1539 doit[D_CBC_256_AES] = 1;
1543 #ifndef OPENSSL_NO_CAMELLIA
1544 if (strcmp(*argv, "camellia") == 0) {
1545 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1546 doit[D_CBC_256_CML] = 1;
1550 #ifndef OPENSSL_NO_EC
1551 if (strcmp(*argv, "ecdsa") == 0) {
1552 for (i = 0; i < EC_NUM; i++)
1556 if (found(*argv, ecdsa_choices, &i)) {
1560 if (strcmp(*argv, "ecdh") == 0) {
1561 for (i = 0; i < EC_NUM; i++)
1565 if (found(*argv, ecdh_choices, &i)) {
1570 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1574 /* Initialize the job pool if async mode is enabled */
1575 if (async_jobs > 0) {
1576 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1577 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1582 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1583 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1584 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1586 for (i = 0; i < loopargs_len; i++) {
1587 if (async_jobs > 0) {
1588 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1589 if (loopargs[i].wait_ctx == NULL) {
1590 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1595 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1596 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1597 /* Align the start of buffers on a 64 byte boundary */
1598 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1599 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1600 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1601 #ifndef OPENSSL_NO_EC
1602 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1603 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1608 if (multi && do_multi(multi))
1612 /* Initialize the engine after the fork */
1613 (void)setup_engine(engine_id, 0);
1615 /* No parameters; turn on everything. */
1616 if ((argc == 0) && !doit[D_EVP]) {
1617 for (i = 0; i < ALGOR_NUM; i++)
1620 for (i = 0; i < RSA_NUM; i++)
1622 #ifndef OPENSSL_NO_DSA
1623 for (i = 0; i < DSA_NUM; i++)
1626 #ifndef OPENSSL_NO_EC
1627 for (i = 0; i < EC_NUM; i++)
1629 for (i = 0; i < EC_NUM; i++)
1633 for (i = 0; i < ALGOR_NUM; i++)
1637 if (usertime == 0 && !mr)
1639 "You have chosen to measure elapsed time "
1640 "instead of user CPU time.\n");
1642 #ifndef OPENSSL_NO_RSA
1643 for (i = 0; i < loopargs_len; i++) {
1644 for (k = 0; k < RSA_NUM; k++) {
1645 const unsigned char *p;
1648 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1649 if (loopargs[i].rsa_key[k] == NULL) {
1650 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1657 #ifndef OPENSSL_NO_DSA
1658 for (i = 0; i < loopargs_len; i++) {
1659 loopargs[i].dsa_key[0] = get_dsa512();
1660 loopargs[i].dsa_key[1] = get_dsa1024();
1661 loopargs[i].dsa_key[2] = get_dsa2048();
1664 #ifndef OPENSSL_NO_DES
1665 DES_set_key_unchecked(&key, &sch);
1666 DES_set_key_unchecked(&key2, &sch2);
1667 DES_set_key_unchecked(&key3, &sch3);
1669 #ifndef OPENSSL_NO_AES
1670 AES_set_encrypt_key(key16, 128, &aes_ks1);
1671 AES_set_encrypt_key(key24, 192, &aes_ks2);
1672 AES_set_encrypt_key(key32, 256, &aes_ks3);
1674 #ifndef OPENSSL_NO_CAMELLIA
1675 Camellia_set_key(key16, 128, &camellia_ks1);
1676 Camellia_set_key(ckey24, 192, &camellia_ks2);
1677 Camellia_set_key(ckey32, 256, &camellia_ks3);
1679 #ifndef OPENSSL_NO_IDEA
1680 idea_set_encrypt_key(key16, &idea_ks);
1682 #ifndef OPENSSL_NO_SEED
1683 SEED_set_key(key16, &seed_ks);
1685 #ifndef OPENSSL_NO_RC4
1686 RC4_set_key(&rc4_ks, 16, key16);
1688 #ifndef OPENSSL_NO_RC2
1689 RC2_set_key(&rc2_ks, 16, key16, 128);
1691 #ifndef OPENSSL_NO_RC5
1692 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1694 #ifndef OPENSSL_NO_BF
1695 BF_set_key(&bf_ks, 16, key16);
1697 #ifndef OPENSSL_NO_CAST
1698 CAST_set_key(&cast_ks, 16, key16);
1700 #ifndef OPENSSL_NO_RSA
1701 memset(rsa_c, 0, sizeof(rsa_c));
1704 # ifndef OPENSSL_NO_DES
1705 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1711 for (it = count; it; it--)
1712 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1713 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1717 c[D_MD2][0] = count / 10;
1718 c[D_MDC2][0] = count / 10;
1719 c[D_MD4][0] = count;
1720 c[D_MD5][0] = count;
1721 c[D_HMAC][0] = count;
1722 c[D_SHA1][0] = count;
1723 c[D_RMD160][0] = count;
1724 c[D_RC4][0] = count * 5;
1725 c[D_CBC_DES][0] = count;
1726 c[D_EDE3_DES][0] = count / 3;
1727 c[D_CBC_IDEA][0] = count;
1728 c[D_CBC_SEED][0] = count;
1729 c[D_CBC_RC2][0] = count;
1730 c[D_CBC_RC5][0] = count;
1731 c[D_CBC_BF][0] = count;
1732 c[D_CBC_CAST][0] = count;
1733 c[D_CBC_128_AES][0] = count;
1734 c[D_CBC_192_AES][0] = count;
1735 c[D_CBC_256_AES][0] = count;
1736 c[D_CBC_128_CML][0] = count;
1737 c[D_CBC_192_CML][0] = count;
1738 c[D_CBC_256_CML][0] = count;
1739 c[D_SHA256][0] = count;
1740 c[D_SHA512][0] = count;
1741 c[D_WHIRLPOOL][0] = count;
1742 c[D_IGE_128_AES][0] = count;
1743 c[D_IGE_192_AES][0] = count;
1744 c[D_IGE_256_AES][0] = count;
1745 c[D_GHASH][0] = count;
1747 for (i = 1; i < SIZE_NUM; i++) {
1750 l0 = (long)lengths[0];
1751 l1 = (long)lengths[i];
1753 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1754 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1755 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1756 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1757 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1758 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1759 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1760 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1761 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1762 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1763 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1765 l0 = (long)lengths[i - 1];
1767 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1768 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1769 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1770 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1771 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1772 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1773 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1774 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1775 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1776 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1777 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1778 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1779 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1780 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1781 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1782 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1783 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1784 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1787 # ifndef OPENSSL_NO_RSA
1788 rsa_c[R_RSA_512][0] = count / 2000;
1789 rsa_c[R_RSA_512][1] = count / 400;
1790 for (i = 1; i < RSA_NUM; i++) {
1791 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1792 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1793 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1796 if (rsa_c[i][0] == 0) {
1804 # ifndef OPENSSL_NO_DSA
1805 dsa_c[R_DSA_512][0] = count / 1000;
1806 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1807 for (i = 1; i < DSA_NUM; i++) {
1808 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1809 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1810 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1813 if (dsa_c[i] == 0) {
1821 # ifndef OPENSSL_NO_EC
1822 ecdsa_c[R_EC_P160][0] = count / 1000;
1823 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1824 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1825 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1826 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1827 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1830 if (ecdsa_c[i] == 0) {
1836 ecdsa_c[R_EC_K163][0] = count / 1000;
1837 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1838 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1839 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1840 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1841 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1844 if (ecdsa_c[i] == 0) {
1850 ecdsa_c[R_EC_B163][0] = count / 1000;
1851 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1852 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1853 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1854 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1855 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1858 if (ecdsa_c[i] == 0) {
1865 ecdh_c[R_EC_P160][0] = count / 1000;
1866 ecdh_c[R_EC_P160][1] = count / 1000;
1867 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1868 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1869 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1870 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1873 if (ecdh_c[i] == 0) {
1879 ecdh_c[R_EC_K163][0] = count / 1000;
1880 ecdh_c[R_EC_K163][1] = count / 1000;
1881 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1882 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1883 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1884 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1887 if (ecdh_c[i] == 0) {
1893 ecdh_c[R_EC_B163][0] = count / 1000;
1894 ecdh_c[R_EC_B163][1] = count / 1000;
1895 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1896 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1897 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1898 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1901 if (ecdh_c[i] == 0) {
1910 /* not worth fixing */
1911 # error "You cannot disable DES on systems without SIGALRM."
1912 # endif /* OPENSSL_NO_DES */
1915 signal(SIGALRM, sig_done);
1917 #endif /* SIGALRM */
1919 #ifndef OPENSSL_NO_MD2
1921 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1922 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1924 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1926 print_result(D_MD2, testnum, count, d);
1930 #ifndef OPENSSL_NO_MDC2
1932 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1933 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1935 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1937 print_result(D_MDC2, testnum, count, d);
1942 #ifndef OPENSSL_NO_MD4
1944 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1945 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1947 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1949 print_result(D_MD4, testnum, count, d);
1954 #ifndef OPENSSL_NO_MD5
1956 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1957 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1959 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1961 print_result(D_MD5, testnum, count, d);
1966 #ifndef OPENSSL_NO_MD5
1968 for (i = 0; i < loopargs_len; i++) {
1969 loopargs[i].hctx = HMAC_CTX_new();
1970 if (loopargs[i].hctx == NULL) {
1971 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1975 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1976 16, EVP_md5(), NULL);
1978 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1979 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1981 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1983 print_result(D_HMAC, testnum, count, d);
1985 for (i = 0; i < loopargs_len; i++) {
1986 HMAC_CTX_free(loopargs[i].hctx);
1991 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1992 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1994 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1996 print_result(D_SHA1, testnum, count, d);
1999 if (doit[D_SHA256]) {
2000 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2001 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
2003 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2005 print_result(D_SHA256, testnum, count, d);
2008 if (doit[D_SHA512]) {
2009 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2010 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
2012 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2014 print_result(D_SHA512, testnum, count, d);
2018 #ifndef OPENSSL_NO_WHIRLPOOL
2019 if (doit[D_WHIRLPOOL]) {
2020 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2021 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
2023 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2025 print_result(D_WHIRLPOOL, testnum, count, d);
2030 #ifndef OPENSSL_NO_RMD160
2031 if (doit[D_RMD160]) {
2032 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2033 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2035 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2037 print_result(D_RMD160, testnum, count, d);
2041 #ifndef OPENSSL_NO_RC4
2043 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2044 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2046 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2048 print_result(D_RC4, testnum, count, d);
2052 #ifndef OPENSSL_NO_DES
2053 if (doit[D_CBC_DES]) {
2054 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2055 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2057 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2059 print_result(D_CBC_DES, testnum, count, d);
2063 if (doit[D_EDE3_DES]) {
2064 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2065 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2067 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2069 print_result(D_EDE3_DES, testnum, count, d);
2073 #ifndef OPENSSL_NO_AES
2074 if (doit[D_CBC_128_AES]) {
2075 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2076 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2079 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2081 print_result(D_CBC_128_AES, testnum, count, d);
2084 if (doit[D_CBC_192_AES]) {
2085 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2086 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2089 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2091 print_result(D_CBC_192_AES, testnum, count, d);
2094 if (doit[D_CBC_256_AES]) {
2095 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2096 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2099 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2101 print_result(D_CBC_256_AES, testnum, count, d);
2105 if (doit[D_IGE_128_AES]) {
2106 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2107 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2110 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2112 print_result(D_IGE_128_AES, testnum, count, d);
2115 if (doit[D_IGE_192_AES]) {
2116 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2117 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2120 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2122 print_result(D_IGE_192_AES, testnum, count, d);
2125 if (doit[D_IGE_256_AES]) {
2126 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2127 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2130 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2132 print_result(D_IGE_256_AES, testnum, count, d);
2135 if (doit[D_GHASH]) {
2136 for (i = 0; i < loopargs_len; i++) {
2137 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2138 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2141 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2142 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2144 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2146 print_result(D_GHASH, testnum, count, d);
2148 for (i = 0; i < loopargs_len; i++)
2149 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2152 #ifndef OPENSSL_NO_CAMELLIA
2153 if (doit[D_CBC_128_CML]) {
2154 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2155 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2157 if (async_jobs > 0) {
2158 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2162 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2163 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2164 (unsigned long)lengths[testnum], &camellia_ks1,
2165 iv, CAMELLIA_ENCRYPT);
2167 print_result(D_CBC_128_CML, testnum, count, d);
2170 if (doit[D_CBC_192_CML]) {
2171 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2172 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2174 if (async_jobs > 0) {
2175 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2179 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2180 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2181 (unsigned long)lengths[testnum], &camellia_ks2,
2182 iv, CAMELLIA_ENCRYPT);
2184 print_result(D_CBC_192_CML, testnum, count, d);
2187 if (doit[D_CBC_256_CML]) {
2188 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2189 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2191 if (async_jobs > 0) {
2192 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2196 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2197 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2198 (unsigned long)lengths[testnum], &camellia_ks3,
2199 iv, CAMELLIA_ENCRYPT);
2201 print_result(D_CBC_256_CML, testnum, count, d);
2205 #ifndef OPENSSL_NO_IDEA
2206 if (doit[D_CBC_IDEA]) {
2207 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2208 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2209 if (async_jobs > 0) {
2210 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2214 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2215 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2216 (unsigned long)lengths[testnum], &idea_ks,
2219 print_result(D_CBC_IDEA, testnum, count, d);
2223 #ifndef OPENSSL_NO_SEED
2224 if (doit[D_CBC_SEED]) {
2225 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2226 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2227 if (async_jobs > 0) {
2228 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2232 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2233 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2234 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2236 print_result(D_CBC_SEED, testnum, count, d);
2240 #ifndef OPENSSL_NO_RC2
2241 if (doit[D_CBC_RC2]) {
2242 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2243 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2244 if (async_jobs > 0) {
2245 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2249 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2250 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2251 (unsigned long)lengths[testnum], &rc2_ks,
2254 print_result(D_CBC_RC2, testnum, count, d);
2258 #ifndef OPENSSL_NO_RC5
2259 if (doit[D_CBC_RC5]) {
2260 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2261 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2262 if (async_jobs > 0) {
2263 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2267 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2268 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2269 (unsigned long)lengths[testnum], &rc5_ks,
2272 print_result(D_CBC_RC5, testnum, count, d);
2276 #ifndef OPENSSL_NO_BF
2277 if (doit[D_CBC_BF]) {
2278 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2279 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2280 if (async_jobs > 0) {
2281 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2285 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2286 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2287 (unsigned long)lengths[testnum], &bf_ks,
2290 print_result(D_CBC_BF, testnum, count, d);
2294 #ifndef OPENSSL_NO_CAST
2295 if (doit[D_CBC_CAST]) {
2296 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2297 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2298 if (async_jobs > 0) {
2299 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2303 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2304 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2305 (unsigned long)lengths[testnum], &cast_ks,
2308 print_result(D_CBC_CAST, testnum, count, d);
2314 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2315 if (multiblock && evp_cipher) {
2317 (EVP_CIPHER_flags(evp_cipher) &
2318 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2319 BIO_printf(bio_err, "%s is not multi-block capable\n",
2320 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2323 if (async_jobs > 0) {
2324 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2327 multiblock_speed(evp_cipher);
2332 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2335 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2337 * -O3 -fschedule-insns messes up an optimization here!
2338 * names[D_EVP] somehow becomes NULL
2340 print_message(names[D_EVP], save_count, lengths[testnum]);
2342 for (k = 0; k < loopargs_len; k++) {
2343 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2345 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2347 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2348 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2352 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2354 for (k = 0; k < loopargs_len; k++) {
2355 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2359 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2360 print_message(names[D_EVP], save_count, lengths[testnum]);
2362 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2365 print_result(D_EVP, testnum, count, d);
2369 for (i = 0; i < loopargs_len; i++)
2370 RAND_bytes(loopargs[i].buf, 36);
2372 #ifndef OPENSSL_NO_RSA
2373 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2375 if (!rsa_doit[testnum])
2377 for (i = 0; i < loopargs_len; i++) {
2378 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2379 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2385 "RSA sign failure. No RSA sign will be done.\n");
2386 ERR_print_errors(bio_err);
2389 pkey_print_message("private", "rsa",
2390 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2391 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2393 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2396 mr ? "+R1:%ld:%d:%.2f\n"
2397 : "%ld %d bit private RSA's in %.2fs\n",
2398 count, rsa_bits[testnum], d);
2399 rsa_results[testnum][0] = d / (double)count;
2403 for (i = 0; i < loopargs_len; i++) {
2404 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2405 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2411 "RSA verify failure. No RSA verify will be done.\n");
2412 ERR_print_errors(bio_err);
2413 rsa_doit[testnum] = 0;
2415 pkey_print_message("public", "rsa",
2416 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2418 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2421 mr ? "+R2:%ld:%d:%.2f\n"
2422 : "%ld %d bit public RSA's in %.2fs\n",
2423 count, rsa_bits[testnum], d);
2424 rsa_results[testnum][1] = d / (double)count;
2427 if (rsa_count <= 1) {
2428 /* if longer than 10s, don't do any more */
2429 for (testnum++; testnum < RSA_NUM; testnum++)
2430 rsa_doit[testnum] = 0;
2435 for (i = 0; i < loopargs_len; i++)
2436 RAND_bytes(loopargs[i].buf, 36);
2438 #ifndef OPENSSL_NO_DSA
2439 if (RAND_status() != 1) {
2440 RAND_seed(rnd_seed, sizeof rnd_seed);
2443 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2445 if (!dsa_doit[testnum])
2448 /* DSA_generate_key(dsa_key[testnum]); */
2449 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2450 for (i = 0; i < loopargs_len; i++) {
2451 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2452 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2458 "DSA sign failure. No DSA sign will be done.\n");
2459 ERR_print_errors(bio_err);
2462 pkey_print_message("sign", "dsa",
2463 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2465 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2468 mr ? "+R3:%ld:%d:%.2f\n"
2469 : "%ld %d bit DSA signs in %.2fs\n",
2470 count, dsa_bits[testnum], d);
2471 dsa_results[testnum][0] = d / (double)count;
2475 for (i = 0; i < loopargs_len; i++) {
2476 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2477 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2483 "DSA verify failure. No DSA verify will be done.\n");
2484 ERR_print_errors(bio_err);
2485 dsa_doit[testnum] = 0;
2487 pkey_print_message("verify", "dsa",
2488 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2490 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2493 mr ? "+R4:%ld:%d:%.2f\n"
2494 : "%ld %d bit DSA verify in %.2fs\n",
2495 count, dsa_bits[testnum], d);
2496 dsa_results[testnum][1] = d / (double)count;
2499 if (rsa_count <= 1) {
2500 /* if longer than 10s, don't do any more */
2501 for (testnum++; testnum < DSA_NUM; testnum++)
2502 dsa_doit[testnum] = 0;
2509 #ifndef OPENSSL_NO_EC
2510 if (RAND_status() != 1) {
2511 RAND_seed(rnd_seed, sizeof rnd_seed);
2514 for (testnum = 0; testnum < EC_NUM; testnum++) {
2517 if (!ecdsa_doit[testnum])
2518 continue; /* Ignore Curve */
2519 for (i = 0; i < loopargs_len; i++) {
2520 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2521 if (loopargs[i].ecdsa[testnum] == NULL) {
2527 BIO_printf(bio_err, "ECDSA failure.\n");
2528 ERR_print_errors(bio_err);
2531 for (i = 0; i < loopargs_len; i++) {
2532 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2533 /* Perform ECDSA signature test */
2534 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2535 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2536 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2542 "ECDSA sign failure. No ECDSA sign will be done.\n");
2543 ERR_print_errors(bio_err);
2546 pkey_print_message("sign", "ecdsa",
2547 ecdsa_c[testnum][0],
2548 test_curves_bits[testnum], ECDSA_SECONDS);
2550 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2554 mr ? "+R5:%ld:%d:%.2f\n" :
2555 "%ld %d bit ECDSA signs in %.2fs \n",
2556 count, test_curves_bits[testnum], d);
2557 ecdsa_results[testnum][0] = d / (double)count;
2561 /* Perform ECDSA verification test */
2562 for (i = 0; i < loopargs_len; i++) {
2563 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2564 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2570 "ECDSA verify failure. No ECDSA verify will be done.\n");
2571 ERR_print_errors(bio_err);
2572 ecdsa_doit[testnum] = 0;
2574 pkey_print_message("verify", "ecdsa",
2575 ecdsa_c[testnum][1],
2576 test_curves_bits[testnum], ECDSA_SECONDS);
2578 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2581 mr ? "+R6:%ld:%d:%.2f\n"
2582 : "%ld %d bit ECDSA verify in %.2fs\n",
2583 count, test_curves_bits[testnum], d);
2584 ecdsa_results[testnum][1] = d / (double)count;
2587 if (rsa_count <= 1) {
2588 /* if longer than 10s, don't do any more */
2589 for (testnum++; testnum < EC_NUM; testnum++)
2590 ecdsa_doit[testnum] = 0;
2598 #ifndef OPENSSL_NO_EC
2599 if (RAND_status() != 1) {
2600 RAND_seed(rnd_seed, sizeof rnd_seed);
2603 for (testnum = 0; testnum < EC_NUM; testnum++) {
2604 if (!ecdh_doit[testnum])
2606 for (i = 0; i < loopargs_len; i++) {
2607 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2608 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2609 if (loopargs[i].ecdh_a[testnum] == NULL ||
2610 loopargs[i].ecdh_b[testnum] == NULL) {
2615 if (ecdh_checks == 0) {
2616 BIO_printf(bio_err, "ECDH failure.\n");
2617 ERR_print_errors(bio_err);
2620 for (i = 0; i < loopargs_len; i++) {
2621 /* generate two ECDH key pairs */
2622 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2623 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2624 BIO_printf(bio_err, "ECDH key generation failure.\n");
2625 ERR_print_errors(bio_err);
2630 * If field size is not more than 24 octets, then use SHA-1
2631 * hash of result; otherwise, use result (see section 4.8 of
2632 * draft-ietf-tls-ecc-03.txt).
2636 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2637 if (field_size <= 24 * 8) {
2638 outlen = KDF1_SHA1_len;
2641 outlen = (field_size + 7) / 8;
2645 ECDH_compute_key(loopargs[i].secret_a, outlen,
2646 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2647 loopargs[i].ecdh_a[testnum], kdf);
2649 ECDH_compute_key(loopargs[i].secret_b, outlen,
2650 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2651 loopargs[i].ecdh_b[testnum], kdf);
2652 if (secret_size_a != secret_size_b)
2657 for (secret_idx = 0; (secret_idx < secret_size_a)
2658 && (ecdh_checks == 1); secret_idx++) {
2659 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2663 if (ecdh_checks == 0) {
2664 BIO_printf(bio_err, "ECDH computations don't match.\n");
2665 ERR_print_errors(bio_err);
2670 if (ecdh_checks != 0) {
2671 pkey_print_message("", "ecdh",
2673 test_curves_bits[testnum], ECDH_SECONDS);
2675 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2678 mr ? "+R7:%ld:%d:%.2f\n" :
2679 "%ld %d-bit ECDH ops in %.2fs\n", count,
2680 test_curves_bits[testnum], d);
2681 ecdh_results[testnum][0] = d / (double)count;
2687 if (rsa_count <= 1) {
2688 /* if longer than 10s, don't do any more */
2689 for (testnum++; testnum < EC_NUM; testnum++)
2690 ecdh_doit[testnum] = 0;
2700 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2701 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2703 printf("%s ", BN_options());
2704 #ifndef OPENSSL_NO_MD2
2705 printf("%s ", MD2_options());
2707 #ifndef OPENSSL_NO_RC4
2708 printf("%s ", RC4_options());
2710 #ifndef OPENSSL_NO_DES
2711 printf("%s ", DES_options());
2713 #ifndef OPENSSL_NO_AES
2714 printf("%s ", AES_options());
2716 #ifndef OPENSSL_NO_IDEA
2717 printf("%s ", idea_options());
2719 #ifndef OPENSSL_NO_BF
2720 printf("%s ", BF_options());
2722 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2730 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2733 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2734 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2738 for (k = 0; k < ALGOR_NUM; k++) {
2742 printf("+F:%d:%s", k, names[k]);
2744 printf("%-13s", names[k]);
2745 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2746 if (results[k][testnum] > 10000 && !mr)
2747 printf(" %11.2fk", results[k][testnum] / 1e3);
2749 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2753 #ifndef OPENSSL_NO_RSA
2755 for (k = 0; k < RSA_NUM; k++) {
2758 if (testnum && !mr) {
2759 printf("%18ssign verify sign/s verify/s\n", " ");
2763 printf("+F2:%u:%u:%f:%f\n",
2764 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2766 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2767 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2768 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2771 #ifndef OPENSSL_NO_DSA
2773 for (k = 0; k < DSA_NUM; k++) {
2776 if (testnum && !mr) {
2777 printf("%18ssign verify sign/s verify/s\n", " ");
2781 printf("+F3:%u:%u:%f:%f\n",
2782 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2784 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2785 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2786 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2789 #ifndef OPENSSL_NO_EC
2791 for (k = 0; k < EC_NUM; k++) {
2794 if (testnum && !mr) {
2795 printf("%30ssign verify sign/s verify/s\n", " ");
2800 printf("+F4:%u:%u:%f:%f\n",
2801 k, test_curves_bits[k],
2802 ecdsa_results[k][0], ecdsa_results[k][1]);
2804 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2805 test_curves_bits[k],
2806 test_curves_names[k],
2807 ecdsa_results[k][0], ecdsa_results[k][1],
2808 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2812 #ifndef OPENSSL_NO_EC
2814 for (k = 0; k < EC_NUM; k++) {
2817 if (testnum && !mr) {
2818 printf("%30sop op/s\n", " ");
2822 printf("+F5:%u:%u:%f:%f\n",
2823 k, test_curves_bits[k],
2824 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2827 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2828 test_curves_bits[k],
2829 test_curves_names[k],
2830 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2837 ERR_print_errors(bio_err);
2838 for (i = 0; i < loopargs_len; i++) {
2839 OPENSSL_free(loopargs[i].buf_malloc);
2840 OPENSSL_free(loopargs[i].buf2_malloc);
2841 OPENSSL_free(loopargs[i].siglen);
2843 #ifndef OPENSSL_NO_RSA
2844 for (i = 0; i < loopargs_len; i++) {
2845 for (k = 0; k < RSA_NUM; k++)
2846 RSA_free(loopargs[i].rsa_key[k]);
2849 #ifndef OPENSSL_NO_DSA
2850 for (i = 0; i < loopargs_len; i++) {
2851 for (k = 0; k < DSA_NUM; k++)
2852 DSA_free(loopargs[i].dsa_key[k]);
2856 #ifndef OPENSSL_NO_EC
2857 for (i = 0; i < loopargs_len; i++) {
2858 for (k = 0; k < EC_NUM; k++) {
2859 EC_KEY_free(loopargs[i].ecdsa[k]);
2860 EC_KEY_free(loopargs[i].ecdh_a[k]);
2861 EC_KEY_free(loopargs[i].ecdh_b[k]);
2863 OPENSSL_free(loopargs[i].secret_a);
2864 OPENSSL_free(loopargs[i].secret_b);
2867 if (async_jobs > 0) {
2868 for (i = 0; i < loopargs_len; i++)
2869 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2871 ASYNC_cleanup_thread();
2873 OPENSSL_free(loopargs);
2877 static void print_message(const char *s, long num, int length)
2881 mr ? "+DT:%s:%d:%d\n"
2882 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2883 (void)BIO_flush(bio_err);
2887 mr ? "+DN:%s:%ld:%d\n"
2888 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2889 (void)BIO_flush(bio_err);
2893 static void pkey_print_message(const char *str, const char *str2, long num,
2898 mr ? "+DTP:%d:%s:%s:%d\n"
2899 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2900 (void)BIO_flush(bio_err);
2904 mr ? "+DNP:%ld:%d:%s:%s\n"
2905 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2906 (void)BIO_flush(bio_err);
2910 static void print_result(int alg, int run_no, int count, double time_used)
2913 mr ? "+R:%d:%s:%f\n"
2914 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2915 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2919 static char *sstrsep(char **string, const char *delim)
2922 char *token = *string;
2927 memset(isdelim, 0, sizeof isdelim);
2931 isdelim[(unsigned char)(*delim)] = 1;
2935 while (!isdelim[(unsigned char)(**string)]) {
2947 static int do_multi(int multi)
2952 static char sep[] = ":";
2954 fds = malloc(sizeof(*fds) * multi);
2955 for (n = 0; n < multi; ++n) {
2956 if (pipe(fd) == -1) {
2957 BIO_printf(bio_err, "pipe failure\n");
2961 (void)BIO_flush(bio_err);
2968 if (dup(fd[1]) == -1) {
2969 BIO_printf(bio_err, "dup failed\n");
2978 printf("Forked child %d\n", n);
2981 /* for now, assume the pipe is long enough to take all the output */
2982 for (n = 0; n < multi; ++n) {
2987 f = fdopen(fds[n], "r");
2988 while (fgets(buf, sizeof buf, f)) {
2989 p = strchr(buf, '\n');
2992 if (buf[0] != '+') {
2993 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2997 printf("Got: %s from %d\n", buf, n);
2998 if (strncmp(buf, "+F:", 3) == 0) {
3003 alg = atoi(sstrsep(&p, sep));
3005 for (j = 0; j < SIZE_NUM; ++j)
3006 results[alg][j] += atof(sstrsep(&p, sep));
3007 } else if (strncmp(buf, "+F2:", 4) == 0) {
3012 k = atoi(sstrsep(&p, sep));
3015 d = atof(sstrsep(&p, sep));
3017 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
3019 rsa_results[k][0] = d;
3021 d = atof(sstrsep(&p, sep));
3023 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3025 rsa_results[k][1] = d;
3027 # ifndef OPENSSL_NO_DSA
3028 else if (strncmp(buf, "+F3:", 4) == 0) {
3033 k = atoi(sstrsep(&p, sep));
3036 d = atof(sstrsep(&p, sep));
3038 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3040 dsa_results[k][0] = d;
3042 d = atof(sstrsep(&p, sep));
3044 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3046 dsa_results[k][1] = d;
3049 # ifndef OPENSSL_NO_EC
3050 else if (strncmp(buf, "+F4:", 4) == 0) {
3055 k = atoi(sstrsep(&p, sep));
3058 d = atof(sstrsep(&p, sep));
3060 ecdsa_results[k][0] =
3061 1 / (1 / ecdsa_results[k][0] + 1 / d);
3063 ecdsa_results[k][0] = d;
3065 d = atof(sstrsep(&p, sep));
3067 ecdsa_results[k][1] =
3068 1 / (1 / ecdsa_results[k][1] + 1 / d);
3070 ecdsa_results[k][1] = d;
3074 # ifndef OPENSSL_NO_EC
3075 else if (strncmp(buf, "+F5:", 4) == 0) {
3080 k = atoi(sstrsep(&p, sep));
3083 d = atof(sstrsep(&p, sep));
3085 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3087 ecdh_results[k][0] = d;
3092 else if (strncmp(buf, "+H:", 3) == 0) {
3095 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3105 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3107 static int mblengths[] =
3108 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3109 int j, count, num = OSSL_NELEM(mblengths);
3110 const char *alg_name;
3111 unsigned char *inp, *out, no_key[32], no_iv[16];
3112 EVP_CIPHER_CTX *ctx;
3115 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3116 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3117 ctx = EVP_CIPHER_CTX_new();
3118 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3119 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3121 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3123 for (j = 0; j < num; j++) {
3124 print_message(alg_name, 0, mblengths[j]);
3126 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3127 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3128 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3129 size_t len = mblengths[j];
3132 memset(aad, 0, 8); /* avoid uninitialized values */
3133 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3134 aad[9] = 3; /* version */
3136 aad[11] = 0; /* length */
3138 mb_param.out = NULL;
3141 mb_param.interleave = 8;
3143 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3144 sizeof(mb_param), &mb_param);
3150 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3151 sizeof(mb_param), &mb_param);
3155 RAND_bytes(out, 16);
3159 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3160 EVP_AEAD_TLS1_AAD_LEN, aad);
3161 EVP_Cipher(ctx, out, inp, len + pad);
3165 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3166 : "%d %s's in %.2fs\n", count, "evp", d);
3167 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3171 fprintf(stdout, "+H");
3172 for (j = 0; j < num; j++)
3173 fprintf(stdout, ":%d", mblengths[j]);
3174 fprintf(stdout, "\n");
3175 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3176 for (j = 0; j < num; j++)
3177 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3178 fprintf(stdout, "\n");
3181 "The 'numbers' are in 1000s of bytes per second processed.\n");
3182 fprintf(stdout, "type ");
3183 for (j = 0; j < num; j++)
3184 fprintf(stdout, "%7d bytes", mblengths[j]);
3185 fprintf(stdout, "\n");
3186 fprintf(stdout, "%-24s", alg_name);
3188 for (j = 0; j < num; j++) {
3189 if (results[D_EVP][j] > 10000)
3190 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3192 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3194 fprintf(stdout, "\n");
3199 EVP_CIPHER_CTX_free(ctx);