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];
610 for (count = 0; COND(c[D_MD2][testnum]); count++) {
611 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
619 #ifndef OPENSSL_NO_MDC2
620 static int EVP_Digest_MDC2_loop(void *args)
622 loopargs_t *tempargs = (loopargs_t *)args;
623 unsigned char *buf = tempargs->buf;
624 unsigned char mdc2[MDC2_DIGEST_LENGTH];
627 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
628 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
636 #ifndef OPENSSL_NO_MD4
637 static int EVP_Digest_MD4_loop(void *args)
639 loopargs_t *tempargs = (loopargs_t *)args;
640 unsigned char *buf = tempargs->buf;
641 unsigned char md4[MD4_DIGEST_LENGTH];
644 for (count = 0; COND(c[D_MD4][testnum]); count++) {
645 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
653 #ifndef OPENSSL_NO_MD5
654 static int MD5_loop(void *args)
656 loopargs_t *tempargs = (loopargs_t *)args;
657 unsigned char *buf = tempargs->buf;
658 unsigned char md5[MD5_DIGEST_LENGTH];
660 for (count = 0; COND(c[D_MD5][testnum]); count++)
661 MD5(buf, lengths[testnum], md5);
665 static int HMAC_loop(void *args)
667 loopargs_t *tempargs = (loopargs_t *)args;
668 unsigned char *buf = tempargs->buf;
669 HMAC_CTX *hctx = tempargs->hctx;
670 unsigned char hmac[MD5_DIGEST_LENGTH];
673 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
674 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
675 HMAC_Update(hctx, buf, lengths[testnum]);
676 HMAC_Final(hctx, hmac, NULL);
682 static int SHA1_loop(void *args)
684 loopargs_t *tempargs = (loopargs_t *)args;
685 unsigned char *buf = tempargs->buf;
686 unsigned char sha[SHA_DIGEST_LENGTH];
688 for (count = 0; COND(c[D_SHA1][testnum]); count++)
689 SHA1(buf, lengths[testnum], sha);
693 static int SHA256_loop(void *args)
695 loopargs_t *tempargs = (loopargs_t *)args;
696 unsigned char *buf = tempargs->buf;
697 unsigned char sha256[SHA256_DIGEST_LENGTH];
699 for (count = 0; COND(c[D_SHA256][testnum]); count++)
700 SHA256(buf, lengths[testnum], sha256);
704 static int SHA512_loop(void *args)
706 loopargs_t *tempargs = (loopargs_t *)args;
707 unsigned char *buf = tempargs->buf;
708 unsigned char sha512[SHA512_DIGEST_LENGTH];
710 for (count = 0; COND(c[D_SHA512][testnum]); count++)
711 SHA512(buf, lengths[testnum], sha512);
715 #ifndef OPENSSL_NO_WHIRLPOOL
716 static int WHIRLPOOL_loop(void *args)
718 loopargs_t *tempargs = (loopargs_t *)args;
719 unsigned char *buf = tempargs->buf;
720 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
722 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
723 WHIRLPOOL(buf, lengths[testnum], whirlpool);
728 #ifndef OPENSSL_NO_RMD160
729 static int EVP_Digest_RMD160_loop(void *args)
731 loopargs_t *tempargs = (loopargs_t *)args;
732 unsigned char *buf = tempargs->buf;
733 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
735 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
736 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
737 NULL, EVP_ripemd160(), NULL))
744 #ifndef OPENSSL_NO_RC4
745 static RC4_KEY rc4_ks;
746 static int RC4_loop(void *args)
748 loopargs_t *tempargs = (loopargs_t *)args;
749 unsigned char *buf = tempargs->buf;
751 for (count = 0; COND(c[D_RC4][testnum]); count++)
752 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
757 #ifndef OPENSSL_NO_DES
758 static unsigned char DES_iv[8];
759 static DES_key_schedule sch;
760 static DES_key_schedule sch2;
761 static DES_key_schedule sch3;
762 static int DES_ncbc_encrypt_loop(void *args)
764 loopargs_t *tempargs = (loopargs_t *)args;
765 unsigned char *buf = tempargs->buf;
767 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
768 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
769 &DES_iv, DES_ENCRYPT);
773 static int DES_ede3_cbc_encrypt_loop(void *args)
775 loopargs_t *tempargs = (loopargs_t *)args;
776 unsigned char *buf = tempargs->buf;
778 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
779 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
781 &DES_iv, DES_ENCRYPT);
786 #define MAX_BLOCK_SIZE 128
788 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
789 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
790 static int AES_cbc_128_encrypt_loop(void *args)
792 loopargs_t *tempargs = (loopargs_t *)args;
793 unsigned char *buf = tempargs->buf;
795 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
796 AES_cbc_encrypt(buf, buf,
797 (size_t)lengths[testnum], &aes_ks1,
802 static int AES_cbc_192_encrypt_loop(void *args)
804 loopargs_t *tempargs = (loopargs_t *)args;
805 unsigned char *buf = tempargs->buf;
807 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
808 AES_cbc_encrypt(buf, buf,
809 (size_t)lengths[testnum], &aes_ks2,
814 static int AES_cbc_256_encrypt_loop(void *args)
816 loopargs_t *tempargs = (loopargs_t *)args;
817 unsigned char *buf = tempargs->buf;
819 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
820 AES_cbc_encrypt(buf, buf,
821 (size_t)lengths[testnum], &aes_ks3,
826 static int AES_ige_128_encrypt_loop(void *args)
828 loopargs_t *tempargs = (loopargs_t *)args;
829 unsigned char *buf = tempargs->buf;
830 unsigned char *buf2 = tempargs->buf2;
832 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
833 AES_ige_encrypt(buf, buf2,
834 (size_t)lengths[testnum], &aes_ks1,
839 static int AES_ige_192_encrypt_loop(void *args)
841 loopargs_t *tempargs = (loopargs_t *)args;
842 unsigned char *buf = tempargs->buf;
843 unsigned char *buf2 = tempargs->buf2;
845 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
846 AES_ige_encrypt(buf, buf2,
847 (size_t)lengths[testnum], &aes_ks2,
852 static int AES_ige_256_encrypt_loop(void *args)
854 loopargs_t *tempargs = (loopargs_t *)args;
855 unsigned char *buf = tempargs->buf;
856 unsigned char *buf2 = tempargs->buf2;
858 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
859 AES_ige_encrypt(buf, buf2,
860 (size_t)lengths[testnum], &aes_ks3,
865 static int CRYPTO_gcm128_aad_loop(void *args)
867 loopargs_t *tempargs = (loopargs_t *)args;
868 unsigned char *buf = tempargs->buf;
869 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
871 for (count = 0; COND(c[D_GHASH][testnum]); count++)
872 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
876 static long save_count = 0;
877 static int decrypt = 0;
878 static int EVP_Update_loop(void *args)
880 loopargs_t *tempargs = (loopargs_t *)args;
881 unsigned char *buf = tempargs->buf;
882 EVP_CIPHER_CTX *ctx = tempargs->ctx;
885 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
888 for (count = 0; COND(nb_iter); count++)
889 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
891 for (count = 0; COND(nb_iter); count++)
892 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
894 EVP_DecryptFinal_ex(ctx, buf, &outl);
896 EVP_EncryptFinal_ex(ctx, buf, &outl);
900 static const EVP_MD *evp_md = NULL;
901 static int EVP_Digest_loop(void *args)
903 loopargs_t *tempargs = (loopargs_t *)args;
904 unsigned char *buf = tempargs->buf;
905 unsigned char md[EVP_MAX_MD_SIZE];
908 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
911 for (count = 0; COND(nb_iter); count++) {
912 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
918 #ifndef OPENSSL_NO_RSA
919 static long rsa_c[RSA_NUM][2];
921 static int RSA_sign_loop(void *args)
923 loopargs_t *tempargs = (loopargs_t *)args;
924 unsigned char *buf = tempargs->buf;
925 unsigned char *buf2 = tempargs->buf2;
926 unsigned int *rsa_num = tempargs->siglen;
927 RSA **rsa_key = tempargs->rsa_key;
929 for (count = 0; COND(rsa_c[testnum][0]); count++) {
930 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
932 BIO_printf(bio_err, "RSA sign failure\n");
933 ERR_print_errors(bio_err);
941 static int RSA_verify_loop(void *args)
943 loopargs_t *tempargs = (loopargs_t *)args;
944 unsigned char *buf = tempargs->buf;
945 unsigned char *buf2 = tempargs->buf2;
946 unsigned int rsa_num = *(tempargs->siglen);
947 RSA **rsa_key = tempargs->rsa_key;
949 for (count = 0; COND(rsa_c[testnum][1]); count++) {
950 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
952 BIO_printf(bio_err, "RSA verify failure\n");
953 ERR_print_errors(bio_err);
962 #ifndef OPENSSL_NO_DSA
963 static long dsa_c[DSA_NUM][2];
964 static int DSA_sign_loop(void *args)
966 loopargs_t *tempargs = (loopargs_t *)args;
967 unsigned char *buf = tempargs->buf;
968 unsigned char *buf2 = tempargs->buf2;
969 DSA **dsa_key = tempargs->dsa_key;
970 unsigned int *siglen = tempargs->siglen;
972 for (count = 0; COND(dsa_c[testnum][0]); count++) {
973 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
975 BIO_printf(bio_err, "DSA sign failure\n");
976 ERR_print_errors(bio_err);
984 static int DSA_verify_loop(void *args)
986 loopargs_t *tempargs = (loopargs_t *)args;
987 unsigned char *buf = tempargs->buf;
988 unsigned char *buf2 = tempargs->buf2;
989 DSA **dsa_key = tempargs->dsa_key;
990 unsigned int siglen = *(tempargs->siglen);
992 for (count = 0; COND(dsa_c[testnum][1]); count++) {
993 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
995 BIO_printf(bio_err, "DSA verify failure\n");
996 ERR_print_errors(bio_err);
1005 #ifndef OPENSSL_NO_EC
1006 static long ecdsa_c[EC_NUM][2];
1007 static int ECDSA_sign_loop(void *args)
1009 loopargs_t *tempargs = (loopargs_t *)args;
1010 unsigned char *buf = tempargs->buf;
1011 EC_KEY **ecdsa = tempargs->ecdsa;
1012 unsigned char *ecdsasig = tempargs->buf2;
1013 unsigned int *ecdsasiglen = tempargs->siglen;
1015 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1016 ret = ECDSA_sign(0, buf, 20,
1017 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1019 BIO_printf(bio_err, "ECDSA sign failure\n");
1020 ERR_print_errors(bio_err);
1028 static int ECDSA_verify_loop(void *args)
1030 loopargs_t *tempargs = (loopargs_t *)args;
1031 unsigned char *buf = tempargs->buf;
1032 EC_KEY **ecdsa = tempargs->ecdsa;
1033 unsigned char *ecdsasig = tempargs->buf2;
1034 unsigned int ecdsasiglen = *(tempargs->siglen);
1036 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1037 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1040 BIO_printf(bio_err, "ECDSA verify failure\n");
1041 ERR_print_errors(bio_err);
1049 /* ******************************************************************** */
1050 static long ecdh_c[EC_NUM][1];
1052 static int ECDH_compute_key_loop(void *args)
1054 loopargs_t *tempargs = (loopargs_t *)args;
1055 EC_KEY **ecdh_a = tempargs->ecdh_a;
1056 EC_KEY **ecdh_b = tempargs->ecdh_b;
1057 unsigned char *secret_a = tempargs->secret_a;
1058 int count, outlen = tempargs->outlen;
1059 kdf_fn kdf = tempargs->kdf;
1061 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1062 ECDH_compute_key(secret_a, outlen,
1063 EC_KEY_get0_public_key(ecdh_b[testnum]),
1064 ecdh_a[testnum], kdf);
1068 #endif /* ndef OPENSSL_NO_EC */
1071 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1073 int job_op_count = 0;
1074 int total_op_count = 0;
1075 int num_inprogress = 0;
1078 OSSL_ASYNC_FD job_fd = 0;
1079 size_t num_job_fds = 0;
1083 if (async_jobs == 0) {
1084 return loop_function((void *)loopargs);
1088 for (i = 0; i < async_jobs && !error; i++) {
1089 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1090 &job_op_count, loop_function,
1091 (void *)(loopargs + i), sizeof(loopargs_t))) {
1096 if (job_op_count == -1) {
1099 total_op_count += job_op_count;
1104 BIO_printf(bio_err, "Failure in the job\n");
1105 ERR_print_errors(bio_err);
1111 while (num_inprogress > 0) {
1112 #if defined(OPENSSL_SYS_WINDOWS)
1114 #elif defined(OPENSSL_SYS_UNIX)
1115 int select_result = 0;
1116 OSSL_ASYNC_FD max_fd = 0;
1119 FD_ZERO(&waitfdset);
1121 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1122 if (loopargs[i].inprogress_job == NULL)
1125 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1126 || num_job_fds > 1) {
1127 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1128 ERR_print_errors(bio_err);
1132 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1133 FD_SET(job_fd, &waitfdset);
1134 if (job_fd > max_fd)
1138 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1140 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1141 "Decrease the value of async_jobs\n",
1142 max_fd, FD_SETSIZE);
1143 ERR_print_errors(bio_err);
1148 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1149 if (select_result == -1 && errno == EINTR)
1152 if (select_result == -1) {
1153 BIO_printf(bio_err, "Failure in the select\n");
1154 ERR_print_errors(bio_err);
1159 if (select_result == 0)
1163 for (i = 0; i < async_jobs; i++) {
1164 if (loopargs[i].inprogress_job == NULL)
1167 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1168 || num_job_fds > 1) {
1169 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1170 ERR_print_errors(bio_err);
1174 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1176 #if defined(OPENSSL_SYS_UNIX)
1177 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1179 #elif defined(OPENSSL_SYS_WINDOWS)
1180 if (num_job_fds == 1 &&
1181 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
1185 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1186 &job_op_count, loop_function, (void *)(loopargs + i),
1187 sizeof(loopargs_t))) {
1191 if (job_op_count == -1) {
1194 total_op_count += job_op_count;
1197 loopargs[i].inprogress_job = NULL;
1202 loopargs[i].inprogress_job = NULL;
1203 BIO_printf(bio_err, "Failure in the job\n");
1204 ERR_print_errors(bio_err);
1211 return error ? -1 : total_op_count;
1214 int speed_main(int argc, char **argv)
1216 loopargs_t *loopargs = NULL;
1218 int loopargs_len = 0;
1220 #ifndef OPENSSL_NO_ENGINE
1221 const char *engine_id = NULL;
1223 const EVP_CIPHER *evp_cipher = NULL;
1226 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
1227 #ifndef OPENSSL_NO_DSA
1228 int dsa_doit[DSA_NUM];
1230 int rsa_doit[RSA_NUM];
1231 int ret = 1, i, k, misalign = 0;
1237 /* What follows are the buffers and key material. */
1238 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
1241 #ifndef OPENSSL_NO_RC5
1244 #ifndef OPENSSL_NO_RC2
1247 #ifndef OPENSSL_NO_IDEA
1248 IDEA_KEY_SCHEDULE idea_ks;
1250 #ifndef OPENSSL_NO_SEED
1251 SEED_KEY_SCHEDULE seed_ks;
1253 #ifndef OPENSSL_NO_BF
1256 #ifndef OPENSSL_NO_CAST
1259 static const unsigned char key16[16] = {
1260 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1261 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1263 static const unsigned char key24[24] = {
1264 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1265 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1266 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1268 static const unsigned char key32[32] = {
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,
1272 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1274 #ifndef OPENSSL_NO_CAMELLIA
1275 static const unsigned char ckey24[24] = {
1276 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1277 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1278 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1280 static const unsigned char ckey32[32] = {
1281 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1282 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1283 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1284 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1286 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1288 #ifndef OPENSSL_NO_DES
1289 static DES_cblock key = {
1290 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1292 static DES_cblock key2 = {
1293 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1295 static DES_cblock key3 = {
1296 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1299 #ifndef OPENSSL_NO_RSA
1300 static unsigned int rsa_bits[RSA_NUM] = {
1301 512, 1024, 2048, 3072, 4096, 7680, 15360
1303 static unsigned char *rsa_data[RSA_NUM] = {
1304 test512, test1024, test2048, test3072, test4096, test7680, test15360
1306 static int rsa_data_length[RSA_NUM] = {
1307 sizeof(test512), sizeof(test1024),
1308 sizeof(test2048), sizeof(test3072),
1309 sizeof(test4096), sizeof(test7680),
1313 #ifndef OPENSSL_NO_DSA
1314 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1316 #ifndef OPENSSL_NO_EC
1318 * We only test over the following curves as they are representative, To
1319 * add tests over more curves, simply add the curve NID and curve name to
1320 * the following arrays and increase the EC_NUM value accordingly.
1322 static unsigned int test_curves[EC_NUM] = {
1324 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1325 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1327 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1328 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1329 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1334 static const char *test_curves_names[EC_NUM] = {
1336 "secp160r1", "nistp192", "nistp224",
1337 "nistp256", "nistp384", "nistp521",
1339 "nistk163", "nistk233", "nistk283",
1340 "nistk409", "nistk571", "nistb163",
1341 "nistb233", "nistb283", "nistb409",
1346 static int test_curves_bits[EC_NUM] = {
1352 571, 253 /* X25519 */
1355 #ifndef OPENSSL_NO_EC
1356 int ecdsa_doit[EC_NUM];
1357 int secret_size_a, secret_size_b;
1358 int ecdh_checks = 1;
1360 int ecdh_doit[EC_NUM];
1363 memset(results, 0, sizeof(results));
1365 #ifndef OPENSSL_NO_DES
1366 memset(DES_iv, 0, sizeof(DES_iv));
1368 memset(iv, 0, sizeof(iv));
1370 for (i = 0; i < ALGOR_NUM; i++)
1372 for (i = 0; i < RSA_NUM; i++)
1374 #ifndef OPENSSL_NO_DSA
1375 for (i = 0; i < DSA_NUM; i++)
1378 #ifndef OPENSSL_NO_EC
1379 for (i = 0; i < EC_NUM; i++)
1381 for (i = 0; i < EC_NUM; i++)
1387 prog = opt_init(argc, argv, speed_options);
1388 while ((o = opt_next()) != OPT_EOF) {
1393 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1396 opt_help(speed_options);
1403 evp_cipher = EVP_get_cipherbyname(opt_arg());
1404 if (evp_cipher == NULL)
1405 evp_md = EVP_get_digestbyname(opt_arg());
1406 if (evp_cipher == NULL && evp_md == NULL) {
1408 "%s: %s an unknown cipher or digest\n",
1419 * In a forked execution, an engine might need to be
1420 * initialised by each child process, not by the parent.
1421 * So store the name here and run setup_engine() later on.
1423 #ifndef OPENSSL_NO_ENGINE
1424 engine_id = opt_arg();
1429 multi = atoi(opt_arg());
1433 #ifndef OPENSSL_NO_ASYNC
1434 async_jobs = atoi(opt_arg());
1435 if (!ASYNC_is_capable()) {
1437 "%s: async_jobs specified but async not supported\n",
1444 if (!opt_int(opt_arg(), &misalign))
1446 if (misalign > MISALIGN) {
1448 "%s: Maximum offset is %d\n", prog, MISALIGN);
1460 argc = opt_num_rest();
1463 /* Remaining arguments are algorithms. */
1464 for ( ; *argv; argv++) {
1465 if (found(*argv, doit_choices, &i)) {
1469 #ifndef OPENSSL_NO_DES
1470 if (strcmp(*argv, "des") == 0) {
1471 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1475 if (strcmp(*argv, "sha") == 0) {
1476 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1479 #ifndef OPENSSL_NO_RSA
1481 if (strcmp(*argv, "openssl") == 0) {
1482 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1486 if (strcmp(*argv, "rsa") == 0) {
1487 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1488 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1489 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1490 rsa_doit[R_RSA_15360] = 1;
1493 if (found(*argv, rsa_choices, &i)) {
1498 #ifndef OPENSSL_NO_DSA
1499 if (strcmp(*argv, "dsa") == 0) {
1500 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1501 dsa_doit[R_DSA_2048] = 1;
1504 if (found(*argv, dsa_choices, &i)) {
1509 if (strcmp(*argv, "aes") == 0) {
1510 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1511 doit[D_CBC_256_AES] = 1;
1514 #ifndef OPENSSL_NO_CAMELLIA
1515 if (strcmp(*argv, "camellia") == 0) {
1516 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1517 doit[D_CBC_256_CML] = 1;
1521 #ifndef OPENSSL_NO_EC
1522 if (strcmp(*argv, "ecdsa") == 0) {
1523 for (i = 0; i < EC_NUM; i++)
1527 if (found(*argv, ecdsa_choices, &i)) {
1531 if (strcmp(*argv, "ecdh") == 0) {
1532 for (i = 0; i < EC_NUM; i++)
1536 if (found(*argv, ecdh_choices, &i)) {
1541 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1545 /* Initialize the job pool if async mode is enabled */
1546 if (async_jobs > 0) {
1547 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1549 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1554 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1555 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1556 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1558 for (i = 0; i < loopargs_len; i++) {
1559 if (async_jobs > 0) {
1560 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1561 if (loopargs[i].wait_ctx == NULL) {
1562 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1567 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1568 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1569 /* Align the start of buffers on a 64 byte boundary */
1570 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1571 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1572 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1573 #ifndef OPENSSL_NO_EC
1574 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1575 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1580 if (multi && do_multi(multi))
1584 /* Initialize the engine after the fork */
1585 (void)setup_engine(engine_id, 0);
1587 /* No parameters; turn on everything. */
1588 if ((argc == 0) && !doit[D_EVP]) {
1589 for (i = 0; i < ALGOR_NUM; i++)
1592 for (i = 0; i < RSA_NUM; i++)
1594 #ifndef OPENSSL_NO_DSA
1595 for (i = 0; i < DSA_NUM; i++)
1598 #ifndef OPENSSL_NO_EC
1599 for (i = 0; i < EC_NUM; i++)
1601 for (i = 0; i < EC_NUM; i++)
1605 for (i = 0; i < ALGOR_NUM; i++)
1609 if (usertime == 0 && !mr)
1611 "You have chosen to measure elapsed time "
1612 "instead of user CPU time.\n");
1614 #ifndef OPENSSL_NO_RSA
1615 for (i = 0; i < loopargs_len; i++) {
1616 for (k = 0; k < RSA_NUM; k++) {
1617 const unsigned char *p;
1620 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1621 if (loopargs[i].rsa_key[k] == NULL) {
1622 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1629 #ifndef OPENSSL_NO_DSA
1630 for (i = 0; i < loopargs_len; i++) {
1631 loopargs[i].dsa_key[0] = get_dsa512();
1632 loopargs[i].dsa_key[1] = get_dsa1024();
1633 loopargs[i].dsa_key[2] = get_dsa2048();
1636 #ifndef OPENSSL_NO_DES
1637 DES_set_key_unchecked(&key, &sch);
1638 DES_set_key_unchecked(&key2, &sch2);
1639 DES_set_key_unchecked(&key3, &sch3);
1641 AES_set_encrypt_key(key16, 128, &aes_ks1);
1642 AES_set_encrypt_key(key24, 192, &aes_ks2);
1643 AES_set_encrypt_key(key32, 256, &aes_ks3);
1644 #ifndef OPENSSL_NO_CAMELLIA
1645 Camellia_set_key(key16, 128, &camellia_ks1);
1646 Camellia_set_key(ckey24, 192, &camellia_ks2);
1647 Camellia_set_key(ckey32, 256, &camellia_ks3);
1649 #ifndef OPENSSL_NO_IDEA
1650 IDEA_set_encrypt_key(key16, &idea_ks);
1652 #ifndef OPENSSL_NO_SEED
1653 SEED_set_key(key16, &seed_ks);
1655 #ifndef OPENSSL_NO_RC4
1656 RC4_set_key(&rc4_ks, 16, key16);
1658 #ifndef OPENSSL_NO_RC2
1659 RC2_set_key(&rc2_ks, 16, key16, 128);
1661 #ifndef OPENSSL_NO_RC5
1662 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1664 #ifndef OPENSSL_NO_BF
1665 BF_set_key(&bf_ks, 16, key16);
1667 #ifndef OPENSSL_NO_CAST
1668 CAST_set_key(&cast_ks, 16, key16);
1670 #ifndef OPENSSL_NO_RSA
1671 memset(rsa_c, 0, sizeof(rsa_c));
1674 # ifndef OPENSSL_NO_DES
1675 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1681 for (it = count; it; it--)
1682 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1683 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1687 c[D_MD2][0] = count / 10;
1688 c[D_MDC2][0] = count / 10;
1689 c[D_MD4][0] = count;
1690 c[D_MD5][0] = count;
1691 c[D_HMAC][0] = count;
1692 c[D_SHA1][0] = count;
1693 c[D_RMD160][0] = count;
1694 c[D_RC4][0] = count * 5;
1695 c[D_CBC_DES][0] = count;
1696 c[D_EDE3_DES][0] = count / 3;
1697 c[D_CBC_IDEA][0] = count;
1698 c[D_CBC_SEED][0] = count;
1699 c[D_CBC_RC2][0] = count;
1700 c[D_CBC_RC5][0] = count;
1701 c[D_CBC_BF][0] = count;
1702 c[D_CBC_CAST][0] = count;
1703 c[D_CBC_128_AES][0] = count;
1704 c[D_CBC_192_AES][0] = count;
1705 c[D_CBC_256_AES][0] = count;
1706 c[D_CBC_128_CML][0] = count;
1707 c[D_CBC_192_CML][0] = count;
1708 c[D_CBC_256_CML][0] = count;
1709 c[D_SHA256][0] = count;
1710 c[D_SHA512][0] = count;
1711 c[D_WHIRLPOOL][0] = count;
1712 c[D_IGE_128_AES][0] = count;
1713 c[D_IGE_192_AES][0] = count;
1714 c[D_IGE_256_AES][0] = count;
1715 c[D_GHASH][0] = count;
1717 for (i = 1; i < SIZE_NUM; i++) {
1720 l0 = (long)lengths[0];
1721 l1 = (long)lengths[i];
1723 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1724 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1725 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1726 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1727 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1728 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1729 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1730 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1731 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1732 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1733 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1735 l0 = (long)lengths[i - 1];
1737 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1738 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1739 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1740 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1741 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1742 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1743 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1744 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1745 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1746 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1747 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1748 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1749 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1750 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1751 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1752 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1753 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1754 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1757 # ifndef OPENSSL_NO_RSA
1758 rsa_c[R_RSA_512][0] = count / 2000;
1759 rsa_c[R_RSA_512][1] = count / 400;
1760 for (i = 1; i < RSA_NUM; i++) {
1761 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1762 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1763 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1766 if (rsa_c[i][0] == 0) {
1774 # ifndef OPENSSL_NO_DSA
1775 dsa_c[R_DSA_512][0] = count / 1000;
1776 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1777 for (i = 1; i < DSA_NUM; i++) {
1778 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1779 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1780 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1783 if (dsa_c[i] == 0) { /* Always false */
1791 # ifndef OPENSSL_NO_EC
1792 ecdsa_c[R_EC_P160][0] = count / 1000;
1793 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1794 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1795 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1796 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1797 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1800 if (ecdsa_c[i] == 0) { /* Always false */
1806 ecdsa_c[R_EC_K163][0] = count / 1000;
1807 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1808 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1809 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1810 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1811 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1814 if (ecdsa_c[i] == 0) { /* Always false */
1820 ecdsa_c[R_EC_B163][0] = count / 1000;
1821 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1822 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1823 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1824 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1825 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1828 if (ecdsa_c[i] == 0) { /* Always false */
1835 ecdh_c[R_EC_P160][0] = count / 1000;
1836 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1837 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1838 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1841 if (ecdh_c[i] == 0) { /* always false */
1846 ecdh_c[R_EC_K163][0] = count / 1000;
1847 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1848 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1849 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1852 if (ecdh_c[i] == 0) { /* always false */
1857 ecdh_c[R_EC_B163][0] = count / 1000;
1858 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1859 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1860 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1863 if (ecdh_c[i] == 0) { /* always false */
1871 /* not worth fixing */
1872 # error "You cannot disable DES on systems without SIGALRM."
1873 # endif /* OPENSSL_NO_DES */
1876 signal(SIGALRM, sig_done);
1878 #endif /* SIGALRM */
1880 #ifndef OPENSSL_NO_MD2
1882 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1883 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1885 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1887 print_result(D_MD2, testnum, count, d);
1891 #ifndef OPENSSL_NO_MDC2
1893 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1894 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1896 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1898 print_result(D_MDC2, testnum, count, d);
1903 #ifndef OPENSSL_NO_MD4
1905 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1906 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1908 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1910 print_result(D_MD4, testnum, count, d);
1915 #ifndef OPENSSL_NO_MD5
1917 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1918 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1920 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1922 print_result(D_MD5, testnum, count, d);
1927 #ifndef OPENSSL_NO_MD5
1929 char hmac_key[] = "This is a key...";
1930 int len = strlen(hmac_key);
1932 for (i = 0; i < loopargs_len; i++) {
1933 loopargs[i].hctx = HMAC_CTX_new();
1934 if (loopargs[i].hctx == NULL) {
1935 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1939 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1941 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1942 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1944 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1946 print_result(D_HMAC, testnum, count, d);
1948 for (i = 0; i < loopargs_len; i++) {
1949 HMAC_CTX_free(loopargs[i].hctx);
1954 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1955 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1957 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1959 print_result(D_SHA1, testnum, count, d);
1962 if (doit[D_SHA256]) {
1963 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1964 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1966 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1968 print_result(D_SHA256, testnum, count, d);
1971 if (doit[D_SHA512]) {
1972 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1973 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1975 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1977 print_result(D_SHA512, testnum, count, d);
1981 #ifndef OPENSSL_NO_WHIRLPOOL
1982 if (doit[D_WHIRLPOOL]) {
1983 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1984 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1986 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1988 print_result(D_WHIRLPOOL, testnum, count, d);
1993 #ifndef OPENSSL_NO_RMD160
1994 if (doit[D_RMD160]) {
1995 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1996 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1998 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2000 print_result(D_RMD160, testnum, count, d);
2004 #ifndef OPENSSL_NO_RC4
2006 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2007 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2009 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2011 print_result(D_RC4, testnum, count, d);
2015 #ifndef OPENSSL_NO_DES
2016 if (doit[D_CBC_DES]) {
2017 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2018 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2020 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2022 print_result(D_CBC_DES, testnum, count, d);
2026 if (doit[D_EDE3_DES]) {
2027 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2028 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2030 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2032 print_result(D_EDE3_DES, testnum, count, d);
2037 if (doit[D_CBC_128_AES]) {
2038 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2039 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2042 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2044 print_result(D_CBC_128_AES, testnum, count, d);
2047 if (doit[D_CBC_192_AES]) {
2048 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2049 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2052 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2054 print_result(D_CBC_192_AES, testnum, count, d);
2057 if (doit[D_CBC_256_AES]) {
2058 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2059 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2062 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2064 print_result(D_CBC_256_AES, testnum, count, d);
2068 if (doit[D_IGE_128_AES]) {
2069 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2070 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2073 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2075 print_result(D_IGE_128_AES, testnum, count, d);
2078 if (doit[D_IGE_192_AES]) {
2079 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2080 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2083 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2085 print_result(D_IGE_192_AES, testnum, count, d);
2088 if (doit[D_IGE_256_AES]) {
2089 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2090 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2093 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2095 print_result(D_IGE_256_AES, testnum, count, d);
2098 if (doit[D_GHASH]) {
2099 for (i = 0; i < loopargs_len; i++) {
2100 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2101 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2104 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2105 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2107 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2109 print_result(D_GHASH, testnum, count, d);
2111 for (i = 0; i < loopargs_len; i++)
2112 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2115 #ifndef OPENSSL_NO_CAMELLIA
2116 if (doit[D_CBC_128_CML]) {
2117 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2118 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2120 if (async_jobs > 0) {
2121 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2125 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2126 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2127 (size_t)lengths[testnum], &camellia_ks1,
2128 iv, CAMELLIA_ENCRYPT);
2130 print_result(D_CBC_128_CML, testnum, count, d);
2133 if (doit[D_CBC_192_CML]) {
2134 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2135 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2137 if (async_jobs > 0) {
2138 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2142 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2143 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2144 (size_t)lengths[testnum], &camellia_ks2,
2145 iv, CAMELLIA_ENCRYPT);
2147 print_result(D_CBC_192_CML, testnum, count, d);
2150 if (doit[D_CBC_256_CML]) {
2151 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2152 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2154 if (async_jobs > 0) {
2155 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2159 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2160 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2161 (size_t)lengths[testnum], &camellia_ks3,
2162 iv, CAMELLIA_ENCRYPT);
2164 print_result(D_CBC_256_CML, testnum, count, d);
2168 #ifndef OPENSSL_NO_IDEA
2169 if (doit[D_CBC_IDEA]) {
2170 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2171 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2172 if (async_jobs > 0) {
2173 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2177 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2178 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2179 (size_t)lengths[testnum], &idea_ks,
2182 print_result(D_CBC_IDEA, testnum, count, d);
2186 #ifndef OPENSSL_NO_SEED
2187 if (doit[D_CBC_SEED]) {
2188 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2189 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2190 if (async_jobs > 0) {
2191 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2195 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2196 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2197 (size_t)lengths[testnum], &seed_ks, iv, 1);
2199 print_result(D_CBC_SEED, testnum, count, d);
2203 #ifndef OPENSSL_NO_RC2
2204 if (doit[D_CBC_RC2]) {
2205 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2206 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2207 if (async_jobs > 0) {
2208 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2212 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2213 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2214 (size_t)lengths[testnum], &rc2_ks,
2217 print_result(D_CBC_RC2, testnum, count, d);
2221 #ifndef OPENSSL_NO_RC5
2222 if (doit[D_CBC_RC5]) {
2223 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2224 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2225 if (async_jobs > 0) {
2226 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2230 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2231 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2232 (size_t)lengths[testnum], &rc5_ks,
2235 print_result(D_CBC_RC5, testnum, count, d);
2239 #ifndef OPENSSL_NO_BF
2240 if (doit[D_CBC_BF]) {
2241 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2242 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2243 if (async_jobs > 0) {
2244 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2248 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2249 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2250 (size_t)lengths[testnum], &bf_ks,
2253 print_result(D_CBC_BF, testnum, count, d);
2257 #ifndef OPENSSL_NO_CAST
2258 if (doit[D_CBC_CAST]) {
2259 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2260 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2261 if (async_jobs > 0) {
2262 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2266 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2267 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2268 (size_t)lengths[testnum], &cast_ks,
2271 print_result(D_CBC_CAST, testnum, count, d);
2277 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2278 if (multiblock && evp_cipher) {
2280 (EVP_CIPHER_flags(evp_cipher) &
2281 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2282 BIO_printf(bio_err, "%s is not multi-block capable\n",
2283 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2286 if (async_jobs > 0) {
2287 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2290 multiblock_speed(evp_cipher);
2295 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2298 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2300 * -O3 -fschedule-insns messes up an optimization here!
2301 * names[D_EVP] somehow becomes NULL
2303 print_message(names[D_EVP], save_count, lengths[testnum]);
2305 for (k = 0; k < loopargs_len; k++) {
2306 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2308 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2310 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2311 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2315 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2317 for (k = 0; k < loopargs_len; k++) {
2318 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2322 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2323 print_message(names[D_EVP], save_count, lengths[testnum]);
2325 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2328 print_result(D_EVP, testnum, count, d);
2332 for (i = 0; i < loopargs_len; i++)
2333 RAND_bytes(loopargs[i].buf, 36);
2335 #ifndef OPENSSL_NO_RSA
2336 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2338 if (!rsa_doit[testnum])
2340 for (i = 0; i < loopargs_len; i++) {
2341 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2342 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2348 "RSA sign failure. No RSA sign will be done.\n");
2349 ERR_print_errors(bio_err);
2352 pkey_print_message("private", "rsa",
2353 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2354 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2356 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2359 mr ? "+R1:%ld:%d:%.2f\n"
2360 : "%ld %d bit private RSA's in %.2fs\n",
2361 count, rsa_bits[testnum], d);
2362 rsa_results[testnum][0] = d / (double)count;
2366 for (i = 0; i < loopargs_len; i++) {
2367 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2368 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2374 "RSA verify failure. No RSA verify will be done.\n");
2375 ERR_print_errors(bio_err);
2376 rsa_doit[testnum] = 0;
2378 pkey_print_message("public", "rsa",
2379 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2381 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2384 mr ? "+R2:%ld:%d:%.2f\n"
2385 : "%ld %d bit public RSA's in %.2fs\n",
2386 count, rsa_bits[testnum], d);
2387 rsa_results[testnum][1] = d / (double)count;
2390 if (rsa_count <= 1) {
2391 /* if longer than 10s, don't do any more */
2392 for (testnum++; testnum < RSA_NUM; testnum++)
2393 rsa_doit[testnum] = 0;
2398 for (i = 0; i < loopargs_len; i++)
2399 RAND_bytes(loopargs[i].buf, 36);
2401 #ifndef OPENSSL_NO_DSA
2402 if (RAND_status() != 1) {
2403 RAND_seed(rnd_seed, sizeof rnd_seed);
2405 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2407 if (!dsa_doit[testnum])
2410 /* DSA_generate_key(dsa_key[testnum]); */
2411 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2412 for (i = 0; i < loopargs_len; i++) {
2413 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2414 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2420 "DSA sign failure. No DSA sign will be done.\n");
2421 ERR_print_errors(bio_err);
2424 pkey_print_message("sign", "dsa",
2425 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2427 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2430 mr ? "+R3:%ld:%d:%.2f\n"
2431 : "%ld %d bit DSA signs in %.2fs\n",
2432 count, dsa_bits[testnum], d);
2433 dsa_results[testnum][0] = d / (double)count;
2437 for (i = 0; i < loopargs_len; i++) {
2438 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2439 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2445 "DSA verify failure. No DSA verify will be done.\n");
2446 ERR_print_errors(bio_err);
2447 dsa_doit[testnum] = 0;
2449 pkey_print_message("verify", "dsa",
2450 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2452 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2455 mr ? "+R4:%ld:%d:%.2f\n"
2456 : "%ld %d bit DSA verify in %.2fs\n",
2457 count, dsa_bits[testnum], d);
2458 dsa_results[testnum][1] = d / (double)count;
2461 if (rsa_count <= 1) {
2462 /* if longer than 10s, don't do any more */
2463 for (testnum++; testnum < DSA_NUM; testnum++)
2464 dsa_doit[testnum] = 0;
2469 #ifndef OPENSSL_NO_EC
2470 if (RAND_status() != 1) {
2471 RAND_seed(rnd_seed, sizeof rnd_seed);
2473 for (testnum = 0; testnum < EC_NUM; testnum++) {
2476 if (!ecdsa_doit[testnum])
2477 continue; /* Ignore Curve */
2478 for (i = 0; i < loopargs_len; i++) {
2479 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2480 if (loopargs[i].ecdsa[testnum] == NULL) {
2486 BIO_printf(bio_err, "ECDSA failure.\n");
2487 ERR_print_errors(bio_err);
2490 for (i = 0; i < loopargs_len; i++) {
2491 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2492 /* Perform ECDSA signature test */
2493 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2494 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2495 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2501 "ECDSA sign failure. No ECDSA sign will be done.\n");
2502 ERR_print_errors(bio_err);
2505 pkey_print_message("sign", "ecdsa",
2506 ecdsa_c[testnum][0],
2507 test_curves_bits[testnum], ECDSA_SECONDS);
2509 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2513 mr ? "+R5:%ld:%d:%.2f\n" :
2514 "%ld %d bit ECDSA signs in %.2fs \n",
2515 count, test_curves_bits[testnum], d);
2516 ecdsa_results[testnum][0] = d / (double)count;
2520 /* Perform ECDSA verification test */
2521 for (i = 0; i < loopargs_len; i++) {
2522 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2523 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2529 "ECDSA verify failure. No ECDSA verify will be done.\n");
2530 ERR_print_errors(bio_err);
2531 ecdsa_doit[testnum] = 0;
2533 pkey_print_message("verify", "ecdsa",
2534 ecdsa_c[testnum][1],
2535 test_curves_bits[testnum], ECDSA_SECONDS);
2537 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2540 mr ? "+R6:%ld:%d:%.2f\n"
2541 : "%ld %d bit ECDSA verify in %.2fs\n",
2542 count, test_curves_bits[testnum], d);
2543 ecdsa_results[testnum][1] = d / (double)count;
2546 if (rsa_count <= 1) {
2547 /* if longer than 10s, don't do any more */
2548 for (testnum++; testnum < EC_NUM; testnum++)
2549 ecdsa_doit[testnum] = 0;
2555 #ifndef OPENSSL_NO_EC
2556 if (RAND_status() != 1) {
2557 RAND_seed(rnd_seed, sizeof rnd_seed);
2559 for (testnum = 0; testnum < EC_NUM; testnum++) {
2560 if (!ecdh_doit[testnum])
2562 for (i = 0; i < loopargs_len; i++) {
2563 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2564 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2565 if (loopargs[i].ecdh_a[testnum] == NULL ||
2566 loopargs[i].ecdh_b[testnum] == NULL) {
2571 if (ecdh_checks == 0) {
2572 BIO_printf(bio_err, "ECDH failure.\n");
2573 ERR_print_errors(bio_err);
2576 for (i = 0; i < loopargs_len; i++) {
2577 /* generate two ECDH key pairs */
2578 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2579 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2580 BIO_printf(bio_err, "ECDH key generation failure.\n");
2581 ERR_print_errors(bio_err);
2586 * If field size is not more than 24 octets, then use SHA-1
2587 * hash of result; otherwise, use result (see section 4.8 of
2588 * draft-ietf-tls-ecc-03.txt).
2590 int field_size = EC_GROUP_get_degree(
2591 EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2593 if (field_size <= 24 * 8) { /* 192 bits */
2594 loopargs[i].outlen = KDF1_SHA1_len;
2595 loopargs[i].kdf = KDF1_SHA1;
2597 loopargs[i].outlen = (field_size + 7) / 8;
2598 loopargs[i].kdf = NULL;
2601 ECDH_compute_key(loopargs[i].secret_a, loopargs[i].outlen,
2602 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2603 loopargs[i].ecdh_a[testnum], loopargs[i].kdf);
2605 ECDH_compute_key(loopargs[i].secret_b, loopargs[i].outlen,
2606 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2607 loopargs[i].ecdh_b[testnum], loopargs[i].kdf);
2608 if (secret_size_a != secret_size_b)
2613 for (secret_idx = 0; (secret_idx < secret_size_a)
2614 && (ecdh_checks == 1); secret_idx++) {
2615 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2619 if (ecdh_checks == 0) {
2620 BIO_printf(bio_err, "ECDH computations don't match.\n");
2621 ERR_print_errors(bio_err);
2627 if (ecdh_checks != 0) {
2628 pkey_print_message("", "ecdh",
2630 test_curves_bits[testnum], ECDH_SECONDS);
2632 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2635 mr ? "+R7:%ld:%d:%.2f\n" :
2636 "%ld %d-bit ECDH ops in %.2fs\n", count,
2637 test_curves_bits[testnum], d);
2638 ecdh_results[testnum][0] = d / (double)count;
2643 if (rsa_count <= 1) {
2644 /* if longer than 10s, don't do any more */
2645 for (testnum++; testnum < EC_NUM; testnum++)
2646 ecdh_doit[testnum] = 0;
2654 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2655 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2657 printf("%s ", BN_options());
2658 #ifndef OPENSSL_NO_MD2
2659 printf("%s ", MD2_options());
2661 #ifndef OPENSSL_NO_RC4
2662 printf("%s ", RC4_options());
2664 #ifndef OPENSSL_NO_DES
2665 printf("%s ", DES_options());
2667 printf("%s ", AES_options());
2668 #ifndef OPENSSL_NO_IDEA
2669 printf("%s ", IDEA_options());
2671 #ifndef OPENSSL_NO_BF
2672 printf("%s ", BF_options());
2674 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2682 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2685 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2686 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2690 for (k = 0; k < ALGOR_NUM; k++) {
2694 printf("+F:%d:%s", k, names[k]);
2696 printf("%-13s", names[k]);
2697 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2698 if (results[k][testnum] > 10000 && !mr)
2699 printf(" %11.2fk", results[k][testnum] / 1e3);
2701 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2705 #ifndef OPENSSL_NO_RSA
2707 for (k = 0; k < RSA_NUM; k++) {
2710 if (testnum && !mr) {
2711 printf("%18ssign verify sign/s verify/s\n", " ");
2715 printf("+F2:%u:%u:%f:%f\n",
2716 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2718 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2719 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2720 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2723 #ifndef OPENSSL_NO_DSA
2725 for (k = 0; k < DSA_NUM; k++) {
2728 if (testnum && !mr) {
2729 printf("%18ssign verify sign/s verify/s\n", " ");
2733 printf("+F3:%u:%u:%f:%f\n",
2734 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2736 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2737 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2738 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2741 #ifndef OPENSSL_NO_EC
2743 for (k = 0; k < EC_NUM; k++) {
2746 if (testnum && !mr) {
2747 printf("%30ssign verify sign/s verify/s\n", " ");
2752 printf("+F4:%u:%u:%f:%f\n",
2753 k, test_curves_bits[k],
2754 ecdsa_results[k][0], ecdsa_results[k][1]);
2756 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2757 test_curves_bits[k],
2758 test_curves_names[k],
2759 ecdsa_results[k][0], ecdsa_results[k][1],
2760 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2764 #ifndef OPENSSL_NO_EC
2766 for (k = 0; k < EC_NUM; k++) {
2769 if (testnum && !mr) {
2770 printf("%30sop op/s\n", " ");
2774 printf("+F5:%u:%u:%f:%f\n",
2775 k, test_curves_bits[k],
2776 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2779 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2780 test_curves_bits[k],
2781 test_curves_names[k],
2782 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2789 ERR_print_errors(bio_err);
2790 for (i = 0; i < loopargs_len; i++) {
2791 OPENSSL_free(loopargs[i].buf_malloc);
2792 OPENSSL_free(loopargs[i].buf2_malloc);
2793 OPENSSL_free(loopargs[i].siglen);
2795 #ifndef OPENSSL_NO_RSA
2796 for (i = 0; i < loopargs_len; i++) {
2797 for (k = 0; k < RSA_NUM; k++)
2798 RSA_free(loopargs[i].rsa_key[k]);
2801 #ifndef OPENSSL_NO_DSA
2802 for (i = 0; i < loopargs_len; i++) {
2803 for (k = 0; k < DSA_NUM; k++)
2804 DSA_free(loopargs[i].dsa_key[k]);
2808 #ifndef OPENSSL_NO_EC
2809 for (i = 0; i < loopargs_len; i++) {
2810 for (k = 0; k < EC_NUM; k++) {
2811 EC_KEY_free(loopargs[i].ecdsa[k]);
2812 EC_KEY_free(loopargs[i].ecdh_a[k]);
2813 EC_KEY_free(loopargs[i].ecdh_b[k]);
2815 OPENSSL_free(loopargs[i].secret_a);
2816 OPENSSL_free(loopargs[i].secret_b);
2819 if (async_jobs > 0) {
2820 for (i = 0; i < loopargs_len; i++)
2821 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2825 ASYNC_cleanup_thread();
2827 OPENSSL_free(loopargs);
2831 static void print_message(const char *s, long num, int length)
2835 mr ? "+DT:%s:%d:%d\n"
2836 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2837 (void)BIO_flush(bio_err);
2841 mr ? "+DN:%s:%ld:%d\n"
2842 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2843 (void)BIO_flush(bio_err);
2847 static void pkey_print_message(const char *str, const char *str2, long num,
2852 mr ? "+DTP:%d:%s:%s:%d\n"
2853 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2854 (void)BIO_flush(bio_err);
2858 mr ? "+DNP:%ld:%d:%s:%s\n"
2859 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2860 (void)BIO_flush(bio_err);
2864 static void print_result(int alg, int run_no, int count, double time_used)
2867 BIO_puts(bio_err, "EVP error!\n");
2871 mr ? "+R:%d:%s:%f\n"
2872 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2873 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2877 static char *sstrsep(char **string, const char *delim)
2880 char *token = *string;
2885 memset(isdelim, 0, sizeof isdelim);
2889 isdelim[(unsigned char)(*delim)] = 1;
2893 while (!isdelim[(unsigned char)(**string)]) {
2905 static int do_multi(int multi)
2910 static char sep[] = ":";
2912 fds = malloc(sizeof(*fds) * multi);
2913 for (n = 0; n < multi; ++n) {
2914 if (pipe(fd) == -1) {
2915 BIO_printf(bio_err, "pipe failure\n");
2919 (void)BIO_flush(bio_err);
2926 if (dup(fd[1]) == -1) {
2927 BIO_printf(bio_err, "dup failed\n");
2936 printf("Forked child %d\n", n);
2939 /* for now, assume the pipe is long enough to take all the output */
2940 for (n = 0; n < multi; ++n) {
2945 f = fdopen(fds[n], "r");
2946 while (fgets(buf, sizeof buf, f)) {
2947 p = strchr(buf, '\n');
2950 if (buf[0] != '+') {
2951 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2955 printf("Got: %s from %d\n", buf, n);
2956 if (strncmp(buf, "+F:", 3) == 0) {
2961 alg = atoi(sstrsep(&p, sep));
2963 for (j = 0; j < SIZE_NUM; ++j)
2964 results[alg][j] += atof(sstrsep(&p, sep));
2965 } else if (strncmp(buf, "+F2:", 4) == 0) {
2970 k = atoi(sstrsep(&p, sep));
2973 d = atof(sstrsep(&p, sep));
2975 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2977 rsa_results[k][0] = d;
2979 d = atof(sstrsep(&p, sep));
2981 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2983 rsa_results[k][1] = d;
2985 # ifndef OPENSSL_NO_DSA
2986 else if (strncmp(buf, "+F3:", 4) == 0) {
2991 k = atoi(sstrsep(&p, sep));
2994 d = atof(sstrsep(&p, sep));
2996 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2998 dsa_results[k][0] = d;
3000 d = atof(sstrsep(&p, sep));
3002 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3004 dsa_results[k][1] = d;
3007 # ifndef OPENSSL_NO_EC
3008 else if (strncmp(buf, "+F4:", 4) == 0) {
3013 k = atoi(sstrsep(&p, sep));
3016 d = atof(sstrsep(&p, sep));
3018 ecdsa_results[k][0] =
3019 1 / (1 / ecdsa_results[k][0] + 1 / d);
3021 ecdsa_results[k][0] = d;
3023 d = atof(sstrsep(&p, sep));
3025 ecdsa_results[k][1] =
3026 1 / (1 / ecdsa_results[k][1] + 1 / d);
3028 ecdsa_results[k][1] = d;
3032 # ifndef OPENSSL_NO_EC
3033 else if (strncmp(buf, "+F5:", 4) == 0) {
3038 k = atoi(sstrsep(&p, sep));
3041 d = atof(sstrsep(&p, sep));
3043 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3045 ecdh_results[k][0] = d;
3050 else if (strncmp(buf, "+H:", 3) == 0) {
3053 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3063 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3065 static int mblengths[] =
3066 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3067 int j, count, num = OSSL_NELEM(mblengths);
3068 const char *alg_name;
3069 unsigned char *inp, *out, no_key[32], no_iv[16];
3070 EVP_CIPHER_CTX *ctx;
3073 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3074 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3075 ctx = EVP_CIPHER_CTX_new();
3076 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3077 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3079 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3081 for (j = 0; j < num; j++) {
3082 print_message(alg_name, 0, mblengths[j]);
3084 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3085 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3086 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3087 size_t len = mblengths[j];
3090 memset(aad, 0, 8); /* avoid uninitialized values */
3091 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3092 aad[9] = 3; /* version */
3094 aad[11] = 0; /* length */
3096 mb_param.out = NULL;
3099 mb_param.interleave = 8;
3101 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3102 sizeof(mb_param), &mb_param);
3108 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3109 sizeof(mb_param), &mb_param);
3113 RAND_bytes(out, 16);
3117 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3118 EVP_AEAD_TLS1_AAD_LEN, aad);
3119 EVP_Cipher(ctx, out, inp, len + pad);
3123 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3124 : "%d %s's in %.2fs\n", count, "evp", d);
3125 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3129 fprintf(stdout, "+H");
3130 for (j = 0; j < num; j++)
3131 fprintf(stdout, ":%d", mblengths[j]);
3132 fprintf(stdout, "\n");
3133 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3134 for (j = 0; j < num; j++)
3135 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3136 fprintf(stdout, "\n");
3139 "The 'numbers' are in 1000s of bytes per second processed.\n");
3140 fprintf(stdout, "type ");
3141 for (j = 0; j < num; j++)
3142 fprintf(stdout, "%7d bytes", mblengths[j]);
3143 fprintf(stdout, "\n");
3144 fprintf(stdout, "%-24s", alg_name);
3146 for (j = 0; j < num; j++) {
3147 if (results[D_EVP][j] > 10000)
3148 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3150 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3152 fprintf(stdout, "\n");
3157 EVP_CIPHER_CTX_free(ctx);