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, schlock;
279 static void alarm_win32(unsigned int secs)
284 # define alarm alarm_win32
286 static DWORD WINAPI sleepy(VOID * arg)
294 static double Time_F(int s)
301 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
303 DWORD err = GetLastError();
304 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
308 Sleep(0); /* scheduler spinlock */
309 ret = app_tminterval(s, usertime);
311 ret = app_tminterval(s, usertime);
313 TerminateThread(thr, 0);
321 static double Time_F(int s)
323 double ret = app_tminterval(s, usertime);
330 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
332 static int found(const char *name, const OPT_PAIR *pairs, int *result)
334 for (; pairs->name; pairs++)
335 if (strcmp(name, pairs->name) == 0) {
336 *result = pairs->retval;
342 typedef enum OPTION_choice {
343 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
344 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
345 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM
348 const OPTIONS speed_options[] = {
349 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
350 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
351 {"help", OPT_HELP, '-', "Display this summary"},
352 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
353 {"decrypt", OPT_DECRYPT, '-',
354 "Time decryption instead of encryption (only EVP)"},
355 {"mr", OPT_MR, '-', "Produce machine readable output"},
357 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
358 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
359 {"elapsed", OPT_ELAPSED, '-',
360 "Measure time in real time instead of CPU user time"},
362 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
364 #ifndef OPENSSL_NO_ASYNC
365 {"async_jobs", OPT_ASYNCJOBS, 'p',
366 "Enable async mode and start pnum jobs"},
369 #ifndef OPENSSL_NO_ENGINE
370 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
385 #define D_CBC_IDEA 10
386 #define D_CBC_SEED 11
390 #define D_CBC_CAST 15
391 #define D_CBC_128_AES 16
392 #define D_CBC_192_AES 17
393 #define D_CBC_256_AES 18
394 #define D_CBC_128_CML 19
395 #define D_CBC_192_CML 20
396 #define D_CBC_256_CML 21
400 #define D_WHIRLPOOL 25
401 #define D_IGE_128_AES 26
402 #define D_IGE_192_AES 27
403 #define D_IGE_256_AES 28
405 static OPT_PAIR doit_choices[] = {
406 #ifndef OPENSSL_NO_MD2
409 #ifndef OPENSSL_NO_MDC2
412 #ifndef OPENSSL_NO_MD4
415 #ifndef OPENSSL_NO_MD5
420 {"sha256", D_SHA256},
421 {"sha512", D_SHA512},
422 #ifndef OPENSSL_NO_WHIRLPOOL
423 {"whirlpool", D_WHIRLPOOL},
425 #ifndef OPENSSL_NO_RMD160
426 {"ripemd", D_RMD160},
427 {"rmd160", D_RMD160},
428 {"ripemd160", D_RMD160},
430 #ifndef OPENSSL_NO_RC4
433 #ifndef OPENSSL_NO_DES
434 {"des-cbc", D_CBC_DES},
435 {"des-ede3", D_EDE3_DES},
437 {"aes-128-cbc", D_CBC_128_AES},
438 {"aes-192-cbc", D_CBC_192_AES},
439 {"aes-256-cbc", D_CBC_256_AES},
440 {"aes-128-ige", D_IGE_128_AES},
441 {"aes-192-ige", D_IGE_192_AES},
442 {"aes-256-ige", D_IGE_256_AES},
443 #ifndef OPENSSL_NO_RC2
444 {"rc2-cbc", D_CBC_RC2},
447 #ifndef OPENSSL_NO_RC5
448 {"rc5-cbc", D_CBC_RC5},
451 #ifndef OPENSSL_NO_IDEA
452 {"idea-cbc", D_CBC_IDEA},
453 {"idea", D_CBC_IDEA},
455 #ifndef OPENSSL_NO_SEED
456 {"seed-cbc", D_CBC_SEED},
457 {"seed", D_CBC_SEED},
459 #ifndef OPENSSL_NO_BF
460 {"bf-cbc", D_CBC_BF},
461 {"blowfish", D_CBC_BF},
464 #ifndef OPENSSL_NO_CAST
465 {"cast-cbc", D_CBC_CAST},
466 {"cast", D_CBC_CAST},
467 {"cast5", D_CBC_CAST},
473 #ifndef OPENSSL_NO_DSA
475 # define R_DSA_1024 1
476 # define R_DSA_2048 2
477 static OPT_PAIR dsa_choices[] = {
478 {"dsa512", R_DSA_512},
479 {"dsa1024", R_DSA_1024},
480 {"dsa2048", R_DSA_2048},
491 #define R_RSA_15360 6
492 static OPT_PAIR rsa_choices[] = {
493 {"rsa512", R_RSA_512},
494 {"rsa1024", R_RSA_1024},
495 {"rsa2048", R_RSA_2048},
496 {"rsa3072", R_RSA_3072},
497 {"rsa4096", R_RSA_4096},
498 {"rsa7680", R_RSA_7680},
499 {"rsa15360", R_RSA_15360},
519 #define R_EC_X25519 16
520 #ifndef OPENSSL_NO_EC
521 static OPT_PAIR ecdsa_choices[] = {
522 {"ecdsap160", R_EC_P160},
523 {"ecdsap192", R_EC_P192},
524 {"ecdsap224", R_EC_P224},
525 {"ecdsap256", R_EC_P256},
526 {"ecdsap384", R_EC_P384},
527 {"ecdsap521", R_EC_P521},
528 {"ecdsak163", R_EC_K163},
529 {"ecdsak233", R_EC_K233},
530 {"ecdsak283", R_EC_K283},
531 {"ecdsak409", R_EC_K409},
532 {"ecdsak571", R_EC_K571},
533 {"ecdsab163", R_EC_B163},
534 {"ecdsab233", R_EC_B233},
535 {"ecdsab283", R_EC_B283},
536 {"ecdsab409", R_EC_B409},
537 {"ecdsab571", R_EC_B571},
541 static OPT_PAIR ecdh_choices[] = {
542 {"ecdhp160", R_EC_P160},
543 {"ecdhp192", R_EC_P192},
544 {"ecdhp224", R_EC_P224},
545 {"ecdhp256", R_EC_P256},
546 {"ecdhp384", R_EC_P384},
547 {"ecdhp521", R_EC_P521},
548 {"ecdhk163", R_EC_K163},
549 {"ecdhk233", R_EC_K233},
550 {"ecdhk283", R_EC_K283},
551 {"ecdhk409", R_EC_K409},
552 {"ecdhk571", R_EC_K571},
553 {"ecdhb163", R_EC_B163},
554 {"ecdhb233", R_EC_B233},
555 {"ecdhb283", R_EC_B283},
556 {"ecdhb409", R_EC_B409},
557 {"ecdhb571", R_EC_B571},
558 {"ecdhx25519", R_EC_X25519},
564 # define COND(d) (count < (d))
565 # define COUNT(d) (d)
567 # define COND(unused_cond) (run && count<0x7fffffff)
568 # define COUNT(d) (count)
573 /* Nb of iterations to do per algorithm and key-size */
574 static long c[ALGOR_NUM][SIZE_NUM];
576 #ifndef OPENSSL_NO_MD2
577 static int EVP_Digest_MD2_loop(void *args)
579 loopargs_t *tempargs = *(loopargs_t **) args;
580 unsigned char *buf = tempargs->buf;
581 unsigned char md2[MD2_DIGEST_LENGTH];
584 for (count = 0; COND(c[D_MD2][testnum]); count++) {
585 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
593 #ifndef OPENSSL_NO_MDC2
594 static int EVP_Digest_MDC2_loop(void *args)
596 loopargs_t *tempargs = *(loopargs_t **) args;
597 unsigned char *buf = tempargs->buf;
598 unsigned char mdc2[MDC2_DIGEST_LENGTH];
601 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
602 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
610 #ifndef OPENSSL_NO_MD4
611 static int EVP_Digest_MD4_loop(void *args)
613 loopargs_t *tempargs = *(loopargs_t **) args;
614 unsigned char *buf = tempargs->buf;
615 unsigned char md4[MD4_DIGEST_LENGTH];
618 for (count = 0; COND(c[D_MD4][testnum]); count++) {
619 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
627 #ifndef OPENSSL_NO_MD5
628 static int MD5_loop(void *args)
630 loopargs_t *tempargs = *(loopargs_t **) args;
631 unsigned char *buf = tempargs->buf;
632 unsigned char md5[MD5_DIGEST_LENGTH];
634 for (count = 0; COND(c[D_MD5][testnum]); count++)
635 MD5(buf, lengths[testnum], md5);
639 static int HMAC_loop(void *args)
641 loopargs_t *tempargs = *(loopargs_t **) args;
642 unsigned char *buf = tempargs->buf;
643 HMAC_CTX *hctx = tempargs->hctx;
644 unsigned char hmac[MD5_DIGEST_LENGTH];
647 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
648 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
649 HMAC_Update(hctx, buf, lengths[testnum]);
650 HMAC_Final(hctx, hmac, NULL);
656 static int SHA1_loop(void *args)
658 loopargs_t *tempargs = *(loopargs_t **) args;
659 unsigned char *buf = tempargs->buf;
660 unsigned char sha[SHA_DIGEST_LENGTH];
662 for (count = 0; COND(c[D_SHA1][testnum]); count++)
663 SHA1(buf, lengths[testnum], sha);
667 static int SHA256_loop(void *args)
669 loopargs_t *tempargs = *(loopargs_t **) args;
670 unsigned char *buf = tempargs->buf;
671 unsigned char sha256[SHA256_DIGEST_LENGTH];
673 for (count = 0; COND(c[D_SHA256][testnum]); count++)
674 SHA256(buf, lengths[testnum], sha256);
678 static int SHA512_loop(void *args)
680 loopargs_t *tempargs = *(loopargs_t **) args;
681 unsigned char *buf = tempargs->buf;
682 unsigned char sha512[SHA512_DIGEST_LENGTH];
684 for (count = 0; COND(c[D_SHA512][testnum]); count++)
685 SHA512(buf, lengths[testnum], sha512);
689 #ifndef OPENSSL_NO_WHIRLPOOL
690 static int WHIRLPOOL_loop(void *args)
692 loopargs_t *tempargs = *(loopargs_t **) args;
693 unsigned char *buf = tempargs->buf;
694 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
696 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
697 WHIRLPOOL(buf, lengths[testnum], whirlpool);
702 #ifndef OPENSSL_NO_RMD160
703 static int EVP_Digest_RMD160_loop(void *args)
705 loopargs_t *tempargs = *(loopargs_t **) args;
706 unsigned char *buf = tempargs->buf;
707 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
709 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
710 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
711 NULL, EVP_ripemd160(), NULL))
718 #ifndef OPENSSL_NO_RC4
719 static RC4_KEY rc4_ks;
720 static int RC4_loop(void *args)
722 loopargs_t *tempargs = *(loopargs_t **) args;
723 unsigned char *buf = tempargs->buf;
725 for (count = 0; COND(c[D_RC4][testnum]); count++)
726 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
731 #ifndef OPENSSL_NO_DES
732 static unsigned char DES_iv[8];
733 static DES_key_schedule sch;
734 static DES_key_schedule sch2;
735 static DES_key_schedule sch3;
736 static int DES_ncbc_encrypt_loop(void *args)
738 loopargs_t *tempargs = *(loopargs_t **) args;
739 unsigned char *buf = tempargs->buf;
741 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
742 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
743 &DES_iv, DES_ENCRYPT);
747 static int DES_ede3_cbc_encrypt_loop(void *args)
749 loopargs_t *tempargs = *(loopargs_t **) args;
750 unsigned char *buf = tempargs->buf;
752 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
753 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
754 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
759 #define MAX_BLOCK_SIZE 128
761 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
762 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
763 static int AES_cbc_128_encrypt_loop(void *args)
765 loopargs_t *tempargs = *(loopargs_t **) args;
766 unsigned char *buf = tempargs->buf;
768 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
769 AES_cbc_encrypt(buf, buf,
770 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
774 static int AES_cbc_192_encrypt_loop(void *args)
776 loopargs_t *tempargs = *(loopargs_t **) args;
777 unsigned char *buf = tempargs->buf;
779 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
780 AES_cbc_encrypt(buf, buf,
781 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
785 static int AES_cbc_256_encrypt_loop(void *args)
787 loopargs_t *tempargs = *(loopargs_t **) args;
788 unsigned char *buf = tempargs->buf;
790 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
791 AES_cbc_encrypt(buf, buf,
792 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
796 static int AES_ige_128_encrypt_loop(void *args)
798 loopargs_t *tempargs = *(loopargs_t **) args;
799 unsigned char *buf = tempargs->buf;
800 unsigned char *buf2 = tempargs->buf2;
802 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
803 AES_ige_encrypt(buf, buf2,
804 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
808 static int AES_ige_192_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_192_AES][testnum]); count++)
815 AES_ige_encrypt(buf, buf2,
816 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
820 static int AES_ige_256_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_256_AES][testnum]); count++)
827 AES_ige_encrypt(buf, buf2,
828 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
832 static int CRYPTO_gcm128_aad_loop(void *args)
834 loopargs_t *tempargs = *(loopargs_t **) args;
835 unsigned char *buf = tempargs->buf;
836 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
838 for (count = 0; COND(c[D_GHASH][testnum]); count++)
839 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
843 static long save_count = 0;
844 static int decrypt = 0;
845 static int EVP_Update_loop(void *args)
847 loopargs_t *tempargs = *(loopargs_t **) args;
848 unsigned char *buf = tempargs->buf;
849 EVP_CIPHER_CTX *ctx = tempargs->ctx;
852 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
855 for (count = 0; COND(nb_iter); count++)
856 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
858 for (count = 0; COND(nb_iter); count++)
859 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
861 EVP_DecryptFinal_ex(ctx, buf, &outl);
863 EVP_EncryptFinal_ex(ctx, buf, &outl);
867 static const EVP_MD *evp_md = NULL;
868 static int EVP_Digest_loop(void *args)
870 loopargs_t *tempargs = *(loopargs_t **) args;
871 unsigned char *buf = tempargs->buf;
872 unsigned char md[EVP_MAX_MD_SIZE];
875 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
878 for (count = 0; COND(nb_iter); count++) {
879 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
885 #ifndef OPENSSL_NO_RSA
886 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
888 static int RSA_sign_loop(void *args)
890 loopargs_t *tempargs = *(loopargs_t **) args;
891 unsigned char *buf = tempargs->buf;
892 unsigned char *buf2 = tempargs->buf2;
893 unsigned int *rsa_num = &tempargs->siglen;
894 RSA **rsa_key = tempargs->rsa_key;
896 for (count = 0; COND(rsa_c[testnum][0]); count++) {
897 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
899 BIO_printf(bio_err, "RSA sign failure\n");
900 ERR_print_errors(bio_err);
908 static int RSA_verify_loop(void *args)
910 loopargs_t *tempargs = *(loopargs_t **) args;
911 unsigned char *buf = tempargs->buf;
912 unsigned char *buf2 = tempargs->buf2;
913 unsigned int rsa_num = tempargs->siglen;
914 RSA **rsa_key = tempargs->rsa_key;
916 for (count = 0; COND(rsa_c[testnum][1]); count++) {
918 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
920 BIO_printf(bio_err, "RSA verify failure\n");
921 ERR_print_errors(bio_err);
930 #ifndef OPENSSL_NO_DSA
931 static long dsa_c[DSA_NUM][2];
932 static int DSA_sign_loop(void *args)
934 loopargs_t *tempargs = *(loopargs_t **) args;
935 unsigned char *buf = tempargs->buf;
936 unsigned char *buf2 = tempargs->buf2;
937 DSA **dsa_key = tempargs->dsa_key;
938 unsigned int *siglen = &tempargs->siglen;
940 for (count = 0; COND(dsa_c[testnum][0]); count++) {
941 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
943 BIO_printf(bio_err, "DSA sign failure\n");
944 ERR_print_errors(bio_err);
952 static int DSA_verify_loop(void *args)
954 loopargs_t *tempargs = *(loopargs_t **) args;
955 unsigned char *buf = tempargs->buf;
956 unsigned char *buf2 = tempargs->buf2;
957 DSA **dsa_key = tempargs->dsa_key;
958 unsigned int siglen = tempargs->siglen;
960 for (count = 0; COND(dsa_c[testnum][1]); count++) {
961 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
963 BIO_printf(bio_err, "DSA verify failure\n");
964 ERR_print_errors(bio_err);
973 #ifndef OPENSSL_NO_EC
974 static long ecdsa_c[EC_NUM][2];
975 static int ECDSA_sign_loop(void *args)
977 loopargs_t *tempargs = *(loopargs_t **) args;
978 unsigned char *buf = tempargs->buf;
979 EC_KEY **ecdsa = tempargs->ecdsa;
980 unsigned char *ecdsasig = tempargs->buf2;
981 unsigned int *ecdsasiglen = &tempargs->siglen;
983 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
984 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
986 BIO_printf(bio_err, "ECDSA sign failure\n");
987 ERR_print_errors(bio_err);
995 static int ECDSA_verify_loop(void *args)
997 loopargs_t *tempargs = *(loopargs_t **) args;
998 unsigned char *buf = tempargs->buf;
999 EC_KEY **ecdsa = tempargs->ecdsa;
1000 unsigned char *ecdsasig = tempargs->buf2;
1001 unsigned int ecdsasiglen = tempargs->siglen;
1003 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1004 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1006 BIO_printf(bio_err, "ECDSA verify failure\n");
1007 ERR_print_errors(bio_err);
1015 /* ******************************************************************** */
1016 static long ecdh_c[EC_NUM][1];
1018 static int ECDH_EVP_derive_key_loop(void *args)
1020 loopargs_t *tempargs = *(loopargs_t **) args;
1021 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1022 unsigned char *derived_secret = tempargs->secret_a;
1024 size_t *outlen = &(tempargs->outlen[testnum]);
1026 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1027 EVP_PKEY_derive(ctx, derived_secret, outlen);
1032 #endif /* OPENSSL_NO_EC */
1034 static int run_benchmark(int async_jobs,
1035 int (*loop_function) (void *), loopargs_t * loopargs)
1037 int job_op_count = 0;
1038 int total_op_count = 0;
1039 int num_inprogress = 0;
1040 int error = 0, i = 0, ret = 0;
1041 OSSL_ASYNC_FD job_fd = 0;
1042 size_t num_job_fds = 0;
1046 if (async_jobs == 0) {
1047 return loop_function((void *)&loopargs);
1050 for (i = 0; i < async_jobs && !error; i++) {
1051 loopargs_t *looparg_item = loopargs + i;
1053 /* Copy pointer content (looparg_t item address) into async context */
1054 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1055 &job_op_count, loop_function,
1056 (void *)&looparg_item, sizeof(looparg_item));
1062 if (job_op_count == -1) {
1065 total_op_count += job_op_count;
1070 BIO_printf(bio_err, "Failure in the job\n");
1071 ERR_print_errors(bio_err);
1077 while (num_inprogress > 0) {
1078 #if defined(OPENSSL_SYS_WINDOWS)
1080 #elif defined(OPENSSL_SYS_UNIX)
1081 int select_result = 0;
1082 OSSL_ASYNC_FD max_fd = 0;
1085 FD_ZERO(&waitfdset);
1087 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1088 if (loopargs[i].inprogress_job == NULL)
1091 if (!ASYNC_WAIT_CTX_get_all_fds
1092 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1093 || num_job_fds > 1) {
1094 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1095 ERR_print_errors(bio_err);
1099 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1101 FD_SET(job_fd, &waitfdset);
1102 if (job_fd > max_fd)
1106 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1108 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1109 "Decrease the value of async_jobs\n",
1110 max_fd, FD_SETSIZE);
1111 ERR_print_errors(bio_err);
1116 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1117 if (select_result == -1 && errno == EINTR)
1120 if (select_result == -1) {
1121 BIO_printf(bio_err, "Failure in the select\n");
1122 ERR_print_errors(bio_err);
1127 if (select_result == 0)
1131 for (i = 0; i < async_jobs; i++) {
1132 if (loopargs[i].inprogress_job == NULL)
1135 if (!ASYNC_WAIT_CTX_get_all_fds
1136 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1137 || num_job_fds > 1) {
1138 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1139 ERR_print_errors(bio_err);
1143 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1146 #if defined(OPENSSL_SYS_UNIX)
1147 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1149 #elif defined(OPENSSL_SYS_WINDOWS)
1150 if (num_job_fds == 1
1151 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1156 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1157 loopargs[i].wait_ctx, &job_op_count,
1158 loop_function, (void *)(loopargs + i),
1159 sizeof(loopargs_t));
1164 if (job_op_count == -1) {
1167 total_op_count += job_op_count;
1170 loopargs[i].inprogress_job = NULL;
1175 loopargs[i].inprogress_job = NULL;
1176 BIO_printf(bio_err, "Failure in the job\n");
1177 ERR_print_errors(bio_err);
1184 return error ? -1 : total_op_count;
1187 int speed_main(int argc, char **argv)
1190 loopargs_t *loopargs = NULL;
1192 int loopargs_len = 0;
1194 const char *engine_id = NULL;
1195 const EVP_CIPHER *evp_cipher = NULL;
1198 int multiblock = 0, pr_header = 0;
1199 int doit[ALGOR_NUM] = { 0 };
1200 int ret = 1, i, k, misalign = 0;
1205 unsigned int async_jobs = 0;
1206 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1207 || !defined(OPENSSL_NO_EC)
1211 /* What follows are the buffers and key material. */
1212 #ifndef OPENSSL_NO_RC5
1215 #ifndef OPENSSL_NO_RC2
1218 #ifndef OPENSSL_NO_IDEA
1219 IDEA_KEY_SCHEDULE idea_ks;
1221 #ifndef OPENSSL_NO_SEED
1222 SEED_KEY_SCHEDULE seed_ks;
1224 #ifndef OPENSSL_NO_BF
1227 #ifndef OPENSSL_NO_CAST
1230 static const unsigned char key16[16] = {
1231 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1232 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1234 static const unsigned char key24[24] = {
1235 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1236 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1237 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1239 static const unsigned char key32[32] = {
1240 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1241 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1242 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1243 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1245 #ifndef OPENSSL_NO_CAMELLIA
1246 static const unsigned char ckey24[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 ckey32[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 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1259 #ifndef OPENSSL_NO_DES
1260 static DES_cblock key = {
1261 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1263 static DES_cblock key2 = {
1264 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1266 static DES_cblock key3 = {
1267 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1270 #ifndef OPENSSL_NO_RSA
1271 static const unsigned int rsa_bits[RSA_NUM] = {
1272 512, 1024, 2048, 3072, 4096, 7680, 15360
1274 static const unsigned char *rsa_data[RSA_NUM] = {
1275 test512, test1024, test2048, test3072, test4096, test7680, test15360
1277 static const int rsa_data_length[RSA_NUM] = {
1278 sizeof(test512), sizeof(test1024),
1279 sizeof(test2048), sizeof(test3072),
1280 sizeof(test4096), sizeof(test7680),
1283 int rsa_doit[RSA_NUM] = { 0 };
1285 #ifndef OPENSSL_NO_DSA
1286 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1287 int dsa_doit[DSA_NUM] = { 0 };
1289 #ifndef OPENSSL_NO_EC
1291 * We only test over the following curves as they are representative, To
1292 * add tests over more curves, simply add the curve NID and curve name to
1293 * the following arrays and increase the EC_NUM value accordingly.
1295 static const unsigned int test_curves[EC_NUM] = {
1297 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1298 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1300 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1301 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1302 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1307 static const char *test_curves_names[EC_NUM] = {
1309 "secp160r1", "nistp192", "nistp224",
1310 "nistp256", "nistp384", "nistp521",
1312 "nistk163", "nistk233", "nistk283",
1313 "nistk409", "nistk571", "nistb163",
1314 "nistb233", "nistb283", "nistb409",
1319 static const int test_curves_bits[EC_NUM] = {
1325 571, 253 /* X25519 */
1328 int ecdsa_doit[EC_NUM] = { 0 };
1329 int ecdh_doit[EC_NUM] = { 0 };
1330 #endif /* ndef OPENSSL_NO_EC */
1332 prog = opt_init(argc, argv, speed_options);
1333 while ((o = opt_next()) != OPT_EOF) {
1338 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1341 opt_help(speed_options);
1349 evp_cipher = EVP_get_cipherbyname(opt_arg());
1350 if (evp_cipher == NULL)
1351 evp_md = EVP_get_digestbyname(opt_arg());
1352 if (evp_cipher == NULL && evp_md == NULL) {
1354 "%s: %s is an unknown cipher or digest\n",
1365 * In a forked execution, an engine might need to be
1366 * initialised by each child process, not by the parent.
1367 * So store the name here and run setup_engine() later on.
1369 engine_id = opt_arg();
1373 multi = atoi(opt_arg());
1377 #ifndef OPENSSL_NO_ASYNC
1378 async_jobs = atoi(opt_arg());
1379 if (!ASYNC_is_capable()) {
1381 "%s: async_jobs specified but async not supported\n",
1385 if (async_jobs > 99999) {
1387 "%s: too many async_jobs\n",
1394 if (!opt_int(opt_arg(), &misalign))
1396 if (misalign > MISALIGN) {
1398 "%s: Maximum offset is %d\n", prog, MISALIGN);
1407 #ifdef OPENSSL_NO_MULTIBLOCK
1409 "%s: -mb specified but multi-block support is disabled\n",
1420 argc = opt_num_rest();
1423 /* Remaining arguments are algorithms. */
1424 for (; *argv; argv++) {
1425 if (found(*argv, doit_choices, &i)) {
1429 #ifndef OPENSSL_NO_DES
1430 if (strcmp(*argv, "des") == 0) {
1431 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1435 if (strcmp(*argv, "sha") == 0) {
1436 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1439 #ifndef OPENSSL_NO_RSA
1440 if (strcmp(*argv, "openssl") == 0)
1442 if (strcmp(*argv, "rsa") == 0) {
1443 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1444 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1445 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1446 rsa_doit[R_RSA_15360] = 1;
1449 if (found(*argv, rsa_choices, &i)) {
1454 #ifndef OPENSSL_NO_DSA
1455 if (strcmp(*argv, "dsa") == 0) {
1456 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1457 dsa_doit[R_DSA_2048] = 1;
1460 if (found(*argv, dsa_choices, &i)) {
1465 if (strcmp(*argv, "aes") == 0) {
1466 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1469 #ifndef OPENSSL_NO_CAMELLIA
1470 if (strcmp(*argv, "camellia") == 0) {
1471 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1475 #ifndef OPENSSL_NO_EC
1476 if (strcmp(*argv, "ecdsa") == 0) {
1477 for (i = 0; i < EC_NUM; i++)
1481 if (found(*argv, ecdsa_choices, &i)) {
1485 if (strcmp(*argv, "ecdh") == 0) {
1486 for (i = 0; i < EC_NUM; i++)
1490 if (found(*argv, ecdh_choices, &i)) {
1495 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1499 /* Initialize the job pool if async mode is enabled */
1500 if (async_jobs > 0) {
1501 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1503 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1508 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1510 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1511 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1513 for (i = 0; i < loopargs_len; i++) {
1514 if (async_jobs > 0) {
1515 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1516 if (loopargs[i].wait_ctx == NULL) {
1517 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1522 loopargs[i].buf_malloc =
1523 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1524 loopargs[i].buf2_malloc =
1525 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1526 /* Align the start of buffers on a 64 byte boundary */
1527 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1528 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1529 #ifndef OPENSSL_NO_EC
1530 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1531 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1536 if (multi && do_multi(multi))
1540 /* Initialize the engine after the fork */
1541 e = setup_engine(engine_id, 0);
1543 /* No parameters; turn on everything. */
1544 if ((argc == 0) && !doit[D_EVP]) {
1545 for (i = 0; i < ALGOR_NUM; i++)
1548 #ifndef OPENSSL_NO_RSA
1549 for (i = 0; i < RSA_NUM; i++)
1552 #ifndef OPENSSL_NO_DSA
1553 for (i = 0; i < DSA_NUM; i++)
1556 #ifndef OPENSSL_NO_EC
1557 for (i = 0; i < EC_NUM; i++)
1559 for (i = 0; i < EC_NUM; i++)
1563 for (i = 0; i < ALGOR_NUM; i++)
1567 if (usertime == 0 && !mr)
1569 "You have chosen to measure elapsed time "
1570 "instead of user CPU time.\n");
1572 #ifndef OPENSSL_NO_RSA
1573 for (i = 0; i < loopargs_len; i++) {
1574 for (k = 0; k < RSA_NUM; k++) {
1575 const unsigned char *p;
1578 loopargs[i].rsa_key[k] =
1579 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1580 if (loopargs[i].rsa_key[k] == NULL) {
1582 "internal error loading RSA key number %d\n", k);
1588 #ifndef OPENSSL_NO_DSA
1589 for (i = 0; i < loopargs_len; i++) {
1590 loopargs[i].dsa_key[0] = get_dsa(512);
1591 loopargs[i].dsa_key[1] = get_dsa(1024);
1592 loopargs[i].dsa_key[2] = get_dsa(2048);
1595 #ifndef OPENSSL_NO_DES
1596 DES_set_key_unchecked(&key, &sch);
1597 DES_set_key_unchecked(&key2, &sch2);
1598 DES_set_key_unchecked(&key3, &sch3);
1600 AES_set_encrypt_key(key16, 128, &aes_ks1);
1601 AES_set_encrypt_key(key24, 192, &aes_ks2);
1602 AES_set_encrypt_key(key32, 256, &aes_ks3);
1603 #ifndef OPENSSL_NO_CAMELLIA
1604 Camellia_set_key(key16, 128, &camellia_ks1);
1605 Camellia_set_key(ckey24, 192, &camellia_ks2);
1606 Camellia_set_key(ckey32, 256, &camellia_ks3);
1608 #ifndef OPENSSL_NO_IDEA
1609 IDEA_set_encrypt_key(key16, &idea_ks);
1611 #ifndef OPENSSL_NO_SEED
1612 SEED_set_key(key16, &seed_ks);
1614 #ifndef OPENSSL_NO_RC4
1615 RC4_set_key(&rc4_ks, 16, key16);
1617 #ifndef OPENSSL_NO_RC2
1618 RC2_set_key(&rc2_ks, 16, key16, 128);
1620 #ifndef OPENSSL_NO_RC5
1621 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1623 #ifndef OPENSSL_NO_BF
1624 BF_set_key(&bf_ks, 16, key16);
1626 #ifndef OPENSSL_NO_CAST
1627 CAST_set_key(&cast_ks, 16, key16);
1630 # ifndef OPENSSL_NO_DES
1631 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1637 for (it = count; it; it--)
1638 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1639 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1643 c[D_MD2][0] = count / 10;
1644 c[D_MDC2][0] = count / 10;
1645 c[D_MD4][0] = count;
1646 c[D_MD5][0] = count;
1647 c[D_HMAC][0] = count;
1648 c[D_SHA1][0] = count;
1649 c[D_RMD160][0] = count;
1650 c[D_RC4][0] = count * 5;
1651 c[D_CBC_DES][0] = count;
1652 c[D_EDE3_DES][0] = count / 3;
1653 c[D_CBC_IDEA][0] = count;
1654 c[D_CBC_SEED][0] = count;
1655 c[D_CBC_RC2][0] = count;
1656 c[D_CBC_RC5][0] = count;
1657 c[D_CBC_BF][0] = count;
1658 c[D_CBC_CAST][0] = count;
1659 c[D_CBC_128_AES][0] = count;
1660 c[D_CBC_192_AES][0] = count;
1661 c[D_CBC_256_AES][0] = count;
1662 c[D_CBC_128_CML][0] = count;
1663 c[D_CBC_192_CML][0] = count;
1664 c[D_CBC_256_CML][0] = count;
1665 c[D_SHA256][0] = count;
1666 c[D_SHA512][0] = count;
1667 c[D_WHIRLPOOL][0] = count;
1668 c[D_IGE_128_AES][0] = count;
1669 c[D_IGE_192_AES][0] = count;
1670 c[D_IGE_256_AES][0] = count;
1671 c[D_GHASH][0] = count;
1673 for (i = 1; i < SIZE_NUM; i++) {
1676 l0 = (long)lengths[0];
1677 l1 = (long)lengths[i];
1679 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1680 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1681 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1682 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1683 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1684 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1685 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1686 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1687 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1688 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1689 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1691 l0 = (long)lengths[i - 1];
1693 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1694 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1695 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1696 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1697 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1698 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1699 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1700 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1701 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1702 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1703 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1704 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1705 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1706 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1707 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1708 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1709 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1710 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1713 # ifndef OPENSSL_NO_RSA
1714 rsa_c[R_RSA_512][0] = count / 2000;
1715 rsa_c[R_RSA_512][1] = count / 400;
1716 for (i = 1; i < RSA_NUM; i++) {
1717 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1718 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1719 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1722 if (rsa_c[i][0] == 0) {
1723 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1730 # ifndef OPENSSL_NO_DSA
1731 dsa_c[R_DSA_512][0] = count / 1000;
1732 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1733 for (i = 1; i < DSA_NUM; i++) {
1734 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1735 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1736 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1739 if (dsa_c[i][0] == 0) {
1740 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1747 # ifndef OPENSSL_NO_EC
1748 ecdsa_c[R_EC_P160][0] = count / 1000;
1749 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1750 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1751 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1752 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1753 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1756 if (ecdsa_c[i][0] == 0) {
1762 ecdsa_c[R_EC_K163][0] = count / 1000;
1763 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1764 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1765 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1766 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1767 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1770 if (ecdsa_c[i][0] == 0) {
1776 ecdsa_c[R_EC_B163][0] = count / 1000;
1777 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1778 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1779 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1780 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1781 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1784 if (ecdsa_c[i][0] == 0) {
1791 ecdh_c[R_EC_P160][0] = count / 1000;
1792 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1793 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1794 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1797 if (ecdh_c[i][0] == 0) {
1802 ecdh_c[R_EC_K163][0] = count / 1000;
1803 for (i = R_EC_K233; i <= R_EC_K571; 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_B163][0] = count / 1000;
1814 for (i = R_EC_B233; i <= R_EC_B571; 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) {
1827 /* not worth fixing */
1828 # error "You cannot disable DES on systems without SIGALRM."
1829 # endif /* OPENSSL_NO_DES */
1832 signal(SIGALRM, sig_done);
1834 #endif /* SIGALRM */
1836 #ifndef OPENSSL_NO_MD2
1838 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1839 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1841 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1843 print_result(D_MD2, testnum, count, d);
1847 #ifndef OPENSSL_NO_MDC2
1849 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1850 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1852 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1854 print_result(D_MDC2, testnum, count, d);
1859 #ifndef OPENSSL_NO_MD4
1861 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1862 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1864 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1866 print_result(D_MD4, testnum, count, d);
1871 #ifndef OPENSSL_NO_MD5
1873 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1874 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1876 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1878 print_result(D_MD5, testnum, count, d);
1883 static const char hmac_key[] = "This is a key...";
1884 int len = strlen(hmac_key);
1886 for (i = 0; i < loopargs_len; i++) {
1887 loopargs[i].hctx = HMAC_CTX_new();
1888 if (loopargs[i].hctx == NULL) {
1889 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1893 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1895 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1896 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1898 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1900 print_result(D_HMAC, testnum, count, d);
1902 for (i = 0; i < loopargs_len; i++) {
1903 HMAC_CTX_free(loopargs[i].hctx);
1908 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1909 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1911 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1913 print_result(D_SHA1, testnum, count, d);
1916 if (doit[D_SHA256]) {
1917 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1918 print_message(names[D_SHA256], c[D_SHA256][testnum],
1921 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1923 print_result(D_SHA256, testnum, count, d);
1926 if (doit[D_SHA512]) {
1927 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1928 print_message(names[D_SHA512], c[D_SHA512][testnum],
1931 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1933 print_result(D_SHA512, testnum, count, d);
1936 #ifndef OPENSSL_NO_WHIRLPOOL
1937 if (doit[D_WHIRLPOOL]) {
1938 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1939 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1942 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1944 print_result(D_WHIRLPOOL, testnum, count, d);
1949 #ifndef OPENSSL_NO_RMD160
1950 if (doit[D_RMD160]) {
1951 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1952 print_message(names[D_RMD160], c[D_RMD160][testnum],
1955 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1957 print_result(D_RMD160, testnum, count, d);
1961 #ifndef OPENSSL_NO_RC4
1963 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1964 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1966 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1968 print_result(D_RC4, testnum, count, d);
1972 #ifndef OPENSSL_NO_DES
1973 if (doit[D_CBC_DES]) {
1974 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1975 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
1978 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1980 print_result(D_CBC_DES, testnum, count, d);
1984 if (doit[D_EDE3_DES]) {
1985 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1986 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
1990 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
1992 print_result(D_EDE3_DES, testnum, count, d);
1997 if (doit[D_CBC_128_AES]) {
1998 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1999 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2003 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2005 print_result(D_CBC_128_AES, testnum, count, d);
2008 if (doit[D_CBC_192_AES]) {
2009 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2010 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2014 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2016 print_result(D_CBC_192_AES, testnum, count, d);
2019 if (doit[D_CBC_256_AES]) {
2020 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2021 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2025 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2027 print_result(D_CBC_256_AES, testnum, count, d);
2031 if (doit[D_IGE_128_AES]) {
2032 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2033 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2037 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2039 print_result(D_IGE_128_AES, testnum, count, d);
2042 if (doit[D_IGE_192_AES]) {
2043 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2044 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2048 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2050 print_result(D_IGE_192_AES, testnum, count, d);
2053 if (doit[D_IGE_256_AES]) {
2054 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2055 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2059 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2061 print_result(D_IGE_256_AES, testnum, count, d);
2064 if (doit[D_GHASH]) {
2065 for (i = 0; i < loopargs_len; i++) {
2066 loopargs[i].gcm_ctx =
2067 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2068 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2069 (unsigned char *)"0123456789ab", 12);
2072 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2073 print_message(names[D_GHASH], c[D_GHASH][testnum],
2076 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2078 print_result(D_GHASH, testnum, count, d);
2080 for (i = 0; i < loopargs_len; i++)
2081 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2083 #ifndef OPENSSL_NO_CAMELLIA
2084 if (doit[D_CBC_128_CML]) {
2085 if (async_jobs > 0) {
2086 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2087 names[D_CBC_128_CML]);
2088 doit[D_CBC_128_CML] = 0;
2090 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2091 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2094 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2095 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2096 (size_t)lengths[testnum], &camellia_ks1,
2097 iv, CAMELLIA_ENCRYPT);
2099 print_result(D_CBC_128_CML, testnum, count, d);
2102 if (doit[D_CBC_192_CML]) {
2103 if (async_jobs > 0) {
2104 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2105 names[D_CBC_192_CML]);
2106 doit[D_CBC_192_CML] = 0;
2108 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2109 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2111 if (async_jobs > 0) {
2112 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2116 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2117 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2118 (size_t)lengths[testnum], &camellia_ks2,
2119 iv, CAMELLIA_ENCRYPT);
2121 print_result(D_CBC_192_CML, testnum, count, d);
2124 if (doit[D_CBC_256_CML]) {
2125 if (async_jobs > 0) {
2126 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2127 names[D_CBC_256_CML]);
2128 doit[D_CBC_256_CML] = 0;
2130 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2131 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2134 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2135 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2136 (size_t)lengths[testnum], &camellia_ks3,
2137 iv, CAMELLIA_ENCRYPT);
2139 print_result(D_CBC_256_CML, testnum, count, d);
2143 #ifndef OPENSSL_NO_IDEA
2144 if (doit[D_CBC_IDEA]) {
2145 if (async_jobs > 0) {
2146 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2148 doit[D_CBC_IDEA] = 0;
2150 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2151 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2154 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2155 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2156 (size_t)lengths[testnum], &idea_ks,
2159 print_result(D_CBC_IDEA, testnum, count, d);
2163 #ifndef OPENSSL_NO_SEED
2164 if (doit[D_CBC_SEED]) {
2165 if (async_jobs > 0) {
2166 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2168 doit[D_CBC_SEED] = 0;
2170 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2171 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2174 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2175 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2176 (size_t)lengths[testnum], &seed_ks, iv, 1);
2178 print_result(D_CBC_SEED, testnum, count, d);
2182 #ifndef OPENSSL_NO_RC2
2183 if (doit[D_CBC_RC2]) {
2184 if (async_jobs > 0) {
2185 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2187 doit[D_CBC_RC2] = 0;
2189 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2190 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2192 if (async_jobs > 0) {
2193 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2197 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2198 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2199 (size_t)lengths[testnum], &rc2_ks,
2202 print_result(D_CBC_RC2, testnum, count, d);
2206 #ifndef OPENSSL_NO_RC5
2207 if (doit[D_CBC_RC5]) {
2208 if (async_jobs > 0) {
2209 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2211 doit[D_CBC_RC5] = 0;
2213 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2214 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2216 if (async_jobs > 0) {
2217 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2221 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2222 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2223 (size_t)lengths[testnum], &rc5_ks,
2226 print_result(D_CBC_RC5, testnum, count, d);
2230 #ifndef OPENSSL_NO_BF
2231 if (doit[D_CBC_BF]) {
2232 if (async_jobs > 0) {
2233 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2237 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2238 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2241 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2242 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2243 (size_t)lengths[testnum], &bf_ks,
2246 print_result(D_CBC_BF, testnum, count, d);
2250 #ifndef OPENSSL_NO_CAST
2251 if (doit[D_CBC_CAST]) {
2252 if (async_jobs > 0) {
2253 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2255 doit[D_CBC_CAST] = 0;
2257 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2258 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2261 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2262 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2263 (size_t)lengths[testnum], &cast_ks,
2266 print_result(D_CBC_CAST, testnum, count, d);
2272 if (multiblock && evp_cipher) {
2274 (EVP_CIPHER_flags(evp_cipher) &
2275 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2276 BIO_printf(bio_err, "%s is not multi-block capable\n",
2277 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2280 if (async_jobs > 0) {
2281 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2284 multiblock_speed(evp_cipher);
2288 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2291 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2293 * -O3 -fschedule-insns messes up an optimization here!
2294 * names[D_EVP] somehow becomes NULL
2296 print_message(names[D_EVP], save_count, lengths[testnum]);
2298 for (k = 0; k < loopargs_len; k++) {
2299 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2301 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2304 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2306 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2310 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2312 for (k = 0; k < loopargs_len; k++) {
2313 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2317 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2318 print_message(names[D_EVP], save_count, lengths[testnum]);
2320 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2323 print_result(D_EVP, testnum, count, d);
2327 for (i = 0; i < loopargs_len; i++)
2328 RAND_bytes(loopargs[i].buf, 36);
2330 #ifndef OPENSSL_NO_RSA
2331 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2333 if (!rsa_doit[testnum])
2335 for (i = 0; i < loopargs_len; i++) {
2336 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2337 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2343 "RSA sign failure. No RSA sign will be done.\n");
2344 ERR_print_errors(bio_err);
2347 pkey_print_message("private", "rsa",
2348 rsa_c[testnum][0], rsa_bits[testnum],
2350 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2352 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2355 mr ? "+R1:%ld:%d:%.2f\n"
2356 : "%ld %d bit private RSA's in %.2fs\n",
2357 count, rsa_bits[testnum], d);
2358 rsa_results[testnum][0] = (double)count / d;
2362 for (i = 0; i < loopargs_len; i++) {
2363 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2364 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2370 "RSA verify failure. No RSA verify will be done.\n");
2371 ERR_print_errors(bio_err);
2372 rsa_doit[testnum] = 0;
2374 pkey_print_message("public", "rsa",
2375 rsa_c[testnum][1], rsa_bits[testnum],
2378 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2381 mr ? "+R2:%ld:%d:%.2f\n"
2382 : "%ld %d bit public RSA's in %.2fs\n",
2383 count, rsa_bits[testnum], d);
2384 rsa_results[testnum][1] = (double)count / d;
2387 if (rsa_count <= 1) {
2388 /* if longer than 10s, don't do any more */
2389 for (testnum++; testnum < RSA_NUM; testnum++)
2390 rsa_doit[testnum] = 0;
2393 #endif /* OPENSSL_NO_RSA */
2395 for (i = 0; i < loopargs_len; i++)
2396 RAND_bytes(loopargs[i].buf, 36);
2398 #ifndef OPENSSL_NO_DSA
2399 if (RAND_status() != 1) {
2400 RAND_seed(rnd_seed, sizeof rnd_seed);
2402 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2404 if (!dsa_doit[testnum])
2407 /* DSA_generate_key(dsa_key[testnum]); */
2408 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2409 for (i = 0; i < loopargs_len; i++) {
2410 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2411 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2417 "DSA sign failure. No DSA sign will be done.\n");
2418 ERR_print_errors(bio_err);
2421 pkey_print_message("sign", "dsa",
2422 dsa_c[testnum][0], dsa_bits[testnum],
2425 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2428 mr ? "+R3:%ld:%d:%.2f\n"
2429 : "%ld %d bit DSA signs in %.2fs\n",
2430 count, dsa_bits[testnum], d);
2431 dsa_results[testnum][0] = (double)count / d;
2435 for (i = 0; i < loopargs_len; i++) {
2436 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2437 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2443 "DSA verify failure. No DSA verify will be done.\n");
2444 ERR_print_errors(bio_err);
2445 dsa_doit[testnum] = 0;
2447 pkey_print_message("verify", "dsa",
2448 dsa_c[testnum][1], dsa_bits[testnum],
2451 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2454 mr ? "+R4:%ld:%d:%.2f\n"
2455 : "%ld %d bit DSA verify in %.2fs\n",
2456 count, dsa_bits[testnum], d);
2457 dsa_results[testnum][1] = (double)count / d;
2460 if (rsa_count <= 1) {
2461 /* if longer than 10s, don't do any more */
2462 for (testnum++; testnum < DSA_NUM; testnum++)
2463 dsa_doit[testnum] = 0;
2466 #endif /* OPENSSL_NO_DSA */
2468 #ifndef OPENSSL_NO_EC
2469 if (RAND_status() != 1) {
2470 RAND_seed(rnd_seed, sizeof rnd_seed);
2472 for (testnum = 0; testnum < EC_NUM; testnum++) {
2475 if (!ecdsa_doit[testnum])
2476 continue; /* Ignore Curve */
2477 for (i = 0; i < loopargs_len; i++) {
2478 loopargs[i].ecdsa[testnum] =
2479 EC_KEY_new_by_curve_name(test_curves[testnum]);
2480 if (loopargs[i].ecdsa[testnum] == NULL) {
2486 BIO_printf(bio_err, "ECDSA failure.\n");
2487 ERR_print_errors(bio_err);
2490 for (i = 0; i < loopargs_len; i++) {
2491 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2492 /* Perform ECDSA signature test */
2493 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2494 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2495 &loopargs[i].siglen,
2496 loopargs[i].ecdsa[testnum]);
2502 "ECDSA sign failure. No ECDSA sign will be done.\n");
2503 ERR_print_errors(bio_err);
2506 pkey_print_message("sign", "ecdsa",
2507 ecdsa_c[testnum][0],
2508 test_curves_bits[testnum], ECDSA_SECONDS);
2510 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2514 mr ? "+R5:%ld:%d:%.2f\n" :
2515 "%ld %d bit ECDSA signs in %.2fs \n",
2516 count, test_curves_bits[testnum], d);
2517 ecdsa_results[testnum][0] = (double)count / d;
2521 /* Perform ECDSA verification test */
2522 for (i = 0; i < loopargs_len; i++) {
2523 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2525 loopargs[i].ecdsa[testnum]);
2531 "ECDSA verify failure. No ECDSA verify will be done.\n");
2532 ERR_print_errors(bio_err);
2533 ecdsa_doit[testnum] = 0;
2535 pkey_print_message("verify", "ecdsa",
2536 ecdsa_c[testnum][1],
2537 test_curves_bits[testnum], ECDSA_SECONDS);
2539 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2542 mr ? "+R6:%ld:%d:%.2f\n"
2543 : "%ld %d bit ECDSA verify in %.2fs\n",
2544 count, test_curves_bits[testnum], d);
2545 ecdsa_results[testnum][1] = (double)count / d;
2548 if (rsa_count <= 1) {
2549 /* if longer than 10s, don't do any more */
2550 for (testnum++; testnum < EC_NUM; testnum++)
2551 ecdsa_doit[testnum] = 0;
2556 if (RAND_status() != 1) {
2557 RAND_seed(rnd_seed, sizeof rnd_seed);
2559 for (testnum = 0; testnum < EC_NUM; testnum++) {
2560 int ecdh_checks = 1;
2562 if (!ecdh_doit[testnum])
2565 for (i = 0; i < loopargs_len; i++) {
2566 EVP_PKEY_CTX *kctx = NULL;
2567 EVP_PKEY_CTX *test_ctx = NULL;
2568 EVP_PKEY_CTX *ctx = NULL;
2569 EVP_PKEY *key_A = NULL;
2570 EVP_PKEY *key_B = NULL;
2574 /* Ensure that the error queue is empty */
2575 if (ERR_peek_error()) {
2577 "WARNING: the error queue contains previous unhandled errors.\n");
2578 ERR_print_errors(bio_err);
2581 /* Let's try to create a ctx directly from the NID: this works for
2582 * curves like Curve25519 that are not implemented through the low
2583 * level EC interface.
2584 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2585 * then we set the curve by NID before deriving the actual keygen
2586 * ctx for that specific curve. */
2587 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2589 EVP_PKEY_CTX *pctx = NULL;
2590 EVP_PKEY *params = NULL;
2592 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2593 * "int_ctx_new:unsupported algorithm" error was added to the
2595 * We remove it from the error queue as we are handling it. */
2596 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2597 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2598 /* check that the error origin matches */
2599 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2600 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2601 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2602 ERR_get_error(); /* pop error from queue */
2603 if (ERR_peek_error()) {
2605 "Unhandled error in the error queue during ECDH init.\n");
2606 ERR_print_errors(bio_err);
2611 if ( /* Create the context for parameter generation */
2612 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2613 /* Initialise the parameter generation */
2614 !EVP_PKEY_paramgen_init(pctx) ||
2615 /* Set the curve by NID */
2616 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2619 /* Create the parameter object params */
2620 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2622 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2623 ERR_print_errors(bio_err);
2627 /* Create the context for the key generation */
2628 kctx = EVP_PKEY_CTX_new(params, NULL);
2630 EVP_PKEY_free(params);
2632 EVP_PKEY_CTX_free(pctx);
2635 if (kctx == NULL || /* keygen ctx is not null */
2636 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2638 BIO_printf(bio_err, "ECDH keygen failure.\n");
2639 ERR_print_errors(bio_err);
2644 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2645 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2646 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2647 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2648 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2649 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2650 outlen == 0 || /* ensure outlen is a valid size */
2651 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2653 BIO_printf(bio_err, "ECDH key generation failure.\n");
2654 ERR_print_errors(bio_err);
2659 /* Here we perform a test run, comparing the output of a*B and b*A;
2660 * we try this here and assume that further EVP_PKEY_derive calls
2661 * never fail, so we can skip checks in the actually benchmarked
2662 * code, for maximum performance. */
2663 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2664 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2665 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2666 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2667 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2668 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2669 test_outlen != outlen /* compare output length */ ) {
2671 BIO_printf(bio_err, "ECDH computation failure.\n");
2672 ERR_print_errors(bio_err);
2677 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2678 if (CRYPTO_memcmp(loopargs[i].secret_a,
2679 loopargs[i].secret_b, outlen)) {
2681 BIO_printf(bio_err, "ECDH computations don't match.\n");
2682 ERR_print_errors(bio_err);
2687 loopargs[i].ecdh_ctx[testnum] = ctx;
2688 loopargs[i].outlen[testnum] = outlen;
2690 EVP_PKEY_CTX_free(kctx);
2692 EVP_PKEY_CTX_free(test_ctx);
2695 if (ecdh_checks != 0) {
2696 pkey_print_message("", "ecdh",
2698 test_curves_bits[testnum], ECDH_SECONDS);
2701 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2704 mr ? "+R7:%ld:%d:%.2f\n" :
2705 "%ld %d-bit ECDH ops in %.2fs\n", count,
2706 test_curves_bits[testnum], d);
2707 ecdh_results[testnum][0] = (double)count / d;
2711 if (rsa_count <= 1) {
2712 /* if longer than 10s, don't do any more */
2713 for (testnum++; testnum < EC_NUM; testnum++)
2714 ecdh_doit[testnum] = 0;
2717 #endif /* OPENSSL_NO_EC */
2722 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2723 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2725 printf("%s ", BN_options());
2726 #ifndef OPENSSL_NO_MD2
2727 printf("%s ", MD2_options());
2729 #ifndef OPENSSL_NO_RC4
2730 printf("%s ", RC4_options());
2732 #ifndef OPENSSL_NO_DES
2733 printf("%s ", DES_options());
2735 printf("%s ", AES_options());
2736 #ifndef OPENSSL_NO_IDEA
2737 printf("%s ", IDEA_options());
2739 #ifndef OPENSSL_NO_BF
2740 printf("%s ", BF_options());
2742 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2750 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2753 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2754 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2758 for (k = 0; k < ALGOR_NUM; k++) {
2762 printf("+F:%d:%s", k, names[k]);
2764 printf("%-13s", names[k]);
2765 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2766 if (results[k][testnum] > 10000 && !mr)
2767 printf(" %11.2fk", results[k][testnum] / 1e3);
2769 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2773 #ifndef OPENSSL_NO_RSA
2775 for (k = 0; k < RSA_NUM; k++) {
2778 if (testnum && !mr) {
2779 printf("%18ssign verify sign/s verify/s\n", " ");
2783 printf("+F2:%u:%u:%f:%f\n",
2784 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2786 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2787 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2788 rsa_results[k][0], rsa_results[k][1]);
2791 #ifndef OPENSSL_NO_DSA
2793 for (k = 0; k < DSA_NUM; k++) {
2796 if (testnum && !mr) {
2797 printf("%18ssign verify sign/s verify/s\n", " ");
2801 printf("+F3:%u:%u:%f:%f\n",
2802 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2804 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2805 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2806 dsa_results[k][0], dsa_results[k][1]);
2809 #ifndef OPENSSL_NO_EC
2811 for (k = 0; k < EC_NUM; k++) {
2814 if (testnum && !mr) {
2815 printf("%30ssign verify sign/s verify/s\n", " ");
2820 printf("+F4:%u:%u:%f:%f\n",
2821 k, test_curves_bits[k],
2822 ecdsa_results[k][0], ecdsa_results[k][1]);
2824 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2825 test_curves_bits[k],
2826 test_curves_names[k],
2827 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2828 ecdsa_results[k][0], ecdsa_results[k][1]);
2832 for (k = 0; k < EC_NUM; k++) {
2835 if (testnum && !mr) {
2836 printf("%30sop op/s\n", " ");
2840 printf("+F5:%u:%u:%f:%f\n",
2841 k, test_curves_bits[k],
2842 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2845 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2846 test_curves_bits[k],
2847 test_curves_names[k],
2848 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2855 ERR_print_errors(bio_err);
2856 for (i = 0; i < loopargs_len; i++) {
2857 OPENSSL_free(loopargs[i].buf_malloc);
2858 OPENSSL_free(loopargs[i].buf2_malloc);
2860 #ifndef OPENSSL_NO_RSA
2861 for (k = 0; k < RSA_NUM; k++)
2862 RSA_free(loopargs[i].rsa_key[k]);
2864 #ifndef OPENSSL_NO_DSA
2865 for (k = 0; k < DSA_NUM; k++)
2866 DSA_free(loopargs[i].dsa_key[k]);
2868 #ifndef OPENSSL_NO_EC
2869 for (k = 0; k < EC_NUM; k++) {
2870 EC_KEY_free(loopargs[i].ecdsa[k]);
2871 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2873 OPENSSL_free(loopargs[i].secret_a);
2874 OPENSSL_free(loopargs[i].secret_b);
2878 if (async_jobs > 0) {
2879 for (i = 0; i < loopargs_len; i++)
2880 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2884 ASYNC_cleanup_thread();
2886 OPENSSL_free(loopargs);
2891 static void print_message(const char *s, long num, int length)
2895 mr ? "+DT:%s:%d:%d\n"
2896 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2897 (void)BIO_flush(bio_err);
2901 mr ? "+DN:%s:%ld:%d\n"
2902 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2903 (void)BIO_flush(bio_err);
2907 static void pkey_print_message(const char *str, const char *str2, long num,
2912 mr ? "+DTP:%d:%s:%s:%d\n"
2913 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2914 (void)BIO_flush(bio_err);
2918 mr ? "+DNP:%ld:%d:%s:%s\n"
2919 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2920 (void)BIO_flush(bio_err);
2924 static void print_result(int alg, int run_no, int count, double time_used)
2927 BIO_puts(bio_err, "EVP error!\n");
2931 mr ? "+R:%d:%s:%f\n"
2932 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2933 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2937 static char *sstrsep(char **string, const char *delim)
2940 char *token = *string;
2945 memset(isdelim, 0, sizeof isdelim);
2949 isdelim[(unsigned char)(*delim)] = 1;
2953 while (!isdelim[(unsigned char)(**string)]) {
2965 static int do_multi(int multi)
2970 static char sep[] = ":";
2972 fds = malloc(sizeof(*fds) * multi);
2973 for (n = 0; n < multi; ++n) {
2974 if (pipe(fd) == -1) {
2975 BIO_printf(bio_err, "pipe failure\n");
2979 (void)BIO_flush(bio_err);
2986 if (dup(fd[1]) == -1) {
2987 BIO_printf(bio_err, "dup failed\n");
2996 printf("Forked child %d\n", n);
2999 /* for now, assume the pipe is long enough to take all the output */
3000 for (n = 0; n < multi; ++n) {
3005 f = fdopen(fds[n], "r");
3006 while (fgets(buf, sizeof buf, f)) {
3007 p = strchr(buf, '\n');
3010 if (buf[0] != '+') {
3012 "Don't understand line '%s' from child %d\n", buf,
3016 printf("Got: %s from %d\n", buf, n);
3017 if (strncmp(buf, "+F:", 3) == 0) {
3022 alg = atoi(sstrsep(&p, sep));
3024 for (j = 0; j < SIZE_NUM; ++j)
3025 results[alg][j] += atof(sstrsep(&p, sep));
3026 } else if (strncmp(buf, "+F2:", 4) == 0) {
3031 k = atoi(sstrsep(&p, sep));
3034 d = atof(sstrsep(&p, sep));
3035 rsa_results[k][0] += d;
3037 d = atof(sstrsep(&p, sep));
3038 rsa_results[k][1] += d;
3040 # ifndef OPENSSL_NO_DSA
3041 else if (strncmp(buf, "+F3:", 4) == 0) {
3046 k = atoi(sstrsep(&p, sep));
3049 d = atof(sstrsep(&p, sep));
3050 dsa_results[k][0] += d;
3052 d = atof(sstrsep(&p, sep));
3053 dsa_results[k][1] += d;
3056 # ifndef OPENSSL_NO_EC
3057 else if (strncmp(buf, "+F4:", 4) == 0) {
3062 k = atoi(sstrsep(&p, sep));
3065 d = atof(sstrsep(&p, sep));
3066 ecdsa_results[k][0] += d;
3068 d = atof(sstrsep(&p, sep));
3069 ecdsa_results[k][1] += d;
3070 } else if (strncmp(buf, "+F5:", 4) == 0) {
3075 k = atoi(sstrsep(&p, sep));
3078 d = atof(sstrsep(&p, sep));
3079 ecdh_results[k][0] += d;
3083 else if (strncmp(buf, "+H:", 3) == 0) {
3086 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3097 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3099 static int mblengths[] =
3100 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3101 int j, count, num = OSSL_NELEM(mblengths);
3102 const char *alg_name;
3103 unsigned char *inp, *out, no_key[32], no_iv[16];
3104 EVP_CIPHER_CTX *ctx;
3107 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3108 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3109 ctx = EVP_CIPHER_CTX_new();
3110 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3111 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3112 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3114 for (j = 0; j < num; j++) {
3115 print_message(alg_name, 0, mblengths[j]);
3117 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3118 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3119 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3120 size_t len = mblengths[j];
3123 memset(aad, 0, 8); /* avoid uninitialized values */
3124 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3125 aad[9] = 3; /* version */
3127 aad[11] = 0; /* length */
3129 mb_param.out = NULL;
3132 mb_param.interleave = 8;
3134 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3135 sizeof(mb_param), &mb_param);
3141 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3142 sizeof(mb_param), &mb_param);
3146 RAND_bytes(out, 16);
3150 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3151 EVP_AEAD_TLS1_AAD_LEN, aad);
3152 EVP_Cipher(ctx, out, inp, len + pad);
3156 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3157 : "%d %s's in %.2fs\n", count, "evp", d);
3158 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3162 fprintf(stdout, "+H");
3163 for (j = 0; j < num; j++)
3164 fprintf(stdout, ":%d", mblengths[j]);
3165 fprintf(stdout, "\n");
3166 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3167 for (j = 0; j < num; j++)
3168 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3169 fprintf(stdout, "\n");
3172 "The 'numbers' are in 1000s of bytes per second processed.\n");
3173 fprintf(stdout, "type ");
3174 for (j = 0; j < num; j++)
3175 fprintf(stdout, "%7d bytes", mblengths[j]);
3176 fprintf(stdout, "\n");
3177 fprintf(stdout, "%-24s", alg_name);
3179 for (j = 0; j < num; j++) {
3180 if (results[D_EVP][j] > 10000)
3181 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3183 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3185 fprintf(stdout, "\n");
3190 EVP_CIPHER_CTX_free(ctx);