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];
251 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
252 # define SIGRETTYPE void
254 # define SIGRETTYPE int
257 static SIGRETTYPE sig_done(int sig);
258 static SIGRETTYPE sig_done(int sig)
260 signal(SIGALRM, sig_done);
270 # if !defined(SIGALRM)
273 static unsigned int lapse;
274 static volatile unsigned int schlock;
275 static void alarm_win32(unsigned int secs)
280 # define alarm alarm_win32
282 static DWORD WINAPI sleepy(VOID * arg)
290 static double Time_F(int s)
297 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
299 DWORD err = GetLastError();
300 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
304 Sleep(0); /* scheduler spinlock */
305 ret = app_tminterval(s, usertime);
307 ret = app_tminterval(s, usertime);
309 TerminateThread(thr, 0);
317 static double Time_F(int s)
319 double ret = app_tminterval(s, usertime);
326 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
328 static int found(const char *name, const OPT_PAIR *pairs, int *result)
330 for (; pairs->name; pairs++)
331 if (strcmp(name, pairs->name) == 0) {
332 *result = pairs->retval;
338 typedef enum OPTION_choice {
339 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
340 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
341 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM
344 const OPTIONS speed_options[] = {
345 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
346 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
347 {"help", OPT_HELP, '-', "Display this summary"},
348 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
349 {"decrypt", OPT_DECRYPT, '-',
350 "Time decryption instead of encryption (only EVP)"},
351 {"mr", OPT_MR, '-', "Produce machine readable output"},
353 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
354 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
355 {"elapsed", OPT_ELAPSED, '-',
356 "Measure time in real time instead of CPU user time"},
358 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
360 #ifndef OPENSSL_NO_ASYNC
361 {"async_jobs", OPT_ASYNCJOBS, 'p',
362 "Enable async mode and start pnum jobs"},
365 #ifndef OPENSSL_NO_ENGINE
366 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
381 #define D_CBC_IDEA 10
382 #define D_CBC_SEED 11
386 #define D_CBC_CAST 15
387 #define D_CBC_128_AES 16
388 #define D_CBC_192_AES 17
389 #define D_CBC_256_AES 18
390 #define D_CBC_128_CML 19
391 #define D_CBC_192_CML 20
392 #define D_CBC_256_CML 21
396 #define D_WHIRLPOOL 25
397 #define D_IGE_128_AES 26
398 #define D_IGE_192_AES 27
399 #define D_IGE_256_AES 28
401 static OPT_PAIR doit_choices[] = {
402 #ifndef OPENSSL_NO_MD2
405 #ifndef OPENSSL_NO_MDC2
408 #ifndef OPENSSL_NO_MD4
411 #ifndef OPENSSL_NO_MD5
416 {"sha256", D_SHA256},
417 {"sha512", D_SHA512},
418 #ifndef OPENSSL_NO_WHIRLPOOL
419 {"whirlpool", D_WHIRLPOOL},
421 #ifndef OPENSSL_NO_RMD160
422 {"ripemd", D_RMD160},
423 {"rmd160", D_RMD160},
424 {"ripemd160", D_RMD160},
426 #ifndef OPENSSL_NO_RC4
429 #ifndef OPENSSL_NO_DES
430 {"des-cbc", D_CBC_DES},
431 {"des-ede3", D_EDE3_DES},
433 {"aes-128-cbc", D_CBC_128_AES},
434 {"aes-192-cbc", D_CBC_192_AES},
435 {"aes-256-cbc", D_CBC_256_AES},
436 {"aes-128-ige", D_IGE_128_AES},
437 {"aes-192-ige", D_IGE_192_AES},
438 {"aes-256-ige", D_IGE_256_AES},
439 #ifndef OPENSSL_NO_RC2
440 {"rc2-cbc", D_CBC_RC2},
443 #ifndef OPENSSL_NO_RC5
444 {"rc5-cbc", D_CBC_RC5},
447 #ifndef OPENSSL_NO_IDEA
448 {"idea-cbc", D_CBC_IDEA},
449 {"idea", D_CBC_IDEA},
451 #ifndef OPENSSL_NO_SEED
452 {"seed-cbc", D_CBC_SEED},
453 {"seed", D_CBC_SEED},
455 #ifndef OPENSSL_NO_BF
456 {"bf-cbc", D_CBC_BF},
457 {"blowfish", D_CBC_BF},
460 #ifndef OPENSSL_NO_CAST
461 {"cast-cbc", D_CBC_CAST},
462 {"cast", D_CBC_CAST},
463 {"cast5", D_CBC_CAST},
469 #ifndef OPENSSL_NO_DSA
471 # define R_DSA_1024 1
472 # define R_DSA_2048 2
473 static OPT_PAIR dsa_choices[] = {
474 {"dsa512", R_DSA_512},
475 {"dsa1024", R_DSA_1024},
476 {"dsa2048", R_DSA_2048},
487 #define R_RSA_15360 6
488 static OPT_PAIR rsa_choices[] = {
489 {"rsa512", R_RSA_512},
490 {"rsa1024", R_RSA_1024},
491 {"rsa2048", R_RSA_2048},
492 {"rsa3072", R_RSA_3072},
493 {"rsa4096", R_RSA_4096},
494 {"rsa7680", R_RSA_7680},
495 {"rsa15360", R_RSA_15360},
515 #define R_EC_X25519 16
516 #ifndef OPENSSL_NO_EC
517 static OPT_PAIR ecdsa_choices[] = {
518 {"ecdsap160", R_EC_P160},
519 {"ecdsap192", R_EC_P192},
520 {"ecdsap224", R_EC_P224},
521 {"ecdsap256", R_EC_P256},
522 {"ecdsap384", R_EC_P384},
523 {"ecdsap521", R_EC_P521},
524 {"ecdsak163", R_EC_K163},
525 {"ecdsak233", R_EC_K233},
526 {"ecdsak283", R_EC_K283},
527 {"ecdsak409", R_EC_K409},
528 {"ecdsak571", R_EC_K571},
529 {"ecdsab163", R_EC_B163},
530 {"ecdsab233", R_EC_B233},
531 {"ecdsab283", R_EC_B283},
532 {"ecdsab409", R_EC_B409},
533 {"ecdsab571", R_EC_B571},
537 static OPT_PAIR ecdh_choices[] = {
538 {"ecdhp160", R_EC_P160},
539 {"ecdhp192", R_EC_P192},
540 {"ecdhp224", R_EC_P224},
541 {"ecdhp256", R_EC_P256},
542 {"ecdhp384", R_EC_P384},
543 {"ecdhp521", R_EC_P521},
544 {"ecdhk163", R_EC_K163},
545 {"ecdhk233", R_EC_K233},
546 {"ecdhk283", R_EC_K283},
547 {"ecdhk409", R_EC_K409},
548 {"ecdhk571", R_EC_K571},
549 {"ecdhb163", R_EC_B163},
550 {"ecdhb233", R_EC_B233},
551 {"ecdhb283", R_EC_B283},
552 {"ecdhb409", R_EC_B409},
553 {"ecdhb571", R_EC_B571},
554 {"ecdhx25519", R_EC_X25519},
560 # define COND(d) (count < (d))
561 # define COUNT(d) (d)
563 # define COND(unused_cond) (run && count<0x7fffffff)
564 # define COUNT(d) (count)
569 /* Nb of iterations to do per algorithm and key-size */
570 static long c[ALGOR_NUM][SIZE_NUM];
572 #ifndef OPENSSL_NO_MD2
573 static int EVP_Digest_MD2_loop(void *args)
575 loopargs_t *tempargs = *(loopargs_t **) args;
576 unsigned char *buf = tempargs->buf;
577 unsigned char md2[MD2_DIGEST_LENGTH];
580 for (count = 0; COND(c[D_MD2][testnum]); count++) {
581 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
589 #ifndef OPENSSL_NO_MDC2
590 static int EVP_Digest_MDC2_loop(void *args)
592 loopargs_t *tempargs = *(loopargs_t **) args;
593 unsigned char *buf = tempargs->buf;
594 unsigned char mdc2[MDC2_DIGEST_LENGTH];
597 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
598 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
606 #ifndef OPENSSL_NO_MD4
607 static int EVP_Digest_MD4_loop(void *args)
609 loopargs_t *tempargs = *(loopargs_t **) args;
610 unsigned char *buf = tempargs->buf;
611 unsigned char md4[MD4_DIGEST_LENGTH];
614 for (count = 0; COND(c[D_MD4][testnum]); count++) {
615 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
623 #ifndef OPENSSL_NO_MD5
624 static int MD5_loop(void *args)
626 loopargs_t *tempargs = *(loopargs_t **) args;
627 unsigned char *buf = tempargs->buf;
628 unsigned char md5[MD5_DIGEST_LENGTH];
630 for (count = 0; COND(c[D_MD5][testnum]); count++)
631 MD5(buf, lengths[testnum], md5);
635 static int HMAC_loop(void *args)
637 loopargs_t *tempargs = *(loopargs_t **) args;
638 unsigned char *buf = tempargs->buf;
639 HMAC_CTX *hctx = tempargs->hctx;
640 unsigned char hmac[MD5_DIGEST_LENGTH];
643 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
644 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
645 HMAC_Update(hctx, buf, lengths[testnum]);
646 HMAC_Final(hctx, hmac, NULL);
652 static int SHA1_loop(void *args)
654 loopargs_t *tempargs = *(loopargs_t **) args;
655 unsigned char *buf = tempargs->buf;
656 unsigned char sha[SHA_DIGEST_LENGTH];
658 for (count = 0; COND(c[D_SHA1][testnum]); count++)
659 SHA1(buf, lengths[testnum], sha);
663 static int SHA256_loop(void *args)
665 loopargs_t *tempargs = *(loopargs_t **) args;
666 unsigned char *buf = tempargs->buf;
667 unsigned char sha256[SHA256_DIGEST_LENGTH];
669 for (count = 0; COND(c[D_SHA256][testnum]); count++)
670 SHA256(buf, lengths[testnum], sha256);
674 static int SHA512_loop(void *args)
676 loopargs_t *tempargs = *(loopargs_t **) args;
677 unsigned char *buf = tempargs->buf;
678 unsigned char sha512[SHA512_DIGEST_LENGTH];
680 for (count = 0; COND(c[D_SHA512][testnum]); count++)
681 SHA512(buf, lengths[testnum], sha512);
685 #ifndef OPENSSL_NO_WHIRLPOOL
686 static int WHIRLPOOL_loop(void *args)
688 loopargs_t *tempargs = *(loopargs_t **) args;
689 unsigned char *buf = tempargs->buf;
690 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
692 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
693 WHIRLPOOL(buf, lengths[testnum], whirlpool);
698 #ifndef OPENSSL_NO_RMD160
699 static int EVP_Digest_RMD160_loop(void *args)
701 loopargs_t *tempargs = *(loopargs_t **) args;
702 unsigned char *buf = tempargs->buf;
703 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
705 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
706 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
707 NULL, EVP_ripemd160(), NULL))
714 #ifndef OPENSSL_NO_RC4
715 static RC4_KEY rc4_ks;
716 static int RC4_loop(void *args)
718 loopargs_t *tempargs = *(loopargs_t **) args;
719 unsigned char *buf = tempargs->buf;
721 for (count = 0; COND(c[D_RC4][testnum]); count++)
722 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
727 #ifndef OPENSSL_NO_DES
728 static unsigned char DES_iv[8];
729 static DES_key_schedule sch;
730 static DES_key_schedule sch2;
731 static DES_key_schedule sch3;
732 static int DES_ncbc_encrypt_loop(void *args)
734 loopargs_t *tempargs = *(loopargs_t **) args;
735 unsigned char *buf = tempargs->buf;
737 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
738 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
739 &DES_iv, DES_ENCRYPT);
743 static int DES_ede3_cbc_encrypt_loop(void *args)
745 loopargs_t *tempargs = *(loopargs_t **) args;
746 unsigned char *buf = tempargs->buf;
748 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
749 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
750 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
755 #define MAX_BLOCK_SIZE 128
757 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
758 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
759 static int AES_cbc_128_encrypt_loop(void *args)
761 loopargs_t *tempargs = *(loopargs_t **) args;
762 unsigned char *buf = tempargs->buf;
764 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
765 AES_cbc_encrypt(buf, buf,
766 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
770 static int AES_cbc_192_encrypt_loop(void *args)
772 loopargs_t *tempargs = *(loopargs_t **) args;
773 unsigned char *buf = tempargs->buf;
775 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
776 AES_cbc_encrypt(buf, buf,
777 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
781 static int AES_cbc_256_encrypt_loop(void *args)
783 loopargs_t *tempargs = *(loopargs_t **) args;
784 unsigned char *buf = tempargs->buf;
786 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
787 AES_cbc_encrypt(buf, buf,
788 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
792 static int AES_ige_128_encrypt_loop(void *args)
794 loopargs_t *tempargs = *(loopargs_t **) args;
795 unsigned char *buf = tempargs->buf;
796 unsigned char *buf2 = tempargs->buf2;
798 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
799 AES_ige_encrypt(buf, buf2,
800 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
804 static int AES_ige_192_encrypt_loop(void *args)
806 loopargs_t *tempargs = *(loopargs_t **) args;
807 unsigned char *buf = tempargs->buf;
808 unsigned char *buf2 = tempargs->buf2;
810 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
811 AES_ige_encrypt(buf, buf2,
812 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
816 static int AES_ige_256_encrypt_loop(void *args)
818 loopargs_t *tempargs = *(loopargs_t **) args;
819 unsigned char *buf = tempargs->buf;
820 unsigned char *buf2 = tempargs->buf2;
822 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
823 AES_ige_encrypt(buf, buf2,
824 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
828 static int CRYPTO_gcm128_aad_loop(void *args)
830 loopargs_t *tempargs = *(loopargs_t **) args;
831 unsigned char *buf = tempargs->buf;
832 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
834 for (count = 0; COND(c[D_GHASH][testnum]); count++)
835 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
839 static long save_count = 0;
840 static int decrypt = 0;
841 static int EVP_Update_loop(void *args)
843 loopargs_t *tempargs = *(loopargs_t **) args;
844 unsigned char *buf = tempargs->buf;
845 EVP_CIPHER_CTX *ctx = tempargs->ctx;
848 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
851 for (count = 0; COND(nb_iter); count++)
852 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
854 for (count = 0; COND(nb_iter); count++)
855 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
857 EVP_DecryptFinal_ex(ctx, buf, &outl);
859 EVP_EncryptFinal_ex(ctx, buf, &outl);
863 static const EVP_MD *evp_md = NULL;
864 static int EVP_Digest_loop(void *args)
866 loopargs_t *tempargs = *(loopargs_t **) args;
867 unsigned char *buf = tempargs->buf;
868 unsigned char md[EVP_MAX_MD_SIZE];
871 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
874 for (count = 0; COND(nb_iter); count++) {
875 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
881 #ifndef OPENSSL_NO_RSA
882 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
884 static int RSA_sign_loop(void *args)
886 loopargs_t *tempargs = *(loopargs_t **) args;
887 unsigned char *buf = tempargs->buf;
888 unsigned char *buf2 = tempargs->buf2;
889 unsigned int *rsa_num = &tempargs->siglen;
890 RSA **rsa_key = tempargs->rsa_key;
892 for (count = 0; COND(rsa_c[testnum][0]); count++) {
893 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
895 BIO_printf(bio_err, "RSA sign failure\n");
896 ERR_print_errors(bio_err);
904 static int RSA_verify_loop(void *args)
906 loopargs_t *tempargs = *(loopargs_t **) args;
907 unsigned char *buf = tempargs->buf;
908 unsigned char *buf2 = tempargs->buf2;
909 unsigned int rsa_num = tempargs->siglen;
910 RSA **rsa_key = tempargs->rsa_key;
912 for (count = 0; COND(rsa_c[testnum][1]); count++) {
914 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
916 BIO_printf(bio_err, "RSA verify failure\n");
917 ERR_print_errors(bio_err);
926 #ifndef OPENSSL_NO_DSA
927 static long dsa_c[DSA_NUM][2];
928 static int DSA_sign_loop(void *args)
930 loopargs_t *tempargs = *(loopargs_t **) args;
931 unsigned char *buf = tempargs->buf;
932 unsigned char *buf2 = tempargs->buf2;
933 DSA **dsa_key = tempargs->dsa_key;
934 unsigned int *siglen = &tempargs->siglen;
936 for (count = 0; COND(dsa_c[testnum][0]); count++) {
937 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
939 BIO_printf(bio_err, "DSA sign failure\n");
940 ERR_print_errors(bio_err);
948 static int DSA_verify_loop(void *args)
950 loopargs_t *tempargs = *(loopargs_t **) args;
951 unsigned char *buf = tempargs->buf;
952 unsigned char *buf2 = tempargs->buf2;
953 DSA **dsa_key = tempargs->dsa_key;
954 unsigned int siglen = tempargs->siglen;
956 for (count = 0; COND(dsa_c[testnum][1]); count++) {
957 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
959 BIO_printf(bio_err, "DSA verify failure\n");
960 ERR_print_errors(bio_err);
969 #ifndef OPENSSL_NO_EC
970 static long ecdsa_c[EC_NUM][2];
971 static int ECDSA_sign_loop(void *args)
973 loopargs_t *tempargs = *(loopargs_t **) args;
974 unsigned char *buf = tempargs->buf;
975 EC_KEY **ecdsa = tempargs->ecdsa;
976 unsigned char *ecdsasig = tempargs->buf2;
977 unsigned int *ecdsasiglen = &tempargs->siglen;
979 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
980 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
982 BIO_printf(bio_err, "ECDSA sign failure\n");
983 ERR_print_errors(bio_err);
991 static int ECDSA_verify_loop(void *args)
993 loopargs_t *tempargs = *(loopargs_t **) args;
994 unsigned char *buf = tempargs->buf;
995 EC_KEY **ecdsa = tempargs->ecdsa;
996 unsigned char *ecdsasig = tempargs->buf2;
997 unsigned int ecdsasiglen = tempargs->siglen;
999 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1000 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1002 BIO_printf(bio_err, "ECDSA verify failure\n");
1003 ERR_print_errors(bio_err);
1011 /* ******************************************************************** */
1012 static long ecdh_c[EC_NUM][1];
1014 static int ECDH_EVP_derive_key_loop(void *args)
1016 loopargs_t *tempargs = *(loopargs_t **) args;
1017 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1018 unsigned char *derived_secret = tempargs->secret_a;
1020 size_t *outlen = &(tempargs->outlen[testnum]);
1022 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1023 EVP_PKEY_derive(ctx, derived_secret, outlen);
1028 #endif /* OPENSSL_NO_EC */
1030 static int run_benchmark(int async_jobs,
1031 int (*loop_function) (void *), loopargs_t * loopargs)
1033 int job_op_count = 0;
1034 int total_op_count = 0;
1035 int num_inprogress = 0;
1036 int error = 0, i = 0, ret = 0;
1037 OSSL_ASYNC_FD job_fd = 0;
1038 size_t num_job_fds = 0;
1042 if (async_jobs == 0) {
1043 return loop_function((void *)&loopargs);
1046 for (i = 0; i < async_jobs && !error; i++) {
1047 loopargs_t *looparg_item = loopargs + i;
1049 /* Copy pointer content (looparg_t item address) into async context */
1050 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1051 &job_op_count, loop_function,
1052 (void *)&looparg_item, sizeof(looparg_item));
1058 if (job_op_count == -1) {
1061 total_op_count += job_op_count;
1066 BIO_printf(bio_err, "Failure in the job\n");
1067 ERR_print_errors(bio_err);
1073 while (num_inprogress > 0) {
1074 #if defined(OPENSSL_SYS_WINDOWS)
1076 #elif defined(OPENSSL_SYS_UNIX)
1077 int select_result = 0;
1078 OSSL_ASYNC_FD max_fd = 0;
1081 FD_ZERO(&waitfdset);
1083 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1084 if (loopargs[i].inprogress_job == NULL)
1087 if (!ASYNC_WAIT_CTX_get_all_fds
1088 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1089 || num_job_fds > 1) {
1090 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1091 ERR_print_errors(bio_err);
1095 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1097 FD_SET(job_fd, &waitfdset);
1098 if (job_fd > max_fd)
1102 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1104 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1105 "Decrease the value of async_jobs\n",
1106 max_fd, FD_SETSIZE);
1107 ERR_print_errors(bio_err);
1112 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1113 if (select_result == -1 && errno == EINTR)
1116 if (select_result == -1) {
1117 BIO_printf(bio_err, "Failure in the select\n");
1118 ERR_print_errors(bio_err);
1123 if (select_result == 0)
1127 for (i = 0; i < async_jobs; i++) {
1128 if (loopargs[i].inprogress_job == NULL)
1131 if (!ASYNC_WAIT_CTX_get_all_fds
1132 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1133 || num_job_fds > 1) {
1134 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1135 ERR_print_errors(bio_err);
1139 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1142 #if defined(OPENSSL_SYS_UNIX)
1143 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1145 #elif defined(OPENSSL_SYS_WINDOWS)
1146 if (num_job_fds == 1
1147 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1152 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1153 loopargs[i].wait_ctx, &job_op_count,
1154 loop_function, (void *)(loopargs + i),
1155 sizeof(loopargs_t));
1160 if (job_op_count == -1) {
1163 total_op_count += job_op_count;
1166 loopargs[i].inprogress_job = NULL;
1171 loopargs[i].inprogress_job = NULL;
1172 BIO_printf(bio_err, "Failure in the job\n");
1173 ERR_print_errors(bio_err);
1180 return error ? -1 : total_op_count;
1183 int speed_main(int argc, char **argv)
1186 loopargs_t *loopargs = NULL;
1188 int loopargs_len = 0;
1190 const char *engine_id = NULL;
1191 const EVP_CIPHER *evp_cipher = NULL;
1194 int multiblock = 0, pr_header = 0;
1195 int doit[ALGOR_NUM] = { 0 };
1196 int ret = 1, i, k, misalign = 0;
1201 unsigned int async_jobs = 0;
1202 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1203 || !defined(OPENSSL_NO_EC)
1207 /* What follows are the buffers and key material. */
1208 #ifndef OPENSSL_NO_RC5
1211 #ifndef OPENSSL_NO_RC2
1214 #ifndef OPENSSL_NO_IDEA
1215 IDEA_KEY_SCHEDULE idea_ks;
1217 #ifndef OPENSSL_NO_SEED
1218 SEED_KEY_SCHEDULE seed_ks;
1220 #ifndef OPENSSL_NO_BF
1223 #ifndef OPENSSL_NO_CAST
1226 static const unsigned char key16[16] = {
1227 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1228 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1230 static const unsigned char key24[24] = {
1231 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1232 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1233 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1235 static const unsigned char key32[32] = {
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,
1239 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1241 #ifndef OPENSSL_NO_CAMELLIA
1242 static const unsigned char ckey24[24] = {
1243 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1244 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1245 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1247 static const unsigned char ckey32[32] = {
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,
1251 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1253 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1255 #ifndef OPENSSL_NO_DES
1256 static DES_cblock key = {
1257 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1259 static DES_cblock key2 = {
1260 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1262 static DES_cblock key3 = {
1263 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1266 #ifndef OPENSSL_NO_RSA
1267 static const unsigned int rsa_bits[RSA_NUM] = {
1268 512, 1024, 2048, 3072, 4096, 7680, 15360
1270 static const unsigned char *rsa_data[RSA_NUM] = {
1271 test512, test1024, test2048, test3072, test4096, test7680, test15360
1273 static const int rsa_data_length[RSA_NUM] = {
1274 sizeof(test512), sizeof(test1024),
1275 sizeof(test2048), sizeof(test3072),
1276 sizeof(test4096), sizeof(test7680),
1279 int rsa_doit[RSA_NUM] = { 0 };
1281 #ifndef OPENSSL_NO_DSA
1282 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1283 int dsa_doit[DSA_NUM] = { 0 };
1285 #ifndef OPENSSL_NO_EC
1287 * We only test over the following curves as they are representative, To
1288 * add tests over more curves, simply add the curve NID and curve name to
1289 * the following arrays and increase the EC_NUM value accordingly.
1291 static const unsigned int test_curves[EC_NUM] = {
1293 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1294 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1296 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1297 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1298 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1303 static const char *test_curves_names[EC_NUM] = {
1305 "secp160r1", "nistp192", "nistp224",
1306 "nistp256", "nistp384", "nistp521",
1308 "nistk163", "nistk233", "nistk283",
1309 "nistk409", "nistk571", "nistb163",
1310 "nistb233", "nistb283", "nistb409",
1315 static const int test_curves_bits[EC_NUM] = {
1321 571, 253 /* X25519 */
1324 int ecdsa_doit[EC_NUM] = { 0 };
1325 int ecdh_doit[EC_NUM] = { 0 };
1326 #endif /* ndef OPENSSL_NO_EC */
1328 prog = opt_init(argc, argv, speed_options);
1329 while ((o = opt_next()) != OPT_EOF) {
1334 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1337 opt_help(speed_options);
1345 evp_cipher = EVP_get_cipherbyname(opt_arg());
1346 if (evp_cipher == NULL)
1347 evp_md = EVP_get_digestbyname(opt_arg());
1348 if (evp_cipher == NULL && evp_md == NULL) {
1350 "%s: %s is an unknown cipher or digest\n",
1361 * In a forked execution, an engine might need to be
1362 * initialised by each child process, not by the parent.
1363 * So store the name here and run setup_engine() later on.
1365 engine_id = opt_arg();
1369 multi = atoi(opt_arg());
1373 #ifndef OPENSSL_NO_ASYNC
1374 async_jobs = atoi(opt_arg());
1375 if (!ASYNC_is_capable()) {
1377 "%s: async_jobs specified but async not supported\n",
1381 if (async_jobs > 99999) {
1383 "%s: too many async_jobs\n",
1390 if (!opt_int(opt_arg(), &misalign))
1392 if (misalign > MISALIGN) {
1394 "%s: Maximum offset is %d\n", prog, MISALIGN);
1403 #ifdef OPENSSL_NO_MULTIBLOCK
1405 "%s: -mb specified but multi-block support is disabled\n",
1416 argc = opt_num_rest();
1419 /* Remaining arguments are algorithms. */
1420 for (; *argv; argv++) {
1421 if (found(*argv, doit_choices, &i)) {
1425 #ifndef OPENSSL_NO_DES
1426 if (strcmp(*argv, "des") == 0) {
1427 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1431 if (strcmp(*argv, "sha") == 0) {
1432 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1435 #ifndef OPENSSL_NO_RSA
1436 if (strcmp(*argv, "openssl") == 0)
1438 if (strcmp(*argv, "rsa") == 0) {
1439 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1440 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1441 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1442 rsa_doit[R_RSA_15360] = 1;
1445 if (found(*argv, rsa_choices, &i)) {
1450 #ifndef OPENSSL_NO_DSA
1451 if (strcmp(*argv, "dsa") == 0) {
1452 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1453 dsa_doit[R_DSA_2048] = 1;
1456 if (found(*argv, dsa_choices, &i)) {
1461 if (strcmp(*argv, "aes") == 0) {
1462 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1465 #ifndef OPENSSL_NO_CAMELLIA
1466 if (strcmp(*argv, "camellia") == 0) {
1467 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1471 #ifndef OPENSSL_NO_EC
1472 if (strcmp(*argv, "ecdsa") == 0) {
1473 for (i = 0; i < EC_NUM; i++)
1477 if (found(*argv, ecdsa_choices, &i)) {
1481 if (strcmp(*argv, "ecdh") == 0) {
1482 for (i = 0; i < EC_NUM; i++)
1486 if (found(*argv, ecdh_choices, &i)) {
1491 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1495 /* Initialize the job pool if async mode is enabled */
1496 if (async_jobs > 0) {
1497 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1499 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1504 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1506 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1507 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1509 for (i = 0; i < loopargs_len; i++) {
1510 if (async_jobs > 0) {
1511 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1512 if (loopargs[i].wait_ctx == NULL) {
1513 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1518 loopargs[i].buf_malloc =
1519 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1520 loopargs[i].buf2_malloc =
1521 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1522 /* Align the start of buffers on a 64 byte boundary */
1523 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1524 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1525 #ifndef OPENSSL_NO_EC
1526 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1527 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1532 if (multi && do_multi(multi))
1536 /* Initialize the engine after the fork */
1537 e = setup_engine(engine_id, 0);
1539 /* No parameters; turn on everything. */
1540 if ((argc == 0) && !doit[D_EVP]) {
1541 for (i = 0; i < ALGOR_NUM; i++)
1544 #ifndef OPENSSL_NO_RSA
1545 for (i = 0; i < RSA_NUM; i++)
1548 #ifndef OPENSSL_NO_DSA
1549 for (i = 0; i < DSA_NUM; i++)
1552 #ifndef OPENSSL_NO_EC
1553 for (i = 0; i < EC_NUM; i++)
1555 for (i = 0; i < EC_NUM; i++)
1559 for (i = 0; i < ALGOR_NUM; i++)
1563 if (usertime == 0 && !mr)
1565 "You have chosen to measure elapsed time "
1566 "instead of user CPU time.\n");
1568 #ifndef OPENSSL_NO_RSA
1569 for (i = 0; i < loopargs_len; i++) {
1570 for (k = 0; k < RSA_NUM; k++) {
1571 const unsigned char *p;
1574 loopargs[i].rsa_key[k] =
1575 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1576 if (loopargs[i].rsa_key[k] == NULL) {
1578 "internal error loading RSA key number %d\n", k);
1584 #ifndef OPENSSL_NO_DSA
1585 for (i = 0; i < loopargs_len; i++) {
1586 loopargs[i].dsa_key[0] = get_dsa(512);
1587 loopargs[i].dsa_key[1] = get_dsa(1024);
1588 loopargs[i].dsa_key[2] = get_dsa(2048);
1591 #ifndef OPENSSL_NO_DES
1592 DES_set_key_unchecked(&key, &sch);
1593 DES_set_key_unchecked(&key2, &sch2);
1594 DES_set_key_unchecked(&key3, &sch3);
1596 AES_set_encrypt_key(key16, 128, &aes_ks1);
1597 AES_set_encrypt_key(key24, 192, &aes_ks2);
1598 AES_set_encrypt_key(key32, 256, &aes_ks3);
1599 #ifndef OPENSSL_NO_CAMELLIA
1600 Camellia_set_key(key16, 128, &camellia_ks1);
1601 Camellia_set_key(ckey24, 192, &camellia_ks2);
1602 Camellia_set_key(ckey32, 256, &camellia_ks3);
1604 #ifndef OPENSSL_NO_IDEA
1605 IDEA_set_encrypt_key(key16, &idea_ks);
1607 #ifndef OPENSSL_NO_SEED
1608 SEED_set_key(key16, &seed_ks);
1610 #ifndef OPENSSL_NO_RC4
1611 RC4_set_key(&rc4_ks, 16, key16);
1613 #ifndef OPENSSL_NO_RC2
1614 RC2_set_key(&rc2_ks, 16, key16, 128);
1616 #ifndef OPENSSL_NO_RC5
1617 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1619 #ifndef OPENSSL_NO_BF
1620 BF_set_key(&bf_ks, 16, key16);
1622 #ifndef OPENSSL_NO_CAST
1623 CAST_set_key(&cast_ks, 16, key16);
1626 # ifndef OPENSSL_NO_DES
1627 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1633 for (it = count; it; it--)
1634 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1635 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1639 c[D_MD2][0] = count / 10;
1640 c[D_MDC2][0] = count / 10;
1641 c[D_MD4][0] = count;
1642 c[D_MD5][0] = count;
1643 c[D_HMAC][0] = count;
1644 c[D_SHA1][0] = count;
1645 c[D_RMD160][0] = count;
1646 c[D_RC4][0] = count * 5;
1647 c[D_CBC_DES][0] = count;
1648 c[D_EDE3_DES][0] = count / 3;
1649 c[D_CBC_IDEA][0] = count;
1650 c[D_CBC_SEED][0] = count;
1651 c[D_CBC_RC2][0] = count;
1652 c[D_CBC_RC5][0] = count;
1653 c[D_CBC_BF][0] = count;
1654 c[D_CBC_CAST][0] = count;
1655 c[D_CBC_128_AES][0] = count;
1656 c[D_CBC_192_AES][0] = count;
1657 c[D_CBC_256_AES][0] = count;
1658 c[D_CBC_128_CML][0] = count;
1659 c[D_CBC_192_CML][0] = count;
1660 c[D_CBC_256_CML][0] = count;
1661 c[D_SHA256][0] = count;
1662 c[D_SHA512][0] = count;
1663 c[D_WHIRLPOOL][0] = count;
1664 c[D_IGE_128_AES][0] = count;
1665 c[D_IGE_192_AES][0] = count;
1666 c[D_IGE_256_AES][0] = count;
1667 c[D_GHASH][0] = count;
1669 for (i = 1; i < SIZE_NUM; i++) {
1672 l0 = (long)lengths[0];
1673 l1 = (long)lengths[i];
1675 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1676 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1677 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1678 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1679 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1680 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1681 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1682 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1683 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1684 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1685 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1687 l0 = (long)lengths[i - 1];
1689 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1690 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1691 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1692 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1693 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1694 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1695 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1696 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1697 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1698 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1699 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1700 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1701 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1702 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1703 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1704 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1705 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1706 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1709 # ifndef OPENSSL_NO_RSA
1710 rsa_c[R_RSA_512][0] = count / 2000;
1711 rsa_c[R_RSA_512][1] = count / 400;
1712 for (i = 1; i < RSA_NUM; i++) {
1713 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1714 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1715 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1718 if (rsa_c[i][0] == 0) {
1719 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1726 # ifndef OPENSSL_NO_DSA
1727 dsa_c[R_DSA_512][0] = count / 1000;
1728 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1729 for (i = 1; i < DSA_NUM; i++) {
1730 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1731 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1732 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1735 if (dsa_c[i][0] == 0) {
1736 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1743 # ifndef OPENSSL_NO_EC
1744 ecdsa_c[R_EC_P160][0] = count / 1000;
1745 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1746 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1747 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1748 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1749 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1752 if (ecdsa_c[i][0] == 0) {
1758 ecdsa_c[R_EC_K163][0] = count / 1000;
1759 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1760 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1761 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1762 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1763 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1766 if (ecdsa_c[i][0] == 0) {
1772 ecdsa_c[R_EC_B163][0] = count / 1000;
1773 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1774 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1775 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1776 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1777 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1780 if (ecdsa_c[i][0] == 0) {
1787 ecdh_c[R_EC_P160][0] = count / 1000;
1788 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1789 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1790 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1793 if (ecdh_c[i][0] == 0) {
1798 ecdh_c[R_EC_K163][0] = count / 1000;
1799 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1800 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1801 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1804 if (ecdh_c[i][0] == 0) {
1809 ecdh_c[R_EC_B163][0] = count / 1000;
1810 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1811 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1812 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1815 if (ecdh_c[i][0] == 0) {
1823 /* not worth fixing */
1824 # error "You cannot disable DES on systems without SIGALRM."
1825 # endif /* OPENSSL_NO_DES */
1828 signal(SIGALRM, sig_done);
1830 #endif /* SIGALRM */
1832 #ifndef OPENSSL_NO_MD2
1834 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1835 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1837 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1839 print_result(D_MD2, testnum, count, d);
1843 #ifndef OPENSSL_NO_MDC2
1845 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1846 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1848 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1850 print_result(D_MDC2, testnum, count, d);
1855 #ifndef OPENSSL_NO_MD4
1857 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1858 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1860 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1862 print_result(D_MD4, testnum, count, d);
1867 #ifndef OPENSSL_NO_MD5
1869 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1870 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1872 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1874 print_result(D_MD5, testnum, count, d);
1879 static const char hmac_key[] = "This is a key...";
1880 int len = strlen(hmac_key);
1882 for (i = 0; i < loopargs_len; i++) {
1883 loopargs[i].hctx = HMAC_CTX_new();
1884 if (loopargs[i].hctx == NULL) {
1885 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1889 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1891 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1892 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1894 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1896 print_result(D_HMAC, testnum, count, d);
1898 for (i = 0; i < loopargs_len; i++) {
1899 HMAC_CTX_free(loopargs[i].hctx);
1904 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1905 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1907 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1909 print_result(D_SHA1, testnum, count, d);
1912 if (doit[D_SHA256]) {
1913 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1914 print_message(names[D_SHA256], c[D_SHA256][testnum],
1917 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1919 print_result(D_SHA256, testnum, count, d);
1922 if (doit[D_SHA512]) {
1923 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1924 print_message(names[D_SHA512], c[D_SHA512][testnum],
1927 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1929 print_result(D_SHA512, testnum, count, d);
1932 #ifndef OPENSSL_NO_WHIRLPOOL
1933 if (doit[D_WHIRLPOOL]) {
1934 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1935 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1938 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1940 print_result(D_WHIRLPOOL, testnum, count, d);
1945 #ifndef OPENSSL_NO_RMD160
1946 if (doit[D_RMD160]) {
1947 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1948 print_message(names[D_RMD160], c[D_RMD160][testnum],
1951 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1953 print_result(D_RMD160, testnum, count, d);
1957 #ifndef OPENSSL_NO_RC4
1959 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1960 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1962 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1964 print_result(D_RC4, testnum, count, d);
1968 #ifndef OPENSSL_NO_DES
1969 if (doit[D_CBC_DES]) {
1970 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1971 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
1974 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1976 print_result(D_CBC_DES, testnum, count, d);
1980 if (doit[D_EDE3_DES]) {
1981 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1982 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
1986 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
1988 print_result(D_EDE3_DES, testnum, count, d);
1993 if (doit[D_CBC_128_AES]) {
1994 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1995 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
1999 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2001 print_result(D_CBC_128_AES, testnum, count, d);
2004 if (doit[D_CBC_192_AES]) {
2005 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2006 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2010 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2012 print_result(D_CBC_192_AES, testnum, count, d);
2015 if (doit[D_CBC_256_AES]) {
2016 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2017 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2021 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2023 print_result(D_CBC_256_AES, testnum, count, d);
2027 if (doit[D_IGE_128_AES]) {
2028 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2029 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2033 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2035 print_result(D_IGE_128_AES, testnum, count, d);
2038 if (doit[D_IGE_192_AES]) {
2039 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2040 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2044 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2046 print_result(D_IGE_192_AES, testnum, count, d);
2049 if (doit[D_IGE_256_AES]) {
2050 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2051 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2055 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2057 print_result(D_IGE_256_AES, testnum, count, d);
2060 if (doit[D_GHASH]) {
2061 for (i = 0; i < loopargs_len; i++) {
2062 loopargs[i].gcm_ctx =
2063 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2064 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2065 (unsigned char *)"0123456789ab", 12);
2068 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2069 print_message(names[D_GHASH], c[D_GHASH][testnum],
2072 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2074 print_result(D_GHASH, testnum, count, d);
2076 for (i = 0; i < loopargs_len; i++)
2077 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2079 #ifndef OPENSSL_NO_CAMELLIA
2080 if (doit[D_CBC_128_CML]) {
2081 if (async_jobs > 0) {
2082 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2083 names[D_CBC_128_CML]);
2084 doit[D_CBC_128_CML] = 0;
2086 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2087 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2090 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2091 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2092 (size_t)lengths[testnum], &camellia_ks1,
2093 iv, CAMELLIA_ENCRYPT);
2095 print_result(D_CBC_128_CML, testnum, count, d);
2098 if (doit[D_CBC_192_CML]) {
2099 if (async_jobs > 0) {
2100 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2101 names[D_CBC_192_CML]);
2102 doit[D_CBC_192_CML] = 0;
2104 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2105 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2107 if (async_jobs > 0) {
2108 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2112 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2113 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2114 (size_t)lengths[testnum], &camellia_ks2,
2115 iv, CAMELLIA_ENCRYPT);
2117 print_result(D_CBC_192_CML, testnum, count, d);
2120 if (doit[D_CBC_256_CML]) {
2121 if (async_jobs > 0) {
2122 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2123 names[D_CBC_256_CML]);
2124 doit[D_CBC_256_CML] = 0;
2126 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2127 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2130 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2131 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2132 (size_t)lengths[testnum], &camellia_ks3,
2133 iv, CAMELLIA_ENCRYPT);
2135 print_result(D_CBC_256_CML, testnum, count, d);
2139 #ifndef OPENSSL_NO_IDEA
2140 if (doit[D_CBC_IDEA]) {
2141 if (async_jobs > 0) {
2142 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2144 doit[D_CBC_IDEA] = 0;
2146 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2147 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2150 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2151 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2152 (size_t)lengths[testnum], &idea_ks,
2155 print_result(D_CBC_IDEA, testnum, count, d);
2159 #ifndef OPENSSL_NO_SEED
2160 if (doit[D_CBC_SEED]) {
2161 if (async_jobs > 0) {
2162 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2164 doit[D_CBC_SEED] = 0;
2166 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2167 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2170 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2171 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2172 (size_t)lengths[testnum], &seed_ks, iv, 1);
2174 print_result(D_CBC_SEED, testnum, count, d);
2178 #ifndef OPENSSL_NO_RC2
2179 if (doit[D_CBC_RC2]) {
2180 if (async_jobs > 0) {
2181 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2183 doit[D_CBC_RC2] = 0;
2185 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2186 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2188 if (async_jobs > 0) {
2189 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2193 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2194 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2195 (size_t)lengths[testnum], &rc2_ks,
2198 print_result(D_CBC_RC2, testnum, count, d);
2202 #ifndef OPENSSL_NO_RC5
2203 if (doit[D_CBC_RC5]) {
2204 if (async_jobs > 0) {
2205 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2207 doit[D_CBC_RC5] = 0;
2209 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2210 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2212 if (async_jobs > 0) {
2213 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2217 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2218 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2219 (size_t)lengths[testnum], &rc5_ks,
2222 print_result(D_CBC_RC5, testnum, count, d);
2226 #ifndef OPENSSL_NO_BF
2227 if (doit[D_CBC_BF]) {
2228 if (async_jobs > 0) {
2229 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2233 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2234 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2237 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2238 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2239 (size_t)lengths[testnum], &bf_ks,
2242 print_result(D_CBC_BF, testnum, count, d);
2246 #ifndef OPENSSL_NO_CAST
2247 if (doit[D_CBC_CAST]) {
2248 if (async_jobs > 0) {
2249 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2251 doit[D_CBC_CAST] = 0;
2253 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2254 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2257 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2258 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2259 (size_t)lengths[testnum], &cast_ks,
2262 print_result(D_CBC_CAST, testnum, count, d);
2268 if (multiblock && evp_cipher) {
2270 (EVP_CIPHER_flags(evp_cipher) &
2271 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2272 BIO_printf(bio_err, "%s is not multi-block capable\n",
2273 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2276 if (async_jobs > 0) {
2277 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2280 multiblock_speed(evp_cipher);
2284 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2287 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2289 * -O3 -fschedule-insns messes up an optimization here!
2290 * names[D_EVP] somehow becomes NULL
2292 print_message(names[D_EVP], save_count, lengths[testnum]);
2294 for (k = 0; k < loopargs_len; k++) {
2295 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2297 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2300 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2302 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2306 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2308 for (k = 0; k < loopargs_len; k++) {
2309 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2313 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2314 print_message(names[D_EVP], save_count, lengths[testnum]);
2316 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2319 print_result(D_EVP, testnum, count, d);
2323 for (i = 0; i < loopargs_len; i++)
2324 RAND_bytes(loopargs[i].buf, 36);
2326 #ifndef OPENSSL_NO_RSA
2327 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2329 if (!rsa_doit[testnum])
2331 for (i = 0; i < loopargs_len; i++) {
2332 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2333 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2339 "RSA sign failure. No RSA sign will be done.\n");
2340 ERR_print_errors(bio_err);
2343 pkey_print_message("private", "rsa",
2344 rsa_c[testnum][0], rsa_bits[testnum],
2346 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2348 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2351 mr ? "+R1:%ld:%d:%.2f\n"
2352 : "%ld %d bit private RSA's in %.2fs\n",
2353 count, rsa_bits[testnum], d);
2354 rsa_results[testnum][0] = (double)count / d;
2358 for (i = 0; i < loopargs_len; i++) {
2359 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2360 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2366 "RSA verify failure. No RSA verify will be done.\n");
2367 ERR_print_errors(bio_err);
2368 rsa_doit[testnum] = 0;
2370 pkey_print_message("public", "rsa",
2371 rsa_c[testnum][1], rsa_bits[testnum],
2374 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2377 mr ? "+R2:%ld:%d:%.2f\n"
2378 : "%ld %d bit public RSA's in %.2fs\n",
2379 count, rsa_bits[testnum], d);
2380 rsa_results[testnum][1] = (double)count / d;
2383 if (rsa_count <= 1) {
2384 /* if longer than 10s, don't do any more */
2385 for (testnum++; testnum < RSA_NUM; testnum++)
2386 rsa_doit[testnum] = 0;
2389 #endif /* OPENSSL_NO_RSA */
2391 for (i = 0; i < loopargs_len; i++)
2392 RAND_bytes(loopargs[i].buf, 36);
2394 #ifndef OPENSSL_NO_DSA
2395 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2397 if (!dsa_doit[testnum])
2400 /* DSA_generate_key(dsa_key[testnum]); */
2401 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2402 for (i = 0; i < loopargs_len; i++) {
2403 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2404 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2410 "DSA sign failure. No DSA sign will be done.\n");
2411 ERR_print_errors(bio_err);
2414 pkey_print_message("sign", "dsa",
2415 dsa_c[testnum][0], dsa_bits[testnum],
2418 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2421 mr ? "+R3:%ld:%d:%.2f\n"
2422 : "%ld %d bit DSA signs in %.2fs\n",
2423 count, dsa_bits[testnum], d);
2424 dsa_results[testnum][0] = (double)count / d;
2428 for (i = 0; i < loopargs_len; i++) {
2429 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2430 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2436 "DSA verify failure. No DSA verify will be done.\n");
2437 ERR_print_errors(bio_err);
2438 dsa_doit[testnum] = 0;
2440 pkey_print_message("verify", "dsa",
2441 dsa_c[testnum][1], dsa_bits[testnum],
2444 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2447 mr ? "+R4:%ld:%d:%.2f\n"
2448 : "%ld %d bit DSA verify in %.2fs\n",
2449 count, dsa_bits[testnum], d);
2450 dsa_results[testnum][1] = (double)count / d;
2453 if (rsa_count <= 1) {
2454 /* if longer than 10s, don't do any more */
2455 for (testnum++; testnum < DSA_NUM; testnum++)
2456 dsa_doit[testnum] = 0;
2459 #endif /* OPENSSL_NO_DSA */
2461 #ifndef OPENSSL_NO_EC
2462 for (testnum = 0; testnum < EC_NUM; testnum++) {
2465 if (!ecdsa_doit[testnum])
2466 continue; /* Ignore Curve */
2467 for (i = 0; i < loopargs_len; i++) {
2468 loopargs[i].ecdsa[testnum] =
2469 EC_KEY_new_by_curve_name(test_curves[testnum]);
2470 if (loopargs[i].ecdsa[testnum] == NULL) {
2476 BIO_printf(bio_err, "ECDSA failure.\n");
2477 ERR_print_errors(bio_err);
2480 for (i = 0; i < loopargs_len; i++) {
2481 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2482 /* Perform ECDSA signature test */
2483 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2484 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2485 &loopargs[i].siglen,
2486 loopargs[i].ecdsa[testnum]);
2492 "ECDSA sign failure. No ECDSA sign will be done.\n");
2493 ERR_print_errors(bio_err);
2496 pkey_print_message("sign", "ecdsa",
2497 ecdsa_c[testnum][0],
2498 test_curves_bits[testnum], ECDSA_SECONDS);
2500 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2504 mr ? "+R5:%ld:%d:%.2f\n" :
2505 "%ld %d bit ECDSA signs in %.2fs \n",
2506 count, test_curves_bits[testnum], d);
2507 ecdsa_results[testnum][0] = (double)count / d;
2511 /* Perform ECDSA verification test */
2512 for (i = 0; i < loopargs_len; i++) {
2513 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2515 loopargs[i].ecdsa[testnum]);
2521 "ECDSA verify failure. No ECDSA verify will be done.\n");
2522 ERR_print_errors(bio_err);
2523 ecdsa_doit[testnum] = 0;
2525 pkey_print_message("verify", "ecdsa",
2526 ecdsa_c[testnum][1],
2527 test_curves_bits[testnum], ECDSA_SECONDS);
2529 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2532 mr ? "+R6:%ld:%d:%.2f\n"
2533 : "%ld %d bit ECDSA verify in %.2fs\n",
2534 count, test_curves_bits[testnum], d);
2535 ecdsa_results[testnum][1] = (double)count / d;
2538 if (rsa_count <= 1) {
2539 /* if longer than 10s, don't do any more */
2540 for (testnum++; testnum < EC_NUM; testnum++)
2541 ecdsa_doit[testnum] = 0;
2546 for (testnum = 0; testnum < EC_NUM; testnum++) {
2547 int ecdh_checks = 1;
2549 if (!ecdh_doit[testnum])
2552 for (i = 0; i < loopargs_len; i++) {
2553 EVP_PKEY_CTX *kctx = NULL;
2554 EVP_PKEY_CTX *test_ctx = NULL;
2555 EVP_PKEY_CTX *ctx = NULL;
2556 EVP_PKEY *key_A = NULL;
2557 EVP_PKEY *key_B = NULL;
2561 /* Ensure that the error queue is empty */
2562 if (ERR_peek_error()) {
2564 "WARNING: the error queue contains previous unhandled errors.\n");
2565 ERR_print_errors(bio_err);
2568 /* Let's try to create a ctx directly from the NID: this works for
2569 * curves like Curve25519 that are not implemented through the low
2570 * level EC interface.
2571 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2572 * then we set the curve by NID before deriving the actual keygen
2573 * ctx for that specific curve. */
2574 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2576 EVP_PKEY_CTX *pctx = NULL;
2577 EVP_PKEY *params = NULL;
2579 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2580 * "int_ctx_new:unsupported algorithm" error was added to the
2582 * We remove it from the error queue as we are handling it. */
2583 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2584 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2585 /* check that the error origin matches */
2586 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2587 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2588 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2589 ERR_get_error(); /* pop error from queue */
2590 if (ERR_peek_error()) {
2592 "Unhandled error in the error queue during ECDH init.\n");
2593 ERR_print_errors(bio_err);
2598 if ( /* Create the context for parameter generation */
2599 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2600 /* Initialise the parameter generation */
2601 !EVP_PKEY_paramgen_init(pctx) ||
2602 /* Set the curve by NID */
2603 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2606 /* Create the parameter object params */
2607 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2609 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2610 ERR_print_errors(bio_err);
2614 /* Create the context for the key generation */
2615 kctx = EVP_PKEY_CTX_new(params, NULL);
2617 EVP_PKEY_free(params);
2619 EVP_PKEY_CTX_free(pctx);
2622 if (kctx == NULL || /* keygen ctx is not null */
2623 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2625 BIO_printf(bio_err, "ECDH keygen failure.\n");
2626 ERR_print_errors(bio_err);
2631 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2632 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2633 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2634 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2635 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2636 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2637 outlen == 0 || /* ensure outlen is a valid size */
2638 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2640 BIO_printf(bio_err, "ECDH key generation failure.\n");
2641 ERR_print_errors(bio_err);
2646 /* Here we perform a test run, comparing the output of a*B and b*A;
2647 * we try this here and assume that further EVP_PKEY_derive calls
2648 * never fail, so we can skip checks in the actually benchmarked
2649 * code, for maximum performance. */
2650 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2651 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2652 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2653 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2654 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2655 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2656 test_outlen != outlen /* compare output length */ ) {
2658 BIO_printf(bio_err, "ECDH computation failure.\n");
2659 ERR_print_errors(bio_err);
2664 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2665 if (CRYPTO_memcmp(loopargs[i].secret_a,
2666 loopargs[i].secret_b, outlen)) {
2668 BIO_printf(bio_err, "ECDH computations don't match.\n");
2669 ERR_print_errors(bio_err);
2674 loopargs[i].ecdh_ctx[testnum] = ctx;
2675 loopargs[i].outlen[testnum] = outlen;
2677 EVP_PKEY_CTX_free(kctx);
2679 EVP_PKEY_CTX_free(test_ctx);
2682 if (ecdh_checks != 0) {
2683 pkey_print_message("", "ecdh",
2685 test_curves_bits[testnum], ECDH_SECONDS);
2688 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2691 mr ? "+R7:%ld:%d:%.2f\n" :
2692 "%ld %d-bit ECDH ops in %.2fs\n", count,
2693 test_curves_bits[testnum], d);
2694 ecdh_results[testnum][0] = (double)count / d;
2698 if (rsa_count <= 1) {
2699 /* if longer than 10s, don't do any more */
2700 for (testnum++; testnum < EC_NUM; testnum++)
2701 ecdh_doit[testnum] = 0;
2704 #endif /* OPENSSL_NO_EC */
2709 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2710 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2712 printf("%s ", BN_options());
2713 #ifndef OPENSSL_NO_MD2
2714 printf("%s ", MD2_options());
2716 #ifndef OPENSSL_NO_RC4
2717 printf("%s ", RC4_options());
2719 #ifndef OPENSSL_NO_DES
2720 printf("%s ", DES_options());
2722 printf("%s ", AES_options());
2723 #ifndef OPENSSL_NO_IDEA
2724 printf("%s ", IDEA_options());
2726 #ifndef OPENSSL_NO_BF
2727 printf("%s ", BF_options());
2729 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2737 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2740 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2741 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2745 for (k = 0; k < ALGOR_NUM; k++) {
2749 printf("+F:%d:%s", k, names[k]);
2751 printf("%-13s", names[k]);
2752 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2753 if (results[k][testnum] > 10000 && !mr)
2754 printf(" %11.2fk", results[k][testnum] / 1e3);
2756 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2760 #ifndef OPENSSL_NO_RSA
2762 for (k = 0; k < RSA_NUM; k++) {
2765 if (testnum && !mr) {
2766 printf("%18ssign verify sign/s verify/s\n", " ");
2770 printf("+F2:%u:%u:%f:%f\n",
2771 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2773 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2774 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2775 rsa_results[k][0], rsa_results[k][1]);
2778 #ifndef OPENSSL_NO_DSA
2780 for (k = 0; k < DSA_NUM; k++) {
2783 if (testnum && !mr) {
2784 printf("%18ssign verify sign/s verify/s\n", " ");
2788 printf("+F3:%u:%u:%f:%f\n",
2789 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2791 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2792 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2793 dsa_results[k][0], dsa_results[k][1]);
2796 #ifndef OPENSSL_NO_EC
2798 for (k = 0; k < EC_NUM; k++) {
2801 if (testnum && !mr) {
2802 printf("%30ssign verify sign/s verify/s\n", " ");
2807 printf("+F4:%u:%u:%f:%f\n",
2808 k, test_curves_bits[k],
2809 ecdsa_results[k][0], ecdsa_results[k][1]);
2811 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2812 test_curves_bits[k],
2813 test_curves_names[k],
2814 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2815 ecdsa_results[k][0], ecdsa_results[k][1]);
2819 for (k = 0; k < EC_NUM; k++) {
2822 if (testnum && !mr) {
2823 printf("%30sop op/s\n", " ");
2827 printf("+F5:%u:%u:%f:%f\n",
2828 k, test_curves_bits[k],
2829 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2832 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2833 test_curves_bits[k],
2834 test_curves_names[k],
2835 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2842 ERR_print_errors(bio_err);
2843 for (i = 0; i < loopargs_len; i++) {
2844 OPENSSL_free(loopargs[i].buf_malloc);
2845 OPENSSL_free(loopargs[i].buf2_malloc);
2847 #ifndef OPENSSL_NO_RSA
2848 for (k = 0; k < RSA_NUM; k++)
2849 RSA_free(loopargs[i].rsa_key[k]);
2851 #ifndef OPENSSL_NO_DSA
2852 for (k = 0; k < DSA_NUM; k++)
2853 DSA_free(loopargs[i].dsa_key[k]);
2855 #ifndef OPENSSL_NO_EC
2856 for (k = 0; k < EC_NUM; k++) {
2857 EC_KEY_free(loopargs[i].ecdsa[k]);
2858 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2860 OPENSSL_free(loopargs[i].secret_a);
2861 OPENSSL_free(loopargs[i].secret_b);
2865 if (async_jobs > 0) {
2866 for (i = 0; i < loopargs_len; i++)
2867 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2871 ASYNC_cleanup_thread();
2873 OPENSSL_free(loopargs);
2878 static void print_message(const char *s, long num, int length)
2882 mr ? "+DT:%s:%d:%d\n"
2883 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2884 (void)BIO_flush(bio_err);
2888 mr ? "+DN:%s:%ld:%d\n"
2889 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2890 (void)BIO_flush(bio_err);
2894 static void pkey_print_message(const char *str, const char *str2, long num,
2899 mr ? "+DTP:%d:%s:%s:%d\n"
2900 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2901 (void)BIO_flush(bio_err);
2905 mr ? "+DNP:%ld:%d:%s:%s\n"
2906 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2907 (void)BIO_flush(bio_err);
2911 static void print_result(int alg, int run_no, int count, double time_used)
2914 BIO_puts(bio_err, "EVP error!\n");
2918 mr ? "+R:%d:%s:%f\n"
2919 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2920 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2924 static char *sstrsep(char **string, const char *delim)
2927 char *token = *string;
2932 memset(isdelim, 0, sizeof isdelim);
2936 isdelim[(unsigned char)(*delim)] = 1;
2940 while (!isdelim[(unsigned char)(**string)]) {
2952 static int do_multi(int multi)
2957 static char sep[] = ":";
2959 fds = malloc(sizeof(*fds) * multi);
2960 for (n = 0; n < multi; ++n) {
2961 if (pipe(fd) == -1) {
2962 BIO_printf(bio_err, "pipe failure\n");
2966 (void)BIO_flush(bio_err);
2973 if (dup(fd[1]) == -1) {
2974 BIO_printf(bio_err, "dup failed\n");
2983 printf("Forked child %d\n", n);
2986 /* for now, assume the pipe is long enough to take all the output */
2987 for (n = 0; n < multi; ++n) {
2992 f = fdopen(fds[n], "r");
2993 while (fgets(buf, sizeof buf, f)) {
2994 p = strchr(buf, '\n');
2997 if (buf[0] != '+') {
2999 "Don't understand line '%s' from child %d\n", buf,
3003 printf("Got: %s from %d\n", buf, n);
3004 if (strncmp(buf, "+F:", 3) == 0) {
3009 alg = atoi(sstrsep(&p, sep));
3011 for (j = 0; j < SIZE_NUM; ++j)
3012 results[alg][j] += atof(sstrsep(&p, sep));
3013 } else if (strncmp(buf, "+F2:", 4) == 0) {
3018 k = atoi(sstrsep(&p, sep));
3021 d = atof(sstrsep(&p, sep));
3022 rsa_results[k][0] += d;
3024 d = atof(sstrsep(&p, sep));
3025 rsa_results[k][1] += d;
3027 # ifndef OPENSSL_NO_DSA
3028 else if (strncmp(buf, "+F3:", 4) == 0) {
3033 k = atoi(sstrsep(&p, sep));
3036 d = atof(sstrsep(&p, sep));
3037 dsa_results[k][0] += d;
3039 d = atof(sstrsep(&p, sep));
3040 dsa_results[k][1] += d;
3043 # ifndef OPENSSL_NO_EC
3044 else if (strncmp(buf, "+F4:", 4) == 0) {
3049 k = atoi(sstrsep(&p, sep));
3052 d = atof(sstrsep(&p, sep));
3053 ecdsa_results[k][0] += d;
3055 d = atof(sstrsep(&p, sep));
3056 ecdsa_results[k][1] += d;
3057 } else if (strncmp(buf, "+F5:", 4) == 0) {
3062 k = atoi(sstrsep(&p, sep));
3065 d = atof(sstrsep(&p, sep));
3066 ecdh_results[k][0] += d;
3070 else if (strncmp(buf, "+H:", 3) == 0) {
3073 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3084 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3086 static int mblengths[] =
3087 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3088 int j, count, num = OSSL_NELEM(mblengths);
3089 const char *alg_name;
3090 unsigned char *inp, *out, no_key[32], no_iv[16];
3091 EVP_CIPHER_CTX *ctx;
3094 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3095 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3096 ctx = EVP_CIPHER_CTX_new();
3097 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3098 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3099 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3101 for (j = 0; j < num; j++) {
3102 print_message(alg_name, 0, mblengths[j]);
3104 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3105 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3106 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3107 size_t len = mblengths[j];
3110 memset(aad, 0, 8); /* avoid uninitialized values */
3111 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3112 aad[9] = 3; /* version */
3114 aad[11] = 0; /* length */
3116 mb_param.out = NULL;
3119 mb_param.interleave = 8;
3121 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3122 sizeof(mb_param), &mb_param);
3128 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3129 sizeof(mb_param), &mb_param);
3133 RAND_bytes(out, 16);
3137 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3138 EVP_AEAD_TLS1_AAD_LEN, aad);
3139 EVP_Cipher(ctx, out, inp, len + pad);
3143 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3144 : "%d %s's in %.2fs\n", count, "evp", d);
3145 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3149 fprintf(stdout, "+H");
3150 for (j = 0; j < num; j++)
3151 fprintf(stdout, ":%d", mblengths[j]);
3152 fprintf(stdout, "\n");
3153 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3154 for (j = 0; j < num; j++)
3155 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3156 fprintf(stdout, "\n");
3159 "The 'numbers' are in 1000s of bytes per second processed.\n");
3160 fprintf(stdout, "type ");
3161 for (j = 0; j < num; j++)
3162 fprintf(stdout, "%7d bytes", mblengths[j]);
3163 fprintf(stdout, "\n");
3164 fprintf(stdout, "%-24s", alg_name);
3166 for (j = 0; j < num; j++) {
3167 if (results[D_EVP][j] > 10000)
3168 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3170 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3172 fprintf(stdout, "\n");
3177 EVP_CIPHER_CTX_free(ctx);