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 struct loopargs_st {
148 ASYNC_JOB *inprogress_job;
149 ASYNC_WAIT_CTX *wait_ctx;
152 unsigned char *buf_malloc;
153 unsigned char *buf2_malloc;
154 unsigned int *siglen;
155 #ifndef OPENSSL_NO_RSA
156 RSA *rsa_key[RSA_NUM];
158 #ifndef OPENSSL_NO_DSA
159 DSA *dsa_key[DSA_NUM];
161 #ifndef OPENSSL_NO_EC
162 EC_KEY *ecdsa[EC_NUM];
163 EC_KEY *ecdh_a[EC_NUM];
164 EC_KEY *ecdh_b[EC_NUM];
165 unsigned char *secret_a;
166 unsigned char *secret_b;
170 GCM128_CONTEXT *gcm_ctx;
173 #ifndef OPENSSL_NO_MD2
174 static int EVP_Digest_MD2_loop(void *args);
177 #ifndef OPENSSL_NO_MDC2
178 static int EVP_Digest_MDC2_loop(void *args);
180 #ifndef OPENSSL_NO_MD4
181 static int EVP_Digest_MD4_loop(void *args);
183 #ifndef OPENSSL_NO_MD5
184 static int MD5_loop(void *args);
185 static int HMAC_loop(void *args);
187 static int SHA1_loop(void *args);
188 static int SHA256_loop(void *args);
189 static int SHA512_loop(void *args);
190 #ifndef OPENSSL_NO_WHIRLPOOL
191 static int WHIRLPOOL_loop(void *args);
193 #ifndef OPENSSL_NO_RMD160
194 static int EVP_Digest_RMD160_loop(void *args);
196 #ifndef OPENSSL_NO_RC4
197 static int RC4_loop(void *args);
199 #ifndef OPENSSL_NO_DES
200 static int DES_ncbc_encrypt_loop(void *args);
201 static int DES_ede3_cbc_encrypt_loop(void *args);
203 static int AES_cbc_128_encrypt_loop(void *args);
204 static int AES_cbc_192_encrypt_loop(void *args);
205 static int AES_ige_128_encrypt_loop(void *args);
206 static int AES_cbc_256_encrypt_loop(void *args);
207 static int AES_ige_192_encrypt_loop(void *args);
208 static int AES_ige_256_encrypt_loop(void *args);
209 static int CRYPTO_gcm128_aad_loop(void *args);
210 static int EVP_Update_loop(void *args);
211 static int EVP_Digest_loop(void *args);
212 #ifndef OPENSSL_NO_RSA
213 static int RSA_sign_loop(void *args);
214 static int RSA_verify_loop(void *args);
216 #ifndef OPENSSL_NO_DSA
217 static int DSA_sign_loop(void *args);
218 static int DSA_verify_loop(void *args);
220 #ifndef OPENSSL_NO_EC
221 static int ECDSA_sign_loop(void *args);
222 static int ECDSA_verify_loop(void *args);
223 static int ECDH_compute_key_loop(void *args);
225 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
227 static double Time_F(int s);
228 static void print_message(const char *s, long num, int length);
229 static void pkey_print_message(const char *str, const char *str2,
230 long num, int bits, int sec);
231 static void print_result(int alg, int run_no, int count, double time_used);
233 static int do_multi(int multi);
236 static const char *names[ALGOR_NUM] = {
237 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
238 "des cbc", "des ede3", "idea cbc", "seed cbc",
239 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
240 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
241 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
242 "evp", "sha256", "sha512", "whirlpool",
243 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
246 static double results[ALGOR_NUM][SIZE_NUM];
247 static int lengths[SIZE_NUM] = {
248 16, 64, 256, 1024, 8 * 1024, 16 * 1024
251 #ifndef OPENSSL_NO_RSA
252 static double rsa_results[RSA_NUM][2];
254 #ifndef OPENSSL_NO_DSA
255 static double dsa_results[DSA_NUM][2];
257 #ifndef OPENSSL_NO_EC
258 static double ecdsa_results[EC_NUM][2];
259 static double ecdh_results[EC_NUM][1];
262 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
263 static const char rnd_seed[] =
264 "string to make the random number generator think it has entropy";
268 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
269 # define SIGRETTYPE void
271 # define SIGRETTYPE int
274 static SIGRETTYPE sig_done(int sig);
275 static SIGRETTYPE sig_done(int sig)
277 signal(SIGALRM, sig_done);
287 # if !defined(SIGALRM)
290 static unsigned int lapse, schlock;
291 static void alarm_win32(unsigned int secs)
296 # define alarm alarm_win32
298 static DWORD WINAPI sleepy(VOID * arg)
306 static double Time_F(int s)
313 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
315 DWORD err = GetLastError();
316 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
320 Sleep(0); /* scheduler spinlock */
321 ret = app_tminterval(s, usertime);
323 ret = app_tminterval(s, usertime);
325 TerminateThread(thr, 0);
333 static double Time_F(int s)
335 double ret = app_tminterval(s, usertime);
342 #ifndef OPENSSL_NO_EC
343 static const int KDF1_SHA1_len = 20;
344 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
347 if (*outlen < SHA_DIGEST_LENGTH)
349 *outlen = SHA_DIGEST_LENGTH;
350 return SHA1(in, inlen, out);
352 #endif /* OPENSSL_NO_EC */
354 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
356 static int found(const char *name, const OPT_PAIR * pairs, int *result)
358 for (; pairs->name; pairs++)
359 if (strcmp(name, pairs->name) == 0) {
360 *result = pairs->retval;
366 typedef enum OPTION_choice {
367 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
368 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
369 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
372 OPTIONS speed_options[] = {
373 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
374 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
375 {"help", OPT_HELP, '-', "Display this summary"},
376 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
377 {"decrypt", OPT_DECRYPT, '-',
378 "Time decryption instead of encryption (only EVP)"},
379 {"mr", OPT_MR, '-', "Produce machine readable output"},
381 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
382 {"elapsed", OPT_ELAPSED, '-',
383 "Measure time in real time instead of CPU user time"},
385 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
387 #ifndef OPENSSL_NO_ASYNC
388 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
390 #ifndef OPENSSL_NO_ENGINE
391 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
406 #define D_CBC_IDEA 10
407 #define D_CBC_SEED 11
411 #define D_CBC_CAST 15
412 #define D_CBC_128_AES 16
413 #define D_CBC_192_AES 17
414 #define D_CBC_256_AES 18
415 #define D_CBC_128_CML 19
416 #define D_CBC_192_CML 20
417 #define D_CBC_256_CML 21
421 #define D_WHIRLPOOL 25
422 #define D_IGE_128_AES 26
423 #define D_IGE_192_AES 27
424 #define D_IGE_256_AES 28
426 static OPT_PAIR doit_choices[] = {
427 #ifndef OPENSSL_NO_MD2
430 #ifndef OPENSSL_NO_MDC2
433 #ifndef OPENSSL_NO_MD4
436 #ifndef OPENSSL_NO_MD5
439 #ifndef OPENSSL_NO_MD5
443 {"sha256", D_SHA256},
444 {"sha512", D_SHA512},
445 #ifndef OPENSSL_NO_WHIRLPOOL
446 {"whirlpool", D_WHIRLPOOL},
448 #ifndef OPENSSL_NO_RMD160
449 {"ripemd", D_RMD160},
450 {"rmd160", D_RMD160},
451 {"ripemd160", D_RMD160},
453 #ifndef OPENSSL_NO_RC4
456 #ifndef OPENSSL_NO_DES
457 {"des-cbc", D_CBC_DES},
458 {"des-ede3", D_EDE3_DES},
460 {"aes-128-cbc", D_CBC_128_AES},
461 {"aes-192-cbc", D_CBC_192_AES},
462 {"aes-256-cbc", D_CBC_256_AES},
463 {"aes-128-ige", D_IGE_128_AES},
464 {"aes-192-ige", D_IGE_192_AES},
465 {"aes-256-ige", D_IGE_256_AES},
466 #ifndef OPENSSL_NO_RC2
467 {"rc2-cbc", D_CBC_RC2},
470 #ifndef OPENSSL_NO_RC5
471 {"rc5-cbc", D_CBC_RC5},
474 #ifndef OPENSSL_NO_IDEA
475 {"idea-cbc", D_CBC_IDEA},
476 {"idea", D_CBC_IDEA},
478 #ifndef OPENSSL_NO_SEED
479 {"seed-cbc", D_CBC_SEED},
480 {"seed", D_CBC_SEED},
482 #ifndef OPENSSL_NO_BF
483 {"bf-cbc", D_CBC_BF},
484 {"blowfish", D_CBC_BF},
487 #ifndef OPENSSL_NO_CAST
488 {"cast-cbc", D_CBC_CAST},
489 {"cast", D_CBC_CAST},
490 {"cast5", D_CBC_CAST},
496 #ifndef OPENSSL_NO_DSA
498 # define R_DSA_1024 1
499 # define R_DSA_2048 2
500 static OPT_PAIR dsa_choices[] = {
501 {"dsa512", R_DSA_512},
502 {"dsa1024", R_DSA_1024},
503 {"dsa2048", R_DSA_2048},
514 #define R_RSA_15360 6
515 static OPT_PAIR rsa_choices[] = {
516 {"rsa512", R_RSA_512},
517 {"rsa1024", R_RSA_1024},
518 {"rsa2048", R_RSA_2048},
519 {"rsa3072", R_RSA_3072},
520 {"rsa4096", R_RSA_4096},
521 {"rsa7680", R_RSA_7680},
522 {"rsa15360", R_RSA_15360},
542 #define R_EC_X25519 16
543 #ifndef OPENSSL_NO_EC
544 static OPT_PAIR ecdsa_choices[] = {
545 {"ecdsap160", R_EC_P160},
546 {"ecdsap192", R_EC_P192},
547 {"ecdsap224", R_EC_P224},
548 {"ecdsap256", R_EC_P256},
549 {"ecdsap384", R_EC_P384},
550 {"ecdsap521", R_EC_P521},
551 {"ecdsak163", R_EC_K163},
552 {"ecdsak233", R_EC_K233},
553 {"ecdsak283", R_EC_K283},
554 {"ecdsak409", R_EC_K409},
555 {"ecdsak571", R_EC_K571},
556 {"ecdsab163", R_EC_B163},
557 {"ecdsab233", R_EC_B233},
558 {"ecdsab283", R_EC_B283},
559 {"ecdsab409", R_EC_B409},
560 {"ecdsab571", R_EC_B571},
563 static OPT_PAIR ecdh_choices[] = {
564 {"ecdhp160", R_EC_P160},
565 {"ecdhp192", R_EC_P192},
566 {"ecdhp224", R_EC_P224},
567 {"ecdhp256", R_EC_P256},
568 {"ecdhp384", R_EC_P384},
569 {"ecdhp521", R_EC_P521},
570 {"ecdhk163", R_EC_K163},
571 {"ecdhk233", R_EC_K233},
572 {"ecdhk283", R_EC_K283},
573 {"ecdhk409", R_EC_K409},
574 {"ecdhk571", R_EC_K571},
575 {"ecdhb163", R_EC_B163},
576 {"ecdhb233", R_EC_B233},
577 {"ecdhb283", R_EC_B283},
578 {"ecdhb409", R_EC_B409},
579 {"ecdhb571", R_EC_B571},
580 {"ecdhx25519", R_EC_X25519},
586 # define COND(d) (count < (d))
587 # define COUNT(d) (d)
589 # define COND(unused_cond) (run && count<0x7fffffff)
590 # define COUNT(d) (count)
595 static long c[ALGOR_NUM][SIZE_NUM];
597 #ifndef OPENSSL_NO_MD2
598 static int EVP_Digest_MD2_loop(void *args)
600 loopargs_t *tempargs = (loopargs_t *)args;
601 unsigned char *buf = tempargs->buf;
602 unsigned char md2[MD2_DIGEST_LENGTH];
604 for (count = 0; COND(c[D_MD2][testnum]); count++) {
605 if (!EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
613 #ifndef OPENSSL_NO_MDC2
614 static int EVP_Digest_MDC2_loop(void *args)
616 loopargs_t *tempargs = (loopargs_t *)args;
617 unsigned char *buf = tempargs->buf;
618 unsigned char mdc2[MDC2_DIGEST_LENGTH];
620 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
621 if (!EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
629 #ifndef OPENSSL_NO_MD4
630 static int EVP_Digest_MD4_loop(void *args)
632 loopargs_t *tempargs = (loopargs_t *)args;
633 unsigned char *buf = tempargs->buf;
634 unsigned char md4[MD4_DIGEST_LENGTH];
636 for (count = 0; COND(c[D_MD4][testnum]); count++) {
637 if (!EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
638 NULL, EVP_md4(), NULL))
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];
664 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
665 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
666 HMAC_Update(hctx, buf, lengths[testnum]);
667 HMAC_Final(hctx, &(hmac[0]), NULL);
673 static int SHA1_loop(void *args)
675 loopargs_t *tempargs = (loopargs_t *)args;
676 unsigned char *buf = tempargs->buf;
677 unsigned char sha[SHA_DIGEST_LENGTH];
679 for (count = 0; COND(c[D_SHA1][testnum]); count++)
680 SHA1(buf, lengths[testnum], sha);
684 static int SHA256_loop(void *args)
686 loopargs_t *tempargs = (loopargs_t *)args;
687 unsigned char *buf = tempargs->buf;
688 unsigned char sha256[SHA256_DIGEST_LENGTH];
690 for (count = 0; COND(c[D_SHA256][testnum]); count++)
691 SHA256(buf, lengths[testnum], sha256);
695 static int SHA512_loop(void *args)
697 loopargs_t *tempargs = (loopargs_t *)args;
698 unsigned char *buf = tempargs->buf;
699 unsigned char sha512[SHA512_DIGEST_LENGTH];
701 for (count = 0; COND(c[D_SHA512][testnum]); count++)
702 SHA512(buf, lengths[testnum], sha512);
706 #ifndef OPENSSL_NO_WHIRLPOOL
707 static int WHIRLPOOL_loop(void *args)
709 loopargs_t *tempargs = (loopargs_t *)args;
710 unsigned char *buf = tempargs->buf;
711 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
713 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
714 WHIRLPOOL(buf, lengths[testnum], whirlpool);
719 #ifndef OPENSSL_NO_RMD160
720 static int EVP_Digest_RMD160_loop(void *args)
722 loopargs_t *tempargs = (loopargs_t *)args;
723 unsigned char *buf = tempargs->buf;
724 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
726 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
727 if (!EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]),
728 NULL, EVP_ripemd160(), NULL))
735 #ifndef OPENSSL_NO_RC4
736 static RC4_KEY rc4_ks;
737 static int RC4_loop(void *args)
739 loopargs_t *tempargs = (loopargs_t *)args;
740 unsigned char *buf = tempargs->buf;
742 for (count = 0; COND(c[D_RC4][testnum]); count++)
743 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
748 #ifndef OPENSSL_NO_DES
749 static unsigned char DES_iv[8];
750 static DES_key_schedule sch;
751 static DES_key_schedule sch2;
752 static DES_key_schedule sch3;
753 static int DES_ncbc_encrypt_loop(void *args)
755 loopargs_t *tempargs = (loopargs_t *)args;
756 unsigned char *buf = tempargs->buf;
758 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
759 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
760 &DES_iv, DES_ENCRYPT);
764 static int DES_ede3_cbc_encrypt_loop(void *args)
766 loopargs_t *tempargs = (loopargs_t *)args;
767 unsigned char *buf = tempargs->buf;
769 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
770 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
772 &DES_iv, DES_ENCRYPT);
777 #define MAX_BLOCK_SIZE 128
779 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
780 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
781 static int AES_cbc_128_encrypt_loop(void *args)
783 loopargs_t *tempargs = (loopargs_t *)args;
784 unsigned char *buf = tempargs->buf;
786 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
787 AES_cbc_encrypt(buf, buf,
788 (unsigned long)lengths[testnum], &aes_ks1,
793 static int AES_cbc_192_encrypt_loop(void *args)
795 loopargs_t *tempargs = (loopargs_t *)args;
796 unsigned char *buf = tempargs->buf;
798 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
799 AES_cbc_encrypt(buf, buf,
800 (unsigned long)lengths[testnum], &aes_ks2,
805 static int AES_cbc_256_encrypt_loop(void *args)
807 loopargs_t *tempargs = (loopargs_t *)args;
808 unsigned char *buf = tempargs->buf;
810 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
811 AES_cbc_encrypt(buf, buf,
812 (unsigned long)lengths[testnum], &aes_ks3,
817 static int AES_ige_128_encrypt_loop(void *args)
819 loopargs_t *tempargs = (loopargs_t *)args;
820 unsigned char *buf = tempargs->buf;
821 unsigned char *buf2 = tempargs->buf2;
823 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
824 AES_ige_encrypt(buf, buf2,
825 (unsigned long)lengths[testnum], &aes_ks1,
830 static int AES_ige_192_encrypt_loop(void *args)
832 loopargs_t *tempargs = (loopargs_t *)args;
833 unsigned char *buf = tempargs->buf;
834 unsigned char *buf2 = tempargs->buf2;
836 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
837 AES_ige_encrypt(buf, buf2,
838 (unsigned long)lengths[testnum], &aes_ks2,
843 static int AES_ige_256_encrypt_loop(void *args)
845 loopargs_t *tempargs = (loopargs_t *)args;
846 unsigned char *buf = tempargs->buf;
847 unsigned char *buf2 = tempargs->buf2;
849 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
850 AES_ige_encrypt(buf, buf2,
851 (unsigned long)lengths[testnum], &aes_ks3,
856 static int CRYPTO_gcm128_aad_loop(void *args)
858 loopargs_t *tempargs = (loopargs_t *)args;
859 unsigned char *buf = tempargs->buf;
860 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
862 for (count = 0; COND(c[D_GHASH][testnum]); count++)
863 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
867 static long save_count = 0;
868 static int decrypt = 0;
869 static int EVP_Update_loop(void *args)
871 loopargs_t *tempargs = (loopargs_t *)args;
872 unsigned char *buf = tempargs->buf;
873 EVP_CIPHER_CTX *ctx = tempargs->ctx;
876 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
879 for (count = 0; COND(nb_iter); count++)
880 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
882 for (count = 0; COND(nb_iter); count++)
883 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
885 EVP_DecryptFinal_ex(ctx, buf, &outl);
887 EVP_EncryptFinal_ex(ctx, buf, &outl);
891 static const EVP_MD *evp_md = NULL;
892 static int EVP_Digest_loop(void *args)
894 loopargs_t *tempargs = (loopargs_t *)args;
895 unsigned char *buf = tempargs->buf;
896 unsigned char md[EVP_MAX_MD_SIZE];
899 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
902 for (count = 0; COND(nb_iter); count++) {
903 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
909 #ifndef OPENSSL_NO_RSA
910 static long rsa_c[RSA_NUM][2];
912 static int RSA_sign_loop(void *args)
914 loopargs_t *tempargs = (loopargs_t *)args;
915 unsigned char *buf = tempargs->buf;
916 unsigned char *buf2 = tempargs->buf2;
917 unsigned int *rsa_num = tempargs->siglen;
918 RSA **rsa_key = tempargs->rsa_key;
920 for (count = 0; COND(rsa_c[testnum][0]); count++) {
921 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
923 BIO_printf(bio_err, "RSA sign failure\n");
924 ERR_print_errors(bio_err);
932 static int RSA_verify_loop(void *args)
934 loopargs_t *tempargs = (loopargs_t *)args;
935 unsigned char *buf = tempargs->buf;
936 unsigned char *buf2 = tempargs->buf2;
937 unsigned int rsa_num = *(tempargs->siglen);
938 RSA **rsa_key = tempargs->rsa_key;
940 for (count = 0; COND(rsa_c[testnum][1]); count++) {
941 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
943 BIO_printf(bio_err, "RSA verify failure\n");
944 ERR_print_errors(bio_err);
953 #ifndef OPENSSL_NO_DSA
954 static long dsa_c[DSA_NUM][2];
955 static int DSA_sign_loop(void *args)
957 loopargs_t *tempargs = (loopargs_t *)args;
958 unsigned char *buf = tempargs->buf;
959 unsigned char *buf2 = tempargs->buf2;
960 DSA **dsa_key = tempargs->dsa_key;
961 unsigned int *siglen = tempargs->siglen;
963 for (count = 0; COND(dsa_c[testnum][0]); count++) {
964 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
966 BIO_printf(bio_err, "DSA sign failure\n");
967 ERR_print_errors(bio_err);
975 static int DSA_verify_loop(void *args)
977 loopargs_t *tempargs = (loopargs_t *)args;
978 unsigned char *buf = tempargs->buf;
979 unsigned char *buf2 = tempargs->buf2;
980 DSA **dsa_key = tempargs->dsa_key;
981 unsigned int siglen = *(tempargs->siglen);
983 for (count = 0; COND(dsa_c[testnum][1]); count++) {
984 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
986 BIO_printf(bio_err, "DSA verify failure\n");
987 ERR_print_errors(bio_err);
996 #ifndef OPENSSL_NO_EC
997 static long ecdsa_c[EC_NUM][2];
998 static int ECDSA_sign_loop(void *args)
1000 loopargs_t *tempargs = (loopargs_t *)args;
1001 unsigned char *buf = tempargs->buf;
1002 EC_KEY **ecdsa = tempargs->ecdsa;
1003 unsigned char *ecdsasig = tempargs->buf2;
1004 unsigned int *ecdsasiglen = tempargs->siglen;
1006 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1007 ret = ECDSA_sign(0, buf, 20,
1008 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1010 BIO_printf(bio_err, "ECDSA sign failure\n");
1011 ERR_print_errors(bio_err);
1019 static int ECDSA_verify_loop(void *args)
1021 loopargs_t *tempargs = (loopargs_t *)args;
1022 unsigned char *buf = tempargs->buf;
1023 EC_KEY **ecdsa = tempargs->ecdsa;
1024 unsigned char *ecdsasig = tempargs->buf2;
1025 unsigned int ecdsasiglen = *(tempargs->siglen);
1027 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1028 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1031 BIO_printf(bio_err, "ECDSA verify failure\n");
1032 ERR_print_errors(bio_err);
1041 static void *(*kdf) (const void *in, size_t inlen, void *out,
1044 /* ******************************************************************** */
1045 static long ecdh_c[EC_NUM][1];
1047 static int ECDH_compute_key_loop(void *args)
1049 loopargs_t *tempargs = (loopargs_t *)args;
1050 EC_KEY **ecdh_a = tempargs->ecdh_a;
1051 EC_KEY **ecdh_b = tempargs->ecdh_b;
1052 unsigned char *secret_a = tempargs->secret_a;
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);
1061 #endif /* ndef OPENSSL_NO_EC */
1064 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1066 int job_op_count = 0;
1067 int total_op_count = 0;
1068 int num_inprogress = 0;
1071 OSSL_ASYNC_FD job_fd = 0;
1072 size_t num_job_fds = 0;
1076 if (async_jobs == 0) {
1077 return loop_function((void *)loopargs);
1081 for (i = 0; i < async_jobs && !error; i++) {
1082 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1083 &job_op_count, loop_function,
1084 (void *)(loopargs + i), sizeof(loopargs_t))) {
1089 if (job_op_count == -1) {
1092 total_op_count += job_op_count;
1097 BIO_printf(bio_err, "Failure in the job\n");
1098 ERR_print_errors(bio_err);
1104 while (num_inprogress > 0) {
1105 #if defined(OPENSSL_SYS_WINDOWS)
1107 #elif defined(OPENSSL_SYS_UNIX)
1108 int select_result = 0;
1109 OSSL_ASYNC_FD max_fd = 0;
1112 FD_ZERO(&waitfdset);
1114 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1115 if (loopargs[i].inprogress_job == NULL)
1118 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1119 || num_job_fds > 1) {
1120 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1121 ERR_print_errors(bio_err);
1125 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1126 FD_SET(job_fd, &waitfdset);
1127 if (job_fd > max_fd)
1131 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1133 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1134 "Decrease the value of async_jobs\n",
1135 max_fd, FD_SETSIZE);
1136 ERR_print_errors(bio_err);
1141 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1142 if (select_result == -1 && errno == EINTR)
1145 if (select_result == -1) {
1146 BIO_printf(bio_err, "Failure in the select\n");
1147 ERR_print_errors(bio_err);
1152 if (select_result == 0)
1156 for (i = 0; i < async_jobs; i++) {
1157 if (loopargs[i].inprogress_job == NULL)
1160 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1161 || num_job_fds > 1) {
1162 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1163 ERR_print_errors(bio_err);
1167 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1169 #if defined(OPENSSL_SYS_UNIX)
1170 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1172 #elif defined(OPENSSL_SYS_WINDOWS)
1173 if (num_job_fds == 1 &&
1174 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1178 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1179 &job_op_count, loop_function, (void *)(loopargs + i),
1180 sizeof(loopargs_t))) {
1184 if (job_op_count == -1) {
1187 total_op_count += job_op_count;
1190 loopargs[i].inprogress_job = NULL;
1195 loopargs[i].inprogress_job = NULL;
1196 BIO_printf(bio_err, "Failure in the job\n");
1197 ERR_print_errors(bio_err);
1204 return error ? -1 : total_op_count;
1207 int speed_main(int argc, char **argv)
1209 loopargs_t *loopargs = NULL;
1211 int loopargs_len = 0;
1213 #ifndef OPENSSL_NO_ENGINE
1214 const char *engine_id = NULL;
1216 const EVP_CIPHER *evp_cipher = NULL;
1219 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1220 #ifndef OPENSSL_NO_DSA
1221 int dsa_doit[DSA_NUM];
1223 int rsa_doit[RSA_NUM];
1224 int ret = 1, i, k, misalign = 0;
1230 /* What follows are the buffers and key material. */
1231 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1234 #ifndef OPENSSL_NO_RC5
1237 #ifndef OPENSSL_NO_RC2
1240 #ifndef OPENSSL_NO_IDEA
1241 IDEA_KEY_SCHEDULE idea_ks;
1243 #ifndef OPENSSL_NO_SEED
1244 SEED_KEY_SCHEDULE seed_ks;
1246 #ifndef OPENSSL_NO_BF
1249 #ifndef OPENSSL_NO_CAST
1252 static const unsigned char key16[16] = {
1253 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1254 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1256 static const unsigned char key24[24] = {
1257 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1258 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1259 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1261 static const unsigned char key32[32] = {
1262 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1263 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1264 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1265 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1267 #ifndef OPENSSL_NO_CAMELLIA
1268 static const unsigned char ckey24[24] = {
1269 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1270 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1271 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1273 static const unsigned char ckey32[32] = {
1274 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1275 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1276 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1277 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1279 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1281 #ifndef OPENSSL_NO_DES
1282 static DES_cblock key = {
1283 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1285 static DES_cblock key2 = {
1286 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1288 static DES_cblock key3 = {
1289 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1292 #ifndef OPENSSL_NO_RSA
1293 static unsigned int rsa_bits[RSA_NUM] = {
1294 512, 1024, 2048, 3072, 4096, 7680, 15360
1296 static unsigned char *rsa_data[RSA_NUM] = {
1297 test512, test1024, test2048, test3072, test4096, test7680, test15360
1299 static int rsa_data_length[RSA_NUM] = {
1300 sizeof(test512), sizeof(test1024),
1301 sizeof(test2048), sizeof(test3072),
1302 sizeof(test4096), sizeof(test7680),
1306 #ifndef OPENSSL_NO_DSA
1307 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1309 #ifndef OPENSSL_NO_EC
1311 * We only test over the following curves as they are representative, To
1312 * add tests over more curves, simply add the curve NID and curve name to
1313 * the following arrays and increase the EC_NUM value accordingly.
1315 static unsigned int test_curves[EC_NUM] = {
1317 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1318 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1320 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1321 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1322 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1327 static const char *test_curves_names[EC_NUM] = {
1329 "secp160r1", "nistp192", "nistp224",
1330 "nistp256", "nistp384", "nistp521",
1332 "nistk163", "nistk233", "nistk283",
1333 "nistk409", "nistk571", "nistb163",
1334 "nistb233", "nistb283", "nistb409",
1339 static int test_curves_bits[EC_NUM] = {
1345 571, 253 /* X25519 */
1348 #ifndef OPENSSL_NO_EC
1349 int ecdsa_doit[EC_NUM];
1350 int secret_size_a, secret_size_b;
1351 int ecdh_checks = 1;
1353 int ecdh_doit[EC_NUM];
1356 memset(results, 0, sizeof(results));
1358 #ifndef OPENSSL_NO_DES
1359 memset(DES_iv, 0, sizeof(DES_iv));
1361 memset(iv, 0, sizeof(iv));
1363 for (i = 0; i < ALGOR_NUM; i++)
1365 for (i = 0; i < RSA_NUM; i++)
1367 #ifndef OPENSSL_NO_DSA
1368 for (i = 0; i < DSA_NUM; i++)
1371 #ifndef OPENSSL_NO_EC
1372 for (i = 0; i < EC_NUM; i++)
1374 for (i = 0; i < EC_NUM; i++)
1380 prog = opt_init(argc, argv, speed_options);
1381 while ((o = opt_next()) != OPT_EOF) {
1386 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1389 opt_help(speed_options);
1396 evp_cipher = EVP_get_cipherbyname(opt_arg());
1397 if (evp_cipher == NULL)
1398 evp_md = EVP_get_digestbyname(opt_arg());
1399 if (evp_cipher == NULL && evp_md == NULL) {
1401 "%s: %s an unknown cipher or digest\n",
1412 * In a forked execution, an engine might need to be
1413 * initialised by each child process, not by the parent.
1414 * So store the name here and run setup_engine() later on.
1416 #ifndef OPENSSL_NO_ENGINE
1417 engine_id = opt_arg();
1422 multi = atoi(opt_arg());
1426 #ifndef OPENSSL_NO_ASYNC
1427 async_jobs = atoi(opt_arg());
1428 if (!ASYNC_is_capable()) {
1430 "%s: async_jobs specified but async not supported\n",
1437 if (!opt_int(opt_arg(), &misalign))
1439 if (misalign > MISALIGN) {
1441 "%s: Maximum offset is %d\n", prog, MISALIGN);
1453 argc = opt_num_rest();
1456 /* Remaining arguments are algorithms. */
1457 for ( ; *argv; argv++) {
1458 if (found(*argv, doit_choices, &i)) {
1462 #ifndef OPENSSL_NO_DES
1463 if (strcmp(*argv, "des") == 0) {
1464 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1468 if (strcmp(*argv, "sha") == 0) {
1469 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1472 #ifndef OPENSSL_NO_RSA
1474 if (strcmp(*argv, "openssl") == 0) {
1475 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1479 if (strcmp(*argv, "rsa") == 0) {
1480 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1481 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1482 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1483 rsa_doit[R_RSA_15360] = 1;
1486 if (found(*argv, rsa_choices, &i)) {
1491 #ifndef OPENSSL_NO_DSA
1492 if (strcmp(*argv, "dsa") == 0) {
1493 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1494 dsa_doit[R_DSA_2048] = 1;
1497 if (found(*argv, dsa_choices, &i)) {
1502 if (strcmp(*argv, "aes") == 0) {
1503 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1504 doit[D_CBC_256_AES] = 1;
1507 #ifndef OPENSSL_NO_CAMELLIA
1508 if (strcmp(*argv, "camellia") == 0) {
1509 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1510 doit[D_CBC_256_CML] = 1;
1514 #ifndef OPENSSL_NO_EC
1515 if (strcmp(*argv, "ecdsa") == 0) {
1516 for (i = 0; i < EC_NUM; i++)
1520 if (found(*argv, ecdsa_choices, &i)) {
1524 if (strcmp(*argv, "ecdh") == 0) {
1525 for (i = 0; i < EC_NUM; i++)
1529 if (found(*argv, ecdh_choices, &i)) {
1534 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1538 /* Initialize the job pool if async mode is enabled */
1539 if (async_jobs > 0) {
1540 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1542 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1547 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1548 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1549 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1551 for (i = 0; i < loopargs_len; i++) {
1552 if (async_jobs > 0) {
1553 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1554 if (loopargs[i].wait_ctx == NULL) {
1555 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1560 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1561 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1562 /* Align the start of buffers on a 64 byte boundary */
1563 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1564 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1565 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1566 #ifndef OPENSSL_NO_EC
1567 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1568 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1573 if (multi && do_multi(multi))
1577 /* Initialize the engine after the fork */
1578 (void)setup_engine(engine_id, 0);
1580 /* No parameters; turn on everything. */
1581 if ((argc == 0) && !doit[D_EVP]) {
1582 for (i = 0; i < ALGOR_NUM; i++)
1585 for (i = 0; i < RSA_NUM; i++)
1587 #ifndef OPENSSL_NO_DSA
1588 for (i = 0; i < DSA_NUM; i++)
1591 #ifndef OPENSSL_NO_EC
1592 for (i = 0; i < EC_NUM; i++)
1594 for (i = 0; i < EC_NUM; i++)
1598 for (i = 0; i < ALGOR_NUM; i++)
1602 if (usertime == 0 && !mr)
1604 "You have chosen to measure elapsed time "
1605 "instead of user CPU time.\n");
1607 #ifndef OPENSSL_NO_RSA
1608 for (i = 0; i < loopargs_len; i++) {
1609 for (k = 0; k < RSA_NUM; k++) {
1610 const unsigned char *p;
1613 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1614 if (loopargs[i].rsa_key[k] == NULL) {
1615 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1622 #ifndef OPENSSL_NO_DSA
1623 for (i = 0; i < loopargs_len; i++) {
1624 loopargs[i].dsa_key[0] = get_dsa512();
1625 loopargs[i].dsa_key[1] = get_dsa1024();
1626 loopargs[i].dsa_key[2] = get_dsa2048();
1629 #ifndef OPENSSL_NO_DES
1630 DES_set_key_unchecked(&key, &sch);
1631 DES_set_key_unchecked(&key2, &sch2);
1632 DES_set_key_unchecked(&key3, &sch3);
1634 AES_set_encrypt_key(key16, 128, &aes_ks1);
1635 AES_set_encrypt_key(key24, 192, &aes_ks2);
1636 AES_set_encrypt_key(key32, 256, &aes_ks3);
1637 #ifndef OPENSSL_NO_CAMELLIA
1638 Camellia_set_key(key16, 128, &camellia_ks1);
1639 Camellia_set_key(ckey24, 192, &camellia_ks2);
1640 Camellia_set_key(ckey32, 256, &camellia_ks3);
1642 #ifndef OPENSSL_NO_IDEA
1643 IDEA_set_encrypt_key(key16, &idea_ks);
1645 #ifndef OPENSSL_NO_SEED
1646 SEED_set_key(key16, &seed_ks);
1648 #ifndef OPENSSL_NO_RC4
1649 RC4_set_key(&rc4_ks, 16, key16);
1651 #ifndef OPENSSL_NO_RC2
1652 RC2_set_key(&rc2_ks, 16, key16, 128);
1654 #ifndef OPENSSL_NO_RC5
1655 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1657 #ifndef OPENSSL_NO_BF
1658 BF_set_key(&bf_ks, 16, key16);
1660 #ifndef OPENSSL_NO_CAST
1661 CAST_set_key(&cast_ks, 16, key16);
1663 #ifndef OPENSSL_NO_RSA
1664 memset(rsa_c, 0, sizeof(rsa_c));
1667 # ifndef OPENSSL_NO_DES
1668 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1674 for (it = count; it; it--)
1675 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1676 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1680 c[D_MD2][0] = count / 10;
1681 c[D_MDC2][0] = count / 10;
1682 c[D_MD4][0] = count;
1683 c[D_MD5][0] = count;
1684 c[D_HMAC][0] = count;
1685 c[D_SHA1][0] = count;
1686 c[D_RMD160][0] = count;
1687 c[D_RC4][0] = count * 5;
1688 c[D_CBC_DES][0] = count;
1689 c[D_EDE3_DES][0] = count / 3;
1690 c[D_CBC_IDEA][0] = count;
1691 c[D_CBC_SEED][0] = count;
1692 c[D_CBC_RC2][0] = count;
1693 c[D_CBC_RC5][0] = count;
1694 c[D_CBC_BF][0] = count;
1695 c[D_CBC_CAST][0] = count;
1696 c[D_CBC_128_AES][0] = count;
1697 c[D_CBC_192_AES][0] = count;
1698 c[D_CBC_256_AES][0] = count;
1699 c[D_CBC_128_CML][0] = count;
1700 c[D_CBC_192_CML][0] = count;
1701 c[D_CBC_256_CML][0] = count;
1702 c[D_SHA256][0] = count;
1703 c[D_SHA512][0] = count;
1704 c[D_WHIRLPOOL][0] = count;
1705 c[D_IGE_128_AES][0] = count;
1706 c[D_IGE_192_AES][0] = count;
1707 c[D_IGE_256_AES][0] = count;
1708 c[D_GHASH][0] = count;
1710 for (i = 1; i < SIZE_NUM; i++) {
1713 l0 = (long)lengths[0];
1714 l1 = (long)lengths[i];
1716 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1717 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1718 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1719 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1720 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1721 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1722 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1723 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1724 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1725 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1726 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1728 l0 = (long)lengths[i - 1];
1730 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1731 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1732 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1733 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1734 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1735 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1736 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1737 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1738 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1739 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1740 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1741 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1742 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1743 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1744 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1745 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1746 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1747 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1750 # ifndef OPENSSL_NO_RSA
1751 rsa_c[R_RSA_512][0] = count / 2000;
1752 rsa_c[R_RSA_512][1] = count / 400;
1753 for (i = 1; i < RSA_NUM; i++) {
1754 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1755 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1756 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1759 if (rsa_c[i][0] == 0) {
1767 # ifndef OPENSSL_NO_DSA
1768 dsa_c[R_DSA_512][0] = count / 1000;
1769 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1770 for (i = 1; i < DSA_NUM; i++) {
1771 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1772 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1773 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1776 if (dsa_c[i] == 0) { /* Always false */
1784 # ifndef OPENSSL_NO_EC
1785 ecdsa_c[R_EC_P160][0] = count / 1000;
1786 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1787 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1788 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1789 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1790 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1793 if (ecdsa_c[i] == 0) { /* Always false */
1799 ecdsa_c[R_EC_K163][0] = count / 1000;
1800 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1801 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1802 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1803 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1804 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1807 if (ecdsa_c[i] == 0) { /* Always false */
1813 ecdsa_c[R_EC_B163][0] = count / 1000;
1814 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1815 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1816 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1817 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1818 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1821 if (ecdsa_c[i] == 0) { /* Always false */
1828 ecdh_c[R_EC_P160][0] = count / 1000;
1829 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1830 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1831 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1834 if (ecdh_c[i] == 0) { /* always false */
1839 ecdh_c[R_EC_K163][0] = count / 1000;
1840 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1841 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1842 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1845 if (ecdh_c[i] == 0) { /* always false */
1850 ecdh_c[R_EC_B163][0] = count / 1000;
1851 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1852 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1853 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1856 if (ecdh_c[i] == 0) { /* always false */
1864 /* not worth fixing */
1865 # error "You cannot disable DES on systems without SIGALRM."
1866 # endif /* OPENSSL_NO_DES */
1869 signal(SIGALRM, sig_done);
1871 #endif /* SIGALRM */
1873 #ifndef OPENSSL_NO_MD2
1875 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1876 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1878 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1880 print_result(D_MD2, testnum, count, d);
1884 #ifndef OPENSSL_NO_MDC2
1886 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1887 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1889 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1891 print_result(D_MDC2, testnum, count, d);
1896 #ifndef OPENSSL_NO_MD4
1898 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1899 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1901 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1903 print_result(D_MD4, testnum, count, d);
1908 #ifndef OPENSSL_NO_MD5
1910 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1911 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1913 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1915 print_result(D_MD5, testnum, count, d);
1920 #ifndef OPENSSL_NO_MD5
1922 for (i = 0; i < loopargs_len; i++) {
1923 loopargs[i].hctx = HMAC_CTX_new();
1924 if (loopargs[i].hctx == NULL) {
1925 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1929 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1930 16, EVP_md5(), NULL);
1932 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1933 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1935 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1937 print_result(D_HMAC, testnum, count, d);
1939 for (i = 0; i < loopargs_len; i++) {
1940 HMAC_CTX_free(loopargs[i].hctx);
1945 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1946 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1948 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1950 print_result(D_SHA1, testnum, count, d);
1953 if (doit[D_SHA256]) {
1954 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1955 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1957 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1959 print_result(D_SHA256, testnum, count, d);
1962 if (doit[D_SHA512]) {
1963 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1964 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1966 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1968 print_result(D_SHA512, testnum, count, d);
1972 #ifndef OPENSSL_NO_WHIRLPOOL
1973 if (doit[D_WHIRLPOOL]) {
1974 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1975 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1977 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1979 print_result(D_WHIRLPOOL, testnum, count, d);
1984 #ifndef OPENSSL_NO_RMD160
1985 if (doit[D_RMD160]) {
1986 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1987 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1989 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1991 print_result(D_RMD160, testnum, count, d);
1995 #ifndef OPENSSL_NO_RC4
1997 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1998 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2000 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2002 print_result(D_RC4, testnum, count, d);
2006 #ifndef OPENSSL_NO_DES
2007 if (doit[D_CBC_DES]) {
2008 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2009 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2011 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2013 print_result(D_CBC_DES, testnum, count, d);
2017 if (doit[D_EDE3_DES]) {
2018 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2019 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2021 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2023 print_result(D_EDE3_DES, testnum, count, d);
2028 if (doit[D_CBC_128_AES]) {
2029 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2030 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2033 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2035 print_result(D_CBC_128_AES, testnum, count, d);
2038 if (doit[D_CBC_192_AES]) {
2039 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2040 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2043 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2045 print_result(D_CBC_192_AES, testnum, count, d);
2048 if (doit[D_CBC_256_AES]) {
2049 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2050 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2053 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2055 print_result(D_CBC_256_AES, testnum, count, d);
2059 if (doit[D_IGE_128_AES]) {
2060 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2061 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2064 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2066 print_result(D_IGE_128_AES, testnum, count, d);
2069 if (doit[D_IGE_192_AES]) {
2070 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2071 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2074 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2076 print_result(D_IGE_192_AES, testnum, count, d);
2079 if (doit[D_IGE_256_AES]) {
2080 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2081 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2084 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2086 print_result(D_IGE_256_AES, testnum, count, d);
2089 if (doit[D_GHASH]) {
2090 for (i = 0; i < loopargs_len; i++) {
2091 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2092 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2095 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2096 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2098 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2100 print_result(D_GHASH, testnum, count, d);
2102 for (i = 0; i < loopargs_len; i++)
2103 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2106 #ifndef OPENSSL_NO_CAMELLIA
2107 if (doit[D_CBC_128_CML]) {
2108 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2109 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2111 if (async_jobs > 0) {
2112 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2116 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2117 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2118 (unsigned long)lengths[testnum], &camellia_ks1,
2119 iv, CAMELLIA_ENCRYPT);
2121 print_result(D_CBC_128_CML, testnum, count, d);
2124 if (doit[D_CBC_192_CML]) {
2125 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2126 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2128 if (async_jobs > 0) {
2129 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2133 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2134 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2135 (unsigned long)lengths[testnum], &camellia_ks2,
2136 iv, CAMELLIA_ENCRYPT);
2138 print_result(D_CBC_192_CML, testnum, count, d);
2141 if (doit[D_CBC_256_CML]) {
2142 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2143 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2145 if (async_jobs > 0) {
2146 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2150 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2151 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2152 (unsigned long)lengths[testnum], &camellia_ks3,
2153 iv, CAMELLIA_ENCRYPT);
2155 print_result(D_CBC_256_CML, testnum, count, d);
2159 #ifndef OPENSSL_NO_IDEA
2160 if (doit[D_CBC_IDEA]) {
2161 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2162 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2163 if (async_jobs > 0) {
2164 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2168 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2169 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2170 (unsigned long)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 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2180 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2181 if (async_jobs > 0) {
2182 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2186 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2187 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2188 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
2190 print_result(D_CBC_SEED, testnum, count, d);
2194 #ifndef OPENSSL_NO_RC2
2195 if (doit[D_CBC_RC2]) {
2196 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2197 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2198 if (async_jobs > 0) {
2199 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2203 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2204 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2205 (unsigned long)lengths[testnum], &rc2_ks,
2208 print_result(D_CBC_RC2, testnum, count, d);
2212 #ifndef OPENSSL_NO_RC5
2213 if (doit[D_CBC_RC5]) {
2214 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2215 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2216 if (async_jobs > 0) {
2217 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2221 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2222 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2223 (unsigned long)lengths[testnum], &rc5_ks,
2226 print_result(D_CBC_RC5, testnum, count, d);
2230 #ifndef OPENSSL_NO_BF
2231 if (doit[D_CBC_BF]) {
2232 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2233 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2234 if (async_jobs > 0) {
2235 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2239 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2240 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2241 (unsigned long)lengths[testnum], &bf_ks,
2244 print_result(D_CBC_BF, testnum, count, d);
2248 #ifndef OPENSSL_NO_CAST
2249 if (doit[D_CBC_CAST]) {
2250 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2251 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2252 if (async_jobs > 0) {
2253 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2257 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2258 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2259 (unsigned long)lengths[testnum], &cast_ks,
2262 print_result(D_CBC_CAST, testnum, count, d);
2268 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2269 if (multiblock && evp_cipher) {
2271 (EVP_CIPHER_flags(evp_cipher) &
2272 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2273 BIO_printf(bio_err, "%s is not multi-block capable\n",
2274 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2277 if (async_jobs > 0) {
2278 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2281 multiblock_speed(evp_cipher);
2286 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2289 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2291 * -O3 -fschedule-insns messes up an optimization here!
2292 * names[D_EVP] somehow becomes NULL
2294 print_message(names[D_EVP], save_count, lengths[testnum]);
2296 for (k = 0; k < loopargs_len; k++) {
2297 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2299 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2301 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2302 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2306 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2308 for (k = 0; k < loopargs_len; k++) {
2309 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2313 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2314 print_message(names[D_EVP], save_count, lengths[testnum]);
2316 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2319 print_result(D_EVP, testnum, count, d);
2323 for (i = 0; i < loopargs_len; i++)
2324 RAND_bytes(loopargs[i].buf, 36);
2326 #ifndef OPENSSL_NO_RSA
2327 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2329 if (!rsa_doit[testnum])
2331 for (i = 0; i < loopargs_len; i++) {
2332 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2333 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2339 "RSA sign failure. No RSA sign will be done.\n");
2340 ERR_print_errors(bio_err);
2343 pkey_print_message("private", "rsa",
2344 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2345 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2347 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2350 mr ? "+R1:%ld:%d:%.2f\n"
2351 : "%ld %d bit private RSA's in %.2fs\n",
2352 count, rsa_bits[testnum], d);
2353 rsa_results[testnum][0] = d / (double)count;
2357 for (i = 0; i < loopargs_len; i++) {
2358 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2359 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2365 "RSA verify failure. No RSA verify will be done.\n");
2366 ERR_print_errors(bio_err);
2367 rsa_doit[testnum] = 0;
2369 pkey_print_message("public", "rsa",
2370 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2372 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2375 mr ? "+R2:%ld:%d:%.2f\n"
2376 : "%ld %d bit public RSA's in %.2fs\n",
2377 count, rsa_bits[testnum], d);
2378 rsa_results[testnum][1] = d / (double)count;
2381 if (rsa_count <= 1) {
2382 /* if longer than 10s, don't do any more */
2383 for (testnum++; testnum < RSA_NUM; testnum++)
2384 rsa_doit[testnum] = 0;
2389 for (i = 0; i < loopargs_len; i++)
2390 RAND_bytes(loopargs[i].buf, 36);
2392 #ifndef OPENSSL_NO_DSA
2393 if (RAND_status() != 1) {
2394 RAND_seed(rnd_seed, sizeof rnd_seed);
2396 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2398 if (!dsa_doit[testnum])
2401 /* DSA_generate_key(dsa_key[testnum]); */
2402 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2403 for (i = 0; i < loopargs_len; i++) {
2404 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2405 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2411 "DSA sign failure. No DSA sign will be done.\n");
2412 ERR_print_errors(bio_err);
2415 pkey_print_message("sign", "dsa",
2416 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2418 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2421 mr ? "+R3:%ld:%d:%.2f\n"
2422 : "%ld %d bit DSA signs in %.2fs\n",
2423 count, dsa_bits[testnum], d);
2424 dsa_results[testnum][0] = d / (double)count;
2428 for (i = 0; i < loopargs_len; i++) {
2429 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2430 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2436 "DSA verify failure. No DSA verify will be done.\n");
2437 ERR_print_errors(bio_err);
2438 dsa_doit[testnum] = 0;
2440 pkey_print_message("verify", "dsa",
2441 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2443 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2446 mr ? "+R4:%ld:%d:%.2f\n"
2447 : "%ld %d bit DSA verify in %.2fs\n",
2448 count, dsa_bits[testnum], d);
2449 dsa_results[testnum][1] = d / (double)count;
2452 if (rsa_count <= 1) {
2453 /* if longer than 10s, don't do any more */
2454 for (testnum++; testnum < DSA_NUM; testnum++)
2455 dsa_doit[testnum] = 0;
2460 #ifndef OPENSSL_NO_EC
2461 if (RAND_status() != 1) {
2462 RAND_seed(rnd_seed, sizeof rnd_seed);
2464 for (testnum = 0; testnum < EC_NUM; testnum++) {
2467 if (!ecdsa_doit[testnum])
2468 continue; /* Ignore Curve */
2469 for (i = 0; i < loopargs_len; i++) {
2470 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2471 if (loopargs[i].ecdsa[testnum] == NULL) {
2477 BIO_printf(bio_err, "ECDSA failure.\n");
2478 ERR_print_errors(bio_err);
2481 for (i = 0; i < loopargs_len; i++) {
2482 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2483 /* Perform ECDSA signature test */
2484 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2485 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2486 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2492 "ECDSA sign failure. No ECDSA sign will be done.\n");
2493 ERR_print_errors(bio_err);
2496 pkey_print_message("sign", "ecdsa",
2497 ecdsa_c[testnum][0],
2498 test_curves_bits[testnum], ECDSA_SECONDS);
2500 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2504 mr ? "+R5:%ld:%d:%.2f\n" :
2505 "%ld %d bit ECDSA signs in %.2fs \n",
2506 count, test_curves_bits[testnum], d);
2507 ecdsa_results[testnum][0] = d / (double)count;
2511 /* Perform ECDSA verification test */
2512 for (i = 0; i < loopargs_len; i++) {
2513 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2514 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2520 "ECDSA verify failure. No ECDSA verify will be done.\n");
2521 ERR_print_errors(bio_err);
2522 ecdsa_doit[testnum] = 0;
2524 pkey_print_message("verify", "ecdsa",
2525 ecdsa_c[testnum][1],
2526 test_curves_bits[testnum], ECDSA_SECONDS);
2528 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2531 mr ? "+R6:%ld:%d:%.2f\n"
2532 : "%ld %d bit ECDSA verify in %.2fs\n",
2533 count, test_curves_bits[testnum], d);
2534 ecdsa_results[testnum][1] = d / (double)count;
2537 if (rsa_count <= 1) {
2538 /* if longer than 10s, don't do any more */
2539 for (testnum++; testnum < EC_NUM; testnum++)
2540 ecdsa_doit[testnum] = 0;
2546 #ifndef OPENSSL_NO_EC
2547 if (RAND_status() != 1) {
2548 RAND_seed(rnd_seed, sizeof rnd_seed);
2550 for (testnum = 0; testnum < EC_NUM; testnum++) {
2551 if (!ecdh_doit[testnum])
2553 for (i = 0; i < loopargs_len; i++) {
2554 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2555 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2556 if (loopargs[i].ecdh_a[testnum] == NULL ||
2557 loopargs[i].ecdh_b[testnum] == NULL) {
2562 if (ecdh_checks == 0) {
2563 BIO_printf(bio_err, "ECDH failure.\n");
2564 ERR_print_errors(bio_err);
2567 for (i = 0; i < loopargs_len; i++) {
2568 /* generate two ECDH key pairs */
2569 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2570 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2571 BIO_printf(bio_err, "ECDH key generation failure.\n");
2572 ERR_print_errors(bio_err);
2577 * If field size is not more than 24 octets, then use SHA-1
2578 * hash of result; otherwise, use result (see section 4.8 of
2579 * draft-ietf-tls-ecc-03.txt).
2583 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2584 if (field_size <= 24 * 8) {
2585 outlen = KDF1_SHA1_len;
2588 outlen = (field_size + 7) / 8;
2592 ECDH_compute_key(loopargs[i].secret_a, outlen,
2593 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2594 loopargs[i].ecdh_a[testnum], kdf);
2596 ECDH_compute_key(loopargs[i].secret_b, outlen,
2597 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2598 loopargs[i].ecdh_b[testnum], kdf);
2599 if (secret_size_a != secret_size_b)
2604 for (secret_idx = 0; (secret_idx < secret_size_a)
2605 && (ecdh_checks == 1); secret_idx++) {
2606 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2610 if (ecdh_checks == 0) {
2611 BIO_printf(bio_err, "ECDH computations don't match.\n");
2612 ERR_print_errors(bio_err);
2618 if (ecdh_checks != 0) {
2619 pkey_print_message("", "ecdh",
2621 test_curves_bits[testnum], ECDH_SECONDS);
2623 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2626 mr ? "+R7:%ld:%d:%.2f\n" :
2627 "%ld %d-bit ECDH ops in %.2fs\n", count,
2628 test_curves_bits[testnum], d);
2629 ecdh_results[testnum][0] = d / (double)count;
2634 if (rsa_count <= 1) {
2635 /* if longer than 10s, don't do any more */
2636 for (testnum++; testnum < EC_NUM; testnum++)
2637 ecdh_doit[testnum] = 0;
2645 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2646 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2648 printf("%s ", BN_options());
2649 #ifndef OPENSSL_NO_MD2
2650 printf("%s ", MD2_options());
2652 #ifndef OPENSSL_NO_RC4
2653 printf("%s ", RC4_options());
2655 #ifndef OPENSSL_NO_DES
2656 printf("%s ", DES_options());
2658 printf("%s ", AES_options());
2659 #ifndef OPENSSL_NO_IDEA
2660 printf("%s ", IDEA_options());
2662 #ifndef OPENSSL_NO_BF
2663 printf("%s ", BF_options());
2665 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2673 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2676 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2677 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2681 for (k = 0; k < ALGOR_NUM; k++) {
2685 printf("+F:%d:%s", k, names[k]);
2687 printf("%-13s", names[k]);
2688 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2689 if (results[k][testnum] > 10000 && !mr)
2690 printf(" %11.2fk", results[k][testnum] / 1e3);
2692 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2696 #ifndef OPENSSL_NO_RSA
2698 for (k = 0; k < RSA_NUM; k++) {
2701 if (testnum && !mr) {
2702 printf("%18ssign verify sign/s verify/s\n", " ");
2706 printf("+F2:%u:%u:%f:%f\n",
2707 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2709 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2710 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2711 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2714 #ifndef OPENSSL_NO_DSA
2716 for (k = 0; k < DSA_NUM; k++) {
2719 if (testnum && !mr) {
2720 printf("%18ssign verify sign/s verify/s\n", " ");
2724 printf("+F3:%u:%u:%f:%f\n",
2725 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2727 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2728 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2729 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2732 #ifndef OPENSSL_NO_EC
2734 for (k = 0; k < EC_NUM; k++) {
2737 if (testnum && !mr) {
2738 printf("%30ssign verify sign/s verify/s\n", " ");
2743 printf("+F4:%u:%u:%f:%f\n",
2744 k, test_curves_bits[k],
2745 ecdsa_results[k][0], ecdsa_results[k][1]);
2747 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2748 test_curves_bits[k],
2749 test_curves_names[k],
2750 ecdsa_results[k][0], ecdsa_results[k][1],
2751 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2755 #ifndef OPENSSL_NO_EC
2757 for (k = 0; k < EC_NUM; k++) {
2760 if (testnum && !mr) {
2761 printf("%30sop op/s\n", " ");
2765 printf("+F5:%u:%u:%f:%f\n",
2766 k, test_curves_bits[k],
2767 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2770 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2771 test_curves_bits[k],
2772 test_curves_names[k],
2773 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2780 ERR_print_errors(bio_err);
2781 for (i = 0; i < loopargs_len; i++) {
2782 OPENSSL_free(loopargs[i].buf_malloc);
2783 OPENSSL_free(loopargs[i].buf2_malloc);
2784 OPENSSL_free(loopargs[i].siglen);
2786 #ifndef OPENSSL_NO_RSA
2787 for (i = 0; i < loopargs_len; i++) {
2788 for (k = 0; k < RSA_NUM; k++)
2789 RSA_free(loopargs[i].rsa_key[k]);
2792 #ifndef OPENSSL_NO_DSA
2793 for (i = 0; i < loopargs_len; i++) {
2794 for (k = 0; k < DSA_NUM; k++)
2795 DSA_free(loopargs[i].dsa_key[k]);
2799 #ifndef OPENSSL_NO_EC
2800 for (i = 0; i < loopargs_len; i++) {
2801 for (k = 0; k < EC_NUM; k++) {
2802 EC_KEY_free(loopargs[i].ecdsa[k]);
2803 EC_KEY_free(loopargs[i].ecdh_a[k]);
2804 EC_KEY_free(loopargs[i].ecdh_b[k]);
2806 OPENSSL_free(loopargs[i].secret_a);
2807 OPENSSL_free(loopargs[i].secret_b);
2810 if (async_jobs > 0) {
2811 for (i = 0; i < loopargs_len; i++)
2812 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2816 ASYNC_cleanup_thread();
2818 OPENSSL_free(loopargs);
2822 static void print_message(const char *s, long num, int length)
2826 mr ? "+DT:%s:%d:%d\n"
2827 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2828 (void)BIO_flush(bio_err);
2832 mr ? "+DN:%s:%ld:%d\n"
2833 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2834 (void)BIO_flush(bio_err);
2838 static void pkey_print_message(const char *str, const char *str2, long num,
2843 mr ? "+DTP:%d:%s:%s:%d\n"
2844 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2845 (void)BIO_flush(bio_err);
2849 mr ? "+DNP:%ld:%d:%s:%s\n"
2850 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2851 (void)BIO_flush(bio_err);
2855 static void print_result(int alg, int run_no, int count, double time_used)
2858 BIO_puts(bio_err, "EVP error!\n");
2862 mr ? "+R:%d:%s:%f\n"
2863 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2864 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2868 static char *sstrsep(char **string, const char *delim)
2871 char *token = *string;
2876 memset(isdelim, 0, sizeof isdelim);
2880 isdelim[(unsigned char)(*delim)] = 1;
2884 while (!isdelim[(unsigned char)(**string)]) {
2896 static int do_multi(int multi)
2901 static char sep[] = ":";
2903 fds = malloc(sizeof(*fds) * multi);
2904 for (n = 0; n < multi; ++n) {
2905 if (pipe(fd) == -1) {
2906 BIO_printf(bio_err, "pipe failure\n");
2910 (void)BIO_flush(bio_err);
2917 if (dup(fd[1]) == -1) {
2918 BIO_printf(bio_err, "dup failed\n");
2927 printf("Forked child %d\n", n);
2930 /* for now, assume the pipe is long enough to take all the output */
2931 for (n = 0; n < multi; ++n) {
2936 f = fdopen(fds[n], "r");
2937 while (fgets(buf, sizeof buf, f)) {
2938 p = strchr(buf, '\n');
2941 if (buf[0] != '+') {
2942 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2946 printf("Got: %s from %d\n", buf, n);
2947 if (strncmp(buf, "+F:", 3) == 0) {
2952 alg = atoi(sstrsep(&p, sep));
2954 for (j = 0; j < SIZE_NUM; ++j)
2955 results[alg][j] += atof(sstrsep(&p, sep));
2956 } else if (strncmp(buf, "+F2:", 4) == 0) {
2961 k = atoi(sstrsep(&p, sep));
2964 d = atof(sstrsep(&p, sep));
2966 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2968 rsa_results[k][0] = d;
2970 d = atof(sstrsep(&p, sep));
2972 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2974 rsa_results[k][1] = d;
2976 # ifndef OPENSSL_NO_DSA
2977 else if (strncmp(buf, "+F3:", 4) == 0) {
2982 k = atoi(sstrsep(&p, sep));
2985 d = atof(sstrsep(&p, sep));
2987 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2989 dsa_results[k][0] = d;
2991 d = atof(sstrsep(&p, sep));
2993 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2995 dsa_results[k][1] = d;
2998 # ifndef OPENSSL_NO_EC
2999 else if (strncmp(buf, "+F4:", 4) == 0) {
3004 k = atoi(sstrsep(&p, sep));
3007 d = atof(sstrsep(&p, sep));
3009 ecdsa_results[k][0] =
3010 1 / (1 / ecdsa_results[k][0] + 1 / d);
3012 ecdsa_results[k][0] = d;
3014 d = atof(sstrsep(&p, sep));
3016 ecdsa_results[k][1] =
3017 1 / (1 / ecdsa_results[k][1] + 1 / d);
3019 ecdsa_results[k][1] = d;
3023 # ifndef OPENSSL_NO_EC
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);