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
210 #define MAX_ECDH_SIZE 256
213 static volatile int run = 0;
216 static int usertime = 1;
218 typedef struct loopargs_st {
219 ASYNC_JOB *inprogress_job;
220 ASYNC_WAIT_CTX *wait_ctx;
223 unsigned char *buf_malloc;
224 unsigned char *buf2_malloc;
225 unsigned int *siglen;
226 #ifndef OPENSSL_NO_RSA
227 RSA *rsa_key[RSA_NUM];
229 #ifndef OPENSSL_NO_DSA
230 DSA *dsa_key[DSA_NUM];
232 #ifndef OPENSSL_NO_EC
233 EC_KEY *ecdsa[EC_NUM];
234 EC_KEY *ecdh_a[EC_NUM];
235 EC_KEY *ecdh_b[EC_NUM];
236 unsigned char *secret_a;
237 unsigned char *secret_b;
241 GCM128_CONTEXT *gcm_ctx;
244 #ifndef OPENSSL_NO_MD2
245 static int EVP_Digest_MD2_loop(void *args);
248 #ifndef OPENSSL_NO_MDC2
249 static int EVP_Digest_MDC2_loop(void *args);
251 #ifndef OPENSSL_NO_MD4
252 static int EVP_Digest_MD4_loop(void *args);
254 #ifndef OPENSSL_NO_MD5
255 static int MD5_loop(void *args);
256 static int HMAC_loop(void *args);
258 static int SHA1_loop(void *args);
259 static int SHA256_loop(void *args);
260 static int SHA512_loop(void *args);
261 #ifndef OPENSSL_NO_WHIRLPOOL
262 static int WHIRLPOOL_loop(void *args);
264 #ifndef OPENSSL_NO_RMD160
265 static int EVP_Digest_RMD160_loop(void *args);
267 #ifndef OPENSSL_NO_RC4
268 static int RC4_loop(void *args);
270 #ifndef OPENSSL_NO_DES
271 static int DES_ncbc_encrypt_loop(void *args);
272 static int DES_ede3_cbc_encrypt_loop(void *args);
274 #ifndef OPENSSL_NO_AES
275 static int AES_cbc_128_encrypt_loop(void *args);
276 static int AES_cbc_192_encrypt_loop(void *args);
277 static int AES_ige_128_encrypt_loop(void *args);
278 static int AES_cbc_256_encrypt_loop(void *args);
279 static int AES_ige_192_encrypt_loop(void *args);
280 static int AES_ige_256_encrypt_loop(void *args);
281 static int CRYPTO_gcm128_aad_loop(void *args);
283 static int EVP_Update_loop(void *args);
284 static int EVP_Digest_loop(void *args);
285 #ifndef OPENSSL_NO_RSA
286 static int RSA_sign_loop(void *args);
287 static int RSA_verify_loop(void *args);
289 #ifndef OPENSSL_NO_DSA
290 static int DSA_sign_loop(void *args);
291 static int DSA_verify_loop(void *args);
293 #ifndef OPENSSL_NO_EC
294 static int ECDSA_sign_loop(void *args);
295 static int ECDSA_verify_loop(void *args);
296 static int ECDH_compute_key_loop(void *args);
298 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
300 static double Time_F(int s);
301 static void print_message(const char *s, long num, int length);
302 static void pkey_print_message(const char *str, const char *str2,
303 long num, int bits, int sec);
304 static void print_result(int alg, int run_no, int count, double time_used);
306 static int do_multi(int multi);
309 static const char *names[ALGOR_NUM] = {
310 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
311 "des cbc", "des ede3", "idea cbc", "seed cbc",
312 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
313 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
314 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
315 "evp", "sha256", "sha512", "whirlpool",
316 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
319 static double results[ALGOR_NUM][SIZE_NUM];
320 static int lengths[SIZE_NUM] = {
321 16, 64, 256, 1024, 8 * 1024, 16 * 1024
324 #ifndef OPENSSL_NO_RSA
325 static double rsa_results[RSA_NUM][2];
327 #ifndef OPENSSL_NO_DSA
328 static double dsa_results[DSA_NUM][2];
330 #ifndef OPENSSL_NO_EC
331 static double ecdsa_results[EC_NUM][2];
332 static double ecdh_results[EC_NUM][1];
335 #if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
336 static const char rnd_seed[] =
337 "string to make the random number generator think it has entropy";
338 static int rnd_fake = 0;
342 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
343 # define SIGRETTYPE void
345 # define SIGRETTYPE int
348 static SIGRETTYPE sig_done(int sig);
349 static SIGRETTYPE sig_done(int sig)
351 signal(SIGALRM, sig_done);
361 # if !defined(SIGALRM)
364 static unsigned int lapse, schlock;
365 static void alarm_win32(unsigned int secs)
370 # define alarm alarm_win32
372 static DWORD WINAPI sleepy(VOID * arg)
380 static double Time_F(int s)
387 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
389 DWORD err = GetLastError();
390 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
394 Sleep(0); /* scheduler spinlock */
395 ret = app_tminterval(s, usertime);
397 ret = app_tminterval(s, usertime);
399 TerminateThread(thr, 0);
407 static double Time_F(int s)
409 double ret = app_tminterval(s, usertime);
416 #ifndef OPENSSL_NO_EC
417 static const int KDF1_SHA1_len = 20;
418 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
421 if (*outlen < SHA_DIGEST_LENGTH)
423 *outlen = SHA_DIGEST_LENGTH;
424 return SHA1(in, inlen, out);
426 #endif /* OPENSSL_NO_EC */
428 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
430 static int found(const char *name, const OPT_PAIR * pairs, int *result)
432 for (; pairs->name; pairs++)
433 if (strcmp(name, pairs->name) == 0) {
434 *result = pairs->retval;
440 typedef enum OPTION_choice {
441 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
442 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
443 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
446 OPTIONS speed_options[] = {
447 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
448 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
449 {"help", OPT_HELP, '-', "Display this summary"},
450 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
451 {"decrypt", OPT_DECRYPT, '-',
452 "Time decryption instead of encryption (only EVP)"},
453 {"mr", OPT_MR, '-', "Produce machine readable output"},
455 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
456 {"elapsed", OPT_ELAPSED, '-',
457 "Measure time in real time instead of CPU user time"},
459 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
462 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
464 #ifndef OPENSSL_NO_ENGINE
465 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
480 #define D_CBC_IDEA 10
481 #define D_CBC_SEED 11
485 #define D_CBC_CAST 15
486 #define D_CBC_128_AES 16
487 #define D_CBC_192_AES 17
488 #define D_CBC_256_AES 18
489 #define D_CBC_128_CML 19
490 #define D_CBC_192_CML 20
491 #define D_CBC_256_CML 21
495 #define D_WHIRLPOOL 25
496 #define D_IGE_128_AES 26
497 #define D_IGE_192_AES 27
498 #define D_IGE_256_AES 28
500 static OPT_PAIR doit_choices[] = {
501 #ifndef OPENSSL_NO_MD2
504 #ifndef OPENSSL_NO_MDC2
507 #ifndef OPENSSL_NO_MD4
510 #ifndef OPENSSL_NO_MD5
513 #ifndef OPENSSL_NO_MD5
517 {"sha256", D_SHA256},
518 {"sha512", D_SHA512},
519 #ifndef OPENSSL_NO_WHIRLPOOL
520 {"whirlpool", D_WHIRLPOOL},
522 #ifndef OPENSSL_NO_RMD160
523 {"ripemd", D_RMD160},
524 {"rmd160", D_RMD160},
525 {"ripemd160", D_RMD160},
527 #ifndef OPENSSL_NO_RC4
530 #ifndef OPENSSL_NO_DES
531 {"des-cbc", D_CBC_DES},
532 {"des-ede3", D_EDE3_DES},
534 #ifndef OPENSSL_NO_AES
535 {"aes-128-cbc", D_CBC_128_AES},
536 {"aes-192-cbc", D_CBC_192_AES},
537 {"aes-256-cbc", D_CBC_256_AES},
538 {"aes-128-ige", D_IGE_128_AES},
539 {"aes-192-ige", D_IGE_192_AES},
540 {"aes-256-ige", D_IGE_256_AES},
542 #ifndef OPENSSL_NO_RC2
543 {"rc2-cbc", D_CBC_RC2},
546 #ifndef OPENSSL_NO_RC5
547 {"rc5-cbc", D_CBC_RC5},
550 #ifndef OPENSSL_NO_IDEA
551 {"idea-cbc", D_CBC_IDEA},
552 {"idea", D_CBC_IDEA},
554 #ifndef OPENSSL_NO_SEED
555 {"seed-cbc", D_CBC_SEED},
556 {"seed", D_CBC_SEED},
558 #ifndef OPENSSL_NO_BF
559 {"bf-cbc", D_CBC_BF},
560 {"blowfish", D_CBC_BF},
563 #ifndef OPENSSL_NO_CAST
564 {"cast-cbc", D_CBC_CAST},
565 {"cast", D_CBC_CAST},
566 {"cast5", D_CBC_CAST},
575 static OPT_PAIR dsa_choices[] = {
576 {"dsa512", R_DSA_512},
577 {"dsa1024", R_DSA_1024},
578 {"dsa2048", R_DSA_2048},
588 #define R_RSA_15360 6
589 static OPT_PAIR rsa_choices[] = {
590 {"rsa512", R_RSA_512},
591 {"rsa1024", R_RSA_1024},
592 {"rsa2048", R_RSA_2048},
593 {"rsa3072", R_RSA_3072},
594 {"rsa4096", R_RSA_4096},
595 {"rsa7680", R_RSA_7680},
596 {"rsa15360", R_RSA_15360},
616 #define R_EC_X25519 16
617 #ifndef OPENSSL_NO_EC
618 static OPT_PAIR ecdsa_choices[] = {
619 {"ecdsap160", R_EC_P160},
620 {"ecdsap192", R_EC_P192},
621 {"ecdsap224", R_EC_P224},
622 {"ecdsap256", R_EC_P256},
623 {"ecdsap384", R_EC_P384},
624 {"ecdsap521", R_EC_P521},
625 {"ecdsak163", R_EC_K163},
626 {"ecdsak233", R_EC_K233},
627 {"ecdsak283", R_EC_K283},
628 {"ecdsak409", R_EC_K409},
629 {"ecdsak571", R_EC_K571},
630 {"ecdsab163", R_EC_B163},
631 {"ecdsab233", R_EC_B233},
632 {"ecdsab283", R_EC_B283},
633 {"ecdsab409", R_EC_B409},
634 {"ecdsab571", R_EC_B571},
637 static OPT_PAIR ecdh_choices[] = {
638 {"ecdhp160", R_EC_P160},
639 {"ecdhp192", R_EC_P192},
640 {"ecdhp224", R_EC_P224},
641 {"ecdhp256", R_EC_P256},
642 {"ecdhp384", R_EC_P384},
643 {"ecdhp521", R_EC_P521},
644 {"ecdhk163", R_EC_K163},
645 {"ecdhk233", R_EC_K233},
646 {"ecdhk283", R_EC_K283},
647 {"ecdhk409", R_EC_K409},
648 {"ecdhk571", R_EC_K571},
649 {"ecdhb163", R_EC_B163},
650 {"ecdhb233", R_EC_B233},
651 {"ecdhb283", R_EC_B283},
652 {"ecdhb409", R_EC_B409},
653 {"ecdhb571", R_EC_B571},
654 {"ecdhx25519", R_EC_X25519},
660 # define COND(d) (count < (d))
661 # define COUNT(d) (d)
663 # define COND(c) (run && count<0x7fffffff)
664 # define COUNT(d) (count)
668 static char *engine_id = NULL;
671 #ifndef OPENSSL_NO_MD2
672 static int EVP_Digest_MD2_loop(void *args)
674 loopargs_t *tempargs = (loopargs_t *)args;
675 unsigned char *buf = tempargs->buf;
676 unsigned char md2[MD2_DIGEST_LENGTH];
678 for (count = 0; COND(c[D_MD2][testnum]); count++)
679 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
685 #ifndef OPENSSL_NO_MDC2
686 static int EVP_Digest_MDC2_loop(void *args)
688 loopargs_t *tempargs = (loopargs_t *)args;
689 unsigned char *buf = tempargs->buf;
690 unsigned char mdc2[MDC2_DIGEST_LENGTH];
692 for (count = 0; COND(c[D_MDC2][testnum]); count++)
693 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
699 #ifndef OPENSSL_NO_MD4
700 static int EVP_Digest_MD4_loop(void *args)
702 loopargs_t *tempargs = (loopargs_t *)args;
703 unsigned char *buf = tempargs->buf;
704 unsigned char md4[MD4_DIGEST_LENGTH];
706 for (count = 0; COND(c[D_MD4][testnum]); count++)
707 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
708 NULL, EVP_md4(), NULL);
713 #ifndef OPENSSL_NO_MD5
714 static int MD5_loop(void *args)
716 loopargs_t *tempargs = (loopargs_t *)args;
717 unsigned char *buf = tempargs->buf;
718 unsigned char md5[MD5_DIGEST_LENGTH];
720 for (count = 0; COND(c[D_MD5][testnum]); count++)
721 MD5(buf, lengths[testnum], md5);
725 static int HMAC_loop(void *args)
727 loopargs_t *tempargs = (loopargs_t *)args;
728 unsigned char *buf = tempargs->buf;
729 HMAC_CTX *hctx = tempargs->hctx;
730 unsigned char hmac[MD5_DIGEST_LENGTH];
732 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
733 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
734 HMAC_Update(hctx, buf, lengths[testnum]);
735 HMAC_Final(hctx, &(hmac[0]), NULL);
741 static int SHA1_loop(void *args)
743 loopargs_t *tempargs = (loopargs_t *)args;
744 unsigned char *buf = tempargs->buf;
745 unsigned char sha[SHA_DIGEST_LENGTH];
747 for (count = 0; COND(c[D_SHA1][testnum]); count++)
748 SHA1(buf, lengths[testnum], sha);
752 static int SHA256_loop(void *args)
754 loopargs_t *tempargs = (loopargs_t *)args;
755 unsigned char *buf = tempargs->buf;
756 unsigned char sha256[SHA256_DIGEST_LENGTH];
758 for (count = 0; COND(c[D_SHA256][testnum]); count++)
759 SHA256(buf, lengths[testnum], sha256);
763 static int SHA512_loop(void *args)
765 loopargs_t *tempargs = (loopargs_t *)args;
766 unsigned char *buf = tempargs->buf;
767 unsigned char sha512[SHA512_DIGEST_LENGTH];
769 for (count = 0; COND(c[D_SHA512][testnum]); count++)
770 SHA512(buf, lengths[testnum], sha512);
774 #ifndef OPENSSL_NO_WHIRLPOOL
775 static int WHIRLPOOL_loop(void *args)
777 loopargs_t *tempargs = (loopargs_t *)args;
778 unsigned char *buf = tempargs->buf;
779 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
781 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
782 WHIRLPOOL(buf, lengths[testnum], whirlpool);
787 #ifndef OPENSSL_NO_RMD160
788 static int EVP_Digest_RMD160_loop(void *args)
790 loopargs_t *tempargs = (loopargs_t *)args;
791 unsigned char *buf = tempargs->buf;
792 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
794 for (count = 0; COND(c[D_RMD160][testnum]); count++)
795 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
796 EVP_ripemd160(), NULL);
801 #ifndef OPENSSL_NO_RC4
802 static RC4_KEY rc4_ks;
803 static int RC4_loop(void *args)
805 loopargs_t *tempargs = (loopargs_t *)args;
806 unsigned char *buf = tempargs->buf;
808 for (count = 0; COND(c[D_RC4][testnum]); count++)
809 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
814 #ifndef OPENSSL_NO_DES
815 static unsigned char DES_iv[8];
816 static DES_key_schedule sch;
817 static DES_key_schedule sch2;
818 static DES_key_schedule sch3;
819 static int DES_ncbc_encrypt_loop(void *args)
821 loopargs_t *tempargs = (loopargs_t *)args;
822 unsigned char *buf = tempargs->buf;
824 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
825 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
826 &DES_iv, DES_ENCRYPT);
830 static int DES_ede3_cbc_encrypt_loop(void *args)
832 loopargs_t *tempargs = (loopargs_t *)args;
833 unsigned char *buf = tempargs->buf;
835 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
836 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
838 &DES_iv, DES_ENCRYPT);
843 #ifndef OPENSSL_NO_AES
844 # define MAX_BLOCK_SIZE 128
846 # define MAX_BLOCK_SIZE 64
849 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
850 #ifndef OPENSSL_NO_AES
851 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
852 static int AES_cbc_128_encrypt_loop(void *args)
854 loopargs_t *tempargs = (loopargs_t *)args;
855 unsigned char *buf = tempargs->buf;
857 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
858 AES_cbc_encrypt(buf, buf,
859 (unsigned long)lengths[testnum], &aes_ks1,
864 static int AES_cbc_192_encrypt_loop(void *args)
866 loopargs_t *tempargs = (loopargs_t *)args;
867 unsigned char *buf = tempargs->buf;
869 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
870 AES_cbc_encrypt(buf, buf,
871 (unsigned long)lengths[testnum], &aes_ks2,
876 static int AES_cbc_256_encrypt_loop(void *args)
878 loopargs_t *tempargs = (loopargs_t *)args;
879 unsigned char *buf = tempargs->buf;
881 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
882 AES_cbc_encrypt(buf, buf,
883 (unsigned long)lengths[testnum], &aes_ks3,
888 static int AES_ige_128_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_128_AES][testnum]); count++)
895 AES_ige_encrypt(buf, buf2,
896 (unsigned long)lengths[testnum], &aes_ks1,
901 static int AES_ige_192_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_192_AES][testnum]); count++)
908 AES_ige_encrypt(buf, buf2,
909 (unsigned long)lengths[testnum], &aes_ks2,
914 static int AES_ige_256_encrypt_loop(void *args)
916 loopargs_t *tempargs = (loopargs_t *)args;
917 unsigned char *buf = tempargs->buf;
918 unsigned char *buf2 = tempargs->buf2;
920 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
921 AES_ige_encrypt(buf, buf2,
922 (unsigned long)lengths[testnum], &aes_ks3,
927 static int CRYPTO_gcm128_aad_loop(void *args)
929 loopargs_t *tempargs = (loopargs_t *)args;
930 unsigned char *buf = tempargs->buf;
931 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
933 for (count = 0; COND(c[D_GHASH][testnum]); count++)
934 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
940 static int decrypt = 0;
941 static int EVP_Update_loop(void *args)
943 loopargs_t *tempargs = (loopargs_t *)args;
944 unsigned char *buf = tempargs->buf;
945 EVP_CIPHER_CTX *ctx = tempargs->ctx;
949 COND(save_count * 4 * lengths[0] / lengths[testnum]);
951 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
954 COND(save_count * 4 * lengths[0] / lengths[testnum]);
956 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
958 EVP_DecryptFinal_ex(ctx, buf, &outl);
960 EVP_EncryptFinal_ex(ctx, buf, &outl);
964 static const EVP_MD *evp_md = NULL;
965 static int EVP_Digest_loop(void *args)
967 loopargs_t *tempargs = (loopargs_t *)args;
968 unsigned char *buf = tempargs->buf;
969 unsigned char md[EVP_MAX_MD_SIZE];
972 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
973 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
978 #ifndef OPENSSL_NO_RSA
979 static long rsa_c[RSA_NUM][2];
981 static int RSA_sign_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][0]); count++) {
990 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
992 BIO_printf(bio_err, "RSA sign failure\n");
993 ERR_print_errors(bio_err);
1001 static int RSA_verify_loop(void *args)
1003 loopargs_t *tempargs = (loopargs_t *)args;
1004 unsigned char *buf = tempargs->buf;
1005 unsigned char *buf2 = tempargs->buf2;
1006 unsigned int rsa_num = *(tempargs->siglen);
1007 RSA **rsa_key = tempargs->rsa_key;
1009 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1010 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1012 BIO_printf(bio_err, "RSA verify failure\n");
1013 ERR_print_errors(bio_err);
1022 #ifndef OPENSSL_NO_DSA
1023 static long dsa_c[DSA_NUM][2];
1024 static int DSA_sign_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][0]); count++) {
1033 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1035 BIO_printf(bio_err, "DSA sign failure\n");
1036 ERR_print_errors(bio_err);
1044 static int DSA_verify_loop(void *args)
1046 loopargs_t *tempargs = (loopargs_t *)args;
1047 unsigned char *buf = tempargs->buf;
1048 unsigned char *buf2 = tempargs->buf2;
1049 DSA **dsa_key = tempargs->dsa_key;
1050 unsigned int siglen = *(tempargs->siglen);
1052 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1053 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1055 BIO_printf(bio_err, "DSA verify failure\n");
1056 ERR_print_errors(bio_err);
1065 #ifndef OPENSSL_NO_EC
1066 static long ecdsa_c[EC_NUM][2];
1067 static int ECDSA_sign_loop(void *args)
1069 loopargs_t *tempargs = (loopargs_t *)args;
1070 unsigned char *buf = tempargs->buf;
1071 EC_KEY **ecdsa = tempargs->ecdsa;
1072 unsigned char *ecdsasig = tempargs->buf2;
1073 unsigned int *ecdsasiglen = tempargs->siglen;
1075 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1076 ret = ECDSA_sign(0, buf, 20,
1077 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1079 BIO_printf(bio_err, "ECDSA sign failure\n");
1080 ERR_print_errors(bio_err);
1088 static int ECDSA_verify_loop(void *args)
1090 loopargs_t *tempargs = (loopargs_t *)args;
1091 unsigned char *buf = tempargs->buf;
1092 EC_KEY **ecdsa = tempargs->ecdsa;
1093 unsigned char *ecdsasig = tempargs->buf2;
1094 unsigned int ecdsasiglen = *(tempargs->siglen);
1096 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1097 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1100 BIO_printf(bio_err, "ECDSA verify failure\n");
1101 ERR_print_errors(bio_err);
1110 static void *(*kdf) (const void *in, size_t inlen, void *out,
1113 static int ECDH_compute_key_loop(void *args)
1115 loopargs_t *tempargs = (loopargs_t *)args;
1116 EC_KEY **ecdh_a = tempargs->ecdh_a;
1117 EC_KEY **ecdh_b = tempargs->ecdh_b;
1118 unsigned char *secret_a = tempargs->secret_a;
1120 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1121 ECDH_compute_key(secret_a, outlen,
1122 EC_KEY_get0_public_key(ecdh_b[testnum]),
1123 ecdh_a[testnum], kdf);
1130 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1132 int job_op_count = 0;
1133 int total_op_count = 0;
1134 int num_inprogress = 0;
1137 OSSL_ASYNC_FD job_fd = 0;
1138 size_t num_job_fds = 0;
1139 #if defined(ASYNC_POSIX)
1141 OSSL_ASYNC_FD max_fd = 0;
1146 if (async_jobs == 0) {
1147 return loop_function((void *)loopargs);
1151 for (i = 0; i < async_jobs && !error; i++) {
1152 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1153 &job_op_count, loop_function,
1154 (void *)(loopargs + i), sizeof(loopargs_t))) {
1159 if (job_op_count == -1) {
1162 total_op_count += job_op_count;
1167 BIO_printf(bio_err, "Failure in the job\n");
1168 ERR_print_errors(bio_err);
1174 #if defined(ASYNC_POSIX)
1175 FD_ZERO(&waitfdset);
1177 /* Add to the wait set all the fds that are already in the WAIT_CTX
1178 * This is required when the same ctx is used multiple times
1179 * For the purpose of speed, each job can be associated to at most one fd
1181 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1182 if (loopargs[i].inprogress_job == NULL)
1185 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1186 || num_job_fds > 1) {
1187 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1188 ERR_print_errors(bio_err);
1192 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1193 FD_SET(job_fd, &waitfdset);
1194 if (job_fd > max_fd)
1199 while (num_inprogress > 0) {
1200 #if defined(ASYNC_POSIX)
1201 int select_result = 0;
1202 struct timeval select_timeout;
1203 select_timeout.tv_sec = 0;
1204 select_timeout.tv_usec = 0;
1206 for (i = 0; i < async_jobs; i++) {
1207 if (loopargs[i].inprogress_job != NULL) {
1208 /* Consider only changed fds to minimize the operations on waitfdset */
1209 OSSL_ASYNC_FD add_fd, del_fd;
1210 size_t num_add_fds, num_del_fds;
1211 if (!ASYNC_WAIT_CTX_get_changed_fds(loopargs[i].wait_ctx, NULL,
1212 &num_add_fds, NULL, &num_del_fds)) {
1213 BIO_printf(bio_err, "Failure in ASYNC_WAIT_CTX\n");
1214 ERR_print_errors(bio_err);
1218 if (num_add_fds > 1 || num_del_fds > 1) {
1219 BIO_printf(bio_err, "Too many fds have changed in ASYNC_WAIT_CTX\n");
1220 ERR_print_errors(bio_err);
1224 if (num_add_fds == 0 && num_del_fds == 0)
1227 ASYNC_WAIT_CTX_get_changed_fds(loopargs[i].wait_ctx, &add_fd, &num_add_fds,
1228 &del_fd, &num_del_fds);
1230 if (num_del_fds == 1)
1231 FD_CLR(del_fd, &waitfdset);
1233 if (num_add_fds == 1) {
1234 FD_SET(add_fd, &waitfdset);
1235 if (add_fd > max_fd)
1240 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, &select_timeout);
1242 if (select_result == -1 && errno == EINTR)
1245 if (select_result == -1) {
1246 BIO_printf(bio_err, "Failure in the select\n");
1247 ERR_print_errors(bio_err);
1252 if (select_result == 0)
1255 #elif defined(ASYNC_WIN)
1259 for (i = 0; i < async_jobs; i++) {
1260 if (loopargs[i].inprogress_job == NULL)
1263 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1264 || num_job_fds > 1) {
1265 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1266 ERR_print_errors(bio_err);
1270 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1272 #if defined(ASYNC_POSIX)
1273 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1275 #elif defined(ASYNC_WIN)
1276 if (num_job_fds == 1 &&
1277 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1281 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1282 &job_op_count, loop_function, (void *)(loopargs + i),
1283 sizeof(loopargs_t))) {
1287 if (job_op_count == -1) {
1290 total_op_count += job_op_count;
1293 #if defined(ASYNC_POSIX)
1294 FD_CLR(job_fd, &waitfdset);
1296 loopargs[i].inprogress_job = NULL;
1301 loopargs[i].inprogress_job = NULL;
1302 BIO_printf(bio_err, "Failure in the job\n");
1303 ERR_print_errors(bio_err);
1310 return error ? -1 : total_op_count;
1313 int speed_main(int argc, char **argv)
1315 loopargs_t *loopargs = NULL;
1316 int loopargs_len = 0;
1318 const EVP_CIPHER *evp_cipher = NULL;
1321 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1322 int dsa_doit[DSA_NUM], rsa_doit[RSA_NUM];
1323 int ret = 1, i, k, misalign = 0;
1324 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
1329 /* What follows are the buffers and key material. */
1330 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1333 #ifndef OPENSSL_NO_RC5
1336 #ifndef OPENSSL_NO_RC2
1339 #ifndef OPENSSL_NO_IDEA
1340 IDEA_KEY_SCHEDULE idea_ks;
1342 #ifndef OPENSSL_NO_SEED
1343 SEED_KEY_SCHEDULE seed_ks;
1345 #ifndef OPENSSL_NO_BF
1348 #ifndef OPENSSL_NO_CAST
1351 static const unsigned char key16[16] = {
1352 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1353 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1355 #ifndef OPENSSL_NO_AES
1356 static const unsigned char key24[24] = {
1357 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1358 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1359 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1361 static const unsigned char key32[32] = {
1362 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1363 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1364 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1365 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1368 #ifndef OPENSSL_NO_CAMELLIA
1369 static const unsigned char ckey24[24] = {
1370 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1371 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1372 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1374 static const unsigned char ckey32[32] = {
1375 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1376 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1377 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1378 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1380 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1382 #ifndef OPENSSL_NO_DES
1383 static DES_cblock key = {
1384 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1386 static DES_cblock key2 = {
1387 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1389 static DES_cblock key3 = {
1390 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1393 #ifndef OPENSSL_NO_RSA
1394 static unsigned int rsa_bits[RSA_NUM] = {
1395 512, 1024, 2048, 3072, 4096, 7680, 15360
1397 static unsigned char *rsa_data[RSA_NUM] = {
1398 test512, test1024, test2048, test3072, test4096, test7680, test15360
1400 static int rsa_data_length[RSA_NUM] = {
1401 sizeof(test512), sizeof(test1024),
1402 sizeof(test2048), sizeof(test3072),
1403 sizeof(test4096), sizeof(test7680),
1407 #ifndef OPENSSL_NO_DSA
1408 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1410 #ifndef OPENSSL_NO_EC
1412 * We only test over the following curves as they are representative, To
1413 * add tests over more curves, simply add the curve NID and curve name to
1414 * the following arrays and increase the EC_NUM value accordingly.
1416 static unsigned int test_curves[EC_NUM] = {
1418 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1419 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1421 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1422 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1423 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1428 static const char *test_curves_names[EC_NUM] = {
1430 "secp160r1", "nistp192", "nistp224",
1431 "nistp256", "nistp384", "nistp521",
1433 "nistk163", "nistk233", "nistk283",
1434 "nistk409", "nistk571", "nistb163",
1435 "nistb233", "nistb283", "nistb409",
1440 static int test_curves_bits[EC_NUM] = {
1446 571, 253 /* X25519 */
1449 #ifndef OPENSSL_NO_EC
1450 int ecdsa_doit[EC_NUM];
1451 int secret_size_a, secret_size_b;
1452 int ecdh_checks = 1;
1454 long ecdh_c[EC_NUM][2];
1455 int ecdh_doit[EC_NUM];
1458 memset(results, 0, sizeof(results));
1460 memset(c, 0, sizeof(c));
1461 memset(DES_iv, 0, sizeof(DES_iv));
1462 memset(iv, 0, sizeof(iv));
1464 for (i = 0; i < ALGOR_NUM; i++)
1466 for (i = 0; i < RSA_NUM; i++)
1468 for (i = 0; i < DSA_NUM; i++)
1470 #ifndef OPENSSL_NO_EC
1471 for (i = 0; i < EC_NUM; i++)
1473 for (i = 0; i < EC_NUM; i++)
1479 prog = opt_init(argc, argv, speed_options);
1480 while ((o = opt_next()) != OPT_EOF) {
1485 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1488 opt_help(speed_options);
1495 evp_cipher = EVP_get_cipherbyname(opt_arg());
1496 if (evp_cipher == NULL)
1497 evp_md = EVP_get_digestbyname(opt_arg());
1498 if (evp_cipher == NULL && evp_md == NULL) {
1500 "%s: %s an unknown cipher or digest\n",
1511 * In a forked execution, an engine might need to be
1512 * initialised by each child process, not by the parent.
1513 * So store the name here and run setup_engine() later on.
1515 engine_id = opt_arg();
1519 multi = atoi(opt_arg());
1524 async_jobs = atoi(opt_arg());
1528 if (!opt_int(opt_arg(), &misalign))
1530 if (misalign > MISALIGN) {
1532 "%s: Maximum offset is %d\n", prog, MISALIGN);
1544 argc = opt_num_rest();
1547 /* Remaining arguments are algorithms. */
1548 for ( ; *argv; argv++) {
1549 if (found(*argv, doit_choices, &i)) {
1553 #ifndef OPENSSL_NO_DES
1554 if (strcmp(*argv, "des") == 0) {
1555 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1559 if (strcmp(*argv, "sha") == 0) {
1560 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1563 #ifndef OPENSSL_NO_RSA
1565 if (strcmp(*argv, "openssl") == 0) {
1566 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1570 if (strcmp(*argv, "rsa") == 0) {
1571 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1572 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1573 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1574 rsa_doit[R_RSA_15360] = 1;
1577 if (found(*argv, rsa_choices, &i)) {
1582 #ifndef OPENSSL_NO_DSA
1583 if (strcmp(*argv, "dsa") == 0) {
1584 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1585 dsa_doit[R_DSA_2048] = 1;
1588 if (found(*argv, dsa_choices, &i)) {
1593 #ifndef OPENSSL_NO_AES
1594 if (strcmp(*argv, "aes") == 0) {
1595 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1596 doit[D_CBC_256_AES] = 1;
1600 #ifndef OPENSSL_NO_CAMELLIA
1601 if (strcmp(*argv, "camellia") == 0) {
1602 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1603 doit[D_CBC_256_CML] = 1;
1607 #ifndef OPENSSL_NO_EC
1608 if (strcmp(*argv, "ecdsa") == 0) {
1609 for (i = 0; i < EC_NUM; i++)
1613 if (found(*argv, ecdsa_choices, &i)) {
1617 if (strcmp(*argv, "ecdh") == 0) {
1618 for (i = 0; i < EC_NUM; i++)
1622 if (found(*argv, ecdh_choices, &i)) {
1627 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1631 /* Initialize the job pool if async mode is enabled */
1632 if (async_jobs > 0) {
1633 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1634 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1639 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1640 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1641 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1643 for (i = 0; i < loopargs_len; i++) {
1644 if (async_jobs > 0) {
1645 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1646 if (loopargs[i].wait_ctx == NULL) {
1647 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1652 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1653 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1654 /* Align the start of buffers on a 64 byte boundary */
1655 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1656 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1657 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1658 #ifndef OPENSSL_NO_EC
1659 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1660 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1665 if (multi && do_multi(multi))
1669 /* Initialize the engine after the fork */
1670 (void)setup_engine(engine_id, 0);
1672 /* No parameters; turn on everything. */
1673 if ((argc == 0) && !doit[D_EVP]) {
1674 for (i = 0; i < ALGOR_NUM; i++)
1677 for (i = 0; i < RSA_NUM; i++)
1679 for (i = 0; i < DSA_NUM; i++)
1681 #ifndef OPENSSL_NO_EC
1682 for (i = 0; i < EC_NUM; i++)
1684 for (i = 0; i < EC_NUM; i++)
1688 for (i = 0; i < ALGOR_NUM; i++)
1692 if (usertime == 0 && !mr)
1694 "You have chosen to measure elapsed time "
1695 "instead of user CPU time.\n");
1697 #ifndef OPENSSL_NO_RSA
1698 for (i = 0; i < loopargs_len; i++) {
1699 for (k = 0; k < RSA_NUM; k++) {
1700 const unsigned char *p;
1703 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1704 if (loopargs[i].rsa_key[k] == NULL) {
1705 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1712 #ifndef OPENSSL_NO_DSA
1713 for (i = 0; i < loopargs_len; i++) {
1714 loopargs[i].dsa_key[0] = get_dsa512();
1715 loopargs[i].dsa_key[1] = get_dsa1024();
1716 loopargs[i].dsa_key[2] = get_dsa2048();
1719 #ifndef OPENSSL_NO_DES
1720 DES_set_key_unchecked(&key, &sch);
1721 DES_set_key_unchecked(&key2, &sch2);
1722 DES_set_key_unchecked(&key3, &sch3);
1724 #ifndef OPENSSL_NO_AES
1725 AES_set_encrypt_key(key16, 128, &aes_ks1);
1726 AES_set_encrypt_key(key24, 192, &aes_ks2);
1727 AES_set_encrypt_key(key32, 256, &aes_ks3);
1729 #ifndef OPENSSL_NO_CAMELLIA
1730 Camellia_set_key(key16, 128, &camellia_ks1);
1731 Camellia_set_key(ckey24, 192, &camellia_ks2);
1732 Camellia_set_key(ckey32, 256, &camellia_ks3);
1734 #ifndef OPENSSL_NO_IDEA
1735 idea_set_encrypt_key(key16, &idea_ks);
1737 #ifndef OPENSSL_NO_SEED
1738 SEED_set_key(key16, &seed_ks);
1740 #ifndef OPENSSL_NO_RC4
1741 RC4_set_key(&rc4_ks, 16, key16);
1743 #ifndef OPENSSL_NO_RC2
1744 RC2_set_key(&rc2_ks, 16, key16, 128);
1746 #ifndef OPENSSL_NO_RC5
1747 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1749 #ifndef OPENSSL_NO_BF
1750 BF_set_key(&bf_ks, 16, key16);
1752 #ifndef OPENSSL_NO_CAST
1753 CAST_set_key(&cast_ks, 16, key16);
1755 #ifndef OPENSSL_NO_RSA
1756 memset(rsa_c, 0, sizeof(rsa_c));
1759 # ifndef OPENSSL_NO_DES
1760 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1766 for (it = count; it; it--)
1767 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1768 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1772 c[D_MD2][0] = count / 10;
1773 c[D_MDC2][0] = count / 10;
1774 c[D_MD4][0] = count;
1775 c[D_MD5][0] = count;
1776 c[D_HMAC][0] = count;
1777 c[D_SHA1][0] = count;
1778 c[D_RMD160][0] = count;
1779 c[D_RC4][0] = count * 5;
1780 c[D_CBC_DES][0] = count;
1781 c[D_EDE3_DES][0] = count / 3;
1782 c[D_CBC_IDEA][0] = count;
1783 c[D_CBC_SEED][0] = count;
1784 c[D_CBC_RC2][0] = count;
1785 c[D_CBC_RC5][0] = count;
1786 c[D_CBC_BF][0] = count;
1787 c[D_CBC_CAST][0] = count;
1788 c[D_CBC_128_AES][0] = count;
1789 c[D_CBC_192_AES][0] = count;
1790 c[D_CBC_256_AES][0] = count;
1791 c[D_CBC_128_CML][0] = count;
1792 c[D_CBC_192_CML][0] = count;
1793 c[D_CBC_256_CML][0] = count;
1794 c[D_SHA256][0] = count;
1795 c[D_SHA512][0] = count;
1796 c[D_WHIRLPOOL][0] = count;
1797 c[D_IGE_128_AES][0] = count;
1798 c[D_IGE_192_AES][0] = count;
1799 c[D_IGE_256_AES][0] = count;
1800 c[D_GHASH][0] = count;
1802 for (i = 1; i < SIZE_NUM; i++) {
1805 l0 = (long)lengths[0];
1806 l1 = (long)lengths[i];
1808 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1809 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1810 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1811 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1812 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1813 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1814 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1815 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1816 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1817 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1818 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1820 l0 = (long)lengths[i - 1];
1822 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1823 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1824 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1825 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1826 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1827 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1828 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1829 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1830 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1831 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1832 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1833 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1834 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1835 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1836 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1837 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1838 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1839 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1842 # ifndef OPENSSL_NO_RSA
1843 rsa_c[R_RSA_512][0] = count / 2000;
1844 rsa_c[R_RSA_512][1] = count / 400;
1845 for (i = 1; i < RSA_NUM; i++) {
1846 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1847 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1848 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1851 if (rsa_c[i][0] == 0) {
1859 # ifndef OPENSSL_NO_DSA
1860 dsa_c[R_DSA_512][0] = count / 1000;
1861 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1862 for (i = 1; i < DSA_NUM; i++) {
1863 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1864 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1865 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1868 if (dsa_c[i] == 0) {
1876 # ifndef OPENSSL_NO_EC
1877 ecdsa_c[R_EC_P160][0] = count / 1000;
1878 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1879 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1880 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1881 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1882 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1885 if (ecdsa_c[i] == 0) {
1891 ecdsa_c[R_EC_K163][0] = count / 1000;
1892 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1893 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1894 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1895 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1896 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1899 if (ecdsa_c[i] == 0) {
1905 ecdsa_c[R_EC_B163][0] = count / 1000;
1906 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1907 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1908 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1909 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1910 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1913 if (ecdsa_c[i] == 0) {
1920 ecdh_c[R_EC_P160][0] = count / 1000;
1921 ecdh_c[R_EC_P160][1] = count / 1000;
1922 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1923 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1924 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1925 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1928 if (ecdh_c[i] == 0) {
1934 ecdh_c[R_EC_K163][0] = count / 1000;
1935 ecdh_c[R_EC_K163][1] = count / 1000;
1936 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1937 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1938 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1939 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1942 if (ecdh_c[i] == 0) {
1948 ecdh_c[R_EC_B163][0] = count / 1000;
1949 ecdh_c[R_EC_B163][1] = count / 1000;
1950 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1951 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1952 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1953 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1956 if (ecdh_c[i] == 0) {
1965 /* not worth fixing */
1966 # error "You cannot disable DES on systems without SIGALRM."
1967 # endif /* OPENSSL_NO_DES */
1970 signal(SIGALRM, sig_done);
1972 #endif /* SIGALRM */
1974 #ifndef OPENSSL_NO_MD2
1976 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1977 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1979 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1981 print_result(D_MD2, testnum, count, d);
1985 #ifndef OPENSSL_NO_MDC2
1987 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1988 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1990 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1992 print_result(D_MDC2, testnum, count, d);
1997 #ifndef OPENSSL_NO_MD4
1999 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2000 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
2002 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2004 print_result(D_MD4, testnum, count, d);
2009 #ifndef OPENSSL_NO_MD5
2011 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2012 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
2014 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2016 print_result(D_MD5, testnum, count, d);
2021 #ifndef OPENSSL_NO_MD5
2023 for (i = 0; i < loopargs_len; i++) {
2024 loopargs[i].hctx = HMAC_CTX_new();
2025 if (loopargs[i].hctx == NULL) {
2026 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2030 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
2031 16, EVP_md5(), NULL);
2033 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2034 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
2036 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2038 print_result(D_HMAC, testnum, count, d);
2040 for (i = 0; i < loopargs_len; i++) {
2041 HMAC_CTX_free(loopargs[i].hctx);
2046 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2047 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
2049 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2051 print_result(D_SHA1, testnum, count, d);
2054 if (doit[D_SHA256]) {
2055 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2056 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
2058 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2060 print_result(D_SHA256, testnum, count, d);
2063 if (doit[D_SHA512]) {
2064 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2065 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
2067 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2069 print_result(D_SHA512, testnum, count, d);
2073 #ifndef OPENSSL_NO_WHIRLPOOL
2074 if (doit[D_WHIRLPOOL]) {
2075 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2076 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
2078 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2080 print_result(D_WHIRLPOOL, testnum, count, d);
2085 #ifndef OPENSSL_NO_RMD160
2086 if (doit[D_RMD160]) {
2087 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2088 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
2090 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2092 print_result(D_RMD160, testnum, count, d);
2096 #ifndef OPENSSL_NO_RC4
2098 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2099 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2101 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2103 print_result(D_RC4, testnum, count, d);
2107 #ifndef OPENSSL_NO_DES
2108 if (doit[D_CBC_DES]) {
2109 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2110 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2112 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2114 print_result(D_CBC_DES, testnum, count, d);
2118 if (doit[D_EDE3_DES]) {
2119 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2120 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2122 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2124 print_result(D_EDE3_DES, testnum, count, d);
2128 #ifndef OPENSSL_NO_AES
2129 if (doit[D_CBC_128_AES]) {
2130 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2131 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2134 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2136 print_result(D_CBC_128_AES, testnum, count, d);
2139 if (doit[D_CBC_192_AES]) {
2140 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2141 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2144 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2146 print_result(D_CBC_192_AES, testnum, count, d);
2149 if (doit[D_CBC_256_AES]) {
2150 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2151 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2154 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2156 print_result(D_CBC_256_AES, testnum, count, d);
2160 if (doit[D_IGE_128_AES]) {
2161 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2162 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2165 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2167 print_result(D_IGE_128_AES, testnum, count, d);
2170 if (doit[D_IGE_192_AES]) {
2171 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2172 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2175 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2177 print_result(D_IGE_192_AES, testnum, count, d);
2180 if (doit[D_IGE_256_AES]) {
2181 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2182 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2185 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2187 print_result(D_IGE_256_AES, testnum, count, d);
2190 if (doit[D_GHASH]) {
2191 for (i = 0; i < loopargs_len; i++) {
2192 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2193 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2196 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2197 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2199 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2201 print_result(D_GHASH, testnum, count, d);
2203 for (i = 0; i < loopargs_len; i++)
2204 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2207 #ifndef OPENSSL_NO_CAMELLIA
2208 if (doit[D_CBC_128_CML]) {
2209 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2210 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2212 if (async_jobs > 0) {
2213 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2217 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2218 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2219 (unsigned long)lengths[testnum], &camellia_ks1,
2220 iv, CAMELLIA_ENCRYPT);
2222 print_result(D_CBC_128_CML, testnum, count, d);
2225 if (doit[D_CBC_192_CML]) {
2226 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2227 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2229 if (async_jobs > 0) {
2230 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2234 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2235 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2236 (unsigned long)lengths[testnum], &camellia_ks2,
2237 iv, CAMELLIA_ENCRYPT);
2239 print_result(D_CBC_192_CML, testnum, count, d);
2242 if (doit[D_CBC_256_CML]) {
2243 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2244 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2246 if (async_jobs > 0) {
2247 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2251 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2252 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2253 (unsigned long)lengths[testnum], &camellia_ks3,
2254 iv, CAMELLIA_ENCRYPT);
2256 print_result(D_CBC_256_CML, testnum, count, d);
2260 #ifndef OPENSSL_NO_IDEA
2261 if (doit[D_CBC_IDEA]) {
2262 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2263 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2264 if (async_jobs > 0) {
2265 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2269 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2270 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2271 (unsigned long)lengths[testnum], &idea_ks,
2274 print_result(D_CBC_IDEA, testnum, count, d);
2278 #ifndef OPENSSL_NO_SEED
2279 if (doit[D_CBC_SEED]) {
2280 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2281 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2282 if (async_jobs > 0) {
2283 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2287 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2288 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2289 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2291 print_result(D_CBC_SEED, testnum, count, d);
2295 #ifndef OPENSSL_NO_RC2
2296 if (doit[D_CBC_RC2]) {
2297 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2298 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2299 if (async_jobs > 0) {
2300 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2304 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2305 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2306 (unsigned long)lengths[testnum], &rc2_ks,
2309 print_result(D_CBC_RC2, testnum, count, d);
2313 #ifndef OPENSSL_NO_RC5
2314 if (doit[D_CBC_RC5]) {
2315 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2316 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2317 if (async_jobs > 0) {
2318 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2322 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2323 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2324 (unsigned long)lengths[testnum], &rc5_ks,
2327 print_result(D_CBC_RC5, testnum, count, d);
2331 #ifndef OPENSSL_NO_BF
2332 if (doit[D_CBC_BF]) {
2333 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2334 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2335 if (async_jobs > 0) {
2336 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2340 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2341 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2342 (unsigned long)lengths[testnum], &bf_ks,
2345 print_result(D_CBC_BF, testnum, count, d);
2349 #ifndef OPENSSL_NO_CAST
2350 if (doit[D_CBC_CAST]) {
2351 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2352 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2353 if (async_jobs > 0) {
2354 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2358 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2359 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2360 (unsigned long)lengths[testnum], &cast_ks,
2363 print_result(D_CBC_CAST, testnum, count, d);
2369 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2370 if (multiblock && evp_cipher) {
2372 (EVP_CIPHER_flags(evp_cipher) &
2373 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2374 BIO_printf(bio_err, "%s is not multi-block capable\n",
2375 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2378 if (async_jobs > 0) {
2379 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2382 multiblock_speed(evp_cipher);
2387 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2390 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2392 * -O3 -fschedule-insns messes up an optimization here!
2393 * names[D_EVP] somehow becomes NULL
2395 print_message(names[D_EVP], save_count, lengths[testnum]);
2397 for (k = 0; k < loopargs_len; k++) {
2398 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2400 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2402 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2403 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2407 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2409 for (k = 0; k < loopargs_len; k++) {
2410 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2414 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2415 print_message(names[D_EVP], save_count, lengths[testnum]);
2417 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2420 print_result(D_EVP, testnum, count, d);
2424 for (i = 0; i < loopargs_len; i++)
2425 RAND_bytes(loopargs[i].buf, 36);
2427 #ifndef OPENSSL_NO_RSA
2428 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2430 if (!rsa_doit[testnum])
2432 for (i = 0; i < loopargs_len; i++) {
2433 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2434 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2440 "RSA sign failure. No RSA sign will be done.\n");
2441 ERR_print_errors(bio_err);
2444 pkey_print_message("private", "rsa",
2445 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2446 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2448 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2451 mr ? "+R1:%ld:%d:%.2f\n"
2452 : "%ld %d bit private RSA's in %.2fs\n",
2453 count, rsa_bits[testnum], d);
2454 rsa_results[testnum][0] = d / (double)count;
2458 for (i = 0; i < loopargs_len; i++) {
2459 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2460 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2466 "RSA verify failure. No RSA verify will be done.\n");
2467 ERR_print_errors(bio_err);
2468 rsa_doit[testnum] = 0;
2470 pkey_print_message("public", "rsa",
2471 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2473 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2476 mr ? "+R2:%ld:%d:%.2f\n"
2477 : "%ld %d bit public RSA's in %.2fs\n",
2478 count, rsa_bits[testnum], d);
2479 rsa_results[testnum][1] = d / (double)count;
2482 if (rsa_count <= 1) {
2483 /* if longer than 10s, don't do any more */
2484 for (testnum++; testnum < RSA_NUM; testnum++)
2485 rsa_doit[testnum] = 0;
2490 for (i = 0; i < loopargs_len; i++)
2491 RAND_bytes(loopargs[i].buf, 36);
2493 #ifndef OPENSSL_NO_DSA
2494 if (RAND_status() != 1) {
2495 RAND_seed(rnd_seed, sizeof rnd_seed);
2498 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2500 if (!dsa_doit[testnum])
2503 /* DSA_generate_key(dsa_key[testnum]); */
2504 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2505 for (i = 0; i < loopargs_len; i++) {
2506 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2507 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2513 "DSA sign failure. No DSA sign will be done.\n");
2514 ERR_print_errors(bio_err);
2517 pkey_print_message("sign", "dsa",
2518 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2520 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2523 mr ? "+R3:%ld:%d:%.2f\n"
2524 : "%ld %d bit DSA signs in %.2fs\n",
2525 count, dsa_bits[testnum], d);
2526 dsa_results[testnum][0] = d / (double)count;
2530 for (i = 0; i < loopargs_len; i++) {
2531 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2532 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2538 "DSA verify failure. No DSA verify will be done.\n");
2539 ERR_print_errors(bio_err);
2540 dsa_doit[testnum] = 0;
2542 pkey_print_message("verify", "dsa",
2543 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2545 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2548 mr ? "+R4:%ld:%d:%.2f\n"
2549 : "%ld %d bit DSA verify in %.2fs\n",
2550 count, dsa_bits[testnum], d);
2551 dsa_results[testnum][1] = d / (double)count;
2554 if (rsa_count <= 1) {
2555 /* if longer than 10s, don't do any more */
2556 for (testnum++; testnum < DSA_NUM; testnum++)
2557 dsa_doit[testnum] = 0;
2564 #ifndef OPENSSL_NO_EC
2565 if (RAND_status() != 1) {
2566 RAND_seed(rnd_seed, sizeof rnd_seed);
2569 for (testnum = 0; testnum < EC_NUM; testnum++) {
2572 if (!ecdsa_doit[testnum])
2573 continue; /* Ignore Curve */
2574 for (i = 0; i < loopargs_len; i++) {
2575 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2576 if (loopargs[i].ecdsa[testnum] == NULL) {
2582 BIO_printf(bio_err, "ECDSA failure.\n");
2583 ERR_print_errors(bio_err);
2586 for (i = 0; i < loopargs_len; i++) {
2587 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2588 /* Perform ECDSA signature test */
2589 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2590 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2591 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2597 "ECDSA sign failure. No ECDSA sign will be done.\n");
2598 ERR_print_errors(bio_err);
2601 pkey_print_message("sign", "ecdsa",
2602 ecdsa_c[testnum][0],
2603 test_curves_bits[testnum], ECDSA_SECONDS);
2605 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2609 mr ? "+R5:%ld:%d:%.2f\n" :
2610 "%ld %d bit ECDSA signs in %.2fs \n",
2611 count, test_curves_bits[testnum], d);
2612 ecdsa_results[testnum][0] = d / (double)count;
2616 /* Perform ECDSA verification test */
2617 for (i = 0; i < loopargs_len; i++) {
2618 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2619 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2625 "ECDSA verify failure. No ECDSA verify will be done.\n");
2626 ERR_print_errors(bio_err);
2627 ecdsa_doit[testnum] = 0;
2629 pkey_print_message("verify", "ecdsa",
2630 ecdsa_c[testnum][1],
2631 test_curves_bits[testnum], ECDSA_SECONDS);
2633 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2636 mr ? "+R6:%ld:%d:%.2f\n"
2637 : "%ld %d bit ECDSA verify in %.2fs\n",
2638 count, test_curves_bits[testnum], d);
2639 ecdsa_results[testnum][1] = d / (double)count;
2642 if (rsa_count <= 1) {
2643 /* if longer than 10s, don't do any more */
2644 for (testnum++; testnum < EC_NUM; testnum++)
2645 ecdsa_doit[testnum] = 0;
2653 #ifndef OPENSSL_NO_EC
2654 if (RAND_status() != 1) {
2655 RAND_seed(rnd_seed, sizeof rnd_seed);
2658 for (testnum = 0; testnum < EC_NUM; testnum++) {
2659 if (!ecdh_doit[testnum])
2661 for (i = 0; i < loopargs_len; i++) {
2662 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2663 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2664 if (loopargs[i].ecdh_a[testnum] == NULL ||
2665 loopargs[i].ecdh_b[testnum] == NULL) {
2670 if (ecdh_checks == 0) {
2671 BIO_printf(bio_err, "ECDH failure.\n");
2672 ERR_print_errors(bio_err);
2675 for (i = 0; i < loopargs_len; i++) {
2676 /* generate two ECDH key pairs */
2677 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2678 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2679 BIO_printf(bio_err, "ECDH key generation failure.\n");
2680 ERR_print_errors(bio_err);
2685 * If field size is not more than 24 octets, then use SHA-1
2686 * hash of result; otherwise, use result (see section 4.8 of
2687 * draft-ietf-tls-ecc-03.txt).
2691 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2692 if (field_size <= 24 * 8) {
2693 outlen = KDF1_SHA1_len;
2696 outlen = (field_size + 7) / 8;
2700 ECDH_compute_key(loopargs[i].secret_a, outlen,
2701 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2702 loopargs[i].ecdh_a[testnum], kdf);
2704 ECDH_compute_key(loopargs[i].secret_b, outlen,
2705 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2706 loopargs[i].ecdh_b[testnum], kdf);
2707 if (secret_size_a != secret_size_b)
2712 for (secret_idx = 0; (secret_idx < secret_size_a)
2713 && (ecdh_checks == 1); secret_idx++) {
2714 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2718 if (ecdh_checks == 0) {
2719 BIO_printf(bio_err, "ECDH computations don't match.\n");
2720 ERR_print_errors(bio_err);
2725 if (ecdh_checks != 0) {
2726 pkey_print_message("", "ecdh",
2728 test_curves_bits[testnum], ECDH_SECONDS);
2730 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2733 mr ? "+R7:%ld:%d:%.2f\n" :
2734 "%ld %d-bit ECDH ops in %.2fs\n", count,
2735 test_curves_bits[testnum], d);
2736 ecdh_results[testnum][0] = d / (double)count;
2742 if (rsa_count <= 1) {
2743 /* if longer than 10s, don't do any more */
2744 for (testnum++; testnum < EC_NUM; testnum++)
2745 ecdh_doit[testnum] = 0;
2755 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2756 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2758 printf("%s ", BN_options());
2759 #ifndef OPENSSL_NO_MD2
2760 printf("%s ", MD2_options());
2762 #ifndef OPENSSL_NO_RC4
2763 printf("%s ", RC4_options());
2765 #ifndef OPENSSL_NO_DES
2766 printf("%s ", DES_options());
2768 #ifndef OPENSSL_NO_AES
2769 printf("%s ", AES_options());
2771 #ifndef OPENSSL_NO_IDEA
2772 printf("%s ", idea_options());
2774 #ifndef OPENSSL_NO_BF
2775 printf("%s ", BF_options());
2777 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2785 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2788 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2789 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2793 for (k = 0; k < ALGOR_NUM; k++) {
2797 printf("+F:%d:%s", k, names[k]);
2799 printf("%-13s", names[k]);
2800 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2801 if (results[k][testnum] > 10000 && !mr)
2802 printf(" %11.2fk", results[k][testnum] / 1e3);
2804 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2808 #ifndef OPENSSL_NO_RSA
2810 for (k = 0; k < RSA_NUM; k++) {
2813 if (testnum && !mr) {
2814 printf("%18ssign verify sign/s verify/s\n", " ");
2818 printf("+F2:%u:%u:%f:%f\n",
2819 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2821 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2822 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2823 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2826 #ifndef OPENSSL_NO_DSA
2828 for (k = 0; k < DSA_NUM; k++) {
2831 if (testnum && !mr) {
2832 printf("%18ssign verify sign/s verify/s\n", " ");
2836 printf("+F3:%u:%u:%f:%f\n",
2837 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2839 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2840 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2841 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2844 #ifndef OPENSSL_NO_EC
2846 for (k = 0; k < EC_NUM; k++) {
2849 if (testnum && !mr) {
2850 printf("%30ssign verify sign/s verify/s\n", " ");
2855 printf("+F4:%u:%u:%f:%f\n",
2856 k, test_curves_bits[k],
2857 ecdsa_results[k][0], ecdsa_results[k][1]);
2859 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2860 test_curves_bits[k],
2861 test_curves_names[k],
2862 ecdsa_results[k][0], ecdsa_results[k][1],
2863 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2867 #ifndef OPENSSL_NO_EC
2869 for (k = 0; k < EC_NUM; k++) {
2872 if (testnum && !mr) {
2873 printf("%30sop op/s\n", " ");
2877 printf("+F5:%u:%u:%f:%f\n",
2878 k, test_curves_bits[k],
2879 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2882 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2883 test_curves_bits[k],
2884 test_curves_names[k],
2885 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2892 ERR_print_errors(bio_err);
2893 for (i = 0; i < loopargs_len; i++) {
2894 OPENSSL_free(loopargs[i].buf_malloc);
2895 OPENSSL_free(loopargs[i].buf2_malloc);
2896 OPENSSL_free(loopargs[i].siglen);
2898 #ifndef OPENSSL_NO_RSA
2899 for (i = 0; i < loopargs_len; i++) {
2900 for (k = 0; k < RSA_NUM; k++)
2901 RSA_free(loopargs[i].rsa_key[k]);
2904 #ifndef OPENSSL_NO_DSA
2905 for (i = 0; i < loopargs_len; i++) {
2906 for (k = 0; k < DSA_NUM; k++)
2907 DSA_free(loopargs[i].dsa_key[k]);
2911 #ifndef OPENSSL_NO_EC
2912 for (i = 0; i < loopargs_len; i++) {
2913 for (k = 0; k < EC_NUM; k++) {
2914 EC_KEY_free(loopargs[i].ecdsa[k]);
2915 EC_KEY_free(loopargs[i].ecdh_a[k]);
2916 EC_KEY_free(loopargs[i].ecdh_b[k]);
2918 OPENSSL_free(loopargs[i].secret_a);
2919 OPENSSL_free(loopargs[i].secret_b);
2922 if (async_jobs > 0) {
2923 for (i = 0; i < loopargs_len; i++)
2924 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2926 ASYNC_cleanup_thread();
2928 OPENSSL_free(loopargs);
2932 static void print_message(const char *s, long num, int length)
2936 mr ? "+DT:%s:%d:%d\n"
2937 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2938 (void)BIO_flush(bio_err);
2942 mr ? "+DN:%s:%ld:%d\n"
2943 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2944 (void)BIO_flush(bio_err);
2948 static void pkey_print_message(const char *str, const char *str2, long num,
2953 mr ? "+DTP:%d:%s:%s:%d\n"
2954 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2955 (void)BIO_flush(bio_err);
2959 mr ? "+DNP:%ld:%d:%s:%s\n"
2960 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2961 (void)BIO_flush(bio_err);
2965 static void print_result(int alg, int run_no, int count, double time_used)
2968 mr ? "+R:%d:%s:%f\n"
2969 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2970 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2974 static char *sstrsep(char **string, const char *delim)
2977 char *token = *string;
2982 memset(isdelim, 0, sizeof isdelim);
2986 isdelim[(unsigned char)(*delim)] = 1;
2990 while (!isdelim[(unsigned char)(**string)]) {
3002 static int do_multi(int multi)
3007 static char sep[] = ":";
3009 fds = malloc(sizeof(*fds) * multi);
3010 for (n = 0; n < multi; ++n) {
3011 if (pipe(fd) == -1) {
3012 BIO_printf(bio_err, "pipe failure\n");
3016 (void)BIO_flush(bio_err);
3023 if (dup(fd[1]) == -1) {
3024 BIO_printf(bio_err, "dup failed\n");
3033 printf("Forked child %d\n", n);
3036 /* for now, assume the pipe is long enough to take all the output */
3037 for (n = 0; n < multi; ++n) {
3042 f = fdopen(fds[n], "r");
3043 while (fgets(buf, sizeof buf, f)) {
3044 p = strchr(buf, '\n');
3047 if (buf[0] != '+') {
3048 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
3052 printf("Got: %s from %d\n", buf, n);
3053 if (strncmp(buf, "+F:", 3) == 0) {
3058 alg = atoi(sstrsep(&p, sep));
3060 for (j = 0; j < SIZE_NUM; ++j)
3061 results[alg][j] += atof(sstrsep(&p, sep));
3062 } else if (strncmp(buf, "+F2:", 4) == 0) {
3067 k = atoi(sstrsep(&p, sep));
3070 d = atof(sstrsep(&p, sep));
3072 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
3074 rsa_results[k][0] = d;
3076 d = atof(sstrsep(&p, sep));
3078 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3080 rsa_results[k][1] = d;
3082 # ifndef OPENSSL_NO_DSA
3083 else if (strncmp(buf, "+F3:", 4) == 0) {
3088 k = atoi(sstrsep(&p, sep));
3091 d = atof(sstrsep(&p, sep));
3093 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3095 dsa_results[k][0] = d;
3097 d = atof(sstrsep(&p, sep));
3099 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3101 dsa_results[k][1] = d;
3104 # ifndef OPENSSL_NO_EC
3105 else if (strncmp(buf, "+F4:", 4) == 0) {
3110 k = atoi(sstrsep(&p, sep));
3113 d = atof(sstrsep(&p, sep));
3115 ecdsa_results[k][0] =
3116 1 / (1 / ecdsa_results[k][0] + 1 / d);
3118 ecdsa_results[k][0] = d;
3120 d = atof(sstrsep(&p, sep));
3122 ecdsa_results[k][1] =
3123 1 / (1 / ecdsa_results[k][1] + 1 / d);
3125 ecdsa_results[k][1] = d;
3129 # ifndef OPENSSL_NO_EC
3130 else if (strncmp(buf, "+F5:", 4) == 0) {
3135 k = atoi(sstrsep(&p, sep));
3138 d = atof(sstrsep(&p, sep));
3140 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3142 ecdh_results[k][0] = d;
3147 else if (strncmp(buf, "+H:", 3) == 0) {
3150 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3160 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3162 static int mblengths[] =
3163 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3164 int j, count, num = OSSL_NELEM(mblengths);
3165 const char *alg_name;
3166 unsigned char *inp, *out, no_key[32], no_iv[16];
3167 EVP_CIPHER_CTX *ctx;
3170 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3171 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3172 ctx = EVP_CIPHER_CTX_new();
3173 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3174 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3176 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3178 for (j = 0; j < num; j++) {
3179 print_message(alg_name, 0, mblengths[j]);
3181 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3182 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3183 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3184 size_t len = mblengths[j];
3187 memset(aad, 0, 8); /* avoid uninitialized values */
3188 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3189 aad[9] = 3; /* version */
3191 aad[11] = 0; /* length */
3193 mb_param.out = NULL;
3196 mb_param.interleave = 8;
3198 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3199 sizeof(mb_param), &mb_param);
3205 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3206 sizeof(mb_param), &mb_param);
3210 RAND_bytes(out, 16);
3214 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3215 EVP_AEAD_TLS1_AAD_LEN, aad);
3216 EVP_Cipher(ctx, out, inp, len + pad);
3220 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3221 : "%d %s's in %.2fs\n", count, "evp", d);
3222 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3226 fprintf(stdout, "+H");
3227 for (j = 0; j < num; j++)
3228 fprintf(stdout, ":%d", mblengths[j]);
3229 fprintf(stdout, "\n");
3230 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3231 for (j = 0; j < num; j++)
3232 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3233 fprintf(stdout, "\n");
3236 "The 'numbers' are in 1000s of bytes per second processed.\n");
3237 fprintf(stdout, "type ");
3238 for (j = 0; j < num; j++)
3239 fprintf(stdout, "%7d bytes", mblengths[j]);
3240 fprintf(stdout, "\n");
3241 fprintf(stdout, "%-24s", alg_name);
3243 for (j = 0; j < num; j++) {
3244 if (results[D_EVP][j] > 10000)
3245 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3247 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3249 fprintf(stdout, "\n");
3254 EVP_CIPHER_CTX_free(ctx);