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];
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 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
376 {"elapsed", OPT_ELAPSED, '-',
377 "Measure time in real time instead of CPU user time"},
379 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
381 #ifndef OPENSSL_NO_ASYNC
382 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
384 #ifndef OPENSSL_NO_ENGINE
385 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
400 #define D_CBC_IDEA 10
401 #define D_CBC_SEED 11
405 #define D_CBC_CAST 15
406 #define D_CBC_128_AES 16
407 #define D_CBC_192_AES 17
408 #define D_CBC_256_AES 18
409 #define D_CBC_128_CML 19
410 #define D_CBC_192_CML 20
411 #define D_CBC_256_CML 21
415 #define D_WHIRLPOOL 25
416 #define D_IGE_128_AES 26
417 #define D_IGE_192_AES 27
418 #define D_IGE_256_AES 28
420 static OPT_PAIR doit_choices[] = {
421 #ifndef OPENSSL_NO_MD2
424 #ifndef OPENSSL_NO_MDC2
427 #ifndef OPENSSL_NO_MD4
430 #ifndef OPENSSL_NO_MD5
433 #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},
557 static OPT_PAIR ecdh_choices[] = {
558 {"ecdhp160", R_EC_P160},
559 {"ecdhp192", R_EC_P192},
560 {"ecdhp224", R_EC_P224},
561 {"ecdhp256", R_EC_P256},
562 {"ecdhp384", R_EC_P384},
563 {"ecdhp521", R_EC_P521},
564 {"ecdhk163", R_EC_K163},
565 {"ecdhk233", R_EC_K233},
566 {"ecdhk283", R_EC_K283},
567 {"ecdhk409", R_EC_K409},
568 {"ecdhk571", R_EC_K571},
569 {"ecdhb163", R_EC_B163},
570 {"ecdhb233", R_EC_B233},
571 {"ecdhb283", R_EC_B283},
572 {"ecdhb409", R_EC_B409},
573 {"ecdhb571", R_EC_B571},
574 {"ecdhx25519", R_EC_X25519},
580 # define COND(d) (count < (d))
581 # define COUNT(d) (d)
583 # define COND(unused_cond) (run && count<0x7fffffff)
584 # define COUNT(d) (count)
589 static long c[ALGOR_NUM][SIZE_NUM];
591 #ifndef OPENSSL_NO_MD2
592 static int EVP_Digest_MD2_loop(void *args)
594 loopargs_t *tempargs = (loopargs_t *)args;
595 unsigned char *buf = tempargs->buf;
596 unsigned char md2[MD2_DIGEST_LENGTH];
599 for (count = 0; COND(c[D_MD2][testnum]); count++) {
600 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
608 #ifndef OPENSSL_NO_MDC2
609 static int EVP_Digest_MDC2_loop(void *args)
611 loopargs_t *tempargs = (loopargs_t *)args;
612 unsigned char *buf = tempargs->buf;
613 unsigned char mdc2[MDC2_DIGEST_LENGTH];
616 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
617 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
625 #ifndef OPENSSL_NO_MD4
626 static int EVP_Digest_MD4_loop(void *args)
628 loopargs_t *tempargs = (loopargs_t *)args;
629 unsigned char *buf = tempargs->buf;
630 unsigned char md4[MD4_DIGEST_LENGTH];
633 for (count = 0; COND(c[D_MD4][testnum]); count++) {
634 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
642 #ifndef OPENSSL_NO_MD5
643 static int MD5_loop(void *args)
645 loopargs_t *tempargs = (loopargs_t *)args;
646 unsigned char *buf = tempargs->buf;
647 unsigned char md5[MD5_DIGEST_LENGTH];
649 for (count = 0; COND(c[D_MD5][testnum]); count++)
650 MD5(buf, lengths[testnum], md5);
654 static int HMAC_loop(void *args)
656 loopargs_t *tempargs = (loopargs_t *)args;
657 unsigned char *buf = tempargs->buf;
658 HMAC_CTX *hctx = tempargs->hctx;
659 unsigned char hmac[MD5_DIGEST_LENGTH];
662 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
663 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
664 HMAC_Update(hctx, buf, lengths[testnum]);
665 HMAC_Final(hctx, hmac, NULL);
671 static int SHA1_loop(void *args)
673 loopargs_t *tempargs = (loopargs_t *)args;
674 unsigned char *buf = tempargs->buf;
675 unsigned char sha[SHA_DIGEST_LENGTH];
677 for (count = 0; COND(c[D_SHA1][testnum]); count++)
678 SHA1(buf, lengths[testnum], sha);
682 static int SHA256_loop(void *args)
684 loopargs_t *tempargs = (loopargs_t *)args;
685 unsigned char *buf = tempargs->buf;
686 unsigned char sha256[SHA256_DIGEST_LENGTH];
688 for (count = 0; COND(c[D_SHA256][testnum]); count++)
689 SHA256(buf, lengths[testnum], sha256);
693 static int SHA512_loop(void *args)
695 loopargs_t *tempargs = (loopargs_t *)args;
696 unsigned char *buf = tempargs->buf;
697 unsigned char sha512[SHA512_DIGEST_LENGTH];
699 for (count = 0; COND(c[D_SHA512][testnum]); count++)
700 SHA512(buf, lengths[testnum], sha512);
704 #ifndef OPENSSL_NO_WHIRLPOOL
705 static int WHIRLPOOL_loop(void *args)
707 loopargs_t *tempargs = (loopargs_t *)args;
708 unsigned char *buf = tempargs->buf;
709 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
711 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
712 WHIRLPOOL(buf, lengths[testnum], whirlpool);
717 #ifndef OPENSSL_NO_RMD160
718 static int EVP_Digest_RMD160_loop(void *args)
720 loopargs_t *tempargs = (loopargs_t *)args;
721 unsigned char *buf = tempargs->buf;
722 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
724 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
725 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
726 NULL, EVP_ripemd160(), NULL))
733 #ifndef OPENSSL_NO_RC4
734 static RC4_KEY rc4_ks;
735 static int RC4_loop(void *args)
737 loopargs_t *tempargs = (loopargs_t *)args;
738 unsigned char *buf = tempargs->buf;
740 for (count = 0; COND(c[D_RC4][testnum]); count++)
741 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
746 #ifndef OPENSSL_NO_DES
747 static unsigned char DES_iv[8];
748 static DES_key_schedule sch;
749 static DES_key_schedule sch2;
750 static DES_key_schedule sch3;
751 static int DES_ncbc_encrypt_loop(void *args)
753 loopargs_t *tempargs = (loopargs_t *)args;
754 unsigned char *buf = tempargs->buf;
756 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
757 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
758 &DES_iv, DES_ENCRYPT);
762 static int DES_ede3_cbc_encrypt_loop(void *args)
764 loopargs_t *tempargs = (loopargs_t *)args;
765 unsigned char *buf = tempargs->buf;
767 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
768 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
770 &DES_iv, DES_ENCRYPT);
775 #define MAX_BLOCK_SIZE 128
777 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
778 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
779 static int AES_cbc_128_encrypt_loop(void *args)
781 loopargs_t *tempargs = (loopargs_t *)args;
782 unsigned char *buf = tempargs->buf;
784 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
785 AES_cbc_encrypt(buf, buf,
786 (size_t)lengths[testnum], &aes_ks1,
791 static int AES_cbc_192_encrypt_loop(void *args)
793 loopargs_t *tempargs = (loopargs_t *)args;
794 unsigned char *buf = tempargs->buf;
796 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
797 AES_cbc_encrypt(buf, buf,
798 (size_t)lengths[testnum], &aes_ks2,
803 static int AES_cbc_256_encrypt_loop(void *args)
805 loopargs_t *tempargs = (loopargs_t *)args;
806 unsigned char *buf = tempargs->buf;
808 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
809 AES_cbc_encrypt(buf, buf,
810 (size_t)lengths[testnum], &aes_ks3,
815 static int AES_ige_128_encrypt_loop(void *args)
817 loopargs_t *tempargs = (loopargs_t *)args;
818 unsigned char *buf = tempargs->buf;
819 unsigned char *buf2 = tempargs->buf2;
821 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
822 AES_ige_encrypt(buf, buf2,
823 (size_t)lengths[testnum], &aes_ks1,
828 static int AES_ige_192_encrypt_loop(void *args)
830 loopargs_t *tempargs = (loopargs_t *)args;
831 unsigned char *buf = tempargs->buf;
832 unsigned char *buf2 = tempargs->buf2;
834 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
835 AES_ige_encrypt(buf, buf2,
836 (size_t)lengths[testnum], &aes_ks2,
841 static int AES_ige_256_encrypt_loop(void *args)
843 loopargs_t *tempargs = (loopargs_t *)args;
844 unsigned char *buf = tempargs->buf;
845 unsigned char *buf2 = tempargs->buf2;
847 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
848 AES_ige_encrypt(buf, buf2,
849 (size_t)lengths[testnum], &aes_ks3,
854 static int CRYPTO_gcm128_aad_loop(void *args)
856 loopargs_t *tempargs = (loopargs_t *)args;
857 unsigned char *buf = tempargs->buf;
858 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
860 for (count = 0; COND(c[D_GHASH][testnum]); count++)
861 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
865 static long save_count = 0;
866 static int decrypt = 0;
867 static int EVP_Update_loop(void *args)
869 loopargs_t *tempargs = (loopargs_t *)args;
870 unsigned char *buf = tempargs->buf;
871 EVP_CIPHER_CTX *ctx = tempargs->ctx;
874 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
877 for (count = 0; COND(nb_iter); count++)
878 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
880 for (count = 0; COND(nb_iter); count++)
881 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
883 EVP_DecryptFinal_ex(ctx, buf, &outl);
885 EVP_EncryptFinal_ex(ctx, buf, &outl);
889 static const EVP_MD *evp_md = NULL;
890 static int EVP_Digest_loop(void *args)
892 loopargs_t *tempargs = (loopargs_t *)args;
893 unsigned char *buf = tempargs->buf;
894 unsigned char md[EVP_MAX_MD_SIZE];
897 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
900 for (count = 0; COND(nb_iter); count++) {
901 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
907 #ifndef OPENSSL_NO_RSA
908 static long rsa_c[RSA_NUM][2];
910 static int RSA_sign_loop(void *args)
912 loopargs_t *tempargs = (loopargs_t *)args;
913 unsigned char *buf = tempargs->buf;
914 unsigned char *buf2 = tempargs->buf2;
915 unsigned int *rsa_num = tempargs->siglen;
916 RSA **rsa_key = tempargs->rsa_key;
918 for (count = 0; COND(rsa_c[testnum][0]); count++) {
919 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
921 BIO_printf(bio_err, "RSA sign failure\n");
922 ERR_print_errors(bio_err);
930 static int RSA_verify_loop(void *args)
932 loopargs_t *tempargs = (loopargs_t *)args;
933 unsigned char *buf = tempargs->buf;
934 unsigned char *buf2 = tempargs->buf2;
935 unsigned int rsa_num = *(tempargs->siglen);
936 RSA **rsa_key = tempargs->rsa_key;
938 for (count = 0; COND(rsa_c[testnum][1]); count++) {
939 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
941 BIO_printf(bio_err, "RSA verify failure\n");
942 ERR_print_errors(bio_err);
951 #ifndef OPENSSL_NO_DSA
952 static long dsa_c[DSA_NUM][2];
953 static int DSA_sign_loop(void *args)
955 loopargs_t *tempargs = (loopargs_t *)args;
956 unsigned char *buf = tempargs->buf;
957 unsigned char *buf2 = tempargs->buf2;
958 DSA **dsa_key = tempargs->dsa_key;
959 unsigned int *siglen = tempargs->siglen;
961 for (count = 0; COND(dsa_c[testnum][0]); count++) {
962 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
964 BIO_printf(bio_err, "DSA sign failure\n");
965 ERR_print_errors(bio_err);
973 static int DSA_verify_loop(void *args)
975 loopargs_t *tempargs = (loopargs_t *)args;
976 unsigned char *buf = tempargs->buf;
977 unsigned char *buf2 = tempargs->buf2;
978 DSA **dsa_key = tempargs->dsa_key;
979 unsigned int siglen = *(tempargs->siglen);
981 for (count = 0; COND(dsa_c[testnum][1]); count++) {
982 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
984 BIO_printf(bio_err, "DSA verify failure\n");
985 ERR_print_errors(bio_err);
994 #ifndef OPENSSL_NO_EC
995 static long ecdsa_c[EC_NUM][2];
996 static int ECDSA_sign_loop(void *args)
998 loopargs_t *tempargs = (loopargs_t *)args;
999 unsigned char *buf = tempargs->buf;
1000 EC_KEY **ecdsa = tempargs->ecdsa;
1001 unsigned char *ecdsasig = tempargs->buf2;
1002 unsigned int *ecdsasiglen = tempargs->siglen;
1004 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1005 ret = ECDSA_sign(0, buf, 20,
1006 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1008 BIO_printf(bio_err, "ECDSA sign failure\n");
1009 ERR_print_errors(bio_err);
1017 static int ECDSA_verify_loop(void *args)
1019 loopargs_t *tempargs = (loopargs_t *)args;
1020 unsigned char *buf = tempargs->buf;
1021 EC_KEY **ecdsa = tempargs->ecdsa;
1022 unsigned char *ecdsasig = tempargs->buf2;
1023 unsigned int ecdsasiglen = *(tempargs->siglen);
1025 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1026 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1029 BIO_printf(bio_err, "ECDSA verify failure\n");
1030 ERR_print_errors(bio_err);
1038 /* ******************************************************************** */
1039 static long ecdh_c[EC_NUM][1];
1041 static int ECDH_compute_key_loop(void *args)
1043 loopargs_t *tempargs = (loopargs_t *)args;
1044 EC_KEY **ecdh_a = tempargs->ecdh_a;
1045 EC_KEY **ecdh_b = tempargs->ecdh_b;
1046 unsigned char *secret_a = tempargs->secret_a;
1047 int count, outlen = tempargs->outlen;
1048 kdf_fn kdf = tempargs->kdf;
1050 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1051 ECDH_compute_key(secret_a, outlen,
1052 EC_KEY_get0_public_key(ecdh_b[testnum]),
1053 ecdh_a[testnum], kdf);
1058 static const int KDF1_SHA1_len = 20;
1059 static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
1062 if (*outlen < SHA_DIGEST_LENGTH)
1064 *outlen = SHA_DIGEST_LENGTH;
1065 return SHA1(in, inlen, out);
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, pr_header = 0;
1227 int doit[ALGOR_NUM] = { 0 };
1228 int ret = 1, i, k, misalign = 0;
1234 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1235 || !defined(OPENSSL_NO_EC)
1239 /* What follows are the buffers and key material. */
1240 #ifndef OPENSSL_NO_RC5
1243 #ifndef OPENSSL_NO_RC2
1246 #ifndef OPENSSL_NO_IDEA
1247 IDEA_KEY_SCHEDULE idea_ks;
1249 #ifndef OPENSSL_NO_SEED
1250 SEED_KEY_SCHEDULE seed_ks;
1252 #ifndef OPENSSL_NO_BF
1255 #ifndef OPENSSL_NO_CAST
1258 static const unsigned char key16[16] = {
1259 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1260 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1262 static const unsigned char key24[24] = {
1263 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1264 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1265 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1267 static const unsigned char key32[32] = {
1268 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1269 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1270 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1271 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1273 #ifndef OPENSSL_NO_CAMELLIA
1274 static const unsigned char ckey24[24] = {
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
1279 static const unsigned char ckey32[32] = {
1280 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1281 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1282 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1283 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1285 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1287 #ifndef OPENSSL_NO_DES
1288 static DES_cblock key = {
1289 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1291 static DES_cblock key2 = {
1292 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1294 static DES_cblock key3 = {
1295 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1298 #ifndef OPENSSL_NO_RSA
1299 static const unsigned int rsa_bits[RSA_NUM] = {
1300 512, 1024, 2048, 3072, 4096, 7680, 15360
1302 static const unsigned char *rsa_data[RSA_NUM] = {
1303 test512, test1024, test2048, test3072, test4096, test7680, test15360
1305 static const int rsa_data_length[RSA_NUM] = {
1306 sizeof(test512), sizeof(test1024),
1307 sizeof(test2048), sizeof(test3072),
1308 sizeof(test4096), sizeof(test7680),
1311 int rsa_doit[RSA_NUM] = { 0 };
1313 #ifndef OPENSSL_NO_DSA
1314 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1315 int dsa_doit[DSA_NUM] = { 0 };
1317 #ifndef OPENSSL_NO_EC
1319 * We only test over the following curves as they are representative, To
1320 * add tests over more curves, simply add the curve NID and curve name to
1321 * the following arrays and increase the EC_NUM value accordingly.
1323 static const unsigned int test_curves[EC_NUM] = {
1325 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1326 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1328 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1329 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1330 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1335 static const char *test_curves_names[EC_NUM] = {
1337 "secp160r1", "nistp192", "nistp224",
1338 "nistp256", "nistp384", "nistp521",
1340 "nistk163", "nistk233", "nistk283",
1341 "nistk409", "nistk571", "nistb163",
1342 "nistb233", "nistb283", "nistb409",
1347 static const int test_curves_bits[EC_NUM] = {
1353 571, 253 /* X25519 */
1356 int ecdsa_doit[EC_NUM] = { 0 };
1357 int ecdh_doit[EC_NUM] = { 0 };
1358 #endif /* ndef OPENSSL_NO_EC */
1360 prog = opt_init(argc, argv, speed_options);
1361 while ((o = opt_next()) != OPT_EOF) {
1366 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1369 opt_help(speed_options);
1376 evp_cipher = EVP_get_cipherbyname(opt_arg());
1377 if (evp_cipher == NULL)
1378 evp_md = EVP_get_digestbyname(opt_arg());
1379 if (evp_cipher == NULL && evp_md == NULL) {
1381 "%s: %s an unknown cipher or digest\n",
1392 * In a forked execution, an engine might need to be
1393 * initialised by each child process, not by the parent.
1394 * So store the name here and run setup_engine() later on.
1396 #ifndef OPENSSL_NO_ENGINE
1397 engine_id = opt_arg();
1402 multi = atoi(opt_arg());
1406 #ifndef OPENSSL_NO_ASYNC
1407 async_jobs = atoi(opt_arg());
1408 if (!ASYNC_is_capable()) {
1410 "%s: async_jobs specified but async not supported\n",
1417 if (!opt_int(opt_arg(), &misalign))
1419 if (misalign > MISALIGN) {
1421 "%s: Maximum offset is %d\n", prog, MISALIGN);
1433 argc = opt_num_rest();
1436 /* Remaining arguments are algorithms. */
1437 for ( ; *argv; argv++) {
1438 if (found(*argv, doit_choices, &i)) {
1442 #ifndef OPENSSL_NO_DES
1443 if (strcmp(*argv, "des") == 0) {
1444 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1448 if (strcmp(*argv, "sha") == 0) {
1449 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1452 #ifndef OPENSSL_NO_RSA
1454 if (strcmp(*argv, "openssl") == 0) {
1455 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1459 if (strcmp(*argv, "rsa") == 0) {
1460 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1461 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1462 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1463 rsa_doit[R_RSA_15360] = 1;
1466 if (found(*argv, rsa_choices, &i)) {
1471 #ifndef OPENSSL_NO_DSA
1472 if (strcmp(*argv, "dsa") == 0) {
1473 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1474 dsa_doit[R_DSA_2048] = 1;
1477 if (found(*argv, dsa_choices, &i)) {
1482 if (strcmp(*argv, "aes") == 0) {
1483 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1484 doit[D_CBC_256_AES] = 1;
1487 #ifndef OPENSSL_NO_CAMELLIA
1488 if (strcmp(*argv, "camellia") == 0) {
1489 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1490 doit[D_CBC_256_CML] = 1;
1494 #ifndef OPENSSL_NO_EC
1495 if (strcmp(*argv, "ecdsa") == 0) {
1496 for (i = 0; i < EC_NUM; i++)
1500 if (found(*argv, ecdsa_choices, &i)) {
1504 if (strcmp(*argv, "ecdh") == 0) {
1505 for (i = 0; i < EC_NUM; i++)
1509 if (found(*argv, ecdh_choices, &i)) {
1514 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1518 /* Initialize the job pool if async mode is enabled */
1519 if (async_jobs > 0) {
1520 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1522 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1527 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1528 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1529 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1531 for (i = 0; i < loopargs_len; i++) {
1532 if (async_jobs > 0) {
1533 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1534 if (loopargs[i].wait_ctx == NULL) {
1535 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1540 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1541 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1542 /* Align the start of buffers on a 64 byte boundary */
1543 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1544 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1545 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
1546 #ifndef OPENSSL_NO_EC
1547 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1548 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1553 if (multi && do_multi(multi))
1557 /* Initialize the engine after the fork */
1558 (void)setup_engine(engine_id, 0);
1560 /* No parameters; turn on everything. */
1561 if ((argc == 0) && !doit[D_EVP]) {
1562 for (i = 0; i < ALGOR_NUM; i++)
1565 for (i = 0; i < RSA_NUM; i++)
1567 #ifndef OPENSSL_NO_DSA
1568 for (i = 0; i < DSA_NUM; i++)
1571 #ifndef OPENSSL_NO_EC
1572 for (i = 0; i < EC_NUM; i++)
1574 for (i = 0; i < EC_NUM; i++)
1578 for (i = 0; i < ALGOR_NUM; i++)
1582 if (usertime == 0 && !mr)
1584 "You have chosen to measure elapsed time "
1585 "instead of user CPU time.\n");
1587 #ifndef OPENSSL_NO_RSA
1588 for (i = 0; i < loopargs_len; i++) {
1589 for (k = 0; k < RSA_NUM; k++) {
1590 const unsigned char *p;
1593 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1594 if (loopargs[i].rsa_key[k] == NULL) {
1595 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1602 #ifndef OPENSSL_NO_DSA
1603 for (i = 0; i < loopargs_len; i++) {
1604 loopargs[i].dsa_key[0] = get_dsa512();
1605 loopargs[i].dsa_key[1] = get_dsa1024();
1606 loopargs[i].dsa_key[2] = get_dsa2048();
1609 #ifndef OPENSSL_NO_DES
1610 DES_set_key_unchecked(&key, &sch);
1611 DES_set_key_unchecked(&key2, &sch2);
1612 DES_set_key_unchecked(&key3, &sch3);
1614 AES_set_encrypt_key(key16, 128, &aes_ks1);
1615 AES_set_encrypt_key(key24, 192, &aes_ks2);
1616 AES_set_encrypt_key(key32, 256, &aes_ks3);
1617 #ifndef OPENSSL_NO_CAMELLIA
1618 Camellia_set_key(key16, 128, &camellia_ks1);
1619 Camellia_set_key(ckey24, 192, &camellia_ks2);
1620 Camellia_set_key(ckey32, 256, &camellia_ks3);
1622 #ifndef OPENSSL_NO_IDEA
1623 IDEA_set_encrypt_key(key16, &idea_ks);
1625 #ifndef OPENSSL_NO_SEED
1626 SEED_set_key(key16, &seed_ks);
1628 #ifndef OPENSSL_NO_RC4
1629 RC4_set_key(&rc4_ks, 16, key16);
1631 #ifndef OPENSSL_NO_RC2
1632 RC2_set_key(&rc2_ks, 16, key16, 128);
1634 #ifndef OPENSSL_NO_RC5
1635 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1637 #ifndef OPENSSL_NO_BF
1638 BF_set_key(&bf_ks, 16, key16);
1640 #ifndef OPENSSL_NO_CAST
1641 CAST_set_key(&cast_ks, 16, key16);
1644 # ifndef OPENSSL_NO_DES
1645 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1651 for (it = count; it; it--)
1652 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1653 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1657 c[D_MD2][0] = count / 10;
1658 c[D_MDC2][0] = count / 10;
1659 c[D_MD4][0] = count;
1660 c[D_MD5][0] = count;
1661 c[D_HMAC][0] = count;
1662 c[D_SHA1][0] = count;
1663 c[D_RMD160][0] = count;
1664 c[D_RC4][0] = count * 5;
1665 c[D_CBC_DES][0] = count;
1666 c[D_EDE3_DES][0] = count / 3;
1667 c[D_CBC_IDEA][0] = count;
1668 c[D_CBC_SEED][0] = count;
1669 c[D_CBC_RC2][0] = count;
1670 c[D_CBC_RC5][0] = count;
1671 c[D_CBC_BF][0] = count;
1672 c[D_CBC_CAST][0] = count;
1673 c[D_CBC_128_AES][0] = count;
1674 c[D_CBC_192_AES][0] = count;
1675 c[D_CBC_256_AES][0] = count;
1676 c[D_CBC_128_CML][0] = count;
1677 c[D_CBC_192_CML][0] = count;
1678 c[D_CBC_256_CML][0] = count;
1679 c[D_SHA256][0] = count;
1680 c[D_SHA512][0] = count;
1681 c[D_WHIRLPOOL][0] = count;
1682 c[D_IGE_128_AES][0] = count;
1683 c[D_IGE_192_AES][0] = count;
1684 c[D_IGE_256_AES][0] = count;
1685 c[D_GHASH][0] = count;
1687 for (i = 1; i < SIZE_NUM; i++) {
1690 l0 = (long)lengths[0];
1691 l1 = (long)lengths[i];
1693 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1694 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1695 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1696 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1697 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1698 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1699 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1700 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1701 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1702 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1703 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1705 l0 = (long)lengths[i - 1];
1707 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1708 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1709 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1710 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1711 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1712 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1713 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1714 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1715 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1716 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1717 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1718 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1719 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1720 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1721 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1722 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1723 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1724 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1727 # ifndef OPENSSL_NO_RSA
1728 rsa_c[R_RSA_512][0] = count / 2000;
1729 rsa_c[R_RSA_512][1] = count / 400;
1730 for (i = 1; i < RSA_NUM; i++) {
1731 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1732 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1733 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1736 if (rsa_c[i][0] == 0) {
1744 # ifndef OPENSSL_NO_DSA
1745 dsa_c[R_DSA_512][0] = count / 1000;
1746 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1747 for (i = 1; i < DSA_NUM; i++) {
1748 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1749 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1750 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1753 if (dsa_c[i] == 0) { /* Always false */
1761 # ifndef OPENSSL_NO_EC
1762 ecdsa_c[R_EC_P160][0] = count / 1000;
1763 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1764 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1765 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1766 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1767 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1770 if (ecdsa_c[i] == 0) { /* Always false */
1776 ecdsa_c[R_EC_K163][0] = count / 1000;
1777 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1778 for (i = R_EC_K233; i <= R_EC_K571; 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) { /* Always false */
1790 ecdsa_c[R_EC_B163][0] = count / 1000;
1791 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1792 for (i = R_EC_B233; i <= R_EC_B571; 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) { /* Always false */
1805 ecdh_c[R_EC_P160][0] = count / 1000;
1806 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1807 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1808 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1811 if (ecdh_c[i] == 0) { /* always false */
1816 ecdh_c[R_EC_K163][0] = count / 1000;
1817 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1818 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1819 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1822 if (ecdh_c[i] == 0) { /* always false */
1827 ecdh_c[R_EC_B163][0] = count / 1000;
1828 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1829 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1830 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1833 if (ecdh_c[i] == 0) { /* always false */
1841 /* not worth fixing */
1842 # error "You cannot disable DES on systems without SIGALRM."
1843 # endif /* OPENSSL_NO_DES */
1846 signal(SIGALRM, sig_done);
1848 #endif /* SIGALRM */
1850 #ifndef OPENSSL_NO_MD2
1852 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1853 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1855 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1857 print_result(D_MD2, testnum, count, d);
1861 #ifndef OPENSSL_NO_MDC2
1863 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1864 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1866 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1868 print_result(D_MDC2, testnum, count, d);
1873 #ifndef OPENSSL_NO_MD4
1875 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1876 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1878 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1880 print_result(D_MD4, testnum, count, d);
1885 #ifndef OPENSSL_NO_MD5
1887 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1888 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1890 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1892 print_result(D_MD5, testnum, count, d);
1897 #ifndef OPENSSL_NO_MD5
1899 char hmac_key[] = "This is a key...";
1900 int len = strlen(hmac_key);
1902 for (i = 0; i < loopargs_len; i++) {
1903 loopargs[i].hctx = HMAC_CTX_new();
1904 if (loopargs[i].hctx == NULL) {
1905 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1909 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1911 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1912 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1914 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1916 print_result(D_HMAC, testnum, count, d);
1918 for (i = 0; i < loopargs_len; i++) {
1919 HMAC_CTX_free(loopargs[i].hctx);
1924 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1925 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1927 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1929 print_result(D_SHA1, testnum, count, d);
1932 if (doit[D_SHA256]) {
1933 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1934 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1936 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1938 print_result(D_SHA256, testnum, count, d);
1941 if (doit[D_SHA512]) {
1942 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1943 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1945 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1947 print_result(D_SHA512, testnum, count, d);
1951 #ifndef OPENSSL_NO_WHIRLPOOL
1952 if (doit[D_WHIRLPOOL]) {
1953 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1954 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1956 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1958 print_result(D_WHIRLPOOL, testnum, count, d);
1963 #ifndef OPENSSL_NO_RMD160
1964 if (doit[D_RMD160]) {
1965 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1966 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1968 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1970 print_result(D_RMD160, testnum, count, d);
1974 #ifndef OPENSSL_NO_RC4
1976 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1977 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1979 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1981 print_result(D_RC4, testnum, count, d);
1985 #ifndef OPENSSL_NO_DES
1986 if (doit[D_CBC_DES]) {
1987 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1988 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
1990 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1992 print_result(D_CBC_DES, testnum, count, d);
1996 if (doit[D_EDE3_DES]) {
1997 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1998 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2000 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2002 print_result(D_EDE3_DES, testnum, count, d);
2007 if (doit[D_CBC_128_AES]) {
2008 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2009 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2012 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2014 print_result(D_CBC_128_AES, testnum, count, d);
2017 if (doit[D_CBC_192_AES]) {
2018 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2019 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2022 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2024 print_result(D_CBC_192_AES, testnum, count, d);
2027 if (doit[D_CBC_256_AES]) {
2028 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2029 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2032 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2034 print_result(D_CBC_256_AES, testnum, count, d);
2038 if (doit[D_IGE_128_AES]) {
2039 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2040 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2043 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2045 print_result(D_IGE_128_AES, testnum, count, d);
2048 if (doit[D_IGE_192_AES]) {
2049 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2050 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2053 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2055 print_result(D_IGE_192_AES, testnum, count, d);
2058 if (doit[D_IGE_256_AES]) {
2059 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2060 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2063 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2065 print_result(D_IGE_256_AES, testnum, count, d);
2068 if (doit[D_GHASH]) {
2069 for (i = 0; i < loopargs_len; i++) {
2070 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2071 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2074 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2075 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2077 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2079 print_result(D_GHASH, testnum, count, d);
2081 for (i = 0; i < loopargs_len; i++)
2082 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2085 #ifndef OPENSSL_NO_CAMELLIA
2086 if (doit[D_CBC_128_CML]) {
2087 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2088 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2090 if (async_jobs > 0) {
2091 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2095 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2096 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2097 (size_t)lengths[testnum], &camellia_ks1,
2098 iv, CAMELLIA_ENCRYPT);
2100 print_result(D_CBC_128_CML, testnum, count, d);
2103 if (doit[D_CBC_192_CML]) {
2104 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2105 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2107 if (async_jobs > 0) {
2108 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2112 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2113 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2114 (size_t)lengths[testnum], &camellia_ks2,
2115 iv, CAMELLIA_ENCRYPT);
2117 print_result(D_CBC_192_CML, testnum, count, d);
2120 if (doit[D_CBC_256_CML]) {
2121 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2122 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2124 if (async_jobs > 0) {
2125 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2129 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2130 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2131 (size_t)lengths[testnum], &camellia_ks3,
2132 iv, CAMELLIA_ENCRYPT);
2134 print_result(D_CBC_256_CML, testnum, count, d);
2138 #ifndef OPENSSL_NO_IDEA
2139 if (doit[D_CBC_IDEA]) {
2140 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2141 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2142 if (async_jobs > 0) {
2143 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2147 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2148 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2149 (size_t)lengths[testnum], &idea_ks,
2152 print_result(D_CBC_IDEA, testnum, count, d);
2156 #ifndef OPENSSL_NO_SEED
2157 if (doit[D_CBC_SEED]) {
2158 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2159 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2160 if (async_jobs > 0) {
2161 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2165 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2166 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2167 (size_t)lengths[testnum], &seed_ks, iv, 1);
2169 print_result(D_CBC_SEED, testnum, count, d);
2173 #ifndef OPENSSL_NO_RC2
2174 if (doit[D_CBC_RC2]) {
2175 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2176 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2177 if (async_jobs > 0) {
2178 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2182 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2183 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2184 (size_t)lengths[testnum], &rc2_ks,
2187 print_result(D_CBC_RC2, testnum, count, d);
2191 #ifndef OPENSSL_NO_RC5
2192 if (doit[D_CBC_RC5]) {
2193 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2194 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2195 if (async_jobs > 0) {
2196 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2200 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2201 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2202 (size_t)lengths[testnum], &rc5_ks,
2205 print_result(D_CBC_RC5, testnum, count, d);
2209 #ifndef OPENSSL_NO_BF
2210 if (doit[D_CBC_BF]) {
2211 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2212 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2213 if (async_jobs > 0) {
2214 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2218 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2219 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2220 (size_t)lengths[testnum], &bf_ks,
2223 print_result(D_CBC_BF, testnum, count, d);
2227 #ifndef OPENSSL_NO_CAST
2228 if (doit[D_CBC_CAST]) {
2229 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2230 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2231 if (async_jobs > 0) {
2232 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2236 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2237 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2238 (size_t)lengths[testnum], &cast_ks,
2241 print_result(D_CBC_CAST, testnum, count, d);
2247 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2248 if (multiblock && evp_cipher) {
2250 (EVP_CIPHER_flags(evp_cipher) &
2251 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2252 BIO_printf(bio_err, "%s is not multi-block capable\n",
2253 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2256 if (async_jobs > 0) {
2257 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2260 multiblock_speed(evp_cipher);
2265 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2268 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2270 * -O3 -fschedule-insns messes up an optimization here!
2271 * names[D_EVP] somehow becomes NULL
2273 print_message(names[D_EVP], save_count, lengths[testnum]);
2275 for (k = 0; k < loopargs_len; k++) {
2276 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2278 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2280 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2281 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2285 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2287 for (k = 0; k < loopargs_len; k++) {
2288 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2292 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2293 print_message(names[D_EVP], save_count, lengths[testnum]);
2295 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2298 print_result(D_EVP, testnum, count, d);
2302 for (i = 0; i < loopargs_len; i++)
2303 RAND_bytes(loopargs[i].buf, 36);
2305 #ifndef OPENSSL_NO_RSA
2306 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2308 if (!rsa_doit[testnum])
2310 for (i = 0; i < loopargs_len; i++) {
2311 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2312 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2318 "RSA sign failure. No RSA sign will be done.\n");
2319 ERR_print_errors(bio_err);
2322 pkey_print_message("private", "rsa",
2323 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2324 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2326 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2329 mr ? "+R1:%ld:%d:%.2f\n"
2330 : "%ld %d bit private RSA's in %.2fs\n",
2331 count, rsa_bits[testnum], d);
2332 rsa_results[testnum][0] = d / (double)count;
2336 for (i = 0; i < loopargs_len; i++) {
2337 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2338 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
2344 "RSA verify failure. No RSA verify will be done.\n");
2345 ERR_print_errors(bio_err);
2346 rsa_doit[testnum] = 0;
2348 pkey_print_message("public", "rsa",
2349 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2351 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2354 mr ? "+R2:%ld:%d:%.2f\n"
2355 : "%ld %d bit public RSA's in %.2fs\n",
2356 count, rsa_bits[testnum], d);
2357 rsa_results[testnum][1] = d / (double)count;
2360 if (rsa_count <= 1) {
2361 /* if longer than 10s, don't do any more */
2362 for (testnum++; testnum < RSA_NUM; testnum++)
2363 rsa_doit[testnum] = 0;
2368 for (i = 0; i < loopargs_len; i++)
2369 RAND_bytes(loopargs[i].buf, 36);
2371 #ifndef OPENSSL_NO_DSA
2372 if (RAND_status() != 1) {
2373 RAND_seed(rnd_seed, sizeof rnd_seed);
2375 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2377 if (!dsa_doit[testnum])
2380 /* DSA_generate_key(dsa_key[testnum]); */
2381 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2382 for (i = 0; i < loopargs_len; i++) {
2383 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2384 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2390 "DSA sign failure. No DSA sign will be done.\n");
2391 ERR_print_errors(bio_err);
2394 pkey_print_message("sign", "dsa",
2395 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2397 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2400 mr ? "+R3:%ld:%d:%.2f\n"
2401 : "%ld %d bit DSA signs in %.2fs\n",
2402 count, dsa_bits[testnum], d);
2403 dsa_results[testnum][0] = d / (double)count;
2407 for (i = 0; i < loopargs_len; i++) {
2408 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2409 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
2415 "DSA verify failure. No DSA verify will be done.\n");
2416 ERR_print_errors(bio_err);
2417 dsa_doit[testnum] = 0;
2419 pkey_print_message("verify", "dsa",
2420 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2422 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2425 mr ? "+R4:%ld:%d:%.2f\n"
2426 : "%ld %d bit DSA verify in %.2fs\n",
2427 count, dsa_bits[testnum], d);
2428 dsa_results[testnum][1] = d / (double)count;
2431 if (rsa_count <= 1) {
2432 /* if longer than 10s, don't do any more */
2433 for (testnum++; testnum < DSA_NUM; testnum++)
2434 dsa_doit[testnum] = 0;
2439 #ifndef OPENSSL_NO_EC
2440 if (RAND_status() != 1) {
2441 RAND_seed(rnd_seed, sizeof rnd_seed);
2443 for (testnum = 0; testnum < EC_NUM; testnum++) {
2446 if (!ecdsa_doit[testnum])
2447 continue; /* Ignore Curve */
2448 for (i = 0; i < loopargs_len; i++) {
2449 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2450 if (loopargs[i].ecdsa[testnum] == NULL) {
2456 BIO_printf(bio_err, "ECDSA failure.\n");
2457 ERR_print_errors(bio_err);
2460 for (i = 0; i < loopargs_len; i++) {
2461 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2462 /* Perform ECDSA signature test */
2463 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2464 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2465 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2471 "ECDSA sign failure. No ECDSA sign will be done.\n");
2472 ERR_print_errors(bio_err);
2475 pkey_print_message("sign", "ecdsa",
2476 ecdsa_c[testnum][0],
2477 test_curves_bits[testnum], ECDSA_SECONDS);
2479 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2483 mr ? "+R5:%ld:%d:%.2f\n" :
2484 "%ld %d bit ECDSA signs in %.2fs \n",
2485 count, test_curves_bits[testnum], d);
2486 ecdsa_results[testnum][0] = d / (double)count;
2490 /* Perform ECDSA verification test */
2491 for (i = 0; i < loopargs_len; i++) {
2492 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2493 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
2499 "ECDSA verify failure. No ECDSA verify will be done.\n");
2500 ERR_print_errors(bio_err);
2501 ecdsa_doit[testnum] = 0;
2503 pkey_print_message("verify", "ecdsa",
2504 ecdsa_c[testnum][1],
2505 test_curves_bits[testnum], ECDSA_SECONDS);
2507 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2510 mr ? "+R6:%ld:%d:%.2f\n"
2511 : "%ld %d bit ECDSA verify in %.2fs\n",
2512 count, test_curves_bits[testnum], d);
2513 ecdsa_results[testnum][1] = d / (double)count;
2516 if (rsa_count <= 1) {
2517 /* if longer than 10s, don't do any more */
2518 for (testnum++; testnum < EC_NUM; testnum++)
2519 ecdsa_doit[testnum] = 0;
2524 if (RAND_status() != 1) {
2525 RAND_seed(rnd_seed, sizeof rnd_seed);
2527 for (testnum = 0; testnum < EC_NUM; testnum++) {
2528 int ecdh_checks = 1;
2530 if (!ecdh_doit[testnum])
2532 for (i = 0; i < loopargs_len; i++) {
2533 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2534 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2535 if (loopargs[i].ecdh_a[testnum] == NULL ||
2536 loopargs[i].ecdh_b[testnum] == NULL) {
2541 if (ecdh_checks == 0) {
2542 BIO_printf(bio_err, "ECDH failure.\n");
2543 ERR_print_errors(bio_err);
2546 for (i = 0; i < loopargs_len; i++) {
2547 /* generate two ECDH key pairs */
2548 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2549 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2550 BIO_printf(bio_err, "ECDH key generation failure.\n");
2551 ERR_print_errors(bio_err);
2555 int secret_size_a, secret_size_b;
2557 * If field size is not more than 24 octets, then use SHA-1
2558 * hash of result; otherwise, use result (see section 4.8 of
2559 * draft-ietf-tls-ecc-03.txt).
2561 int field_size = EC_GROUP_get_degree(
2562 EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2564 if (field_size <= 24 * 8) { /* 192 bits */
2565 loopargs[i].outlen = KDF1_SHA1_len;
2566 loopargs[i].kdf = KDF1_SHA1;
2568 loopargs[i].outlen = (field_size + 7) / 8;
2569 loopargs[i].kdf = NULL;
2572 ECDH_compute_key(loopargs[i].secret_a, loopargs[i].outlen,
2573 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2574 loopargs[i].ecdh_a[testnum], loopargs[i].kdf);
2576 ECDH_compute_key(loopargs[i].secret_b, loopargs[i].outlen,
2577 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2578 loopargs[i].ecdh_b[testnum], loopargs[i].kdf);
2579 if (secret_size_a != secret_size_b)
2584 for (k = 0; k < secret_size_a && ecdh_checks == 1; k++) {
2585 if (loopargs[i].secret_a[k] != loopargs[i].secret_b[k])
2589 if (ecdh_checks == 0) {
2590 BIO_printf(bio_err, "ECDH computations don't match.\n");
2591 ERR_print_errors(bio_err);
2597 if (ecdh_checks != 0) {
2598 pkey_print_message("", "ecdh",
2600 test_curves_bits[testnum], ECDH_SECONDS);
2602 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2605 mr ? "+R7:%ld:%d:%.2f\n" :
2606 "%ld %d-bit ECDH ops in %.2fs\n", count,
2607 test_curves_bits[testnum], d);
2608 ecdh_results[testnum][0] = d / (double)count;
2613 if (rsa_count <= 1) {
2614 /* if longer than 10s, don't do any more */
2615 for (testnum++; testnum < EC_NUM; testnum++)
2616 ecdh_doit[testnum] = 0;
2624 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2625 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2627 printf("%s ", BN_options());
2628 #ifndef OPENSSL_NO_MD2
2629 printf("%s ", MD2_options());
2631 #ifndef OPENSSL_NO_RC4
2632 printf("%s ", RC4_options());
2634 #ifndef OPENSSL_NO_DES
2635 printf("%s ", DES_options());
2637 printf("%s ", AES_options());
2638 #ifndef OPENSSL_NO_IDEA
2639 printf("%s ", IDEA_options());
2641 #ifndef OPENSSL_NO_BF
2642 printf("%s ", BF_options());
2644 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2652 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2655 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2656 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2660 for (k = 0; k < ALGOR_NUM; k++) {
2664 printf("+F:%d:%s", k, names[k]);
2666 printf("%-13s", names[k]);
2667 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2668 if (results[k][testnum] > 10000 && !mr)
2669 printf(" %11.2fk", results[k][testnum] / 1e3);
2671 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2675 #ifndef OPENSSL_NO_RSA
2677 for (k = 0; k < RSA_NUM; k++) {
2680 if (testnum && !mr) {
2681 printf("%18ssign verify sign/s verify/s\n", " ");
2685 printf("+F2:%u:%u:%f:%f\n",
2686 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2688 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2689 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2690 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2693 #ifndef OPENSSL_NO_DSA
2695 for (k = 0; k < DSA_NUM; k++) {
2698 if (testnum && !mr) {
2699 printf("%18ssign verify sign/s verify/s\n", " ");
2703 printf("+F3:%u:%u:%f:%f\n",
2704 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2706 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2707 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2708 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2711 #ifndef OPENSSL_NO_EC
2713 for (k = 0; k < EC_NUM; k++) {
2716 if (testnum && !mr) {
2717 printf("%30ssign verify sign/s verify/s\n", " ");
2722 printf("+F4:%u:%u:%f:%f\n",
2723 k, test_curves_bits[k],
2724 ecdsa_results[k][0], ecdsa_results[k][1]);
2726 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2727 test_curves_bits[k],
2728 test_curves_names[k],
2729 ecdsa_results[k][0], ecdsa_results[k][1],
2730 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2734 for (k = 0; k < EC_NUM; k++) {
2737 if (testnum && !mr) {
2738 printf("%30sop op/s\n", " ");
2742 printf("+F5:%u:%u:%f:%f\n",
2743 k, test_curves_bits[k],
2744 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2747 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2748 test_curves_bits[k],
2749 test_curves_names[k],
2750 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2757 ERR_print_errors(bio_err);
2758 for (i = 0; i < loopargs_len; i++) {
2759 OPENSSL_free(loopargs[i].buf_malloc);
2760 OPENSSL_free(loopargs[i].buf2_malloc);
2761 OPENSSL_free(loopargs[i].siglen);
2763 #ifndef OPENSSL_NO_RSA
2764 for (k = 0; k < RSA_NUM; k++)
2765 RSA_free(loopargs[i].rsa_key[k]);
2767 #ifndef OPENSSL_NO_DSA
2768 for (k = 0; k < DSA_NUM; k++)
2769 DSA_free(loopargs[i].dsa_key[k]);
2771 #ifndef OPENSSL_NO_EC
2772 for (k = 0; k < EC_NUM; k++) {
2773 EC_KEY_free(loopargs[i].ecdsa[k]);
2774 EC_KEY_free(loopargs[i].ecdh_a[k]);
2775 EC_KEY_free(loopargs[i].ecdh_b[k]);
2777 OPENSSL_free(loopargs[i].secret_a);
2778 OPENSSL_free(loopargs[i].secret_b);
2782 if (async_jobs > 0) {
2783 for (i = 0; i < loopargs_len; i++)
2784 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2788 ASYNC_cleanup_thread();
2790 OPENSSL_free(loopargs);
2794 static void print_message(const char *s, long num, int length)
2798 mr ? "+DT:%s:%d:%d\n"
2799 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2800 (void)BIO_flush(bio_err);
2804 mr ? "+DN:%s:%ld:%d\n"
2805 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2806 (void)BIO_flush(bio_err);
2810 static void pkey_print_message(const char *str, const char *str2, long num,
2815 mr ? "+DTP:%d:%s:%s:%d\n"
2816 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2817 (void)BIO_flush(bio_err);
2821 mr ? "+DNP:%ld:%d:%s:%s\n"
2822 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2823 (void)BIO_flush(bio_err);
2827 static void print_result(int alg, int run_no, int count, double time_used)
2830 BIO_puts(bio_err, "EVP error!\n");
2834 mr ? "+R:%d:%s:%f\n"
2835 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2836 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2840 static char *sstrsep(char **string, const char *delim)
2843 char *token = *string;
2848 memset(isdelim, 0, sizeof isdelim);
2852 isdelim[(unsigned char)(*delim)] = 1;
2856 while (!isdelim[(unsigned char)(**string)]) {
2868 static int do_multi(int multi)
2873 static char sep[] = ":";
2875 fds = malloc(sizeof(*fds) * multi);
2876 for (n = 0; n < multi; ++n) {
2877 if (pipe(fd) == -1) {
2878 BIO_printf(bio_err, "pipe failure\n");
2882 (void)BIO_flush(bio_err);
2889 if (dup(fd[1]) == -1) {
2890 BIO_printf(bio_err, "dup failed\n");
2899 printf("Forked child %d\n", n);
2902 /* for now, assume the pipe is long enough to take all the output */
2903 for (n = 0; n < multi; ++n) {
2908 f = fdopen(fds[n], "r");
2909 while (fgets(buf, sizeof buf, f)) {
2910 p = strchr(buf, '\n');
2913 if (buf[0] != '+') {
2914 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2918 printf("Got: %s from %d\n", buf, n);
2919 if (strncmp(buf, "+F:", 3) == 0) {
2924 alg = atoi(sstrsep(&p, sep));
2926 for (j = 0; j < SIZE_NUM; ++j)
2927 results[alg][j] += atof(sstrsep(&p, sep));
2928 } else if (strncmp(buf, "+F2:", 4) == 0) {
2933 k = atoi(sstrsep(&p, sep));
2936 d = atof(sstrsep(&p, sep));
2938 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2940 rsa_results[k][0] = d;
2942 d = atof(sstrsep(&p, sep));
2944 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2946 rsa_results[k][1] = d;
2948 # ifndef OPENSSL_NO_DSA
2949 else if (strncmp(buf, "+F3:", 4) == 0) {
2954 k = atoi(sstrsep(&p, sep));
2957 d = atof(sstrsep(&p, sep));
2959 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2961 dsa_results[k][0] = d;
2963 d = atof(sstrsep(&p, sep));
2965 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2967 dsa_results[k][1] = d;
2970 # ifndef OPENSSL_NO_EC
2971 else if (strncmp(buf, "+F4:", 4) == 0) {
2976 k = atoi(sstrsep(&p, sep));
2979 d = atof(sstrsep(&p, sep));
2981 ecdsa_results[k][0] =
2982 1 / (1 / ecdsa_results[k][0] + 1 / d);
2984 ecdsa_results[k][0] = d;
2986 d = atof(sstrsep(&p, sep));
2988 ecdsa_results[k][1] =
2989 1 / (1 / ecdsa_results[k][1] + 1 / d);
2991 ecdsa_results[k][1] = d;
2995 # ifndef OPENSSL_NO_EC
2996 else if (strncmp(buf, "+F5:", 4) == 0) {
3001 k = atoi(sstrsep(&p, sep));
3004 d = atof(sstrsep(&p, sep));
3006 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3008 ecdh_results[k][0] = d;
3013 else if (strncmp(buf, "+H:", 3) == 0) {
3016 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3026 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3028 static int mblengths[] =
3029 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3030 int j, count, num = OSSL_NELEM(mblengths);
3031 const char *alg_name;
3032 unsigned char *inp, *out, no_key[32], no_iv[16];
3033 EVP_CIPHER_CTX *ctx;
3036 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3037 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3038 ctx = EVP_CIPHER_CTX_new();
3039 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3040 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3042 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3044 for (j = 0; j < num; j++) {
3045 print_message(alg_name, 0, mblengths[j]);
3047 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3048 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3049 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3050 size_t len = mblengths[j];
3053 memset(aad, 0, 8); /* avoid uninitialized values */
3054 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3055 aad[9] = 3; /* version */
3057 aad[11] = 0; /* length */
3059 mb_param.out = NULL;
3062 mb_param.interleave = 8;
3064 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3065 sizeof(mb_param), &mb_param);
3071 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3072 sizeof(mb_param), &mb_param);
3076 RAND_bytes(out, 16);
3080 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3081 EVP_AEAD_TLS1_AAD_LEN, aad);
3082 EVP_Cipher(ctx, out, inp, len + pad);
3086 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3087 : "%d %s's in %.2fs\n", count, "evp", d);
3088 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3092 fprintf(stdout, "+H");
3093 for (j = 0; j < num; j++)
3094 fprintf(stdout, ":%d", mblengths[j]);
3095 fprintf(stdout, "\n");
3096 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3097 for (j = 0; j < num; j++)
3098 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3099 fprintf(stdout, "\n");
3102 "The 'numbers' are in 1000s of bytes per second processed.\n");
3103 fprintf(stdout, "type ");
3104 for (j = 0; j < num; j++)
3105 fprintf(stdout, "%7d bytes", mblengths[j]);
3106 fprintf(stdout, "\n");
3107 fprintf(stdout, "%-24s", alg_name);
3109 for (j = 0; j < num; j++) {
3110 if (results[D_EVP][j] > 10000)
3111 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3113 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3115 fprintf(stdout, "\n");
3120 EVP_CIPHER_CTX_free(ctx);