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
94 #ifndef OPENSSL_SYS_NETWARE
102 #if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
106 #if !defined(OPENSSL_NO_ASYNC)
107 # if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
108 # if _POSIX_VERSION >= 200112L
111 # elif defined(_WIN32) || defined(__CYGWIN__)
116 #if !defined(ASYNC_POSIX) && !defined(ASYNC_WIN)
120 #include <openssl/bn.h>
121 #ifndef OPENSSL_NO_DES
122 # include <openssl/des.h>
124 #ifndef OPENSSL_NO_AES
125 # include <openssl/aes.h>
127 #ifndef OPENSSL_NO_CAMELLIA
128 # include <openssl/camellia.h>
130 #ifndef OPENSSL_NO_MD2
131 # include <openssl/md2.h>
133 #ifndef OPENSSL_NO_MDC2
134 # include <openssl/mdc2.h>
136 #ifndef OPENSSL_NO_MD4
137 # include <openssl/md4.h>
139 #ifndef OPENSSL_NO_MD5
140 # include <openssl/md5.h>
142 #include <openssl/hmac.h>
143 #include <openssl/sha.h>
144 #ifndef OPENSSL_NO_RMD160
145 # include <openssl/ripemd.h>
147 #ifndef OPENSSL_NO_WHIRLPOOL
148 # include <openssl/whrlpool.h>
150 #ifndef OPENSSL_NO_RC4
151 # include <openssl/rc4.h>
153 #ifndef OPENSSL_NO_RC5
154 # include <openssl/rc5.h>
156 #ifndef OPENSSL_NO_RC2
157 # include <openssl/rc2.h>
159 #ifndef OPENSSL_NO_IDEA
160 # include <openssl/idea.h>
162 #ifndef OPENSSL_NO_SEED
163 # include <openssl/seed.h>
165 #ifndef OPENSSL_NO_BF
166 # include <openssl/blowfish.h>
168 #ifndef OPENSSL_NO_CAST
169 # include <openssl/cast.h>
171 #ifndef OPENSSL_NO_RSA
172 # include <openssl/rsa.h>
173 # include "./testrsa.h"
175 #include <openssl/x509.h>
176 #ifndef OPENSSL_NO_DSA
177 # include <openssl/dsa.h>
178 # include "./testdsa.h"
180 #ifndef OPENSSL_NO_EC
181 # include <openssl/ec.h>
183 #include <openssl/modes.h>
186 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
200 #define BUFSIZE (1024*16+1)
201 #define MAX_MISALIGNMENT 63
203 static volatile int run = 0;
206 static int usertime = 1;
208 typedef struct loopargs_st {
209 ASYNC_JOB *inprogress_job;
212 unsigned char *buf_malloc;
213 unsigned char *buf2_malloc;
216 GCM128_CONTEXT *gcm_ctx;
217 unsigned char ecdsasig[256];
221 #ifndef OPENSSL_NO_MD2
222 static int EVP_Digest_MD2_loop(void *args);
225 #ifndef OPENSSL_NO_MDC2
226 static int EVP_Digest_MDC2_loop(void *args);
228 #ifndef OPENSSL_NO_MD4
229 static int EVP_Digest_MD4_loop(void *args);
231 #ifndef OPENSSL_NO_MD5
232 static int MD5_loop(void *args);
233 static int HMAC_loop(void *args);
235 static int SHA1_loop(void *args);
236 static int SHA256_loop(void *args);
237 static int SHA512_loop(void *args);
238 #ifndef OPENSSL_NO_WHIRLPOOL
239 static int WHIRLPOOL_loop(void *args);
241 #ifndef OPENSSL_NO_RMD160
242 static int EVP_Digest_RMD160_loop(void *args);
244 #ifndef OPENSSL_NO_RC4
245 static int RC4_loop(void *args);
247 #ifndef OPENSSL_NO_DES
248 static int DES_ncbc_encrypt_loop(void *args);
249 static int DES_ede3_cbc_encrypt_loop(void *args);
251 #ifndef OPENSSL_NO_AES
252 static int AES_cbc_128_encrypt_loop(void *args);
253 static int AES_cbc_192_encrypt_loop(void *args);
254 static int AES_ige_128_encrypt_loop(void *args);
255 static int AES_cbc_256_encrypt_loop(void *args);
256 static int AES_ige_192_encrypt_loop(void *args);
257 static int AES_ige_256_encrypt_loop(void *args);
258 static int CRYPTO_gcm128_aad_loop(void *args);
260 static int EVP_Update_loop(void *args);
261 static int EVP_Digest_loop(void *args);
262 #ifndef OPENSSL_NO_RSA
263 static int RSA_sign_loop(void *args);
264 static int RSA_verify_loop(void *args);
266 #ifndef OPENSSL_NO_DSA
267 static int DSA_sign_loop(void *args);
268 static int DSA_verify_loop(void *args);
270 #ifndef OPENSSL_NO_EC
271 static int ECDSA_sign_loop(void *args);
272 static int ECDSA_verify_loop(void *args);
273 static int ECDH_compute_key_loop(void *args);
275 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
277 static double Time_F(int s);
278 static void print_message(const char *s, long num, int length);
279 static void pkey_print_message(const char *str, const char *str2,
280 long num, int bits, int sec);
281 static void print_result(int alg, int run_no, int count, double time_used);
283 static int do_multi(int multi);
293 #define MAX_ECDH_SIZE 256
296 static const char *names[ALGOR_NUM] = {
297 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
298 "des cbc", "des ede3", "idea cbc", "seed cbc",
299 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
300 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
301 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
302 "evp", "sha256", "sha512", "whirlpool",
303 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
306 static double results[ALGOR_NUM][SIZE_NUM];
307 static int lengths[SIZE_NUM] = {
308 16, 64, 256, 1024, 8 * 1024, 16 * 1024
311 #ifndef OPENSSL_NO_RSA
312 static double rsa_results[RSA_NUM][2];
314 #ifndef OPENSSL_NO_DSA
315 static double dsa_results[DSA_NUM][2];
317 #ifndef OPENSSL_NO_EC
318 static double ecdsa_results[EC_NUM][2];
319 static double ecdh_results[EC_NUM][1];
322 #if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
323 static const char rnd_seed[] =
324 "string to make the random number generator think it has entropy";
325 static int rnd_fake = 0;
329 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
330 # define SIGRETTYPE void
332 # define SIGRETTYPE int
335 static SIGRETTYPE sig_done(int sig);
336 static SIGRETTYPE sig_done(int sig)
338 signal(SIGALRM, sig_done);
348 # if !defined(SIGALRM)
351 static unsigned int lapse, schlock;
352 static void alarm_win32(unsigned int secs)
357 # define alarm alarm_win32
359 static DWORD WINAPI sleepy(VOID * arg)
367 static double Time_F(int s)
374 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
376 DWORD err = GetLastError();
377 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
381 Sleep(0); /* scheduler spinlock */
382 ret = app_tminterval(s, usertime);
384 ret = app_tminterval(s, usertime);
386 TerminateThread(thr, 0);
394 static double Time_F(int s)
396 double ret = app_tminterval(s, usertime);
403 #ifndef OPENSSL_NO_EC
404 static const int KDF1_SHA1_len = 20;
405 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
408 if (*outlen < SHA_DIGEST_LENGTH)
410 *outlen = SHA_DIGEST_LENGTH;
411 return SHA1(in, inlen, out);
413 #endif /* OPENSSL_NO_EC */
415 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
417 static int found(const char *name, const OPT_PAIR * pairs, int *result)
419 for (; pairs->name; pairs++)
420 if (strcmp(name, pairs->name) == 0) {
421 *result = pairs->retval;
427 typedef enum OPTION_choice {
428 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
429 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
430 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
433 OPTIONS speed_options[] = {
434 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
435 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
436 {"help", OPT_HELP, '-', "Display this summary"},
437 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
438 {"decrypt", OPT_DECRYPT, '-',
439 "Time decryption instead of encryption (only EVP)"},
440 {"mr", OPT_MR, '-', "Produce machine readable output"},
442 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
443 {"elapsed", OPT_ELAPSED, '-',
444 "Measure time in real time instead of CPU user time"},
446 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
449 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
451 #ifndef OPENSSL_NO_ENGINE
452 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
467 #define D_CBC_IDEA 10
468 #define D_CBC_SEED 11
472 #define D_CBC_CAST 15
473 #define D_CBC_128_AES 16
474 #define D_CBC_192_AES 17
475 #define D_CBC_256_AES 18
476 #define D_CBC_128_CML 19
477 #define D_CBC_192_CML 20
478 #define D_CBC_256_CML 21
482 #define D_WHIRLPOOL 25
483 #define D_IGE_128_AES 26
484 #define D_IGE_192_AES 27
485 #define D_IGE_256_AES 28
487 static OPT_PAIR doit_choices[] = {
488 #ifndef OPENSSL_NO_MD2
491 #ifndef OPENSSL_NO_MDC2
494 #ifndef OPENSSL_NO_MD4
497 #ifndef OPENSSL_NO_MD5
500 #ifndef OPENSSL_NO_MD5
504 {"sha256", D_SHA256},
505 {"sha512", D_SHA512},
506 #ifndef OPENSSL_NO_WHIRLPOOL
507 {"whirlpool", D_WHIRLPOOL},
509 #ifndef OPENSSL_NO_RMD160
510 {"ripemd", D_RMD160},
511 {"rmd160", D_RMD160},
512 {"ripemd160", D_RMD160},
514 #ifndef OPENSSL_NO_RC4
517 #ifndef OPENSSL_NO_DES
518 {"des-cbc", D_CBC_DES},
519 {"des-ede3", D_EDE3_DES},
521 #ifndef OPENSSL_NO_AES
522 {"aes-128-cbc", D_CBC_128_AES},
523 {"aes-192-cbc", D_CBC_192_AES},
524 {"aes-256-cbc", D_CBC_256_AES},
525 {"aes-128-ige", D_IGE_128_AES},
526 {"aes-192-ige", D_IGE_192_AES},
527 {"aes-256-ige", D_IGE_256_AES},
529 #ifndef OPENSSL_NO_RC2
530 {"rc2-cbc", D_CBC_RC2},
533 #ifndef OPENSSL_NO_RC5
534 {"rc5-cbc", D_CBC_RC5},
537 #ifndef OPENSSL_NO_IDEA
538 {"idea-cbc", D_CBC_IDEA},
539 {"idea", D_CBC_IDEA},
541 #ifndef OPENSSL_NO_SEED
542 {"seed-cbc", D_CBC_SEED},
543 {"seed", D_CBC_SEED},
545 #ifndef OPENSSL_NO_BF
546 {"bf-cbc", D_CBC_BF},
547 {"blowfish", D_CBC_BF},
550 #ifndef OPENSSL_NO_CAST
551 {"cast-cbc", D_CBC_CAST},
552 {"cast", D_CBC_CAST},
553 {"cast5", D_CBC_CAST},
562 static OPT_PAIR dsa_choices[] = {
563 {"dsa512", R_DSA_512},
564 {"dsa1024", R_DSA_1024},
565 {"dsa2048", R_DSA_2048},
575 #define R_RSA_15360 6
576 static OPT_PAIR rsa_choices[] = {
577 {"rsa512", R_RSA_512},
578 {"rsa1024", R_RSA_1024},
579 {"rsa2048", R_RSA_2048},
580 {"rsa3072", R_RSA_3072},
581 {"rsa4096", R_RSA_4096},
582 {"rsa7680", R_RSA_7680},
583 {"rsa15360", R_RSA_15360},
603 #define R_EC_X25519 16
604 #ifndef OPENSSL_NO_EC
605 static OPT_PAIR ecdsa_choices[] = {
606 {"ecdsap160", R_EC_P160},
607 {"ecdsap192", R_EC_P192},
608 {"ecdsap224", R_EC_P224},
609 {"ecdsap256", R_EC_P256},
610 {"ecdsap384", R_EC_P384},
611 {"ecdsap521", R_EC_P521},
612 {"ecdsak163", R_EC_K163},
613 {"ecdsak233", R_EC_K233},
614 {"ecdsak283", R_EC_K283},
615 {"ecdsak409", R_EC_K409},
616 {"ecdsak571", R_EC_K571},
617 {"ecdsab163", R_EC_B163},
618 {"ecdsab233", R_EC_B233},
619 {"ecdsab283", R_EC_B283},
620 {"ecdsab409", R_EC_B409},
621 {"ecdsab571", R_EC_B571},
624 static OPT_PAIR ecdh_choices[] = {
625 {"ecdhp160", R_EC_P160},
626 {"ecdhp192", R_EC_P192},
627 {"ecdhp224", R_EC_P224},
628 {"ecdhp256", R_EC_P256},
629 {"ecdhp384", R_EC_P384},
630 {"ecdhp521", R_EC_P521},
631 {"ecdhk163", R_EC_K163},
632 {"ecdhk233", R_EC_K233},
633 {"ecdhk283", R_EC_K283},
634 {"ecdhk409", R_EC_K409},
635 {"ecdhk571", R_EC_K571},
636 {"ecdhb163", R_EC_B163},
637 {"ecdhb233", R_EC_B233},
638 {"ecdhb283", R_EC_B283},
639 {"ecdhb409", R_EC_B409},
640 {"ecdhb571", R_EC_B571},
641 {"ecdhx25519", R_EC_X25519},
647 # define COND(d) (count < (d))
648 # define COUNT(d) (d)
650 # define COND(c) (run && count<0x7fffffff)
651 # define COUNT(d) (count)
655 static char *engine_id = NULL;
658 #ifndef OPENSSL_NO_MD2
659 static int EVP_Digest_MD2_loop(void *args)
661 loopargs_t *tempargs = (loopargs_t *)args;
662 unsigned char *buf = tempargs->buf;
663 unsigned char md2[MD2_DIGEST_LENGTH];
665 for (count = 0; COND(c[D_MD2][testnum]); count++)
666 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
672 #ifndef OPENSSL_NO_MDC2
673 static int EVP_Digest_MDC2_loop(void *args)
675 loopargs_t *tempargs = (loopargs_t *)args;
676 unsigned char *buf = tempargs->buf;
677 unsigned char mdc2[MDC2_DIGEST_LENGTH];
679 for (count = 0; COND(c[D_MDC2][testnum]); count++)
680 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
686 #ifndef OPENSSL_NO_MD4
687 static int EVP_Digest_MD4_loop(void *args)
689 loopargs_t *tempargs = (loopargs_t *)args;
690 unsigned char *buf = tempargs->buf;
691 unsigned char md4[MD4_DIGEST_LENGTH];
693 for (count = 0; COND(c[D_MD4][testnum]); count++)
694 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
695 NULL, EVP_md4(), NULL);
700 #ifndef OPENSSL_NO_MD5
701 static int MD5_loop(void *args)
703 loopargs_t *tempargs = (loopargs_t *)args;
704 unsigned char *buf = tempargs->buf;
705 unsigned char md5[MD5_DIGEST_LENGTH];
707 for (count = 0; COND(c[D_MD5][testnum]); count++)
708 MD5(buf, lengths[testnum], md5);
712 static int HMAC_loop(void *args)
714 loopargs_t *tempargs = (loopargs_t *)args;
715 unsigned char *buf = tempargs->buf;
716 HMAC_CTX *hctx = tempargs->hctx;
717 unsigned char hmac[MD5_DIGEST_LENGTH];
719 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
720 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
721 HMAC_Update(hctx, buf, lengths[testnum]);
722 HMAC_Final(hctx, &(hmac[0]), NULL);
728 static int SHA1_loop(void *args)
730 loopargs_t *tempargs = (loopargs_t *)args;
731 unsigned char *buf = tempargs->buf;
732 unsigned char sha[SHA_DIGEST_LENGTH];
734 for (count = 0; COND(c[D_SHA1][testnum]); count++)
735 SHA1(buf, lengths[testnum], sha);
739 static int SHA256_loop(void *args)
741 loopargs_t *tempargs = (loopargs_t *)args;
742 unsigned char *buf = tempargs->buf;
743 unsigned char sha256[SHA256_DIGEST_LENGTH];
745 for (count = 0; COND(c[D_SHA256][testnum]); count++)
746 SHA256(buf, lengths[testnum], sha256);
750 static int SHA512_loop(void *args)
752 loopargs_t *tempargs = (loopargs_t *)args;
753 unsigned char *buf = tempargs->buf;
754 unsigned char sha512[SHA512_DIGEST_LENGTH];
756 for (count = 0; COND(c[D_SHA512][testnum]); count++)
757 SHA512(buf, lengths[testnum], sha512);
761 #ifndef OPENSSL_NO_WHIRLPOOL
762 static int WHIRLPOOL_loop(void *args)
764 loopargs_t *tempargs = (loopargs_t *)args;
765 unsigned char *buf = tempargs->buf;
766 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
768 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
769 WHIRLPOOL(buf, lengths[testnum], whirlpool);
774 #ifndef OPENSSL_NO_RMD160
775 static int EVP_Digest_RMD160_loop(void *args)
777 loopargs_t *tempargs = (loopargs_t *)args;
778 unsigned char *buf = tempargs->buf;
779 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
781 for (count = 0; COND(c[D_RMD160][testnum]); count++)
782 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
783 EVP_ripemd160(), NULL);
788 #ifndef OPENSSL_NO_RC4
789 static RC4_KEY rc4_ks;
790 static int RC4_loop(void *args)
792 loopargs_t *tempargs = (loopargs_t *)args;
793 unsigned char *buf = tempargs->buf;
795 for (count = 0; COND(c[D_RC4][testnum]); count++)
796 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
801 #ifndef OPENSSL_NO_DES
802 static unsigned char DES_iv[8];
803 static DES_key_schedule sch;
804 static DES_key_schedule sch2;
805 static DES_key_schedule sch3;
806 static int DES_ncbc_encrypt_loop(void *args)
808 loopargs_t *tempargs = (loopargs_t *)args;
809 unsigned char *buf = tempargs->buf;
811 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
812 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
813 &DES_iv, DES_ENCRYPT);
817 static int DES_ede3_cbc_encrypt_loop(void *args)
819 loopargs_t *tempargs = (loopargs_t *)args;
820 unsigned char *buf = tempargs->buf;
822 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
823 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
825 &DES_iv, DES_ENCRYPT);
830 #ifndef OPENSSL_NO_AES
831 # define MAX_BLOCK_SIZE 128
833 # define MAX_BLOCK_SIZE 64
836 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
837 #ifndef OPENSSL_NO_AES
838 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
839 static int AES_cbc_128_encrypt_loop(void *args)
841 loopargs_t *tempargs = (loopargs_t *)args;
842 unsigned char *buf = tempargs->buf;
844 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
845 AES_cbc_encrypt(buf, buf,
846 (unsigned long)lengths[testnum], &aes_ks1,
851 static int AES_cbc_192_encrypt_loop(void *args)
853 loopargs_t *tempargs = (loopargs_t *)args;
854 unsigned char *buf = tempargs->buf;
856 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
857 AES_cbc_encrypt(buf, buf,
858 (unsigned long)lengths[testnum], &aes_ks2,
863 static int AES_cbc_256_encrypt_loop(void *args)
865 loopargs_t *tempargs = (loopargs_t *)args;
866 unsigned char *buf = tempargs->buf;
868 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
869 AES_cbc_encrypt(buf, buf,
870 (unsigned long)lengths[testnum], &aes_ks3,
875 static int AES_ige_128_encrypt_loop(void *args)
877 loopargs_t *tempargs = (loopargs_t *)args;
878 unsigned char *buf = tempargs->buf;
879 unsigned char *buf2 = tempargs->buf2;
881 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
882 AES_ige_encrypt(buf, buf2,
883 (unsigned long)lengths[testnum], &aes_ks1,
888 static int AES_ige_192_encrypt_loop(void *args)
890 loopargs_t *tempargs = (loopargs_t *)args;
891 unsigned char *buf = tempargs->buf;
892 unsigned char *buf2 = tempargs->buf2;
894 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
895 AES_ige_encrypt(buf, buf2,
896 (unsigned long)lengths[testnum], &aes_ks2,
901 static int AES_ige_256_encrypt_loop(void *args)
903 loopargs_t *tempargs = (loopargs_t *)args;
904 unsigned char *buf = tempargs->buf;
905 unsigned char *buf2 = tempargs->buf2;
907 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
908 AES_ige_encrypt(buf, buf2,
909 (unsigned long)lengths[testnum], &aes_ks3,
914 static int CRYPTO_gcm128_aad_loop(void *args)
916 loopargs_t *tempargs = (loopargs_t *)args;
917 unsigned char *buf = tempargs->buf;
918 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
920 for (count = 0; COND(c[D_GHASH][testnum]); count++)
921 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
927 static int decrypt = 0;
928 static int EVP_Update_loop(void *args)
930 loopargs_t *tempargs = (loopargs_t *)args;
931 unsigned char *buf = tempargs->buf;
932 EVP_CIPHER_CTX *ctx = tempargs->ctx;
936 COND(save_count * 4 * lengths[0] / lengths[testnum]);
938 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
941 COND(save_count * 4 * lengths[0] / lengths[testnum]);
943 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
945 EVP_DecryptFinal_ex(ctx, buf, &outl);
947 EVP_EncryptFinal_ex(ctx, buf, &outl);
951 static const EVP_MD *evp_md = NULL;
952 static int EVP_Digest_loop(void *args)
954 loopargs_t *tempargs = (loopargs_t *)args;
955 unsigned char *buf = tempargs->buf;
956 unsigned char md[EVP_MAX_MD_SIZE];
959 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
960 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
965 #ifndef OPENSSL_NO_RSA
966 static unsigned rsa_num;
967 static RSA *rsa_key[RSA_NUM];
968 static long rsa_c[RSA_NUM][2];
970 static int RSA_sign_loop(void *args)
972 loopargs_t *tempargs = (loopargs_t *)args;
973 unsigned char *buf = tempargs->buf;
974 unsigned char *buf2 = tempargs->buf2;
976 for (count = 0; COND(rsa_c[testnum][0]); count++) {
977 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[testnum]);
979 BIO_printf(bio_err, "RSA sign failure\n");
980 ERR_print_errors(bio_err);
988 static int RSA_verify_loop(void *args)
990 loopargs_t *tempargs = (loopargs_t *)args;
991 unsigned char *buf = tempargs->buf;
992 unsigned char *buf2 = tempargs->buf2;
994 for (count = 0; COND(rsa_c[testnum][1]); count++) {
995 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
997 BIO_printf(bio_err, "RSA verify failure\n");
998 ERR_print_errors(bio_err);
1007 #ifndef OPENSSL_NO_DSA
1008 static DSA *dsa_key[DSA_NUM];
1009 static long dsa_c[DSA_NUM][2];
1010 static int DSA_sign_loop(void *args)
1012 loopargs_t *tempargs = (loopargs_t *)args;
1013 unsigned char *buf = tempargs->buf;
1014 unsigned char *buf2 = tempargs->buf2;
1015 unsigned int *siglen = &(tempargs->siglen);
1017 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1018 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1020 BIO_printf(bio_err, "DSA sign failure\n");
1021 ERR_print_errors(bio_err);
1029 static int DSA_verify_loop(void *args)
1031 loopargs_t *tempargs = (loopargs_t *)args;
1032 unsigned char *buf = tempargs->buf;
1033 unsigned char *buf2 = tempargs->buf2;
1034 unsigned int siglen = tempargs->siglen;
1036 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1037 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1039 BIO_printf(bio_err, "DSA verify failure\n");
1040 ERR_print_errors(bio_err);
1049 #ifndef OPENSSL_NO_EC
1050 static EC_KEY *ecdsa[EC_NUM];
1051 static long ecdsa_c[EC_NUM][2];
1052 static int ECDSA_sign_loop(void *args)
1054 loopargs_t *tempargs = (loopargs_t *)args;
1055 unsigned char *buf = tempargs->buf;
1056 unsigned char *ecdsasig = tempargs->ecdsasig;
1057 unsigned int *ecdsasiglen = &(tempargs->siglen);
1059 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1060 ret = ECDSA_sign(0, buf, 20,
1061 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1063 BIO_printf(bio_err, "ECDSA sign failure\n");
1064 ERR_print_errors(bio_err);
1072 static int ECDSA_verify_loop(void *args)
1074 loopargs_t *tempargs = (loopargs_t *)args;
1075 unsigned char *buf = tempargs->buf;
1076 unsigned char *ecdsasig = tempargs->ecdsasig;
1077 unsigned int ecdsasiglen = tempargs->siglen;
1079 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1080 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1083 BIO_printf(bio_err, "ECDSA verify failure\n");
1084 ERR_print_errors(bio_err);
1092 static unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
1093 static EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
1095 static void *(*kdf) (const void *in, size_t inlen, void *out,
1098 static int ECDH_compute_key_loop(void *args)
1101 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1102 ECDH_compute_key(secret_a, outlen,
1103 EC_KEY_get0_public_key(ecdh_b[testnum]),
1104 ecdh_a[testnum], kdf);
1111 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1113 int job_op_count = 0;
1114 int total_op_count = 0;
1115 int num_inprogress = 0;
1121 if (0 == async_jobs) {
1122 return loop_function((void *)loopargs);
1125 for (i = 0; i < async_jobs && !error; i++) {
1126 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), &job_op_count,
1127 loop_function, (void *)(loopargs + i), sizeof(loopargs_t))) {
1132 if (job_op_count == -1) {
1135 total_op_count += job_op_count;
1140 BIO_printf(bio_err, "Failure in the job\n");
1141 ERR_print_errors(bio_err);
1147 while (num_inprogress > 0) {
1148 OSSL_ASYNC_FD job_fd = 0;
1149 #if defined(ASYNC_POSIX)
1150 OSSL_ASYNC_FD max_fd = 0;
1151 int select_result = 0;
1153 struct timeval select_timeout;
1154 FD_ZERO(&waitfdset);
1155 select_timeout.tv_sec=0;
1156 select_timeout.tv_usec=0;
1158 for (i = 0; i < async_jobs; i++) {
1159 if (loopargs[i].inprogress_job != NULL) {
1160 job_fd = ASYNC_get_wait_fd(loopargs[i].inprogress_job);
1161 FD_SET(job_fd, &waitfdset);
1162 if (job_fd > max_fd)
1166 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, &select_timeout);
1168 if (select_result == -1 && errno == EINTR)
1171 if (select_result == -1) {
1172 BIO_printf(bio_err, "Failure in the select\n");
1173 ERR_print_errors(bio_err);
1178 if (select_result == 0)
1181 #elif defined(ASYNC_WIN)
1185 for (i = 0; i < async_jobs; i++) {
1186 if (loopargs[i].inprogress_job == NULL)
1189 job_fd = ASYNC_get_wait_fd(loopargs[i].inprogress_job);
1191 #if defined(ASYNC_POSIX)
1192 if (!FD_ISSET(job_fd, &waitfdset))
1194 #elif defined(ASYNC_WIN)
1195 if (!PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1199 switch (ASYNC_start_job(&(loopargs[i].inprogress_job),
1200 &job_op_count, loop_function, (void *)(loopargs + i),
1201 sizeof(loopargs_t))) {
1205 if (job_op_count == -1) {
1208 total_op_count += job_op_count;
1211 loopargs[i].inprogress_job = NULL;
1216 loopargs[i].inprogress_job = NULL;
1217 BIO_printf(bio_err, "Failure in the job\n");
1218 ERR_print_errors(bio_err);
1225 return error ? -1 : total_op_count;
1228 int speed_main(int argc, char **argv)
1230 loopargs_t *loopargs = NULL;
1231 int loopargs_len = 0;
1233 const EVP_CIPHER *evp_cipher = NULL;
1236 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1237 int dsa_doit[DSA_NUM], rsa_doit[RSA_NUM];
1238 int ret = 1, i, k, misalign = 0;
1239 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
1244 /* What follows are the buffers and key material. */
1245 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1248 #ifndef OPENSSL_NO_RC5
1251 #ifndef OPENSSL_NO_RC2
1254 #ifndef OPENSSL_NO_IDEA
1255 IDEA_KEY_SCHEDULE idea_ks;
1257 #ifndef OPENSSL_NO_SEED
1258 SEED_KEY_SCHEDULE seed_ks;
1260 #ifndef OPENSSL_NO_BF
1263 #ifndef OPENSSL_NO_CAST
1266 static const unsigned char key16[16] = {
1267 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1268 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1270 #ifndef OPENSSL_NO_AES
1271 static const unsigned char key24[24] = {
1272 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1273 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1274 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1276 static const unsigned char key32[32] = {
1277 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1278 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1279 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1280 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1283 #ifndef OPENSSL_NO_CAMELLIA
1284 static const unsigned char ckey24[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 ckey32[32] = {
1290 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1291 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1292 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1293 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1295 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1297 #ifndef OPENSSL_NO_DES
1298 static DES_cblock key = {
1299 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1301 static DES_cblock key2 = {
1302 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1304 static DES_cblock key3 = {
1305 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1308 #ifndef OPENSSL_NO_RSA
1309 static unsigned int rsa_bits[RSA_NUM] = {
1310 512, 1024, 2048, 3072, 4096, 7680, 15360
1312 static unsigned char *rsa_data[RSA_NUM] = {
1313 test512, test1024, test2048, test3072, test4096, test7680, test15360
1315 static int rsa_data_length[RSA_NUM] = {
1316 sizeof(test512), sizeof(test1024),
1317 sizeof(test2048), sizeof(test3072),
1318 sizeof(test4096), sizeof(test7680),
1322 #ifndef OPENSSL_NO_DSA
1323 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1325 #ifndef OPENSSL_NO_EC
1327 * We only test over the following curves as they are representative, To
1328 * add tests over more curves, simply add the curve NID and curve name to
1329 * the following arrays and increase the EC_NUM value accordingly.
1331 static unsigned int test_curves[EC_NUM] = {
1333 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1334 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1336 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1337 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1338 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1343 static const char *test_curves_names[EC_NUM] = {
1345 "secp160r1", "nistp192", "nistp224",
1346 "nistp256", "nistp384", "nistp521",
1348 "nistk163", "nistk233", "nistk283",
1349 "nistk409", "nistk571", "nistb163",
1350 "nistb233", "nistb283", "nistb409",
1355 static int test_curves_bits[EC_NUM] = {
1361 571, 253 /* X25519 */
1364 #ifndef OPENSSL_NO_EC
1365 int ecdsa_doit[EC_NUM];
1366 int secret_size_a, secret_size_b;
1367 int ecdh_checks = 0;
1369 long ecdh_c[EC_NUM][2];
1370 int ecdh_doit[EC_NUM];
1373 memset(results, 0, sizeof(results));
1374 #ifndef OPENSSL_NO_DSA
1375 memset(dsa_key, 0, sizeof(dsa_key));
1377 #ifndef OPENSSL_NO_EC
1378 for (i = 0; i < EC_NUM; i++)
1380 for (i = 0; i < EC_NUM; i++)
1381 ecdh_a[i] = ecdh_b[i] = NULL;
1383 #ifndef OPENSSL_NO_RSA
1384 memset(rsa_key, 0, sizeof(rsa_key));
1385 for (i = 0; i < RSA_NUM; i++)
1389 memset(c, 0, sizeof(c));
1390 memset(DES_iv, 0, sizeof(DES_iv));
1391 memset(iv, 0, sizeof(iv));
1393 for (i = 0; i < ALGOR_NUM; i++)
1395 for (i = 0; i < RSA_NUM; i++)
1397 for (i = 0; i < DSA_NUM; i++)
1399 #ifndef OPENSSL_NO_EC
1400 for (i = 0; i < EC_NUM; i++)
1402 for (i = 0; i < EC_NUM; i++)
1408 prog = opt_init(argc, argv, speed_options);
1409 while ((o = opt_next()) != OPT_EOF) {
1414 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1417 opt_help(speed_options);
1424 evp_cipher = EVP_get_cipherbyname(opt_arg());
1425 if (evp_cipher == NULL)
1426 evp_md = EVP_get_digestbyname(opt_arg());
1427 if (evp_cipher == NULL && evp_md == NULL) {
1429 "%s: %s an unknown cipher or digest\n",
1440 * In a forked execution, an engine might need to be
1441 * initialised by each child process, not by the parent.
1442 * So store the name here and run setup_engine() later on.
1444 engine_id = opt_arg();
1448 multi = atoi(opt_arg());
1453 async_jobs = atoi(opt_arg());
1457 if (!opt_int(opt_arg(), &misalign))
1459 if (misalign > MISALIGN) {
1461 "%s: Maximum offset is %d\n", prog, MISALIGN);
1473 argc = opt_num_rest();
1476 /* Remaining arguments are algorithms. */
1477 for ( ; *argv; argv++) {
1478 if (found(*argv, doit_choices, &i)) {
1482 #ifndef OPENSSL_NO_DES
1483 if (strcmp(*argv, "des") == 0) {
1484 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1488 if (strcmp(*argv, "sha") == 0) {
1489 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1492 #ifndef OPENSSL_NO_RSA
1494 if (strcmp(*argv, "openssl") == 0) {
1495 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1499 if (strcmp(*argv, "rsa") == 0) {
1500 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1501 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1502 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1503 rsa_doit[R_RSA_15360] = 1;
1506 if (found(*argv, rsa_choices, &i)) {
1511 #ifndef OPENSSL_NO_DSA
1512 if (strcmp(*argv, "dsa") == 0) {
1513 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1514 dsa_doit[R_DSA_2048] = 1;
1517 if (found(*argv, dsa_choices, &i)) {
1522 #ifndef OPENSSL_NO_AES
1523 if (strcmp(*argv, "aes") == 0) {
1524 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1525 doit[D_CBC_256_AES] = 1;
1529 #ifndef OPENSSL_NO_CAMELLIA
1530 if (strcmp(*argv, "camellia") == 0) {
1531 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1532 doit[D_CBC_256_CML] = 1;
1536 #ifndef OPENSSL_NO_EC
1537 if (strcmp(*argv, "ecdsa") == 0) {
1538 for (i = 0; i < EC_NUM; i++)
1542 if (found(*argv, ecdsa_choices, &i)) {
1546 if (strcmp(*argv, "ecdh") == 0) {
1547 for (i = 0; i < EC_NUM; i++)
1551 if (found(*argv, ecdh_choices, &i)) {
1556 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1560 /* Initialize the job pool if async mode is enabled */
1561 if (async_jobs > 0) {
1562 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1563 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1568 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1569 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1570 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1572 for (i = 0; i < loopargs_len; ++i) {
1573 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1574 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1575 /* Align the start of buffers on a 64 byte boundary */
1576 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1577 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1581 if (multi && do_multi(multi))
1585 /* Initialize the engine after the fork */
1586 (void)setup_engine(engine_id, 0);
1588 /* No parameters; turn on everything. */
1589 if ((argc == 0) && !doit[D_EVP]) {
1590 for (i = 0; i < ALGOR_NUM; i++)
1593 for (i = 0; i < RSA_NUM; i++)
1595 for (i = 0; i < DSA_NUM; i++)
1597 #ifndef OPENSSL_NO_EC
1598 for (i = 0; i < EC_NUM; i++)
1600 for (i = 0; i < EC_NUM; i++)
1604 for (i = 0; i < ALGOR_NUM; i++)
1608 if (usertime == 0 && !mr)
1610 "You have chosen to measure elapsed time "
1611 "instead of user CPU time.\n");
1613 #ifndef OPENSSL_NO_RSA
1614 for (i = 0; i < RSA_NUM; i++) {
1615 const unsigned char *p;
1618 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1619 if (rsa_key[i] == NULL) {
1620 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1627 #ifndef OPENSSL_NO_DSA
1628 dsa_key[0] = get_dsa512();
1629 dsa_key[1] = get_dsa1024();
1630 dsa_key[2] = get_dsa2048();
1633 #ifndef OPENSSL_NO_DES
1634 DES_set_key_unchecked(&key, &sch);
1635 DES_set_key_unchecked(&key2, &sch2);
1636 DES_set_key_unchecked(&key3, &sch3);
1638 #ifndef OPENSSL_NO_AES
1639 AES_set_encrypt_key(key16, 128, &aes_ks1);
1640 AES_set_encrypt_key(key24, 192, &aes_ks2);
1641 AES_set_encrypt_key(key32, 256, &aes_ks3);
1643 #ifndef OPENSSL_NO_CAMELLIA
1644 Camellia_set_key(key16, 128, &camellia_ks1);
1645 Camellia_set_key(ckey24, 192, &camellia_ks2);
1646 Camellia_set_key(ckey32, 256, &camellia_ks3);
1648 #ifndef OPENSSL_NO_IDEA
1649 idea_set_encrypt_key(key16, &idea_ks);
1651 #ifndef OPENSSL_NO_SEED
1652 SEED_set_key(key16, &seed_ks);
1654 #ifndef OPENSSL_NO_RC4
1655 RC4_set_key(&rc4_ks, 16, key16);
1657 #ifndef OPENSSL_NO_RC2
1658 RC2_set_key(&rc2_ks, 16, key16, 128);
1660 #ifndef OPENSSL_NO_RC5
1661 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1663 #ifndef OPENSSL_NO_BF
1664 BF_set_key(&bf_ks, 16, key16);
1666 #ifndef OPENSSL_NO_CAST
1667 CAST_set_key(&cast_ks, 16, key16);
1669 #ifndef OPENSSL_NO_RSA
1670 memset(rsa_c, 0, sizeof(rsa_c));
1673 # ifndef OPENSSL_NO_DES
1674 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1680 for (it = count; it; it--)
1681 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1682 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1686 c[D_MD2][0] = count / 10;
1687 c[D_MDC2][0] = count / 10;
1688 c[D_MD4][0] = count;
1689 c[D_MD5][0] = count;
1690 c[D_HMAC][0] = count;
1691 c[D_SHA1][0] = count;
1692 c[D_RMD160][0] = count;
1693 c[D_RC4][0] = count * 5;
1694 c[D_CBC_DES][0] = count;
1695 c[D_EDE3_DES][0] = count / 3;
1696 c[D_CBC_IDEA][0] = count;
1697 c[D_CBC_SEED][0] = count;
1698 c[D_CBC_RC2][0] = count;
1699 c[D_CBC_RC5][0] = count;
1700 c[D_CBC_BF][0] = count;
1701 c[D_CBC_CAST][0] = count;
1702 c[D_CBC_128_AES][0] = count;
1703 c[D_CBC_192_AES][0] = count;
1704 c[D_CBC_256_AES][0] = count;
1705 c[D_CBC_128_CML][0] = count;
1706 c[D_CBC_192_CML][0] = count;
1707 c[D_CBC_256_CML][0] = count;
1708 c[D_SHA256][0] = count;
1709 c[D_SHA512][0] = count;
1710 c[D_WHIRLPOOL][0] = count;
1711 c[D_IGE_128_AES][0] = count;
1712 c[D_IGE_192_AES][0] = count;
1713 c[D_IGE_256_AES][0] = count;
1714 c[D_GHASH][0] = count;
1716 for (i = 1; i < SIZE_NUM; i++) {
1719 l0 = (long)lengths[0];
1720 l1 = (long)lengths[i];
1722 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1723 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1724 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1725 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1726 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1727 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1728 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1729 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1730 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1731 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1732 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1734 l0 = (long)lengths[i - 1];
1736 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1737 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1738 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1739 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1740 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1741 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1742 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1743 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1744 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1745 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1746 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1747 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1748 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1749 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1750 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1751 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1752 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1753 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1756 # ifndef OPENSSL_NO_RSA
1757 rsa_c[R_RSA_512][0] = count / 2000;
1758 rsa_c[R_RSA_512][1] = count / 400;
1759 for (i = 1; i < RSA_NUM; i++) {
1760 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1761 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1762 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1765 if (rsa_c[i][0] == 0) {
1773 # ifndef OPENSSL_NO_DSA
1774 dsa_c[R_DSA_512][0] = count / 1000;
1775 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1776 for (i = 1; i < DSA_NUM; i++) {
1777 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1778 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1779 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1782 if (dsa_c[i] == 0) {
1790 # ifndef OPENSSL_NO_EC
1791 ecdsa_c[R_EC_P160][0] = count / 1000;
1792 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1793 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1794 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1795 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1796 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1799 if (ecdsa_c[i] == 0) {
1805 ecdsa_c[R_EC_K163][0] = count / 1000;
1806 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1807 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1808 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1809 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1810 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1813 if (ecdsa_c[i] == 0) {
1819 ecdsa_c[R_EC_B163][0] = count / 1000;
1820 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1821 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1822 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1823 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1824 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1827 if (ecdsa_c[i] == 0) {
1834 ecdh_c[R_EC_P160][0] = count / 1000;
1835 ecdh_c[R_EC_P160][1] = count / 1000;
1836 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1837 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1838 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1839 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1842 if (ecdh_c[i] == 0) {
1848 ecdh_c[R_EC_K163][0] = count / 1000;
1849 ecdh_c[R_EC_K163][1] = count / 1000;
1850 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1851 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1852 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1853 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1856 if (ecdh_c[i] == 0) {
1862 ecdh_c[R_EC_B163][0] = count / 1000;
1863 ecdh_c[R_EC_B163][1] = count / 1000;
1864 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1865 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1866 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1867 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1870 if (ecdh_c[i] == 0) {
1879 /* not worth fixing */
1880 # error "You cannot disable DES on systems without SIGALRM."
1881 # endif /* OPENSSL_NO_DES */
1884 signal(SIGALRM, sig_done);
1886 #endif /* SIGALRM */
1888 #ifndef OPENSSL_NO_MD2
1890 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1891 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1893 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1895 print_result(D_MD2, testnum, count, d);
1899 #ifndef OPENSSL_NO_MDC2
1901 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1902 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1904 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1906 print_result(D_MDC2, testnum, count, d);
1911 #ifndef OPENSSL_NO_MD4
1913 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1914 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1916 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1918 print_result(D_MD4, testnum, count, d);
1923 #ifndef OPENSSL_NO_MD5
1925 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1926 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1928 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1930 print_result(D_MD5, testnum, count, d);
1935 #ifndef OPENSSL_NO_MD5
1937 for (i = 0; i < loopargs_len; ++i) {
1938 loopargs[i].hctx = HMAC_CTX_new();
1939 if (loopargs[i].hctx == NULL) {
1940 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1944 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1945 16, EVP_md5(), NULL);
1947 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1948 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1950 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1952 print_result(D_HMAC, testnum, count, d);
1954 for (i = 0; i < loopargs_len; ++i) {
1955 HMAC_CTX_free(loopargs[i].hctx);
1960 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1961 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1963 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1965 print_result(D_SHA1, testnum, count, d);
1968 if (doit[D_SHA256]) {
1969 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1970 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1972 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1974 print_result(D_SHA256, testnum, count, d);
1977 if (doit[D_SHA512]) {
1978 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1979 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1981 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1983 print_result(D_SHA512, testnum, count, d);
1987 #ifndef OPENSSL_NO_WHIRLPOOL
1988 if (doit[D_WHIRLPOOL]) {
1989 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1990 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1992 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1994 print_result(D_WHIRLPOOL, testnum, count, d);
1999 #ifndef OPENSSL_NO_RMD160
2000 if (doit[D_RMD160]) {
2001 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2002 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2004 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2006 print_result(D_RMD160, testnum, count, d);
2010 #ifndef OPENSSL_NO_RC4
2012 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2013 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2015 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2017 print_result(D_RC4, testnum, count, d);
2021 #ifndef OPENSSL_NO_DES
2022 if (doit[D_CBC_DES]) {
2023 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2024 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2026 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2028 print_result(D_CBC_DES, testnum, count, d);
2032 if (doit[D_EDE3_DES]) {
2033 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2034 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2036 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2038 print_result(D_EDE3_DES, testnum, count, d);
2042 #ifndef OPENSSL_NO_AES
2043 if (doit[D_CBC_128_AES]) {
2044 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2045 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2048 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2050 print_result(D_CBC_128_AES, testnum, count, d);
2053 if (doit[D_CBC_192_AES]) {
2054 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2055 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2058 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2060 print_result(D_CBC_192_AES, testnum, count, d);
2063 if (doit[D_CBC_256_AES]) {
2064 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2065 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2068 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2070 print_result(D_CBC_256_AES, testnum, count, d);
2074 if (doit[D_IGE_128_AES]) {
2075 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2076 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2079 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2081 print_result(D_IGE_128_AES, testnum, count, d);
2084 if (doit[D_IGE_192_AES]) {
2085 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2086 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2089 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2091 print_result(D_IGE_192_AES, testnum, count, d);
2094 if (doit[D_IGE_256_AES]) {
2095 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2096 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2099 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2101 print_result(D_IGE_256_AES, testnum, count, d);
2104 if (doit[D_GHASH]) {
2105 for (i = 0; i < loopargs_len; ++i) {
2106 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2107 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2110 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2111 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2113 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2115 print_result(D_GHASH, testnum, count, d);
2117 for (i = 0; i < loopargs_len; ++i)
2118 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2121 #ifndef OPENSSL_NO_CAMELLIA
2122 if (doit[D_CBC_128_CML]) {
2123 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2124 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2126 if (async_jobs > 0) {
2127 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2131 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2132 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2133 (unsigned long)lengths[testnum], &camellia_ks1,
2134 iv, CAMELLIA_ENCRYPT);
2136 print_result(D_CBC_128_CML, testnum, count, d);
2139 if (doit[D_CBC_192_CML]) {
2140 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2141 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2143 if (async_jobs > 0) {
2144 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2148 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2149 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2150 (unsigned long)lengths[testnum], &camellia_ks2,
2151 iv, CAMELLIA_ENCRYPT);
2153 print_result(D_CBC_192_CML, testnum, count, d);
2156 if (doit[D_CBC_256_CML]) {
2157 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2158 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2160 if (async_jobs > 0) {
2161 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2165 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2166 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2167 (unsigned long)lengths[testnum], &camellia_ks3,
2168 iv, CAMELLIA_ENCRYPT);
2170 print_result(D_CBC_256_CML, testnum, count, d);
2174 #ifndef OPENSSL_NO_IDEA
2175 if (doit[D_CBC_IDEA]) {
2176 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2177 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2178 if (async_jobs > 0) {
2179 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2183 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2184 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2185 (unsigned long)lengths[testnum], &idea_ks,
2188 print_result(D_CBC_IDEA, testnum, count, d);
2192 #ifndef OPENSSL_NO_SEED
2193 if (doit[D_CBC_SEED]) {
2194 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2195 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2196 if (async_jobs > 0) {
2197 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2201 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2202 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2203 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2205 print_result(D_CBC_SEED, testnum, count, d);
2209 #ifndef OPENSSL_NO_RC2
2210 if (doit[D_CBC_RC2]) {
2211 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2212 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2213 if (async_jobs > 0) {
2214 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2218 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2219 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2220 (unsigned long)lengths[testnum], &rc2_ks,
2223 print_result(D_CBC_RC2, testnum, count, d);
2227 #ifndef OPENSSL_NO_RC5
2228 if (doit[D_CBC_RC5]) {
2229 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2230 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2231 if (async_jobs > 0) {
2232 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2236 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2237 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2238 (unsigned long)lengths[testnum], &rc5_ks,
2241 print_result(D_CBC_RC5, testnum, count, d);
2245 #ifndef OPENSSL_NO_BF
2246 if (doit[D_CBC_BF]) {
2247 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2248 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2249 if (async_jobs > 0) {
2250 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2254 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2255 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2256 (unsigned long)lengths[testnum], &bf_ks,
2259 print_result(D_CBC_BF, testnum, count, d);
2263 #ifndef OPENSSL_NO_CAST
2264 if (doit[D_CBC_CAST]) {
2265 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2266 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2267 if (async_jobs > 0) {
2268 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2272 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2273 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2274 (unsigned long)lengths[testnum], &cast_ks,
2277 print_result(D_CBC_CAST, testnum, count, d);
2283 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2284 if (multiblock && evp_cipher) {
2286 (EVP_CIPHER_flags(evp_cipher) &
2287 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2288 BIO_printf(bio_err, "%s is not multi-block capable\n",
2289 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2292 if (async_jobs > 0) {
2293 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2296 multiblock_speed(evp_cipher);
2301 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2304 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2306 * -O3 -fschedule-insns messes up an optimization here!
2307 * names[D_EVP] somehow becomes NULL
2309 print_message(names[D_EVP], save_count, lengths[testnum]);
2311 for (k = 0; k < loopargs_len; k++) {
2312 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2314 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2316 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2317 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2321 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2323 for (k = 0; k < loopargs_len; k++) {
2324 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2328 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2329 print_message(names[D_EVP], save_count, lengths[testnum]);
2331 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2334 print_result(D_EVP, testnum, count, d);
2338 for (i = 0; i < loopargs_len; ++i)
2339 RAND_bytes(loopargs[i].buf, 36);
2341 #ifndef OPENSSL_NO_RSA
2342 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2344 if (!rsa_doit[testnum])
2346 for (i = 0; i < loopargs_len; ++i) {
2347 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2, &rsa_num, rsa_key[testnum]);
2353 "RSA sign failure. No RSA sign will be done.\n");
2354 ERR_print_errors(bio_err);
2357 pkey_print_message("private", "rsa",
2358 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2359 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2361 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2364 mr ? "+R1:%ld:%d:%.2f\n"
2365 : "%ld %d bit private RSA's in %.2fs\n",
2366 count, rsa_bits[testnum], d);
2367 rsa_results[testnum][0] = d / (double)count;
2371 for (i = 0; i < loopargs_len; ++i) {
2372 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2, rsa_num, rsa_key[testnum]);
2378 "RSA verify failure. No RSA verify will be done.\n");
2379 ERR_print_errors(bio_err);
2380 rsa_doit[testnum] = 0;
2382 pkey_print_message("public", "rsa",
2383 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2385 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2388 mr ? "+R2:%ld:%d:%.2f\n"
2389 : "%ld %d bit public RSA's in %.2fs\n",
2390 count, rsa_bits[testnum], d);
2391 rsa_results[testnum][1] = d / (double)count;
2394 if (rsa_count <= 1) {
2395 /* if longer than 10s, don't do any more */
2396 for (testnum++; testnum < RSA_NUM; testnum++)
2397 rsa_doit[testnum] = 0;
2402 for (i = 0; i < loopargs_len; ++i)
2403 RAND_bytes(loopargs[i].buf, 36);
2405 #ifndef OPENSSL_NO_DSA
2406 if (RAND_status() != 1) {
2407 RAND_seed(rnd_seed, sizeof rnd_seed);
2410 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2412 if (!dsa_doit[testnum])
2415 /* DSA_generate_key(dsa_key[testnum]); */
2416 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2417 for (i = 0; i < loopargs_len; ++i) {
2418 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2, &(loopargs[i].siglen), dsa_key[testnum]);
2424 "DSA sign failure. No DSA sign will be done.\n");
2425 ERR_print_errors(bio_err);
2428 pkey_print_message("sign", "dsa",
2429 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2431 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2434 mr ? "+R3:%ld:%d:%.2f\n"
2435 : "%ld %d bit DSA signs in %.2fs\n",
2436 count, dsa_bits[testnum], d);
2437 dsa_results[testnum][0] = d / (double)count;
2441 for (i = 0; i < loopargs_len; ++i) {
2442 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2, loopargs[i].siglen, dsa_key[testnum]);
2448 "DSA verify failure. No DSA verify will be done.\n");
2449 ERR_print_errors(bio_err);
2450 dsa_doit[testnum] = 0;
2452 pkey_print_message("verify", "dsa",
2453 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2455 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2458 mr ? "+R4:%ld:%d:%.2f\n"
2459 : "%ld %d bit DSA verify in %.2fs\n",
2460 count, dsa_bits[testnum], d);
2461 dsa_results[testnum][1] = d / (double)count;
2464 if (rsa_count <= 1) {
2465 /* if longer than 10s, don't do any more */
2466 for (testnum++; testnum < DSA_NUM; testnum++)
2467 dsa_doit[testnum] = 0;
2474 #ifndef OPENSSL_NO_EC
2475 if (RAND_status() != 1) {
2476 RAND_seed(rnd_seed, sizeof rnd_seed);
2479 for (testnum = 0; testnum < EC_NUM; testnum++) {
2482 if (!ecdsa_doit[testnum])
2483 continue; /* Ignore Curve */
2484 ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2485 if (ecdsa[testnum] == NULL) {
2486 BIO_printf(bio_err, "ECDSA failure.\n");
2487 ERR_print_errors(bio_err);
2490 EC_KEY_precompute_mult(ecdsa[testnum], NULL);
2491 /* Perform ECDSA signature test */
2492 EC_KEY_generate_key(ecdsa[testnum]);
2493 for (i = 0; i < loopargs_len; ++i) {
2494 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].ecdsasig, &(loopargs[i].siglen), ecdsa[testnum]);
2500 "ECDSA sign failure. No ECDSA sign will be done.\n");
2501 ERR_print_errors(bio_err);
2504 pkey_print_message("sign", "ecdsa",
2505 ecdsa_c[testnum][0],
2506 test_curves_bits[testnum], ECDSA_SECONDS);
2508 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2512 mr ? "+R5:%ld:%d:%.2f\n" :
2513 "%ld %d bit ECDSA signs in %.2fs \n",
2514 count, test_curves_bits[testnum], d);
2515 ecdsa_results[testnum][0] = d / (double)count;
2519 /* Perform ECDSA verification test */
2520 for (i = 0; i < loopargs_len; ++i) {
2521 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].ecdsasig, loopargs[i].siglen, ecdsa[testnum]);
2527 "ECDSA verify failure. No ECDSA verify will be done.\n");
2528 ERR_print_errors(bio_err);
2529 ecdsa_doit[testnum] = 0;
2531 pkey_print_message("verify", "ecdsa",
2532 ecdsa_c[testnum][1],
2533 test_curves_bits[testnum], ECDSA_SECONDS);
2535 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2538 mr ? "+R6:%ld:%d:%.2f\n"
2539 : "%ld %d bit ECDSA verify in %.2fs\n",
2540 count, test_curves_bits[testnum], d);
2541 ecdsa_results[testnum][1] = d / (double)count;
2544 if (rsa_count <= 1) {
2545 /* if longer than 10s, don't do any more */
2546 for (testnum++; testnum < EC_NUM; testnum++)
2547 ecdsa_doit[testnum] = 0;
2555 #ifndef OPENSSL_NO_EC
2556 if (RAND_status() != 1) {
2557 RAND_seed(rnd_seed, sizeof rnd_seed);
2560 for (testnum = 0; testnum < EC_NUM; testnum++) {
2561 if (!ecdh_doit[testnum])
2563 ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2564 ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2565 if ((ecdh_a[testnum] == NULL) || (ecdh_b[testnum] == NULL)) {
2566 BIO_printf(bio_err, "ECDH failure.\n");
2567 ERR_print_errors(bio_err);
2570 /* generate two ECDH key pairs */
2571 if (!EC_KEY_generate_key(ecdh_a[testnum]) ||
2572 !EC_KEY_generate_key(ecdh_b[testnum])) {
2573 BIO_printf(bio_err, "ECDH key generation failure.\n");
2574 ERR_print_errors(bio_err);
2578 * If field size is not more than 24 octets, then use SHA-1
2579 * hash of result; otherwise, use result (see section 4.8 of
2580 * draft-ietf-tls-ecc-03.txt).
2584 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[testnum]));
2585 if (field_size <= 24 * 8) {
2586 outlen = KDF1_SHA1_len;
2589 outlen = (field_size + 7) / 8;
2593 ECDH_compute_key(secret_a, outlen,
2594 EC_KEY_get0_public_key(ecdh_b[testnum]),
2595 ecdh_a[testnum], kdf);
2597 ECDH_compute_key(secret_b, outlen,
2598 EC_KEY_get0_public_key(ecdh_a[testnum]),
2599 ecdh_b[testnum], kdf);
2600 if (secret_size_a != secret_size_b)
2605 for (secret_idx = 0; (secret_idx < secret_size_a)
2606 && (ecdh_checks == 1); secret_idx++) {
2607 if (secret_a[secret_idx] != secret_b[secret_idx])
2611 if (ecdh_checks == 0) {
2612 BIO_printf(bio_err, "ECDH computations don't match.\n");
2613 ERR_print_errors(bio_err);
2617 pkey_print_message("", "ecdh",
2619 test_curves_bits[testnum], ECDH_SECONDS);
2621 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2624 mr ? "+R7:%ld:%d:%.2f\n" :
2625 "%ld %d-bit ECDH ops in %.2fs\n", count,
2626 test_curves_bits[testnum], d);
2627 ecdh_results[testnum][0] = d / (double)count;
2632 if (rsa_count <= 1) {
2633 /* if longer than 10s, don't do any more */
2634 for (testnum++; testnum < EC_NUM; testnum++)
2635 ecdh_doit[testnum] = 0;
2645 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2646 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2648 printf("%s ", BN_options());
2649 #ifndef OPENSSL_NO_MD2
2650 printf("%s ", MD2_options());
2652 #ifndef OPENSSL_NO_RC4
2653 printf("%s ", RC4_options());
2655 #ifndef OPENSSL_NO_DES
2656 printf("%s ", DES_options());
2658 #ifndef OPENSSL_NO_AES
2659 printf("%s ", AES_options());
2661 #ifndef OPENSSL_NO_IDEA
2662 printf("%s ", idea_options());
2664 #ifndef OPENSSL_NO_BF
2665 printf("%s ", BF_options());
2667 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2675 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2678 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2679 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2683 for (k = 0; k < ALGOR_NUM; k++) {
2687 printf("+F:%d:%s", k, names[k]);
2689 printf("%-13s", names[k]);
2690 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2691 if (results[k][testnum] > 10000 && !mr)
2692 printf(" %11.2fk", results[k][testnum] / 1e3);
2694 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2698 #ifndef OPENSSL_NO_RSA
2700 for (k = 0; k < RSA_NUM; k++) {
2703 if (testnum && !mr) {
2704 printf("%18ssign verify sign/s verify/s\n", " ");
2708 printf("+F2:%u:%u:%f:%f\n",
2709 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2711 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2712 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2713 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2716 #ifndef OPENSSL_NO_DSA
2718 for (k = 0; k < DSA_NUM; k++) {
2721 if (testnum && !mr) {
2722 printf("%18ssign verify sign/s verify/s\n", " ");
2726 printf("+F3:%u:%u:%f:%f\n",
2727 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2729 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2730 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2731 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2734 #ifndef OPENSSL_NO_EC
2736 for (k = 0; k < EC_NUM; k++) {
2739 if (testnum && !mr) {
2740 printf("%30ssign verify sign/s verify/s\n", " ");
2745 printf("+F4:%u:%u:%f:%f\n",
2746 k, test_curves_bits[k],
2747 ecdsa_results[k][0], ecdsa_results[k][1]);
2749 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2750 test_curves_bits[k],
2751 test_curves_names[k],
2752 ecdsa_results[k][0], ecdsa_results[k][1],
2753 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2757 #ifndef OPENSSL_NO_EC
2759 for (k = 0; k < EC_NUM; k++) {
2762 if (testnum && !mr) {
2763 printf("%30sop op/s\n", " ");
2767 printf("+F5:%u:%u:%f:%f\n",
2768 k, test_curves_bits[k],
2769 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2772 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2773 test_curves_bits[k],
2774 test_curves_names[k],
2775 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2782 ERR_print_errors(bio_err);
2783 for (i = 0; i < loopargs_len; ++i) {
2784 if (loopargs[i].buf_malloc != NULL)
2785 OPENSSL_free(loopargs[i].buf_malloc);
2786 if (loopargs[i].buf2_malloc != NULL)
2787 OPENSSL_free(loopargs[i].buf2_malloc);
2789 if (loopargs != NULL)
2790 OPENSSL_free(loopargs);
2791 #ifndef OPENSSL_NO_RSA
2792 for (i = 0; i < RSA_NUM; i++)
2793 RSA_free(rsa_key[i]);
2795 #ifndef OPENSSL_NO_DSA
2796 for (i = 0; i < DSA_NUM; i++)
2797 DSA_free(dsa_key[i]);
2800 #ifndef OPENSSL_NO_EC
2801 for (i = 0; i < EC_NUM; i++) {
2802 EC_KEY_free(ecdsa[i]);
2803 EC_KEY_free(ecdh_a[i]);
2804 EC_KEY_free(ecdh_b[i]);
2808 ASYNC_cleanup_thread();
2812 static void print_message(const char *s, long num, int length)
2816 mr ? "+DT:%s:%d:%d\n"
2817 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2818 (void)BIO_flush(bio_err);
2822 mr ? "+DN:%s:%ld:%d\n"
2823 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2824 (void)BIO_flush(bio_err);
2828 static void pkey_print_message(const char *str, const char *str2, long num,
2833 mr ? "+DTP:%d:%s:%s:%d\n"
2834 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2835 (void)BIO_flush(bio_err);
2839 mr ? "+DNP:%ld:%d:%s:%s\n"
2840 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2841 (void)BIO_flush(bio_err);
2845 static void print_result(int alg, int run_no, int count, double time_used)
2848 mr ? "+R:%d:%s:%f\n"
2849 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2850 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2854 static char *sstrsep(char **string, const char *delim)
2857 char *token = *string;
2862 memset(isdelim, 0, sizeof isdelim);
2866 isdelim[(unsigned char)(*delim)] = 1;
2870 while (!isdelim[(unsigned char)(**string)]) {
2882 static int do_multi(int multi)
2887 static char sep[] = ":";
2889 fds = malloc(sizeof(*fds) * multi);
2890 for (n = 0; n < multi; ++n) {
2891 if (pipe(fd) == -1) {
2892 BIO_printf(bio_err, "pipe failure\n");
2896 (void)BIO_flush(bio_err);
2903 if (dup(fd[1]) == -1) {
2904 BIO_printf(bio_err, "dup failed\n");
2913 printf("Forked child %d\n", n);
2916 /* for now, assume the pipe is long enough to take all the output */
2917 for (n = 0; n < multi; ++n) {
2922 f = fdopen(fds[n], "r");
2923 while (fgets(buf, sizeof buf, f)) {
2924 p = strchr(buf, '\n');
2927 if (buf[0] != '+') {
2928 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2932 printf("Got: %s from %d\n", buf, n);
2933 if (strncmp(buf, "+F:", 3) == 0) {
2938 alg = atoi(sstrsep(&p, sep));
2940 for (j = 0; j < SIZE_NUM; ++j)
2941 results[alg][j] += atof(sstrsep(&p, sep));
2942 } else if (strncmp(buf, "+F2:", 4) == 0) {
2947 k = atoi(sstrsep(&p, sep));
2950 d = atof(sstrsep(&p, sep));
2952 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2954 rsa_results[k][0] = d;
2956 d = atof(sstrsep(&p, sep));
2958 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2960 rsa_results[k][1] = d;
2962 # ifndef OPENSSL_NO_DSA
2963 else if (strncmp(buf, "+F3:", 4) == 0) {
2968 k = atoi(sstrsep(&p, sep));
2971 d = atof(sstrsep(&p, sep));
2973 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2975 dsa_results[k][0] = d;
2977 d = atof(sstrsep(&p, sep));
2979 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2981 dsa_results[k][1] = d;
2984 # ifndef OPENSSL_NO_EC
2985 else if (strncmp(buf, "+F4:", 4) == 0) {
2990 k = atoi(sstrsep(&p, sep));
2993 d = atof(sstrsep(&p, sep));
2995 ecdsa_results[k][0] =
2996 1 / (1 / ecdsa_results[k][0] + 1 / d);
2998 ecdsa_results[k][0] = d;
3000 d = atof(sstrsep(&p, sep));
3002 ecdsa_results[k][1] =
3003 1 / (1 / ecdsa_results[k][1] + 1 / d);
3005 ecdsa_results[k][1] = d;
3009 # ifndef OPENSSL_NO_EC
3010 else if (strncmp(buf, "+F5:", 4) == 0) {
3015 k = atoi(sstrsep(&p, sep));
3018 d = atof(sstrsep(&p, sep));
3020 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3022 ecdh_results[k][0] = d;
3027 else if (strncmp(buf, "+H:", 3) == 0) {
3030 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3040 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3042 static int mblengths[] =
3043 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3044 int j, count, num = OSSL_NELEM(mblengths);
3045 const char *alg_name;
3046 unsigned char *inp, *out, no_key[32], no_iv[16];
3047 EVP_CIPHER_CTX *ctx;
3050 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3051 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3052 ctx = EVP_CIPHER_CTX_new();
3053 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3054 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3056 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3058 for (j = 0; j < num; j++) {
3059 print_message(alg_name, 0, mblengths[j]);
3061 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3062 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3063 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3064 size_t len = mblengths[j];
3067 memset(aad, 0, 8); /* avoid uninitialized values */
3068 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3069 aad[9] = 3; /* version */
3071 aad[11] = 0; /* length */
3073 mb_param.out = NULL;
3076 mb_param.interleave = 8;
3078 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3079 sizeof(mb_param), &mb_param);
3085 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3086 sizeof(mb_param), &mb_param);
3090 RAND_bytes(out, 16);
3094 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3095 EVP_AEAD_TLS1_AAD_LEN, aad);
3096 EVP_Cipher(ctx, out, inp, len + pad);
3100 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3101 : "%d %s's in %.2fs\n", count, "evp", d);
3102 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3106 fprintf(stdout, "+H");
3107 for (j = 0; j < num; j++)
3108 fprintf(stdout, ":%d", mblengths[j]);
3109 fprintf(stdout, "\n");
3110 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3111 for (j = 0; j < num; j++)
3112 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3113 fprintf(stdout, "\n");
3116 "The 'numbers' are in 1000s of bytes per second processed.\n");
3117 fprintf(stdout, "type ");
3118 for (j = 0; j < num; j++)
3119 fprintf(stdout, "%7d bytes", mblengths[j]);
3120 fprintf(stdout, "\n");
3121 fprintf(stdout, "%-24s", alg_name);
3123 for (j = 0; j < num; j++) {
3124 if (results[D_EVP][j] > 10000)
3125 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3127 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3129 fprintf(stdout, "\n");
3134 EVP_CIPHER_CTX_free(ctx);