2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the OpenSSL license (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #define PRIME_SECONDS 10
14 #define RSA_SECONDS 10
15 #define DSA_SECONDS 10
16 #define ECDSA_SECONDS 10
17 #define ECDH_SECONDS 10
24 #include <openssl/crypto.h>
25 #include <openssl/rand.h>
26 #include <openssl/err.h>
27 #include <openssl/evp.h>
28 #include <openssl/objects.h>
29 #include <openssl/async.h>
30 #if !defined(OPENSSL_SYS_MSDOS)
31 # include OPENSSL_UNISTD
38 #include <openssl/bn.h>
39 #ifndef OPENSSL_NO_DES
40 # include <openssl/des.h>
42 #include <openssl/aes.h>
43 #ifndef OPENSSL_NO_CAMELLIA
44 # include <openssl/camellia.h>
46 #ifndef OPENSSL_NO_MD2
47 # include <openssl/md2.h>
49 #ifndef OPENSSL_NO_MDC2
50 # include <openssl/mdc2.h>
52 #ifndef OPENSSL_NO_MD4
53 # include <openssl/md4.h>
55 #ifndef OPENSSL_NO_MD5
56 # include <openssl/md5.h>
58 #include <openssl/hmac.h>
59 #include <openssl/sha.h>
60 #ifndef OPENSSL_NO_RMD160
61 # include <openssl/ripemd.h>
63 #ifndef OPENSSL_NO_WHIRLPOOL
64 # include <openssl/whrlpool.h>
66 #ifndef OPENSSL_NO_RC4
67 # include <openssl/rc4.h>
69 #ifndef OPENSSL_NO_RC5
70 # include <openssl/rc5.h>
72 #ifndef OPENSSL_NO_RC2
73 # include <openssl/rc2.h>
75 #ifndef OPENSSL_NO_IDEA
76 # include <openssl/idea.h>
78 #ifndef OPENSSL_NO_SEED
79 # include <openssl/seed.h>
82 # include <openssl/blowfish.h>
84 #ifndef OPENSSL_NO_CAST
85 # include <openssl/cast.h>
87 #ifndef OPENSSL_NO_RSA
88 # include <openssl/rsa.h>
89 # include "./testrsa.h"
91 #include <openssl/x509.h>
92 #ifndef OPENSSL_NO_DSA
93 # include <openssl/dsa.h>
94 # include "./testdsa.h"
97 # include <openssl/ec.h>
99 #include <openssl/modes.h>
102 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
116 #define BUFSIZE (1024*16+1)
117 #define MAX_MISALIGNMENT 63
126 #define MAX_ECDH_SIZE 256
129 static volatile int run = 0;
132 static int usertime = 1;
134 typedef struct loopargs_st {
135 ASYNC_JOB *inprogress_job;
136 ASYNC_WAIT_CTX *wait_ctx;
139 unsigned char *buf_malloc;
140 unsigned char *buf2_malloc;
142 #ifndef OPENSSL_NO_RSA
143 RSA *rsa_key[RSA_NUM];
145 #ifndef OPENSSL_NO_DSA
146 DSA *dsa_key[DSA_NUM];
148 #ifndef OPENSSL_NO_EC
149 EC_KEY *ecdsa[EC_NUM];
150 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
151 unsigned char *secret_a;
152 unsigned char *secret_b;
153 size_t outlen[EC_NUM];
157 GCM128_CONTEXT *gcm_ctx;
160 #ifndef OPENSSL_NO_MD2
161 static int EVP_Digest_MD2_loop(void *args);
164 #ifndef OPENSSL_NO_MDC2
165 static int EVP_Digest_MDC2_loop(void *args);
167 #ifndef OPENSSL_NO_MD4
168 static int EVP_Digest_MD4_loop(void *args);
170 #ifndef OPENSSL_NO_MD5
171 static int MD5_loop(void *args);
172 static int HMAC_loop(void *args);
174 static int SHA1_loop(void *args);
175 static int SHA256_loop(void *args);
176 static int SHA512_loop(void *args);
177 #ifndef OPENSSL_NO_WHIRLPOOL
178 static int WHIRLPOOL_loop(void *args);
180 #ifndef OPENSSL_NO_RMD160
181 static int EVP_Digest_RMD160_loop(void *args);
183 #ifndef OPENSSL_NO_RC4
184 static int RC4_loop(void *args);
186 #ifndef OPENSSL_NO_DES
187 static int DES_ncbc_encrypt_loop(void *args);
188 static int DES_ede3_cbc_encrypt_loop(void *args);
190 static int AES_cbc_128_encrypt_loop(void *args);
191 static int AES_cbc_192_encrypt_loop(void *args);
192 static int AES_ige_128_encrypt_loop(void *args);
193 static int AES_cbc_256_encrypt_loop(void *args);
194 static int AES_ige_192_encrypt_loop(void *args);
195 static int AES_ige_256_encrypt_loop(void *args);
196 static int CRYPTO_gcm128_aad_loop(void *args);
197 static int EVP_Update_loop(void *args);
198 static int EVP_Digest_loop(void *args);
199 #ifndef OPENSSL_NO_RSA
200 static int RSA_sign_loop(void *args);
201 static int RSA_verify_loop(void *args);
203 #ifndef OPENSSL_NO_DSA
204 static int DSA_sign_loop(void *args);
205 static int DSA_verify_loop(void *args);
207 #ifndef OPENSSL_NO_EC
208 static int ECDSA_sign_loop(void *args);
209 static int ECDSA_verify_loop(void *args);
211 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
212 loopargs_t * loopargs);
214 static double Time_F(int s);
215 static void print_message(const char *s, long num, int length);
216 static void pkey_print_message(const char *str, const char *str2,
217 long num, int bits, int sec);
218 static void print_result(int alg, int run_no, int count, double time_used);
220 static int do_multi(int multi);
223 static const char *names[ALGOR_NUM] = {
224 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
225 "des cbc", "des ede3", "idea cbc", "seed cbc",
226 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
227 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
228 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
229 "evp", "sha256", "sha512", "whirlpool",
230 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
233 static double results[ALGOR_NUM][SIZE_NUM];
235 static const int lengths[SIZE_NUM] = {
236 16, 64, 256, 1024, 8 * 1024, 16 * 1024
239 #ifndef OPENSSL_NO_RSA
240 static double rsa_results[RSA_NUM][2];
242 #ifndef OPENSSL_NO_DSA
243 static double dsa_results[DSA_NUM][2];
245 #ifndef OPENSSL_NO_EC
246 static double ecdsa_results[EC_NUM][2];
247 static double ecdh_results[EC_NUM][1];
250 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
251 static const char rnd_seed[] =
252 "string to make the random number generator think it has randomness";
256 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
257 # define SIGRETTYPE void
259 # define SIGRETTYPE int
262 static SIGRETTYPE sig_done(int sig);
263 static SIGRETTYPE sig_done(int sig)
265 signal(SIGALRM, sig_done);
275 # if !defined(SIGALRM)
278 static unsigned int lapse;
279 static volatile unsigned int schlock;
280 static void alarm_win32(unsigned int secs)
285 # define alarm alarm_win32
287 static DWORD WINAPI sleepy(VOID * arg)
295 static double Time_F(int s)
302 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
304 DWORD err = GetLastError();
305 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
309 Sleep(0); /* scheduler spinlock */
310 ret = app_tminterval(s, usertime);
312 ret = app_tminterval(s, usertime);
314 TerminateThread(thr, 0);
322 static double Time_F(int s)
324 double ret = app_tminterval(s, usertime);
331 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
333 static int found(const char *name, const OPT_PAIR *pairs, int *result)
335 for (; pairs->name; pairs++)
336 if (strcmp(name, pairs->name) == 0) {
337 *result = pairs->retval;
343 typedef enum OPTION_choice {
344 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
345 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
346 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM
349 const OPTIONS speed_options[] = {
350 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
351 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
352 {"help", OPT_HELP, '-', "Display this summary"},
353 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
354 {"decrypt", OPT_DECRYPT, '-',
355 "Time decryption instead of encryption (only EVP)"},
356 {"mr", OPT_MR, '-', "Produce machine readable output"},
358 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
359 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
360 {"elapsed", OPT_ELAPSED, '-',
361 "Measure time in real time instead of CPU user time"},
363 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
365 #ifndef OPENSSL_NO_ASYNC
366 {"async_jobs", OPT_ASYNCJOBS, 'p',
367 "Enable async mode and start pnum jobs"},
370 #ifndef OPENSSL_NO_ENGINE
371 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
386 #define D_CBC_IDEA 10
387 #define D_CBC_SEED 11
391 #define D_CBC_CAST 15
392 #define D_CBC_128_AES 16
393 #define D_CBC_192_AES 17
394 #define D_CBC_256_AES 18
395 #define D_CBC_128_CML 19
396 #define D_CBC_192_CML 20
397 #define D_CBC_256_CML 21
401 #define D_WHIRLPOOL 25
402 #define D_IGE_128_AES 26
403 #define D_IGE_192_AES 27
404 #define D_IGE_256_AES 28
406 static OPT_PAIR doit_choices[] = {
407 #ifndef OPENSSL_NO_MD2
410 #ifndef OPENSSL_NO_MDC2
413 #ifndef OPENSSL_NO_MD4
416 #ifndef OPENSSL_NO_MD5
421 {"sha256", D_SHA256},
422 {"sha512", D_SHA512},
423 #ifndef OPENSSL_NO_WHIRLPOOL
424 {"whirlpool", D_WHIRLPOOL},
426 #ifndef OPENSSL_NO_RMD160
427 {"ripemd", D_RMD160},
428 {"rmd160", D_RMD160},
429 {"ripemd160", D_RMD160},
431 #ifndef OPENSSL_NO_RC4
434 #ifndef OPENSSL_NO_DES
435 {"des-cbc", D_CBC_DES},
436 {"des-ede3", D_EDE3_DES},
438 {"aes-128-cbc", D_CBC_128_AES},
439 {"aes-192-cbc", D_CBC_192_AES},
440 {"aes-256-cbc", D_CBC_256_AES},
441 {"aes-128-ige", D_IGE_128_AES},
442 {"aes-192-ige", D_IGE_192_AES},
443 {"aes-256-ige", D_IGE_256_AES},
444 #ifndef OPENSSL_NO_RC2
445 {"rc2-cbc", D_CBC_RC2},
448 #ifndef OPENSSL_NO_RC5
449 {"rc5-cbc", D_CBC_RC5},
452 #ifndef OPENSSL_NO_IDEA
453 {"idea-cbc", D_CBC_IDEA},
454 {"idea", D_CBC_IDEA},
456 #ifndef OPENSSL_NO_SEED
457 {"seed-cbc", D_CBC_SEED},
458 {"seed", D_CBC_SEED},
460 #ifndef OPENSSL_NO_BF
461 {"bf-cbc", D_CBC_BF},
462 {"blowfish", D_CBC_BF},
465 #ifndef OPENSSL_NO_CAST
466 {"cast-cbc", D_CBC_CAST},
467 {"cast", D_CBC_CAST},
468 {"cast5", D_CBC_CAST},
474 #ifndef OPENSSL_NO_DSA
476 # define R_DSA_1024 1
477 # define R_DSA_2048 2
478 static OPT_PAIR dsa_choices[] = {
479 {"dsa512", R_DSA_512},
480 {"dsa1024", R_DSA_1024},
481 {"dsa2048", R_DSA_2048},
492 #define R_RSA_15360 6
493 static OPT_PAIR rsa_choices[] = {
494 {"rsa512", R_RSA_512},
495 {"rsa1024", R_RSA_1024},
496 {"rsa2048", R_RSA_2048},
497 {"rsa3072", R_RSA_3072},
498 {"rsa4096", R_RSA_4096},
499 {"rsa7680", R_RSA_7680},
500 {"rsa15360", R_RSA_15360},
520 #define R_EC_X25519 16
521 #ifndef OPENSSL_NO_EC
522 static OPT_PAIR ecdsa_choices[] = {
523 {"ecdsap160", R_EC_P160},
524 {"ecdsap192", R_EC_P192},
525 {"ecdsap224", R_EC_P224},
526 {"ecdsap256", R_EC_P256},
527 {"ecdsap384", R_EC_P384},
528 {"ecdsap521", R_EC_P521},
529 {"ecdsak163", R_EC_K163},
530 {"ecdsak233", R_EC_K233},
531 {"ecdsak283", R_EC_K283},
532 {"ecdsak409", R_EC_K409},
533 {"ecdsak571", R_EC_K571},
534 {"ecdsab163", R_EC_B163},
535 {"ecdsab233", R_EC_B233},
536 {"ecdsab283", R_EC_B283},
537 {"ecdsab409", R_EC_B409},
538 {"ecdsab571", R_EC_B571},
542 static OPT_PAIR ecdh_choices[] = {
543 {"ecdhp160", R_EC_P160},
544 {"ecdhp192", R_EC_P192},
545 {"ecdhp224", R_EC_P224},
546 {"ecdhp256", R_EC_P256},
547 {"ecdhp384", R_EC_P384},
548 {"ecdhp521", R_EC_P521},
549 {"ecdhk163", R_EC_K163},
550 {"ecdhk233", R_EC_K233},
551 {"ecdhk283", R_EC_K283},
552 {"ecdhk409", R_EC_K409},
553 {"ecdhk571", R_EC_K571},
554 {"ecdhb163", R_EC_B163},
555 {"ecdhb233", R_EC_B233},
556 {"ecdhb283", R_EC_B283},
557 {"ecdhb409", R_EC_B409},
558 {"ecdhb571", R_EC_B571},
559 {"ecdhx25519", R_EC_X25519},
565 # define COND(d) (count < (d))
566 # define COUNT(d) (d)
568 # define COND(unused_cond) (run && count<0x7fffffff)
569 # define COUNT(d) (count)
574 /* Nb of iterations to do per algorithm and key-size */
575 static long c[ALGOR_NUM][SIZE_NUM];
577 #ifndef OPENSSL_NO_MD2
578 static int EVP_Digest_MD2_loop(void *args)
580 loopargs_t *tempargs = *(loopargs_t **) args;
581 unsigned char *buf = tempargs->buf;
582 unsigned char md2[MD2_DIGEST_LENGTH];
585 for (count = 0; COND(c[D_MD2][testnum]); count++) {
586 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
594 #ifndef OPENSSL_NO_MDC2
595 static int EVP_Digest_MDC2_loop(void *args)
597 loopargs_t *tempargs = *(loopargs_t **) args;
598 unsigned char *buf = tempargs->buf;
599 unsigned char mdc2[MDC2_DIGEST_LENGTH];
602 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
603 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
611 #ifndef OPENSSL_NO_MD4
612 static int EVP_Digest_MD4_loop(void *args)
614 loopargs_t *tempargs = *(loopargs_t **) args;
615 unsigned char *buf = tempargs->buf;
616 unsigned char md4[MD4_DIGEST_LENGTH];
619 for (count = 0; COND(c[D_MD4][testnum]); count++) {
620 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
628 #ifndef OPENSSL_NO_MD5
629 static int MD5_loop(void *args)
631 loopargs_t *tempargs = *(loopargs_t **) args;
632 unsigned char *buf = tempargs->buf;
633 unsigned char md5[MD5_DIGEST_LENGTH];
635 for (count = 0; COND(c[D_MD5][testnum]); count++)
636 MD5(buf, lengths[testnum], md5);
640 static int HMAC_loop(void *args)
642 loopargs_t *tempargs = *(loopargs_t **) args;
643 unsigned char *buf = tempargs->buf;
644 HMAC_CTX *hctx = tempargs->hctx;
645 unsigned char hmac[MD5_DIGEST_LENGTH];
648 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
649 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
650 HMAC_Update(hctx, buf, lengths[testnum]);
651 HMAC_Final(hctx, hmac, NULL);
657 static int SHA1_loop(void *args)
659 loopargs_t *tempargs = *(loopargs_t **) args;
660 unsigned char *buf = tempargs->buf;
661 unsigned char sha[SHA_DIGEST_LENGTH];
663 for (count = 0; COND(c[D_SHA1][testnum]); count++)
664 SHA1(buf, lengths[testnum], sha);
668 static int SHA256_loop(void *args)
670 loopargs_t *tempargs = *(loopargs_t **) args;
671 unsigned char *buf = tempargs->buf;
672 unsigned char sha256[SHA256_DIGEST_LENGTH];
674 for (count = 0; COND(c[D_SHA256][testnum]); count++)
675 SHA256(buf, lengths[testnum], sha256);
679 static int SHA512_loop(void *args)
681 loopargs_t *tempargs = *(loopargs_t **) args;
682 unsigned char *buf = tempargs->buf;
683 unsigned char sha512[SHA512_DIGEST_LENGTH];
685 for (count = 0; COND(c[D_SHA512][testnum]); count++)
686 SHA512(buf, lengths[testnum], sha512);
690 #ifndef OPENSSL_NO_WHIRLPOOL
691 static int WHIRLPOOL_loop(void *args)
693 loopargs_t *tempargs = *(loopargs_t **) args;
694 unsigned char *buf = tempargs->buf;
695 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
697 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
698 WHIRLPOOL(buf, lengths[testnum], whirlpool);
703 #ifndef OPENSSL_NO_RMD160
704 static int EVP_Digest_RMD160_loop(void *args)
706 loopargs_t *tempargs = *(loopargs_t **) args;
707 unsigned char *buf = tempargs->buf;
708 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
710 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
711 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
712 NULL, EVP_ripemd160(), NULL))
719 #ifndef OPENSSL_NO_RC4
720 static RC4_KEY rc4_ks;
721 static int RC4_loop(void *args)
723 loopargs_t *tempargs = *(loopargs_t **) args;
724 unsigned char *buf = tempargs->buf;
726 for (count = 0; COND(c[D_RC4][testnum]); count++)
727 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
732 #ifndef OPENSSL_NO_DES
733 static unsigned char DES_iv[8];
734 static DES_key_schedule sch;
735 static DES_key_schedule sch2;
736 static DES_key_schedule sch3;
737 static int DES_ncbc_encrypt_loop(void *args)
739 loopargs_t *tempargs = *(loopargs_t **) args;
740 unsigned char *buf = tempargs->buf;
742 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
743 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
744 &DES_iv, DES_ENCRYPT);
748 static int DES_ede3_cbc_encrypt_loop(void *args)
750 loopargs_t *tempargs = *(loopargs_t **) args;
751 unsigned char *buf = tempargs->buf;
753 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
754 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
755 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
760 #define MAX_BLOCK_SIZE 128
762 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
763 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
764 static int AES_cbc_128_encrypt_loop(void *args)
766 loopargs_t *tempargs = *(loopargs_t **) args;
767 unsigned char *buf = tempargs->buf;
769 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
770 AES_cbc_encrypt(buf, buf,
771 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
775 static int AES_cbc_192_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_192_AES][testnum]); count++)
781 AES_cbc_encrypt(buf, buf,
782 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
786 static int AES_cbc_256_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_256_AES][testnum]); count++)
792 AES_cbc_encrypt(buf, buf,
793 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
797 static int AES_ige_128_encrypt_loop(void *args)
799 loopargs_t *tempargs = *(loopargs_t **) args;
800 unsigned char *buf = tempargs->buf;
801 unsigned char *buf2 = tempargs->buf2;
803 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
804 AES_ige_encrypt(buf, buf2,
805 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
809 static int AES_ige_192_encrypt_loop(void *args)
811 loopargs_t *tempargs = *(loopargs_t **) args;
812 unsigned char *buf = tempargs->buf;
813 unsigned char *buf2 = tempargs->buf2;
815 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
816 AES_ige_encrypt(buf, buf2,
817 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
821 static int AES_ige_256_encrypt_loop(void *args)
823 loopargs_t *tempargs = *(loopargs_t **) args;
824 unsigned char *buf = tempargs->buf;
825 unsigned char *buf2 = tempargs->buf2;
827 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
828 AES_ige_encrypt(buf, buf2,
829 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
833 static int CRYPTO_gcm128_aad_loop(void *args)
835 loopargs_t *tempargs = *(loopargs_t **) args;
836 unsigned char *buf = tempargs->buf;
837 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
839 for (count = 0; COND(c[D_GHASH][testnum]); count++)
840 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
844 static long save_count = 0;
845 static int decrypt = 0;
846 static int EVP_Update_loop(void *args)
848 loopargs_t *tempargs = *(loopargs_t **) args;
849 unsigned char *buf = tempargs->buf;
850 EVP_CIPHER_CTX *ctx = tempargs->ctx;
853 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
856 for (count = 0; COND(nb_iter); count++)
857 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
859 for (count = 0; COND(nb_iter); count++)
860 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
862 EVP_DecryptFinal_ex(ctx, buf, &outl);
864 EVP_EncryptFinal_ex(ctx, buf, &outl);
868 static const EVP_MD *evp_md = NULL;
869 static int EVP_Digest_loop(void *args)
871 loopargs_t *tempargs = *(loopargs_t **) args;
872 unsigned char *buf = tempargs->buf;
873 unsigned char md[EVP_MAX_MD_SIZE];
876 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
879 for (count = 0; COND(nb_iter); count++) {
880 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
886 #ifndef OPENSSL_NO_RSA
887 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
889 static int RSA_sign_loop(void *args)
891 loopargs_t *tempargs = *(loopargs_t **) args;
892 unsigned char *buf = tempargs->buf;
893 unsigned char *buf2 = tempargs->buf2;
894 unsigned int *rsa_num = &tempargs->siglen;
895 RSA **rsa_key = tempargs->rsa_key;
897 for (count = 0; COND(rsa_c[testnum][0]); count++) {
898 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
900 BIO_printf(bio_err, "RSA sign failure\n");
901 ERR_print_errors(bio_err);
909 static int RSA_verify_loop(void *args)
911 loopargs_t *tempargs = *(loopargs_t **) args;
912 unsigned char *buf = tempargs->buf;
913 unsigned char *buf2 = tempargs->buf2;
914 unsigned int rsa_num = tempargs->siglen;
915 RSA **rsa_key = tempargs->rsa_key;
917 for (count = 0; COND(rsa_c[testnum][1]); count++) {
919 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
921 BIO_printf(bio_err, "RSA verify failure\n");
922 ERR_print_errors(bio_err);
931 #ifndef OPENSSL_NO_DSA
932 static long dsa_c[DSA_NUM][2];
933 static int DSA_sign_loop(void *args)
935 loopargs_t *tempargs = *(loopargs_t **) args;
936 unsigned char *buf = tempargs->buf;
937 unsigned char *buf2 = tempargs->buf2;
938 DSA **dsa_key = tempargs->dsa_key;
939 unsigned int *siglen = &tempargs->siglen;
941 for (count = 0; COND(dsa_c[testnum][0]); count++) {
942 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
944 BIO_printf(bio_err, "DSA sign failure\n");
945 ERR_print_errors(bio_err);
953 static int DSA_verify_loop(void *args)
955 loopargs_t *tempargs = *(loopargs_t **) args;
956 unsigned char *buf = tempargs->buf;
957 unsigned char *buf2 = tempargs->buf2;
958 DSA **dsa_key = tempargs->dsa_key;
959 unsigned int siglen = tempargs->siglen;
961 for (count = 0; COND(dsa_c[testnum][1]); count++) {
962 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
964 BIO_printf(bio_err, "DSA verify failure\n");
965 ERR_print_errors(bio_err);
974 #ifndef OPENSSL_NO_EC
975 static long ecdsa_c[EC_NUM][2];
976 static int ECDSA_sign_loop(void *args)
978 loopargs_t *tempargs = *(loopargs_t **) args;
979 unsigned char *buf = tempargs->buf;
980 EC_KEY **ecdsa = tempargs->ecdsa;
981 unsigned char *ecdsasig = tempargs->buf2;
982 unsigned int *ecdsasiglen = &tempargs->siglen;
984 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
985 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
987 BIO_printf(bio_err, "ECDSA sign failure\n");
988 ERR_print_errors(bio_err);
996 static int ECDSA_verify_loop(void *args)
998 loopargs_t *tempargs = *(loopargs_t **) args;
999 unsigned char *buf = tempargs->buf;
1000 EC_KEY **ecdsa = tempargs->ecdsa;
1001 unsigned char *ecdsasig = tempargs->buf2;
1002 unsigned int ecdsasiglen = tempargs->siglen;
1004 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1005 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1007 BIO_printf(bio_err, "ECDSA verify failure\n");
1008 ERR_print_errors(bio_err);
1016 /* ******************************************************************** */
1017 static long ecdh_c[EC_NUM][1];
1019 static int ECDH_EVP_derive_key_loop(void *args)
1021 loopargs_t *tempargs = *(loopargs_t **) args;
1022 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1023 unsigned char *derived_secret = tempargs->secret_a;
1025 size_t *outlen = &(tempargs->outlen[testnum]);
1027 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1028 EVP_PKEY_derive(ctx, derived_secret, outlen);
1033 #endif /* OPENSSL_NO_EC */
1035 static int run_benchmark(int async_jobs,
1036 int (*loop_function) (void *), loopargs_t * loopargs)
1038 int job_op_count = 0;
1039 int total_op_count = 0;
1040 int num_inprogress = 0;
1041 int error = 0, i = 0, ret = 0;
1042 OSSL_ASYNC_FD job_fd = 0;
1043 size_t num_job_fds = 0;
1047 if (async_jobs == 0) {
1048 return loop_function((void *)&loopargs);
1051 for (i = 0; i < async_jobs && !error; i++) {
1052 loopargs_t *looparg_item = loopargs + i;
1054 /* Copy pointer content (looparg_t item address) into async context */
1055 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1056 &job_op_count, loop_function,
1057 (void *)&looparg_item, sizeof(looparg_item));
1063 if (job_op_count == -1) {
1066 total_op_count += job_op_count;
1071 BIO_printf(bio_err, "Failure in the job\n");
1072 ERR_print_errors(bio_err);
1078 while (num_inprogress > 0) {
1079 #if defined(OPENSSL_SYS_WINDOWS)
1081 #elif defined(OPENSSL_SYS_UNIX)
1082 int select_result = 0;
1083 OSSL_ASYNC_FD max_fd = 0;
1086 FD_ZERO(&waitfdset);
1088 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1089 if (loopargs[i].inprogress_job == NULL)
1092 if (!ASYNC_WAIT_CTX_get_all_fds
1093 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1094 || num_job_fds > 1) {
1095 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1096 ERR_print_errors(bio_err);
1100 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1102 FD_SET(job_fd, &waitfdset);
1103 if (job_fd > max_fd)
1107 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1109 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1110 "Decrease the value of async_jobs\n",
1111 max_fd, FD_SETSIZE);
1112 ERR_print_errors(bio_err);
1117 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1118 if (select_result == -1 && errno == EINTR)
1121 if (select_result == -1) {
1122 BIO_printf(bio_err, "Failure in the select\n");
1123 ERR_print_errors(bio_err);
1128 if (select_result == 0)
1132 for (i = 0; i < async_jobs; i++) {
1133 if (loopargs[i].inprogress_job == NULL)
1136 if (!ASYNC_WAIT_CTX_get_all_fds
1137 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1138 || num_job_fds > 1) {
1139 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1140 ERR_print_errors(bio_err);
1144 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1147 #if defined(OPENSSL_SYS_UNIX)
1148 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1150 #elif defined(OPENSSL_SYS_WINDOWS)
1151 if (num_job_fds == 1
1152 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1157 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1158 loopargs[i].wait_ctx, &job_op_count,
1159 loop_function, (void *)(loopargs + i),
1160 sizeof(loopargs_t));
1165 if (job_op_count == -1) {
1168 total_op_count += job_op_count;
1171 loopargs[i].inprogress_job = NULL;
1176 loopargs[i].inprogress_job = NULL;
1177 BIO_printf(bio_err, "Failure in the job\n");
1178 ERR_print_errors(bio_err);
1185 return error ? -1 : total_op_count;
1188 int speed_main(int argc, char **argv)
1191 loopargs_t *loopargs = NULL;
1193 int loopargs_len = 0;
1195 const char *engine_id = NULL;
1196 const EVP_CIPHER *evp_cipher = NULL;
1199 int multiblock = 0, pr_header = 0;
1200 int doit[ALGOR_NUM] = { 0 };
1201 int ret = 1, i, k, misalign = 0;
1206 unsigned int async_jobs = 0;
1207 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1208 || !defined(OPENSSL_NO_EC)
1212 /* What follows are the buffers and key material. */
1213 #ifndef OPENSSL_NO_RC5
1216 #ifndef OPENSSL_NO_RC2
1219 #ifndef OPENSSL_NO_IDEA
1220 IDEA_KEY_SCHEDULE idea_ks;
1222 #ifndef OPENSSL_NO_SEED
1223 SEED_KEY_SCHEDULE seed_ks;
1225 #ifndef OPENSSL_NO_BF
1228 #ifndef OPENSSL_NO_CAST
1231 static const unsigned char key16[16] = {
1232 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1233 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1235 static const unsigned char key24[24] = {
1236 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1237 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1238 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1240 static const unsigned char key32[32] = {
1241 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1242 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1243 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1244 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1246 #ifndef OPENSSL_NO_CAMELLIA
1247 static const unsigned char ckey24[24] = {
1248 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1249 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1250 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1252 static const unsigned char ckey32[32] = {
1253 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1254 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1255 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1256 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1258 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1260 #ifndef OPENSSL_NO_DES
1261 static DES_cblock key = {
1262 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1264 static DES_cblock key2 = {
1265 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1267 static DES_cblock key3 = {
1268 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1271 #ifndef OPENSSL_NO_RSA
1272 static const unsigned int rsa_bits[RSA_NUM] = {
1273 512, 1024, 2048, 3072, 4096, 7680, 15360
1275 static const unsigned char *rsa_data[RSA_NUM] = {
1276 test512, test1024, test2048, test3072, test4096, test7680, test15360
1278 static const int rsa_data_length[RSA_NUM] = {
1279 sizeof(test512), sizeof(test1024),
1280 sizeof(test2048), sizeof(test3072),
1281 sizeof(test4096), sizeof(test7680),
1284 int rsa_doit[RSA_NUM] = { 0 };
1286 #ifndef OPENSSL_NO_DSA
1287 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1288 int dsa_doit[DSA_NUM] = { 0 };
1290 #ifndef OPENSSL_NO_EC
1292 * We only test over the following curves as they are representative, To
1293 * add tests over more curves, simply add the curve NID and curve name to
1294 * the following arrays and increase the EC_NUM value accordingly.
1296 static const unsigned int test_curves[EC_NUM] = {
1298 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1299 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1301 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1302 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1303 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1308 static const char *test_curves_names[EC_NUM] = {
1310 "secp160r1", "nistp192", "nistp224",
1311 "nistp256", "nistp384", "nistp521",
1313 "nistk163", "nistk233", "nistk283",
1314 "nistk409", "nistk571", "nistb163",
1315 "nistb233", "nistb283", "nistb409",
1320 static const int test_curves_bits[EC_NUM] = {
1326 571, 253 /* X25519 */
1329 int ecdsa_doit[EC_NUM] = { 0 };
1330 int ecdh_doit[EC_NUM] = { 0 };
1331 #endif /* ndef OPENSSL_NO_EC */
1333 prog = opt_init(argc, argv, speed_options);
1334 while ((o = opt_next()) != OPT_EOF) {
1339 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1342 opt_help(speed_options);
1350 evp_cipher = EVP_get_cipherbyname(opt_arg());
1351 if (evp_cipher == NULL)
1352 evp_md = EVP_get_digestbyname(opt_arg());
1353 if (evp_cipher == NULL && evp_md == NULL) {
1355 "%s: %s is an unknown cipher or digest\n",
1366 * In a forked execution, an engine might need to be
1367 * initialised by each child process, not by the parent.
1368 * So store the name here and run setup_engine() later on.
1370 engine_id = opt_arg();
1374 multi = atoi(opt_arg());
1378 #ifndef OPENSSL_NO_ASYNC
1379 async_jobs = atoi(opt_arg());
1380 if (!ASYNC_is_capable()) {
1382 "%s: async_jobs specified but async not supported\n",
1386 if (async_jobs > 99999) {
1388 "%s: too many async_jobs\n",
1395 if (!opt_int(opt_arg(), &misalign))
1397 if (misalign > MISALIGN) {
1399 "%s: Maximum offset is %d\n", prog, MISALIGN);
1408 #ifdef OPENSSL_NO_MULTIBLOCK
1410 "%s: -mb specified but multi-block support is disabled\n",
1421 argc = opt_num_rest();
1424 /* Remaining arguments are algorithms. */
1425 for (; *argv; argv++) {
1426 if (found(*argv, doit_choices, &i)) {
1430 #ifndef OPENSSL_NO_DES
1431 if (strcmp(*argv, "des") == 0) {
1432 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1436 if (strcmp(*argv, "sha") == 0) {
1437 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1440 #ifndef OPENSSL_NO_RSA
1441 if (strcmp(*argv, "openssl") == 0)
1443 if (strcmp(*argv, "rsa") == 0) {
1444 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1445 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1446 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1447 rsa_doit[R_RSA_15360] = 1;
1450 if (found(*argv, rsa_choices, &i)) {
1455 #ifndef OPENSSL_NO_DSA
1456 if (strcmp(*argv, "dsa") == 0) {
1457 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1458 dsa_doit[R_DSA_2048] = 1;
1461 if (found(*argv, dsa_choices, &i)) {
1466 if (strcmp(*argv, "aes") == 0) {
1467 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1470 #ifndef OPENSSL_NO_CAMELLIA
1471 if (strcmp(*argv, "camellia") == 0) {
1472 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1476 #ifndef OPENSSL_NO_EC
1477 if (strcmp(*argv, "ecdsa") == 0) {
1478 for (i = 0; i < EC_NUM; i++)
1482 if (found(*argv, ecdsa_choices, &i)) {
1486 if (strcmp(*argv, "ecdh") == 0) {
1487 for (i = 0; i < EC_NUM; i++)
1491 if (found(*argv, ecdh_choices, &i)) {
1496 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1500 /* Initialize the job pool if async mode is enabled */
1501 if (async_jobs > 0) {
1502 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1504 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1509 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1511 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1512 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1514 for (i = 0; i < loopargs_len; i++) {
1515 if (async_jobs > 0) {
1516 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1517 if (loopargs[i].wait_ctx == NULL) {
1518 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1523 loopargs[i].buf_malloc =
1524 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1525 loopargs[i].buf2_malloc =
1526 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1527 /* Align the start of buffers on a 64 byte boundary */
1528 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1529 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1530 #ifndef OPENSSL_NO_EC
1531 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1532 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1537 if (multi && do_multi(multi))
1541 /* Initialize the engine after the fork */
1542 e = setup_engine(engine_id, 0);
1544 /* No parameters; turn on everything. */
1545 if ((argc == 0) && !doit[D_EVP]) {
1546 for (i = 0; i < ALGOR_NUM; i++)
1549 #ifndef OPENSSL_NO_RSA
1550 for (i = 0; i < RSA_NUM; i++)
1553 #ifndef OPENSSL_NO_DSA
1554 for (i = 0; i < DSA_NUM; i++)
1557 #ifndef OPENSSL_NO_EC
1558 for (i = 0; i < EC_NUM; i++)
1560 for (i = 0; i < EC_NUM; i++)
1564 for (i = 0; i < ALGOR_NUM; i++)
1568 if (usertime == 0 && !mr)
1570 "You have chosen to measure elapsed time "
1571 "instead of user CPU time.\n");
1573 #ifndef OPENSSL_NO_RSA
1574 for (i = 0; i < loopargs_len; i++) {
1575 for (k = 0; k < RSA_NUM; k++) {
1576 const unsigned char *p;
1579 loopargs[i].rsa_key[k] =
1580 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1581 if (loopargs[i].rsa_key[k] == NULL) {
1583 "internal error loading RSA key number %d\n", k);
1589 #ifndef OPENSSL_NO_DSA
1590 for (i = 0; i < loopargs_len; i++) {
1591 loopargs[i].dsa_key[0] = get_dsa(512);
1592 loopargs[i].dsa_key[1] = get_dsa(1024);
1593 loopargs[i].dsa_key[2] = get_dsa(2048);
1596 #ifndef OPENSSL_NO_DES
1597 DES_set_key_unchecked(&key, &sch);
1598 DES_set_key_unchecked(&key2, &sch2);
1599 DES_set_key_unchecked(&key3, &sch3);
1601 AES_set_encrypt_key(key16, 128, &aes_ks1);
1602 AES_set_encrypt_key(key24, 192, &aes_ks2);
1603 AES_set_encrypt_key(key32, 256, &aes_ks3);
1604 #ifndef OPENSSL_NO_CAMELLIA
1605 Camellia_set_key(key16, 128, &camellia_ks1);
1606 Camellia_set_key(ckey24, 192, &camellia_ks2);
1607 Camellia_set_key(ckey32, 256, &camellia_ks3);
1609 #ifndef OPENSSL_NO_IDEA
1610 IDEA_set_encrypt_key(key16, &idea_ks);
1612 #ifndef OPENSSL_NO_SEED
1613 SEED_set_key(key16, &seed_ks);
1615 #ifndef OPENSSL_NO_RC4
1616 RC4_set_key(&rc4_ks, 16, key16);
1618 #ifndef OPENSSL_NO_RC2
1619 RC2_set_key(&rc2_ks, 16, key16, 128);
1621 #ifndef OPENSSL_NO_RC5
1622 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1624 #ifndef OPENSSL_NO_BF
1625 BF_set_key(&bf_ks, 16, key16);
1627 #ifndef OPENSSL_NO_CAST
1628 CAST_set_key(&cast_ks, 16, key16);
1631 # ifndef OPENSSL_NO_DES
1632 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1638 for (it = count; it; it--)
1639 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1640 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1644 c[D_MD2][0] = count / 10;
1645 c[D_MDC2][0] = count / 10;
1646 c[D_MD4][0] = count;
1647 c[D_MD5][0] = count;
1648 c[D_HMAC][0] = count;
1649 c[D_SHA1][0] = count;
1650 c[D_RMD160][0] = count;
1651 c[D_RC4][0] = count * 5;
1652 c[D_CBC_DES][0] = count;
1653 c[D_EDE3_DES][0] = count / 3;
1654 c[D_CBC_IDEA][0] = count;
1655 c[D_CBC_SEED][0] = count;
1656 c[D_CBC_RC2][0] = count;
1657 c[D_CBC_RC5][0] = count;
1658 c[D_CBC_BF][0] = count;
1659 c[D_CBC_CAST][0] = count;
1660 c[D_CBC_128_AES][0] = count;
1661 c[D_CBC_192_AES][0] = count;
1662 c[D_CBC_256_AES][0] = count;
1663 c[D_CBC_128_CML][0] = count;
1664 c[D_CBC_192_CML][0] = count;
1665 c[D_CBC_256_CML][0] = count;
1666 c[D_SHA256][0] = count;
1667 c[D_SHA512][0] = count;
1668 c[D_WHIRLPOOL][0] = count;
1669 c[D_IGE_128_AES][0] = count;
1670 c[D_IGE_192_AES][0] = count;
1671 c[D_IGE_256_AES][0] = count;
1672 c[D_GHASH][0] = count;
1674 for (i = 1; i < SIZE_NUM; i++) {
1677 l0 = (long)lengths[0];
1678 l1 = (long)lengths[i];
1680 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1681 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1682 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1683 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1684 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1685 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1686 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1687 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1688 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1689 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1690 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1692 l0 = (long)lengths[i - 1];
1694 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1695 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1696 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1697 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1698 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1699 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1700 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1701 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1702 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1703 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1704 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1705 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1706 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1707 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1708 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1709 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1710 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1711 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1714 # ifndef OPENSSL_NO_RSA
1715 rsa_c[R_RSA_512][0] = count / 2000;
1716 rsa_c[R_RSA_512][1] = count / 400;
1717 for (i = 1; i < RSA_NUM; i++) {
1718 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1719 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1720 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1723 if (rsa_c[i][0] == 0) {
1724 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1731 # ifndef OPENSSL_NO_DSA
1732 dsa_c[R_DSA_512][0] = count / 1000;
1733 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1734 for (i = 1; i < DSA_NUM; i++) {
1735 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1736 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1737 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1740 if (dsa_c[i][0] == 0) {
1741 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1748 # ifndef OPENSSL_NO_EC
1749 ecdsa_c[R_EC_P160][0] = count / 1000;
1750 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1751 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1752 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1753 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1754 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1757 if (ecdsa_c[i][0] == 0) {
1763 ecdsa_c[R_EC_K163][0] = count / 1000;
1764 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1765 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1766 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1767 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1768 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1771 if (ecdsa_c[i][0] == 0) {
1777 ecdsa_c[R_EC_B163][0] = count / 1000;
1778 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1779 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1780 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1781 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1782 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1785 if (ecdsa_c[i][0] == 0) {
1792 ecdh_c[R_EC_P160][0] = count / 1000;
1793 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1794 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1795 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1798 if (ecdh_c[i][0] == 0) {
1803 ecdh_c[R_EC_K163][0] = count / 1000;
1804 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1805 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1806 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1809 if (ecdh_c[i][0] == 0) {
1814 ecdh_c[R_EC_B163][0] = count / 1000;
1815 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1816 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1817 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1820 if (ecdh_c[i][0] == 0) {
1828 /* not worth fixing */
1829 # error "You cannot disable DES on systems without SIGALRM."
1830 # endif /* OPENSSL_NO_DES */
1833 signal(SIGALRM, sig_done);
1835 #endif /* SIGALRM */
1837 #ifndef OPENSSL_NO_MD2
1839 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1840 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1842 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1844 print_result(D_MD2, testnum, count, d);
1848 #ifndef OPENSSL_NO_MDC2
1850 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1851 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1853 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1855 print_result(D_MDC2, testnum, count, d);
1860 #ifndef OPENSSL_NO_MD4
1862 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1863 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1865 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1867 print_result(D_MD4, testnum, count, d);
1872 #ifndef OPENSSL_NO_MD5
1874 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1875 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1877 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1879 print_result(D_MD5, testnum, count, d);
1884 static const char hmac_key[] = "This is a key...";
1885 int len = strlen(hmac_key);
1887 for (i = 0; i < loopargs_len; i++) {
1888 loopargs[i].hctx = HMAC_CTX_new();
1889 if (loopargs[i].hctx == NULL) {
1890 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1894 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1896 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1897 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1899 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1901 print_result(D_HMAC, testnum, count, d);
1903 for (i = 0; i < loopargs_len; i++) {
1904 HMAC_CTX_free(loopargs[i].hctx);
1909 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1910 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1912 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1914 print_result(D_SHA1, testnum, count, d);
1917 if (doit[D_SHA256]) {
1918 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1919 print_message(names[D_SHA256], c[D_SHA256][testnum],
1922 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1924 print_result(D_SHA256, testnum, count, d);
1927 if (doit[D_SHA512]) {
1928 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1929 print_message(names[D_SHA512], c[D_SHA512][testnum],
1932 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1934 print_result(D_SHA512, testnum, count, d);
1937 #ifndef OPENSSL_NO_WHIRLPOOL
1938 if (doit[D_WHIRLPOOL]) {
1939 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1940 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1943 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1945 print_result(D_WHIRLPOOL, testnum, count, d);
1950 #ifndef OPENSSL_NO_RMD160
1951 if (doit[D_RMD160]) {
1952 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1953 print_message(names[D_RMD160], c[D_RMD160][testnum],
1956 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1958 print_result(D_RMD160, testnum, count, d);
1962 #ifndef OPENSSL_NO_RC4
1964 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1965 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1967 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1969 print_result(D_RC4, testnum, count, d);
1973 #ifndef OPENSSL_NO_DES
1974 if (doit[D_CBC_DES]) {
1975 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1976 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
1979 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1981 print_result(D_CBC_DES, testnum, count, d);
1985 if (doit[D_EDE3_DES]) {
1986 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1987 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
1991 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
1993 print_result(D_EDE3_DES, testnum, count, d);
1998 if (doit[D_CBC_128_AES]) {
1999 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2000 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2004 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2006 print_result(D_CBC_128_AES, testnum, count, d);
2009 if (doit[D_CBC_192_AES]) {
2010 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2011 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2015 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2017 print_result(D_CBC_192_AES, testnum, count, d);
2020 if (doit[D_CBC_256_AES]) {
2021 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2022 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2026 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2028 print_result(D_CBC_256_AES, testnum, count, d);
2032 if (doit[D_IGE_128_AES]) {
2033 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2034 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2038 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2040 print_result(D_IGE_128_AES, testnum, count, d);
2043 if (doit[D_IGE_192_AES]) {
2044 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2045 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2049 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2051 print_result(D_IGE_192_AES, testnum, count, d);
2054 if (doit[D_IGE_256_AES]) {
2055 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2056 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2060 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2062 print_result(D_IGE_256_AES, testnum, count, d);
2065 if (doit[D_GHASH]) {
2066 for (i = 0; i < loopargs_len; i++) {
2067 loopargs[i].gcm_ctx =
2068 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2069 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2070 (unsigned char *)"0123456789ab", 12);
2073 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2074 print_message(names[D_GHASH], c[D_GHASH][testnum],
2077 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2079 print_result(D_GHASH, testnum, count, d);
2081 for (i = 0; i < loopargs_len; i++)
2082 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2084 #ifndef OPENSSL_NO_CAMELLIA
2085 if (doit[D_CBC_128_CML]) {
2086 if (async_jobs > 0) {
2087 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2088 names[D_CBC_128_CML]);
2089 doit[D_CBC_128_CML] = 0;
2091 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2092 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2095 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2096 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2097 (size_t)lengths[testnum], &camellia_ks1,
2098 iv, CAMELLIA_ENCRYPT);
2100 print_result(D_CBC_128_CML, testnum, count, d);
2103 if (doit[D_CBC_192_CML]) {
2104 if (async_jobs > 0) {
2105 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2106 names[D_CBC_192_CML]);
2107 doit[D_CBC_192_CML] = 0;
2109 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2110 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2112 if (async_jobs > 0) {
2113 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2117 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2118 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2119 (size_t)lengths[testnum], &camellia_ks2,
2120 iv, CAMELLIA_ENCRYPT);
2122 print_result(D_CBC_192_CML, testnum, count, d);
2125 if (doit[D_CBC_256_CML]) {
2126 if (async_jobs > 0) {
2127 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2128 names[D_CBC_256_CML]);
2129 doit[D_CBC_256_CML] = 0;
2131 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2132 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2135 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2136 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2137 (size_t)lengths[testnum], &camellia_ks3,
2138 iv, CAMELLIA_ENCRYPT);
2140 print_result(D_CBC_256_CML, testnum, count, d);
2144 #ifndef OPENSSL_NO_IDEA
2145 if (doit[D_CBC_IDEA]) {
2146 if (async_jobs > 0) {
2147 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2149 doit[D_CBC_IDEA] = 0;
2151 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2152 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2155 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2156 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2157 (size_t)lengths[testnum], &idea_ks,
2160 print_result(D_CBC_IDEA, testnum, count, d);
2164 #ifndef OPENSSL_NO_SEED
2165 if (doit[D_CBC_SEED]) {
2166 if (async_jobs > 0) {
2167 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2169 doit[D_CBC_SEED] = 0;
2171 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2172 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2175 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2176 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2177 (size_t)lengths[testnum], &seed_ks, iv, 1);
2179 print_result(D_CBC_SEED, testnum, count, d);
2183 #ifndef OPENSSL_NO_RC2
2184 if (doit[D_CBC_RC2]) {
2185 if (async_jobs > 0) {
2186 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2188 doit[D_CBC_RC2] = 0;
2190 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2191 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2193 if (async_jobs > 0) {
2194 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2198 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2199 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2200 (size_t)lengths[testnum], &rc2_ks,
2203 print_result(D_CBC_RC2, testnum, count, d);
2207 #ifndef OPENSSL_NO_RC5
2208 if (doit[D_CBC_RC5]) {
2209 if (async_jobs > 0) {
2210 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2212 doit[D_CBC_RC5] = 0;
2214 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2215 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2217 if (async_jobs > 0) {
2218 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2222 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2223 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2224 (size_t)lengths[testnum], &rc5_ks,
2227 print_result(D_CBC_RC5, testnum, count, d);
2231 #ifndef OPENSSL_NO_BF
2232 if (doit[D_CBC_BF]) {
2233 if (async_jobs > 0) {
2234 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2238 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2239 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2242 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2243 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2244 (size_t)lengths[testnum], &bf_ks,
2247 print_result(D_CBC_BF, testnum, count, d);
2251 #ifndef OPENSSL_NO_CAST
2252 if (doit[D_CBC_CAST]) {
2253 if (async_jobs > 0) {
2254 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2256 doit[D_CBC_CAST] = 0;
2258 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2259 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2262 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2263 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2264 (size_t)lengths[testnum], &cast_ks,
2267 print_result(D_CBC_CAST, testnum, count, d);
2273 if (multiblock && evp_cipher) {
2275 (EVP_CIPHER_flags(evp_cipher) &
2276 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2277 BIO_printf(bio_err, "%s is not multi-block capable\n",
2278 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2281 if (async_jobs > 0) {
2282 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2285 multiblock_speed(evp_cipher);
2289 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2292 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2294 * -O3 -fschedule-insns messes up an optimization here!
2295 * names[D_EVP] somehow becomes NULL
2297 print_message(names[D_EVP], save_count, lengths[testnum]);
2299 for (k = 0; k < loopargs_len; k++) {
2300 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2302 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2305 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2307 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2311 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2313 for (k = 0; k < loopargs_len; k++) {
2314 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2318 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2319 print_message(names[D_EVP], save_count, lengths[testnum]);
2321 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2324 print_result(D_EVP, testnum, count, d);
2328 for (i = 0; i < loopargs_len; i++)
2329 RAND_bytes(loopargs[i].buf, 36);
2331 #ifndef OPENSSL_NO_RSA
2332 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2334 if (!rsa_doit[testnum])
2336 for (i = 0; i < loopargs_len; i++) {
2337 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2338 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2344 "RSA sign failure. No RSA sign will be done.\n");
2345 ERR_print_errors(bio_err);
2348 pkey_print_message("private", "rsa",
2349 rsa_c[testnum][0], rsa_bits[testnum],
2351 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2353 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2356 mr ? "+R1:%ld:%d:%.2f\n"
2357 : "%ld %d bit private RSA's in %.2fs\n",
2358 count, rsa_bits[testnum], d);
2359 rsa_results[testnum][0] = (double)count / d;
2363 for (i = 0; i < loopargs_len; i++) {
2364 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2365 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2371 "RSA verify failure. No RSA verify will be done.\n");
2372 ERR_print_errors(bio_err);
2373 rsa_doit[testnum] = 0;
2375 pkey_print_message("public", "rsa",
2376 rsa_c[testnum][1], rsa_bits[testnum],
2379 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2382 mr ? "+R2:%ld:%d:%.2f\n"
2383 : "%ld %d bit public RSA's in %.2fs\n",
2384 count, rsa_bits[testnum], d);
2385 rsa_results[testnum][1] = (double)count / d;
2388 if (rsa_count <= 1) {
2389 /* if longer than 10s, don't do any more */
2390 for (testnum++; testnum < RSA_NUM; testnum++)
2391 rsa_doit[testnum] = 0;
2394 #endif /* OPENSSL_NO_RSA */
2396 for (i = 0; i < loopargs_len; i++)
2397 RAND_bytes(loopargs[i].buf, 36);
2399 #ifndef OPENSSL_NO_DSA
2400 if (RAND_status() != 1) {
2401 RAND_seed(rnd_seed, sizeof rnd_seed);
2403 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2405 if (!dsa_doit[testnum])
2408 /* DSA_generate_key(dsa_key[testnum]); */
2409 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2410 for (i = 0; i < loopargs_len; i++) {
2411 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2412 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2418 "DSA sign failure. No DSA sign will be done.\n");
2419 ERR_print_errors(bio_err);
2422 pkey_print_message("sign", "dsa",
2423 dsa_c[testnum][0], dsa_bits[testnum],
2426 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2429 mr ? "+R3:%ld:%d:%.2f\n"
2430 : "%ld %d bit DSA signs in %.2fs\n",
2431 count, dsa_bits[testnum], d);
2432 dsa_results[testnum][0] = (double)count / d;
2436 for (i = 0; i < loopargs_len; i++) {
2437 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2438 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2444 "DSA verify failure. No DSA verify will be done.\n");
2445 ERR_print_errors(bio_err);
2446 dsa_doit[testnum] = 0;
2448 pkey_print_message("verify", "dsa",
2449 dsa_c[testnum][1], dsa_bits[testnum],
2452 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2455 mr ? "+R4:%ld:%d:%.2f\n"
2456 : "%ld %d bit DSA verify in %.2fs\n",
2457 count, dsa_bits[testnum], d);
2458 dsa_results[testnum][1] = (double)count / d;
2461 if (rsa_count <= 1) {
2462 /* if longer than 10s, don't do any more */
2463 for (testnum++; testnum < DSA_NUM; testnum++)
2464 dsa_doit[testnum] = 0;
2467 #endif /* OPENSSL_NO_DSA */
2469 #ifndef OPENSSL_NO_EC
2470 if (RAND_status() != 1) {
2471 RAND_seed(rnd_seed, sizeof rnd_seed);
2473 for (testnum = 0; testnum < EC_NUM; testnum++) {
2476 if (!ecdsa_doit[testnum])
2477 continue; /* Ignore Curve */
2478 for (i = 0; i < loopargs_len; i++) {
2479 loopargs[i].ecdsa[testnum] =
2480 EC_KEY_new_by_curve_name(test_curves[testnum]);
2481 if (loopargs[i].ecdsa[testnum] == NULL) {
2487 BIO_printf(bio_err, "ECDSA failure.\n");
2488 ERR_print_errors(bio_err);
2491 for (i = 0; i < loopargs_len; i++) {
2492 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2493 /* Perform ECDSA signature test */
2494 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2495 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2496 &loopargs[i].siglen,
2497 loopargs[i].ecdsa[testnum]);
2503 "ECDSA sign failure. No ECDSA sign will be done.\n");
2504 ERR_print_errors(bio_err);
2507 pkey_print_message("sign", "ecdsa",
2508 ecdsa_c[testnum][0],
2509 test_curves_bits[testnum], ECDSA_SECONDS);
2511 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2515 mr ? "+R5:%ld:%d:%.2f\n" :
2516 "%ld %d bit ECDSA signs in %.2fs \n",
2517 count, test_curves_bits[testnum], d);
2518 ecdsa_results[testnum][0] = (double)count / d;
2522 /* Perform ECDSA verification test */
2523 for (i = 0; i < loopargs_len; i++) {
2524 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2526 loopargs[i].ecdsa[testnum]);
2532 "ECDSA verify failure. No ECDSA verify will be done.\n");
2533 ERR_print_errors(bio_err);
2534 ecdsa_doit[testnum] = 0;
2536 pkey_print_message("verify", "ecdsa",
2537 ecdsa_c[testnum][1],
2538 test_curves_bits[testnum], ECDSA_SECONDS);
2540 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2543 mr ? "+R6:%ld:%d:%.2f\n"
2544 : "%ld %d bit ECDSA verify in %.2fs\n",
2545 count, test_curves_bits[testnum], d);
2546 ecdsa_results[testnum][1] = (double)count / d;
2549 if (rsa_count <= 1) {
2550 /* if longer than 10s, don't do any more */
2551 for (testnum++; testnum < EC_NUM; testnum++)
2552 ecdsa_doit[testnum] = 0;
2557 if (RAND_status() != 1) {
2558 RAND_seed(rnd_seed, sizeof rnd_seed);
2560 for (testnum = 0; testnum < EC_NUM; testnum++) {
2561 int ecdh_checks = 1;
2563 if (!ecdh_doit[testnum])
2566 for (i = 0; i < loopargs_len; i++) {
2567 EVP_PKEY_CTX *kctx = NULL;
2568 EVP_PKEY_CTX *test_ctx = NULL;
2569 EVP_PKEY_CTX *ctx = NULL;
2570 EVP_PKEY *key_A = NULL;
2571 EVP_PKEY *key_B = NULL;
2575 /* Ensure that the error queue is empty */
2576 if (ERR_peek_error()) {
2578 "WARNING: the error queue contains previous unhandled errors.\n");
2579 ERR_print_errors(bio_err);
2582 /* Let's try to create a ctx directly from the NID: this works for
2583 * curves like Curve25519 that are not implemented through the low
2584 * level EC interface.
2585 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2586 * then we set the curve by NID before deriving the actual keygen
2587 * ctx for that specific curve. */
2588 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2590 EVP_PKEY_CTX *pctx = NULL;
2591 EVP_PKEY *params = NULL;
2593 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2594 * "int_ctx_new:unsupported algorithm" error was added to the
2596 * We remove it from the error queue as we are handling it. */
2597 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2598 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2599 /* check that the error origin matches */
2600 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2601 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2602 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2603 ERR_get_error(); /* pop error from queue */
2604 if (ERR_peek_error()) {
2606 "Unhandled error in the error queue during ECDH init.\n");
2607 ERR_print_errors(bio_err);
2612 if ( /* Create the context for parameter generation */
2613 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2614 /* Initialise the parameter generation */
2615 !EVP_PKEY_paramgen_init(pctx) ||
2616 /* Set the curve by NID */
2617 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2620 /* Create the parameter object params */
2621 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2623 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2624 ERR_print_errors(bio_err);
2628 /* Create the context for the key generation */
2629 kctx = EVP_PKEY_CTX_new(params, NULL);
2631 EVP_PKEY_free(params);
2633 EVP_PKEY_CTX_free(pctx);
2636 if (kctx == NULL || /* keygen ctx is not null */
2637 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2639 BIO_printf(bio_err, "ECDH keygen failure.\n");
2640 ERR_print_errors(bio_err);
2645 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2646 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2647 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2648 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2649 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2650 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2651 outlen == 0 || /* ensure outlen is a valid size */
2652 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2654 BIO_printf(bio_err, "ECDH key generation failure.\n");
2655 ERR_print_errors(bio_err);
2660 /* Here we perform a test run, comparing the output of a*B and b*A;
2661 * we try this here and assume that further EVP_PKEY_derive calls
2662 * never fail, so we can skip checks in the actually benchmarked
2663 * code, for maximum performance. */
2664 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2665 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2666 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2667 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2668 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2669 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2670 test_outlen != outlen /* compare output length */ ) {
2672 BIO_printf(bio_err, "ECDH computation failure.\n");
2673 ERR_print_errors(bio_err);
2678 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2679 if (CRYPTO_memcmp(loopargs[i].secret_a,
2680 loopargs[i].secret_b, outlen)) {
2682 BIO_printf(bio_err, "ECDH computations don't match.\n");
2683 ERR_print_errors(bio_err);
2688 loopargs[i].ecdh_ctx[testnum] = ctx;
2689 loopargs[i].outlen[testnum] = outlen;
2691 EVP_PKEY_CTX_free(kctx);
2693 EVP_PKEY_CTX_free(test_ctx);
2696 if (ecdh_checks != 0) {
2697 pkey_print_message("", "ecdh",
2699 test_curves_bits[testnum], ECDH_SECONDS);
2702 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2705 mr ? "+R7:%ld:%d:%.2f\n" :
2706 "%ld %d-bit ECDH ops in %.2fs\n", count,
2707 test_curves_bits[testnum], d);
2708 ecdh_results[testnum][0] = (double)count / d;
2712 if (rsa_count <= 1) {
2713 /* if longer than 10s, don't do any more */
2714 for (testnum++; testnum < EC_NUM; testnum++)
2715 ecdh_doit[testnum] = 0;
2718 #endif /* OPENSSL_NO_EC */
2723 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2724 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2726 printf("%s ", BN_options());
2727 #ifndef OPENSSL_NO_MD2
2728 printf("%s ", MD2_options());
2730 #ifndef OPENSSL_NO_RC4
2731 printf("%s ", RC4_options());
2733 #ifndef OPENSSL_NO_DES
2734 printf("%s ", DES_options());
2736 printf("%s ", AES_options());
2737 #ifndef OPENSSL_NO_IDEA
2738 printf("%s ", IDEA_options());
2740 #ifndef OPENSSL_NO_BF
2741 printf("%s ", BF_options());
2743 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2751 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2754 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2755 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2759 for (k = 0; k < ALGOR_NUM; k++) {
2763 printf("+F:%d:%s", k, names[k]);
2765 printf("%-13s", names[k]);
2766 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2767 if (results[k][testnum] > 10000 && !mr)
2768 printf(" %11.2fk", results[k][testnum] / 1e3);
2770 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2774 #ifndef OPENSSL_NO_RSA
2776 for (k = 0; k < RSA_NUM; k++) {
2779 if (testnum && !mr) {
2780 printf("%18ssign verify sign/s verify/s\n", " ");
2784 printf("+F2:%u:%u:%f:%f\n",
2785 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2787 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2788 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2789 rsa_results[k][0], rsa_results[k][1]);
2792 #ifndef OPENSSL_NO_DSA
2794 for (k = 0; k < DSA_NUM; k++) {
2797 if (testnum && !mr) {
2798 printf("%18ssign verify sign/s verify/s\n", " ");
2802 printf("+F3:%u:%u:%f:%f\n",
2803 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2805 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2806 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2807 dsa_results[k][0], dsa_results[k][1]);
2810 #ifndef OPENSSL_NO_EC
2812 for (k = 0; k < EC_NUM; k++) {
2815 if (testnum && !mr) {
2816 printf("%30ssign verify sign/s verify/s\n", " ");
2821 printf("+F4:%u:%u:%f:%f\n",
2822 k, test_curves_bits[k],
2823 ecdsa_results[k][0], ecdsa_results[k][1]);
2825 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2826 test_curves_bits[k],
2827 test_curves_names[k],
2828 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2829 ecdsa_results[k][0], ecdsa_results[k][1]);
2833 for (k = 0; k < EC_NUM; k++) {
2836 if (testnum && !mr) {
2837 printf("%30sop op/s\n", " ");
2841 printf("+F5:%u:%u:%f:%f\n",
2842 k, test_curves_bits[k],
2843 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2846 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2847 test_curves_bits[k],
2848 test_curves_names[k],
2849 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2856 ERR_print_errors(bio_err);
2857 for (i = 0; i < loopargs_len; i++) {
2858 OPENSSL_free(loopargs[i].buf_malloc);
2859 OPENSSL_free(loopargs[i].buf2_malloc);
2861 #ifndef OPENSSL_NO_RSA
2862 for (k = 0; k < RSA_NUM; k++)
2863 RSA_free(loopargs[i].rsa_key[k]);
2865 #ifndef OPENSSL_NO_DSA
2866 for (k = 0; k < DSA_NUM; k++)
2867 DSA_free(loopargs[i].dsa_key[k]);
2869 #ifndef OPENSSL_NO_EC
2870 for (k = 0; k < EC_NUM; k++) {
2871 EC_KEY_free(loopargs[i].ecdsa[k]);
2872 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2874 OPENSSL_free(loopargs[i].secret_a);
2875 OPENSSL_free(loopargs[i].secret_b);
2879 if (async_jobs > 0) {
2880 for (i = 0; i < loopargs_len; i++)
2881 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2885 ASYNC_cleanup_thread();
2887 OPENSSL_free(loopargs);
2892 static void print_message(const char *s, long num, int length)
2896 mr ? "+DT:%s:%d:%d\n"
2897 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2898 (void)BIO_flush(bio_err);
2902 mr ? "+DN:%s:%ld:%d\n"
2903 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2904 (void)BIO_flush(bio_err);
2908 static void pkey_print_message(const char *str, const char *str2, long num,
2913 mr ? "+DTP:%d:%s:%s:%d\n"
2914 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2915 (void)BIO_flush(bio_err);
2919 mr ? "+DNP:%ld:%d:%s:%s\n"
2920 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2921 (void)BIO_flush(bio_err);
2925 static void print_result(int alg, int run_no, int count, double time_used)
2928 BIO_puts(bio_err, "EVP error!\n");
2932 mr ? "+R:%d:%s:%f\n"
2933 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2934 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2938 static char *sstrsep(char **string, const char *delim)
2941 char *token = *string;
2946 memset(isdelim, 0, sizeof isdelim);
2950 isdelim[(unsigned char)(*delim)] = 1;
2954 while (!isdelim[(unsigned char)(**string)]) {
2966 static int do_multi(int multi)
2971 static char sep[] = ":";
2973 fds = malloc(sizeof(*fds) * multi);
2974 for (n = 0; n < multi; ++n) {
2975 if (pipe(fd) == -1) {
2976 BIO_printf(bio_err, "pipe failure\n");
2980 (void)BIO_flush(bio_err);
2987 if (dup(fd[1]) == -1) {
2988 BIO_printf(bio_err, "dup failed\n");
2997 printf("Forked child %d\n", n);
3000 /* for now, assume the pipe is long enough to take all the output */
3001 for (n = 0; n < multi; ++n) {
3006 f = fdopen(fds[n], "r");
3007 while (fgets(buf, sizeof buf, f)) {
3008 p = strchr(buf, '\n');
3011 if (buf[0] != '+') {
3013 "Don't understand line '%s' from child %d\n", buf,
3017 printf("Got: %s from %d\n", buf, n);
3018 if (strncmp(buf, "+F:", 3) == 0) {
3023 alg = atoi(sstrsep(&p, sep));
3025 for (j = 0; j < SIZE_NUM; ++j)
3026 results[alg][j] += atof(sstrsep(&p, sep));
3027 } else if (strncmp(buf, "+F2:", 4) == 0) {
3032 k = atoi(sstrsep(&p, sep));
3035 d = atof(sstrsep(&p, sep));
3036 rsa_results[k][0] += d;
3038 d = atof(sstrsep(&p, sep));
3039 rsa_results[k][1] += d;
3041 # ifndef OPENSSL_NO_DSA
3042 else if (strncmp(buf, "+F3:", 4) == 0) {
3047 k = atoi(sstrsep(&p, sep));
3050 d = atof(sstrsep(&p, sep));
3051 dsa_results[k][0] += d;
3053 d = atof(sstrsep(&p, sep));
3054 dsa_results[k][1] += d;
3057 # ifndef OPENSSL_NO_EC
3058 else if (strncmp(buf, "+F4:", 4) == 0) {
3063 k = atoi(sstrsep(&p, sep));
3066 d = atof(sstrsep(&p, sep));
3067 ecdsa_results[k][0] += d;
3069 d = atof(sstrsep(&p, sep));
3070 ecdsa_results[k][1] += d;
3071 } else if (strncmp(buf, "+F5:", 4) == 0) {
3076 k = atoi(sstrsep(&p, sep));
3079 d = atof(sstrsep(&p, sep));
3080 ecdh_results[k][0] += d;
3084 else if (strncmp(buf, "+H:", 3) == 0) {
3087 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3098 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3100 static int mblengths[] =
3101 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3102 int j, count, num = OSSL_NELEM(mblengths);
3103 const char *alg_name;
3104 unsigned char *inp, *out, no_key[32], no_iv[16];
3105 EVP_CIPHER_CTX *ctx;
3108 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3109 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3110 ctx = EVP_CIPHER_CTX_new();
3111 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3112 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3113 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3115 for (j = 0; j < num; j++) {
3116 print_message(alg_name, 0, mblengths[j]);
3118 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3119 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3120 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3121 size_t len = mblengths[j];
3124 memset(aad, 0, 8); /* avoid uninitialized values */
3125 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3126 aad[9] = 3; /* version */
3128 aad[11] = 0; /* length */
3130 mb_param.out = NULL;
3133 mb_param.interleave = 8;
3135 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3136 sizeof(mb_param), &mb_param);
3142 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3143 sizeof(mb_param), &mb_param);
3147 RAND_bytes(out, 16);
3151 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3152 EVP_AEAD_TLS1_AAD_LEN, aad);
3153 EVP_Cipher(ctx, out, inp, len + pad);
3157 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3158 : "%d %s's in %.2fs\n", count, "evp", d);
3159 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3163 fprintf(stdout, "+H");
3164 for (j = 0; j < num; j++)
3165 fprintf(stdout, ":%d", mblengths[j]);
3166 fprintf(stdout, "\n");
3167 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3168 for (j = 0; j < num; j++)
3169 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3170 fprintf(stdout, "\n");
3173 "The 'numbers' are in 1000s of bytes per second processed.\n");
3174 fprintf(stdout, "type ");
3175 for (j = 0; j < num; j++)
3176 fprintf(stdout, "%7d bytes", mblengths[j]);
3177 fprintf(stdout, "\n");
3178 fprintf(stdout, "%-24s", alg_name);
3180 for (j = 0; j < num; j++) {
3181 if (results[D_EVP][j] > 10000)
3182 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3184 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3186 fprintf(stdout, "\n");
3191 EVP_CIPHER_CTX_free(ctx);