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 struct loopargs_st {
148 ASYNC_JOB *inprogress_job;
149 ASYNC_WAIT_CTX *wait_ctx;
152 unsigned char *buf_malloc;
153 unsigned char *buf2_malloc;
155 #ifndef OPENSSL_NO_RSA
156 RSA *rsa_key[RSA_NUM];
158 #ifndef OPENSSL_NO_DSA
159 DSA *dsa_key[DSA_NUM];
161 #ifndef OPENSSL_NO_EC
162 EC_KEY *ecdsa[EC_NUM];
163 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
164 unsigned char *secret_a;
165 unsigned char *secret_b;
166 size_t outlen[EC_NUM];
170 GCM128_CONTEXT *gcm_ctx;
173 #ifndef OPENSSL_NO_MD2
174 static int EVP_Digest_MD2_loop(void *args);
177 #ifndef OPENSSL_NO_MDC2
178 static int EVP_Digest_MDC2_loop(void *args);
180 #ifndef OPENSSL_NO_MD4
181 static int EVP_Digest_MD4_loop(void *args);
183 #ifndef OPENSSL_NO_MD5
184 static int MD5_loop(void *args);
185 static int HMAC_loop(void *args);
187 static int SHA1_loop(void *args);
188 static int SHA256_loop(void *args);
189 static int SHA512_loop(void *args);
190 #ifndef OPENSSL_NO_WHIRLPOOL
191 static int WHIRLPOOL_loop(void *args);
193 #ifndef OPENSSL_NO_RMD160
194 static int EVP_Digest_RMD160_loop(void *args);
196 #ifndef OPENSSL_NO_RC4
197 static int RC4_loop(void *args);
199 #ifndef OPENSSL_NO_DES
200 static int DES_ncbc_encrypt_loop(void *args);
201 static int DES_ede3_cbc_encrypt_loop(void *args);
203 static int AES_cbc_128_encrypt_loop(void *args);
204 static int AES_cbc_192_encrypt_loop(void *args);
205 static int AES_ige_128_encrypt_loop(void *args);
206 static int AES_cbc_256_encrypt_loop(void *args);
207 static int AES_ige_192_encrypt_loop(void *args);
208 static int AES_ige_256_encrypt_loop(void *args);
209 static int CRYPTO_gcm128_aad_loop(void *args);
210 static int EVP_Update_loop(void *args);
211 static int EVP_Digest_loop(void *args);
212 #ifndef OPENSSL_NO_RSA
213 static int RSA_sign_loop(void *args);
214 static int RSA_verify_loop(void *args);
216 #ifndef OPENSSL_NO_DSA
217 static int DSA_sign_loop(void *args);
218 static int DSA_verify_loop(void *args);
220 #ifndef OPENSSL_NO_EC
221 static int ECDSA_sign_loop(void *args);
222 static int ECDSA_verify_loop(void *args);
224 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
225 loopargs_t * loopargs);
227 static double Time_F(int s);
228 static void print_message(const char *s, long num, int length);
229 static void pkey_print_message(const char *str, const char *str2,
230 long num, int bits, int sec);
231 static void print_result(int alg, int run_no, int count, double time_used);
233 static int do_multi(int multi);
236 static const char *names[ALGOR_NUM] = {
237 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
238 "des cbc", "des ede3", "idea cbc", "seed cbc",
239 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
240 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
241 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
242 "evp", "sha256", "sha512", "whirlpool",
243 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
246 static double results[ALGOR_NUM][SIZE_NUM];
248 static const int lengths[SIZE_NUM] = {
249 16, 64, 256, 1024, 8 * 1024, 16 * 1024
252 #ifndef OPENSSL_NO_RSA
253 static double rsa_results[RSA_NUM][2];
255 #ifndef OPENSSL_NO_DSA
256 static double dsa_results[DSA_NUM][2];
258 #ifndef OPENSSL_NO_EC
259 static double ecdsa_results[EC_NUM][2];
260 static double ecdh_results[EC_NUM][1];
263 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
264 static const char rnd_seed[] =
265 "string to make the random number generator think it has entropy";
269 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
270 # define SIGRETTYPE void
272 # define SIGRETTYPE int
275 static SIGRETTYPE sig_done(int sig);
276 static SIGRETTYPE sig_done(int sig)
278 signal(SIGALRM, sig_done);
288 # if !defined(SIGALRM)
291 static unsigned int lapse, schlock;
292 static void alarm_win32(unsigned int secs)
297 # define alarm alarm_win32
299 static DWORD WINAPI sleepy(VOID * arg)
307 static double Time_F(int s)
314 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
316 DWORD err = GetLastError();
317 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
321 Sleep(0); /* scheduler spinlock */
322 ret = app_tminterval(s, usertime);
324 ret = app_tminterval(s, usertime);
326 TerminateThread(thr, 0);
334 static double Time_F(int s)
336 double ret = app_tminterval(s, usertime);
343 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
345 static int found(const char *name, const OPT_PAIR *pairs, int *result)
347 for (; pairs->name; pairs++)
348 if (strcmp(name, pairs->name) == 0) {
349 *result = pairs->retval;
355 typedef enum OPTION_choice {
356 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
357 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
358 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
361 const OPTIONS speed_options[] = {
362 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
363 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
364 {"help", OPT_HELP, '-', "Display this summary"},
365 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
366 {"decrypt", OPT_DECRYPT, '-',
367 "Time decryption instead of encryption (only EVP)"},
368 {"mr", OPT_MR, '-', "Produce machine readable output"},
370 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
371 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
372 {"elapsed", OPT_ELAPSED, '-',
373 "Measure time in real time instead of CPU user time"},
375 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
377 #ifndef OPENSSL_NO_ASYNC
378 {"async_jobs", OPT_ASYNCJOBS, 'p',
379 "Enable async mode and start pnum jobs"},
381 #ifndef OPENSSL_NO_ENGINE
382 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
397 #define D_CBC_IDEA 10
398 #define D_CBC_SEED 11
402 #define D_CBC_CAST 15
403 #define D_CBC_128_AES 16
404 #define D_CBC_192_AES 17
405 #define D_CBC_256_AES 18
406 #define D_CBC_128_CML 19
407 #define D_CBC_192_CML 20
408 #define D_CBC_256_CML 21
412 #define D_WHIRLPOOL 25
413 #define D_IGE_128_AES 26
414 #define D_IGE_192_AES 27
415 #define D_IGE_256_AES 28
417 static OPT_PAIR doit_choices[] = {
418 #ifndef OPENSSL_NO_MD2
421 #ifndef OPENSSL_NO_MDC2
424 #ifndef OPENSSL_NO_MD4
427 #ifndef OPENSSL_NO_MD5
432 {"sha256", D_SHA256},
433 {"sha512", D_SHA512},
434 #ifndef OPENSSL_NO_WHIRLPOOL
435 {"whirlpool", D_WHIRLPOOL},
437 #ifndef OPENSSL_NO_RMD160
438 {"ripemd", D_RMD160},
439 {"rmd160", D_RMD160},
440 {"ripemd160", D_RMD160},
442 #ifndef OPENSSL_NO_RC4
445 #ifndef OPENSSL_NO_DES
446 {"des-cbc", D_CBC_DES},
447 {"des-ede3", D_EDE3_DES},
449 {"aes-128-cbc", D_CBC_128_AES},
450 {"aes-192-cbc", D_CBC_192_AES},
451 {"aes-256-cbc", D_CBC_256_AES},
452 {"aes-128-ige", D_IGE_128_AES},
453 {"aes-192-ige", D_IGE_192_AES},
454 {"aes-256-ige", D_IGE_256_AES},
455 #ifndef OPENSSL_NO_RC2
456 {"rc2-cbc", D_CBC_RC2},
459 #ifndef OPENSSL_NO_RC5
460 {"rc5-cbc", D_CBC_RC5},
463 #ifndef OPENSSL_NO_IDEA
464 {"idea-cbc", D_CBC_IDEA},
465 {"idea", D_CBC_IDEA},
467 #ifndef OPENSSL_NO_SEED
468 {"seed-cbc", D_CBC_SEED},
469 {"seed", D_CBC_SEED},
471 #ifndef OPENSSL_NO_BF
472 {"bf-cbc", D_CBC_BF},
473 {"blowfish", D_CBC_BF},
476 #ifndef OPENSSL_NO_CAST
477 {"cast-cbc", D_CBC_CAST},
478 {"cast", D_CBC_CAST},
479 {"cast5", D_CBC_CAST},
485 #ifndef OPENSSL_NO_DSA
487 # define R_DSA_1024 1
488 # define R_DSA_2048 2
489 static OPT_PAIR dsa_choices[] = {
490 {"dsa512", R_DSA_512},
491 {"dsa1024", R_DSA_1024},
492 {"dsa2048", R_DSA_2048},
503 #define R_RSA_15360 6
504 static OPT_PAIR rsa_choices[] = {
505 {"rsa512", R_RSA_512},
506 {"rsa1024", R_RSA_1024},
507 {"rsa2048", R_RSA_2048},
508 {"rsa3072", R_RSA_3072},
509 {"rsa4096", R_RSA_4096},
510 {"rsa7680", R_RSA_7680},
511 {"rsa15360", R_RSA_15360},
531 #define R_EC_X25519 16
532 #ifndef OPENSSL_NO_EC
533 static OPT_PAIR ecdsa_choices[] = {
534 {"ecdsap160", R_EC_P160},
535 {"ecdsap192", R_EC_P192},
536 {"ecdsap224", R_EC_P224},
537 {"ecdsap256", R_EC_P256},
538 {"ecdsap384", R_EC_P384},
539 {"ecdsap521", R_EC_P521},
540 {"ecdsak163", R_EC_K163},
541 {"ecdsak233", R_EC_K233},
542 {"ecdsak283", R_EC_K283},
543 {"ecdsak409", R_EC_K409},
544 {"ecdsak571", R_EC_K571},
545 {"ecdsab163", R_EC_B163},
546 {"ecdsab233", R_EC_B233},
547 {"ecdsab283", R_EC_B283},
548 {"ecdsab409", R_EC_B409},
549 {"ecdsab571", R_EC_B571},
553 static OPT_PAIR ecdh_choices[] = {
554 {"ecdhp160", R_EC_P160},
555 {"ecdhp192", R_EC_P192},
556 {"ecdhp224", R_EC_P224},
557 {"ecdhp256", R_EC_P256},
558 {"ecdhp384", R_EC_P384},
559 {"ecdhp521", R_EC_P521},
560 {"ecdhk163", R_EC_K163},
561 {"ecdhk233", R_EC_K233},
562 {"ecdhk283", R_EC_K283},
563 {"ecdhk409", R_EC_K409},
564 {"ecdhk571", R_EC_K571},
565 {"ecdhb163", R_EC_B163},
566 {"ecdhb233", R_EC_B233},
567 {"ecdhb283", R_EC_B283},
568 {"ecdhb409", R_EC_B409},
569 {"ecdhb571", R_EC_B571},
570 {"ecdhx25519", R_EC_X25519},
576 # define COND(d) (count < (d))
577 # define COUNT(d) (d)
579 # define COND(unused_cond) (run && count<0x7fffffff)
580 # define COUNT(d) (count)
585 /* Nb of iterations to do per algorithm and key-size */
586 static long c[ALGOR_NUM][SIZE_NUM];
588 #ifndef OPENSSL_NO_MD2
589 static int EVP_Digest_MD2_loop(void *args)
591 loopargs_t *tempargs = *(loopargs_t **) args;
592 unsigned char *buf = tempargs->buf;
593 unsigned char md2[MD2_DIGEST_LENGTH];
596 for (count = 0; COND(c[D_MD2][testnum]); count++) {
597 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
605 #ifndef OPENSSL_NO_MDC2
606 static int EVP_Digest_MDC2_loop(void *args)
608 loopargs_t *tempargs = *(loopargs_t **) args;
609 unsigned char *buf = tempargs->buf;
610 unsigned char mdc2[MDC2_DIGEST_LENGTH];
613 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
614 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
622 #ifndef OPENSSL_NO_MD4
623 static int EVP_Digest_MD4_loop(void *args)
625 loopargs_t *tempargs = *(loopargs_t **) args;
626 unsigned char *buf = tempargs->buf;
627 unsigned char md4[MD4_DIGEST_LENGTH];
630 for (count = 0; COND(c[D_MD4][testnum]); count++) {
631 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
639 #ifndef OPENSSL_NO_MD5
640 static int MD5_loop(void *args)
642 loopargs_t *tempargs = *(loopargs_t **) args;
643 unsigned char *buf = tempargs->buf;
644 unsigned char md5[MD5_DIGEST_LENGTH];
646 for (count = 0; COND(c[D_MD5][testnum]); count++)
647 MD5(buf, lengths[testnum], md5);
651 static int HMAC_loop(void *args)
653 loopargs_t *tempargs = *(loopargs_t **) args;
654 unsigned char *buf = tempargs->buf;
655 HMAC_CTX *hctx = tempargs->hctx;
656 unsigned char hmac[MD5_DIGEST_LENGTH];
659 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
660 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
661 HMAC_Update(hctx, buf, lengths[testnum]);
662 HMAC_Final(hctx, hmac, NULL);
668 static int SHA1_loop(void *args)
670 loopargs_t *tempargs = *(loopargs_t **) args;
671 unsigned char *buf = tempargs->buf;
672 unsigned char sha[SHA_DIGEST_LENGTH];
674 for (count = 0; COND(c[D_SHA1][testnum]); count++)
675 SHA1(buf, lengths[testnum], sha);
679 static int SHA256_loop(void *args)
681 loopargs_t *tempargs = *(loopargs_t **) args;
682 unsigned char *buf = tempargs->buf;
683 unsigned char sha256[SHA256_DIGEST_LENGTH];
685 for (count = 0; COND(c[D_SHA256][testnum]); count++)
686 SHA256(buf, lengths[testnum], sha256);
690 static int SHA512_loop(void *args)
692 loopargs_t *tempargs = *(loopargs_t **) args;
693 unsigned char *buf = tempargs->buf;
694 unsigned char sha512[SHA512_DIGEST_LENGTH];
696 for (count = 0; COND(c[D_SHA512][testnum]); count++)
697 SHA512(buf, lengths[testnum], sha512);
701 #ifndef OPENSSL_NO_WHIRLPOOL
702 static int WHIRLPOOL_loop(void *args)
704 loopargs_t *tempargs = *(loopargs_t **) args;
705 unsigned char *buf = tempargs->buf;
706 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
708 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
709 WHIRLPOOL(buf, lengths[testnum], whirlpool);
714 #ifndef OPENSSL_NO_RMD160
715 static int EVP_Digest_RMD160_loop(void *args)
717 loopargs_t *tempargs = *(loopargs_t **) args;
718 unsigned char *buf = tempargs->buf;
719 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
721 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
722 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
723 NULL, EVP_ripemd160(), NULL))
730 #ifndef OPENSSL_NO_RC4
731 static RC4_KEY rc4_ks;
732 static int RC4_loop(void *args)
734 loopargs_t *tempargs = *(loopargs_t **) args;
735 unsigned char *buf = tempargs->buf;
737 for (count = 0; COND(c[D_RC4][testnum]); count++)
738 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
743 #ifndef OPENSSL_NO_DES
744 static unsigned char DES_iv[8];
745 static DES_key_schedule sch;
746 static DES_key_schedule sch2;
747 static DES_key_schedule sch3;
748 static int DES_ncbc_encrypt_loop(void *args)
750 loopargs_t *tempargs = *(loopargs_t **) args;
751 unsigned char *buf = tempargs->buf;
753 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
754 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
755 &DES_iv, DES_ENCRYPT);
759 static int DES_ede3_cbc_encrypt_loop(void *args)
761 loopargs_t *tempargs = *(loopargs_t **) args;
762 unsigned char *buf = tempargs->buf;
764 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
765 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
766 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
771 #define MAX_BLOCK_SIZE 128
773 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
774 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
775 static int AES_cbc_128_encrypt_loop(void *args)
777 loopargs_t *tempargs = *(loopargs_t **) args;
778 unsigned char *buf = tempargs->buf;
780 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
781 AES_cbc_encrypt(buf, buf,
782 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
786 static int AES_cbc_192_encrypt_loop(void *args)
788 loopargs_t *tempargs = *(loopargs_t **) args;
789 unsigned char *buf = tempargs->buf;
791 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
792 AES_cbc_encrypt(buf, buf,
793 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
797 static int AES_cbc_256_encrypt_loop(void *args)
799 loopargs_t *tempargs = *(loopargs_t **) args;
800 unsigned char *buf = tempargs->buf;
802 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
803 AES_cbc_encrypt(buf, buf,
804 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
808 static int AES_ige_128_encrypt_loop(void *args)
810 loopargs_t *tempargs = *(loopargs_t **) args;
811 unsigned char *buf = tempargs->buf;
812 unsigned char *buf2 = tempargs->buf2;
814 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
815 AES_ige_encrypt(buf, buf2,
816 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
820 static int AES_ige_192_encrypt_loop(void *args)
822 loopargs_t *tempargs = *(loopargs_t **) args;
823 unsigned char *buf = tempargs->buf;
824 unsigned char *buf2 = tempargs->buf2;
826 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
827 AES_ige_encrypt(buf, buf2,
828 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
832 static int AES_ige_256_encrypt_loop(void *args)
834 loopargs_t *tempargs = *(loopargs_t **) args;
835 unsigned char *buf = tempargs->buf;
836 unsigned char *buf2 = tempargs->buf2;
838 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
839 AES_ige_encrypt(buf, buf2,
840 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
844 static int CRYPTO_gcm128_aad_loop(void *args)
846 loopargs_t *tempargs = *(loopargs_t **) args;
847 unsigned char *buf = tempargs->buf;
848 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
850 for (count = 0; COND(c[D_GHASH][testnum]); count++)
851 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
855 static long save_count = 0;
856 static int decrypt = 0;
857 static int EVP_Update_loop(void *args)
859 loopargs_t *tempargs = *(loopargs_t **) args;
860 unsigned char *buf = tempargs->buf;
861 EVP_CIPHER_CTX *ctx = tempargs->ctx;
864 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
867 for (count = 0; COND(nb_iter); count++)
868 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
870 for (count = 0; COND(nb_iter); count++)
871 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
873 EVP_DecryptFinal_ex(ctx, buf, &outl);
875 EVP_EncryptFinal_ex(ctx, buf, &outl);
879 static const EVP_MD *evp_md = NULL;
880 static int EVP_Digest_loop(void *args)
882 loopargs_t *tempargs = *(loopargs_t **) args;
883 unsigned char *buf = tempargs->buf;
884 unsigned char md[EVP_MAX_MD_SIZE];
887 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
890 for (count = 0; COND(nb_iter); count++) {
891 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
897 #ifndef OPENSSL_NO_RSA
898 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
900 static int RSA_sign_loop(void *args)
902 loopargs_t *tempargs = *(loopargs_t **) args;
903 unsigned char *buf = tempargs->buf;
904 unsigned char *buf2 = tempargs->buf2;
905 unsigned int *rsa_num = &tempargs->siglen;
906 RSA **rsa_key = tempargs->rsa_key;
908 for (count = 0; COND(rsa_c[testnum][0]); count++) {
909 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
911 BIO_printf(bio_err, "RSA sign failure\n");
912 ERR_print_errors(bio_err);
920 static int RSA_verify_loop(void *args)
922 loopargs_t *tempargs = *(loopargs_t **) args;
923 unsigned char *buf = tempargs->buf;
924 unsigned char *buf2 = tempargs->buf2;
925 unsigned int rsa_num = tempargs->siglen;
926 RSA **rsa_key = tempargs->rsa_key;
928 for (count = 0; COND(rsa_c[testnum][1]); count++) {
930 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
932 BIO_printf(bio_err, "RSA verify failure\n");
933 ERR_print_errors(bio_err);
942 #ifndef OPENSSL_NO_DSA
943 static long dsa_c[DSA_NUM][2];
944 static int DSA_sign_loop(void *args)
946 loopargs_t *tempargs = *(loopargs_t **) args;
947 unsigned char *buf = tempargs->buf;
948 unsigned char *buf2 = tempargs->buf2;
949 DSA **dsa_key = tempargs->dsa_key;
950 unsigned int *siglen = &tempargs->siglen;
952 for (count = 0; COND(dsa_c[testnum][0]); count++) {
953 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
955 BIO_printf(bio_err, "DSA sign failure\n");
956 ERR_print_errors(bio_err);
964 static int DSA_verify_loop(void *args)
966 loopargs_t *tempargs = *(loopargs_t **) args;
967 unsigned char *buf = tempargs->buf;
968 unsigned char *buf2 = tempargs->buf2;
969 DSA **dsa_key = tempargs->dsa_key;
970 unsigned int siglen = tempargs->siglen;
972 for (count = 0; COND(dsa_c[testnum][1]); count++) {
973 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
975 BIO_printf(bio_err, "DSA verify failure\n");
976 ERR_print_errors(bio_err);
985 #ifndef OPENSSL_NO_EC
986 static long ecdsa_c[EC_NUM][2];
987 static int ECDSA_sign_loop(void *args)
989 loopargs_t *tempargs = *(loopargs_t **) args;
990 unsigned char *buf = tempargs->buf;
991 EC_KEY **ecdsa = tempargs->ecdsa;
992 unsigned char *ecdsasig = tempargs->buf2;
993 unsigned int *ecdsasiglen = &tempargs->siglen;
995 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
996 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
998 BIO_printf(bio_err, "ECDSA sign failure\n");
999 ERR_print_errors(bio_err);
1007 static int ECDSA_verify_loop(void *args)
1009 loopargs_t *tempargs = *(loopargs_t **) args;
1010 unsigned char *buf = tempargs->buf;
1011 EC_KEY **ecdsa = tempargs->ecdsa;
1012 unsigned char *ecdsasig = tempargs->buf2;
1013 unsigned int ecdsasiglen = tempargs->siglen;
1015 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1016 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1018 BIO_printf(bio_err, "ECDSA verify failure\n");
1019 ERR_print_errors(bio_err);
1027 /* ******************************************************************** */
1028 static long ecdh_c[EC_NUM][1];
1030 static int ECDH_EVP_derive_key_loop(void *args)
1032 loopargs_t *tempargs = *(loopargs_t **) args;
1033 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1034 unsigned char *derived_secret = tempargs->secret_a;
1036 size_t *outlen = &(tempargs->outlen[testnum]);
1038 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1039 EVP_PKEY_derive(ctx, derived_secret, outlen);
1044 #endif /* OPENSSL_NO_EC */
1046 static int run_benchmark(int async_jobs,
1047 int (*loop_function) (void *), loopargs_t * loopargs)
1049 int job_op_count = 0;
1050 int total_op_count = 0;
1051 int num_inprogress = 0;
1052 int error = 0, i = 0, ret = 0;
1053 OSSL_ASYNC_FD job_fd = 0;
1054 size_t num_job_fds = 0;
1058 if (async_jobs == 0) {
1059 return loop_function((void *)&loopargs);
1062 for (i = 0; i < async_jobs && !error; i++) {
1063 loopargs_t *looparg_item = loopargs + i;
1065 /* Copy pointer content (looparg_t item address) into async context */
1066 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1067 &job_op_count, loop_function,
1068 (void *)&looparg_item, sizeof(looparg_item));
1074 if (job_op_count == -1) {
1077 total_op_count += job_op_count;
1082 BIO_printf(bio_err, "Failure in the job\n");
1083 ERR_print_errors(bio_err);
1089 while (num_inprogress > 0) {
1090 #if defined(OPENSSL_SYS_WINDOWS)
1092 #elif defined(OPENSSL_SYS_UNIX)
1093 int select_result = 0;
1094 OSSL_ASYNC_FD max_fd = 0;
1097 FD_ZERO(&waitfdset);
1099 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1100 if (loopargs[i].inprogress_job == NULL)
1103 if (!ASYNC_WAIT_CTX_get_all_fds
1104 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1105 || num_job_fds > 1) {
1106 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1107 ERR_print_errors(bio_err);
1111 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1113 FD_SET(job_fd, &waitfdset);
1114 if (job_fd > max_fd)
1118 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1120 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1121 "Decrease the value of async_jobs\n",
1122 max_fd, FD_SETSIZE);
1123 ERR_print_errors(bio_err);
1128 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1129 if (select_result == -1 && errno == EINTR)
1132 if (select_result == -1) {
1133 BIO_printf(bio_err, "Failure in the select\n");
1134 ERR_print_errors(bio_err);
1139 if (select_result == 0)
1143 for (i = 0; i < async_jobs; i++) {
1144 if (loopargs[i].inprogress_job == NULL)
1147 if (!ASYNC_WAIT_CTX_get_all_fds
1148 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1149 || num_job_fds > 1) {
1150 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1151 ERR_print_errors(bio_err);
1155 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1158 #if defined(OPENSSL_SYS_UNIX)
1159 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1161 #elif defined(OPENSSL_SYS_WINDOWS)
1162 if (num_job_fds == 1
1163 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1168 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1169 loopargs[i].wait_ctx, &job_op_count,
1170 loop_function, (void *)(loopargs + i),
1171 sizeof(loopargs_t));
1176 if (job_op_count == -1) {
1179 total_op_count += job_op_count;
1182 loopargs[i].inprogress_job = NULL;
1187 loopargs[i].inprogress_job = NULL;
1188 BIO_printf(bio_err, "Failure in the job\n");
1189 ERR_print_errors(bio_err);
1196 return error ? -1 : total_op_count;
1199 int speed_main(int argc, char **argv)
1202 loopargs_t *loopargs = NULL;
1204 int loopargs_len = 0;
1206 const char *engine_id = NULL;
1207 const EVP_CIPHER *evp_cipher = NULL;
1210 int multiblock = 0, pr_header = 0;
1211 int doit[ALGOR_NUM] = { 0 };
1212 int ret = 1, i, k, misalign = 0;
1217 unsigned int async_jobs = 0;
1218 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1219 || !defined(OPENSSL_NO_EC)
1223 /* What follows are the buffers and key material. */
1224 #ifndef OPENSSL_NO_RC5
1227 #ifndef OPENSSL_NO_RC2
1230 #ifndef OPENSSL_NO_IDEA
1231 IDEA_KEY_SCHEDULE idea_ks;
1233 #ifndef OPENSSL_NO_SEED
1234 SEED_KEY_SCHEDULE seed_ks;
1236 #ifndef OPENSSL_NO_BF
1239 #ifndef OPENSSL_NO_CAST
1242 static const unsigned char key16[16] = {
1243 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1244 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1246 static const unsigned char key24[24] = {
1247 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1248 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1249 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1251 static const unsigned char key32[32] = {
1252 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1253 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1254 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1255 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1257 #ifndef OPENSSL_NO_CAMELLIA
1258 static const unsigned char ckey24[24] = {
1259 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1260 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1261 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1263 static const unsigned char ckey32[32] = {
1264 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1265 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1266 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1267 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1269 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1271 #ifndef OPENSSL_NO_DES
1272 static DES_cblock key = {
1273 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1275 static DES_cblock key2 = {
1276 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1278 static DES_cblock key3 = {
1279 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1282 #ifndef OPENSSL_NO_RSA
1283 static const unsigned int rsa_bits[RSA_NUM] = {
1284 512, 1024, 2048, 3072, 4096, 7680, 15360
1286 static const unsigned char *rsa_data[RSA_NUM] = {
1287 test512, test1024, test2048, test3072, test4096, test7680, test15360
1289 static const int rsa_data_length[RSA_NUM] = {
1290 sizeof(test512), sizeof(test1024),
1291 sizeof(test2048), sizeof(test3072),
1292 sizeof(test4096), sizeof(test7680),
1295 int rsa_doit[RSA_NUM] = { 0 };
1297 #ifndef OPENSSL_NO_DSA
1298 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1299 int dsa_doit[DSA_NUM] = { 0 };
1301 #ifndef OPENSSL_NO_EC
1303 * We only test over the following curves as they are representative, To
1304 * add tests over more curves, simply add the curve NID and curve name to
1305 * the following arrays and increase the EC_NUM value accordingly.
1307 static const unsigned int test_curves[EC_NUM] = {
1309 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1310 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1312 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1313 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1314 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1319 static const char *test_curves_names[EC_NUM] = {
1321 "secp160r1", "nistp192", "nistp224",
1322 "nistp256", "nistp384", "nistp521",
1324 "nistk163", "nistk233", "nistk283",
1325 "nistk409", "nistk571", "nistb163",
1326 "nistb233", "nistb283", "nistb409",
1331 static const int test_curves_bits[EC_NUM] = {
1337 571, 253 /* X25519 */
1340 int ecdsa_doit[EC_NUM] = { 0 };
1341 int ecdh_doit[EC_NUM] = { 0 };
1342 #endif /* ndef OPENSSL_NO_EC */
1344 prog = opt_init(argc, argv, speed_options);
1345 while ((o = opt_next()) != OPT_EOF) {
1350 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1353 opt_help(speed_options);
1360 evp_cipher = EVP_get_cipherbyname(opt_arg());
1361 if (evp_cipher == NULL)
1362 evp_md = EVP_get_digestbyname(opt_arg());
1363 if (evp_cipher == NULL && evp_md == NULL) {
1365 "%s: %s is an unknown cipher or digest\n",
1376 * In a forked execution, an engine might need to be
1377 * initialised by each child process, not by the parent.
1378 * So store the name here and run setup_engine() later on.
1380 engine_id = opt_arg();
1384 multi = atoi(opt_arg());
1388 #ifndef OPENSSL_NO_ASYNC
1389 async_jobs = atoi(opt_arg());
1390 if (!ASYNC_is_capable()) {
1392 "%s: async_jobs specified but async not supported\n",
1396 if (async_jobs > 99999) {
1398 "%s: too many async_jobs\n",
1405 if (!opt_int(opt_arg(), &misalign))
1407 if (misalign > MISALIGN) {
1409 "%s: Maximum offset is %d\n", prog, MISALIGN);
1418 #ifdef OPENSSL_NO_MULTIBLOCK
1420 "%s: -mb specified but multi-block support is disabled\n",
1427 argc = opt_num_rest();
1430 /* Remaining arguments are algorithms. */
1431 for (; *argv; argv++) {
1432 if (found(*argv, doit_choices, &i)) {
1436 #ifndef OPENSSL_NO_DES
1437 if (strcmp(*argv, "des") == 0) {
1438 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1442 if (strcmp(*argv, "sha") == 0) {
1443 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1446 #ifndef OPENSSL_NO_RSA
1448 if (strcmp(*argv, "openssl") == 0) {
1449 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1453 if (strcmp(*argv, "rsa") == 0) {
1454 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1455 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1456 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1457 rsa_doit[R_RSA_15360] = 1;
1460 if (found(*argv, rsa_choices, &i)) {
1465 #ifndef OPENSSL_NO_DSA
1466 if (strcmp(*argv, "dsa") == 0) {
1467 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1468 dsa_doit[R_DSA_2048] = 1;
1471 if (found(*argv, dsa_choices, &i)) {
1476 if (strcmp(*argv, "aes") == 0) {
1477 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1480 #ifndef OPENSSL_NO_CAMELLIA
1481 if (strcmp(*argv, "camellia") == 0) {
1482 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1486 #ifndef OPENSSL_NO_EC
1487 if (strcmp(*argv, "ecdsa") == 0) {
1488 for (i = 0; i < EC_NUM; i++)
1492 if (found(*argv, ecdsa_choices, &i)) {
1496 if (strcmp(*argv, "ecdh") == 0) {
1497 for (i = 0; i < EC_NUM; i++)
1501 if (found(*argv, ecdh_choices, &i)) {
1506 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1510 /* Initialize the job pool if async mode is enabled */
1511 if (async_jobs > 0) {
1512 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1514 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1519 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1521 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1522 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1524 for (i = 0; i < loopargs_len; i++) {
1525 if (async_jobs > 0) {
1526 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1527 if (loopargs[i].wait_ctx == NULL) {
1528 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1533 loopargs[i].buf_malloc =
1534 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1535 loopargs[i].buf2_malloc =
1536 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1537 /* Align the start of buffers on a 64 byte boundary */
1538 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1539 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1540 #ifndef OPENSSL_NO_EC
1541 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1542 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1547 if (multi && do_multi(multi))
1551 /* Initialize the engine after the fork */
1552 e = setup_engine(engine_id, 0);
1554 /* No parameters; turn on everything. */
1555 if ((argc == 0) && !doit[D_EVP]) {
1556 for (i = 0; i < ALGOR_NUM; i++)
1559 #ifndef OPENSSL_NO_RSA
1560 for (i = 0; i < RSA_NUM; i++)
1563 #ifndef OPENSSL_NO_DSA
1564 for (i = 0; i < DSA_NUM; i++)
1567 #ifndef OPENSSL_NO_EC
1568 for (i = 0; i < EC_NUM; i++)
1570 for (i = 0; i < EC_NUM; i++)
1574 for (i = 0; i < ALGOR_NUM; i++)
1578 if (usertime == 0 && !mr)
1580 "You have chosen to measure elapsed time "
1581 "instead of user CPU time.\n");
1583 #ifndef OPENSSL_NO_RSA
1584 for (i = 0; i < loopargs_len; i++) {
1585 for (k = 0; k < RSA_NUM; k++) {
1586 const unsigned char *p;
1589 loopargs[i].rsa_key[k] =
1590 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1591 if (loopargs[i].rsa_key[k] == NULL) {
1593 "internal error loading RSA key number %d\n", k);
1599 #ifndef OPENSSL_NO_DSA
1600 for (i = 0; i < loopargs_len; i++) {
1601 loopargs[i].dsa_key[0] = get_dsa512();
1602 loopargs[i].dsa_key[1] = get_dsa1024();
1603 loopargs[i].dsa_key[2] = get_dsa2048();
1606 #ifndef OPENSSL_NO_DES
1607 DES_set_key_unchecked(&key, &sch);
1608 DES_set_key_unchecked(&key2, &sch2);
1609 DES_set_key_unchecked(&key3, &sch3);
1611 AES_set_encrypt_key(key16, 128, &aes_ks1);
1612 AES_set_encrypt_key(key24, 192, &aes_ks2);
1613 AES_set_encrypt_key(key32, 256, &aes_ks3);
1614 #ifndef OPENSSL_NO_CAMELLIA
1615 Camellia_set_key(key16, 128, &camellia_ks1);
1616 Camellia_set_key(ckey24, 192, &camellia_ks2);
1617 Camellia_set_key(ckey32, 256, &camellia_ks3);
1619 #ifndef OPENSSL_NO_IDEA
1620 IDEA_set_encrypt_key(key16, &idea_ks);
1622 #ifndef OPENSSL_NO_SEED
1623 SEED_set_key(key16, &seed_ks);
1625 #ifndef OPENSSL_NO_RC4
1626 RC4_set_key(&rc4_ks, 16, key16);
1628 #ifndef OPENSSL_NO_RC2
1629 RC2_set_key(&rc2_ks, 16, key16, 128);
1631 #ifndef OPENSSL_NO_RC5
1632 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1634 #ifndef OPENSSL_NO_BF
1635 BF_set_key(&bf_ks, 16, key16);
1637 #ifndef OPENSSL_NO_CAST
1638 CAST_set_key(&cast_ks, 16, key16);
1641 # ifndef OPENSSL_NO_DES
1642 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1648 for (it = count; it; it--)
1649 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1650 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1654 c[D_MD2][0] = count / 10;
1655 c[D_MDC2][0] = count / 10;
1656 c[D_MD4][0] = count;
1657 c[D_MD5][0] = count;
1658 c[D_HMAC][0] = count;
1659 c[D_SHA1][0] = count;
1660 c[D_RMD160][0] = count;
1661 c[D_RC4][0] = count * 5;
1662 c[D_CBC_DES][0] = count;
1663 c[D_EDE3_DES][0] = count / 3;
1664 c[D_CBC_IDEA][0] = count;
1665 c[D_CBC_SEED][0] = count;
1666 c[D_CBC_RC2][0] = count;
1667 c[D_CBC_RC5][0] = count;
1668 c[D_CBC_BF][0] = count;
1669 c[D_CBC_CAST][0] = count;
1670 c[D_CBC_128_AES][0] = count;
1671 c[D_CBC_192_AES][0] = count;
1672 c[D_CBC_256_AES][0] = count;
1673 c[D_CBC_128_CML][0] = count;
1674 c[D_CBC_192_CML][0] = count;
1675 c[D_CBC_256_CML][0] = count;
1676 c[D_SHA256][0] = count;
1677 c[D_SHA512][0] = count;
1678 c[D_WHIRLPOOL][0] = count;
1679 c[D_IGE_128_AES][0] = count;
1680 c[D_IGE_192_AES][0] = count;
1681 c[D_IGE_256_AES][0] = count;
1682 c[D_GHASH][0] = count;
1684 for (i = 1; i < SIZE_NUM; i++) {
1687 l0 = (long)lengths[0];
1688 l1 = (long)lengths[i];
1690 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1691 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1692 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1693 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1694 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1695 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1696 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1697 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1698 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1699 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1700 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1702 l0 = (long)lengths[i - 1];
1704 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1705 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1706 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1707 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1708 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1709 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1710 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1711 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1712 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1713 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1714 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1715 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1716 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1717 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1718 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1719 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1720 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1721 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1724 # ifndef OPENSSL_NO_RSA
1725 rsa_c[R_RSA_512][0] = count / 2000;
1726 rsa_c[R_RSA_512][1] = count / 400;
1727 for (i = 1; i < RSA_NUM; i++) {
1728 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1729 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1730 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1733 if (rsa_c[i][0] == 0) {
1734 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1741 # ifndef OPENSSL_NO_DSA
1742 dsa_c[R_DSA_512][0] = count / 1000;
1743 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1744 for (i = 1; i < DSA_NUM; i++) {
1745 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1746 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1747 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1750 if (dsa_c[i][0] == 0) {
1751 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1758 # ifndef OPENSSL_NO_EC
1759 ecdsa_c[R_EC_P160][0] = count / 1000;
1760 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1761 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1762 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1763 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1764 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1767 if (ecdsa_c[i][0] == 0) {
1773 ecdsa_c[R_EC_K163][0] = count / 1000;
1774 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1775 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1776 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1777 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1778 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1781 if (ecdsa_c[i][0] == 0) {
1787 ecdsa_c[R_EC_B163][0] = count / 1000;
1788 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1789 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1790 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1791 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1792 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1795 if (ecdsa_c[i][0] == 0) {
1802 ecdh_c[R_EC_P160][0] = count / 1000;
1803 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1804 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1805 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1808 if (ecdh_c[i][0] == 0) {
1813 ecdh_c[R_EC_K163][0] = count / 1000;
1814 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1815 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1816 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1819 if (ecdh_c[i][0] == 0) {
1824 ecdh_c[R_EC_B163][0] = count / 1000;
1825 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1826 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1827 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1830 if (ecdh_c[i][0] == 0) {
1838 /* not worth fixing */
1839 # error "You cannot disable DES on systems without SIGALRM."
1840 # endif /* OPENSSL_NO_DES */
1843 signal(SIGALRM, sig_done);
1845 #endif /* SIGALRM */
1847 #ifndef OPENSSL_NO_MD2
1849 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1850 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1852 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1854 print_result(D_MD2, testnum, count, d);
1858 #ifndef OPENSSL_NO_MDC2
1860 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1861 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1863 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1865 print_result(D_MDC2, testnum, count, d);
1870 #ifndef OPENSSL_NO_MD4
1872 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1873 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1875 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1877 print_result(D_MD4, testnum, count, d);
1882 #ifndef OPENSSL_NO_MD5
1884 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1885 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1887 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1889 print_result(D_MD5, testnum, count, d);
1894 static const char hmac_key[] = "This is a key...";
1895 int len = strlen(hmac_key);
1897 for (i = 0; i < loopargs_len; i++) {
1898 loopargs[i].hctx = HMAC_CTX_new();
1899 if (loopargs[i].hctx == NULL) {
1900 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1904 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1906 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1907 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1909 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1911 print_result(D_HMAC, testnum, count, d);
1913 for (i = 0; i < loopargs_len; i++) {
1914 HMAC_CTX_free(loopargs[i].hctx);
1919 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1920 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1922 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1924 print_result(D_SHA1, testnum, count, d);
1927 if (doit[D_SHA256]) {
1928 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1929 print_message(names[D_SHA256], c[D_SHA256][testnum],
1932 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1934 print_result(D_SHA256, testnum, count, d);
1937 if (doit[D_SHA512]) {
1938 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1939 print_message(names[D_SHA512], c[D_SHA512][testnum],
1942 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1944 print_result(D_SHA512, testnum, count, d);
1947 #ifndef OPENSSL_NO_WHIRLPOOL
1948 if (doit[D_WHIRLPOOL]) {
1949 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1950 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1953 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1955 print_result(D_WHIRLPOOL, testnum, count, d);
1960 #ifndef OPENSSL_NO_RMD160
1961 if (doit[D_RMD160]) {
1962 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1963 print_message(names[D_RMD160], c[D_RMD160][testnum],
1966 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1968 print_result(D_RMD160, testnum, count, d);
1972 #ifndef OPENSSL_NO_RC4
1974 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1975 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1977 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1979 print_result(D_RC4, testnum, count, d);
1983 #ifndef OPENSSL_NO_DES
1984 if (doit[D_CBC_DES]) {
1985 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1986 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
1989 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1991 print_result(D_CBC_DES, testnum, count, d);
1995 if (doit[D_EDE3_DES]) {
1996 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1997 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2001 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2003 print_result(D_EDE3_DES, testnum, count, d);
2008 if (doit[D_CBC_128_AES]) {
2009 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2010 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2014 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2016 print_result(D_CBC_128_AES, testnum, count, d);
2019 if (doit[D_CBC_192_AES]) {
2020 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2021 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2025 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2027 print_result(D_CBC_192_AES, testnum, count, d);
2030 if (doit[D_CBC_256_AES]) {
2031 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2032 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2036 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2038 print_result(D_CBC_256_AES, testnum, count, d);
2042 if (doit[D_IGE_128_AES]) {
2043 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2044 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2048 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2050 print_result(D_IGE_128_AES, testnum, count, d);
2053 if (doit[D_IGE_192_AES]) {
2054 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2055 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2059 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2061 print_result(D_IGE_192_AES, testnum, count, d);
2064 if (doit[D_IGE_256_AES]) {
2065 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2066 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2070 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 =
2078 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2079 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2080 (unsigned char *)"0123456789ab", 12);
2083 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2084 print_message(names[D_GHASH], c[D_GHASH][testnum],
2087 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2089 print_result(D_GHASH, testnum, count, d);
2091 for (i = 0; i < loopargs_len; i++)
2092 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2094 #ifndef OPENSSL_NO_CAMELLIA
2095 if (doit[D_CBC_128_CML]) {
2096 if (async_jobs > 0) {
2097 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2098 names[D_CBC_128_CML]);
2099 doit[D_CBC_128_CML] = 0;
2101 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2102 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2105 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2106 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2107 (size_t)lengths[testnum], &camellia_ks1,
2108 iv, CAMELLIA_ENCRYPT);
2110 print_result(D_CBC_128_CML, testnum, count, d);
2113 if (doit[D_CBC_192_CML]) {
2114 if (async_jobs > 0) {
2115 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2116 names[D_CBC_192_CML]);
2117 doit[D_CBC_192_CML] = 0;
2119 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2120 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2122 if (async_jobs > 0) {
2123 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2127 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2128 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2129 (size_t)lengths[testnum], &camellia_ks2,
2130 iv, CAMELLIA_ENCRYPT);
2132 print_result(D_CBC_192_CML, testnum, count, d);
2135 if (doit[D_CBC_256_CML]) {
2136 if (async_jobs > 0) {
2137 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2138 names[D_CBC_256_CML]);
2139 doit[D_CBC_256_CML] = 0;
2141 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2142 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2145 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2146 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2147 (size_t)lengths[testnum], &camellia_ks3,
2148 iv, CAMELLIA_ENCRYPT);
2150 print_result(D_CBC_256_CML, testnum, count, d);
2154 #ifndef OPENSSL_NO_IDEA
2155 if (doit[D_CBC_IDEA]) {
2156 if (async_jobs > 0) {
2157 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2159 doit[D_CBC_IDEA] = 0;
2161 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2162 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2165 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2166 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2167 (size_t)lengths[testnum], &idea_ks,
2170 print_result(D_CBC_IDEA, testnum, count, d);
2174 #ifndef OPENSSL_NO_SEED
2175 if (doit[D_CBC_SEED]) {
2176 if (async_jobs > 0) {
2177 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2179 doit[D_CBC_SEED] = 0;
2181 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2182 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2185 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2186 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2187 (size_t)lengths[testnum], &seed_ks, iv, 1);
2189 print_result(D_CBC_SEED, testnum, count, d);
2193 #ifndef OPENSSL_NO_RC2
2194 if (doit[D_CBC_RC2]) {
2195 if (async_jobs > 0) {
2196 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2198 doit[D_CBC_RC2] = 0;
2200 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2201 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2203 if (async_jobs > 0) {
2204 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2208 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2209 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2210 (size_t)lengths[testnum], &rc2_ks,
2213 print_result(D_CBC_RC2, testnum, count, d);
2217 #ifndef OPENSSL_NO_RC5
2218 if (doit[D_CBC_RC5]) {
2219 if (async_jobs > 0) {
2220 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2222 doit[D_CBC_RC5] = 0;
2224 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2225 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2227 if (async_jobs > 0) {
2228 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2232 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2233 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2234 (size_t)lengths[testnum], &rc5_ks,
2237 print_result(D_CBC_RC5, testnum, count, d);
2241 #ifndef OPENSSL_NO_BF
2242 if (doit[D_CBC_BF]) {
2243 if (async_jobs > 0) {
2244 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2248 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2249 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2252 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2253 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2254 (size_t)lengths[testnum], &bf_ks,
2257 print_result(D_CBC_BF, testnum, count, d);
2261 #ifndef OPENSSL_NO_CAST
2262 if (doit[D_CBC_CAST]) {
2263 if (async_jobs > 0) {
2264 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2266 doit[D_CBC_CAST] = 0;
2268 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2269 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2272 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2273 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2274 (size_t)lengths[testnum], &cast_ks,
2277 print_result(D_CBC_CAST, testnum, count, d);
2283 if (multiblock && evp_cipher) {
2285 (EVP_CIPHER_flags(evp_cipher) &
2286 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2287 BIO_printf(bio_err, "%s is not multi-block capable\n",
2288 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2291 if (async_jobs > 0) {
2292 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2295 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] = (double)count / d;
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] = (double)count / d;
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] = (double)count / d;
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] = (double)count / d;
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] = (double)count / d;
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] = (double)count / d;
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 /* Ensure that the error queue is empty */
2586 if (ERR_peek_error()) {
2588 "WARNING: the error queue contains previous unhandled errors.\n");
2589 ERR_print_errors(bio_err);
2592 /* Let's try to create a ctx directly from the NID: this works for
2593 * curves like Curve25519 that are not implemented through the low
2594 * level EC interface.
2595 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2596 * then we set the curve by NID before deriving the actual keygen
2597 * ctx for that specific curve. */
2598 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2600 EVP_PKEY_CTX *pctx = NULL;
2601 EVP_PKEY *params = NULL;
2603 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2604 * "int_ctx_new:unsupported algorithm" error was added to the
2606 * We remove it from the error queue as we are handling it. */
2607 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2608 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2609 /* check that the error origin matches */
2610 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2611 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2612 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2613 ERR_get_error(); /* pop error from queue */
2614 if (ERR_peek_error()) {
2616 "Unhandled error in the error queue during ECDH init.\n");
2617 ERR_print_errors(bio_err);
2622 if ( /* Create the context for parameter generation */
2623 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2624 /* Initialise the parameter generation */
2625 !EVP_PKEY_paramgen_init(pctx) ||
2626 /* Set the curve by NID */
2627 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2630 /* Create the parameter object params */
2631 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2633 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2634 ERR_print_errors(bio_err);
2638 /* Create the context for the key generation */
2639 kctx = EVP_PKEY_CTX_new(params, NULL);
2641 EVP_PKEY_free(params);
2643 EVP_PKEY_CTX_free(pctx);
2646 if (!kctx || /* keygen ctx is not null */
2647 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2649 BIO_printf(bio_err, "ECDH keygen failure.\n");
2650 ERR_print_errors(bio_err);
2655 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2656 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2657 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2658 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2659 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2660 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2661 outlen == 0 || /* ensure outlen is a valid size */
2662 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2664 BIO_printf(bio_err, "ECDH key generation failure.\n");
2665 ERR_print_errors(bio_err);
2670 /* Here we perform a test run, comparing the output of a*B and b*A;
2671 * we try this here and assume that further EVP_PKEY_derive calls
2672 * never fail, so we can skip checks in the actually benchmarked
2673 * code, for maximum performance. */
2674 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2675 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2676 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2677 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2678 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2679 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2680 test_outlen != outlen /* compare output length */ ) {
2682 BIO_printf(bio_err, "ECDH computation failure.\n");
2683 ERR_print_errors(bio_err);
2688 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2689 if (CRYPTO_memcmp(loopargs[i].secret_a,
2690 loopargs[i].secret_b, outlen)) {
2692 BIO_printf(bio_err, "ECDH computations don't match.\n");
2693 ERR_print_errors(bio_err);
2698 loopargs[i].ecdh_ctx[testnum] = ctx;
2699 loopargs[i].outlen[testnum] = outlen;
2701 EVP_PKEY_CTX_free(kctx);
2703 EVP_PKEY_CTX_free(test_ctx);
2706 if (ecdh_checks != 0) {
2707 pkey_print_message("", "ecdh",
2709 test_curves_bits[testnum], ECDH_SECONDS);
2712 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2715 mr ? "+R7:%ld:%d:%.2f\n" :
2716 "%ld %d-bit ECDH ops in %.2fs\n", count,
2717 test_curves_bits[testnum], d);
2718 ecdh_results[testnum][0] = (double)count / d;
2722 if (rsa_count <= 1) {
2723 /* if longer than 10s, don't do any more */
2724 for (testnum++; testnum < EC_NUM; testnum++)
2725 ecdh_doit[testnum] = 0;
2728 #endif /* OPENSSL_NO_EC */
2733 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2734 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2736 printf("%s ", BN_options());
2737 #ifndef OPENSSL_NO_MD2
2738 printf("%s ", MD2_options());
2740 #ifndef OPENSSL_NO_RC4
2741 printf("%s ", RC4_options());
2743 #ifndef OPENSSL_NO_DES
2744 printf("%s ", DES_options());
2746 printf("%s ", AES_options());
2747 #ifndef OPENSSL_NO_IDEA
2748 printf("%s ", IDEA_options());
2750 #ifndef OPENSSL_NO_BF
2751 printf("%s ", BF_options());
2753 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2761 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2764 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2765 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2769 for (k = 0; k < ALGOR_NUM; k++) {
2773 printf("+F:%d:%s", k, names[k]);
2775 printf("%-13s", names[k]);
2776 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2777 if (results[k][testnum] > 10000 && !mr)
2778 printf(" %11.2fk", results[k][testnum] / 1e3);
2780 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2784 #ifndef OPENSSL_NO_RSA
2786 for (k = 0; k < RSA_NUM; k++) {
2789 if (testnum && !mr) {
2790 printf("%18ssign verify sign/s verify/s\n", " ");
2794 printf("+F2:%u:%u:%f:%f\n",
2795 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2797 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2798 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2799 rsa_results[k][0], rsa_results[k][1]);
2802 #ifndef OPENSSL_NO_DSA
2804 for (k = 0; k < DSA_NUM; k++) {
2807 if (testnum && !mr) {
2808 printf("%18ssign verify sign/s verify/s\n", " ");
2812 printf("+F3:%u:%u:%f:%f\n",
2813 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2815 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2816 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2817 dsa_results[k][0], dsa_results[k][1]);
2820 #ifndef OPENSSL_NO_EC
2822 for (k = 0; k < EC_NUM; k++) {
2825 if (testnum && !mr) {
2826 printf("%30ssign verify sign/s verify/s\n", " ");
2831 printf("+F4:%u:%u:%f:%f\n",
2832 k, test_curves_bits[k],
2833 ecdsa_results[k][0], ecdsa_results[k][1]);
2835 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2836 test_curves_bits[k],
2837 test_curves_names[k],
2838 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2839 ecdsa_results[k][0], ecdsa_results[k][1]);
2843 for (k = 0; k < EC_NUM; k++) {
2846 if (testnum && !mr) {
2847 printf("%30sop op/s\n", " ");
2851 printf("+F5:%u:%u:%f:%f\n",
2852 k, test_curves_bits[k],
2853 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2856 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2857 test_curves_bits[k],
2858 test_curves_names[k],
2859 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2866 ERR_print_errors(bio_err);
2867 for (i = 0; i < loopargs_len; i++) {
2868 OPENSSL_free(loopargs[i].buf_malloc);
2869 OPENSSL_free(loopargs[i].buf2_malloc);
2871 #ifndef OPENSSL_NO_RSA
2872 for (k = 0; k < RSA_NUM; k++)
2873 RSA_free(loopargs[i].rsa_key[k]);
2875 #ifndef OPENSSL_NO_DSA
2876 for (k = 0; k < DSA_NUM; k++)
2877 DSA_free(loopargs[i].dsa_key[k]);
2879 #ifndef OPENSSL_NO_EC
2880 for (k = 0; k < EC_NUM; k++) {
2881 EC_KEY_free(loopargs[i].ecdsa[k]);
2882 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2884 OPENSSL_free(loopargs[i].secret_a);
2885 OPENSSL_free(loopargs[i].secret_b);
2889 if (async_jobs > 0) {
2890 for (i = 0; i < loopargs_len; i++)
2891 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2895 ASYNC_cleanup_thread();
2897 OPENSSL_free(loopargs);
2902 static void print_message(const char *s, long num, int length)
2906 mr ? "+DT:%s:%d:%d\n"
2907 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2908 (void)BIO_flush(bio_err);
2912 mr ? "+DN:%s:%ld:%d\n"
2913 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2914 (void)BIO_flush(bio_err);
2918 static void pkey_print_message(const char *str, const char *str2, long num,
2923 mr ? "+DTP:%d:%s:%s:%d\n"
2924 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2925 (void)BIO_flush(bio_err);
2929 mr ? "+DNP:%ld:%d:%s:%s\n"
2930 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2931 (void)BIO_flush(bio_err);
2935 static void print_result(int alg, int run_no, int count, double time_used)
2938 BIO_puts(bio_err, "EVP error!\n");
2942 mr ? "+R:%d:%s:%f\n"
2943 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2944 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2948 static char *sstrsep(char **string, const char *delim)
2951 char *token = *string;
2956 memset(isdelim, 0, sizeof isdelim);
2960 isdelim[(unsigned char)(*delim)] = 1;
2964 while (!isdelim[(unsigned char)(**string)]) {
2976 static int do_multi(int multi)
2981 static char sep[] = ":";
2983 fds = malloc(sizeof(*fds) * multi);
2984 for (n = 0; n < multi; ++n) {
2985 if (pipe(fd) == -1) {
2986 BIO_printf(bio_err, "pipe failure\n");
2990 (void)BIO_flush(bio_err);
2997 if (dup(fd[1]) == -1) {
2998 BIO_printf(bio_err, "dup failed\n");
3007 printf("Forked child %d\n", n);
3010 /* for now, assume the pipe is long enough to take all the output */
3011 for (n = 0; n < multi; ++n) {
3016 f = fdopen(fds[n], "r");
3017 while (fgets(buf, sizeof buf, f)) {
3018 p = strchr(buf, '\n');
3021 if (buf[0] != '+') {
3023 "Don't understand line '%s' from child %d\n", buf,
3027 printf("Got: %s from %d\n", buf, n);
3028 if (strncmp(buf, "+F:", 3) == 0) {
3033 alg = atoi(sstrsep(&p, sep));
3035 for (j = 0; j < SIZE_NUM; ++j)
3036 results[alg][j] += atof(sstrsep(&p, sep));
3037 } else if (strncmp(buf, "+F2:", 4) == 0) {
3042 k = atoi(sstrsep(&p, sep));
3045 d = atof(sstrsep(&p, sep));
3046 rsa_results[k][0] += d;
3048 d = atof(sstrsep(&p, sep));
3049 rsa_results[k][1] += d;
3051 # ifndef OPENSSL_NO_DSA
3052 else if (strncmp(buf, "+F3:", 4) == 0) {
3057 k = atoi(sstrsep(&p, sep));
3060 d = atof(sstrsep(&p, sep));
3061 dsa_results[k][0] += d;
3063 d = atof(sstrsep(&p, sep));
3064 dsa_results[k][1] += d;
3067 # ifndef OPENSSL_NO_EC
3068 else if (strncmp(buf, "+F4:", 4) == 0) {
3073 k = atoi(sstrsep(&p, sep));
3076 d = atof(sstrsep(&p, sep));
3077 ecdsa_results[k][0] += d;
3079 d = atof(sstrsep(&p, sep));
3080 ecdsa_results[k][1] += d;
3081 } else if (strncmp(buf, "+F5:", 4) == 0) {
3086 k = atoi(sstrsep(&p, sep));
3089 d = atof(sstrsep(&p, sep));
3090 ecdh_results[k][0] += d;
3094 else if (strncmp(buf, "+H:", 3) == 0) {
3097 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3108 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3110 static int mblengths[] =
3111 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3112 int j, count, num = OSSL_NELEM(mblengths);
3113 const char *alg_name;
3114 unsigned char *inp, *out, no_key[32], no_iv[16];
3115 EVP_CIPHER_CTX *ctx;
3118 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3119 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3120 ctx = EVP_CIPHER_CTX_new();
3121 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3122 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3123 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3125 for (j = 0; j < num; j++) {
3126 print_message(alg_name, 0, mblengths[j]);
3128 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3129 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3130 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3131 size_t len = mblengths[j];
3134 memset(aad, 0, 8); /* avoid uninitialized values */
3135 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3136 aad[9] = 3; /* version */
3138 aad[11] = 0; /* length */
3140 mb_param.out = NULL;
3143 mb_param.interleave = 8;
3145 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3146 sizeof(mb_param), &mb_param);
3152 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3153 sizeof(mb_param), &mb_param);
3157 RAND_bytes(out, 16);
3161 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3162 EVP_AEAD_TLS1_AAD_LEN, aad);
3163 EVP_Cipher(ctx, out, inp, len + pad);
3167 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3168 : "%d %s's in %.2fs\n", count, "evp", d);
3169 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3173 fprintf(stdout, "+H");
3174 for (j = 0; j < num; j++)
3175 fprintf(stdout, ":%d", mblengths[j]);
3176 fprintf(stdout, "\n");
3177 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3178 for (j = 0; j < num; j++)
3179 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3180 fprintf(stdout, "\n");
3183 "The 'numbers' are in 1000s of bytes per second processed.\n");
3184 fprintf(stdout, "type ");
3185 for (j = 0; j < num; j++)
3186 fprintf(stdout, "%7d bytes", mblengths[j]);
3187 fprintf(stdout, "\n");
3188 fprintf(stdout, "%-24s", alg_name);
3190 for (j = 0; j < num; j++) {
3191 if (results[D_EVP][j] > 10000)
3192 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3194 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3196 fprintf(stdout, "\n");
3201 EVP_CIPHER_CTX_free(ctx);