2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* ====================================================================
11 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
13 * Portions of the attached software ("Contribution") are developed by
14 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
16 * The Contribution is licensed pursuant to the OpenSSL open source
17 * license provided above.
19 * The ECDH and ECDSA speed test software is originally written by
20 * Sumit Gupta of Sun Microsystems Laboratories.
26 #define PRIME_SECONDS 10
27 #define RSA_SECONDS 10
28 #define DSA_SECONDS 10
29 #define ECDSA_SECONDS 10
30 #define ECDH_SECONDS 10
37 #include <openssl/crypto.h>
38 #include <openssl/rand.h>
39 #include <openssl/err.h>
40 #include <openssl/evp.h>
41 #include <openssl/objects.h>
42 #include <openssl/async.h>
43 #if !defined(OPENSSL_SYS_MSDOS)
44 # include OPENSSL_UNISTD
51 #include <openssl/bn.h>
52 #ifndef OPENSSL_NO_DES
53 # include <openssl/des.h>
55 #include <openssl/aes.h>
56 #ifndef OPENSSL_NO_CAMELLIA
57 # include <openssl/camellia.h>
59 #ifndef OPENSSL_NO_MD2
60 # include <openssl/md2.h>
62 #ifndef OPENSSL_NO_MDC2
63 # include <openssl/mdc2.h>
65 #ifndef OPENSSL_NO_MD4
66 # include <openssl/md4.h>
68 #ifndef OPENSSL_NO_MD5
69 # include <openssl/md5.h>
71 #include <openssl/hmac.h>
72 #include <openssl/sha.h>
73 #ifndef OPENSSL_NO_RMD160
74 # include <openssl/ripemd.h>
76 #ifndef OPENSSL_NO_WHIRLPOOL
77 # include <openssl/whrlpool.h>
79 #ifndef OPENSSL_NO_RC4
80 # include <openssl/rc4.h>
82 #ifndef OPENSSL_NO_RC5
83 # include <openssl/rc5.h>
85 #ifndef OPENSSL_NO_RC2
86 # include <openssl/rc2.h>
88 #ifndef OPENSSL_NO_IDEA
89 # include <openssl/idea.h>
91 #ifndef OPENSSL_NO_SEED
92 # include <openssl/seed.h>
95 # include <openssl/blowfish.h>
97 #ifndef OPENSSL_NO_CAST
98 # include <openssl/cast.h>
100 #ifndef OPENSSL_NO_RSA
101 # include <openssl/rsa.h>
102 # include "./testrsa.h"
104 #include <openssl/x509.h>
105 #ifndef OPENSSL_NO_DSA
106 # include <openssl/dsa.h>
107 # include "./testdsa.h"
109 #ifndef OPENSSL_NO_EC
110 # include <openssl/ec.h>
112 #include <openssl/modes.h>
115 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
129 #define BUFSIZE (1024*16+1)
130 #define MAX_MISALIGNMENT 63
139 #define MAX_ECDH_SIZE 256
142 static volatile int run = 0;
145 static int usertime = 1;
147 typedef void *(*kdf_fn) (
148 const void *in, size_t inlen, void *out, size_t *xoutlen);
150 typedef struct loopargs_st {
151 ASYNC_JOB *inprogress_job;
152 ASYNC_WAIT_CTX *wait_ctx;
155 unsigned char *buf_malloc;
156 unsigned char *buf2_malloc;
158 #ifndef OPENSSL_NO_RSA
159 RSA *rsa_key[RSA_NUM];
161 #ifndef OPENSSL_NO_DSA
162 DSA *dsa_key[DSA_NUM];
164 #ifndef OPENSSL_NO_EC
165 EC_KEY *ecdsa[EC_NUM];
166 EC_KEY *ecdh_a[EC_NUM];
167 EC_KEY *ecdh_b[EC_NUM];
168 unsigned char *secret_a;
169 unsigned char *secret_b;
175 GCM128_CONTEXT *gcm_ctx;
178 #ifndef OPENSSL_NO_MD2
179 static int EVP_Digest_MD2_loop(void *args);
182 #ifndef OPENSSL_NO_MDC2
183 static int EVP_Digest_MDC2_loop(void *args);
185 #ifndef OPENSSL_NO_MD4
186 static int EVP_Digest_MD4_loop(void *args);
188 #ifndef OPENSSL_NO_MD5
189 static int MD5_loop(void *args);
190 static int HMAC_loop(void *args);
192 static int SHA1_loop(void *args);
193 static int SHA256_loop(void *args);
194 static int SHA512_loop(void *args);
195 #ifndef OPENSSL_NO_WHIRLPOOL
196 static int WHIRLPOOL_loop(void *args);
198 #ifndef OPENSSL_NO_RMD160
199 static int EVP_Digest_RMD160_loop(void *args);
201 #ifndef OPENSSL_NO_RC4
202 static int RC4_loop(void *args);
204 #ifndef OPENSSL_NO_DES
205 static int DES_ncbc_encrypt_loop(void *args);
206 static int DES_ede3_cbc_encrypt_loop(void *args);
208 static int AES_cbc_128_encrypt_loop(void *args);
209 static int AES_cbc_192_encrypt_loop(void *args);
210 static int AES_ige_128_encrypt_loop(void *args);
211 static int AES_cbc_256_encrypt_loop(void *args);
212 static int AES_ige_192_encrypt_loop(void *args);
213 static int AES_ige_256_encrypt_loop(void *args);
214 static int CRYPTO_gcm128_aad_loop(void *args);
215 static int EVP_Update_loop(void *args);
216 static int EVP_Digest_loop(void *args);
217 #ifndef OPENSSL_NO_RSA
218 static int RSA_sign_loop(void *args);
219 static int RSA_verify_loop(void *args);
221 #ifndef OPENSSL_NO_DSA
222 static int DSA_sign_loop(void *args);
223 static int DSA_verify_loop(void *args);
225 #ifndef OPENSSL_NO_EC
226 static int ECDSA_sign_loop(void *args);
227 static int ECDSA_verify_loop(void *args);
228 static int ECDH_compute_key_loop(void *args);
230 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
232 static double Time_F(int s);
233 static void print_message(const char *s, long num, int length);
234 static void pkey_print_message(const char *str, const char *str2,
235 long num, int bits, int sec);
236 static void print_result(int alg, int run_no, int count, double time_used);
238 static int do_multi(int multi);
241 static const char *names[ALGOR_NUM] = {
242 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
243 "des cbc", "des ede3", "idea cbc", "seed cbc",
244 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
245 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
246 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
247 "evp", "sha256", "sha512", "whirlpool",
248 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
251 static double results[ALGOR_NUM][SIZE_NUM];
253 static const int lengths[SIZE_NUM] = {
254 16, 64, 256, 1024, 8 * 1024, 16 * 1024
257 #ifndef OPENSSL_NO_RSA
258 static double rsa_results[RSA_NUM][2];
260 #ifndef OPENSSL_NO_DSA
261 static double dsa_results[DSA_NUM][2];
263 #ifndef OPENSSL_NO_EC
264 static double ecdsa_results[EC_NUM][2];
265 static double ecdh_results[EC_NUM][1];
268 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
269 static const char rnd_seed[] =
270 "string to make the random number generator think it has entropy";
274 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
275 # define SIGRETTYPE void
277 # define SIGRETTYPE int
280 static SIGRETTYPE sig_done(int sig);
281 static SIGRETTYPE sig_done(int sig)
283 signal(SIGALRM, sig_done);
293 # if !defined(SIGALRM)
296 static unsigned int lapse, schlock;
297 static void alarm_win32(unsigned int secs)
302 # define alarm alarm_win32
304 static DWORD WINAPI sleepy(VOID * arg)
312 static double Time_F(int s)
319 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
321 DWORD err = GetLastError();
322 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
326 Sleep(0); /* scheduler spinlock */
327 ret = app_tminterval(s, usertime);
329 ret = app_tminterval(s, usertime);
331 TerminateThread(thr, 0);
339 static double Time_F(int s)
341 double ret = app_tminterval(s, usertime);
348 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
350 static int found(const char *name, const OPT_PAIR *pairs, int *result)
352 for (; pairs->name; pairs++)
353 if (strcmp(name, pairs->name) == 0) {
354 *result = pairs->retval;
360 typedef enum OPTION_choice {
361 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
362 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
363 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
366 OPTIONS speed_options[] = {
367 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
368 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
369 {"help", OPT_HELP, '-', "Display this summary"},
370 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
371 {"decrypt", OPT_DECRYPT, '-',
372 "Time decryption instead of encryption (only EVP)"},
373 {"mr", OPT_MR, '-', "Produce machine readable output"},
375 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
376 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
377 {"elapsed", OPT_ELAPSED, '-',
378 "Measure time in real time instead of CPU user time"},
380 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
382 #ifndef OPENSSL_NO_ASYNC
383 {"async_jobs", OPT_ASYNCJOBS, 'p',
384 "Enable async mode and start pnum jobs"},
386 #ifndef OPENSSL_NO_ENGINE
387 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
402 #define D_CBC_IDEA 10
403 #define D_CBC_SEED 11
407 #define D_CBC_CAST 15
408 #define D_CBC_128_AES 16
409 #define D_CBC_192_AES 17
410 #define D_CBC_256_AES 18
411 #define D_CBC_128_CML 19
412 #define D_CBC_192_CML 20
413 #define D_CBC_256_CML 21
417 #define D_WHIRLPOOL 25
418 #define D_IGE_128_AES 26
419 #define D_IGE_192_AES 27
420 #define D_IGE_256_AES 28
422 static OPT_PAIR doit_choices[] = {
423 #ifndef OPENSSL_NO_MD2
426 #ifndef OPENSSL_NO_MDC2
429 #ifndef OPENSSL_NO_MD4
432 #ifndef OPENSSL_NO_MD5
437 {"sha256", D_SHA256},
438 {"sha512", D_SHA512},
439 #ifndef OPENSSL_NO_WHIRLPOOL
440 {"whirlpool", D_WHIRLPOOL},
442 #ifndef OPENSSL_NO_RMD160
443 {"ripemd", D_RMD160},
444 {"rmd160", D_RMD160},
445 {"ripemd160", D_RMD160},
447 #ifndef OPENSSL_NO_RC4
450 #ifndef OPENSSL_NO_DES
451 {"des-cbc", D_CBC_DES},
452 {"des-ede3", D_EDE3_DES},
454 {"aes-128-cbc", D_CBC_128_AES},
455 {"aes-192-cbc", D_CBC_192_AES},
456 {"aes-256-cbc", D_CBC_256_AES},
457 {"aes-128-ige", D_IGE_128_AES},
458 {"aes-192-ige", D_IGE_192_AES},
459 {"aes-256-ige", D_IGE_256_AES},
460 #ifndef OPENSSL_NO_RC2
461 {"rc2-cbc", D_CBC_RC2},
464 #ifndef OPENSSL_NO_RC5
465 {"rc5-cbc", D_CBC_RC5},
468 #ifndef OPENSSL_NO_IDEA
469 {"idea-cbc", D_CBC_IDEA},
470 {"idea", D_CBC_IDEA},
472 #ifndef OPENSSL_NO_SEED
473 {"seed-cbc", D_CBC_SEED},
474 {"seed", D_CBC_SEED},
476 #ifndef OPENSSL_NO_BF
477 {"bf-cbc", D_CBC_BF},
478 {"blowfish", D_CBC_BF},
481 #ifndef OPENSSL_NO_CAST
482 {"cast-cbc", D_CBC_CAST},
483 {"cast", D_CBC_CAST},
484 {"cast5", D_CBC_CAST},
490 #ifndef OPENSSL_NO_DSA
492 # define R_DSA_1024 1
493 # define R_DSA_2048 2
494 static OPT_PAIR dsa_choices[] = {
495 {"dsa512", R_DSA_512},
496 {"dsa1024", R_DSA_1024},
497 {"dsa2048", R_DSA_2048},
508 #define R_RSA_15360 6
509 static OPT_PAIR rsa_choices[] = {
510 {"rsa512", R_RSA_512},
511 {"rsa1024", R_RSA_1024},
512 {"rsa2048", R_RSA_2048},
513 {"rsa3072", R_RSA_3072},
514 {"rsa4096", R_RSA_4096},
515 {"rsa7680", R_RSA_7680},
516 {"rsa15360", R_RSA_15360},
536 #define R_EC_X25519 16
537 #ifndef OPENSSL_NO_EC
538 static OPT_PAIR ecdsa_choices[] = {
539 {"ecdsap160", R_EC_P160},
540 {"ecdsap192", R_EC_P192},
541 {"ecdsap224", R_EC_P224},
542 {"ecdsap256", R_EC_P256},
543 {"ecdsap384", R_EC_P384},
544 {"ecdsap521", R_EC_P521},
545 {"ecdsak163", R_EC_K163},
546 {"ecdsak233", R_EC_K233},
547 {"ecdsak283", R_EC_K283},
548 {"ecdsak409", R_EC_K409},
549 {"ecdsak571", R_EC_K571},
550 {"ecdsab163", R_EC_B163},
551 {"ecdsab233", R_EC_B233},
552 {"ecdsab283", R_EC_B283},
553 {"ecdsab409", R_EC_B409},
554 {"ecdsab571", R_EC_B571},
558 static OPT_PAIR ecdh_choices[] = {
559 {"ecdhp160", R_EC_P160},
560 {"ecdhp192", R_EC_P192},
561 {"ecdhp224", R_EC_P224},
562 {"ecdhp256", R_EC_P256},
563 {"ecdhp384", R_EC_P384},
564 {"ecdhp521", R_EC_P521},
565 {"ecdhk163", R_EC_K163},
566 {"ecdhk233", R_EC_K233},
567 {"ecdhk283", R_EC_K283},
568 {"ecdhk409", R_EC_K409},
569 {"ecdhk571", R_EC_K571},
570 {"ecdhb163", R_EC_B163},
571 {"ecdhb233", R_EC_B233},
572 {"ecdhb283", R_EC_B283},
573 {"ecdhb409", R_EC_B409},
574 {"ecdhb571", R_EC_B571},
575 {"ecdhx25519", R_EC_X25519},
581 # define COND(d) (count < (d))
582 # define COUNT(d) (d)
584 # define COND(unused_cond) (run && count<0x7fffffff)
585 # define COUNT(d) (count)
590 /* Nb of iterations to do per algorithm and key-size */
591 static long c[ALGOR_NUM][SIZE_NUM];
593 #ifndef OPENSSL_NO_MD2
594 static int EVP_Digest_MD2_loop(void *args)
596 loopargs_t *tempargs = *(loopargs_t **)args;
597 unsigned char *buf = tempargs->buf;
598 unsigned char md2[MD2_DIGEST_LENGTH];
601 for (count = 0; COND(c[D_MD2][testnum]); count++) {
602 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
610 #ifndef OPENSSL_NO_MDC2
611 static int EVP_Digest_MDC2_loop(void *args)
613 loopargs_t *tempargs = *(loopargs_t **)args;
614 unsigned char *buf = tempargs->buf;
615 unsigned char mdc2[MDC2_DIGEST_LENGTH];
618 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
619 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
627 #ifndef OPENSSL_NO_MD4
628 static int EVP_Digest_MD4_loop(void *args)
630 loopargs_t *tempargs = *(loopargs_t **)args;
631 unsigned char *buf = tempargs->buf;
632 unsigned char md4[MD4_DIGEST_LENGTH];
635 for (count = 0; COND(c[D_MD4][testnum]); count++) {
636 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
644 #ifndef OPENSSL_NO_MD5
645 static int MD5_loop(void *args)
647 loopargs_t *tempargs = *(loopargs_t **)args;
648 unsigned char *buf = tempargs->buf;
649 unsigned char md5[MD5_DIGEST_LENGTH];
651 for (count = 0; COND(c[D_MD5][testnum]); count++)
652 MD5(buf, lengths[testnum], md5);
656 static int HMAC_loop(void *args)
658 loopargs_t *tempargs = *(loopargs_t **)args;
659 unsigned char *buf = tempargs->buf;
660 HMAC_CTX *hctx = tempargs->hctx;
661 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, 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, (size_t)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, (size_t)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 (size_t)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 (size_t)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 (size_t)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 (size_t)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 (size_t)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 (size_t)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]; /* # RSA iteration test */
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);
1040 /* ******************************************************************** */
1041 static long ecdh_c[EC_NUM][1];
1043 static int ECDH_compute_key_loop(void *args)
1045 loopargs_t *tempargs = *(loopargs_t **)args;
1046 EC_KEY **ecdh_a = tempargs->ecdh_a;
1047 EC_KEY **ecdh_b = tempargs->ecdh_b;
1048 unsigned char *secret_a = tempargs->secret_a;
1050 size_t outlen = tempargs->outlen;
1051 kdf_fn kdf = tempargs->kdf;
1053 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1054 ECDH_compute_key(secret_a, outlen,
1055 EC_KEY_get0_public_key(ecdh_b[testnum]),
1056 ecdh_a[testnum], kdf);
1061 static const size_t KDF1_SHA1_len = 20;
1062 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
1065 if (*outlen < SHA_DIGEST_LENGTH)
1067 *outlen = SHA_DIGEST_LENGTH;
1068 return SHA1(in, inlen, out);
1070 #endif /* OPENSSL_NO_EC */
1072 static int run_benchmark(int async_jobs,
1073 int (*loop_function)(void *), loopargs_t *loopargs)
1075 int job_op_count = 0;
1076 int total_op_count = 0;
1077 int num_inprogress = 0;
1078 int error = 0, i = 0, ret = 0;
1079 OSSL_ASYNC_FD job_fd = 0;
1080 size_t num_job_fds = 0;
1084 if (async_jobs == 0) {
1085 return loop_function((void *)&loopargs);
1088 for (i = 0; i < async_jobs && !error; i++) {
1089 loopargs_t *looparg_item = loopargs + i;
1091 /* Copy pointer content (looparg_t item address) into async context */
1092 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1093 &job_op_count, loop_function,
1094 (void *)&looparg_item, sizeof(looparg_item));
1100 if (job_op_count == -1) {
1103 total_op_count += job_op_count;
1108 BIO_printf(bio_err, "Failure in the job\n");
1109 ERR_print_errors(bio_err);
1115 while (num_inprogress > 0) {
1116 #if defined(OPENSSL_SYS_WINDOWS)
1118 #elif defined(OPENSSL_SYS_UNIX)
1119 int select_result = 0;
1120 OSSL_ASYNC_FD max_fd = 0;
1123 FD_ZERO(&waitfdset);
1125 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1126 if (loopargs[i].inprogress_job == NULL)
1129 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1130 || num_job_fds > 1) {
1131 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1132 ERR_print_errors(bio_err);
1136 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1137 FD_SET(job_fd, &waitfdset);
1138 if (job_fd > max_fd)
1142 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1144 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1145 "Decrease the value of async_jobs\n",
1146 max_fd, FD_SETSIZE);
1147 ERR_print_errors(bio_err);
1152 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1153 if (select_result == -1 && errno == EINTR)
1156 if (select_result == -1) {
1157 BIO_printf(bio_err, "Failure in the select\n");
1158 ERR_print_errors(bio_err);
1163 if (select_result == 0)
1167 for (i = 0; i < async_jobs; i++) {
1168 if (loopargs[i].inprogress_job == NULL)
1171 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1172 || num_job_fds > 1) {
1173 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1174 ERR_print_errors(bio_err);
1178 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1180 #if defined(OPENSSL_SYS_UNIX)
1181 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1183 #elif defined(OPENSSL_SYS_WINDOWS)
1184 if (num_job_fds == 1
1185 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1190 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1191 loopargs[i].wait_ctx, &job_op_count, loop_function,
1192 (void *)(loopargs + i), sizeof(loopargs_t));
1197 if (job_op_count == -1) {
1200 total_op_count += job_op_count;
1203 loopargs[i].inprogress_job = NULL;
1208 loopargs[i].inprogress_job = NULL;
1209 BIO_printf(bio_err, "Failure in the job\n");
1210 ERR_print_errors(bio_err);
1217 return error ? -1 : total_op_count;
1220 int speed_main(int argc, char **argv)
1223 loopargs_t *loopargs = NULL;
1225 int loopargs_len = 0;
1227 #ifndef OPENSSL_NO_ENGINE
1228 const char *engine_id = NULL;
1230 const EVP_CIPHER *evp_cipher = NULL;
1233 int multiblock = 0, pr_header = 0;
1234 int doit[ALGOR_NUM] = { 0 };
1235 int ret = 1, i, k, misalign = 0;
1241 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1242 || !defined(OPENSSL_NO_EC)
1246 /* What follows are the buffers and key material. */
1247 #ifndef OPENSSL_NO_RC5
1250 #ifndef OPENSSL_NO_RC2
1253 #ifndef OPENSSL_NO_IDEA
1254 IDEA_KEY_SCHEDULE idea_ks;
1256 #ifndef OPENSSL_NO_SEED
1257 SEED_KEY_SCHEDULE seed_ks;
1259 #ifndef OPENSSL_NO_BF
1262 #ifndef OPENSSL_NO_CAST
1265 static const unsigned char key16[16] = {
1266 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1267 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1269 static const unsigned char key24[24] = {
1270 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1271 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1272 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1274 static const unsigned char key32[32] = {
1275 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1276 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1277 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1278 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1280 #ifndef OPENSSL_NO_CAMELLIA
1281 static const unsigned char ckey24[24] = {
1282 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1283 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1284 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1286 static const unsigned char ckey32[32] = {
1287 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1288 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1289 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1290 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1292 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1294 #ifndef OPENSSL_NO_DES
1295 static DES_cblock key = {
1296 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1298 static DES_cblock key2 = {
1299 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1301 static DES_cblock key3 = {
1302 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1305 #ifndef OPENSSL_NO_RSA
1306 static const unsigned int rsa_bits[RSA_NUM] = {
1307 512, 1024, 2048, 3072, 4096, 7680, 15360
1309 static const unsigned char *rsa_data[RSA_NUM] = {
1310 test512, test1024, test2048, test3072, test4096, test7680, test15360
1312 static const int rsa_data_length[RSA_NUM] = {
1313 sizeof(test512), sizeof(test1024),
1314 sizeof(test2048), sizeof(test3072),
1315 sizeof(test4096), sizeof(test7680),
1318 int rsa_doit[RSA_NUM] = { 0 };
1320 #ifndef OPENSSL_NO_DSA
1321 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1322 int dsa_doit[DSA_NUM] = { 0 };
1324 #ifndef OPENSSL_NO_EC
1326 * We only test over the following curves as they are representative, To
1327 * add tests over more curves, simply add the curve NID and curve name to
1328 * the following arrays and increase the EC_NUM value accordingly.
1330 static const unsigned int test_curves[EC_NUM] = {
1332 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1333 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1335 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1336 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1337 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1342 static const char *test_curves_names[EC_NUM] = {
1344 "secp160r1", "nistp192", "nistp224",
1345 "nistp256", "nistp384", "nistp521",
1347 "nistk163", "nistk233", "nistk283",
1348 "nistk409", "nistk571", "nistb163",
1349 "nistb233", "nistb283", "nistb409",
1354 static const int test_curves_bits[EC_NUM] = {
1360 571, 253 /* X25519 */
1363 int ecdsa_doit[EC_NUM] = { 0 };
1364 int ecdh_doit[EC_NUM] = { 0 };
1365 #endif /* ndef OPENSSL_NO_EC */
1367 prog = opt_init(argc, argv, speed_options);
1368 while ((o = opt_next()) != OPT_EOF) {
1373 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1376 opt_help(speed_options);
1383 evp_cipher = EVP_get_cipherbyname(opt_arg());
1384 if (evp_cipher == NULL)
1385 evp_md = EVP_get_digestbyname(opt_arg());
1386 if (evp_cipher == NULL && evp_md == NULL) {
1388 "%s: %s is an unknown cipher or digest\n",
1399 * In a forked execution, an engine might need to be
1400 * initialised by each child process, not by the parent.
1401 * So store the name here and run setup_engine() later on.
1403 #ifndef OPENSSL_NO_ENGINE
1404 engine_id = opt_arg();
1409 multi = atoi(opt_arg());
1413 #ifndef OPENSSL_NO_ASYNC
1414 async_jobs = atoi(opt_arg());
1415 if (!ASYNC_is_capable()) {
1417 "%s: async_jobs specified but async not supported\n",
1424 if (!opt_int(opt_arg(), &misalign))
1426 if (misalign > MISALIGN) {
1428 "%s: Maximum offset is %d\n", prog, MISALIGN);
1437 #ifdef OPENSSL_NO_MULTIBLOCK
1439 "%s: -mb specified but multi-block support is disabled\n",
1446 argc = opt_num_rest();
1449 /* Remaining arguments are algorithms. */
1450 for ( ; *argv; argv++) {
1451 if (found(*argv, doit_choices, &i)) {
1455 #ifndef OPENSSL_NO_DES
1456 if (strcmp(*argv, "des") == 0) {
1457 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1461 if (strcmp(*argv, "sha") == 0) {
1462 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1465 #ifndef OPENSSL_NO_RSA
1467 if (strcmp(*argv, "openssl") == 0) {
1468 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1472 if (strcmp(*argv, "rsa") == 0) {
1473 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1474 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1475 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1476 rsa_doit[R_RSA_15360] = 1;
1479 if (found(*argv, rsa_choices, &i)) {
1484 #ifndef OPENSSL_NO_DSA
1485 if (strcmp(*argv, "dsa") == 0) {
1486 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1487 dsa_doit[R_DSA_2048] = 1;
1490 if (found(*argv, dsa_choices, &i)) {
1495 if (strcmp(*argv, "aes") == 0) {
1496 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1497 doit[D_CBC_256_AES] = 1;
1500 #ifndef OPENSSL_NO_CAMELLIA
1501 if (strcmp(*argv, "camellia") == 0) {
1502 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1503 doit[D_CBC_256_CML] = 1;
1507 #ifndef OPENSSL_NO_EC
1508 if (strcmp(*argv, "ecdsa") == 0) {
1509 for (i = 0; i < EC_NUM; i++)
1513 if (found(*argv, ecdsa_choices, &i)) {
1517 if (strcmp(*argv, "ecdh") == 0) {
1518 for (i = 0; i < EC_NUM; i++)
1522 if (found(*argv, ecdh_choices, &i)) {
1527 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1531 /* Initialize the job pool if async mode is enabled */
1532 if (async_jobs > 0) {
1533 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1535 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1540 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1541 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1542 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1544 for (i = 0; i < loopargs_len; i++) {
1545 if (async_jobs > 0) {
1546 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1547 if (loopargs[i].wait_ctx == NULL) {
1548 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1553 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1554 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1555 /* Align the start of buffers on a 64 byte boundary */
1556 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1557 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1558 #ifndef OPENSSL_NO_EC
1559 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1560 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1565 if (multi && do_multi(multi))
1569 /* Initialize the engine after the fork */
1570 e = setup_engine(engine_id, 0);
1572 /* No parameters; turn on everything. */
1573 if ((argc == 0) && !doit[D_EVP]) {
1574 for (i = 0; i < ALGOR_NUM; i++)
1577 #ifndef OPENSSL_NO_RSA
1578 for (i = 0; i < RSA_NUM; i++)
1581 #ifndef OPENSSL_NO_DSA
1582 for (i = 0; i < DSA_NUM; i++)
1585 #ifndef OPENSSL_NO_EC
1586 for (i = 0; i < EC_NUM; i++)
1588 for (i = 0; i < EC_NUM; i++)
1592 for (i = 0; i < ALGOR_NUM; i++)
1596 if (usertime == 0 && !mr)
1598 "You have chosen to measure elapsed time "
1599 "instead of user CPU time.\n");
1601 #ifndef OPENSSL_NO_RSA
1602 for (i = 0; i < loopargs_len; i++) {
1603 for (k = 0; k < RSA_NUM; k++) {
1604 const unsigned char *p;
1607 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1608 if (loopargs[i].rsa_key[k] == NULL) {
1609 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1616 #ifndef OPENSSL_NO_DSA
1617 for (i = 0; i < loopargs_len; i++) {
1618 loopargs[i].dsa_key[0] = get_dsa512();
1619 loopargs[i].dsa_key[1] = get_dsa1024();
1620 loopargs[i].dsa_key[2] = get_dsa2048();
1623 #ifndef OPENSSL_NO_DES
1624 DES_set_key_unchecked(&key, &sch);
1625 DES_set_key_unchecked(&key2, &sch2);
1626 DES_set_key_unchecked(&key3, &sch3);
1628 AES_set_encrypt_key(key16, 128, &aes_ks1);
1629 AES_set_encrypt_key(key24, 192, &aes_ks2);
1630 AES_set_encrypt_key(key32, 256, &aes_ks3);
1631 #ifndef OPENSSL_NO_CAMELLIA
1632 Camellia_set_key(key16, 128, &camellia_ks1);
1633 Camellia_set_key(ckey24, 192, &camellia_ks2);
1634 Camellia_set_key(ckey32, 256, &camellia_ks3);
1636 #ifndef OPENSSL_NO_IDEA
1637 IDEA_set_encrypt_key(key16, &idea_ks);
1639 #ifndef OPENSSL_NO_SEED
1640 SEED_set_key(key16, &seed_ks);
1642 #ifndef OPENSSL_NO_RC4
1643 RC4_set_key(&rc4_ks, 16, key16);
1645 #ifndef OPENSSL_NO_RC2
1646 RC2_set_key(&rc2_ks, 16, key16, 128);
1648 #ifndef OPENSSL_NO_RC5
1649 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1651 #ifndef OPENSSL_NO_BF
1652 BF_set_key(&bf_ks, 16, key16);
1654 #ifndef OPENSSL_NO_CAST
1655 CAST_set_key(&cast_ks, 16, key16);
1658 # ifndef OPENSSL_NO_DES
1659 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1665 for (it = count; it; it--)
1666 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1667 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1671 c[D_MD2][0] = count / 10;
1672 c[D_MDC2][0] = count / 10;
1673 c[D_MD4][0] = count;
1674 c[D_MD5][0] = count;
1675 c[D_HMAC][0] = count;
1676 c[D_SHA1][0] = count;
1677 c[D_RMD160][0] = count;
1678 c[D_RC4][0] = count * 5;
1679 c[D_CBC_DES][0] = count;
1680 c[D_EDE3_DES][0] = count / 3;
1681 c[D_CBC_IDEA][0] = count;
1682 c[D_CBC_SEED][0] = count;
1683 c[D_CBC_RC2][0] = count;
1684 c[D_CBC_RC5][0] = count;
1685 c[D_CBC_BF][0] = count;
1686 c[D_CBC_CAST][0] = count;
1687 c[D_CBC_128_AES][0] = count;
1688 c[D_CBC_192_AES][0] = count;
1689 c[D_CBC_256_AES][0] = count;
1690 c[D_CBC_128_CML][0] = count;
1691 c[D_CBC_192_CML][0] = count;
1692 c[D_CBC_256_CML][0] = count;
1693 c[D_SHA256][0] = count;
1694 c[D_SHA512][0] = count;
1695 c[D_WHIRLPOOL][0] = count;
1696 c[D_IGE_128_AES][0] = count;
1697 c[D_IGE_192_AES][0] = count;
1698 c[D_IGE_256_AES][0] = count;
1699 c[D_GHASH][0] = count;
1701 for (i = 1; i < SIZE_NUM; i++) {
1704 l0 = (long)lengths[0];
1705 l1 = (long)lengths[i];
1707 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1708 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1709 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1710 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1711 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1712 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1713 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1714 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1715 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1716 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1717 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1719 l0 = (long)lengths[i - 1];
1721 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1722 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1723 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1724 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1725 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1726 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1727 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1728 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1729 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1730 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1731 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1732 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1733 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1734 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1735 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1736 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1737 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1738 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1741 # ifndef OPENSSL_NO_RSA
1742 rsa_c[R_RSA_512][0] = count / 2000;
1743 rsa_c[R_RSA_512][1] = count / 400;
1744 for (i = 1; i < RSA_NUM; i++) {
1745 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1746 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1747 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1750 if (rsa_c[i][0] == 0) {
1751 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1758 # ifndef OPENSSL_NO_DSA
1759 dsa_c[R_DSA_512][0] = count / 1000;
1760 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1761 for (i = 1; i < DSA_NUM; i++) {
1762 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1763 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1764 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1767 if (dsa_c[i][0] == 0) {
1768 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1775 # ifndef OPENSSL_NO_EC
1776 ecdsa_c[R_EC_P160][0] = count / 1000;
1777 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1778 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1779 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1780 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1781 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1784 if (ecdsa_c[i][0] == 0) {
1790 ecdsa_c[R_EC_K163][0] = count / 1000;
1791 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1792 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1793 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1794 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1795 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1798 if (ecdsa_c[i][0] == 0) {
1804 ecdsa_c[R_EC_B163][0] = count / 1000;
1805 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1806 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1807 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1808 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1809 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1812 if (ecdsa_c[i][0] == 0) {
1819 ecdh_c[R_EC_P160][0] = count / 1000;
1820 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1821 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1822 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1825 if (ecdh_c[i][0] == 0) {
1830 ecdh_c[R_EC_K163][0] = count / 1000;
1831 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1832 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1833 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1836 if (ecdh_c[i][0] == 0) {
1841 ecdh_c[R_EC_B163][0] = count / 1000;
1842 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1843 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1844 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1847 if (ecdh_c[i][0] == 0) {
1855 /* not worth fixing */
1856 # error "You cannot disable DES on systems without SIGALRM."
1857 # endif /* OPENSSL_NO_DES */
1860 signal(SIGALRM, sig_done);
1862 #endif /* SIGALRM */
1864 #ifndef OPENSSL_NO_MD2
1866 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1867 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1869 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1871 print_result(D_MD2, testnum, count, d);
1875 #ifndef OPENSSL_NO_MDC2
1877 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1878 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1880 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1882 print_result(D_MDC2, testnum, count, d);
1887 #ifndef OPENSSL_NO_MD4
1889 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1890 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1892 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1894 print_result(D_MD4, testnum, count, d);
1899 #ifndef OPENSSL_NO_MD5
1901 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1902 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1904 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1906 print_result(D_MD5, testnum, count, d);
1911 static const char hmac_key[] = "This is a key...";
1912 int len = strlen(hmac_key);
1914 for (i = 0; i < loopargs_len; i++) {
1915 loopargs[i].hctx = HMAC_CTX_new();
1916 if (loopargs[i].hctx == NULL) {
1917 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1921 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1923 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1924 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1926 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1928 print_result(D_HMAC, testnum, count, d);
1930 for (i = 0; i < loopargs_len; i++) {
1931 HMAC_CTX_free(loopargs[i].hctx);
1936 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1937 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1939 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1941 print_result(D_SHA1, testnum, count, d);
1944 if (doit[D_SHA256]) {
1945 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1946 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1948 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1950 print_result(D_SHA256, testnum, count, d);
1953 if (doit[D_SHA512]) {
1954 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1955 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1957 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1959 print_result(D_SHA512, testnum, count, d);
1963 #ifndef OPENSSL_NO_WHIRLPOOL
1964 if (doit[D_WHIRLPOOL]) {
1965 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1966 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1968 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1970 print_result(D_WHIRLPOOL, testnum, count, d);
1975 #ifndef OPENSSL_NO_RMD160
1976 if (doit[D_RMD160]) {
1977 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1978 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1980 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1982 print_result(D_RMD160, testnum, count, d);
1986 #ifndef OPENSSL_NO_RC4
1988 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1989 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1991 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1993 print_result(D_RC4, testnum, count, d);
1997 #ifndef OPENSSL_NO_DES
1998 if (doit[D_CBC_DES]) {
1999 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2000 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
2002 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2004 print_result(D_CBC_DES, testnum, count, d);
2008 if (doit[D_EDE3_DES]) {
2009 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2010 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2012 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2014 print_result(D_EDE3_DES, testnum, count, d);
2019 if (doit[D_CBC_128_AES]) {
2020 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2021 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2024 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2026 print_result(D_CBC_128_AES, testnum, count, d);
2029 if (doit[D_CBC_192_AES]) {
2030 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2031 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2034 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2036 print_result(D_CBC_192_AES, testnum, count, d);
2039 if (doit[D_CBC_256_AES]) {
2040 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2041 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2044 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2046 print_result(D_CBC_256_AES, testnum, count, d);
2050 if (doit[D_IGE_128_AES]) {
2051 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2052 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2055 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2057 print_result(D_IGE_128_AES, testnum, count, d);
2060 if (doit[D_IGE_192_AES]) {
2061 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2062 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2065 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2067 print_result(D_IGE_192_AES, testnum, count, d);
2070 if (doit[D_IGE_256_AES]) {
2071 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2072 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2075 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2077 print_result(D_IGE_256_AES, testnum, count, d);
2080 if (doit[D_GHASH]) {
2081 for (i = 0; i < loopargs_len; i++) {
2082 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2083 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2086 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2087 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2089 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2091 print_result(D_GHASH, testnum, count, d);
2093 for (i = 0; i < loopargs_len; i++)
2094 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2097 #ifndef OPENSSL_NO_CAMELLIA
2098 if (doit[D_CBC_128_CML]) {
2099 if (async_jobs > 0) {
2100 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2101 names[D_CBC_128_CML]);
2102 doit[D_CBC_128_CML] = 0;
2104 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2105 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2108 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2109 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2110 (size_t)lengths[testnum], &camellia_ks1,
2111 iv, CAMELLIA_ENCRYPT);
2113 print_result(D_CBC_128_CML, testnum, count, d);
2116 if (doit[D_CBC_192_CML]) {
2117 if (async_jobs > 0) {
2118 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2119 names[D_CBC_192_CML]);
2120 doit[D_CBC_192_CML] = 0;
2122 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2123 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2125 if (async_jobs > 0) {
2126 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2130 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2131 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2132 (size_t)lengths[testnum], &camellia_ks2,
2133 iv, CAMELLIA_ENCRYPT);
2135 print_result(D_CBC_192_CML, testnum, count, d);
2138 if (doit[D_CBC_256_CML]) {
2139 if (async_jobs > 0) {
2140 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2141 names[D_CBC_256_CML]);
2142 doit[D_CBC_256_CML] = 0;
2144 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2145 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2148 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2149 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2150 (size_t)lengths[testnum], &camellia_ks3,
2151 iv, CAMELLIA_ENCRYPT);
2153 print_result(D_CBC_256_CML, testnum, count, d);
2157 #ifndef OPENSSL_NO_IDEA
2158 if (doit[D_CBC_IDEA]) {
2159 if (async_jobs > 0) {
2160 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2162 doit[D_CBC_IDEA] = 0;
2164 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2165 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2167 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2168 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2169 (size_t)lengths[testnum], &idea_ks,
2172 print_result(D_CBC_IDEA, testnum, count, d);
2176 #ifndef OPENSSL_NO_SEED
2177 if (doit[D_CBC_SEED]) {
2178 if (async_jobs > 0) {
2179 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2181 doit[D_CBC_SEED] = 0;
2183 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2184 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2186 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2187 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2188 (size_t)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 if (async_jobs > 0) {
2197 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2199 doit[D_CBC_RC2] = 0;
2201 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2202 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2203 if (async_jobs > 0) {
2204 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2208 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2209 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2210 (size_t)lengths[testnum], &rc2_ks,
2213 print_result(D_CBC_RC2, testnum, count, d);
2217 #ifndef OPENSSL_NO_RC5
2218 if (doit[D_CBC_RC5]) {
2219 if (async_jobs > 0) {
2220 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2222 doit[D_CBC_RC5] = 0;
2224 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2225 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2226 if (async_jobs > 0) {
2227 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2231 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2232 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2233 (size_t)lengths[testnum], &rc5_ks,
2236 print_result(D_CBC_RC5, testnum, count, d);
2240 #ifndef OPENSSL_NO_BF
2241 if (doit[D_CBC_BF]) {
2242 if (async_jobs > 0) {
2243 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2247 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2248 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2250 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2251 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2252 (size_t)lengths[testnum], &bf_ks,
2255 print_result(D_CBC_BF, testnum, count, d);
2259 #ifndef OPENSSL_NO_CAST
2260 if (doit[D_CBC_CAST]) {
2261 if (async_jobs > 0) {
2262 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2264 doit[D_CBC_CAST] = 0;
2266 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2267 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2269 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2270 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2271 (size_t)lengths[testnum], &cast_ks,
2274 print_result(D_CBC_CAST, testnum, count, d);
2280 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2281 if (multiblock && evp_cipher) {
2283 (EVP_CIPHER_flags(evp_cipher) &
2284 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2285 BIO_printf(bio_err, "%s is not multi-block capable\n",
2286 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2289 if (async_jobs > 0) {
2290 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2293 multiblock_speed(evp_cipher);
2298 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2301 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2303 * -O3 -fschedule-insns messes up an optimization here!
2304 * names[D_EVP] somehow becomes NULL
2306 print_message(names[D_EVP], save_count, lengths[testnum]);
2308 for (k = 0; k < loopargs_len; k++) {
2309 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2311 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2313 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2314 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2318 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2320 for (k = 0; k < loopargs_len; k++) {
2321 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2325 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2326 print_message(names[D_EVP], save_count, lengths[testnum]);
2328 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2331 print_result(D_EVP, testnum, count, d);
2335 for (i = 0; i < loopargs_len; i++)
2336 RAND_bytes(loopargs[i].buf, 36);
2338 #ifndef OPENSSL_NO_RSA
2339 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2341 if (!rsa_doit[testnum])
2343 for (i = 0; i < loopargs_len; i++) {
2344 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2345 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2351 "RSA sign failure. No RSA sign will be done.\n");
2352 ERR_print_errors(bio_err);
2355 pkey_print_message("private", "rsa",
2356 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2357 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2359 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2362 mr ? "+R1:%ld:%d:%.2f\n"
2363 : "%ld %d bit private RSA's in %.2fs\n",
2364 count, rsa_bits[testnum], d);
2365 rsa_results[testnum][0] = d / (double)count;
2369 for (i = 0; i < loopargs_len; i++) {
2370 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2371 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2377 "RSA verify failure. No RSA verify will be done.\n");
2378 ERR_print_errors(bio_err);
2379 rsa_doit[testnum] = 0;
2381 pkey_print_message("public", "rsa",
2382 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2384 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2387 mr ? "+R2:%ld:%d:%.2f\n"
2388 : "%ld %d bit public RSA's in %.2fs\n",
2389 count, rsa_bits[testnum], d);
2390 rsa_results[testnum][1] = d / (double)count;
2393 if (rsa_count <= 1) {
2394 /* if longer than 10s, don't do any more */
2395 for (testnum++; testnum < RSA_NUM; testnum++)
2396 rsa_doit[testnum] = 0;
2399 #endif /* OPENSSL_NO_RSA */
2401 for (i = 0; i < loopargs_len; i++)
2402 RAND_bytes(loopargs[i].buf, 36);
2404 #ifndef OPENSSL_NO_DSA
2405 if (RAND_status() != 1) {
2406 RAND_seed(rnd_seed, sizeof rnd_seed);
2408 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2410 if (!dsa_doit[testnum])
2413 /* DSA_generate_key(dsa_key[testnum]); */
2414 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2415 for (i = 0; i < loopargs_len; i++) {
2416 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2417 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2423 "DSA sign failure. No DSA sign will be done.\n");
2424 ERR_print_errors(bio_err);
2427 pkey_print_message("sign", "dsa",
2428 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2430 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2433 mr ? "+R3:%ld:%d:%.2f\n"
2434 : "%ld %d bit DSA signs in %.2fs\n",
2435 count, dsa_bits[testnum], d);
2436 dsa_results[testnum][0] = d / (double)count;
2440 for (i = 0; i < loopargs_len; i++) {
2441 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2442 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2448 "DSA verify failure. No DSA verify will be done.\n");
2449 ERR_print_errors(bio_err);
2450 dsa_doit[testnum] = 0;
2452 pkey_print_message("verify", "dsa",
2453 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2455 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2458 mr ? "+R4:%ld:%d:%.2f\n"
2459 : "%ld %d bit DSA verify in %.2fs\n",
2460 count, dsa_bits[testnum], d);
2461 dsa_results[testnum][1] = d / (double)count;
2464 if (rsa_count <= 1) {
2465 /* if longer than 10s, don't do any more */
2466 for (testnum++; testnum < DSA_NUM; testnum++)
2467 dsa_doit[testnum] = 0;
2470 #endif /* OPENSSL_NO_DSA */
2472 #ifndef OPENSSL_NO_EC
2473 if (RAND_status() != 1) {
2474 RAND_seed(rnd_seed, sizeof rnd_seed);
2476 for (testnum = 0; testnum < EC_NUM; testnum++) {
2479 if (!ecdsa_doit[testnum])
2480 continue; /* Ignore Curve */
2481 for (i = 0; i < loopargs_len; i++) {
2482 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2483 if (loopargs[i].ecdsa[testnum] == NULL) {
2489 BIO_printf(bio_err, "ECDSA failure.\n");
2490 ERR_print_errors(bio_err);
2493 for (i = 0; i < loopargs_len; i++) {
2494 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2495 /* Perform ECDSA signature test */
2496 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2497 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2498 &loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2504 "ECDSA sign failure. No ECDSA sign will be done.\n");
2505 ERR_print_errors(bio_err);
2508 pkey_print_message("sign", "ecdsa",
2509 ecdsa_c[testnum][0],
2510 test_curves_bits[testnum], ECDSA_SECONDS);
2512 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2516 mr ? "+R5:%ld:%d:%.2f\n" :
2517 "%ld %d bit ECDSA signs in %.2fs \n",
2518 count, test_curves_bits[testnum], d);
2519 ecdsa_results[testnum][0] = d / (double)count;
2523 /* Perform ECDSA verification test */
2524 for (i = 0; i < loopargs_len; i++) {
2525 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2526 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2532 "ECDSA verify failure. No ECDSA verify will be done.\n");
2533 ERR_print_errors(bio_err);
2534 ecdsa_doit[testnum] = 0;
2536 pkey_print_message("verify", "ecdsa",
2537 ecdsa_c[testnum][1],
2538 test_curves_bits[testnum], ECDSA_SECONDS);
2540 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2543 mr ? "+R6:%ld:%d:%.2f\n"
2544 : "%ld %d bit ECDSA verify in %.2fs\n",
2545 count, test_curves_bits[testnum], d);
2546 ecdsa_results[testnum][1] = d / (double)count;
2549 if (rsa_count <= 1) {
2550 /* if longer than 10s, don't do any more */
2551 for (testnum++; testnum < EC_NUM; testnum++)
2552 ecdsa_doit[testnum] = 0;
2557 if (RAND_status() != 1) {
2558 RAND_seed(rnd_seed, sizeof rnd_seed);
2560 for (testnum = 0; testnum < EC_NUM; testnum++) {
2561 int ecdh_checks = 1;
2563 if (!ecdh_doit[testnum])
2565 for (i = 0; i < loopargs_len; i++) {
2566 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2567 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2568 if (loopargs[i].ecdh_a[testnum] == NULL ||
2569 loopargs[i].ecdh_b[testnum] == NULL) {
2574 if (ecdh_checks == 0) {
2575 BIO_printf(bio_err, "ECDH failure.\n");
2576 ERR_print_errors(bio_err);
2579 for (i = 0; i < loopargs_len; i++) {
2580 /* generate two ECDH key pairs */
2581 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2582 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2583 BIO_printf(bio_err, "ECDH key generation failure.\n");
2584 ERR_print_errors(bio_err);
2588 int secret_size_a, secret_size_b;
2590 * If field size is not more than 24 octets, then use SHA-1
2591 * hash of result; otherwise, use result (see section 4.8 of
2592 * draft-ietf-tls-ecc-03.txt).
2594 int field_size = EC_GROUP_get_degree(
2595 EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2597 if (field_size <= 24 * 8) { /* 192 bits */
2598 loopargs[i].outlen = KDF1_SHA1_len;
2599 loopargs[i].kdf = KDF1_SHA1;
2601 loopargs[i].outlen = (field_size + 7) / 8;
2602 loopargs[i].kdf = NULL;
2605 ECDH_compute_key(loopargs[i].secret_a, loopargs[i].outlen,
2606 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2607 loopargs[i].ecdh_a[testnum], loopargs[i].kdf);
2609 ECDH_compute_key(loopargs[i].secret_b, loopargs[i].outlen,
2610 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2611 loopargs[i].ecdh_b[testnum], loopargs[i].kdf);
2612 if (secret_size_a != secret_size_b)
2617 for (k = 0; k < secret_size_a && ecdh_checks == 1; k++) {
2618 if (loopargs[i].secret_a[k] != loopargs[i].secret_b[k])
2622 if (ecdh_checks == 0) {
2623 BIO_printf(bio_err, "ECDH computations don't match.\n");
2624 ERR_print_errors(bio_err);
2630 if (ecdh_checks != 0) {
2631 pkey_print_message("", "ecdh",
2633 test_curves_bits[testnum], ECDH_SECONDS);
2635 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2638 mr ? "+R7:%ld:%d:%.2f\n" :
2639 "%ld %d-bit ECDH ops in %.2fs\n", count,
2640 test_curves_bits[testnum], d);
2641 ecdh_results[testnum][0] = d / (double)count;
2646 if (rsa_count <= 1) {
2647 /* if longer than 10s, don't do any more */
2648 for (testnum++; testnum < EC_NUM; testnum++)
2649 ecdh_doit[testnum] = 0;
2652 #endif /* OPENSSL_NO_EC */
2657 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2658 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2660 printf("%s ", BN_options());
2661 #ifndef OPENSSL_NO_MD2
2662 printf("%s ", MD2_options());
2664 #ifndef OPENSSL_NO_RC4
2665 printf("%s ", RC4_options());
2667 #ifndef OPENSSL_NO_DES
2668 printf("%s ", DES_options());
2670 printf("%s ", AES_options());
2671 #ifndef OPENSSL_NO_IDEA
2672 printf("%s ", IDEA_options());
2674 #ifndef OPENSSL_NO_BF
2675 printf("%s ", BF_options());
2677 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2685 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2688 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2689 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2693 for (k = 0; k < ALGOR_NUM; k++) {
2697 printf("+F:%d:%s", k, names[k]);
2699 printf("%-13s", names[k]);
2700 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2701 if (results[k][testnum] > 10000 && !mr)
2702 printf(" %11.2fk", results[k][testnum] / 1e3);
2704 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2708 #ifndef OPENSSL_NO_RSA
2710 for (k = 0; k < RSA_NUM; k++) {
2713 if (testnum && !mr) {
2714 printf("%18ssign verify sign/s verify/s\n", " ");
2718 printf("+F2:%u:%u:%f:%f\n",
2719 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2721 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2722 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2723 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2726 #ifndef OPENSSL_NO_DSA
2728 for (k = 0; k < DSA_NUM; k++) {
2731 if (testnum && !mr) {
2732 printf("%18ssign verify sign/s verify/s\n", " ");
2736 printf("+F3:%u:%u:%f:%f\n",
2737 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2739 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2740 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2741 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2744 #ifndef OPENSSL_NO_EC
2746 for (k = 0; k < EC_NUM; k++) {
2749 if (testnum && !mr) {
2750 printf("%30ssign verify sign/s verify/s\n", " ");
2755 printf("+F4:%u:%u:%f:%f\n",
2756 k, test_curves_bits[k],
2757 ecdsa_results[k][0], ecdsa_results[k][1]);
2759 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2760 test_curves_bits[k],
2761 test_curves_names[k],
2762 ecdsa_results[k][0], ecdsa_results[k][1],
2763 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2767 for (k = 0; k < EC_NUM; k++) {
2770 if (testnum && !mr) {
2771 printf("%30sop op/s\n", " ");
2775 printf("+F5:%u:%u:%f:%f\n",
2776 k, test_curves_bits[k],
2777 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2780 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2781 test_curves_bits[k],
2782 test_curves_names[k],
2783 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2790 ERR_print_errors(bio_err);
2791 for (i = 0; i < loopargs_len; i++) {
2792 OPENSSL_free(loopargs[i].buf_malloc);
2793 OPENSSL_free(loopargs[i].buf2_malloc);
2795 #ifndef OPENSSL_NO_RSA
2796 for (k = 0; k < RSA_NUM; k++)
2797 RSA_free(loopargs[i].rsa_key[k]);
2799 #ifndef OPENSSL_NO_DSA
2800 for (k = 0; k < DSA_NUM; k++)
2801 DSA_free(loopargs[i].dsa_key[k]);
2803 #ifndef OPENSSL_NO_EC
2804 for (k = 0; k < EC_NUM; k++) {
2805 EC_KEY_free(loopargs[i].ecdsa[k]);
2806 EC_KEY_free(loopargs[i].ecdh_a[k]);
2807 EC_KEY_free(loopargs[i].ecdh_b[k]);
2809 OPENSSL_free(loopargs[i].secret_a);
2810 OPENSSL_free(loopargs[i].secret_b);
2814 if (async_jobs > 0) {
2815 for (i = 0; i < loopargs_len; i++)
2816 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2820 ASYNC_cleanup_thread();
2822 OPENSSL_free(loopargs);
2827 static void print_message(const char *s, long num, int length)
2831 mr ? "+DT:%s:%d:%d\n"
2832 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2833 (void)BIO_flush(bio_err);
2837 mr ? "+DN:%s:%ld:%d\n"
2838 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2839 (void)BIO_flush(bio_err);
2843 static void pkey_print_message(const char *str, const char *str2, long num,
2848 mr ? "+DTP:%d:%s:%s:%d\n"
2849 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2850 (void)BIO_flush(bio_err);
2854 mr ? "+DNP:%ld:%d:%s:%s\n"
2855 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2856 (void)BIO_flush(bio_err);
2860 static void print_result(int alg, int run_no, int count, double time_used)
2863 BIO_puts(bio_err, "EVP error!\n");
2867 mr ? "+R:%d:%s:%f\n"
2868 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2869 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2873 static char *sstrsep(char **string, const char *delim)
2876 char *token = *string;
2881 memset(isdelim, 0, sizeof isdelim);
2885 isdelim[(unsigned char)(*delim)] = 1;
2889 while (!isdelim[(unsigned char)(**string)]) {
2901 static int do_multi(int multi)
2906 static char sep[] = ":";
2908 fds = malloc(sizeof(*fds) * multi);
2909 for (n = 0; n < multi; ++n) {
2910 if (pipe(fd) == -1) {
2911 BIO_printf(bio_err, "pipe failure\n");
2915 (void)BIO_flush(bio_err);
2922 if (dup(fd[1]) == -1) {
2923 BIO_printf(bio_err, "dup failed\n");
2932 printf("Forked child %d\n", n);
2935 /* for now, assume the pipe is long enough to take all the output */
2936 for (n = 0; n < multi; ++n) {
2941 f = fdopen(fds[n], "r");
2942 while (fgets(buf, sizeof buf, f)) {
2943 p = strchr(buf, '\n');
2946 if (buf[0] != '+') {
2947 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2951 printf("Got: %s from %d\n", buf, n);
2952 if (strncmp(buf, "+F:", 3) == 0) {
2957 alg = atoi(sstrsep(&p, sep));
2959 for (j = 0; j < SIZE_NUM; ++j)
2960 results[alg][j] += atof(sstrsep(&p, sep));
2961 } else if (strncmp(buf, "+F2:", 4) == 0) {
2966 k = atoi(sstrsep(&p, sep));
2969 d = atof(sstrsep(&p, sep));
2971 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2973 rsa_results[k][0] = d;
2975 d = atof(sstrsep(&p, sep));
2977 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2979 rsa_results[k][1] = d;
2981 # ifndef OPENSSL_NO_DSA
2982 else if (strncmp(buf, "+F3:", 4) == 0) {
2987 k = atoi(sstrsep(&p, sep));
2990 d = atof(sstrsep(&p, sep));
2992 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2994 dsa_results[k][0] = d;
2996 d = atof(sstrsep(&p, sep));
2998 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3000 dsa_results[k][1] = d;
3003 # ifndef OPENSSL_NO_EC
3004 else if (strncmp(buf, "+F4:", 4) == 0) {
3009 k = atoi(sstrsep(&p, sep));
3012 d = atof(sstrsep(&p, sep));
3014 ecdsa_results[k][0] =
3015 1 / (1 / ecdsa_results[k][0] + 1 / d);
3017 ecdsa_results[k][0] = d;
3019 d = atof(sstrsep(&p, sep));
3021 ecdsa_results[k][1] =
3022 1 / (1 / ecdsa_results[k][1] + 1 / d);
3024 ecdsa_results[k][1] = d;
3025 } else if (strncmp(buf, "+F5:", 4) == 0) {
3030 k = atoi(sstrsep(&p, sep));
3033 d = atof(sstrsep(&p, sep));
3035 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3037 ecdh_results[k][0] = d;
3042 else if (strncmp(buf, "+H:", 3) == 0) {
3045 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3055 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3057 static int mblengths[] =
3058 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3059 int j, count, num = OSSL_NELEM(mblengths);
3060 const char *alg_name;
3061 unsigned char *inp, *out, no_key[32], no_iv[16];
3062 EVP_CIPHER_CTX *ctx;
3065 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3066 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3067 ctx = EVP_CIPHER_CTX_new();
3068 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3069 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3071 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3073 for (j = 0; j < num; j++) {
3074 print_message(alg_name, 0, mblengths[j]);
3076 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3077 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3078 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3079 size_t len = mblengths[j];
3082 memset(aad, 0, 8); /* avoid uninitialized values */
3083 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3084 aad[9] = 3; /* version */
3086 aad[11] = 0; /* length */
3088 mb_param.out = NULL;
3091 mb_param.interleave = 8;
3093 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3094 sizeof(mb_param), &mb_param);
3100 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3101 sizeof(mb_param), &mb_param);
3105 RAND_bytes(out, 16);
3109 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3110 EVP_AEAD_TLS1_AAD_LEN, aad);
3111 EVP_Cipher(ctx, out, inp, len + pad);
3115 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3116 : "%d %s's in %.2fs\n", count, "evp", d);
3117 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3121 fprintf(stdout, "+H");
3122 for (j = 0; j < num; j++)
3123 fprintf(stdout, ":%d", mblengths[j]);
3124 fprintf(stdout, "\n");
3125 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3126 for (j = 0; j < num; j++)
3127 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3128 fprintf(stdout, "\n");
3131 "The 'numbers' are in 1000s of bytes per second processed.\n");
3132 fprintf(stdout, "type ");
3133 for (j = 0; j < num; j++)
3134 fprintf(stdout, "%7d bytes", mblengths[j]);
3135 fprintf(stdout, "\n");
3136 fprintf(stdout, "%-24s", alg_name);
3138 for (j = 0; j < num; j++) {
3139 if (results[D_EVP][j] > 10000)
3140 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3142 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3144 fprintf(stdout, "\n");
3149 EVP_CIPHER_CTX_free(ctx);