2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* ====================================================================
11 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
13 * Portions of the attached software ("Contribution") are developed by
14 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
16 * The Contribution is licensed pursuant to the OpenSSL open source
17 * license provided above.
19 * The ECDH and ECDSA speed test software is originally written by
20 * Sumit Gupta of Sun Microsystems Laboratories.
26 #define PRIME_SECONDS 10
27 #define RSA_SECONDS 10
28 #define DSA_SECONDS 10
29 #define ECDSA_SECONDS 10
30 #define ECDH_SECONDS 10
37 #include <openssl/crypto.h>
38 #include <openssl/rand.h>
39 #include <openssl/err.h>
40 #include <openssl/evp.h>
41 #include <openssl/objects.h>
42 #include <openssl/async.h>
43 #if !defined(OPENSSL_SYS_MSDOS)
44 # include OPENSSL_UNISTD
51 #include <openssl/bn.h>
52 #ifndef OPENSSL_NO_DES
53 # include <openssl/des.h>
55 #include <openssl/aes.h>
56 #ifndef OPENSSL_NO_CAMELLIA
57 # include <openssl/camellia.h>
59 #ifndef OPENSSL_NO_MD2
60 # include <openssl/md2.h>
62 #ifndef OPENSSL_NO_MDC2
63 # include <openssl/mdc2.h>
65 #ifndef OPENSSL_NO_MD4
66 # include <openssl/md4.h>
68 #ifndef OPENSSL_NO_MD5
69 # include <openssl/md5.h>
71 #include <openssl/hmac.h>
72 #include <openssl/sha.h>
73 #ifndef OPENSSL_NO_RMD160
74 # include <openssl/ripemd.h>
76 #ifndef OPENSSL_NO_WHIRLPOOL
77 # include <openssl/whrlpool.h>
79 #ifndef OPENSSL_NO_RC4
80 # include <openssl/rc4.h>
82 #ifndef OPENSSL_NO_RC5
83 # include <openssl/rc5.h>
85 #ifndef OPENSSL_NO_RC2
86 # include <openssl/rc2.h>
88 #ifndef OPENSSL_NO_IDEA
89 # include <openssl/idea.h>
91 #ifndef OPENSSL_NO_SEED
92 # include <openssl/seed.h>
95 # include <openssl/blowfish.h>
97 #ifndef OPENSSL_NO_CAST
98 # include <openssl/cast.h>
100 #ifndef OPENSSL_NO_RSA
101 # include <openssl/rsa.h>
102 # include "./testrsa.h"
104 #include <openssl/x509.h>
105 #ifndef OPENSSL_NO_DSA
106 # include <openssl/dsa.h>
107 # include "./testdsa.h"
109 #ifndef OPENSSL_NO_EC
110 # include <openssl/ec.h>
112 #include <openssl/modes.h>
115 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
129 #define BUFSIZE (1024*16+1)
130 #define MAX_MISALIGNMENT 63
139 #define MAX_ECDH_SIZE 256
142 static volatile int run = 0;
145 static int usertime = 1;
147 typedef void *(*kdf_fn) (
148 const void *in, size_t inlen, void *out, size_t *xoutlen);
150 typedef struct loopargs_st {
151 ASYNC_JOB *inprogress_job;
152 ASYNC_WAIT_CTX *wait_ctx;
155 unsigned char *buf_malloc;
156 unsigned char *buf2_malloc;
158 #ifndef OPENSSL_NO_RSA
159 RSA *rsa_key[RSA_NUM];
161 #ifndef OPENSSL_NO_DSA
162 DSA *dsa_key[DSA_NUM];
164 #ifndef OPENSSL_NO_EC
165 EC_KEY *ecdsa[EC_NUM];
166 EC_KEY *ecdh_a[EC_NUM];
167 EC_KEY *ecdh_b[EC_NUM];
168 unsigned char *secret_a;
169 unsigned char *secret_b;
175 GCM128_CONTEXT *gcm_ctx;
178 #ifndef OPENSSL_NO_MD2
179 static int EVP_Digest_MD2_loop(void *args);
182 #ifndef OPENSSL_NO_MDC2
183 static int EVP_Digest_MDC2_loop(void *args);
185 #ifndef OPENSSL_NO_MD4
186 static int EVP_Digest_MD4_loop(void *args);
188 #ifndef OPENSSL_NO_MD5
189 static int MD5_loop(void *args);
190 static int HMAC_loop(void *args);
192 static int SHA1_loop(void *args);
193 static int SHA256_loop(void *args);
194 static int SHA512_loop(void *args);
195 #ifndef OPENSSL_NO_WHIRLPOOL
196 static int WHIRLPOOL_loop(void *args);
198 #ifndef OPENSSL_NO_RMD160
199 static int EVP_Digest_RMD160_loop(void *args);
201 #ifndef OPENSSL_NO_RC4
202 static int RC4_loop(void *args);
204 #ifndef OPENSSL_NO_DES
205 static int DES_ncbc_encrypt_loop(void *args);
206 static int DES_ede3_cbc_encrypt_loop(void *args);
208 static int AES_cbc_128_encrypt_loop(void *args);
209 static int AES_cbc_192_encrypt_loop(void *args);
210 static int AES_ige_128_encrypt_loop(void *args);
211 static int AES_cbc_256_encrypt_loop(void *args);
212 static int AES_ige_192_encrypt_loop(void *args);
213 static int AES_ige_256_encrypt_loop(void *args);
214 static int CRYPTO_gcm128_aad_loop(void *args);
215 static int EVP_Update_loop(void *args);
216 static int EVP_Digest_loop(void *args);
217 #ifndef OPENSSL_NO_RSA
218 static int RSA_sign_loop(void *args);
219 static int RSA_verify_loop(void *args);
221 #ifndef OPENSSL_NO_DSA
222 static int DSA_sign_loop(void *args);
223 static int DSA_verify_loop(void *args);
225 #ifndef OPENSSL_NO_EC
226 static int ECDSA_sign_loop(void *args);
227 static int ECDSA_verify_loop(void *args);
228 static int ECDH_compute_key_loop(void *args);
230 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
232 static double Time_F(int s);
233 static void print_message(const char *s, long num, int length);
234 static void pkey_print_message(const char *str, const char *str2,
235 long num, int bits, int sec);
236 static void print_result(int alg, int run_no, int count, double time_used);
238 static int do_multi(int multi);
241 static const char *names[ALGOR_NUM] = {
242 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
243 "des cbc", "des ede3", "idea cbc", "seed cbc",
244 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
245 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
246 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
247 "evp", "sha256", "sha512", "whirlpool",
248 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
251 static double results[ALGOR_NUM][SIZE_NUM];
253 static const int lengths[SIZE_NUM] = {
254 16, 64, 256, 1024, 8 * 1024, 16 * 1024
257 #ifndef OPENSSL_NO_RSA
258 static double rsa_results[RSA_NUM][2];
260 #ifndef OPENSSL_NO_DSA
261 static double dsa_results[DSA_NUM][2];
263 #ifndef OPENSSL_NO_EC
264 static double ecdsa_results[EC_NUM][2];
265 static double ecdh_results[EC_NUM][1];
268 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
269 static const char rnd_seed[] =
270 "string to make the random number generator think it has entropy";
274 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
275 # define SIGRETTYPE void
277 # define SIGRETTYPE int
280 static SIGRETTYPE sig_done(int sig);
281 static SIGRETTYPE sig_done(int sig)
283 signal(SIGALRM, sig_done);
293 # if !defined(SIGALRM)
296 static unsigned int lapse;
297 static volatile unsigned int schlock;
298 static void alarm_win32(unsigned int secs)
303 # define alarm alarm_win32
305 static DWORD WINAPI sleepy(VOID * arg)
313 static double Time_F(int s)
320 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
322 DWORD err = GetLastError();
323 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
327 Sleep(0); /* scheduler spinlock */
328 ret = app_tminterval(s, usertime);
330 ret = app_tminterval(s, usertime);
332 TerminateThread(thr, 0);
340 static double Time_F(int s)
342 double ret = app_tminterval(s, usertime);
349 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
351 static int found(const char *name, const OPT_PAIR *pairs, int *result)
353 for (; pairs->name; pairs++)
354 if (strcmp(name, pairs->name) == 0) {
355 *result = pairs->retval;
361 typedef enum OPTION_choice {
362 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
363 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
364 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
367 OPTIONS speed_options[] = {
368 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
369 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
370 {"help", OPT_HELP, '-', "Display this summary"},
371 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
372 {"decrypt", OPT_DECRYPT, '-',
373 "Time decryption instead of encryption (only EVP)"},
374 {"mr", OPT_MR, '-', "Produce machine readable output"},
376 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
377 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
378 {"elapsed", OPT_ELAPSED, '-',
379 "Measure time in real time instead of CPU user time"},
381 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
383 #ifndef OPENSSL_NO_ASYNC
384 {"async_jobs", OPT_ASYNCJOBS, 'p',
385 "Enable async mode and start pnum jobs"},
387 #ifndef OPENSSL_NO_ENGINE
388 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
403 #define D_CBC_IDEA 10
404 #define D_CBC_SEED 11
408 #define D_CBC_CAST 15
409 #define D_CBC_128_AES 16
410 #define D_CBC_192_AES 17
411 #define D_CBC_256_AES 18
412 #define D_CBC_128_CML 19
413 #define D_CBC_192_CML 20
414 #define D_CBC_256_CML 21
418 #define D_WHIRLPOOL 25
419 #define D_IGE_128_AES 26
420 #define D_IGE_192_AES 27
421 #define D_IGE_256_AES 28
423 static OPT_PAIR doit_choices[] = {
424 #ifndef OPENSSL_NO_MD2
427 #ifndef OPENSSL_NO_MDC2
430 #ifndef OPENSSL_NO_MD4
433 #ifndef OPENSSL_NO_MD5
438 {"sha256", D_SHA256},
439 {"sha512", D_SHA512},
440 #ifndef OPENSSL_NO_WHIRLPOOL
441 {"whirlpool", D_WHIRLPOOL},
443 #ifndef OPENSSL_NO_RMD160
444 {"ripemd", D_RMD160},
445 {"rmd160", D_RMD160},
446 {"ripemd160", D_RMD160},
448 #ifndef OPENSSL_NO_RC4
451 #ifndef OPENSSL_NO_DES
452 {"des-cbc", D_CBC_DES},
453 {"des-ede3", D_EDE3_DES},
455 {"aes-128-cbc", D_CBC_128_AES},
456 {"aes-192-cbc", D_CBC_192_AES},
457 {"aes-256-cbc", D_CBC_256_AES},
458 {"aes-128-ige", D_IGE_128_AES},
459 {"aes-192-ige", D_IGE_192_AES},
460 {"aes-256-ige", D_IGE_256_AES},
461 #ifndef OPENSSL_NO_RC2
462 {"rc2-cbc", D_CBC_RC2},
465 #ifndef OPENSSL_NO_RC5
466 {"rc5-cbc", D_CBC_RC5},
469 #ifndef OPENSSL_NO_IDEA
470 {"idea-cbc", D_CBC_IDEA},
471 {"idea", D_CBC_IDEA},
473 #ifndef OPENSSL_NO_SEED
474 {"seed-cbc", D_CBC_SEED},
475 {"seed", D_CBC_SEED},
477 #ifndef OPENSSL_NO_BF
478 {"bf-cbc", D_CBC_BF},
479 {"blowfish", D_CBC_BF},
482 #ifndef OPENSSL_NO_CAST
483 {"cast-cbc", D_CBC_CAST},
484 {"cast", D_CBC_CAST},
485 {"cast5", D_CBC_CAST},
491 #ifndef OPENSSL_NO_DSA
493 # define R_DSA_1024 1
494 # define R_DSA_2048 2
495 static OPT_PAIR dsa_choices[] = {
496 {"dsa512", R_DSA_512},
497 {"dsa1024", R_DSA_1024},
498 {"dsa2048", R_DSA_2048},
509 #define R_RSA_15360 6
510 static OPT_PAIR rsa_choices[] = {
511 {"rsa512", R_RSA_512},
512 {"rsa1024", R_RSA_1024},
513 {"rsa2048", R_RSA_2048},
514 {"rsa3072", R_RSA_3072},
515 {"rsa4096", R_RSA_4096},
516 {"rsa7680", R_RSA_7680},
517 {"rsa15360", R_RSA_15360},
537 #define R_EC_X25519 16
538 #ifndef OPENSSL_NO_EC
539 static OPT_PAIR ecdsa_choices[] = {
540 {"ecdsap160", R_EC_P160},
541 {"ecdsap192", R_EC_P192},
542 {"ecdsap224", R_EC_P224},
543 {"ecdsap256", R_EC_P256},
544 {"ecdsap384", R_EC_P384},
545 {"ecdsap521", R_EC_P521},
546 {"ecdsak163", R_EC_K163},
547 {"ecdsak233", R_EC_K233},
548 {"ecdsak283", R_EC_K283},
549 {"ecdsak409", R_EC_K409},
550 {"ecdsak571", R_EC_K571},
551 {"ecdsab163", R_EC_B163},
552 {"ecdsab233", R_EC_B233},
553 {"ecdsab283", R_EC_B283},
554 {"ecdsab409", R_EC_B409},
555 {"ecdsab571", R_EC_B571},
559 static OPT_PAIR ecdh_choices[] = {
560 {"ecdhp160", R_EC_P160},
561 {"ecdhp192", R_EC_P192},
562 {"ecdhp224", R_EC_P224},
563 {"ecdhp256", R_EC_P256},
564 {"ecdhp384", R_EC_P384},
565 {"ecdhp521", R_EC_P521},
566 {"ecdhk163", R_EC_K163},
567 {"ecdhk233", R_EC_K233},
568 {"ecdhk283", R_EC_K283},
569 {"ecdhk409", R_EC_K409},
570 {"ecdhk571", R_EC_K571},
571 {"ecdhb163", R_EC_B163},
572 {"ecdhb233", R_EC_B233},
573 {"ecdhb283", R_EC_B283},
574 {"ecdhb409", R_EC_B409},
575 {"ecdhb571", R_EC_B571},
576 {"ecdhx25519", R_EC_X25519},
582 # define COND(d) (count < (d))
583 # define COUNT(d) (d)
585 # define COND(unused_cond) (run && count<0x7fffffff)
586 # define COUNT(d) (count)
591 /* Nb of iterations to do per algorithm and key-size */
592 static long c[ALGOR_NUM][SIZE_NUM];
594 #ifndef OPENSSL_NO_MD2
595 static int EVP_Digest_MD2_loop(void *args)
597 loopargs_t *tempargs = *(loopargs_t **)args;
598 unsigned char *buf = tempargs->buf;
599 unsigned char md2[MD2_DIGEST_LENGTH];
602 for (count = 0; COND(c[D_MD2][testnum]); count++) {
603 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
611 #ifndef OPENSSL_NO_MDC2
612 static int EVP_Digest_MDC2_loop(void *args)
614 loopargs_t *tempargs = *(loopargs_t **)args;
615 unsigned char *buf = tempargs->buf;
616 unsigned char mdc2[MDC2_DIGEST_LENGTH];
619 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
620 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
628 #ifndef OPENSSL_NO_MD4
629 static int EVP_Digest_MD4_loop(void *args)
631 loopargs_t *tempargs = *(loopargs_t **)args;
632 unsigned char *buf = tempargs->buf;
633 unsigned char md4[MD4_DIGEST_LENGTH];
636 for (count = 0; COND(c[D_MD4][testnum]); count++) {
637 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
645 #ifndef OPENSSL_NO_MD5
646 static int MD5_loop(void *args)
648 loopargs_t *tempargs = *(loopargs_t **)args;
649 unsigned char *buf = tempargs->buf;
650 unsigned char md5[MD5_DIGEST_LENGTH];
652 for (count = 0; COND(c[D_MD5][testnum]); count++)
653 MD5(buf, lengths[testnum], md5);
657 static int HMAC_loop(void *args)
659 loopargs_t *tempargs = *(loopargs_t **)args;
660 unsigned char *buf = tempargs->buf;
661 HMAC_CTX *hctx = tempargs->hctx;
662 unsigned char hmac[MD5_DIGEST_LENGTH];
665 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
666 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
667 HMAC_Update(hctx, buf, lengths[testnum]);
668 HMAC_Final(hctx, hmac, NULL);
674 static int SHA1_loop(void *args)
676 loopargs_t *tempargs = *(loopargs_t **)args;
677 unsigned char *buf = tempargs->buf;
678 unsigned char sha[SHA_DIGEST_LENGTH];
680 for (count = 0; COND(c[D_SHA1][testnum]); count++)
681 SHA1(buf, lengths[testnum], sha);
685 static int SHA256_loop(void *args)
687 loopargs_t *tempargs = *(loopargs_t **)args;
688 unsigned char *buf = tempargs->buf;
689 unsigned char sha256[SHA256_DIGEST_LENGTH];
691 for (count = 0; COND(c[D_SHA256][testnum]); count++)
692 SHA256(buf, lengths[testnum], sha256);
696 static int SHA512_loop(void *args)
698 loopargs_t *tempargs = *(loopargs_t **)args;
699 unsigned char *buf = tempargs->buf;
700 unsigned char sha512[SHA512_DIGEST_LENGTH];
702 for (count = 0; COND(c[D_SHA512][testnum]); count++)
703 SHA512(buf, lengths[testnum], sha512);
707 #ifndef OPENSSL_NO_WHIRLPOOL
708 static int WHIRLPOOL_loop(void *args)
710 loopargs_t *tempargs = *(loopargs_t **)args;
711 unsigned char *buf = tempargs->buf;
712 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
714 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
715 WHIRLPOOL(buf, lengths[testnum], whirlpool);
720 #ifndef OPENSSL_NO_RMD160
721 static int EVP_Digest_RMD160_loop(void *args)
723 loopargs_t *tempargs = *(loopargs_t **)args;
724 unsigned char *buf = tempargs->buf;
725 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
727 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
728 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
729 NULL, EVP_ripemd160(), NULL))
736 #ifndef OPENSSL_NO_RC4
737 static RC4_KEY rc4_ks;
738 static int RC4_loop(void *args)
740 loopargs_t *tempargs = *(loopargs_t **)args;
741 unsigned char *buf = tempargs->buf;
743 for (count = 0; COND(c[D_RC4][testnum]); count++)
744 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
749 #ifndef OPENSSL_NO_DES
750 static unsigned char DES_iv[8];
751 static DES_key_schedule sch;
752 static DES_key_schedule sch2;
753 static DES_key_schedule sch3;
754 static int DES_ncbc_encrypt_loop(void *args)
756 loopargs_t *tempargs = *(loopargs_t **)args;
757 unsigned char *buf = tempargs->buf;
759 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
760 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
761 &DES_iv, DES_ENCRYPT);
765 static int DES_ede3_cbc_encrypt_loop(void *args)
767 loopargs_t *tempargs = *(loopargs_t **)args;
768 unsigned char *buf = tempargs->buf;
770 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
771 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
773 &DES_iv, DES_ENCRYPT);
778 #define MAX_BLOCK_SIZE 128
780 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
781 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
782 static int AES_cbc_128_encrypt_loop(void *args)
784 loopargs_t *tempargs = *(loopargs_t **)args;
785 unsigned char *buf = tempargs->buf;
787 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
788 AES_cbc_encrypt(buf, buf,
789 (size_t)lengths[testnum], &aes_ks1,
794 static int AES_cbc_192_encrypt_loop(void *args)
796 loopargs_t *tempargs = *(loopargs_t **)args;
797 unsigned char *buf = tempargs->buf;
799 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
800 AES_cbc_encrypt(buf, buf,
801 (size_t)lengths[testnum], &aes_ks2,
806 static int AES_cbc_256_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_256_AES][testnum]); count++)
812 AES_cbc_encrypt(buf, buf,
813 (size_t)lengths[testnum], &aes_ks3,
818 static int AES_ige_128_encrypt_loop(void *args)
820 loopargs_t *tempargs = *(loopargs_t **)args;
821 unsigned char *buf = tempargs->buf;
822 unsigned char *buf2 = tempargs->buf2;
824 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
825 AES_ige_encrypt(buf, buf2,
826 (size_t)lengths[testnum], &aes_ks1,
831 static int AES_ige_192_encrypt_loop(void *args)
833 loopargs_t *tempargs = *(loopargs_t **)args;
834 unsigned char *buf = tempargs->buf;
835 unsigned char *buf2 = tempargs->buf2;
837 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
838 AES_ige_encrypt(buf, buf2,
839 (size_t)lengths[testnum], &aes_ks2,
844 static int AES_ige_256_encrypt_loop(void *args)
846 loopargs_t *tempargs = *(loopargs_t **)args;
847 unsigned char *buf = tempargs->buf;
848 unsigned char *buf2 = tempargs->buf2;
850 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
851 AES_ige_encrypt(buf, buf2,
852 (size_t)lengths[testnum], &aes_ks3,
857 static int CRYPTO_gcm128_aad_loop(void *args)
859 loopargs_t *tempargs = *(loopargs_t **)args;
860 unsigned char *buf = tempargs->buf;
861 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
863 for (count = 0; COND(c[D_GHASH][testnum]); count++)
864 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
868 static long save_count = 0;
869 static int decrypt = 0;
870 static int EVP_Update_loop(void *args)
872 loopargs_t *tempargs = *(loopargs_t **)args;
873 unsigned char *buf = tempargs->buf;
874 EVP_CIPHER_CTX *ctx = tempargs->ctx;
877 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
880 for (count = 0; COND(nb_iter); count++)
881 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
883 for (count = 0; COND(nb_iter); count++)
884 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
886 EVP_DecryptFinal_ex(ctx, buf, &outl);
888 EVP_EncryptFinal_ex(ctx, buf, &outl);
892 static const EVP_MD *evp_md = NULL;
893 static int EVP_Digest_loop(void *args)
895 loopargs_t *tempargs = *(loopargs_t **)args;
896 unsigned char *buf = tempargs->buf;
897 unsigned char md[EVP_MAX_MD_SIZE];
900 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
903 for (count = 0; COND(nb_iter); count++) {
904 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
910 #ifndef OPENSSL_NO_RSA
911 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
913 static int RSA_sign_loop(void *args)
915 loopargs_t *tempargs = *(loopargs_t **)args;
916 unsigned char *buf = tempargs->buf;
917 unsigned char *buf2 = tempargs->buf2;
918 unsigned int *rsa_num = &tempargs->siglen;
919 RSA **rsa_key = tempargs->rsa_key;
921 for (count = 0; COND(rsa_c[testnum][0]); count++) {
922 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
924 BIO_printf(bio_err, "RSA sign failure\n");
925 ERR_print_errors(bio_err);
933 static int RSA_verify_loop(void *args)
935 loopargs_t *tempargs = *(loopargs_t **)args;
936 unsigned char *buf = tempargs->buf;
937 unsigned char *buf2 = tempargs->buf2;
938 unsigned int rsa_num = tempargs->siglen;
939 RSA **rsa_key = tempargs->rsa_key;
941 for (count = 0; COND(rsa_c[testnum][1]); count++) {
942 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
944 BIO_printf(bio_err, "RSA verify failure\n");
945 ERR_print_errors(bio_err);
954 #ifndef OPENSSL_NO_DSA
955 static long dsa_c[DSA_NUM][2];
956 static int DSA_sign_loop(void *args)
958 loopargs_t *tempargs = *(loopargs_t **)args;
959 unsigned char *buf = tempargs->buf;
960 unsigned char *buf2 = tempargs->buf2;
961 DSA **dsa_key = tempargs->dsa_key;
962 unsigned int *siglen = &tempargs->siglen;
964 for (count = 0; COND(dsa_c[testnum][0]); count++) {
965 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
967 BIO_printf(bio_err, "DSA sign failure\n");
968 ERR_print_errors(bio_err);
976 static int DSA_verify_loop(void *args)
978 loopargs_t *tempargs = *(loopargs_t **)args;
979 unsigned char *buf = tempargs->buf;
980 unsigned char *buf2 = tempargs->buf2;
981 DSA **dsa_key = tempargs->dsa_key;
982 unsigned int siglen = tempargs->siglen;
984 for (count = 0; COND(dsa_c[testnum][1]); count++) {
985 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
987 BIO_printf(bio_err, "DSA verify failure\n");
988 ERR_print_errors(bio_err);
997 #ifndef OPENSSL_NO_EC
998 static long ecdsa_c[EC_NUM][2];
999 static int ECDSA_sign_loop(void *args)
1001 loopargs_t *tempargs = *(loopargs_t **)args;
1002 unsigned char *buf = tempargs->buf;
1003 EC_KEY **ecdsa = tempargs->ecdsa;
1004 unsigned char *ecdsasig = tempargs->buf2;
1005 unsigned int *ecdsasiglen = &tempargs->siglen;
1007 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1008 ret = ECDSA_sign(0, buf, 20,
1009 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1011 BIO_printf(bio_err, "ECDSA sign failure\n");
1012 ERR_print_errors(bio_err);
1020 static int ECDSA_verify_loop(void *args)
1022 loopargs_t *tempargs = *(loopargs_t **)args;
1023 unsigned char *buf = tempargs->buf;
1024 EC_KEY **ecdsa = tempargs->ecdsa;
1025 unsigned char *ecdsasig = tempargs->buf2;
1026 unsigned int ecdsasiglen = tempargs->siglen;
1028 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1029 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1032 BIO_printf(bio_err, "ECDSA verify failure\n");
1033 ERR_print_errors(bio_err);
1041 /* ******************************************************************** */
1042 static long ecdh_c[EC_NUM][1];
1044 static int ECDH_compute_key_loop(void *args)
1046 loopargs_t *tempargs = *(loopargs_t **)args;
1047 EC_KEY **ecdh_a = tempargs->ecdh_a;
1048 EC_KEY **ecdh_b = tempargs->ecdh_b;
1049 unsigned char *secret_a = tempargs->secret_a;
1051 size_t outlen = tempargs->outlen;
1052 kdf_fn kdf = tempargs->kdf;
1054 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1055 ECDH_compute_key(secret_a, outlen,
1056 EC_KEY_get0_public_key(ecdh_b[testnum]),
1057 ecdh_a[testnum], kdf);
1062 static const size_t KDF1_SHA1_len = 20;
1063 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
1066 if (*outlen < SHA_DIGEST_LENGTH)
1068 *outlen = SHA_DIGEST_LENGTH;
1069 return SHA1(in, inlen, out);
1071 #endif /* OPENSSL_NO_EC */
1073 static int run_benchmark(int async_jobs,
1074 int (*loop_function)(void *), loopargs_t *loopargs)
1076 int job_op_count = 0;
1077 int total_op_count = 0;
1078 int num_inprogress = 0;
1079 int error = 0, i = 0, ret = 0;
1080 OSSL_ASYNC_FD job_fd = 0;
1081 size_t num_job_fds = 0;
1085 if (async_jobs == 0) {
1086 return loop_function((void *)&loopargs);
1089 for (i = 0; i < async_jobs && !error; i++) {
1090 loopargs_t *looparg_item = loopargs + i;
1092 /* Copy pointer content (looparg_t item address) into async context */
1093 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1094 &job_op_count, loop_function,
1095 (void *)&looparg_item, sizeof(looparg_item));
1101 if (job_op_count == -1) {
1104 total_op_count += job_op_count;
1109 BIO_printf(bio_err, "Failure in the job\n");
1110 ERR_print_errors(bio_err);
1116 while (num_inprogress > 0) {
1117 #if defined(OPENSSL_SYS_WINDOWS)
1119 #elif defined(OPENSSL_SYS_UNIX)
1120 int select_result = 0;
1121 OSSL_ASYNC_FD max_fd = 0;
1124 FD_ZERO(&waitfdset);
1126 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1127 if (loopargs[i].inprogress_job == NULL)
1130 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1131 || num_job_fds > 1) {
1132 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1133 ERR_print_errors(bio_err);
1137 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1138 FD_SET(job_fd, &waitfdset);
1139 if (job_fd > max_fd)
1143 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1145 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1146 "Decrease the value of async_jobs\n",
1147 max_fd, FD_SETSIZE);
1148 ERR_print_errors(bio_err);
1153 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1154 if (select_result == -1 && errno == EINTR)
1157 if (select_result == -1) {
1158 BIO_printf(bio_err, "Failure in the select\n");
1159 ERR_print_errors(bio_err);
1164 if (select_result == 0)
1168 for (i = 0; i < async_jobs; i++) {
1169 if (loopargs[i].inprogress_job == NULL)
1172 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1173 || num_job_fds > 1) {
1174 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1175 ERR_print_errors(bio_err);
1179 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1181 #if defined(OPENSSL_SYS_UNIX)
1182 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1184 #elif defined(OPENSSL_SYS_WINDOWS)
1185 if (num_job_fds == 1
1186 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1191 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1192 loopargs[i].wait_ctx, &job_op_count, loop_function,
1193 (void *)(loopargs + i), sizeof(loopargs_t));
1198 if (job_op_count == -1) {
1201 total_op_count += job_op_count;
1204 loopargs[i].inprogress_job = NULL;
1209 loopargs[i].inprogress_job = NULL;
1210 BIO_printf(bio_err, "Failure in the job\n");
1211 ERR_print_errors(bio_err);
1218 return error ? -1 : total_op_count;
1221 int speed_main(int argc, char **argv)
1224 loopargs_t *loopargs = NULL;
1226 int loopargs_len = 0;
1228 const char *engine_id = NULL;
1229 const EVP_CIPHER *evp_cipher = NULL;
1232 int multiblock = 0, pr_header = 0;
1233 int doit[ALGOR_NUM] = { 0 };
1234 int ret = 1, i, k, misalign = 0;
1239 unsigned int async_jobs = 0;
1240 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1241 || !defined(OPENSSL_NO_EC)
1246 /* What follows are the buffers and key material. */
1247 #ifndef OPENSSL_NO_RC5
1250 #ifndef OPENSSL_NO_RC2
1253 #ifndef OPENSSL_NO_IDEA
1254 IDEA_KEY_SCHEDULE idea_ks;
1256 #ifndef OPENSSL_NO_SEED
1257 SEED_KEY_SCHEDULE seed_ks;
1259 #ifndef OPENSSL_NO_BF
1262 #ifndef OPENSSL_NO_CAST
1265 static const unsigned char key16[16] = {
1266 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1267 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1269 static const unsigned char key24[24] = {
1270 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1271 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1272 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1274 static const unsigned char key32[32] = {
1275 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1276 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1277 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1278 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1280 #ifndef OPENSSL_NO_CAMELLIA
1281 static const unsigned char ckey24[24] = {
1282 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1283 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1284 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1286 static const unsigned char ckey32[32] = {
1287 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1288 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1289 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1290 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1292 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1294 #ifndef OPENSSL_NO_DES
1295 static DES_cblock key = {
1296 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1298 static DES_cblock key2 = {
1299 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1301 static DES_cblock key3 = {
1302 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1305 #ifndef OPENSSL_NO_RSA
1306 static const unsigned int rsa_bits[RSA_NUM] = {
1307 512, 1024, 2048, 3072, 4096, 7680, 15360
1309 static const unsigned char *rsa_data[RSA_NUM] = {
1310 test512, test1024, test2048, test3072, test4096, test7680, test15360
1312 static const int rsa_data_length[RSA_NUM] = {
1313 sizeof(test512), sizeof(test1024),
1314 sizeof(test2048), sizeof(test3072),
1315 sizeof(test4096), sizeof(test7680),
1318 int rsa_doit[RSA_NUM] = { 0 };
1320 #ifndef OPENSSL_NO_DSA
1321 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1322 int dsa_doit[DSA_NUM] = { 0 };
1324 #ifndef OPENSSL_NO_EC
1326 * We only test over the following curves as they are representative, To
1327 * add tests over more curves, simply add the curve NID and curve name to
1328 * the following arrays and increase the EC_NUM value accordingly.
1330 static const unsigned int test_curves[EC_NUM] = {
1332 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1333 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1335 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1336 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1337 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1342 static const char *test_curves_names[EC_NUM] = {
1344 "secp160r1", "nistp192", "nistp224",
1345 "nistp256", "nistp384", "nistp521",
1347 "nistk163", "nistk233", "nistk283",
1348 "nistk409", "nistk571", "nistb163",
1349 "nistb233", "nistb283", "nistb409",
1354 static const int test_curves_bits[EC_NUM] = {
1360 571, 253 /* X25519 */
1363 int ecdsa_doit[EC_NUM] = { 0 };
1364 int ecdh_doit[EC_NUM] = { 0 };
1365 #endif /* ndef OPENSSL_NO_EC */
1367 prog = opt_init(argc, argv, speed_options);
1368 while ((o = opt_next()) != OPT_EOF) {
1373 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1376 opt_help(speed_options);
1384 evp_cipher = EVP_get_cipherbyname(opt_arg());
1385 if (evp_cipher == NULL)
1386 evp_md = EVP_get_digestbyname(opt_arg());
1387 if (evp_cipher == NULL && evp_md == NULL) {
1389 "%s: %s is an unknown cipher or digest\n",
1400 * In a forked execution, an engine might need to be
1401 * initialised by each child process, not by the parent.
1402 * So store the name here and run setup_engine() later on.
1404 engine_id = opt_arg();
1408 multi = atoi(opt_arg());
1412 #ifndef OPENSSL_NO_ASYNC
1413 async_jobs = atoi(opt_arg());
1414 if (!ASYNC_is_capable()) {
1416 "%s: async_jobs specified but async not supported\n",
1420 if (async_jobs > 99999) {
1422 "%s: too many async_jobs\n",
1429 if (!opt_int(opt_arg(), &misalign))
1431 if (misalign > MISALIGN) {
1433 "%s: Maximum offset is %d\n", prog, MISALIGN);
1442 #ifdef OPENSSL_NO_MULTIBLOCK
1444 "%s: -mb specified but multi-block support is disabled\n",
1451 argc = opt_num_rest();
1454 /* Remaining arguments are algorithms. */
1455 for ( ; *argv; argv++) {
1456 if (found(*argv, doit_choices, &i)) {
1460 #ifndef OPENSSL_NO_DES
1461 if (strcmp(*argv, "des") == 0) {
1462 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1466 if (strcmp(*argv, "sha") == 0) {
1467 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1470 #ifndef OPENSSL_NO_RSA
1471 if (strcmp(*argv, "openssl") == 0)
1473 if (strcmp(*argv, "rsa") == 0) {
1474 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1475 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1476 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1477 rsa_doit[R_RSA_15360] = 1;
1480 if (found(*argv, rsa_choices, &i)) {
1485 #ifndef OPENSSL_NO_DSA
1486 if (strcmp(*argv, "dsa") == 0) {
1487 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1488 dsa_doit[R_DSA_2048] = 1;
1491 if (found(*argv, dsa_choices, &i)) {
1496 if (strcmp(*argv, "aes") == 0) {
1497 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1498 doit[D_CBC_256_AES] = 1;
1501 #ifndef OPENSSL_NO_CAMELLIA
1502 if (strcmp(*argv, "camellia") == 0) {
1503 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1504 doit[D_CBC_256_CML] = 1;
1508 #ifndef OPENSSL_NO_EC
1509 if (strcmp(*argv, "ecdsa") == 0) {
1510 for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++)
1511 ecdsa_doit[ecdsa_choices[loop].retval] = 1;
1514 if (found(*argv, ecdsa_choices, &i)) {
1518 if (strcmp(*argv, "ecdh") == 0) {
1519 for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++)
1520 ecdh_doit[ecdh_choices[loop].retval] = 1;
1523 if (found(*argv, ecdh_choices, &i)) {
1528 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1532 /* Initialize the job pool if async mode is enabled */
1533 if (async_jobs > 0) {
1534 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1536 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1541 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1542 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1543 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1545 for (i = 0; i < loopargs_len; i++) {
1546 if (async_jobs > 0) {
1547 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1548 if (loopargs[i].wait_ctx == NULL) {
1549 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1554 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1555 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1556 /* Align the start of buffers on a 64 byte boundary */
1557 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1558 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1559 #ifndef OPENSSL_NO_EC
1560 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1561 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1566 if (multi && do_multi(multi))
1570 /* Initialize the engine after the fork */
1571 e = setup_engine(engine_id, 0);
1573 /* No parameters; turn on everything. */
1574 if ((argc == 0) && !doit[D_EVP]) {
1575 for (i = 0; i < ALGOR_NUM; i++)
1578 #ifndef OPENSSL_NO_RSA
1579 for (i = 0; i < RSA_NUM; i++)
1582 #ifndef OPENSSL_NO_DSA
1583 for (i = 0; i < DSA_NUM; i++)
1586 #ifndef OPENSSL_NO_EC
1587 for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++)
1588 ecdsa_doit[ecdsa_choices[loop].retval] = 1;
1589 for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++)
1590 ecdh_doit[ecdh_choices[loop].retval] = 1;
1593 for (i = 0; i < ALGOR_NUM; i++)
1597 if (usertime == 0 && !mr)
1599 "You have chosen to measure elapsed time "
1600 "instead of user CPU time.\n");
1602 #ifndef OPENSSL_NO_RSA
1603 for (i = 0; i < loopargs_len; i++) {
1604 for (k = 0; k < RSA_NUM; k++) {
1605 const unsigned char *p;
1608 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1609 if (loopargs[i].rsa_key[k] == NULL) {
1610 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1617 #ifndef OPENSSL_NO_DSA
1618 for (i = 0; i < loopargs_len; i++) {
1619 loopargs[i].dsa_key[0] = get_dsa512();
1620 loopargs[i].dsa_key[1] = get_dsa1024();
1621 loopargs[i].dsa_key[2] = get_dsa2048();
1624 #ifndef OPENSSL_NO_DES
1625 DES_set_key_unchecked(&key, &sch);
1626 DES_set_key_unchecked(&key2, &sch2);
1627 DES_set_key_unchecked(&key3, &sch3);
1629 AES_set_encrypt_key(key16, 128, &aes_ks1);
1630 AES_set_encrypt_key(key24, 192, &aes_ks2);
1631 AES_set_encrypt_key(key32, 256, &aes_ks3);
1632 #ifndef OPENSSL_NO_CAMELLIA
1633 Camellia_set_key(key16, 128, &camellia_ks1);
1634 Camellia_set_key(ckey24, 192, &camellia_ks2);
1635 Camellia_set_key(ckey32, 256, &camellia_ks3);
1637 #ifndef OPENSSL_NO_IDEA
1638 IDEA_set_encrypt_key(key16, &idea_ks);
1640 #ifndef OPENSSL_NO_SEED
1641 SEED_set_key(key16, &seed_ks);
1643 #ifndef OPENSSL_NO_RC4
1644 RC4_set_key(&rc4_ks, 16, key16);
1646 #ifndef OPENSSL_NO_RC2
1647 RC2_set_key(&rc2_ks, 16, key16, 128);
1649 #ifndef OPENSSL_NO_RC5
1650 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1652 #ifndef OPENSSL_NO_BF
1653 BF_set_key(&bf_ks, 16, key16);
1655 #ifndef OPENSSL_NO_CAST
1656 CAST_set_key(&cast_ks, 16, key16);
1659 # ifndef OPENSSL_NO_DES
1660 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1666 for (it = count; it; it--)
1667 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1668 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1672 c[D_MD2][0] = count / 10;
1673 c[D_MDC2][0] = count / 10;
1674 c[D_MD4][0] = count;
1675 c[D_MD5][0] = count;
1676 c[D_HMAC][0] = count;
1677 c[D_SHA1][0] = count;
1678 c[D_RMD160][0] = count;
1679 c[D_RC4][0] = count * 5;
1680 c[D_CBC_DES][0] = count;
1681 c[D_EDE3_DES][0] = count / 3;
1682 c[D_CBC_IDEA][0] = count;
1683 c[D_CBC_SEED][0] = count;
1684 c[D_CBC_RC2][0] = count;
1685 c[D_CBC_RC5][0] = count;
1686 c[D_CBC_BF][0] = count;
1687 c[D_CBC_CAST][0] = count;
1688 c[D_CBC_128_AES][0] = count;
1689 c[D_CBC_192_AES][0] = count;
1690 c[D_CBC_256_AES][0] = count;
1691 c[D_CBC_128_CML][0] = count;
1692 c[D_CBC_192_CML][0] = count;
1693 c[D_CBC_256_CML][0] = count;
1694 c[D_SHA256][0] = count;
1695 c[D_SHA512][0] = count;
1696 c[D_WHIRLPOOL][0] = count;
1697 c[D_IGE_128_AES][0] = count;
1698 c[D_IGE_192_AES][0] = count;
1699 c[D_IGE_256_AES][0] = count;
1700 c[D_GHASH][0] = count;
1702 for (i = 1; i < SIZE_NUM; i++) {
1705 l0 = (long)lengths[0];
1706 l1 = (long)lengths[i];
1708 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1709 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1710 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1711 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1712 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1713 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1714 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1715 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1716 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1717 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1718 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1720 l0 = (long)lengths[i - 1];
1722 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1723 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1724 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1725 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1726 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1727 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1728 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1729 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1730 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1731 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1732 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1733 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1734 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1735 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1736 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1737 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1738 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1739 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1742 # ifndef OPENSSL_NO_RSA
1743 rsa_c[R_RSA_512][0] = count / 2000;
1744 rsa_c[R_RSA_512][1] = count / 400;
1745 for (i = 1; i < RSA_NUM; i++) {
1746 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1747 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1748 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1751 if (rsa_c[i][0] == 0) {
1752 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1759 # ifndef OPENSSL_NO_DSA
1760 dsa_c[R_DSA_512][0] = count / 1000;
1761 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1762 for (i = 1; i < DSA_NUM; i++) {
1763 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1764 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1765 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1768 if (dsa_c[i][0] == 0) {
1769 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1776 # ifndef OPENSSL_NO_EC
1777 ecdsa_c[R_EC_P160][0] = count / 1000;
1778 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1779 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1780 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1781 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1782 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1785 if (ecdsa_c[i][0] == 0) {
1791 ecdsa_c[R_EC_K163][0] = count / 1000;
1792 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1793 for (i = R_EC_K233; i <= R_EC_K571; 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] == 0) {
1805 ecdsa_c[R_EC_B163][0] = count / 1000;
1806 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1807 for (i = R_EC_B233; i <= R_EC_B571; 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] == 0) {
1820 ecdh_c[R_EC_P160][0] = count / 1000;
1821 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1822 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1823 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1826 if (ecdh_c[i][0] == 0) {
1831 ecdh_c[R_EC_K163][0] = count / 1000;
1832 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1833 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1834 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1837 if (ecdh_c[i][0] == 0) {
1842 ecdh_c[R_EC_B163][0] = count / 1000;
1843 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1844 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1845 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1848 if (ecdh_c[i][0] == 0) {
1856 /* not worth fixing */
1857 # error "You cannot disable DES on systems without SIGALRM."
1858 # endif /* OPENSSL_NO_DES */
1861 signal(SIGALRM, sig_done);
1863 #endif /* SIGALRM */
1865 #ifndef OPENSSL_NO_MD2
1867 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1868 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1870 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1872 print_result(D_MD2, testnum, count, d);
1876 #ifndef OPENSSL_NO_MDC2
1878 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1879 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1881 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1883 print_result(D_MDC2, testnum, count, d);
1888 #ifndef OPENSSL_NO_MD4
1890 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1891 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1893 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1895 print_result(D_MD4, testnum, count, d);
1900 #ifndef OPENSSL_NO_MD5
1902 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1903 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1905 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1907 print_result(D_MD5, testnum, count, d);
1912 static const char hmac_key[] = "This is a key...";
1913 int len = strlen(hmac_key);
1915 for (i = 0; i < loopargs_len; i++) {
1916 loopargs[i].hctx = HMAC_CTX_new();
1917 if (loopargs[i].hctx == NULL) {
1918 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1922 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1924 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1925 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1927 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1929 print_result(D_HMAC, testnum, count, d);
1931 for (i = 0; i < loopargs_len; i++) {
1932 HMAC_CTX_free(loopargs[i].hctx);
1937 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1938 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1940 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1942 print_result(D_SHA1, testnum, count, d);
1945 if (doit[D_SHA256]) {
1946 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1947 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1949 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1951 print_result(D_SHA256, testnum, count, d);
1954 if (doit[D_SHA512]) {
1955 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1956 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1958 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1960 print_result(D_SHA512, testnum, count, d);
1964 #ifndef OPENSSL_NO_WHIRLPOOL
1965 if (doit[D_WHIRLPOOL]) {
1966 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1967 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1969 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1971 print_result(D_WHIRLPOOL, testnum, count, d);
1976 #ifndef OPENSSL_NO_RMD160
1977 if (doit[D_RMD160]) {
1978 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1979 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1981 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1983 print_result(D_RMD160, testnum, count, d);
1987 #ifndef OPENSSL_NO_RC4
1989 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1990 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1992 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1994 print_result(D_RC4, testnum, count, d);
1998 #ifndef OPENSSL_NO_DES
1999 if (doit[D_CBC_DES]) {
2000 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2001 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2003 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2005 print_result(D_CBC_DES, testnum, count, d);
2009 if (doit[D_EDE3_DES]) {
2010 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2011 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2013 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2015 print_result(D_EDE3_DES, testnum, count, d);
2020 if (doit[D_CBC_128_AES]) {
2021 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2022 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2025 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2027 print_result(D_CBC_128_AES, testnum, count, d);
2030 if (doit[D_CBC_192_AES]) {
2031 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2032 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2035 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2037 print_result(D_CBC_192_AES, testnum, count, d);
2040 if (doit[D_CBC_256_AES]) {
2041 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2042 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2045 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2047 print_result(D_CBC_256_AES, testnum, count, d);
2051 if (doit[D_IGE_128_AES]) {
2052 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2053 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2056 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2058 print_result(D_IGE_128_AES, testnum, count, d);
2061 if (doit[D_IGE_192_AES]) {
2062 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2063 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2066 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2068 print_result(D_IGE_192_AES, testnum, count, d);
2071 if (doit[D_IGE_256_AES]) {
2072 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2073 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2076 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2078 print_result(D_IGE_256_AES, testnum, count, d);
2081 if (doit[D_GHASH]) {
2082 for (i = 0; i < loopargs_len; i++) {
2083 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2084 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2087 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2088 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2090 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2092 print_result(D_GHASH, testnum, count, d);
2094 for (i = 0; i < loopargs_len; i++)
2095 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2098 #ifndef OPENSSL_NO_CAMELLIA
2099 if (doit[D_CBC_128_CML]) {
2100 if (async_jobs > 0) {
2101 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2102 names[D_CBC_128_CML]);
2103 doit[D_CBC_128_CML] = 0;
2105 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2106 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2109 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2110 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2111 (size_t)lengths[testnum], &camellia_ks1,
2112 iv, CAMELLIA_ENCRYPT);
2114 print_result(D_CBC_128_CML, testnum, count, d);
2117 if (doit[D_CBC_192_CML]) {
2118 if (async_jobs > 0) {
2119 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2120 names[D_CBC_192_CML]);
2121 doit[D_CBC_192_CML] = 0;
2123 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2124 print_message(names[D_CBC_192_CML], c[D_CBC_192_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_192_CML][testnum]); count++)
2132 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2133 (size_t)lengths[testnum], &camellia_ks2,
2134 iv, CAMELLIA_ENCRYPT);
2136 print_result(D_CBC_192_CML, testnum, count, d);
2139 if (doit[D_CBC_256_CML]) {
2140 if (async_jobs > 0) {
2141 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2142 names[D_CBC_256_CML]);
2143 doit[D_CBC_256_CML] = 0;
2145 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2146 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2149 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2150 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2151 (size_t)lengths[testnum], &camellia_ks3,
2152 iv, CAMELLIA_ENCRYPT);
2154 print_result(D_CBC_256_CML, testnum, count, d);
2158 #ifndef OPENSSL_NO_IDEA
2159 if (doit[D_CBC_IDEA]) {
2160 if (async_jobs > 0) {
2161 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2163 doit[D_CBC_IDEA] = 0;
2165 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2166 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2168 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2169 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2170 (size_t)lengths[testnum], &idea_ks,
2173 print_result(D_CBC_IDEA, testnum, count, d);
2177 #ifndef OPENSSL_NO_SEED
2178 if (doit[D_CBC_SEED]) {
2179 if (async_jobs > 0) {
2180 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2182 doit[D_CBC_SEED] = 0;
2184 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2185 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2187 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2188 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2189 (size_t)lengths[testnum], &seed_ks, iv, 1);
2191 print_result(D_CBC_SEED, testnum, count, d);
2195 #ifndef OPENSSL_NO_RC2
2196 if (doit[D_CBC_RC2]) {
2197 if (async_jobs > 0) {
2198 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2200 doit[D_CBC_RC2] = 0;
2202 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2203 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2204 if (async_jobs > 0) {
2205 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2209 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2210 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2211 (size_t)lengths[testnum], &rc2_ks,
2214 print_result(D_CBC_RC2, testnum, count, d);
2218 #ifndef OPENSSL_NO_RC5
2219 if (doit[D_CBC_RC5]) {
2220 if (async_jobs > 0) {
2221 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2223 doit[D_CBC_RC5] = 0;
2225 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2226 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2227 if (async_jobs > 0) {
2228 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2232 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2233 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2234 (size_t)lengths[testnum], &rc5_ks,
2237 print_result(D_CBC_RC5, testnum, count, d);
2241 #ifndef OPENSSL_NO_BF
2242 if (doit[D_CBC_BF]) {
2243 if (async_jobs > 0) {
2244 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2248 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2249 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2251 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2252 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2253 (size_t)lengths[testnum], &bf_ks,
2256 print_result(D_CBC_BF, testnum, count, d);
2260 #ifndef OPENSSL_NO_CAST
2261 if (doit[D_CBC_CAST]) {
2262 if (async_jobs > 0) {
2263 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2265 doit[D_CBC_CAST] = 0;
2267 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2268 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2270 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2271 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2272 (size_t)lengths[testnum], &cast_ks,
2275 print_result(D_CBC_CAST, testnum, count, d);
2281 if (multiblock && evp_cipher) {
2283 (EVP_CIPHER_flags(evp_cipher) &
2284 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2285 BIO_printf(bio_err, "%s is not multi-block capable\n",
2286 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2289 if (async_jobs > 0) {
2290 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2293 multiblock_speed(evp_cipher);
2297 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2300 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2302 * -O3 -fschedule-insns messes up an optimization here!
2303 * names[D_EVP] somehow becomes NULL
2305 print_message(names[D_EVP], save_count, lengths[testnum]);
2307 for (k = 0; k < loopargs_len; k++) {
2308 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2310 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2312 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2313 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2317 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2319 for (k = 0; k < loopargs_len; k++) {
2320 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2324 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2325 print_message(names[D_EVP], save_count, lengths[testnum]);
2327 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2330 print_result(D_EVP, testnum, count, d);
2334 for (i = 0; i < loopargs_len; i++)
2335 RAND_bytes(loopargs[i].buf, 36);
2337 #ifndef OPENSSL_NO_RSA
2338 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2340 if (!rsa_doit[testnum])
2342 for (i = 0; i < loopargs_len; i++) {
2343 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2344 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2350 "RSA sign failure. No RSA sign will be done.\n");
2351 ERR_print_errors(bio_err);
2354 pkey_print_message("private", "rsa",
2355 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2356 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2358 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2361 mr ? "+R1:%ld:%d:%.2f\n"
2362 : "%ld %d bit private RSA's in %.2fs\n",
2363 count, rsa_bits[testnum], d);
2364 rsa_results[testnum][0] = d / (double)count;
2368 for (i = 0; i < loopargs_len; i++) {
2369 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2370 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2376 "RSA verify failure. No RSA verify will be done.\n");
2377 ERR_print_errors(bio_err);
2378 rsa_doit[testnum] = 0;
2380 pkey_print_message("public", "rsa",
2381 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2383 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2386 mr ? "+R2:%ld:%d:%.2f\n"
2387 : "%ld %d bit public RSA's in %.2fs\n",
2388 count, rsa_bits[testnum], d);
2389 rsa_results[testnum][1] = d / (double)count;
2392 if (rsa_count <= 1) {
2393 /* if longer than 10s, don't do any more */
2394 for (testnum++; testnum < RSA_NUM; testnum++)
2395 rsa_doit[testnum] = 0;
2398 #endif /* OPENSSL_NO_RSA */
2400 for (i = 0; i < loopargs_len; i++)
2401 RAND_bytes(loopargs[i].buf, 36);
2403 #ifndef OPENSSL_NO_DSA
2404 if (RAND_status() != 1) {
2405 RAND_seed(rnd_seed, sizeof(rnd_seed));
2407 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2409 if (!dsa_doit[testnum])
2412 /* DSA_generate_key(dsa_key[testnum]); */
2413 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2414 for (i = 0; i < loopargs_len; i++) {
2415 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2416 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2422 "DSA sign failure. No DSA sign will be done.\n");
2423 ERR_print_errors(bio_err);
2426 pkey_print_message("sign", "dsa",
2427 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2429 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2432 mr ? "+R3:%ld:%d:%.2f\n"
2433 : "%ld %d bit DSA signs in %.2fs\n",
2434 count, dsa_bits[testnum], d);
2435 dsa_results[testnum][0] = d / (double)count;
2439 for (i = 0; i < loopargs_len; i++) {
2440 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2441 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2447 "DSA verify failure. No DSA verify will be done.\n");
2448 ERR_print_errors(bio_err);
2449 dsa_doit[testnum] = 0;
2451 pkey_print_message("verify", "dsa",
2452 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2454 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2457 mr ? "+R4:%ld:%d:%.2f\n"
2458 : "%ld %d bit DSA verify in %.2fs\n",
2459 count, dsa_bits[testnum], d);
2460 dsa_results[testnum][1] = d / (double)count;
2463 if (rsa_count <= 1) {
2464 /* if longer than 10s, don't do any more */
2465 for (testnum++; testnum < DSA_NUM; testnum++)
2466 dsa_doit[testnum] = 0;
2469 #endif /* OPENSSL_NO_DSA */
2471 #ifndef OPENSSL_NO_EC
2472 if (RAND_status() != 1) {
2473 RAND_seed(rnd_seed, sizeof(rnd_seed));
2475 for (testnum = 0; testnum < EC_NUM; testnum++) {
2478 if (!ecdsa_doit[testnum])
2479 continue; /* Ignore Curve */
2480 for (i = 0; i < loopargs_len; i++) {
2481 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2482 if (loopargs[i].ecdsa[testnum] == NULL) {
2488 BIO_printf(bio_err, "ECDSA failure.\n");
2489 ERR_print_errors(bio_err);
2492 for (i = 0; i < loopargs_len; i++) {
2493 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2494 /* Perform ECDSA signature test */
2495 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2496 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2497 &loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2503 "ECDSA sign failure. No ECDSA sign will be done.\n");
2504 ERR_print_errors(bio_err);
2507 pkey_print_message("sign", "ecdsa",
2508 ecdsa_c[testnum][0],
2509 test_curves_bits[testnum], ECDSA_SECONDS);
2511 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2515 mr ? "+R5:%ld:%d:%.2f\n" :
2516 "%ld %d bit ECDSA signs in %.2fs \n",
2517 count, test_curves_bits[testnum], d);
2518 ecdsa_results[testnum][0] = d / (double)count;
2522 /* Perform ECDSA verification test */
2523 for (i = 0; i < loopargs_len; i++) {
2524 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2525 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2531 "ECDSA verify failure. No ECDSA verify will be done.\n");
2532 ERR_print_errors(bio_err);
2533 ecdsa_doit[testnum] = 0;
2535 pkey_print_message("verify", "ecdsa",
2536 ecdsa_c[testnum][1],
2537 test_curves_bits[testnum], ECDSA_SECONDS);
2539 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2542 mr ? "+R6:%ld:%d:%.2f\n"
2543 : "%ld %d bit ECDSA verify in %.2fs\n",
2544 count, test_curves_bits[testnum], d);
2545 ecdsa_results[testnum][1] = d / (double)count;
2548 if (rsa_count <= 1) {
2549 /* if longer than 10s, don't do any more */
2550 for (testnum++; testnum < EC_NUM; testnum++)
2551 ecdsa_doit[testnum] = 0;
2556 if (RAND_status() != 1) {
2557 RAND_seed(rnd_seed, sizeof(rnd_seed));
2559 for (testnum = 0; testnum < EC_NUM; testnum++) {
2560 int ecdh_checks = 1;
2562 if (!ecdh_doit[testnum])
2564 for (i = 0; i < loopargs_len; i++) {
2565 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2566 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2567 if (loopargs[i].ecdh_a[testnum] == NULL ||
2568 loopargs[i].ecdh_b[testnum] == NULL) {
2573 if (ecdh_checks == 0) {
2574 BIO_printf(bio_err, "ECDH failure.\n");
2575 ERR_print_errors(bio_err);
2578 for (i = 0; i < loopargs_len; i++) {
2579 /* generate two ECDH key pairs */
2580 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2581 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2582 BIO_printf(bio_err, "ECDH key generation failure.\n");
2583 ERR_print_errors(bio_err);
2587 int secret_size_a, secret_size_b;
2589 * If field size is not more than 24 octets, then use SHA-1
2590 * hash of result; otherwise, use result (see section 4.8 of
2591 * draft-ietf-tls-ecc-03.txt).
2593 int field_size = EC_GROUP_get_degree(
2594 EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2596 if (field_size <= 24 * 8) { /* 192 bits */
2597 loopargs[i].outlen = KDF1_SHA1_len;
2598 loopargs[i].kdf = KDF1_SHA1;
2600 loopargs[i].outlen = (field_size + 7) / 8;
2601 loopargs[i].kdf = NULL;
2604 ECDH_compute_key(loopargs[i].secret_a, loopargs[i].outlen,
2605 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2606 loopargs[i].ecdh_a[testnum], loopargs[i].kdf);
2608 ECDH_compute_key(loopargs[i].secret_b, loopargs[i].outlen,
2609 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2610 loopargs[i].ecdh_b[testnum], loopargs[i].kdf);
2611 if (secret_size_a != secret_size_b)
2616 for (k = 0; k < secret_size_a && ecdh_checks == 1; k++) {
2617 if (loopargs[i].secret_a[k] != loopargs[i].secret_b[k])
2621 if (ecdh_checks == 0) {
2622 BIO_printf(bio_err, "ECDH computations don't match.\n");
2623 ERR_print_errors(bio_err);
2629 if (ecdh_checks != 0) {
2630 pkey_print_message("", "ecdh",
2632 test_curves_bits[testnum], ECDH_SECONDS);
2634 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2637 mr ? "+R7:%ld:%d:%.2f\n" :
2638 "%ld %d-bit ECDH ops in %.2fs\n", count,
2639 test_curves_bits[testnum], d);
2640 ecdh_results[testnum][0] = d / (double)count;
2645 if (rsa_count <= 1) {
2646 /* if longer than 10s, don't do any more */
2647 for (testnum++; testnum < EC_NUM; testnum++)
2648 ecdh_doit[testnum] = 0;
2651 #endif /* OPENSSL_NO_EC */
2656 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2657 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2659 printf("%s ", BN_options());
2660 #ifndef OPENSSL_NO_MD2
2661 printf("%s ", MD2_options());
2663 #ifndef OPENSSL_NO_RC4
2664 printf("%s ", RC4_options());
2666 #ifndef OPENSSL_NO_DES
2667 printf("%s ", DES_options());
2669 printf("%s ", AES_options());
2670 #ifndef OPENSSL_NO_IDEA
2671 printf("%s ", IDEA_options());
2673 #ifndef OPENSSL_NO_BF
2674 printf("%s ", BF_options());
2676 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2684 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2687 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2688 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2692 for (k = 0; k < ALGOR_NUM; k++) {
2696 printf("+F:%d:%s", k, names[k]);
2698 printf("%-13s", names[k]);
2699 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2700 if (results[k][testnum] > 10000 && !mr)
2701 printf(" %11.2fk", results[k][testnum] / 1e3);
2703 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2707 #ifndef OPENSSL_NO_RSA
2709 for (k = 0; k < RSA_NUM; k++) {
2712 if (testnum && !mr) {
2713 printf("%18ssign verify sign/s verify/s\n", " ");
2717 printf("+F2:%u:%u:%f:%f\n",
2718 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2720 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2721 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2722 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2725 #ifndef OPENSSL_NO_DSA
2727 for (k = 0; k < DSA_NUM; k++) {
2730 if (testnum && !mr) {
2731 printf("%18ssign verify sign/s verify/s\n", " ");
2735 printf("+F3:%u:%u:%f:%f\n",
2736 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2738 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2739 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2740 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2743 #ifndef OPENSSL_NO_EC
2745 for (k = 0; k < EC_NUM; k++) {
2748 if (testnum && !mr) {
2749 printf("%30ssign verify sign/s verify/s\n", " ");
2754 printf("+F4:%u:%u:%f:%f\n",
2755 k, test_curves_bits[k],
2756 ecdsa_results[k][0], ecdsa_results[k][1]);
2758 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2759 test_curves_bits[k],
2760 test_curves_names[k],
2761 ecdsa_results[k][0], ecdsa_results[k][1],
2762 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2766 for (k = 0; k < EC_NUM; k++) {
2769 if (testnum && !mr) {
2770 printf("%30sop op/s\n", " ");
2774 printf("+F5:%u:%u:%f:%f\n",
2775 k, test_curves_bits[k],
2776 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2779 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2780 test_curves_bits[k],
2781 test_curves_names[k],
2782 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2789 ERR_print_errors(bio_err);
2790 for (i = 0; i < loopargs_len; i++) {
2791 OPENSSL_free(loopargs[i].buf_malloc);
2792 OPENSSL_free(loopargs[i].buf2_malloc);
2794 #ifndef OPENSSL_NO_RSA
2795 for (k = 0; k < RSA_NUM; k++)
2796 RSA_free(loopargs[i].rsa_key[k]);
2798 #ifndef OPENSSL_NO_DSA
2799 for (k = 0; k < DSA_NUM; k++)
2800 DSA_free(loopargs[i].dsa_key[k]);
2802 #ifndef OPENSSL_NO_EC
2803 for (k = 0; k < EC_NUM; k++) {
2804 EC_KEY_free(loopargs[i].ecdsa[k]);
2805 EC_KEY_free(loopargs[i].ecdh_a[k]);
2806 EC_KEY_free(loopargs[i].ecdh_b[k]);
2808 OPENSSL_free(loopargs[i].secret_a);
2809 OPENSSL_free(loopargs[i].secret_b);
2813 if (async_jobs > 0) {
2814 for (i = 0; i < loopargs_len; i++)
2815 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2819 ASYNC_cleanup_thread();
2821 OPENSSL_free(loopargs);
2826 static void print_message(const char *s, long num, int length)
2830 mr ? "+DT:%s:%d:%d\n"
2831 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2832 (void)BIO_flush(bio_err);
2836 mr ? "+DN:%s:%ld:%d\n"
2837 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2838 (void)BIO_flush(bio_err);
2842 static void pkey_print_message(const char *str, const char *str2, long num,
2847 mr ? "+DTP:%d:%s:%s:%d\n"
2848 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2849 (void)BIO_flush(bio_err);
2853 mr ? "+DNP:%ld:%d:%s:%s\n"
2854 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2855 (void)BIO_flush(bio_err);
2859 static void print_result(int alg, int run_no, int count, double time_used)
2862 BIO_puts(bio_err, "EVP error!\n");
2866 mr ? "+R:%d:%s:%f\n"
2867 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2868 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2872 static char *sstrsep(char **string, const char *delim)
2875 char *token = *string;
2880 memset(isdelim, 0, sizeof(isdelim));
2884 isdelim[(unsigned char)(*delim)] = 1;
2888 while (!isdelim[(unsigned char)(**string)]) {
2900 static int do_multi(int multi)
2905 static char sep[] = ":";
2907 fds = malloc(sizeof(*fds) * multi);
2908 for (n = 0; n < multi; ++n) {
2909 if (pipe(fd) == -1) {
2910 BIO_printf(bio_err, "pipe failure\n");
2914 (void)BIO_flush(bio_err);
2921 if (dup(fd[1]) == -1) {
2922 BIO_printf(bio_err, "dup failed\n");
2931 printf("Forked child %d\n", n);
2934 /* for now, assume the pipe is long enough to take all the output */
2935 for (n = 0; n < multi; ++n) {
2940 f = fdopen(fds[n], "r");
2941 while (fgets(buf, sizeof(buf), f)) {
2942 p = strchr(buf, '\n');
2945 if (buf[0] != '+') {
2946 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2950 printf("Got: %s from %d\n", buf, n);
2951 if (strncmp(buf, "+F:", 3) == 0) {
2956 alg = atoi(sstrsep(&p, sep));
2958 for (j = 0; j < SIZE_NUM; ++j)
2959 results[alg][j] += atof(sstrsep(&p, sep));
2960 } else if (strncmp(buf, "+F2:", 4) == 0) {
2965 k = atoi(sstrsep(&p, sep));
2968 d = atof(sstrsep(&p, sep));
2970 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2972 rsa_results[k][0] = d;
2974 d = atof(sstrsep(&p, sep));
2976 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2978 rsa_results[k][1] = d;
2980 # ifndef OPENSSL_NO_DSA
2981 else if (strncmp(buf, "+F3:", 4) == 0) {
2986 k = atoi(sstrsep(&p, sep));
2989 d = atof(sstrsep(&p, sep));
2991 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2993 dsa_results[k][0] = d;
2995 d = atof(sstrsep(&p, sep));
2997 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2999 dsa_results[k][1] = d;
3002 # ifndef OPENSSL_NO_EC
3003 else if (strncmp(buf, "+F4:", 4) == 0) {
3008 k = atoi(sstrsep(&p, sep));
3011 d = atof(sstrsep(&p, sep));
3013 ecdsa_results[k][0] =
3014 1 / (1 / ecdsa_results[k][0] + 1 / d);
3016 ecdsa_results[k][0] = d;
3018 d = atof(sstrsep(&p, sep));
3020 ecdsa_results[k][1] =
3021 1 / (1 / ecdsa_results[k][1] + 1 / d);
3023 ecdsa_results[k][1] = d;
3024 } else if (strncmp(buf, "+F5:", 4) == 0) {
3029 k = atoi(sstrsep(&p, sep));
3032 d = atof(sstrsep(&p, sep));
3034 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3036 ecdh_results[k][0] = d;
3041 else if (strncmp(buf, "+H:", 3) == 0) {
3044 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3054 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3056 static int mblengths[] =
3057 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3058 int j, count, num = OSSL_NELEM(mblengths);
3059 const char *alg_name;
3060 unsigned char *inp, *out, no_key[32], no_iv[16];
3061 EVP_CIPHER_CTX *ctx;
3064 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3065 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3066 ctx = EVP_CIPHER_CTX_new();
3067 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3068 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3070 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3072 for (j = 0; j < num; j++) {
3073 print_message(alg_name, 0, mblengths[j]);
3075 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3076 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3077 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3078 size_t len = mblengths[j];
3081 memset(aad, 0, 8); /* avoid uninitialized values */
3082 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3083 aad[9] = 3; /* version */
3085 aad[11] = 0; /* length */
3087 mb_param.out = NULL;
3090 mb_param.interleave = 8;
3092 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3093 sizeof(mb_param), &mb_param);
3099 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3100 sizeof(mb_param), &mb_param);
3104 RAND_bytes(out, 16);
3108 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3109 EVP_AEAD_TLS1_AAD_LEN, aad);
3110 EVP_Cipher(ctx, out, inp, len + pad);
3114 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3115 : "%d %s's in %.2fs\n", count, "evp", d);
3116 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3120 fprintf(stdout, "+H");
3121 for (j = 0; j < num; j++)
3122 fprintf(stdout, ":%d", mblengths[j]);
3123 fprintf(stdout, "\n");
3124 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3125 for (j = 0; j < num; j++)
3126 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3127 fprintf(stdout, "\n");
3130 "The 'numbers' are in 1000s of bytes per second processed.\n");
3131 fprintf(stdout, "type ");
3132 for (j = 0; j < num; j++)
3133 fprintf(stdout, "%7d bytes", mblengths[j]);
3134 fprintf(stdout, "\n");
3135 fprintf(stdout, "%-24s", alg_name);
3137 for (j = 0; j < num; j++) {
3138 if (results[D_EVP][j] > 10000)
3139 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3141 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3143 fprintf(stdout, "\n");
3148 EVP_CIPHER_CTX_free(ctx);