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 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
167 unsigned char *secret_a;
168 unsigned char *secret_b;
169 size_t outlen[EC_NUM];
174 GCM128_CONTEXT *gcm_ctx;
177 #ifndef OPENSSL_NO_MD2
178 static int EVP_Digest_MD2_loop(void *args);
181 #ifndef OPENSSL_NO_MDC2
182 static int EVP_Digest_MDC2_loop(void *args);
184 #ifndef OPENSSL_NO_MD4
185 static int EVP_Digest_MD4_loop(void *args);
187 #ifndef OPENSSL_NO_MD5
188 static int MD5_loop(void *args);
189 static int HMAC_loop(void *args);
191 static int SHA1_loop(void *args);
192 static int SHA256_loop(void *args);
193 static int SHA512_loop(void *args);
194 #ifndef OPENSSL_NO_WHIRLPOOL
195 static int WHIRLPOOL_loop(void *args);
197 #ifndef OPENSSL_NO_RMD160
198 static int EVP_Digest_RMD160_loop(void *args);
200 #ifndef OPENSSL_NO_RC4
201 static int RC4_loop(void *args);
203 #ifndef OPENSSL_NO_DES
204 static int DES_ncbc_encrypt_loop(void *args);
205 static int DES_ede3_cbc_encrypt_loop(void *args);
207 static int AES_cbc_128_encrypt_loop(void *args);
208 static int AES_cbc_192_encrypt_loop(void *args);
209 static int AES_ige_128_encrypt_loop(void *args);
210 static int AES_cbc_256_encrypt_loop(void *args);
211 static int AES_ige_192_encrypt_loop(void *args);
212 static int AES_ige_256_encrypt_loop(void *args);
213 static int CRYPTO_gcm128_aad_loop(void *args);
214 static int EVP_Update_loop(void *args);
215 static int EVP_Digest_loop(void *args);
216 #ifndef OPENSSL_NO_RSA
217 static int RSA_sign_loop(void *args);
218 static int RSA_verify_loop(void *args);
220 #ifndef OPENSSL_NO_DSA
221 static int DSA_sign_loop(void *args);
222 static int DSA_verify_loop(void *args);
224 #ifndef OPENSSL_NO_EC
225 static int ECDSA_sign_loop(void *args);
226 static int ECDSA_verify_loop(void *args);
228 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
230 static double Time_F(int s);
231 static void print_message(const char *s, long num, int length);
232 static void pkey_print_message(const char *str, const char *str2,
233 long num, int bits, int sec);
234 static void print_result(int alg, int run_no, int count, double time_used);
236 static int do_multi(int multi);
239 static const char *names[ALGOR_NUM] = {
240 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
241 "des cbc", "des ede3", "idea cbc", "seed cbc",
242 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
243 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
244 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
245 "evp", "sha256", "sha512", "whirlpool",
246 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
249 static double results[ALGOR_NUM][SIZE_NUM];
251 static const int lengths[SIZE_NUM] = {
252 16, 64, 256, 1024, 8 * 1024, 16 * 1024
255 #ifndef OPENSSL_NO_RSA
256 static double rsa_results[RSA_NUM][2];
258 #ifndef OPENSSL_NO_DSA
259 static double dsa_results[DSA_NUM][2];
261 #ifndef OPENSSL_NO_EC
262 static double ecdsa_results[EC_NUM][2];
263 static double ecdh_results[EC_NUM][1];
266 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
267 static const char rnd_seed[] =
268 "string to make the random number generator think it has entropy";
272 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
273 # define SIGRETTYPE void
275 # define SIGRETTYPE int
278 static SIGRETTYPE sig_done(int sig);
279 static SIGRETTYPE sig_done(int sig)
281 signal(SIGALRM, sig_done);
291 # if !defined(SIGALRM)
294 static unsigned int lapse, schlock;
295 static void alarm_win32(unsigned int secs)
300 # define alarm alarm_win32
302 static DWORD WINAPI sleepy(VOID * arg)
310 static double Time_F(int s)
317 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
319 DWORD err = GetLastError();
320 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
324 Sleep(0); /* scheduler spinlock */
325 ret = app_tminterval(s, usertime);
327 ret = app_tminterval(s, usertime);
329 TerminateThread(thr, 0);
337 static double Time_F(int s)
339 double ret = app_tminterval(s, usertime);
346 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
348 static int found(const char *name, const OPT_PAIR *pairs, int *result)
350 for (; pairs->name; pairs++)
351 if (strcmp(name, pairs->name) == 0) {
352 *result = pairs->retval;
358 typedef enum OPTION_choice {
359 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
360 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
361 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
364 const OPTIONS speed_options[] = {
365 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
366 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
367 {"help", OPT_HELP, '-', "Display this summary"},
368 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
369 {"decrypt", OPT_DECRYPT, '-',
370 "Time decryption instead of encryption (only EVP)"},
371 {"mr", OPT_MR, '-', "Produce machine readable output"},
373 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
374 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
375 {"elapsed", OPT_ELAPSED, '-',
376 "Measure time in real time instead of CPU user time"},
378 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
380 #ifndef OPENSSL_NO_ASYNC
381 {"async_jobs", OPT_ASYNCJOBS, 'p',
382 "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
435 {"sha256", D_SHA256},
436 {"sha512", D_SHA512},
437 #ifndef OPENSSL_NO_WHIRLPOOL
438 {"whirlpool", D_WHIRLPOOL},
440 #ifndef OPENSSL_NO_RMD160
441 {"ripemd", D_RMD160},
442 {"rmd160", D_RMD160},
443 {"ripemd160", D_RMD160},
445 #ifndef OPENSSL_NO_RC4
448 #ifndef OPENSSL_NO_DES
449 {"des-cbc", D_CBC_DES},
450 {"des-ede3", D_EDE3_DES},
452 {"aes-128-cbc", D_CBC_128_AES},
453 {"aes-192-cbc", D_CBC_192_AES},
454 {"aes-256-cbc", D_CBC_256_AES},
455 {"aes-128-ige", D_IGE_128_AES},
456 {"aes-192-ige", D_IGE_192_AES},
457 {"aes-256-ige", D_IGE_256_AES},
458 #ifndef OPENSSL_NO_RC2
459 {"rc2-cbc", D_CBC_RC2},
462 #ifndef OPENSSL_NO_RC5
463 {"rc5-cbc", D_CBC_RC5},
466 #ifndef OPENSSL_NO_IDEA
467 {"idea-cbc", D_CBC_IDEA},
468 {"idea", D_CBC_IDEA},
470 #ifndef OPENSSL_NO_SEED
471 {"seed-cbc", D_CBC_SEED},
472 {"seed", D_CBC_SEED},
474 #ifndef OPENSSL_NO_BF
475 {"bf-cbc", D_CBC_BF},
476 {"blowfish", D_CBC_BF},
479 #ifndef OPENSSL_NO_CAST
480 {"cast-cbc", D_CBC_CAST},
481 {"cast", D_CBC_CAST},
482 {"cast5", D_CBC_CAST},
488 #ifndef OPENSSL_NO_DSA
490 # define R_DSA_1024 1
491 # define R_DSA_2048 2
492 static OPT_PAIR dsa_choices[] = {
493 {"dsa512", R_DSA_512},
494 {"dsa1024", R_DSA_1024},
495 {"dsa2048", R_DSA_2048},
506 #define R_RSA_15360 6
507 static OPT_PAIR rsa_choices[] = {
508 {"rsa512", R_RSA_512},
509 {"rsa1024", R_RSA_1024},
510 {"rsa2048", R_RSA_2048},
511 {"rsa3072", R_RSA_3072},
512 {"rsa4096", R_RSA_4096},
513 {"rsa7680", R_RSA_7680},
514 {"rsa15360", R_RSA_15360},
534 #define R_EC_X25519 16
535 #ifndef OPENSSL_NO_EC
536 static OPT_PAIR ecdsa_choices[] = {
537 {"ecdsap160", R_EC_P160},
538 {"ecdsap192", R_EC_P192},
539 {"ecdsap224", R_EC_P224},
540 {"ecdsap256", R_EC_P256},
541 {"ecdsap384", R_EC_P384},
542 {"ecdsap521", R_EC_P521},
543 {"ecdsak163", R_EC_K163},
544 {"ecdsak233", R_EC_K233},
545 {"ecdsak283", R_EC_K283},
546 {"ecdsak409", R_EC_K409},
547 {"ecdsak571", R_EC_K571},
548 {"ecdsab163", R_EC_B163},
549 {"ecdsab233", R_EC_B233},
550 {"ecdsab283", R_EC_B283},
551 {"ecdsab409", R_EC_B409},
552 {"ecdsab571", R_EC_B571},
556 static OPT_PAIR ecdh_choices[] = {
557 {"ecdhp160", R_EC_P160},
558 {"ecdhp192", R_EC_P192},
559 {"ecdhp224", R_EC_P224},
560 {"ecdhp256", R_EC_P256},
561 {"ecdhp384", R_EC_P384},
562 {"ecdhp521", R_EC_P521},
563 {"ecdhk163", R_EC_K163},
564 {"ecdhk233", R_EC_K233},
565 {"ecdhk283", R_EC_K283},
566 {"ecdhk409", R_EC_K409},
567 {"ecdhk571", R_EC_K571},
568 {"ecdhb163", R_EC_B163},
569 {"ecdhb233", R_EC_B233},
570 {"ecdhb283", R_EC_B283},
571 {"ecdhb409", R_EC_B409},
572 {"ecdhb571", R_EC_B571},
573 {"ecdhx25519", R_EC_X25519},
579 # define COND(d) (count < (d))
580 # define COUNT(d) (d)
582 # define COND(unused_cond) (run && count<0x7fffffff)
583 # define COUNT(d) (count)
588 /* Nb of iterations to do per algorithm and key-size */
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]; /* # RSA iteration test */
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_EVP_derive_key(unsigned char *derived_secret,
1046 if ( (rt=EVP_PKEY_derive(ctx, derived_secret, outlen)) <= 0 ) {
1047 BIO_printf(bio_err, "ECDH EVP_PKEY_derive failure: returned %d\n", rt);
1048 ERR_print_errors(bio_err);
1054 static int ECDH_EVP_derive_key_loop(void *args)
1056 loopargs_t *tempargs = *(loopargs_t **) args;
1057 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1058 unsigned char *derived_secret = tempargs->secret_a;
1060 size_t *outlen = &(tempargs->outlen[testnum]);
1062 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1063 if ( !ECDH_EVP_derive_key(derived_secret, outlen, ctx) )
1069 #endif /* OPENSSL_NO_EC */
1071 static int run_benchmark(int async_jobs,
1072 int (*loop_function)(void *), loopargs_t *loopargs)
1074 int job_op_count = 0;
1075 int total_op_count = 0;
1076 int num_inprogress = 0;
1077 int error = 0, i = 0, ret = 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);
1087 for (i = 0; i < async_jobs && !error; i++) {
1088 loopargs_t *looparg_item = loopargs + i;
1090 /* Copy pointer content (looparg_t item address) into async context */
1091 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1092 &job_op_count, loop_function,
1093 (void *)&looparg_item, sizeof(looparg_item));
1099 if (job_op_count == -1) {
1102 total_op_count += job_op_count;
1107 BIO_printf(bio_err, "Failure in the job\n");
1108 ERR_print_errors(bio_err);
1114 while (num_inprogress > 0) {
1115 #if defined(OPENSSL_SYS_WINDOWS)
1117 #elif defined(OPENSSL_SYS_UNIX)
1118 int select_result = 0;
1119 OSSL_ASYNC_FD max_fd = 0;
1122 FD_ZERO(&waitfdset);
1124 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1125 if (loopargs[i].inprogress_job == NULL)
1128 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1129 || num_job_fds > 1) {
1130 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1131 ERR_print_errors(bio_err);
1135 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1136 FD_SET(job_fd, &waitfdset);
1137 if (job_fd > max_fd)
1141 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1143 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1144 "Decrease the value of async_jobs\n",
1145 max_fd, FD_SETSIZE);
1146 ERR_print_errors(bio_err);
1151 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1152 if (select_result == -1 && errno == EINTR)
1155 if (select_result == -1) {
1156 BIO_printf(bio_err, "Failure in the select\n");
1157 ERR_print_errors(bio_err);
1162 if (select_result == 0)
1166 for (i = 0; i < async_jobs; i++) {
1167 if (loopargs[i].inprogress_job == NULL)
1170 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1171 || num_job_fds > 1) {
1172 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1173 ERR_print_errors(bio_err);
1177 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1179 #if defined(OPENSSL_SYS_UNIX)
1180 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1182 #elif defined(OPENSSL_SYS_WINDOWS)
1183 if (num_job_fds == 1
1184 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1189 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1190 loopargs[i].wait_ctx, &job_op_count, loop_function,
1191 (void *)(loopargs + i), sizeof(loopargs_t));
1196 if (job_op_count == -1) {
1199 total_op_count += job_op_count;
1202 loopargs[i].inprogress_job = NULL;
1207 loopargs[i].inprogress_job = NULL;
1208 BIO_printf(bio_err, "Failure in the job\n");
1209 ERR_print_errors(bio_err);
1216 return error ? -1 : total_op_count;
1219 int speed_main(int argc, char **argv)
1222 loopargs_t *loopargs = NULL;
1224 int loopargs_len = 0;
1226 const char *engine_id = NULL;
1227 const EVP_CIPHER *evp_cipher = NULL;
1230 int multiblock = 0, pr_header = 0;
1231 int doit[ALGOR_NUM] = { 0 };
1232 int ret = 1, i, k, misalign = 0;
1238 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1239 || !defined(OPENSSL_NO_EC)
1243 /* What follows are the buffers and key material. */
1244 #ifndef OPENSSL_NO_RC5
1247 #ifndef OPENSSL_NO_RC2
1250 #ifndef OPENSSL_NO_IDEA
1251 IDEA_KEY_SCHEDULE idea_ks;
1253 #ifndef OPENSSL_NO_SEED
1254 SEED_KEY_SCHEDULE seed_ks;
1256 #ifndef OPENSSL_NO_BF
1259 #ifndef OPENSSL_NO_CAST
1262 static const unsigned char key16[16] = {
1263 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1264 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1266 static const unsigned char key24[24] = {
1267 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1268 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1269 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1271 static const unsigned char key32[32] = {
1272 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1273 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1274 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1275 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1277 #ifndef OPENSSL_NO_CAMELLIA
1278 static const unsigned char ckey24[24] = {
1279 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1280 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1281 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1283 static const unsigned char ckey32[32] = {
1284 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1285 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1286 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1287 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1289 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1291 #ifndef OPENSSL_NO_DES
1292 static DES_cblock key = {
1293 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1295 static DES_cblock key2 = {
1296 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1298 static DES_cblock key3 = {
1299 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1302 #ifndef OPENSSL_NO_RSA
1303 static const unsigned int rsa_bits[RSA_NUM] = {
1304 512, 1024, 2048, 3072, 4096, 7680, 15360
1306 static const unsigned char *rsa_data[RSA_NUM] = {
1307 test512, test1024, test2048, test3072, test4096, test7680, test15360
1309 static const int rsa_data_length[RSA_NUM] = {
1310 sizeof(test512), sizeof(test1024),
1311 sizeof(test2048), sizeof(test3072),
1312 sizeof(test4096), sizeof(test7680),
1315 int rsa_doit[RSA_NUM] = { 0 };
1317 #ifndef OPENSSL_NO_DSA
1318 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1319 int dsa_doit[DSA_NUM] = { 0 };
1321 #ifndef OPENSSL_NO_EC
1323 * We only test over the following curves as they are representative, To
1324 * add tests over more curves, simply add the curve NID and curve name to
1325 * the following arrays and increase the EC_NUM value accordingly.
1327 static const unsigned int test_curves[EC_NUM] = {
1329 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1330 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1332 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1333 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1334 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1339 static const char *test_curves_names[EC_NUM] = {
1341 "secp160r1", "nistp192", "nistp224",
1342 "nistp256", "nistp384", "nistp521",
1344 "nistk163", "nistk233", "nistk283",
1345 "nistk409", "nistk571", "nistb163",
1346 "nistb233", "nistb283", "nistb409",
1351 static const int test_curves_bits[EC_NUM] = {
1357 571, 253 /* X25519 */
1360 int ecdsa_doit[EC_NUM] = { 0 };
1361 int ecdh_doit[EC_NUM] = { 0 };
1362 #endif /* ndef OPENSSL_NO_EC */
1364 prog = opt_init(argc, argv, speed_options);
1365 while ((o = opt_next()) != OPT_EOF) {
1370 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1373 opt_help(speed_options);
1380 evp_cipher = EVP_get_cipherbyname(opt_arg());
1381 if (evp_cipher == NULL)
1382 evp_md = EVP_get_digestbyname(opt_arg());
1383 if (evp_cipher == NULL && evp_md == NULL) {
1385 "%s: %s is an unknown cipher or digest\n",
1396 * In a forked execution, an engine might need to be
1397 * initialised by each child process, not by the parent.
1398 * So store the name here and run setup_engine() later on.
1400 engine_id = opt_arg();
1404 multi = atoi(opt_arg());
1408 #ifndef OPENSSL_NO_ASYNC
1409 async_jobs = atoi(opt_arg());
1410 if (!ASYNC_is_capable()) {
1412 "%s: async_jobs specified but async not supported\n",
1419 if (!opt_int(opt_arg(), &misalign))
1421 if (misalign > MISALIGN) {
1423 "%s: Maximum offset is %d\n", prog, MISALIGN);
1432 #ifdef OPENSSL_NO_MULTIBLOCK
1434 "%s: -mb specified but multi-block support is disabled\n",
1441 argc = opt_num_rest();
1444 /* Remaining arguments are algorithms. */
1445 for ( ; *argv; argv++) {
1446 if (found(*argv, doit_choices, &i)) {
1450 #ifndef OPENSSL_NO_DES
1451 if (strcmp(*argv, "des") == 0) {
1452 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1456 if (strcmp(*argv, "sha") == 0) {
1457 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1460 #ifndef OPENSSL_NO_RSA
1462 if (strcmp(*argv, "openssl") == 0) {
1463 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1467 if (strcmp(*argv, "rsa") == 0) {
1468 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1469 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1470 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1471 rsa_doit[R_RSA_15360] = 1;
1474 if (found(*argv, rsa_choices, &i)) {
1479 #ifndef OPENSSL_NO_DSA
1480 if (strcmp(*argv, "dsa") == 0) {
1481 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1482 dsa_doit[R_DSA_2048] = 1;
1485 if (found(*argv, dsa_choices, &i)) {
1490 if (strcmp(*argv, "aes") == 0) {
1491 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1492 doit[D_CBC_256_AES] = 1;
1495 #ifndef OPENSSL_NO_CAMELLIA
1496 if (strcmp(*argv, "camellia") == 0) {
1497 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1498 doit[D_CBC_256_CML] = 1;
1502 #ifndef OPENSSL_NO_EC
1503 if (strcmp(*argv, "ecdsa") == 0) {
1504 for (i = 0; i < EC_NUM; i++)
1508 if (found(*argv, ecdsa_choices, &i)) {
1512 if (strcmp(*argv, "ecdh") == 0) {
1513 for (i = 0; i < EC_NUM; i++)
1517 if (found(*argv, ecdh_choices, &i)) {
1522 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1526 /* Initialize the job pool if async mode is enabled */
1527 if (async_jobs > 0) {
1528 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1530 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1535 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1536 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1537 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1539 for (i = 0; i < loopargs_len; i++) {
1540 if (async_jobs > 0) {
1541 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1542 if (loopargs[i].wait_ctx == NULL) {
1543 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1548 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1549 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1550 /* Align the start of buffers on a 64 byte boundary */
1551 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1552 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1553 #ifndef OPENSSL_NO_EC
1554 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1555 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1560 if (multi && do_multi(multi))
1564 /* Initialize the engine after the fork */
1565 e = setup_engine(engine_id, 0);
1567 /* No parameters; turn on everything. */
1568 if ((argc == 0) && !doit[D_EVP]) {
1569 for (i = 0; i < ALGOR_NUM; i++)
1572 #ifndef OPENSSL_NO_RSA
1573 for (i = 0; i < RSA_NUM; i++)
1576 #ifndef OPENSSL_NO_DSA
1577 for (i = 0; i < DSA_NUM; i++)
1580 #ifndef OPENSSL_NO_EC
1581 for (i = 0; i < EC_NUM; i++)
1583 for (i = 0; i < EC_NUM; i++)
1587 for (i = 0; i < ALGOR_NUM; i++)
1591 if (usertime == 0 && !mr)
1593 "You have chosen to measure elapsed time "
1594 "instead of user CPU time.\n");
1596 #ifndef OPENSSL_NO_RSA
1597 for (i = 0; i < loopargs_len; i++) {
1598 for (k = 0; k < RSA_NUM; k++) {
1599 const unsigned char *p;
1602 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1603 if (loopargs[i].rsa_key[k] == NULL) {
1604 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1611 #ifndef OPENSSL_NO_DSA
1612 for (i = 0; i < loopargs_len; i++) {
1613 loopargs[i].dsa_key[0] = get_dsa512();
1614 loopargs[i].dsa_key[1] = get_dsa1024();
1615 loopargs[i].dsa_key[2] = get_dsa2048();
1618 #ifndef OPENSSL_NO_DES
1619 DES_set_key_unchecked(&key, &sch);
1620 DES_set_key_unchecked(&key2, &sch2);
1621 DES_set_key_unchecked(&key3, &sch3);
1623 AES_set_encrypt_key(key16, 128, &aes_ks1);
1624 AES_set_encrypt_key(key24, 192, &aes_ks2);
1625 AES_set_encrypt_key(key32, 256, &aes_ks3);
1626 #ifndef OPENSSL_NO_CAMELLIA
1627 Camellia_set_key(key16, 128, &camellia_ks1);
1628 Camellia_set_key(ckey24, 192, &camellia_ks2);
1629 Camellia_set_key(ckey32, 256, &camellia_ks3);
1631 #ifndef OPENSSL_NO_IDEA
1632 IDEA_set_encrypt_key(key16, &idea_ks);
1634 #ifndef OPENSSL_NO_SEED
1635 SEED_set_key(key16, &seed_ks);
1637 #ifndef OPENSSL_NO_RC4
1638 RC4_set_key(&rc4_ks, 16, key16);
1640 #ifndef OPENSSL_NO_RC2
1641 RC2_set_key(&rc2_ks, 16, key16, 128);
1643 #ifndef OPENSSL_NO_RC5
1644 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1646 #ifndef OPENSSL_NO_BF
1647 BF_set_key(&bf_ks, 16, key16);
1649 #ifndef OPENSSL_NO_CAST
1650 CAST_set_key(&cast_ks, 16, key16);
1653 # ifndef OPENSSL_NO_DES
1654 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1660 for (it = count; it; it--)
1661 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1662 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1666 c[D_MD2][0] = count / 10;
1667 c[D_MDC2][0] = count / 10;
1668 c[D_MD4][0] = count;
1669 c[D_MD5][0] = count;
1670 c[D_HMAC][0] = count;
1671 c[D_SHA1][0] = count;
1672 c[D_RMD160][0] = count;
1673 c[D_RC4][0] = count * 5;
1674 c[D_CBC_DES][0] = count;
1675 c[D_EDE3_DES][0] = count / 3;
1676 c[D_CBC_IDEA][0] = count;
1677 c[D_CBC_SEED][0] = count;
1678 c[D_CBC_RC2][0] = count;
1679 c[D_CBC_RC5][0] = count;
1680 c[D_CBC_BF][0] = count;
1681 c[D_CBC_CAST][0] = count;
1682 c[D_CBC_128_AES][0] = count;
1683 c[D_CBC_192_AES][0] = count;
1684 c[D_CBC_256_AES][0] = count;
1685 c[D_CBC_128_CML][0] = count;
1686 c[D_CBC_192_CML][0] = count;
1687 c[D_CBC_256_CML][0] = count;
1688 c[D_SHA256][0] = count;
1689 c[D_SHA512][0] = count;
1690 c[D_WHIRLPOOL][0] = count;
1691 c[D_IGE_128_AES][0] = count;
1692 c[D_IGE_192_AES][0] = count;
1693 c[D_IGE_256_AES][0] = count;
1694 c[D_GHASH][0] = count;
1696 for (i = 1; i < SIZE_NUM; i++) {
1699 l0 = (long)lengths[0];
1700 l1 = (long)lengths[i];
1702 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1703 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1704 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1705 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1706 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1707 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1708 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1709 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1710 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1711 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1712 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1714 l0 = (long)lengths[i - 1];
1716 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1717 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1718 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1719 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1720 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1721 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1722 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1723 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1724 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1725 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1726 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1727 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1728 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1729 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1730 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1731 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1732 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1733 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1736 # ifndef OPENSSL_NO_RSA
1737 rsa_c[R_RSA_512][0] = count / 2000;
1738 rsa_c[R_RSA_512][1] = count / 400;
1739 for (i = 1; i < RSA_NUM; i++) {
1740 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1741 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1742 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1745 if (rsa_c[i][0] == 0) {
1746 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1753 # ifndef OPENSSL_NO_DSA
1754 dsa_c[R_DSA_512][0] = count / 1000;
1755 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1756 for (i = 1; i < DSA_NUM; i++) {
1757 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1758 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1759 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1762 if (dsa_c[i][0] == 0) {
1763 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1770 # ifndef OPENSSL_NO_EC
1771 ecdsa_c[R_EC_P160][0] = count / 1000;
1772 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1773 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1774 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1775 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1776 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1779 if (ecdsa_c[i][0] == 0) {
1785 ecdsa_c[R_EC_K163][0] = count / 1000;
1786 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1787 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1788 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1789 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1790 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1793 if (ecdsa_c[i][0] == 0) {
1799 ecdsa_c[R_EC_B163][0] = count / 1000;
1800 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1801 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1802 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1803 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1804 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1807 if (ecdsa_c[i][0] == 0) {
1814 ecdh_c[R_EC_P160][0] = count / 1000;
1815 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1816 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1817 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1820 if (ecdh_c[i][0] == 0) {
1825 ecdh_c[R_EC_K163][0] = count / 1000;
1826 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1827 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1828 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1831 if (ecdh_c[i][0] == 0) {
1836 ecdh_c[R_EC_B163][0] = count / 1000;
1837 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1838 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1839 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1842 if (ecdh_c[i][0] == 0) {
1850 /* not worth fixing */
1851 # error "You cannot disable DES on systems without SIGALRM."
1852 # endif /* OPENSSL_NO_DES */
1855 signal(SIGALRM, sig_done);
1857 #endif /* SIGALRM */
1859 #ifndef OPENSSL_NO_MD2
1861 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1862 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1864 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1866 print_result(D_MD2, testnum, count, d);
1870 #ifndef OPENSSL_NO_MDC2
1872 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1873 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1875 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1877 print_result(D_MDC2, testnum, count, d);
1882 #ifndef OPENSSL_NO_MD4
1884 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1885 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1887 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1889 print_result(D_MD4, testnum, count, d);
1894 #ifndef OPENSSL_NO_MD5
1896 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1897 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1899 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1901 print_result(D_MD5, testnum, count, d);
1906 static const char hmac_key[] = "This is a key...";
1907 int len = strlen(hmac_key);
1909 for (i = 0; i < loopargs_len; i++) {
1910 loopargs[i].hctx = HMAC_CTX_new();
1911 if (loopargs[i].hctx == NULL) {
1912 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1916 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1918 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1919 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1921 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1923 print_result(D_HMAC, testnum, count, d);
1925 for (i = 0; i < loopargs_len; i++) {
1926 HMAC_CTX_free(loopargs[i].hctx);
1931 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1932 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1934 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1936 print_result(D_SHA1, testnum, count, d);
1939 if (doit[D_SHA256]) {
1940 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1941 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1943 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1945 print_result(D_SHA256, testnum, count, d);
1948 if (doit[D_SHA512]) {
1949 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1950 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1952 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1954 print_result(D_SHA512, testnum, count, d);
1958 #ifndef OPENSSL_NO_WHIRLPOOL
1959 if (doit[D_WHIRLPOOL]) {
1960 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1961 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1963 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1965 print_result(D_WHIRLPOOL, testnum, count, d);
1970 #ifndef OPENSSL_NO_RMD160
1971 if (doit[D_RMD160]) {
1972 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1973 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1975 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1977 print_result(D_RMD160, testnum, count, d);
1981 #ifndef OPENSSL_NO_RC4
1983 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1984 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1986 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1988 print_result(D_RC4, testnum, count, d);
1992 #ifndef OPENSSL_NO_DES
1993 if (doit[D_CBC_DES]) {
1994 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1995 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
1997 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1999 print_result(D_CBC_DES, testnum, count, d);
2003 if (doit[D_EDE3_DES]) {
2004 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2005 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2007 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2009 print_result(D_EDE3_DES, testnum, count, d);
2014 if (doit[D_CBC_128_AES]) {
2015 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2016 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2019 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2021 print_result(D_CBC_128_AES, testnum, count, d);
2024 if (doit[D_CBC_192_AES]) {
2025 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2026 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2029 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2031 print_result(D_CBC_192_AES, testnum, count, d);
2034 if (doit[D_CBC_256_AES]) {
2035 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2036 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2039 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2041 print_result(D_CBC_256_AES, testnum, count, d);
2045 if (doit[D_IGE_128_AES]) {
2046 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2047 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2050 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2052 print_result(D_IGE_128_AES, testnum, count, d);
2055 if (doit[D_IGE_192_AES]) {
2056 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2057 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2060 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2062 print_result(D_IGE_192_AES, testnum, count, d);
2065 if (doit[D_IGE_256_AES]) {
2066 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2067 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2070 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2072 print_result(D_IGE_256_AES, testnum, count, d);
2075 if (doit[D_GHASH]) {
2076 for (i = 0; i < loopargs_len; i++) {
2077 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2078 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2081 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2082 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2084 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2086 print_result(D_GHASH, testnum, count, d);
2088 for (i = 0; i < loopargs_len; i++)
2089 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2092 #ifndef OPENSSL_NO_CAMELLIA
2093 if (doit[D_CBC_128_CML]) {
2094 if (async_jobs > 0) {
2095 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2096 names[D_CBC_128_CML]);
2097 doit[D_CBC_128_CML] = 0;
2099 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2100 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2103 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2104 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2105 (size_t)lengths[testnum], &camellia_ks1,
2106 iv, CAMELLIA_ENCRYPT);
2108 print_result(D_CBC_128_CML, testnum, count, d);
2111 if (doit[D_CBC_192_CML]) {
2112 if (async_jobs > 0) {
2113 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2114 names[D_CBC_192_CML]);
2115 doit[D_CBC_192_CML] = 0;
2117 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2118 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2120 if (async_jobs > 0) {
2121 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2125 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2126 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2127 (size_t)lengths[testnum], &camellia_ks2,
2128 iv, CAMELLIA_ENCRYPT);
2130 print_result(D_CBC_192_CML, testnum, count, d);
2133 if (doit[D_CBC_256_CML]) {
2134 if (async_jobs > 0) {
2135 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2136 names[D_CBC_256_CML]);
2137 doit[D_CBC_256_CML] = 0;
2139 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2140 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2143 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2144 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2145 (size_t)lengths[testnum], &camellia_ks3,
2146 iv, CAMELLIA_ENCRYPT);
2148 print_result(D_CBC_256_CML, testnum, count, d);
2152 #ifndef OPENSSL_NO_IDEA
2153 if (doit[D_CBC_IDEA]) {
2154 if (async_jobs > 0) {
2155 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2157 doit[D_CBC_IDEA] = 0;
2159 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2160 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2162 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2163 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2164 (size_t)lengths[testnum], &idea_ks,
2167 print_result(D_CBC_IDEA, testnum, count, d);
2171 #ifndef OPENSSL_NO_SEED
2172 if (doit[D_CBC_SEED]) {
2173 if (async_jobs > 0) {
2174 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2176 doit[D_CBC_SEED] = 0;
2178 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2179 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2181 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2182 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2183 (size_t)lengths[testnum], &seed_ks, iv, 1);
2185 print_result(D_CBC_SEED, testnum, count, d);
2189 #ifndef OPENSSL_NO_RC2
2190 if (doit[D_CBC_RC2]) {
2191 if (async_jobs > 0) {
2192 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2194 doit[D_CBC_RC2] = 0;
2196 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2197 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2198 if (async_jobs > 0) {
2199 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2203 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2204 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2205 (size_t)lengths[testnum], &rc2_ks,
2208 print_result(D_CBC_RC2, testnum, count, d);
2212 #ifndef OPENSSL_NO_RC5
2213 if (doit[D_CBC_RC5]) {
2214 if (async_jobs > 0) {
2215 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2217 doit[D_CBC_RC5] = 0;
2219 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2220 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2221 if (async_jobs > 0) {
2222 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2226 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2227 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2228 (size_t)lengths[testnum], &rc5_ks,
2231 print_result(D_CBC_RC5, testnum, count, d);
2235 #ifndef OPENSSL_NO_BF
2236 if (doit[D_CBC_BF]) {
2237 if (async_jobs > 0) {
2238 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2242 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2243 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2245 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2246 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2247 (size_t)lengths[testnum], &bf_ks,
2250 print_result(D_CBC_BF, testnum, count, d);
2254 #ifndef OPENSSL_NO_CAST
2255 if (doit[D_CBC_CAST]) {
2256 if (async_jobs > 0) {
2257 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2259 doit[D_CBC_CAST] = 0;
2261 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2262 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2264 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2265 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2266 (size_t)lengths[testnum], &cast_ks,
2269 print_result(D_CBC_CAST, testnum, count, d);
2275 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2276 if (multiblock && evp_cipher) {
2278 (EVP_CIPHER_flags(evp_cipher) &
2279 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2280 BIO_printf(bio_err, "%s is not multi-block capable\n",
2281 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2284 if (async_jobs > 0) {
2285 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2288 multiblock_speed(evp_cipher);
2293 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2296 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2298 * -O3 -fschedule-insns messes up an optimization here!
2299 * names[D_EVP] somehow becomes NULL
2301 print_message(names[D_EVP], save_count, lengths[testnum]);
2303 for (k = 0; k < loopargs_len; k++) {
2304 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2306 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2308 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2309 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2313 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2315 for (k = 0; k < loopargs_len; k++) {
2316 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2320 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2321 print_message(names[D_EVP], save_count, lengths[testnum]);
2323 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2326 print_result(D_EVP, testnum, count, d);
2330 for (i = 0; i < loopargs_len; i++)
2331 RAND_bytes(loopargs[i].buf, 36);
2333 #ifndef OPENSSL_NO_RSA
2334 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2336 if (!rsa_doit[testnum])
2338 for (i = 0; i < loopargs_len; i++) {
2339 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2340 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2346 "RSA sign failure. No RSA sign will be done.\n");
2347 ERR_print_errors(bio_err);
2350 pkey_print_message("private", "rsa",
2351 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2352 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2354 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2357 mr ? "+R1:%ld:%d:%.2f\n"
2358 : "%ld %d bit private RSA's in %.2fs\n",
2359 count, rsa_bits[testnum], d);
2360 rsa_results[testnum][0] = d / (double)count;
2364 for (i = 0; i < loopargs_len; i++) {
2365 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2366 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2372 "RSA verify failure. No RSA verify will be done.\n");
2373 ERR_print_errors(bio_err);
2374 rsa_doit[testnum] = 0;
2376 pkey_print_message("public", "rsa",
2377 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2379 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2382 mr ? "+R2:%ld:%d:%.2f\n"
2383 : "%ld %d bit public RSA's in %.2fs\n",
2384 count, rsa_bits[testnum], d);
2385 rsa_results[testnum][1] = d / (double)count;
2388 if (rsa_count <= 1) {
2389 /* if longer than 10s, don't do any more */
2390 for (testnum++; testnum < RSA_NUM; testnum++)
2391 rsa_doit[testnum] = 0;
2394 #endif /* OPENSSL_NO_RSA */
2396 for (i = 0; i < loopargs_len; i++)
2397 RAND_bytes(loopargs[i].buf, 36);
2399 #ifndef OPENSSL_NO_DSA
2400 if (RAND_status() != 1) {
2401 RAND_seed(rnd_seed, sizeof rnd_seed);
2403 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2405 if (!dsa_doit[testnum])
2408 /* DSA_generate_key(dsa_key[testnum]); */
2409 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2410 for (i = 0; i < loopargs_len; i++) {
2411 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2412 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2418 "DSA sign failure. No DSA sign will be done.\n");
2419 ERR_print_errors(bio_err);
2422 pkey_print_message("sign", "dsa",
2423 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2425 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2428 mr ? "+R3:%ld:%d:%.2f\n"
2429 : "%ld %d bit DSA signs in %.2fs\n",
2430 count, dsa_bits[testnum], d);
2431 dsa_results[testnum][0] = d / (double)count;
2435 for (i = 0; i < loopargs_len; i++) {
2436 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2437 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2443 "DSA verify failure. No DSA verify will be done.\n");
2444 ERR_print_errors(bio_err);
2445 dsa_doit[testnum] = 0;
2447 pkey_print_message("verify", "dsa",
2448 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2450 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2453 mr ? "+R4:%ld:%d:%.2f\n"
2454 : "%ld %d bit DSA verify in %.2fs\n",
2455 count, dsa_bits[testnum], d);
2456 dsa_results[testnum][1] = d / (double)count;
2459 if (rsa_count <= 1) {
2460 /* if longer than 10s, don't do any more */
2461 for (testnum++; testnum < DSA_NUM; testnum++)
2462 dsa_doit[testnum] = 0;
2465 #endif /* OPENSSL_NO_DSA */
2467 #ifndef OPENSSL_NO_EC
2468 if (RAND_status() != 1) {
2469 RAND_seed(rnd_seed, sizeof rnd_seed);
2471 for (testnum = 0; testnum < EC_NUM; testnum++) {
2474 if (!ecdsa_doit[testnum])
2475 continue; /* Ignore Curve */
2476 for (i = 0; i < loopargs_len; i++) {
2477 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2478 if (loopargs[i].ecdsa[testnum] == NULL) {
2484 BIO_printf(bio_err, "ECDSA failure.\n");
2485 ERR_print_errors(bio_err);
2488 for (i = 0; i < loopargs_len; i++) {
2489 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2490 /* Perform ECDSA signature test */
2491 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2492 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2493 &loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2499 "ECDSA sign failure. No ECDSA sign will be done.\n");
2500 ERR_print_errors(bio_err);
2503 pkey_print_message("sign", "ecdsa",
2504 ecdsa_c[testnum][0],
2505 test_curves_bits[testnum], ECDSA_SECONDS);
2507 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2511 mr ? "+R5:%ld:%d:%.2f\n" :
2512 "%ld %d bit ECDSA signs in %.2fs \n",
2513 count, test_curves_bits[testnum], d);
2514 ecdsa_results[testnum][0] = d / (double)count;
2518 /* Perform ECDSA verification test */
2519 for (i = 0; i < loopargs_len; i++) {
2520 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2521 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2527 "ECDSA verify failure. No ECDSA verify will be done.\n");
2528 ERR_print_errors(bio_err);
2529 ecdsa_doit[testnum] = 0;
2531 pkey_print_message("verify", "ecdsa",
2532 ecdsa_c[testnum][1],
2533 test_curves_bits[testnum], ECDSA_SECONDS);
2535 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2538 mr ? "+R6:%ld:%d:%.2f\n"
2539 : "%ld %d bit ECDSA verify in %.2fs\n",
2540 count, test_curves_bits[testnum], d);
2541 ecdsa_results[testnum][1] = d / (double)count;
2544 if (rsa_count <= 1) {
2545 /* if longer than 10s, don't do any more */
2546 for (testnum++; testnum < EC_NUM; testnum++)
2547 ecdsa_doit[testnum] = 0;
2552 if (RAND_status() != 1) {
2553 RAND_seed(rnd_seed, sizeof rnd_seed);
2555 for (testnum = 0; testnum < EC_NUM; testnum++) {
2556 int ecdh_checks = 1;
2558 if (!ecdh_doit[testnum])
2561 for (i = 0; i < loopargs_len; i++) {
2562 EVP_PKEY_CTX *kctx = NULL, *ctx = NULL;
2563 EVP_PKEY *key_A = NULL, *key_B = NULL;
2566 if (testnum == R_EC_X25519) {
2567 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2569 EVP_PKEY_CTX *pctx = NULL;
2570 EVP_PKEY *params = NULL;
2572 if ( /* Create the context for parameter generation */
2573 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2574 /* Initialise the parameter generation */
2575 !EVP_PKEY_paramgen_init(pctx) ||
2576 /* Set the curve by NID */
2577 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, test_curves[testnum]) ||
2578 /* Create the parameter object params */
2579 !EVP_PKEY_paramgen(pctx, ¶ms) ||
2582 BIO_printf(bio_err, "ECDH init failure.\n");
2583 ERR_print_errors(bio_err);
2587 /* Create the context for the key generation */
2588 kctx = EVP_PKEY_CTX_new(params, NULL);
2590 EVP_PKEY_free(params); params = NULL;
2591 EVP_PKEY_CTX_free(pctx); pctx = NULL;
2593 if ( !kctx || /* keygen ctx is not null */
2594 !EVP_PKEY_keygen_init(kctx) || /* init keygen ctx */
2597 BIO_printf(bio_err, "ECDH keygen failure.\n");
2598 ERR_print_errors(bio_err);
2603 if ( !EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2604 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2605 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2606 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2607 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2608 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2609 outlen > MAX_ECDH_SIZE || /* avoid buffer overflow */
2612 BIO_printf(bio_err, "ECDH key generation failure.\n");
2613 ERR_print_errors(bio_err);
2618 loopargs[i].ecdh_ctx[testnum] = ctx;
2619 loopargs[i].outlen[testnum] = outlen;
2621 EVP_PKEY_CTX_free(kctx); kctx = NULL;
2623 if (ecdh_checks != 0) {
2624 pkey_print_message("", "ecdh",
2626 test_curves_bits[testnum], ECDH_SECONDS);
2628 count = run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2631 mr ? "+R7:%ld:%d:%.2f\n" :
2632 "%ld %d-bit ECDH ops in %.2fs\n", count,
2633 test_curves_bits[testnum], d);
2634 ecdh_results[testnum][0] = d / (double)count;
2638 if (rsa_count <= 1) {
2639 /* if longer than 10s, don't do any more */
2640 for (testnum++; testnum < EC_NUM; testnum++)
2641 ecdh_doit[testnum] = 0;
2644 #endif /* OPENSSL_NO_EC */
2649 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2650 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2652 printf("%s ", BN_options());
2653 #ifndef OPENSSL_NO_MD2
2654 printf("%s ", MD2_options());
2656 #ifndef OPENSSL_NO_RC4
2657 printf("%s ", RC4_options());
2659 #ifndef OPENSSL_NO_DES
2660 printf("%s ", DES_options());
2662 printf("%s ", AES_options());
2663 #ifndef OPENSSL_NO_IDEA
2664 printf("%s ", IDEA_options());
2666 #ifndef OPENSSL_NO_BF
2667 printf("%s ", BF_options());
2669 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2677 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2680 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2681 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2685 for (k = 0; k < ALGOR_NUM; k++) {
2689 printf("+F:%d:%s", k, names[k]);
2691 printf("%-13s", names[k]);
2692 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2693 if (results[k][testnum] > 10000 && !mr)
2694 printf(" %11.2fk", results[k][testnum] / 1e3);
2696 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2700 #ifndef OPENSSL_NO_RSA
2702 for (k = 0; k < RSA_NUM; k++) {
2705 if (testnum && !mr) {
2706 printf("%18ssign verify sign/s verify/s\n", " ");
2710 printf("+F2:%u:%u:%f:%f\n",
2711 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2713 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2714 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2715 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2718 #ifndef OPENSSL_NO_DSA
2720 for (k = 0; k < DSA_NUM; k++) {
2723 if (testnum && !mr) {
2724 printf("%18ssign verify sign/s verify/s\n", " ");
2728 printf("+F3:%u:%u:%f:%f\n",
2729 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2731 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2732 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2733 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2736 #ifndef OPENSSL_NO_EC
2738 for (k = 0; k < EC_NUM; k++) {
2741 if (testnum && !mr) {
2742 printf("%30ssign verify sign/s verify/s\n", " ");
2747 printf("+F4:%u:%u:%f:%f\n",
2748 k, test_curves_bits[k],
2749 ecdsa_results[k][0], ecdsa_results[k][1]);
2751 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2752 test_curves_bits[k],
2753 test_curves_names[k],
2754 ecdsa_results[k][0], ecdsa_results[k][1],
2755 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2759 for (k = 0; k < EC_NUM; k++) {
2762 if (testnum && !mr) {
2763 printf("%30sop op/s\n", " ");
2767 printf("+F5:%u:%u:%f:%f\n",
2768 k, test_curves_bits[k],
2769 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2772 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2773 test_curves_bits[k],
2774 test_curves_names[k],
2775 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2782 ERR_print_errors(bio_err);
2783 for (i = 0; i < loopargs_len; i++) {
2784 OPENSSL_free(loopargs[i].buf_malloc);
2785 OPENSSL_free(loopargs[i].buf2_malloc);
2787 #ifndef OPENSSL_NO_RSA
2788 for (k = 0; k < RSA_NUM; k++)
2789 RSA_free(loopargs[i].rsa_key[k]);
2791 #ifndef OPENSSL_NO_DSA
2792 for (k = 0; k < DSA_NUM; k++)
2793 DSA_free(loopargs[i].dsa_key[k]);
2795 #ifndef OPENSSL_NO_EC
2796 for (k = 0; k < EC_NUM; k++) {
2797 EC_KEY_free(loopargs[i].ecdsa[k]);
2798 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2800 OPENSSL_free(loopargs[i].secret_a);
2801 OPENSSL_free(loopargs[i].secret_b);
2805 if (async_jobs > 0) {
2806 for (i = 0; i < loopargs_len; i++)
2807 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2811 ASYNC_cleanup_thread();
2813 OPENSSL_free(loopargs);
2818 static void print_message(const char *s, long num, int length)
2822 mr ? "+DT:%s:%d:%d\n"
2823 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2824 (void)BIO_flush(bio_err);
2828 mr ? "+DN:%s:%ld:%d\n"
2829 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2830 (void)BIO_flush(bio_err);
2834 static void pkey_print_message(const char *str, const char *str2, long num,
2839 mr ? "+DTP:%d:%s:%s:%d\n"
2840 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2841 (void)BIO_flush(bio_err);
2845 mr ? "+DNP:%ld:%d:%s:%s\n"
2846 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2847 (void)BIO_flush(bio_err);
2851 static void print_result(int alg, int run_no, int count, double time_used)
2854 BIO_puts(bio_err, "EVP error!\n");
2858 mr ? "+R:%d:%s:%f\n"
2859 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2860 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2864 static char *sstrsep(char **string, const char *delim)
2867 char *token = *string;
2872 memset(isdelim, 0, sizeof isdelim);
2876 isdelim[(unsigned char)(*delim)] = 1;
2880 while (!isdelim[(unsigned char)(**string)]) {
2892 static int do_multi(int multi)
2897 static char sep[] = ":";
2899 fds = malloc(sizeof(*fds) * multi);
2900 for (n = 0; n < multi; ++n) {
2901 if (pipe(fd) == -1) {
2902 BIO_printf(bio_err, "pipe failure\n");
2906 (void)BIO_flush(bio_err);
2913 if (dup(fd[1]) == -1) {
2914 BIO_printf(bio_err, "dup failed\n");
2923 printf("Forked child %d\n", n);
2926 /* for now, assume the pipe is long enough to take all the output */
2927 for (n = 0; n < multi; ++n) {
2932 f = fdopen(fds[n], "r");
2933 while (fgets(buf, sizeof buf, f)) {
2934 p = strchr(buf, '\n');
2937 if (buf[0] != '+') {
2938 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2942 printf("Got: %s from %d\n", buf, n);
2943 if (strncmp(buf, "+F:", 3) == 0) {
2948 alg = atoi(sstrsep(&p, sep));
2950 for (j = 0; j < SIZE_NUM; ++j)
2951 results[alg][j] += atof(sstrsep(&p, sep));
2952 } else if (strncmp(buf, "+F2:", 4) == 0) {
2957 k = atoi(sstrsep(&p, sep));
2960 d = atof(sstrsep(&p, sep));
2962 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2964 rsa_results[k][0] = d;
2966 d = atof(sstrsep(&p, sep));
2968 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2970 rsa_results[k][1] = d;
2972 # ifndef OPENSSL_NO_DSA
2973 else if (strncmp(buf, "+F3:", 4) == 0) {
2978 k = atoi(sstrsep(&p, sep));
2981 d = atof(sstrsep(&p, sep));
2983 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2985 dsa_results[k][0] = d;
2987 d = atof(sstrsep(&p, sep));
2989 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2991 dsa_results[k][1] = d;
2994 # ifndef OPENSSL_NO_EC
2995 else if (strncmp(buf, "+F4:", 4) == 0) {
3000 k = atoi(sstrsep(&p, sep));
3003 d = atof(sstrsep(&p, sep));
3005 ecdsa_results[k][0] =
3006 1 / (1 / ecdsa_results[k][0] + 1 / d);
3008 ecdsa_results[k][0] = d;
3010 d = atof(sstrsep(&p, sep));
3012 ecdsa_results[k][1] =
3013 1 / (1 / ecdsa_results[k][1] + 1 / d);
3015 ecdsa_results[k][1] = d;
3016 } else if (strncmp(buf, "+F5:", 4) == 0) {
3021 k = atoi(sstrsep(&p, sep));
3024 d = atof(sstrsep(&p, sep));
3026 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3028 ecdh_results[k][0] = d;
3033 else if (strncmp(buf, "+H:", 3) == 0) {
3036 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3046 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3048 static int mblengths[] =
3049 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3050 int j, count, num = OSSL_NELEM(mblengths);
3051 const char *alg_name;
3052 unsigned char *inp, *out, no_key[32], no_iv[16];
3053 EVP_CIPHER_CTX *ctx;
3056 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3057 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3058 ctx = EVP_CIPHER_CTX_new();
3059 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3060 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3062 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3064 for (j = 0; j < num; j++) {
3065 print_message(alg_name, 0, mblengths[j]);
3067 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3068 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3069 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3070 size_t len = mblengths[j];
3073 memset(aad, 0, 8); /* avoid uninitialized values */
3074 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3075 aad[9] = 3; /* version */
3077 aad[11] = 0; /* length */
3079 mb_param.out = NULL;
3082 mb_param.interleave = 8;
3084 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3085 sizeof(mb_param), &mb_param);
3091 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3092 sizeof(mb_param), &mb_param);
3096 RAND_bytes(out, 16);
3100 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3101 EVP_AEAD_TLS1_AAD_LEN, aad);
3102 EVP_Cipher(ctx, out, inp, len + pad);
3106 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3107 : "%d %s's in %.2fs\n", count, "evp", d);
3108 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3112 fprintf(stdout, "+H");
3113 for (j = 0; j < num; j++)
3114 fprintf(stdout, ":%d", mblengths[j]);
3115 fprintf(stdout, "\n");
3116 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3117 for (j = 0; j < num; j++)
3118 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3119 fprintf(stdout, "\n");
3122 "The 'numbers' are in 1000s of bytes per second processed.\n");
3123 fprintf(stdout, "type ");
3124 for (j = 0; j < num; j++)
3125 fprintf(stdout, "%7d bytes", mblengths[j]);
3126 fprintf(stdout, "\n");
3127 fprintf(stdout, "%-24s", alg_name);
3129 for (j = 0; j < num; j++) {
3130 if (results[D_EVP][j] > 10000)
3131 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3133 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3135 fprintf(stdout, "\n");
3140 EVP_CIPHER_CTX_free(ctx);