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) (const void *in, size_t inlen, void *out,
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 *),
229 loopargs_t * loopargs);
231 static double Time_F(int s);
232 static void print_message(const char *s, long num, int length);
233 static void pkey_print_message(const char *str, const char *str2,
234 long num, int bits, int sec);
235 static void print_result(int alg, int run_no, int count, double time_used);
237 static int do_multi(int multi);
240 static const char *names[ALGOR_NUM] = {
241 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
242 "des cbc", "des ede3", "idea cbc", "seed cbc",
243 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
244 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
245 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
246 "evp", "sha256", "sha512", "whirlpool",
247 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
250 static double results[ALGOR_NUM][SIZE_NUM];
252 static const int lengths[SIZE_NUM] = {
253 16, 64, 256, 1024, 8 * 1024, 16 * 1024
256 #ifndef OPENSSL_NO_RSA
257 static double rsa_results[RSA_NUM][2];
259 #ifndef OPENSSL_NO_DSA
260 static double dsa_results[DSA_NUM][2];
262 #ifndef OPENSSL_NO_EC
263 static double ecdsa_results[EC_NUM][2];
264 static double ecdh_results[EC_NUM][1];
267 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
268 static const char rnd_seed[] =
269 "string to make the random number generator think it has entropy";
273 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
274 # define SIGRETTYPE void
276 # define SIGRETTYPE int
279 static SIGRETTYPE sig_done(int sig);
280 static SIGRETTYPE sig_done(int sig)
282 signal(SIGALRM, sig_done);
292 # if !defined(SIGALRM)
295 static unsigned int lapse, schlock;
296 static void alarm_win32(unsigned int secs)
301 # define alarm alarm_win32
303 static DWORD WINAPI sleepy(VOID * arg)
311 static double Time_F(int s)
318 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
320 DWORD err = GetLastError();
321 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
325 Sleep(0); /* scheduler spinlock */
326 ret = app_tminterval(s, usertime);
328 ret = app_tminterval(s, usertime);
330 TerminateThread(thr, 0);
338 static double Time_F(int s)
340 double ret = app_tminterval(s, usertime);
347 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
349 static int found(const char *name, const OPT_PAIR *pairs, int *result)
351 for (; pairs->name; pairs++)
352 if (strcmp(name, pairs->name) == 0) {
353 *result = pairs->retval;
359 typedef enum OPTION_choice {
360 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
361 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
362 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
365 const OPTIONS speed_options[] = {
366 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
367 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
368 {"help", OPT_HELP, '-', "Display this summary"},
369 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
370 {"decrypt", OPT_DECRYPT, '-',
371 "Time decryption instead of encryption (only EVP)"},
372 {"mr", OPT_MR, '-', "Produce machine readable output"},
374 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
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',
383 "Enable async mode and start pnum jobs"},
385 #ifndef OPENSSL_NO_ENGINE
386 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
401 #define D_CBC_IDEA 10
402 #define D_CBC_SEED 11
406 #define D_CBC_CAST 15
407 #define D_CBC_128_AES 16
408 #define D_CBC_192_AES 17
409 #define D_CBC_256_AES 18
410 #define D_CBC_128_CML 19
411 #define D_CBC_192_CML 20
412 #define D_CBC_256_CML 21
416 #define D_WHIRLPOOL 25
417 #define D_IGE_128_AES 26
418 #define D_IGE_192_AES 27
419 #define D_IGE_256_AES 28
421 static OPT_PAIR doit_choices[] = {
422 #ifndef OPENSSL_NO_MD2
425 #ifndef OPENSSL_NO_MDC2
428 #ifndef OPENSSL_NO_MD4
431 #ifndef OPENSSL_NO_MD5
436 {"sha256", D_SHA256},
437 {"sha512", D_SHA512},
438 #ifndef OPENSSL_NO_WHIRLPOOL
439 {"whirlpool", D_WHIRLPOOL},
441 #ifndef OPENSSL_NO_RMD160
442 {"ripemd", D_RMD160},
443 {"rmd160", D_RMD160},
444 {"ripemd160", D_RMD160},
446 #ifndef OPENSSL_NO_RC4
449 #ifndef OPENSSL_NO_DES
450 {"des-cbc", D_CBC_DES},
451 {"des-ede3", D_EDE3_DES},
453 {"aes-128-cbc", D_CBC_128_AES},
454 {"aes-192-cbc", D_CBC_192_AES},
455 {"aes-256-cbc", D_CBC_256_AES},
456 {"aes-128-ige", D_IGE_128_AES},
457 {"aes-192-ige", D_IGE_192_AES},
458 {"aes-256-ige", D_IGE_256_AES},
459 #ifndef OPENSSL_NO_RC2
460 {"rc2-cbc", D_CBC_RC2},
463 #ifndef OPENSSL_NO_RC5
464 {"rc5-cbc", D_CBC_RC5},
467 #ifndef OPENSSL_NO_IDEA
468 {"idea-cbc", D_CBC_IDEA},
469 {"idea", D_CBC_IDEA},
471 #ifndef OPENSSL_NO_SEED
472 {"seed-cbc", D_CBC_SEED},
473 {"seed", D_CBC_SEED},
475 #ifndef OPENSSL_NO_BF
476 {"bf-cbc", D_CBC_BF},
477 {"blowfish", D_CBC_BF},
480 #ifndef OPENSSL_NO_CAST
481 {"cast-cbc", D_CBC_CAST},
482 {"cast", D_CBC_CAST},
483 {"cast5", D_CBC_CAST},
489 #ifndef OPENSSL_NO_DSA
491 # define R_DSA_1024 1
492 # define R_DSA_2048 2
493 static OPT_PAIR dsa_choices[] = {
494 {"dsa512", R_DSA_512},
495 {"dsa1024", R_DSA_1024},
496 {"dsa2048", R_DSA_2048},
507 #define R_RSA_15360 6
508 static OPT_PAIR rsa_choices[] = {
509 {"rsa512", R_RSA_512},
510 {"rsa1024", R_RSA_1024},
511 {"rsa2048", R_RSA_2048},
512 {"rsa3072", R_RSA_3072},
513 {"rsa4096", R_RSA_4096},
514 {"rsa7680", R_RSA_7680},
515 {"rsa15360", R_RSA_15360},
535 #define R_EC_X25519 16
536 #ifndef OPENSSL_NO_EC
537 static OPT_PAIR ecdsa_choices[] = {
538 {"ecdsap160", R_EC_P160},
539 {"ecdsap192", R_EC_P192},
540 {"ecdsap224", R_EC_P224},
541 {"ecdsap256", R_EC_P256},
542 {"ecdsap384", R_EC_P384},
543 {"ecdsap521", R_EC_P521},
544 {"ecdsak163", R_EC_K163},
545 {"ecdsak233", R_EC_K233},
546 {"ecdsak283", R_EC_K283},
547 {"ecdsak409", R_EC_K409},
548 {"ecdsak571", R_EC_K571},
549 {"ecdsab163", R_EC_B163},
550 {"ecdsab233", R_EC_B233},
551 {"ecdsab283", R_EC_B283},
552 {"ecdsab409", R_EC_B409},
553 {"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 /* Nb of iterations to do per algorithm and key-size */
590 static long c[ALGOR_NUM][SIZE_NUM];
592 #ifndef OPENSSL_NO_MD2
593 static int EVP_Digest_MD2_loop(void *args)
595 loopargs_t *tempargs = *(loopargs_t **) args;
596 unsigned char *buf = tempargs->buf;
597 unsigned char md2[MD2_DIGEST_LENGTH];
600 for (count = 0; COND(c[D_MD2][testnum]); count++) {
601 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
609 #ifndef OPENSSL_NO_MDC2
610 static int EVP_Digest_MDC2_loop(void *args)
612 loopargs_t *tempargs = *(loopargs_t **) args;
613 unsigned char *buf = tempargs->buf;
614 unsigned char mdc2[MDC2_DIGEST_LENGTH];
617 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
618 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
626 #ifndef OPENSSL_NO_MD4
627 static int EVP_Digest_MD4_loop(void *args)
629 loopargs_t *tempargs = *(loopargs_t **) args;
630 unsigned char *buf = tempargs->buf;
631 unsigned char md4[MD4_DIGEST_LENGTH];
634 for (count = 0; COND(c[D_MD4][testnum]); count++) {
635 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
643 #ifndef OPENSSL_NO_MD5
644 static int MD5_loop(void *args)
646 loopargs_t *tempargs = *(loopargs_t **) args;
647 unsigned char *buf = tempargs->buf;
648 unsigned char md5[MD5_DIGEST_LENGTH];
650 for (count = 0; COND(c[D_MD5][testnum]); count++)
651 MD5(buf, lengths[testnum], md5);
655 static int HMAC_loop(void *args)
657 loopargs_t *tempargs = *(loopargs_t **) args;
658 unsigned char *buf = tempargs->buf;
659 HMAC_CTX *hctx = tempargs->hctx;
660 unsigned char hmac[MD5_DIGEST_LENGTH];
663 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
664 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
665 HMAC_Update(hctx, buf, lengths[testnum]);
666 HMAC_Final(hctx, hmac, NULL);
672 static int SHA1_loop(void *args)
674 loopargs_t *tempargs = *(loopargs_t **) args;
675 unsigned char *buf = tempargs->buf;
676 unsigned char sha[SHA_DIGEST_LENGTH];
678 for (count = 0; COND(c[D_SHA1][testnum]); count++)
679 SHA1(buf, lengths[testnum], sha);
683 static int SHA256_loop(void *args)
685 loopargs_t *tempargs = *(loopargs_t **) args;
686 unsigned char *buf = tempargs->buf;
687 unsigned char sha256[SHA256_DIGEST_LENGTH];
689 for (count = 0; COND(c[D_SHA256][testnum]); count++)
690 SHA256(buf, lengths[testnum], sha256);
694 static int SHA512_loop(void *args)
696 loopargs_t *tempargs = *(loopargs_t **) args;
697 unsigned char *buf = tempargs->buf;
698 unsigned char sha512[SHA512_DIGEST_LENGTH];
700 for (count = 0; COND(c[D_SHA512][testnum]); count++)
701 SHA512(buf, lengths[testnum], sha512);
705 #ifndef OPENSSL_NO_WHIRLPOOL
706 static int WHIRLPOOL_loop(void *args)
708 loopargs_t *tempargs = *(loopargs_t **) args;
709 unsigned char *buf = tempargs->buf;
710 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
712 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
713 WHIRLPOOL(buf, lengths[testnum], whirlpool);
718 #ifndef OPENSSL_NO_RMD160
719 static int EVP_Digest_RMD160_loop(void *args)
721 loopargs_t *tempargs = *(loopargs_t **) args;
722 unsigned char *buf = tempargs->buf;
723 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
725 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
726 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
727 NULL, EVP_ripemd160(), NULL))
734 #ifndef OPENSSL_NO_RC4
735 static RC4_KEY rc4_ks;
736 static int RC4_loop(void *args)
738 loopargs_t *tempargs = *(loopargs_t **) args;
739 unsigned char *buf = tempargs->buf;
741 for (count = 0; COND(c[D_RC4][testnum]); count++)
742 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
747 #ifndef OPENSSL_NO_DES
748 static unsigned char DES_iv[8];
749 static DES_key_schedule sch;
750 static DES_key_schedule sch2;
751 static DES_key_schedule sch3;
752 static int DES_ncbc_encrypt_loop(void *args)
754 loopargs_t *tempargs = *(loopargs_t **) args;
755 unsigned char *buf = tempargs->buf;
757 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
758 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
759 &DES_iv, DES_ENCRYPT);
763 static int DES_ede3_cbc_encrypt_loop(void *args)
765 loopargs_t *tempargs = *(loopargs_t **) args;
766 unsigned char *buf = tempargs->buf;
768 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
769 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
770 &sch, &sch2, &sch3, &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, iv, AES_ENCRYPT);
790 static int AES_cbc_192_encrypt_loop(void *args)
792 loopargs_t *tempargs = *(loopargs_t **) args;
793 unsigned char *buf = tempargs->buf;
795 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
796 AES_cbc_encrypt(buf, buf,
797 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
801 static int AES_cbc_256_encrypt_loop(void *args)
803 loopargs_t *tempargs = *(loopargs_t **) args;
804 unsigned char *buf = tempargs->buf;
806 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
807 AES_cbc_encrypt(buf, buf,
808 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
812 static int AES_ige_128_encrypt_loop(void *args)
814 loopargs_t *tempargs = *(loopargs_t **) args;
815 unsigned char *buf = tempargs->buf;
816 unsigned char *buf2 = tempargs->buf2;
818 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
819 AES_ige_encrypt(buf, buf2,
820 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
824 static int AES_ige_192_encrypt_loop(void *args)
826 loopargs_t *tempargs = *(loopargs_t **) args;
827 unsigned char *buf = tempargs->buf;
828 unsigned char *buf2 = tempargs->buf2;
830 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
831 AES_ige_encrypt(buf, buf2,
832 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
836 static int AES_ige_256_encrypt_loop(void *args)
838 loopargs_t *tempargs = *(loopargs_t **) args;
839 unsigned char *buf = tempargs->buf;
840 unsigned char *buf2 = tempargs->buf2;
842 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
843 AES_ige_encrypt(buf, buf2,
844 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
848 static int CRYPTO_gcm128_aad_loop(void *args)
850 loopargs_t *tempargs = *(loopargs_t **) args;
851 unsigned char *buf = tempargs->buf;
852 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
854 for (count = 0; COND(c[D_GHASH][testnum]); count++)
855 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
859 static long save_count = 0;
860 static int decrypt = 0;
861 static int EVP_Update_loop(void *args)
863 loopargs_t *tempargs = *(loopargs_t **) args;
864 unsigned char *buf = tempargs->buf;
865 EVP_CIPHER_CTX *ctx = tempargs->ctx;
868 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
871 for (count = 0; COND(nb_iter); count++)
872 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
874 for (count = 0; COND(nb_iter); count++)
875 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
877 EVP_DecryptFinal_ex(ctx, buf, &outl);
879 EVP_EncryptFinal_ex(ctx, buf, &outl);
883 static const EVP_MD *evp_md = NULL;
884 static int EVP_Digest_loop(void *args)
886 loopargs_t *tempargs = *(loopargs_t **) args;
887 unsigned char *buf = tempargs->buf;
888 unsigned char md[EVP_MAX_MD_SIZE];
891 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
894 for (count = 0; COND(nb_iter); count++) {
895 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
901 #ifndef OPENSSL_NO_RSA
902 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
904 static int RSA_sign_loop(void *args)
906 loopargs_t *tempargs = *(loopargs_t **) args;
907 unsigned char *buf = tempargs->buf;
908 unsigned char *buf2 = tempargs->buf2;
909 unsigned int *rsa_num = &tempargs->siglen;
910 RSA **rsa_key = tempargs->rsa_key;
912 for (count = 0; COND(rsa_c[testnum][0]); count++) {
913 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
915 BIO_printf(bio_err, "RSA sign failure\n");
916 ERR_print_errors(bio_err);
924 static int RSA_verify_loop(void *args)
926 loopargs_t *tempargs = *(loopargs_t **) args;
927 unsigned char *buf = tempargs->buf;
928 unsigned char *buf2 = tempargs->buf2;
929 unsigned int rsa_num = tempargs->siglen;
930 RSA **rsa_key = tempargs->rsa_key;
932 for (count = 0; COND(rsa_c[testnum][1]); count++) {
934 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
936 BIO_printf(bio_err, "RSA verify failure\n");
937 ERR_print_errors(bio_err);
946 #ifndef OPENSSL_NO_DSA
947 static long dsa_c[DSA_NUM][2];
948 static int DSA_sign_loop(void *args)
950 loopargs_t *tempargs = *(loopargs_t **) args;
951 unsigned char *buf = tempargs->buf;
952 unsigned char *buf2 = tempargs->buf2;
953 DSA **dsa_key = tempargs->dsa_key;
954 unsigned int *siglen = &tempargs->siglen;
956 for (count = 0; COND(dsa_c[testnum][0]); count++) {
957 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
959 BIO_printf(bio_err, "DSA sign failure\n");
960 ERR_print_errors(bio_err);
968 static int DSA_verify_loop(void *args)
970 loopargs_t *tempargs = *(loopargs_t **) args;
971 unsigned char *buf = tempargs->buf;
972 unsigned char *buf2 = tempargs->buf2;
973 DSA **dsa_key = tempargs->dsa_key;
974 unsigned int siglen = tempargs->siglen;
976 for (count = 0; COND(dsa_c[testnum][1]); count++) {
977 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
979 BIO_printf(bio_err, "DSA verify failure\n");
980 ERR_print_errors(bio_err);
989 #ifndef OPENSSL_NO_EC
990 static long ecdsa_c[EC_NUM][2];
991 static int ECDSA_sign_loop(void *args)
993 loopargs_t *tempargs = *(loopargs_t **) args;
994 unsigned char *buf = tempargs->buf;
995 EC_KEY **ecdsa = tempargs->ecdsa;
996 unsigned char *ecdsasig = tempargs->buf2;
997 unsigned int *ecdsasiglen = &tempargs->siglen;
999 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1000 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1002 BIO_printf(bio_err, "ECDSA sign failure\n");
1003 ERR_print_errors(bio_err);
1011 static int ECDSA_verify_loop(void *args)
1013 loopargs_t *tempargs = *(loopargs_t **) args;
1014 unsigned char *buf = tempargs->buf;
1015 EC_KEY **ecdsa = tempargs->ecdsa;
1016 unsigned char *ecdsasig = tempargs->buf2;
1017 unsigned int ecdsasiglen = tempargs->siglen;
1019 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1020 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1022 BIO_printf(bio_err, "ECDSA verify failure\n");
1023 ERR_print_errors(bio_err);
1031 /* ******************************************************************** */
1032 static long ecdh_c[EC_NUM][1];
1034 static int ECDH_EVP_derive_key_loop(void *args)
1036 loopargs_t *tempargs = *(loopargs_t **) args;
1037 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1038 unsigned char *derived_secret = tempargs->secret_a;
1040 size_t *outlen = &(tempargs->outlen[testnum]);
1042 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1043 EVP_PKEY_derive(ctx, derived_secret, outlen);
1048 #endif /* OPENSSL_NO_EC */
1050 static int run_benchmark(int async_jobs,
1051 int (*loop_function) (void *), loopargs_t * loopargs)
1053 int job_op_count = 0;
1054 int total_op_count = 0;
1055 int num_inprogress = 0;
1056 int error = 0, i = 0, ret = 0;
1057 OSSL_ASYNC_FD job_fd = 0;
1058 size_t num_job_fds = 0;
1062 if (async_jobs == 0) {
1063 return loop_function((void *)&loopargs);
1066 for (i = 0; i < async_jobs && !error; i++) {
1067 loopargs_t *looparg_item = loopargs + i;
1069 /* Copy pointer content (looparg_t item address) into async context */
1070 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1071 &job_op_count, loop_function,
1072 (void *)&looparg_item, sizeof(looparg_item));
1078 if (job_op_count == -1) {
1081 total_op_count += job_op_count;
1086 BIO_printf(bio_err, "Failure in the job\n");
1087 ERR_print_errors(bio_err);
1093 while (num_inprogress > 0) {
1094 #if defined(OPENSSL_SYS_WINDOWS)
1096 #elif defined(OPENSSL_SYS_UNIX)
1097 int select_result = 0;
1098 OSSL_ASYNC_FD max_fd = 0;
1101 FD_ZERO(&waitfdset);
1103 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1104 if (loopargs[i].inprogress_job == NULL)
1107 if (!ASYNC_WAIT_CTX_get_all_fds
1108 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1109 || num_job_fds > 1) {
1110 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1111 ERR_print_errors(bio_err);
1115 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1117 FD_SET(job_fd, &waitfdset);
1118 if (job_fd > max_fd)
1122 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1124 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1125 "Decrease the value of async_jobs\n",
1126 max_fd, FD_SETSIZE);
1127 ERR_print_errors(bio_err);
1132 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1133 if (select_result == -1 && errno == EINTR)
1136 if (select_result == -1) {
1137 BIO_printf(bio_err, "Failure in the select\n");
1138 ERR_print_errors(bio_err);
1143 if (select_result == 0)
1147 for (i = 0; i < async_jobs; i++) {
1148 if (loopargs[i].inprogress_job == NULL)
1151 if (!ASYNC_WAIT_CTX_get_all_fds
1152 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1153 || num_job_fds > 1) {
1154 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1155 ERR_print_errors(bio_err);
1159 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1162 #if defined(OPENSSL_SYS_UNIX)
1163 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1165 #elif defined(OPENSSL_SYS_WINDOWS)
1166 if (num_job_fds == 1
1167 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1172 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1173 loopargs[i].wait_ctx, &job_op_count,
1174 loop_function, (void *)(loopargs + i),
1175 sizeof(loopargs_t));
1180 if (job_op_count == -1) {
1183 total_op_count += job_op_count;
1186 loopargs[i].inprogress_job = NULL;
1191 loopargs[i].inprogress_job = NULL;
1192 BIO_printf(bio_err, "Failure in the job\n");
1193 ERR_print_errors(bio_err);
1200 return error ? -1 : total_op_count;
1203 int speed_main(int argc, char **argv)
1206 loopargs_t *loopargs = NULL;
1208 int loopargs_len = 0;
1210 const char *engine_id = NULL;
1211 const EVP_CIPHER *evp_cipher = NULL;
1214 int multiblock = 0, pr_header = 0;
1215 int doit[ALGOR_NUM] = { 0 };
1216 int ret = 1, i, k, misalign = 0;
1222 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1223 || !defined(OPENSSL_NO_EC)
1227 /* What follows are the buffers and key material. */
1228 #ifndef OPENSSL_NO_RC5
1231 #ifndef OPENSSL_NO_RC2
1234 #ifndef OPENSSL_NO_IDEA
1235 IDEA_KEY_SCHEDULE idea_ks;
1237 #ifndef OPENSSL_NO_SEED
1238 SEED_KEY_SCHEDULE seed_ks;
1240 #ifndef OPENSSL_NO_BF
1243 #ifndef OPENSSL_NO_CAST
1246 static const unsigned char key16[16] = {
1247 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1248 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1250 static const unsigned char key24[24] = {
1251 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1252 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1253 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1255 static const unsigned char key32[32] = {
1256 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1257 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1258 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1259 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1261 #ifndef OPENSSL_NO_CAMELLIA
1262 static const unsigned char ckey24[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 ckey32[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 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1275 #ifndef OPENSSL_NO_DES
1276 static DES_cblock key = {
1277 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1279 static DES_cblock key2 = {
1280 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1282 static DES_cblock key3 = {
1283 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1286 #ifndef OPENSSL_NO_RSA
1287 static const unsigned int rsa_bits[RSA_NUM] = {
1288 512, 1024, 2048, 3072, 4096, 7680, 15360
1290 static const unsigned char *rsa_data[RSA_NUM] = {
1291 test512, test1024, test2048, test3072, test4096, test7680, test15360
1293 static const int rsa_data_length[RSA_NUM] = {
1294 sizeof(test512), sizeof(test1024),
1295 sizeof(test2048), sizeof(test3072),
1296 sizeof(test4096), sizeof(test7680),
1299 int rsa_doit[RSA_NUM] = { 0 };
1301 #ifndef OPENSSL_NO_DSA
1302 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1303 int dsa_doit[DSA_NUM] = { 0 };
1305 #ifndef OPENSSL_NO_EC
1307 * We only test over the following curves as they are representative, To
1308 * add tests over more curves, simply add the curve NID and curve name to
1309 * the following arrays and increase the EC_NUM value accordingly.
1311 static const unsigned int test_curves[EC_NUM] = {
1313 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1314 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1316 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1317 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1318 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1323 static const char *test_curves_names[EC_NUM] = {
1325 "secp160r1", "nistp192", "nistp224",
1326 "nistp256", "nistp384", "nistp521",
1328 "nistk163", "nistk233", "nistk283",
1329 "nistk409", "nistk571", "nistb163",
1330 "nistb233", "nistb283", "nistb409",
1335 static const int test_curves_bits[EC_NUM] = {
1341 571, 253 /* X25519 */
1344 int ecdsa_doit[EC_NUM] = { 0 };
1345 int ecdh_doit[EC_NUM] = { 0 };
1346 #endif /* ndef OPENSSL_NO_EC */
1348 prog = opt_init(argc, argv, speed_options);
1349 while ((o = opt_next()) != OPT_EOF) {
1354 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1357 opt_help(speed_options);
1364 evp_cipher = EVP_get_cipherbyname(opt_arg());
1365 if (evp_cipher == NULL)
1366 evp_md = EVP_get_digestbyname(opt_arg());
1367 if (evp_cipher == NULL && evp_md == NULL) {
1369 "%s: %s is an unknown cipher or digest\n",
1380 * In a forked execution, an engine might need to be
1381 * initialised by each child process, not by the parent.
1382 * So store the name here and run setup_engine() later on.
1384 engine_id = opt_arg();
1388 multi = atoi(opt_arg());
1392 #ifndef OPENSSL_NO_ASYNC
1393 async_jobs = atoi(opt_arg());
1394 if (!ASYNC_is_capable()) {
1396 "%s: async_jobs specified but async not supported\n",
1403 if (!opt_int(opt_arg(), &misalign))
1405 if (misalign > MISALIGN) {
1407 "%s: Maximum offset is %d\n", prog, MISALIGN);
1416 #ifdef OPENSSL_NO_MULTIBLOCK
1418 "%s: -mb specified but multi-block support is disabled\n",
1425 argc = opt_num_rest();
1428 /* Remaining arguments are algorithms. */
1429 for (; *argv; argv++) {
1430 if (found(*argv, doit_choices, &i)) {
1434 #ifndef OPENSSL_NO_DES
1435 if (strcmp(*argv, "des") == 0) {
1436 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1440 if (strcmp(*argv, "sha") == 0) {
1441 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1444 #ifndef OPENSSL_NO_RSA
1446 if (strcmp(*argv, "openssl") == 0) {
1447 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1451 if (strcmp(*argv, "rsa") == 0) {
1452 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1453 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1454 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1455 rsa_doit[R_RSA_15360] = 1;
1458 if (found(*argv, rsa_choices, &i)) {
1463 #ifndef OPENSSL_NO_DSA
1464 if (strcmp(*argv, "dsa") == 0) {
1465 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1466 dsa_doit[R_DSA_2048] = 1;
1469 if (found(*argv, dsa_choices, &i)) {
1474 if (strcmp(*argv, "aes") == 0) {
1475 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1478 #ifndef OPENSSL_NO_CAMELLIA
1479 if (strcmp(*argv, "camellia") == 0) {
1480 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1484 #ifndef OPENSSL_NO_EC
1485 if (strcmp(*argv, "ecdsa") == 0) {
1486 for (i = 0; i < EC_NUM; i++)
1490 if (found(*argv, ecdsa_choices, &i)) {
1494 if (strcmp(*argv, "ecdh") == 0) {
1495 for (i = 0; i < EC_NUM; i++)
1499 if (found(*argv, ecdh_choices, &i)) {
1504 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1508 /* Initialize the job pool if async mode is enabled */
1509 if (async_jobs > 0) {
1510 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1512 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1517 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1519 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1520 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1522 for (i = 0; i < loopargs_len; i++) {
1523 if (async_jobs > 0) {
1524 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1525 if (loopargs[i].wait_ctx == NULL) {
1526 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1531 loopargs[i].buf_malloc =
1532 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1533 loopargs[i].buf2_malloc =
1534 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1535 /* Align the start of buffers on a 64 byte boundary */
1536 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1537 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1538 #ifndef OPENSSL_NO_EC
1539 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1540 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1545 if (multi && do_multi(multi))
1549 /* Initialize the engine after the fork */
1550 e = setup_engine(engine_id, 0);
1552 /* No parameters; turn on everything. */
1553 if ((argc == 0) && !doit[D_EVP]) {
1554 for (i = 0; i < ALGOR_NUM; i++)
1557 #ifndef OPENSSL_NO_RSA
1558 for (i = 0; i < RSA_NUM; i++)
1561 #ifndef OPENSSL_NO_DSA
1562 for (i = 0; i < DSA_NUM; i++)
1565 #ifndef OPENSSL_NO_EC
1566 for (i = 0; i < EC_NUM; i++)
1568 for (i = 0; i < EC_NUM; i++)
1572 for (i = 0; i < ALGOR_NUM; i++)
1576 if (usertime == 0 && !mr)
1578 "You have chosen to measure elapsed time "
1579 "instead of user CPU time.\n");
1581 #ifndef OPENSSL_NO_RSA
1582 for (i = 0; i < loopargs_len; i++) {
1583 for (k = 0; k < RSA_NUM; k++) {
1584 const unsigned char *p;
1587 loopargs[i].rsa_key[k] =
1588 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1589 if (loopargs[i].rsa_key[k] == NULL) {
1591 "internal error loading RSA key number %d\n", k);
1597 #ifndef OPENSSL_NO_DSA
1598 for (i = 0; i < loopargs_len; i++) {
1599 loopargs[i].dsa_key[0] = get_dsa512();
1600 loopargs[i].dsa_key[1] = get_dsa1024();
1601 loopargs[i].dsa_key[2] = get_dsa2048();
1604 #ifndef OPENSSL_NO_DES
1605 DES_set_key_unchecked(&key, &sch);
1606 DES_set_key_unchecked(&key2, &sch2);
1607 DES_set_key_unchecked(&key3, &sch3);
1609 AES_set_encrypt_key(key16, 128, &aes_ks1);
1610 AES_set_encrypt_key(key24, 192, &aes_ks2);
1611 AES_set_encrypt_key(key32, 256, &aes_ks3);
1612 #ifndef OPENSSL_NO_CAMELLIA
1613 Camellia_set_key(key16, 128, &camellia_ks1);
1614 Camellia_set_key(ckey24, 192, &camellia_ks2);
1615 Camellia_set_key(ckey32, 256, &camellia_ks3);
1617 #ifndef OPENSSL_NO_IDEA
1618 IDEA_set_encrypt_key(key16, &idea_ks);
1620 #ifndef OPENSSL_NO_SEED
1621 SEED_set_key(key16, &seed_ks);
1623 #ifndef OPENSSL_NO_RC4
1624 RC4_set_key(&rc4_ks, 16, key16);
1626 #ifndef OPENSSL_NO_RC2
1627 RC2_set_key(&rc2_ks, 16, key16, 128);
1629 #ifndef OPENSSL_NO_RC5
1630 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1632 #ifndef OPENSSL_NO_BF
1633 BF_set_key(&bf_ks, 16, key16);
1635 #ifndef OPENSSL_NO_CAST
1636 CAST_set_key(&cast_ks, 16, key16);
1639 # ifndef OPENSSL_NO_DES
1640 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1646 for (it = count; it; it--)
1647 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1648 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1652 c[D_MD2][0] = count / 10;
1653 c[D_MDC2][0] = count / 10;
1654 c[D_MD4][0] = count;
1655 c[D_MD5][0] = count;
1656 c[D_HMAC][0] = count;
1657 c[D_SHA1][0] = count;
1658 c[D_RMD160][0] = count;
1659 c[D_RC4][0] = count * 5;
1660 c[D_CBC_DES][0] = count;
1661 c[D_EDE3_DES][0] = count / 3;
1662 c[D_CBC_IDEA][0] = count;
1663 c[D_CBC_SEED][0] = count;
1664 c[D_CBC_RC2][0] = count;
1665 c[D_CBC_RC5][0] = count;
1666 c[D_CBC_BF][0] = count;
1667 c[D_CBC_CAST][0] = count;
1668 c[D_CBC_128_AES][0] = count;
1669 c[D_CBC_192_AES][0] = count;
1670 c[D_CBC_256_AES][0] = count;
1671 c[D_CBC_128_CML][0] = count;
1672 c[D_CBC_192_CML][0] = count;
1673 c[D_CBC_256_CML][0] = count;
1674 c[D_SHA256][0] = count;
1675 c[D_SHA512][0] = count;
1676 c[D_WHIRLPOOL][0] = count;
1677 c[D_IGE_128_AES][0] = count;
1678 c[D_IGE_192_AES][0] = count;
1679 c[D_IGE_256_AES][0] = count;
1680 c[D_GHASH][0] = count;
1682 for (i = 1; i < SIZE_NUM; i++) {
1685 l0 = (long)lengths[0];
1686 l1 = (long)lengths[i];
1688 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1689 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1690 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1691 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1692 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1693 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1694 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1695 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1696 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1697 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1698 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1700 l0 = (long)lengths[i - 1];
1702 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1703 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1704 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1705 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1706 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1707 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1708 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1709 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1710 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1711 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1712 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1713 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1714 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1715 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1716 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1717 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1718 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1719 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1722 # ifndef OPENSSL_NO_RSA
1723 rsa_c[R_RSA_512][0] = count / 2000;
1724 rsa_c[R_RSA_512][1] = count / 400;
1725 for (i = 1; i < RSA_NUM; i++) {
1726 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1727 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1728 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1731 if (rsa_c[i][0] == 0) {
1732 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1739 # ifndef OPENSSL_NO_DSA
1740 dsa_c[R_DSA_512][0] = count / 1000;
1741 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1742 for (i = 1; i < DSA_NUM; i++) {
1743 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1744 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1745 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1748 if (dsa_c[i][0] == 0) {
1749 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1756 # ifndef OPENSSL_NO_EC
1757 ecdsa_c[R_EC_P160][0] = count / 1000;
1758 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1759 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1760 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1761 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1762 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1765 if (ecdsa_c[i][0] == 0) {
1771 ecdsa_c[R_EC_K163][0] = count / 1000;
1772 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1773 for (i = R_EC_K233; i <= R_EC_K571; 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_B163][0] = count / 1000;
1786 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1787 for (i = R_EC_B233; i <= R_EC_B571; 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) {
1800 ecdh_c[R_EC_P160][0] = count / 1000;
1801 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1802 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1803 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1806 if (ecdh_c[i][0] == 0) {
1811 ecdh_c[R_EC_K163][0] = count / 1000;
1812 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1813 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1814 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1817 if (ecdh_c[i][0] == 0) {
1822 ecdh_c[R_EC_B163][0] = count / 1000;
1823 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1824 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1825 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1828 if (ecdh_c[i][0] == 0) {
1836 /* not worth fixing */
1837 # error "You cannot disable DES on systems without SIGALRM."
1838 # endif /* OPENSSL_NO_DES */
1841 signal(SIGALRM, sig_done);
1843 #endif /* SIGALRM */
1845 #ifndef OPENSSL_NO_MD2
1847 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1848 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1850 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1852 print_result(D_MD2, testnum, count, d);
1856 #ifndef OPENSSL_NO_MDC2
1858 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1859 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1861 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1863 print_result(D_MDC2, testnum, count, d);
1868 #ifndef OPENSSL_NO_MD4
1870 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1871 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1873 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1875 print_result(D_MD4, testnum, count, d);
1880 #ifndef OPENSSL_NO_MD5
1882 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1883 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1885 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1887 print_result(D_MD5, testnum, count, d);
1892 static const char hmac_key[] = "This is a key...";
1893 int len = strlen(hmac_key);
1895 for (i = 0; i < loopargs_len; i++) {
1896 loopargs[i].hctx = HMAC_CTX_new();
1897 if (loopargs[i].hctx == NULL) {
1898 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1902 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1904 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1905 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1907 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1909 print_result(D_HMAC, testnum, count, d);
1911 for (i = 0; i < loopargs_len; i++) {
1912 HMAC_CTX_free(loopargs[i].hctx);
1917 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1918 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1920 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1922 print_result(D_SHA1, testnum, count, d);
1925 if (doit[D_SHA256]) {
1926 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1927 print_message(names[D_SHA256], c[D_SHA256][testnum],
1930 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1932 print_result(D_SHA256, testnum, count, d);
1935 if (doit[D_SHA512]) {
1936 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1937 print_message(names[D_SHA512], c[D_SHA512][testnum],
1940 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1942 print_result(D_SHA512, testnum, count, d);
1945 #ifndef OPENSSL_NO_WHIRLPOOL
1946 if (doit[D_WHIRLPOOL]) {
1947 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1948 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1951 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1953 print_result(D_WHIRLPOOL, testnum, count, d);
1958 #ifndef OPENSSL_NO_RMD160
1959 if (doit[D_RMD160]) {
1960 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1961 print_message(names[D_RMD160], c[D_RMD160][testnum],
1964 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1966 print_result(D_RMD160, testnum, count, d);
1970 #ifndef OPENSSL_NO_RC4
1972 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1973 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1975 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1977 print_result(D_RC4, testnum, count, d);
1981 #ifndef OPENSSL_NO_DES
1982 if (doit[D_CBC_DES]) {
1983 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1984 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
1987 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1989 print_result(D_CBC_DES, testnum, count, d);
1993 if (doit[D_EDE3_DES]) {
1994 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1995 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
1999 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2001 print_result(D_EDE3_DES, testnum, count, d);
2006 if (doit[D_CBC_128_AES]) {
2007 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2008 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2012 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],
2023 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2025 print_result(D_CBC_192_AES, testnum, count, d);
2028 if (doit[D_CBC_256_AES]) {
2029 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2030 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2034 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2036 print_result(D_CBC_256_AES, testnum, count, d);
2040 if (doit[D_IGE_128_AES]) {
2041 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2042 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2046 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2048 print_result(D_IGE_128_AES, testnum, count, d);
2051 if (doit[D_IGE_192_AES]) {
2052 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2053 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2057 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2059 print_result(D_IGE_192_AES, testnum, count, d);
2062 if (doit[D_IGE_256_AES]) {
2063 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2064 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2068 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2070 print_result(D_IGE_256_AES, testnum, count, d);
2073 if (doit[D_GHASH]) {
2074 for (i = 0; i < loopargs_len; i++) {
2075 loopargs[i].gcm_ctx =
2076 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2077 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2078 (unsigned char *)"0123456789ab", 12);
2081 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2082 print_message(names[D_GHASH], c[D_GHASH][testnum],
2085 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2087 print_result(D_GHASH, testnum, count, d);
2089 for (i = 0; i < loopargs_len; i++)
2090 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],
2163 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2164 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2165 (size_t)lengths[testnum], &idea_ks,
2168 print_result(D_CBC_IDEA, testnum, count, d);
2172 #ifndef OPENSSL_NO_SEED
2173 if (doit[D_CBC_SEED]) {
2174 if (async_jobs > 0) {
2175 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2177 doit[D_CBC_SEED] = 0;
2179 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2180 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2183 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2184 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2185 (size_t)lengths[testnum], &seed_ks, iv, 1);
2187 print_result(D_CBC_SEED, testnum, count, d);
2191 #ifndef OPENSSL_NO_RC2
2192 if (doit[D_CBC_RC2]) {
2193 if (async_jobs > 0) {
2194 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2196 doit[D_CBC_RC2] = 0;
2198 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2199 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2201 if (async_jobs > 0) {
2202 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2206 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2207 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2208 (size_t)lengths[testnum], &rc2_ks,
2211 print_result(D_CBC_RC2, testnum, count, d);
2215 #ifndef OPENSSL_NO_RC5
2216 if (doit[D_CBC_RC5]) {
2217 if (async_jobs > 0) {
2218 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2220 doit[D_CBC_RC5] = 0;
2222 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2223 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2225 if (async_jobs > 0) {
2226 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2230 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2231 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2232 (size_t)lengths[testnum], &rc5_ks,
2235 print_result(D_CBC_RC5, testnum, count, d);
2239 #ifndef OPENSSL_NO_BF
2240 if (doit[D_CBC_BF]) {
2241 if (async_jobs > 0) {
2242 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2246 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2247 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2250 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2251 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2252 (size_t)lengths[testnum], &bf_ks,
2255 print_result(D_CBC_BF, testnum, count, d);
2259 #ifndef OPENSSL_NO_CAST
2260 if (doit[D_CBC_CAST]) {
2261 if (async_jobs > 0) {
2262 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2264 doit[D_CBC_CAST] = 0;
2266 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2267 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2270 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2271 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2272 (size_t)lengths[testnum], &cast_ks,
2275 print_result(D_CBC_CAST, testnum, count, d);
2281 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2282 if (multiblock && evp_cipher) {
2284 (EVP_CIPHER_flags(evp_cipher) &
2285 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2286 BIO_printf(bio_err, "%s is not multi-block capable\n",
2287 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2290 if (async_jobs > 0) {
2291 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2294 multiblock_speed(evp_cipher);
2299 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2302 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2304 * -O3 -fschedule-insns messes up an optimization here!
2305 * names[D_EVP] somehow becomes NULL
2307 print_message(names[D_EVP], save_count, lengths[testnum]);
2309 for (k = 0; k < loopargs_len; k++) {
2310 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2312 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2315 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2317 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2321 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2323 for (k = 0; k < loopargs_len; k++) {
2324 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2328 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2329 print_message(names[D_EVP], save_count, lengths[testnum]);
2331 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2334 print_result(D_EVP, testnum, count, d);
2338 for (i = 0; i < loopargs_len; i++)
2339 RAND_bytes(loopargs[i].buf, 36);
2341 #ifndef OPENSSL_NO_RSA
2342 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2344 if (!rsa_doit[testnum])
2346 for (i = 0; i < loopargs_len; i++) {
2347 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2348 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2354 "RSA sign failure. No RSA sign will be done.\n");
2355 ERR_print_errors(bio_err);
2358 pkey_print_message("private", "rsa",
2359 rsa_c[testnum][0], rsa_bits[testnum],
2361 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2363 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2366 mr ? "+R1:%ld:%d:%.2f\n"
2367 : "%ld %d bit private RSA's in %.2fs\n",
2368 count, rsa_bits[testnum], d);
2369 rsa_results[testnum][0] = d / (double)count;
2373 for (i = 0; i < loopargs_len; i++) {
2374 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2375 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2381 "RSA verify failure. No RSA verify will be done.\n");
2382 ERR_print_errors(bio_err);
2383 rsa_doit[testnum] = 0;
2385 pkey_print_message("public", "rsa",
2386 rsa_c[testnum][1], rsa_bits[testnum],
2389 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2392 mr ? "+R2:%ld:%d:%.2f\n"
2393 : "%ld %d bit public RSA's in %.2fs\n",
2394 count, rsa_bits[testnum], d);
2395 rsa_results[testnum][1] = d / (double)count;
2398 if (rsa_count <= 1) {
2399 /* if longer than 10s, don't do any more */
2400 for (testnum++; testnum < RSA_NUM; testnum++)
2401 rsa_doit[testnum] = 0;
2404 #endif /* OPENSSL_NO_RSA */
2406 for (i = 0; i < loopargs_len; i++)
2407 RAND_bytes(loopargs[i].buf, 36);
2409 #ifndef OPENSSL_NO_DSA
2410 if (RAND_status() != 1) {
2411 RAND_seed(rnd_seed, sizeof rnd_seed);
2413 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2415 if (!dsa_doit[testnum])
2418 /* DSA_generate_key(dsa_key[testnum]); */
2419 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2420 for (i = 0; i < loopargs_len; i++) {
2421 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2422 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2428 "DSA sign failure. No DSA sign will be done.\n");
2429 ERR_print_errors(bio_err);
2432 pkey_print_message("sign", "dsa",
2433 dsa_c[testnum][0], dsa_bits[testnum],
2436 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2439 mr ? "+R3:%ld:%d:%.2f\n"
2440 : "%ld %d bit DSA signs in %.2fs\n",
2441 count, dsa_bits[testnum], d);
2442 dsa_results[testnum][0] = d / (double)count;
2446 for (i = 0; i < loopargs_len; i++) {
2447 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2448 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2454 "DSA verify failure. No DSA verify will be done.\n");
2455 ERR_print_errors(bio_err);
2456 dsa_doit[testnum] = 0;
2458 pkey_print_message("verify", "dsa",
2459 dsa_c[testnum][1], dsa_bits[testnum],
2462 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2465 mr ? "+R4:%ld:%d:%.2f\n"
2466 : "%ld %d bit DSA verify in %.2fs\n",
2467 count, dsa_bits[testnum], d);
2468 dsa_results[testnum][1] = d / (double)count;
2471 if (rsa_count <= 1) {
2472 /* if longer than 10s, don't do any more */
2473 for (testnum++; testnum < DSA_NUM; testnum++)
2474 dsa_doit[testnum] = 0;
2477 #endif /* OPENSSL_NO_DSA */
2479 #ifndef OPENSSL_NO_EC
2480 if (RAND_status() != 1) {
2481 RAND_seed(rnd_seed, sizeof rnd_seed);
2483 for (testnum = 0; testnum < EC_NUM; testnum++) {
2486 if (!ecdsa_doit[testnum])
2487 continue; /* Ignore Curve */
2488 for (i = 0; i < loopargs_len; i++) {
2489 loopargs[i].ecdsa[testnum] =
2490 EC_KEY_new_by_curve_name(test_curves[testnum]);
2491 if (loopargs[i].ecdsa[testnum] == NULL) {
2497 BIO_printf(bio_err, "ECDSA failure.\n");
2498 ERR_print_errors(bio_err);
2501 for (i = 0; i < loopargs_len; i++) {
2502 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2503 /* Perform ECDSA signature test */
2504 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2505 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2506 &loopargs[i].siglen,
2507 loopargs[i].ecdsa[testnum]);
2513 "ECDSA sign failure. No ECDSA sign will be done.\n");
2514 ERR_print_errors(bio_err);
2517 pkey_print_message("sign", "ecdsa",
2518 ecdsa_c[testnum][0],
2519 test_curves_bits[testnum], ECDSA_SECONDS);
2521 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2525 mr ? "+R5:%ld:%d:%.2f\n" :
2526 "%ld %d bit ECDSA signs in %.2fs \n",
2527 count, test_curves_bits[testnum], d);
2528 ecdsa_results[testnum][0] = d / (double)count;
2532 /* Perform ECDSA verification test */
2533 for (i = 0; i < loopargs_len; i++) {
2534 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2536 loopargs[i].ecdsa[testnum]);
2542 "ECDSA verify failure. No ECDSA verify will be done.\n");
2543 ERR_print_errors(bio_err);
2544 ecdsa_doit[testnum] = 0;
2546 pkey_print_message("verify", "ecdsa",
2547 ecdsa_c[testnum][1],
2548 test_curves_bits[testnum], ECDSA_SECONDS);
2550 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2553 mr ? "+R6:%ld:%d:%.2f\n"
2554 : "%ld %d bit ECDSA verify in %.2fs\n",
2555 count, test_curves_bits[testnum], d);
2556 ecdsa_results[testnum][1] = d / (double)count;
2559 if (rsa_count <= 1) {
2560 /* if longer than 10s, don't do any more */
2561 for (testnum++; testnum < EC_NUM; testnum++)
2562 ecdsa_doit[testnum] = 0;
2567 if (RAND_status() != 1) {
2568 RAND_seed(rnd_seed, sizeof rnd_seed);
2570 for (testnum = 0; testnum < EC_NUM; testnum++) {
2571 int ecdh_checks = 1;
2573 if (!ecdh_doit[testnum])
2576 for (i = 0; i < loopargs_len; i++) {
2577 EVP_PKEY_CTX *kctx = NULL;
2578 EVP_PKEY_CTX *test_ctx = NULL;
2579 EVP_PKEY_CTX *ctx = NULL;
2580 EVP_PKEY *key_A = NULL;
2581 EVP_PKEY *key_B = NULL;
2585 if (testnum == R_EC_X25519) {
2586 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2588 EVP_PKEY_CTX *pctx = NULL;
2589 EVP_PKEY *params = NULL;
2591 if ( /* Create the context for parameter generation */
2592 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2593 /* Initialise the parameter generation */
2594 !EVP_PKEY_paramgen_init(pctx) ||
2595 /* Set the curve by NID */
2596 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2599 /* Create the parameter object params */
2600 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2602 BIO_printf(bio_err, "ECDH init failure.\n");
2603 ERR_print_errors(bio_err);
2607 /* Create the context for the key generation */
2608 kctx = EVP_PKEY_CTX_new(params, NULL);
2610 EVP_PKEY_free(params);
2612 EVP_PKEY_CTX_free(pctx);
2615 if (!kctx || /* keygen ctx is not null */
2616 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2618 BIO_printf(bio_err, "ECDH keygen failure.\n");
2619 ERR_print_errors(bio_err);
2624 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2625 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2626 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2627 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2628 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2629 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2630 outlen == 0 || /* ensure outlen is a valid size */
2631 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2633 BIO_printf(bio_err, "ECDH key generation failure.\n");
2634 ERR_print_errors(bio_err);
2639 /* Here we perform a test run, comparing the output of a*B and b*A;
2640 * we try this here and assume that further EVP_PKEY_derive calls
2641 * never fail, so we can skip checks in the actually benchmarked
2642 * code, for maximum performance. */
2643 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2644 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2645 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2646 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2647 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2648 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2649 test_outlen != outlen /* compare output length */ ) {
2651 BIO_printf(bio_err, "ECDH computation failure.\n");
2652 ERR_print_errors(bio_err);
2656 for (k = 0; (unsigned int)k < test_outlen && ecdh_checks == 1; k++) {
2657 if (loopargs[i].secret_a[k] != loopargs[i].secret_b[k])
2660 if (ecdh_checks == 0) {
2661 BIO_printf(bio_err, "ECDH computations don't match.\n");
2662 ERR_print_errors(bio_err);
2667 loopargs[i].ecdh_ctx[testnum] = ctx;
2668 loopargs[i].outlen[testnum] = outlen;
2670 EVP_PKEY_CTX_free(kctx);
2672 EVP_PKEY_CTX_free(test_ctx);
2675 if (ecdh_checks != 0) {
2676 pkey_print_message("", "ecdh",
2678 test_curves_bits[testnum], ECDH_SECONDS);
2681 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2684 mr ? "+R7:%ld:%d:%.2f\n" :
2685 "%ld %d-bit ECDH ops in %.2fs\n", count,
2686 test_curves_bits[testnum], d);
2687 ecdh_results[testnum][0] = d / (double)count;
2691 if (rsa_count <= 1) {
2692 /* if longer than 10s, don't do any more */
2693 for (testnum++; testnum < EC_NUM; testnum++)
2694 ecdh_doit[testnum] = 0;
2697 #endif /* OPENSSL_NO_EC */
2702 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2703 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2705 printf("%s ", BN_options());
2706 #ifndef OPENSSL_NO_MD2
2707 printf("%s ", MD2_options());
2709 #ifndef OPENSSL_NO_RC4
2710 printf("%s ", RC4_options());
2712 #ifndef OPENSSL_NO_DES
2713 printf("%s ", DES_options());
2715 printf("%s ", AES_options());
2716 #ifndef OPENSSL_NO_IDEA
2717 printf("%s ", IDEA_options());
2719 #ifndef OPENSSL_NO_BF
2720 printf("%s ", BF_options());
2722 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2730 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2733 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2734 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2738 for (k = 0; k < ALGOR_NUM; k++) {
2742 printf("+F:%d:%s", k, names[k]);
2744 printf("%-13s", names[k]);
2745 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2746 if (results[k][testnum] > 10000 && !mr)
2747 printf(" %11.2fk", results[k][testnum] / 1e3);
2749 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2753 #ifndef OPENSSL_NO_RSA
2755 for (k = 0; k < RSA_NUM; k++) {
2758 if (testnum && !mr) {
2759 printf("%18ssign verify sign/s verify/s\n", " ");
2763 printf("+F2:%u:%u:%f:%f\n",
2764 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2766 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2767 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2768 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2771 #ifndef OPENSSL_NO_DSA
2773 for (k = 0; k < DSA_NUM; k++) {
2776 if (testnum && !mr) {
2777 printf("%18ssign verify sign/s verify/s\n", " ");
2781 printf("+F3:%u:%u:%f:%f\n",
2782 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2784 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2785 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2786 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2789 #ifndef OPENSSL_NO_EC
2791 for (k = 0; k < EC_NUM; k++) {
2794 if (testnum && !mr) {
2795 printf("%30ssign verify sign/s verify/s\n", " ");
2800 printf("+F4:%u:%u:%f:%f\n",
2801 k, test_curves_bits[k],
2802 ecdsa_results[k][0], ecdsa_results[k][1]);
2804 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2805 test_curves_bits[k],
2806 test_curves_names[k],
2807 ecdsa_results[k][0], ecdsa_results[k][1],
2808 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2812 for (k = 0; k < EC_NUM; k++) {
2815 if (testnum && !mr) {
2816 printf("%30sop op/s\n", " ");
2820 printf("+F5:%u:%u:%f:%f\n",
2821 k, test_curves_bits[k],
2822 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2825 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2826 test_curves_bits[k],
2827 test_curves_names[k],
2828 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2835 ERR_print_errors(bio_err);
2836 for (i = 0; i < loopargs_len; i++) {
2837 OPENSSL_free(loopargs[i].buf_malloc);
2838 OPENSSL_free(loopargs[i].buf2_malloc);
2840 #ifndef OPENSSL_NO_RSA
2841 for (k = 0; k < RSA_NUM; k++)
2842 RSA_free(loopargs[i].rsa_key[k]);
2844 #ifndef OPENSSL_NO_DSA
2845 for (k = 0; k < DSA_NUM; k++)
2846 DSA_free(loopargs[i].dsa_key[k]);
2848 #ifndef OPENSSL_NO_EC
2849 for (k = 0; k < EC_NUM; k++) {
2850 EC_KEY_free(loopargs[i].ecdsa[k]);
2851 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2853 OPENSSL_free(loopargs[i].secret_a);
2854 OPENSSL_free(loopargs[i].secret_b);
2858 if (async_jobs > 0) {
2859 for (i = 0; i < loopargs_len; i++)
2860 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2864 ASYNC_cleanup_thread();
2866 OPENSSL_free(loopargs);
2871 static void print_message(const char *s, long num, int length)
2875 mr ? "+DT:%s:%d:%d\n"
2876 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2877 (void)BIO_flush(bio_err);
2881 mr ? "+DN:%s:%ld:%d\n"
2882 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2883 (void)BIO_flush(bio_err);
2887 static void pkey_print_message(const char *str, const char *str2, long num,
2892 mr ? "+DTP:%d:%s:%s:%d\n"
2893 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2894 (void)BIO_flush(bio_err);
2898 mr ? "+DNP:%ld:%d:%s:%s\n"
2899 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2900 (void)BIO_flush(bio_err);
2904 static void print_result(int alg, int run_no, int count, double time_used)
2907 BIO_puts(bio_err, "EVP error!\n");
2911 mr ? "+R:%d:%s:%f\n"
2912 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2913 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2917 static char *sstrsep(char **string, const char *delim)
2920 char *token = *string;
2925 memset(isdelim, 0, sizeof isdelim);
2929 isdelim[(unsigned char)(*delim)] = 1;
2933 while (!isdelim[(unsigned char)(**string)]) {
2945 static int do_multi(int multi)
2950 static char sep[] = ":";
2952 fds = malloc(sizeof(*fds) * multi);
2953 for (n = 0; n < multi; ++n) {
2954 if (pipe(fd) == -1) {
2955 BIO_printf(bio_err, "pipe failure\n");
2959 (void)BIO_flush(bio_err);
2966 if (dup(fd[1]) == -1) {
2967 BIO_printf(bio_err, "dup failed\n");
2976 printf("Forked child %d\n", n);
2979 /* for now, assume the pipe is long enough to take all the output */
2980 for (n = 0; n < multi; ++n) {
2985 f = fdopen(fds[n], "r");
2986 while (fgets(buf, sizeof buf, f)) {
2987 p = strchr(buf, '\n');
2990 if (buf[0] != '+') {
2992 "Don't understand line '%s' from child %d\n", buf,
2996 printf("Got: %s from %d\n", buf, n);
2997 if (strncmp(buf, "+F:", 3) == 0) {
3002 alg = atoi(sstrsep(&p, sep));
3004 for (j = 0; j < SIZE_NUM; ++j)
3005 results[alg][j] += atof(sstrsep(&p, sep));
3006 } else if (strncmp(buf, "+F2:", 4) == 0) {
3011 k = atoi(sstrsep(&p, sep));
3014 d = atof(sstrsep(&p, sep));
3016 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
3018 rsa_results[k][0] = d;
3020 d = atof(sstrsep(&p, sep));
3022 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3024 rsa_results[k][1] = d;
3026 # ifndef OPENSSL_NO_DSA
3027 else if (strncmp(buf, "+F3:", 4) == 0) {
3032 k = atoi(sstrsep(&p, sep));
3035 d = atof(sstrsep(&p, sep));
3037 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3039 dsa_results[k][0] = d;
3041 d = atof(sstrsep(&p, sep));
3043 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3045 dsa_results[k][1] = d;
3048 # ifndef OPENSSL_NO_EC
3049 else if (strncmp(buf, "+F4:", 4) == 0) {
3054 k = atoi(sstrsep(&p, sep));
3057 d = atof(sstrsep(&p, sep));
3059 ecdsa_results[k][0] = 1 / (1 / ecdsa_results[k][0] + 1 / d);
3061 ecdsa_results[k][0] = d;
3063 d = atof(sstrsep(&p, sep));
3065 ecdsa_results[k][1] = 1 / (1 / ecdsa_results[k][1] + 1 / d);
3067 ecdsa_results[k][1] = d;
3068 } else if (strncmp(buf, "+F5:", 4) == 0) {
3073 k = atoi(sstrsep(&p, sep));
3076 d = atof(sstrsep(&p, sep));
3078 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3080 ecdh_results[k][0] = d;
3085 else if (strncmp(buf, "+H:", 3) == 0) {
3088 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3099 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3101 static int mblengths[] =
3102 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3103 int j, count, num = OSSL_NELEM(mblengths);
3104 const char *alg_name;
3105 unsigned char *inp, *out, no_key[32], no_iv[16];
3106 EVP_CIPHER_CTX *ctx;
3109 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3110 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3111 ctx = EVP_CIPHER_CTX_new();
3112 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3113 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3114 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3116 for (j = 0; j < num; j++) {
3117 print_message(alg_name, 0, mblengths[j]);
3119 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3120 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3121 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3122 size_t len = mblengths[j];
3125 memset(aad, 0, 8); /* avoid uninitialized values */
3126 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3127 aad[9] = 3; /* version */
3129 aad[11] = 0; /* length */
3131 mb_param.out = NULL;
3134 mb_param.interleave = 8;
3136 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3137 sizeof(mb_param), &mb_param);
3143 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3144 sizeof(mb_param), &mb_param);
3148 RAND_bytes(out, 16);
3152 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3153 EVP_AEAD_TLS1_AAD_LEN, aad);
3154 EVP_Cipher(ctx, out, inp, len + pad);
3158 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3159 : "%d %s's in %.2fs\n", count, "evp", d);
3160 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3164 fprintf(stdout, "+H");
3165 for (j = 0; j < num; j++)
3166 fprintf(stdout, ":%d", mblengths[j]);
3167 fprintf(stdout, "\n");
3168 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3169 for (j = 0; j < num; j++)
3170 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3171 fprintf(stdout, "\n");
3174 "The 'numbers' are in 1000s of bytes per second processed.\n");
3175 fprintf(stdout, "type ");
3176 for (j = 0; j < num; j++)
3177 fprintf(stdout, "%7d bytes", mblengths[j]);
3178 fprintf(stdout, "\n");
3179 fprintf(stdout, "%-24s", alg_name);
3181 for (j = 0; j < num; j++) {
3182 if (results[D_EVP][j] > 10000)
3183 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3185 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3187 fprintf(stdout, "\n");
3192 EVP_CIPHER_CTX_free(ctx);