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;
157 unsigned int *siglen;
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];
252 static int lengths[SIZE_NUM] = {
253 16, 64, 256, 1024, 8 * 1024, 16 * 1024
256 #ifndef OPENSSL_NO_RSA
257 static double rsa_results[RSA_NUM][2];
259 #ifndef OPENSSL_NO_DSA
260 static double dsa_results[DSA_NUM][2];
262 #ifndef OPENSSL_NO_EC
263 static double ecdsa_results[EC_NUM][2];
264 static double ecdh_results[EC_NUM][1];
267 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
268 static const char rnd_seed[] =
269 "string to make the random number generator think it has entropy";
273 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
274 # define SIGRETTYPE void
276 # define SIGRETTYPE int
279 static SIGRETTYPE sig_done(int sig);
280 static SIGRETTYPE sig_done(int sig)
282 signal(SIGALRM, sig_done);
292 # if !defined(SIGALRM)
295 static unsigned int lapse, schlock;
296 static void alarm_win32(unsigned int secs)
301 # define alarm alarm_win32
303 static DWORD WINAPI sleepy(VOID * arg)
311 static double Time_F(int s)
318 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
320 DWORD err = GetLastError();
321 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
325 Sleep(0); /* scheduler spinlock */
326 ret = app_tminterval(s, usertime);
328 ret = app_tminterval(s, usertime);
330 TerminateThread(thr, 0);
338 static double Time_F(int s)
340 double ret = app_tminterval(s, usertime);
347 #ifndef OPENSSL_NO_EC
348 static const int KDF1_SHA1_len = 20;
349 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
352 if (*outlen < SHA_DIGEST_LENGTH)
354 *outlen = SHA_DIGEST_LENGTH;
355 return SHA1(in, inlen, out);
357 #endif /* OPENSSL_NO_EC */
359 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
361 static int found(const char *name, const OPT_PAIR * pairs, int *result)
363 for (; pairs->name; pairs++)
364 if (strcmp(name, pairs->name) == 0) {
365 *result = pairs->retval;
371 typedef enum OPTION_choice {
372 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
373 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
374 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
377 OPTIONS speed_options[] = {
378 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
379 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
380 {"help", OPT_HELP, '-', "Display this summary"},
381 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
382 {"decrypt", OPT_DECRYPT, '-',
383 "Time decryption instead of encryption (only EVP)"},
384 {"mr", OPT_MR, '-', "Produce machine readable output"},
386 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
387 {"elapsed", OPT_ELAPSED, '-',
388 "Measure time in real time instead of CPU user time"},
390 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
392 #ifndef OPENSSL_NO_ASYNC
393 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
395 #ifndef OPENSSL_NO_ENGINE
396 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
411 #define D_CBC_IDEA 10
412 #define D_CBC_SEED 11
416 #define D_CBC_CAST 15
417 #define D_CBC_128_AES 16
418 #define D_CBC_192_AES 17
419 #define D_CBC_256_AES 18
420 #define D_CBC_128_CML 19
421 #define D_CBC_192_CML 20
422 #define D_CBC_256_CML 21
426 #define D_WHIRLPOOL 25
427 #define D_IGE_128_AES 26
428 #define D_IGE_192_AES 27
429 #define D_IGE_256_AES 28
431 static OPT_PAIR doit_choices[] = {
432 #ifndef OPENSSL_NO_MD2
435 #ifndef OPENSSL_NO_MDC2
438 #ifndef OPENSSL_NO_MD4
441 #ifndef OPENSSL_NO_MD5
444 #ifndef OPENSSL_NO_MD5
448 {"sha256", D_SHA256},
449 {"sha512", D_SHA512},
450 #ifndef OPENSSL_NO_WHIRLPOOL
451 {"whirlpool", D_WHIRLPOOL},
453 #ifndef OPENSSL_NO_RMD160
454 {"ripemd", D_RMD160},
455 {"rmd160", D_RMD160},
456 {"ripemd160", D_RMD160},
458 #ifndef OPENSSL_NO_RC4
461 #ifndef OPENSSL_NO_DES
462 {"des-cbc", D_CBC_DES},
463 {"des-ede3", D_EDE3_DES},
465 {"aes-128-cbc", D_CBC_128_AES},
466 {"aes-192-cbc", D_CBC_192_AES},
467 {"aes-256-cbc", D_CBC_256_AES},
468 {"aes-128-ige", D_IGE_128_AES},
469 {"aes-192-ige", D_IGE_192_AES},
470 {"aes-256-ige", D_IGE_256_AES},
471 #ifndef OPENSSL_NO_RC2
472 {"rc2-cbc", D_CBC_RC2},
475 #ifndef OPENSSL_NO_RC5
476 {"rc5-cbc", D_CBC_RC5},
479 #ifndef OPENSSL_NO_IDEA
480 {"idea-cbc", D_CBC_IDEA},
481 {"idea", D_CBC_IDEA},
483 #ifndef OPENSSL_NO_SEED
484 {"seed-cbc", D_CBC_SEED},
485 {"seed", D_CBC_SEED},
487 #ifndef OPENSSL_NO_BF
488 {"bf-cbc", D_CBC_BF},
489 {"blowfish", D_CBC_BF},
492 #ifndef OPENSSL_NO_CAST
493 {"cast-cbc", D_CBC_CAST},
494 {"cast", D_CBC_CAST},
495 {"cast5", D_CBC_CAST},
501 #ifndef OPENSSL_NO_DSA
503 # define R_DSA_1024 1
504 # define R_DSA_2048 2
505 static OPT_PAIR dsa_choices[] = {
506 {"dsa512", R_DSA_512},
507 {"dsa1024", R_DSA_1024},
508 {"dsa2048", R_DSA_2048},
519 #define R_RSA_15360 6
520 static OPT_PAIR rsa_choices[] = {
521 {"rsa512", R_RSA_512},
522 {"rsa1024", R_RSA_1024},
523 {"rsa2048", R_RSA_2048},
524 {"rsa3072", R_RSA_3072},
525 {"rsa4096", R_RSA_4096},
526 {"rsa7680", R_RSA_7680},
527 {"rsa15360", R_RSA_15360},
547 #define R_EC_X25519 16
548 #ifndef OPENSSL_NO_EC
549 static OPT_PAIR ecdsa_choices[] = {
550 {"ecdsap160", R_EC_P160},
551 {"ecdsap192", R_EC_P192},
552 {"ecdsap224", R_EC_P224},
553 {"ecdsap256", R_EC_P256},
554 {"ecdsap384", R_EC_P384},
555 {"ecdsap521", R_EC_P521},
556 {"ecdsak163", R_EC_K163},
557 {"ecdsak233", R_EC_K233},
558 {"ecdsak283", R_EC_K283},
559 {"ecdsak409", R_EC_K409},
560 {"ecdsak571", R_EC_K571},
561 {"ecdsab163", R_EC_B163},
562 {"ecdsab233", R_EC_B233},
563 {"ecdsab283", R_EC_B283},
564 {"ecdsab409", R_EC_B409},
565 {"ecdsab571", R_EC_B571},
568 static OPT_PAIR ecdh_choices[] = {
569 {"ecdhp160", R_EC_P160},
570 {"ecdhp192", R_EC_P192},
571 {"ecdhp224", R_EC_P224},
572 {"ecdhp256", R_EC_P256},
573 {"ecdhp384", R_EC_P384},
574 {"ecdhp521", R_EC_P521},
575 {"ecdhk163", R_EC_K163},
576 {"ecdhk233", R_EC_K233},
577 {"ecdhk283", R_EC_K283},
578 {"ecdhk409", R_EC_K409},
579 {"ecdhk571", R_EC_K571},
580 {"ecdhb163", R_EC_B163},
581 {"ecdhb233", R_EC_B233},
582 {"ecdhb283", R_EC_B283},
583 {"ecdhb409", R_EC_B409},
584 {"ecdhb571", R_EC_B571},
585 {"ecdhx25519", R_EC_X25519},
591 # define COND(d) (count < (d))
592 # define COUNT(d) (d)
594 # define COND(unused_cond) (run && count<0x7fffffff)
595 # define COUNT(d) (count)
600 static long c[ALGOR_NUM][SIZE_NUM];
602 #ifndef OPENSSL_NO_MD2
603 static int EVP_Digest_MD2_loop(void *args)
605 loopargs_t *tempargs = (loopargs_t *)args;
606 unsigned char *buf = tempargs->buf;
607 unsigned char md2[MD2_DIGEST_LENGTH];
609 for (count = 0; COND(c[D_MD2][testnum]); count++) {
610 if (!EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
618 #ifndef OPENSSL_NO_MDC2
619 static int EVP_Digest_MDC2_loop(void *args)
621 loopargs_t *tempargs = (loopargs_t *)args;
622 unsigned char *buf = tempargs->buf;
623 unsigned char mdc2[MDC2_DIGEST_LENGTH];
625 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
626 if (!EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
634 #ifndef OPENSSL_NO_MD4
635 static int EVP_Digest_MD4_loop(void *args)
637 loopargs_t *tempargs = (loopargs_t *)args;
638 unsigned char *buf = tempargs->buf;
639 unsigned char md4[MD4_DIGEST_LENGTH];
641 for (count = 0; COND(c[D_MD4][testnum]); count++) {
642 if (!EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
643 NULL, EVP_md4(), NULL))
650 #ifndef OPENSSL_NO_MD5
651 static int MD5_loop(void *args)
653 loopargs_t *tempargs = (loopargs_t *)args;
654 unsigned char *buf = tempargs->buf;
655 unsigned char md5[MD5_DIGEST_LENGTH];
657 for (count = 0; COND(c[D_MD5][testnum]); count++)
658 MD5(buf, lengths[testnum], md5);
662 static int HMAC_loop(void *args)
664 loopargs_t *tempargs = (loopargs_t *)args;
665 unsigned char *buf = tempargs->buf;
666 HMAC_CTX *hctx = tempargs->hctx;
667 unsigned char hmac[MD5_DIGEST_LENGTH];
669 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
670 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
671 HMAC_Update(hctx, buf, lengths[testnum]);
672 HMAC_Final(hctx, &(hmac[0]), NULL);
678 static int SHA1_loop(void *args)
680 loopargs_t *tempargs = (loopargs_t *)args;
681 unsigned char *buf = tempargs->buf;
682 unsigned char sha[SHA_DIGEST_LENGTH];
684 for (count = 0; COND(c[D_SHA1][testnum]); count++)
685 SHA1(buf, lengths[testnum], sha);
689 static int SHA256_loop(void *args)
691 loopargs_t *tempargs = (loopargs_t *)args;
692 unsigned char *buf = tempargs->buf;
693 unsigned char sha256[SHA256_DIGEST_LENGTH];
695 for (count = 0; COND(c[D_SHA256][testnum]); count++)
696 SHA256(buf, lengths[testnum], sha256);
700 static int SHA512_loop(void *args)
702 loopargs_t *tempargs = (loopargs_t *)args;
703 unsigned char *buf = tempargs->buf;
704 unsigned char sha512[SHA512_DIGEST_LENGTH];
706 for (count = 0; COND(c[D_SHA512][testnum]); count++)
707 SHA512(buf, lengths[testnum], sha512);
711 #ifndef OPENSSL_NO_WHIRLPOOL
712 static int WHIRLPOOL_loop(void *args)
714 loopargs_t *tempargs = (loopargs_t *)args;
715 unsigned char *buf = tempargs->buf;
716 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
718 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
719 WHIRLPOOL(buf, lengths[testnum], whirlpool);
724 #ifndef OPENSSL_NO_RMD160
725 static int EVP_Digest_RMD160_loop(void *args)
727 loopargs_t *tempargs = (loopargs_t *)args;
728 unsigned char *buf = tempargs->buf;
729 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
731 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
732 if (!EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]),
733 NULL, EVP_ripemd160(), NULL))
740 #ifndef OPENSSL_NO_RC4
741 static RC4_KEY rc4_ks;
742 static int RC4_loop(void *args)
744 loopargs_t *tempargs = (loopargs_t *)args;
745 unsigned char *buf = tempargs->buf;
747 for (count = 0; COND(c[D_RC4][testnum]); count++)
748 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
753 #ifndef OPENSSL_NO_DES
754 static unsigned char DES_iv[8];
755 static DES_key_schedule sch;
756 static DES_key_schedule sch2;
757 static DES_key_schedule sch3;
758 static int DES_ncbc_encrypt_loop(void *args)
760 loopargs_t *tempargs = (loopargs_t *)args;
761 unsigned char *buf = tempargs->buf;
763 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
764 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
765 &DES_iv, DES_ENCRYPT);
769 static int DES_ede3_cbc_encrypt_loop(void *args)
771 loopargs_t *tempargs = (loopargs_t *)args;
772 unsigned char *buf = tempargs->buf;
774 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
775 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
777 &DES_iv, DES_ENCRYPT);
782 #define MAX_BLOCK_SIZE 128
784 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
785 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
786 static int AES_cbc_128_encrypt_loop(void *args)
788 loopargs_t *tempargs = (loopargs_t *)args;
789 unsigned char *buf = tempargs->buf;
791 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
792 AES_cbc_encrypt(buf, buf,
793 (unsigned long)lengths[testnum], &aes_ks1,
798 static int AES_cbc_192_encrypt_loop(void *args)
800 loopargs_t *tempargs = (loopargs_t *)args;
801 unsigned char *buf = tempargs->buf;
803 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
804 AES_cbc_encrypt(buf, buf,
805 (unsigned long)lengths[testnum], &aes_ks2,
810 static int AES_cbc_256_encrypt_loop(void *args)
812 loopargs_t *tempargs = (loopargs_t *)args;
813 unsigned char *buf = tempargs->buf;
815 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
816 AES_cbc_encrypt(buf, buf,
817 (unsigned long)lengths[testnum], &aes_ks3,
822 static int AES_ige_128_encrypt_loop(void *args)
824 loopargs_t *tempargs = (loopargs_t *)args;
825 unsigned char *buf = tempargs->buf;
826 unsigned char *buf2 = tempargs->buf2;
828 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
829 AES_ige_encrypt(buf, buf2,
830 (unsigned long)lengths[testnum], &aes_ks1,
835 static int AES_ige_192_encrypt_loop(void *args)
837 loopargs_t *tempargs = (loopargs_t *)args;
838 unsigned char *buf = tempargs->buf;
839 unsigned char *buf2 = tempargs->buf2;
841 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
842 AES_ige_encrypt(buf, buf2,
843 (unsigned long)lengths[testnum], &aes_ks2,
848 static int AES_ige_256_encrypt_loop(void *args)
850 loopargs_t *tempargs = (loopargs_t *)args;
851 unsigned char *buf = tempargs->buf;
852 unsigned char *buf2 = tempargs->buf2;
854 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
855 AES_ige_encrypt(buf, buf2,
856 (unsigned long)lengths[testnum], &aes_ks3,
861 static int CRYPTO_gcm128_aad_loop(void *args)
863 loopargs_t *tempargs = (loopargs_t *)args;
864 unsigned char *buf = tempargs->buf;
865 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
867 for (count = 0; COND(c[D_GHASH][testnum]); count++)
868 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
872 static long save_count = 0;
873 static int decrypt = 0;
874 static int EVP_Update_loop(void *args)
876 loopargs_t *tempargs = (loopargs_t *)args;
877 unsigned char *buf = tempargs->buf;
878 EVP_CIPHER_CTX *ctx = tempargs->ctx;
881 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
884 for (count = 0; COND(nb_iter); count++)
885 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
887 for (count = 0; COND(nb_iter); count++)
888 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
890 EVP_DecryptFinal_ex(ctx, buf, &outl);
892 EVP_EncryptFinal_ex(ctx, buf, &outl);
896 static const EVP_MD *evp_md = NULL;
897 static int EVP_Digest_loop(void *args)
899 loopargs_t *tempargs = (loopargs_t *)args;
900 unsigned char *buf = tempargs->buf;
901 unsigned char md[EVP_MAX_MD_SIZE];
904 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
907 for (count = 0; COND(nb_iter); count++) {
908 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
914 #ifndef OPENSSL_NO_RSA
915 static long rsa_c[RSA_NUM][2];
917 static int RSA_sign_loop(void *args)
919 loopargs_t *tempargs = (loopargs_t *)args;
920 unsigned char *buf = tempargs->buf;
921 unsigned char *buf2 = tempargs->buf2;
922 unsigned int *rsa_num = tempargs->siglen;
923 RSA **rsa_key = tempargs->rsa_key;
925 for (count = 0; COND(rsa_c[testnum][0]); count++) {
926 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
928 BIO_printf(bio_err, "RSA sign failure\n");
929 ERR_print_errors(bio_err);
937 static int RSA_verify_loop(void *args)
939 loopargs_t *tempargs = (loopargs_t *)args;
940 unsigned char *buf = tempargs->buf;
941 unsigned char *buf2 = tempargs->buf2;
942 unsigned int rsa_num = *(tempargs->siglen);
943 RSA **rsa_key = tempargs->rsa_key;
945 for (count = 0; COND(rsa_c[testnum][1]); count++) {
946 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
948 BIO_printf(bio_err, "RSA verify failure\n");
949 ERR_print_errors(bio_err);
958 #ifndef OPENSSL_NO_DSA
959 static long dsa_c[DSA_NUM][2];
960 static int DSA_sign_loop(void *args)
962 loopargs_t *tempargs = (loopargs_t *)args;
963 unsigned char *buf = tempargs->buf;
964 unsigned char *buf2 = tempargs->buf2;
965 DSA **dsa_key = tempargs->dsa_key;
966 unsigned int *siglen = tempargs->siglen;
968 for (count = 0; COND(dsa_c[testnum][0]); count++) {
969 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
971 BIO_printf(bio_err, "DSA sign failure\n");
972 ERR_print_errors(bio_err);
980 static int DSA_verify_loop(void *args)
982 loopargs_t *tempargs = (loopargs_t *)args;
983 unsigned char *buf = tempargs->buf;
984 unsigned char *buf2 = tempargs->buf2;
985 DSA **dsa_key = tempargs->dsa_key;
986 unsigned int siglen = *(tempargs->siglen);
988 for (count = 0; COND(dsa_c[testnum][1]); count++) {
989 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
991 BIO_printf(bio_err, "DSA verify failure\n");
992 ERR_print_errors(bio_err);
1001 #ifndef OPENSSL_NO_EC
1002 static long ecdsa_c[EC_NUM][2];
1003 static int ECDSA_sign_loop(void *args)
1005 loopargs_t *tempargs = (loopargs_t *)args;
1006 unsigned char *buf = tempargs->buf;
1007 EC_KEY **ecdsa = tempargs->ecdsa;
1008 unsigned char *ecdsasig = tempargs->buf2;
1009 unsigned int *ecdsasiglen = tempargs->siglen;
1011 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1012 ret = ECDSA_sign(0, buf, 20,
1013 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1015 BIO_printf(bio_err, "ECDSA sign failure\n");
1016 ERR_print_errors(bio_err);
1024 static int ECDSA_verify_loop(void *args)
1026 loopargs_t *tempargs = (loopargs_t *)args;
1027 unsigned char *buf = tempargs->buf;
1028 EC_KEY **ecdsa = tempargs->ecdsa;
1029 unsigned char *ecdsasig = tempargs->buf2;
1030 unsigned int ecdsasiglen = *(tempargs->siglen);
1032 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1033 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1036 BIO_printf(bio_err, "ECDSA verify failure\n");
1037 ERR_print_errors(bio_err);
1045 /* ******************************************************************** */
1046 static long ecdh_c[EC_NUM][1];
1048 static int ECDH_compute_key_loop(void *args)
1050 loopargs_t *tempargs = (loopargs_t *)args;
1051 EC_KEY **ecdh_a = tempargs->ecdh_a;
1052 EC_KEY **ecdh_b = tempargs->ecdh_b;
1053 unsigned char *secret_a = tempargs->secret_a;
1054 int count, outlen = tempargs->outlen;
1055 kdf_fn kdf = tempargs->kdf;
1057 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1058 ECDH_compute_key(secret_a, outlen,
1059 EC_KEY_get0_public_key(ecdh_b[testnum]),
1060 ecdh_a[testnum], kdf);
1064 #endif /* ndef OPENSSL_NO_EC */
1067 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1069 int job_op_count = 0;
1070 int total_op_count = 0;
1071 int num_inprogress = 0;
1074 OSSL_ASYNC_FD job_fd = 0;
1075 size_t num_job_fds = 0;
1079 if (async_jobs == 0) {
1080 return loop_function((void *)loopargs);
1084 for (i = 0; i < async_jobs && !error; i++) {
1085 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1086 &job_op_count, loop_function,
1087 (void *)(loopargs + i), sizeof(loopargs_t))) {
1092 if (job_op_count == -1) {
1095 total_op_count += job_op_count;
1100 BIO_printf(bio_err, "Failure in the job\n");
1101 ERR_print_errors(bio_err);
1107 while (num_inprogress > 0) {
1108 #if defined(OPENSSL_SYS_WINDOWS)
1110 #elif defined(OPENSSL_SYS_UNIX)
1111 int select_result = 0;
1112 OSSL_ASYNC_FD max_fd = 0;
1115 FD_ZERO(&waitfdset);
1117 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1118 if (loopargs[i].inprogress_job == NULL)
1121 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1122 || num_job_fds > 1) {
1123 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1124 ERR_print_errors(bio_err);
1128 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1129 FD_SET(job_fd, &waitfdset);
1130 if (job_fd > max_fd)
1134 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1136 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1137 "Decrease the value of async_jobs\n",
1138 max_fd, FD_SETSIZE);
1139 ERR_print_errors(bio_err);
1144 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1145 if (select_result == -1 && errno == EINTR)
1148 if (select_result == -1) {
1149 BIO_printf(bio_err, "Failure in the select\n");
1150 ERR_print_errors(bio_err);
1155 if (select_result == 0)
1159 for (i = 0; i < async_jobs; i++) {
1160 if (loopargs[i].inprogress_job == NULL)
1163 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1164 || num_job_fds > 1) {
1165 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1166 ERR_print_errors(bio_err);
1170 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1172 #if defined(OPENSSL_SYS_UNIX)
1173 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1175 #elif defined(OPENSSL_SYS_WINDOWS)
1176 if (num_job_fds == 1 &&
1177 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1181 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1182 &job_op_count, loop_function, (void *)(loopargs + i),
1183 sizeof(loopargs_t))) {
1187 if (job_op_count == -1) {
1190 total_op_count += job_op_count;
1193 loopargs[i].inprogress_job = NULL;
1198 loopargs[i].inprogress_job = NULL;
1199 BIO_printf(bio_err, "Failure in the job\n");
1200 ERR_print_errors(bio_err);
1207 return error ? -1 : total_op_count;
1210 int speed_main(int argc, char **argv)
1212 loopargs_t *loopargs = NULL;
1214 int loopargs_len = 0;
1216 #ifndef OPENSSL_NO_ENGINE
1217 const char *engine_id = NULL;
1219 const EVP_CIPHER *evp_cipher = NULL;
1222 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1223 #ifndef OPENSSL_NO_DSA
1224 int dsa_doit[DSA_NUM];
1226 int rsa_doit[RSA_NUM];
1227 int ret = 1, i, k, misalign = 0;
1233 /* What follows are the buffers and key material. */
1234 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1237 #ifndef OPENSSL_NO_RC5
1240 #ifndef OPENSSL_NO_RC2
1243 #ifndef OPENSSL_NO_IDEA
1244 IDEA_KEY_SCHEDULE idea_ks;
1246 #ifndef OPENSSL_NO_SEED
1247 SEED_KEY_SCHEDULE seed_ks;
1249 #ifndef OPENSSL_NO_BF
1252 #ifndef OPENSSL_NO_CAST
1255 static const unsigned char key16[16] = {
1256 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1257 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1259 static const unsigned char key24[24] = {
1260 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1261 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1262 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1264 static const unsigned char key32[32] = {
1265 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1266 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1267 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1268 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1270 #ifndef OPENSSL_NO_CAMELLIA
1271 static const unsigned char ckey24[24] = {
1272 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1273 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1274 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1276 static const unsigned char ckey32[32] = {
1277 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1278 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1279 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1280 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1282 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1284 #ifndef OPENSSL_NO_DES
1285 static DES_cblock key = {
1286 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1288 static DES_cblock key2 = {
1289 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1291 static DES_cblock key3 = {
1292 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1295 #ifndef OPENSSL_NO_RSA
1296 static unsigned int rsa_bits[RSA_NUM] = {
1297 512, 1024, 2048, 3072, 4096, 7680, 15360
1299 static unsigned char *rsa_data[RSA_NUM] = {
1300 test512, test1024, test2048, test3072, test4096, test7680, test15360
1302 static int rsa_data_length[RSA_NUM] = {
1303 sizeof(test512), sizeof(test1024),
1304 sizeof(test2048), sizeof(test3072),
1305 sizeof(test4096), sizeof(test7680),
1309 #ifndef OPENSSL_NO_DSA
1310 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1312 #ifndef OPENSSL_NO_EC
1314 * We only test over the following curves as they are representative, To
1315 * add tests over more curves, simply add the curve NID and curve name to
1316 * the following arrays and increase the EC_NUM value accordingly.
1318 static unsigned int test_curves[EC_NUM] = {
1320 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1321 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1323 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1324 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1325 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1330 static const char *test_curves_names[EC_NUM] = {
1332 "secp160r1", "nistp192", "nistp224",
1333 "nistp256", "nistp384", "nistp521",
1335 "nistk163", "nistk233", "nistk283",
1336 "nistk409", "nistk571", "nistb163",
1337 "nistb233", "nistb283", "nistb409",
1342 static int test_curves_bits[EC_NUM] = {
1348 571, 253 /* X25519 */
1351 #ifndef OPENSSL_NO_EC
1352 int ecdsa_doit[EC_NUM];
1353 int secret_size_a, secret_size_b;
1354 int ecdh_checks = 1;
1356 int ecdh_doit[EC_NUM];
1359 memset(results, 0, sizeof(results));
1361 #ifndef OPENSSL_NO_DES
1362 memset(DES_iv, 0, sizeof(DES_iv));
1364 memset(iv, 0, sizeof(iv));
1366 for (i = 0; i < ALGOR_NUM; i++)
1368 for (i = 0; i < RSA_NUM; i++)
1370 #ifndef OPENSSL_NO_DSA
1371 for (i = 0; i < DSA_NUM; i++)
1374 #ifndef OPENSSL_NO_EC
1375 for (i = 0; i < EC_NUM; i++)
1377 for (i = 0; i < EC_NUM; i++)
1383 prog = opt_init(argc, argv, speed_options);
1384 while ((o = opt_next()) != OPT_EOF) {
1389 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1392 opt_help(speed_options);
1399 evp_cipher = EVP_get_cipherbyname(opt_arg());
1400 if (evp_cipher == NULL)
1401 evp_md = EVP_get_digestbyname(opt_arg());
1402 if (evp_cipher == NULL && evp_md == NULL) {
1404 "%s: %s an unknown cipher or digest\n",
1415 * In a forked execution, an engine might need to be
1416 * initialised by each child process, not by the parent.
1417 * So store the name here and run setup_engine() later on.
1419 #ifndef OPENSSL_NO_ENGINE
1420 engine_id = opt_arg();
1425 multi = atoi(opt_arg());
1429 #ifndef OPENSSL_NO_ASYNC
1430 async_jobs = atoi(opt_arg());
1431 if (!ASYNC_is_capable()) {
1433 "%s: async_jobs specified but async not supported\n",
1440 if (!opt_int(opt_arg(), &misalign))
1442 if (misalign > MISALIGN) {
1444 "%s: Maximum offset is %d\n", prog, MISALIGN);
1456 argc = opt_num_rest();
1459 /* Remaining arguments are algorithms. */
1460 for ( ; *argv; argv++) {
1461 if (found(*argv, doit_choices, &i)) {
1465 #ifndef OPENSSL_NO_DES
1466 if (strcmp(*argv, "des") == 0) {
1467 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1471 if (strcmp(*argv, "sha") == 0) {
1472 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1475 #ifndef OPENSSL_NO_RSA
1477 if (strcmp(*argv, "openssl") == 0) {
1478 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1482 if (strcmp(*argv, "rsa") == 0) {
1483 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1484 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1485 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1486 rsa_doit[R_RSA_15360] = 1;
1489 if (found(*argv, rsa_choices, &i)) {
1494 #ifndef OPENSSL_NO_DSA
1495 if (strcmp(*argv, "dsa") == 0) {
1496 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1497 dsa_doit[R_DSA_2048] = 1;
1500 if (found(*argv, dsa_choices, &i)) {
1505 if (strcmp(*argv, "aes") == 0) {
1506 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1507 doit[D_CBC_256_AES] = 1;
1510 #ifndef OPENSSL_NO_CAMELLIA
1511 if (strcmp(*argv, "camellia") == 0) {
1512 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1513 doit[D_CBC_256_CML] = 1;
1517 #ifndef OPENSSL_NO_EC
1518 if (strcmp(*argv, "ecdsa") == 0) {
1519 for (i = 0; i < EC_NUM; i++)
1523 if (found(*argv, ecdsa_choices, &i)) {
1527 if (strcmp(*argv, "ecdh") == 0) {
1528 for (i = 0; i < EC_NUM; i++)
1532 if (found(*argv, ecdh_choices, &i)) {
1537 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1541 /* Initialize the job pool if async mode is enabled */
1542 if (async_jobs > 0) {
1543 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1545 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1550 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1551 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1552 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1554 for (i = 0; i < loopargs_len; i++) {
1555 if (async_jobs > 0) {
1556 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1557 if (loopargs[i].wait_ctx == NULL) {
1558 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1563 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1564 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1565 /* Align the start of buffers on a 64 byte boundary */
1566 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1567 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1568 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1569 #ifndef OPENSSL_NO_EC
1570 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1571 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1576 if (multi && do_multi(multi))
1580 /* Initialize the engine after the fork */
1581 (void)setup_engine(engine_id, 0);
1583 /* No parameters; turn on everything. */
1584 if ((argc == 0) && !doit[D_EVP]) {
1585 for (i = 0; i < ALGOR_NUM; i++)
1588 for (i = 0; i < RSA_NUM; i++)
1590 #ifndef OPENSSL_NO_DSA
1591 for (i = 0; i < DSA_NUM; i++)
1594 #ifndef OPENSSL_NO_EC
1595 for (i = 0; i < EC_NUM; i++)
1597 for (i = 0; i < EC_NUM; i++)
1601 for (i = 0; i < ALGOR_NUM; i++)
1605 if (usertime == 0 && !mr)
1607 "You have chosen to measure elapsed time "
1608 "instead of user CPU time.\n");
1610 #ifndef OPENSSL_NO_RSA
1611 for (i = 0; i < loopargs_len; i++) {
1612 for (k = 0; k < RSA_NUM; k++) {
1613 const unsigned char *p;
1616 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1617 if (loopargs[i].rsa_key[k] == NULL) {
1618 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1625 #ifndef OPENSSL_NO_DSA
1626 for (i = 0; i < loopargs_len; i++) {
1627 loopargs[i].dsa_key[0] = get_dsa512();
1628 loopargs[i].dsa_key[1] = get_dsa1024();
1629 loopargs[i].dsa_key[2] = get_dsa2048();
1632 #ifndef OPENSSL_NO_DES
1633 DES_set_key_unchecked(&key, &sch);
1634 DES_set_key_unchecked(&key2, &sch2);
1635 DES_set_key_unchecked(&key3, &sch3);
1637 AES_set_encrypt_key(key16, 128, &aes_ks1);
1638 AES_set_encrypt_key(key24, 192, &aes_ks2);
1639 AES_set_encrypt_key(key32, 256, &aes_ks3);
1640 #ifndef OPENSSL_NO_CAMELLIA
1641 Camellia_set_key(key16, 128, &camellia_ks1);
1642 Camellia_set_key(ckey24, 192, &camellia_ks2);
1643 Camellia_set_key(ckey32, 256, &camellia_ks3);
1645 #ifndef OPENSSL_NO_IDEA
1646 IDEA_set_encrypt_key(key16, &idea_ks);
1648 #ifndef OPENSSL_NO_SEED
1649 SEED_set_key(key16, &seed_ks);
1651 #ifndef OPENSSL_NO_RC4
1652 RC4_set_key(&rc4_ks, 16, key16);
1654 #ifndef OPENSSL_NO_RC2
1655 RC2_set_key(&rc2_ks, 16, key16, 128);
1657 #ifndef OPENSSL_NO_RC5
1658 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1660 #ifndef OPENSSL_NO_BF
1661 BF_set_key(&bf_ks, 16, key16);
1663 #ifndef OPENSSL_NO_CAST
1664 CAST_set_key(&cast_ks, 16, key16);
1666 #ifndef OPENSSL_NO_RSA
1667 memset(rsa_c, 0, sizeof(rsa_c));
1670 # ifndef OPENSSL_NO_DES
1671 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1677 for (it = count; it; it--)
1678 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1679 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1683 c[D_MD2][0] = count / 10;
1684 c[D_MDC2][0] = count / 10;
1685 c[D_MD4][0] = count;
1686 c[D_MD5][0] = count;
1687 c[D_HMAC][0] = count;
1688 c[D_SHA1][0] = count;
1689 c[D_RMD160][0] = count;
1690 c[D_RC4][0] = count * 5;
1691 c[D_CBC_DES][0] = count;
1692 c[D_EDE3_DES][0] = count / 3;
1693 c[D_CBC_IDEA][0] = count;
1694 c[D_CBC_SEED][0] = count;
1695 c[D_CBC_RC2][0] = count;
1696 c[D_CBC_RC5][0] = count;
1697 c[D_CBC_BF][0] = count;
1698 c[D_CBC_CAST][0] = count;
1699 c[D_CBC_128_AES][0] = count;
1700 c[D_CBC_192_AES][0] = count;
1701 c[D_CBC_256_AES][0] = count;
1702 c[D_CBC_128_CML][0] = count;
1703 c[D_CBC_192_CML][0] = count;
1704 c[D_CBC_256_CML][0] = count;
1705 c[D_SHA256][0] = count;
1706 c[D_SHA512][0] = count;
1707 c[D_WHIRLPOOL][0] = count;
1708 c[D_IGE_128_AES][0] = count;
1709 c[D_IGE_192_AES][0] = count;
1710 c[D_IGE_256_AES][0] = count;
1711 c[D_GHASH][0] = count;
1713 for (i = 1; i < SIZE_NUM; i++) {
1716 l0 = (long)lengths[0];
1717 l1 = (long)lengths[i];
1719 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1720 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1721 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1722 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1723 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1724 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1725 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1726 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1727 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1728 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1729 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1731 l0 = (long)lengths[i - 1];
1733 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1734 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1735 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1736 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1737 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1738 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1739 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1740 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1741 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1742 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1743 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1744 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1745 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1746 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1747 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1748 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1749 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1750 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1753 # ifndef OPENSSL_NO_RSA
1754 rsa_c[R_RSA_512][0] = count / 2000;
1755 rsa_c[R_RSA_512][1] = count / 400;
1756 for (i = 1; i < RSA_NUM; i++) {
1757 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1758 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1759 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1762 if (rsa_c[i][0] == 0) {
1770 # ifndef OPENSSL_NO_DSA
1771 dsa_c[R_DSA_512][0] = count / 1000;
1772 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1773 for (i = 1; i < DSA_NUM; i++) {
1774 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1775 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1776 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1779 if (dsa_c[i] == 0) { /* Always false */
1787 # ifndef OPENSSL_NO_EC
1788 ecdsa_c[R_EC_P160][0] = count / 1000;
1789 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1790 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1791 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1792 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1793 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1796 if (ecdsa_c[i] == 0) { /* Always false */
1802 ecdsa_c[R_EC_K163][0] = count / 1000;
1803 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1804 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1805 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1806 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1807 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1810 if (ecdsa_c[i] == 0) { /* Always false */
1816 ecdsa_c[R_EC_B163][0] = count / 1000;
1817 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1818 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1819 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1820 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1821 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1824 if (ecdsa_c[i] == 0) { /* Always false */
1831 ecdh_c[R_EC_P160][0] = count / 1000;
1832 for (i = R_EC_P192; i <= R_EC_P521; 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) { /* always false */
1842 ecdh_c[R_EC_K163][0] = count / 1000;
1843 for (i = R_EC_K233; i <= R_EC_K571; 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) { /* always false */
1853 ecdh_c[R_EC_B163][0] = count / 1000;
1854 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1855 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1856 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1859 if (ecdh_c[i] == 0) { /* always false */
1867 /* not worth fixing */
1868 # error "You cannot disable DES on systems without SIGALRM."
1869 # endif /* OPENSSL_NO_DES */
1872 signal(SIGALRM, sig_done);
1874 #endif /* SIGALRM */
1876 #ifndef OPENSSL_NO_MD2
1878 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1879 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1881 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1883 print_result(D_MD2, testnum, count, d);
1887 #ifndef OPENSSL_NO_MDC2
1889 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1890 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1892 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1894 print_result(D_MDC2, testnum, count, d);
1899 #ifndef OPENSSL_NO_MD4
1901 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1902 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1904 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1906 print_result(D_MD4, testnum, count, d);
1911 #ifndef OPENSSL_NO_MD5
1913 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1914 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1916 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1918 print_result(D_MD5, testnum, count, d);
1923 #ifndef OPENSSL_NO_MD5
1925 for (i = 0; i < loopargs_len; i++) {
1926 loopargs[i].hctx = HMAC_CTX_new();
1927 if (loopargs[i].hctx == NULL) {
1928 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1932 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1933 16, EVP_md5(), NULL);
1935 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1936 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1938 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1940 print_result(D_HMAC, testnum, count, d);
1942 for (i = 0; i < loopargs_len; i++) {
1943 HMAC_CTX_free(loopargs[i].hctx);
1948 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1949 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1951 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1953 print_result(D_SHA1, testnum, count, d);
1956 if (doit[D_SHA256]) {
1957 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1958 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1960 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1962 print_result(D_SHA256, testnum, count, d);
1965 if (doit[D_SHA512]) {
1966 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1967 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1969 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1971 print_result(D_SHA512, testnum, count, d);
1975 #ifndef OPENSSL_NO_WHIRLPOOL
1976 if (doit[D_WHIRLPOOL]) {
1977 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1978 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1980 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1982 print_result(D_WHIRLPOOL, testnum, count, d);
1987 #ifndef OPENSSL_NO_RMD160
1988 if (doit[D_RMD160]) {
1989 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1990 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1992 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1994 print_result(D_RMD160, testnum, count, d);
1998 #ifndef OPENSSL_NO_RC4
2000 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2001 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2003 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2005 print_result(D_RC4, testnum, count, d);
2009 #ifndef OPENSSL_NO_DES
2010 if (doit[D_CBC_DES]) {
2011 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2012 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2014 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2016 print_result(D_CBC_DES, testnum, count, d);
2020 if (doit[D_EDE3_DES]) {
2021 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2022 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2024 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2026 print_result(D_EDE3_DES, testnum, count, d);
2031 if (doit[D_CBC_128_AES]) {
2032 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2033 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2036 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2038 print_result(D_CBC_128_AES, testnum, count, d);
2041 if (doit[D_CBC_192_AES]) {
2042 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2043 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2046 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2048 print_result(D_CBC_192_AES, testnum, count, d);
2051 if (doit[D_CBC_256_AES]) {
2052 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2053 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2056 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2058 print_result(D_CBC_256_AES, testnum, count, d);
2062 if (doit[D_IGE_128_AES]) {
2063 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2064 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2067 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2069 print_result(D_IGE_128_AES, testnum, count, d);
2072 if (doit[D_IGE_192_AES]) {
2073 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2074 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2077 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2079 print_result(D_IGE_192_AES, testnum, count, d);
2082 if (doit[D_IGE_256_AES]) {
2083 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2084 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2087 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2089 print_result(D_IGE_256_AES, testnum, count, d);
2092 if (doit[D_GHASH]) {
2093 for (i = 0; i < loopargs_len; i++) {
2094 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2095 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2098 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2099 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2101 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2103 print_result(D_GHASH, testnum, count, d);
2105 for (i = 0; i < loopargs_len; i++)
2106 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2109 #ifndef OPENSSL_NO_CAMELLIA
2110 if (doit[D_CBC_128_CML]) {
2111 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2112 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2114 if (async_jobs > 0) {
2115 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2119 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2120 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2121 (unsigned long)lengths[testnum], &camellia_ks1,
2122 iv, CAMELLIA_ENCRYPT);
2124 print_result(D_CBC_128_CML, testnum, count, d);
2127 if (doit[D_CBC_192_CML]) {
2128 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2129 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2131 if (async_jobs > 0) {
2132 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2136 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2137 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2138 (unsigned long)lengths[testnum], &camellia_ks2,
2139 iv, CAMELLIA_ENCRYPT);
2141 print_result(D_CBC_192_CML, testnum, count, d);
2144 if (doit[D_CBC_256_CML]) {
2145 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2146 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2148 if (async_jobs > 0) {
2149 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2153 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2154 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2155 (unsigned long)lengths[testnum], &camellia_ks3,
2156 iv, CAMELLIA_ENCRYPT);
2158 print_result(D_CBC_256_CML, testnum, count, d);
2162 #ifndef OPENSSL_NO_IDEA
2163 if (doit[D_CBC_IDEA]) {
2164 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2165 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2166 if (async_jobs > 0) {
2167 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2171 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2172 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2173 (unsigned long)lengths[testnum], &idea_ks,
2176 print_result(D_CBC_IDEA, testnum, count, d);
2180 #ifndef OPENSSL_NO_SEED
2181 if (doit[D_CBC_SEED]) {
2182 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2183 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2184 if (async_jobs > 0) {
2185 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2189 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2190 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2191 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2193 print_result(D_CBC_SEED, testnum, count, d);
2197 #ifndef OPENSSL_NO_RC2
2198 if (doit[D_CBC_RC2]) {
2199 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2200 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2201 if (async_jobs > 0) {
2202 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2206 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2207 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2208 (unsigned long)lengths[testnum], &rc2_ks,
2211 print_result(D_CBC_RC2, testnum, count, d);
2215 #ifndef OPENSSL_NO_RC5
2216 if (doit[D_CBC_RC5]) {
2217 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2218 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2219 if (async_jobs > 0) {
2220 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2224 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2225 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2226 (unsigned long)lengths[testnum], &rc5_ks,
2229 print_result(D_CBC_RC5, testnum, count, d);
2233 #ifndef OPENSSL_NO_BF
2234 if (doit[D_CBC_BF]) {
2235 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2236 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2237 if (async_jobs > 0) {
2238 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2242 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2243 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2244 (unsigned long)lengths[testnum], &bf_ks,
2247 print_result(D_CBC_BF, testnum, count, d);
2251 #ifndef OPENSSL_NO_CAST
2252 if (doit[D_CBC_CAST]) {
2253 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2254 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2255 if (async_jobs > 0) {
2256 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2260 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2261 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2262 (unsigned long)lengths[testnum], &cast_ks,
2265 print_result(D_CBC_CAST, testnum, count, d);
2271 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2272 if (multiblock && evp_cipher) {
2274 (EVP_CIPHER_flags(evp_cipher) &
2275 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2276 BIO_printf(bio_err, "%s is not multi-block capable\n",
2277 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2280 if (async_jobs > 0) {
2281 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2284 multiblock_speed(evp_cipher);
2289 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2292 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2294 * -O3 -fschedule-insns messes up an optimization here!
2295 * names[D_EVP] somehow becomes NULL
2297 print_message(names[D_EVP], save_count, lengths[testnum]);
2299 for (k = 0; k < loopargs_len; k++) {
2300 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2302 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2304 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2305 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2309 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2311 for (k = 0; k < loopargs_len; k++) {
2312 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2316 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2317 print_message(names[D_EVP], save_count, lengths[testnum]);
2319 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2322 print_result(D_EVP, testnum, count, d);
2326 for (i = 0; i < loopargs_len; i++)
2327 RAND_bytes(loopargs[i].buf, 36);
2329 #ifndef OPENSSL_NO_RSA
2330 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2332 if (!rsa_doit[testnum])
2334 for (i = 0; i < loopargs_len; i++) {
2335 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2336 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2342 "RSA sign failure. No RSA sign will be done.\n");
2343 ERR_print_errors(bio_err);
2346 pkey_print_message("private", "rsa",
2347 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2348 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2350 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2353 mr ? "+R1:%ld:%d:%.2f\n"
2354 : "%ld %d bit private RSA's in %.2fs\n",
2355 count, rsa_bits[testnum], d);
2356 rsa_results[testnum][0] = d / (double)count;
2360 for (i = 0; i < loopargs_len; i++) {
2361 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2362 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2368 "RSA verify failure. No RSA verify will be done.\n");
2369 ERR_print_errors(bio_err);
2370 rsa_doit[testnum] = 0;
2372 pkey_print_message("public", "rsa",
2373 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2375 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2378 mr ? "+R2:%ld:%d:%.2f\n"
2379 : "%ld %d bit public RSA's in %.2fs\n",
2380 count, rsa_bits[testnum], d);
2381 rsa_results[testnum][1] = d / (double)count;
2384 if (rsa_count <= 1) {
2385 /* if longer than 10s, don't do any more */
2386 for (testnum++; testnum < RSA_NUM; testnum++)
2387 rsa_doit[testnum] = 0;
2392 for (i = 0; i < loopargs_len; i++)
2393 RAND_bytes(loopargs[i].buf, 36);
2395 #ifndef OPENSSL_NO_DSA
2396 if (RAND_status() != 1) {
2397 RAND_seed(rnd_seed, sizeof rnd_seed);
2399 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2401 if (!dsa_doit[testnum])
2404 /* DSA_generate_key(dsa_key[testnum]); */
2405 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2406 for (i = 0; i < loopargs_len; i++) {
2407 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2408 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2414 "DSA sign failure. No DSA sign will be done.\n");
2415 ERR_print_errors(bio_err);
2418 pkey_print_message("sign", "dsa",
2419 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2421 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2424 mr ? "+R3:%ld:%d:%.2f\n"
2425 : "%ld %d bit DSA signs in %.2fs\n",
2426 count, dsa_bits[testnum], d);
2427 dsa_results[testnum][0] = d / (double)count;
2431 for (i = 0; i < loopargs_len; i++) {
2432 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2433 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2439 "DSA verify failure. No DSA verify will be done.\n");
2440 ERR_print_errors(bio_err);
2441 dsa_doit[testnum] = 0;
2443 pkey_print_message("verify", "dsa",
2444 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2446 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2449 mr ? "+R4:%ld:%d:%.2f\n"
2450 : "%ld %d bit DSA verify in %.2fs\n",
2451 count, dsa_bits[testnum], d);
2452 dsa_results[testnum][1] = d / (double)count;
2455 if (rsa_count <= 1) {
2456 /* if longer than 10s, don't do any more */
2457 for (testnum++; testnum < DSA_NUM; testnum++)
2458 dsa_doit[testnum] = 0;
2463 #ifndef OPENSSL_NO_EC
2464 if (RAND_status() != 1) {
2465 RAND_seed(rnd_seed, sizeof rnd_seed);
2467 for (testnum = 0; testnum < EC_NUM; testnum++) {
2470 if (!ecdsa_doit[testnum])
2471 continue; /* Ignore Curve */
2472 for (i = 0; i < loopargs_len; i++) {
2473 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2474 if (loopargs[i].ecdsa[testnum] == NULL) {
2480 BIO_printf(bio_err, "ECDSA failure.\n");
2481 ERR_print_errors(bio_err);
2484 for (i = 0; i < loopargs_len; i++) {
2485 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2486 /* Perform ECDSA signature test */
2487 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2488 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2489 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2495 "ECDSA sign failure. No ECDSA sign will be done.\n");
2496 ERR_print_errors(bio_err);
2499 pkey_print_message("sign", "ecdsa",
2500 ecdsa_c[testnum][0],
2501 test_curves_bits[testnum], ECDSA_SECONDS);
2503 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2507 mr ? "+R5:%ld:%d:%.2f\n" :
2508 "%ld %d bit ECDSA signs in %.2fs \n",
2509 count, test_curves_bits[testnum], d);
2510 ecdsa_results[testnum][0] = d / (double)count;
2514 /* Perform ECDSA verification test */
2515 for (i = 0; i < loopargs_len; i++) {
2516 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2517 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2523 "ECDSA verify failure. No ECDSA verify will be done.\n");
2524 ERR_print_errors(bio_err);
2525 ecdsa_doit[testnum] = 0;
2527 pkey_print_message("verify", "ecdsa",
2528 ecdsa_c[testnum][1],
2529 test_curves_bits[testnum], ECDSA_SECONDS);
2531 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2534 mr ? "+R6:%ld:%d:%.2f\n"
2535 : "%ld %d bit ECDSA verify in %.2fs\n",
2536 count, test_curves_bits[testnum], d);
2537 ecdsa_results[testnum][1] = d / (double)count;
2540 if (rsa_count <= 1) {
2541 /* if longer than 10s, don't do any more */
2542 for (testnum++; testnum < EC_NUM; testnum++)
2543 ecdsa_doit[testnum] = 0;
2549 #ifndef OPENSSL_NO_EC
2550 if (RAND_status() != 1) {
2551 RAND_seed(rnd_seed, sizeof rnd_seed);
2553 for (testnum = 0; testnum < EC_NUM; testnum++) {
2554 if (!ecdh_doit[testnum])
2556 for (i = 0; i < loopargs_len; i++) {
2557 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2558 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2559 if (loopargs[i].ecdh_a[testnum] == NULL ||
2560 loopargs[i].ecdh_b[testnum] == NULL) {
2565 if (ecdh_checks == 0) {
2566 BIO_printf(bio_err, "ECDH failure.\n");
2567 ERR_print_errors(bio_err);
2570 for (i = 0; i < loopargs_len; i++) {
2571 /* generate two ECDH key pairs */
2572 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2573 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2574 BIO_printf(bio_err, "ECDH key generation failure.\n");
2575 ERR_print_errors(bio_err);
2580 * If field size is not more than 24 octets, then use SHA-1
2581 * hash of result; otherwise, use result (see section 4.8 of
2582 * draft-ietf-tls-ecc-03.txt).
2584 int field_size = EC_GROUP_get_degree(
2585 EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2587 if (field_size <= 24 * 8) { /* 192 bits */
2588 loopargs[i].outlen = KDF1_SHA1_len;
2589 loopargs[i].kdf = KDF1_SHA1;
2591 loopargs[i].outlen = (field_size + 7) / 8;
2592 loopargs[i].kdf = NULL;
2595 ECDH_compute_key(loopargs[i].secret_a, loopargs[i].outlen,
2596 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2597 loopargs[i].ecdh_a[testnum], loopargs[i].kdf);
2599 ECDH_compute_key(loopargs[i].secret_b, loopargs[i].outlen,
2600 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2601 loopargs[i].ecdh_b[testnum], loopargs[i].kdf);
2602 if (secret_size_a != secret_size_b)
2607 for (secret_idx = 0; (secret_idx < secret_size_a)
2608 && (ecdh_checks == 1); secret_idx++) {
2609 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2613 if (ecdh_checks == 0) {
2614 BIO_printf(bio_err, "ECDH computations don't match.\n");
2615 ERR_print_errors(bio_err);
2621 if (ecdh_checks != 0) {
2622 pkey_print_message("", "ecdh",
2624 test_curves_bits[testnum], ECDH_SECONDS);
2626 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2629 mr ? "+R7:%ld:%d:%.2f\n" :
2630 "%ld %d-bit ECDH ops in %.2fs\n", count,
2631 test_curves_bits[testnum], d);
2632 ecdh_results[testnum][0] = d / (double)count;
2637 if (rsa_count <= 1) {
2638 /* if longer than 10s, don't do any more */
2639 for (testnum++; testnum < EC_NUM; testnum++)
2640 ecdh_doit[testnum] = 0;
2648 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2649 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2651 printf("%s ", BN_options());
2652 #ifndef OPENSSL_NO_MD2
2653 printf("%s ", MD2_options());
2655 #ifndef OPENSSL_NO_RC4
2656 printf("%s ", RC4_options());
2658 #ifndef OPENSSL_NO_DES
2659 printf("%s ", DES_options());
2661 printf("%s ", AES_options());
2662 #ifndef OPENSSL_NO_IDEA
2663 printf("%s ", IDEA_options());
2665 #ifndef OPENSSL_NO_BF
2666 printf("%s ", BF_options());
2668 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2676 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2679 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2680 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2684 for (k = 0; k < ALGOR_NUM; k++) {
2688 printf("+F:%d:%s", k, names[k]);
2690 printf("%-13s", names[k]);
2691 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2692 if (results[k][testnum] > 10000 && !mr)
2693 printf(" %11.2fk", results[k][testnum] / 1e3);
2695 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2699 #ifndef OPENSSL_NO_RSA
2701 for (k = 0; k < RSA_NUM; k++) {
2704 if (testnum && !mr) {
2705 printf("%18ssign verify sign/s verify/s\n", " ");
2709 printf("+F2:%u:%u:%f:%f\n",
2710 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2712 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2713 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2714 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2717 #ifndef OPENSSL_NO_DSA
2719 for (k = 0; k < DSA_NUM; k++) {
2722 if (testnum && !mr) {
2723 printf("%18ssign verify sign/s verify/s\n", " ");
2727 printf("+F3:%u:%u:%f:%f\n",
2728 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2730 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2731 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2732 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2735 #ifndef OPENSSL_NO_EC
2737 for (k = 0; k < EC_NUM; k++) {
2740 if (testnum && !mr) {
2741 printf("%30ssign verify sign/s verify/s\n", " ");
2746 printf("+F4:%u:%u:%f:%f\n",
2747 k, test_curves_bits[k],
2748 ecdsa_results[k][0], ecdsa_results[k][1]);
2750 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2751 test_curves_bits[k],
2752 test_curves_names[k],
2753 ecdsa_results[k][0], ecdsa_results[k][1],
2754 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2758 #ifndef OPENSSL_NO_EC
2760 for (k = 0; k < EC_NUM; k++) {
2763 if (testnum && !mr) {
2764 printf("%30sop op/s\n", " ");
2768 printf("+F5:%u:%u:%f:%f\n",
2769 k, test_curves_bits[k],
2770 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2773 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2774 test_curves_bits[k],
2775 test_curves_names[k],
2776 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2783 ERR_print_errors(bio_err);
2784 for (i = 0; i < loopargs_len; i++) {
2785 OPENSSL_free(loopargs[i].buf_malloc);
2786 OPENSSL_free(loopargs[i].buf2_malloc);
2787 OPENSSL_free(loopargs[i].siglen);
2789 #ifndef OPENSSL_NO_RSA
2790 for (i = 0; i < loopargs_len; i++) {
2791 for (k = 0; k < RSA_NUM; k++)
2792 RSA_free(loopargs[i].rsa_key[k]);
2795 #ifndef OPENSSL_NO_DSA
2796 for (i = 0; i < loopargs_len; i++) {
2797 for (k = 0; k < DSA_NUM; k++)
2798 DSA_free(loopargs[i].dsa_key[k]);
2802 #ifndef OPENSSL_NO_EC
2803 for (i = 0; i < loopargs_len; i++) {
2804 for (k = 0; k < EC_NUM; k++) {
2805 EC_KEY_free(loopargs[i].ecdsa[k]);
2806 EC_KEY_free(loopargs[i].ecdh_a[k]);
2807 EC_KEY_free(loopargs[i].ecdh_b[k]);
2809 OPENSSL_free(loopargs[i].secret_a);
2810 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);
2825 static void print_message(const char *s, long num, int length)
2829 mr ? "+DT:%s:%d:%d\n"
2830 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2831 (void)BIO_flush(bio_err);
2835 mr ? "+DN:%s:%ld:%d\n"
2836 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2837 (void)BIO_flush(bio_err);
2841 static void pkey_print_message(const char *str, const char *str2, long num,
2846 mr ? "+DTP:%d:%s:%s:%d\n"
2847 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2848 (void)BIO_flush(bio_err);
2852 mr ? "+DNP:%ld:%d:%s:%s\n"
2853 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2854 (void)BIO_flush(bio_err);
2858 static void print_result(int alg, int run_no, int count, double time_used)
2861 BIO_puts(bio_err, "EVP error!\n");
2865 mr ? "+R:%d:%s:%f\n"
2866 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2867 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2871 static char *sstrsep(char **string, const char *delim)
2874 char *token = *string;
2879 memset(isdelim, 0, sizeof isdelim);
2883 isdelim[(unsigned char)(*delim)] = 1;
2887 while (!isdelim[(unsigned char)(**string)]) {
2899 static int do_multi(int multi)
2904 static char sep[] = ":";
2906 fds = malloc(sizeof(*fds) * multi);
2907 for (n = 0; n < multi; ++n) {
2908 if (pipe(fd) == -1) {
2909 BIO_printf(bio_err, "pipe failure\n");
2913 (void)BIO_flush(bio_err);
2920 if (dup(fd[1]) == -1) {
2921 BIO_printf(bio_err, "dup failed\n");
2930 printf("Forked child %d\n", n);
2933 /* for now, assume the pipe is long enough to take all the output */
2934 for (n = 0; n < multi; ++n) {
2939 f = fdopen(fds[n], "r");
2940 while (fgets(buf, sizeof buf, f)) {
2941 p = strchr(buf, '\n');
2944 if (buf[0] != '+') {
2945 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2949 printf("Got: %s from %d\n", buf, n);
2950 if (strncmp(buf, "+F:", 3) == 0) {
2955 alg = atoi(sstrsep(&p, sep));
2957 for (j = 0; j < SIZE_NUM; ++j)
2958 results[alg][j] += atof(sstrsep(&p, sep));
2959 } else if (strncmp(buf, "+F2:", 4) == 0) {
2964 k = atoi(sstrsep(&p, sep));
2967 d = atof(sstrsep(&p, sep));
2969 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2971 rsa_results[k][0] = d;
2973 d = atof(sstrsep(&p, sep));
2975 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2977 rsa_results[k][1] = d;
2979 # ifndef OPENSSL_NO_DSA
2980 else if (strncmp(buf, "+F3:", 4) == 0) {
2985 k = atoi(sstrsep(&p, sep));
2988 d = atof(sstrsep(&p, sep));
2990 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2992 dsa_results[k][0] = d;
2994 d = atof(sstrsep(&p, sep));
2996 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2998 dsa_results[k][1] = d;
3001 # ifndef OPENSSL_NO_EC
3002 else if (strncmp(buf, "+F4:", 4) == 0) {
3007 k = atoi(sstrsep(&p, sep));
3010 d = atof(sstrsep(&p, sep));
3012 ecdsa_results[k][0] =
3013 1 / (1 / ecdsa_results[k][0] + 1 / d);
3015 ecdsa_results[k][0] = d;
3017 d = atof(sstrsep(&p, sep));
3019 ecdsa_results[k][1] =
3020 1 / (1 / ecdsa_results[k][1] + 1 / d);
3022 ecdsa_results[k][1] = d;
3026 # ifndef OPENSSL_NO_EC
3027 else if (strncmp(buf, "+F5:", 4) == 0) {
3032 k = atoi(sstrsep(&p, sep));
3035 d = atof(sstrsep(&p, sep));
3037 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3039 ecdh_results[k][0] = d;
3044 else if (strncmp(buf, "+H:", 3) == 0) {
3047 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3057 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3059 static int mblengths[] =
3060 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3061 int j, count, num = OSSL_NELEM(mblengths);
3062 const char *alg_name;
3063 unsigned char *inp, *out, no_key[32], no_iv[16];
3064 EVP_CIPHER_CTX *ctx;
3067 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3068 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3069 ctx = EVP_CIPHER_CTX_new();
3070 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3071 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3073 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3075 for (j = 0; j < num; j++) {
3076 print_message(alg_name, 0, mblengths[j]);
3078 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3079 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3080 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3081 size_t len = mblengths[j];
3084 memset(aad, 0, 8); /* avoid uninitialized values */
3085 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3086 aad[9] = 3; /* version */
3088 aad[11] = 0; /* length */
3090 mb_param.out = NULL;
3093 mb_param.interleave = 8;
3095 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3096 sizeof(mb_param), &mb_param);
3102 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3103 sizeof(mb_param), &mb_param);
3107 RAND_bytes(out, 16);
3111 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3112 EVP_AEAD_TLS1_AAD_LEN, aad);
3113 EVP_Cipher(ctx, out, inp, len + pad);
3117 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3118 : "%d %s's in %.2fs\n", count, "evp", d);
3119 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3123 fprintf(stdout, "+H");
3124 for (j = 0; j < num; j++)
3125 fprintf(stdout, ":%d", mblengths[j]);
3126 fprintf(stdout, "\n");
3127 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3128 for (j = 0; j < num; j++)
3129 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3130 fprintf(stdout, "\n");
3133 "The 'numbers' are in 1000s of bytes per second processed.\n");
3134 fprintf(stdout, "type ");
3135 for (j = 0; j < num; j++)
3136 fprintf(stdout, "%7d bytes", mblengths[j]);
3137 fprintf(stdout, "\n");
3138 fprintf(stdout, "%-24s", alg_name);
3140 for (j = 0; j < num; j++) {
3141 if (results[D_EVP][j] > 10000)
3142 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3144 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3146 fprintf(stdout, "\n");
3151 EVP_CIPHER_CTX_free(ctx);