2 * Copyright 1995-2018 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 RSA_SECONDS 10
14 #define DSA_SECONDS 10
15 #define ECDSA_SECONDS 10
16 #define ECDH_SECONDS 10
17 #define EdDSA_SECONDS 10
25 #include <openssl/crypto.h>
26 #include <openssl/rand.h>
27 #include <openssl/err.h>
28 #include <openssl/evp.h>
29 #include <openssl/objects.h>
30 #include <openssl/async.h>
31 #if !defined(OPENSSL_SYS_MSDOS)
32 # include OPENSSL_UNISTD
39 #include <openssl/bn.h>
40 #ifndef OPENSSL_NO_DES
41 # include <openssl/des.h>
43 #include <openssl/aes.h>
44 #ifndef OPENSSL_NO_CAMELLIA
45 # include <openssl/camellia.h>
47 #ifndef OPENSSL_NO_MD2
48 # include <openssl/md2.h>
50 #ifndef OPENSSL_NO_MDC2
51 # include <openssl/mdc2.h>
53 #ifndef OPENSSL_NO_MD4
54 # include <openssl/md4.h>
56 #ifndef OPENSSL_NO_MD5
57 # include <openssl/md5.h>
59 #include <openssl/hmac.h>
60 #include <openssl/sha.h>
61 #ifndef OPENSSL_NO_RMD160
62 # include <openssl/ripemd.h>
64 #ifndef OPENSSL_NO_WHIRLPOOL
65 # include <openssl/whrlpool.h>
67 #ifndef OPENSSL_NO_RC4
68 # include <openssl/rc4.h>
70 #ifndef OPENSSL_NO_RC5
71 # include <openssl/rc5.h>
73 #ifndef OPENSSL_NO_RC2
74 # include <openssl/rc2.h>
76 #ifndef OPENSSL_NO_IDEA
77 # include <openssl/idea.h>
79 #ifndef OPENSSL_NO_SEED
80 # include <openssl/seed.h>
83 # include <openssl/blowfish.h>
85 #ifndef OPENSSL_NO_CAST
86 # include <openssl/cast.h>
88 #ifndef OPENSSL_NO_RSA
89 # include <openssl/rsa.h>
90 # include "./testrsa.h"
92 #include <openssl/x509.h>
93 #ifndef OPENSSL_NO_DSA
94 # include <openssl/dsa.h>
95 # include "./testdsa.h"
98 # include <openssl/ec.h>
100 #include <openssl/modes.h>
103 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
116 #define MAX_MISALIGNMENT 63
117 #define MAX_ECDH_SIZE 256
120 typedef struct openssl_speed_sec_st {
127 } openssl_speed_sec_t;
129 static volatile int run = 0;
132 static int usertime = 1;
134 #ifndef OPENSSL_NO_MD2
135 static int EVP_Digest_MD2_loop(void *args);
138 #ifndef OPENSSL_NO_MDC2
139 static int EVP_Digest_MDC2_loop(void *args);
141 #ifndef OPENSSL_NO_MD4
142 static int EVP_Digest_MD4_loop(void *args);
144 #ifndef OPENSSL_NO_MD5
145 static int MD5_loop(void *args);
146 static int HMAC_loop(void *args);
148 static int SHA1_loop(void *args);
149 static int SHA256_loop(void *args);
150 static int SHA512_loop(void *args);
151 #ifndef OPENSSL_NO_WHIRLPOOL
152 static int WHIRLPOOL_loop(void *args);
154 #ifndef OPENSSL_NO_RMD160
155 static int EVP_Digest_RMD160_loop(void *args);
157 #ifndef OPENSSL_NO_RC4
158 static int RC4_loop(void *args);
160 #ifndef OPENSSL_NO_DES
161 static int DES_ncbc_encrypt_loop(void *args);
162 static int DES_ede3_cbc_encrypt_loop(void *args);
164 static int AES_cbc_128_encrypt_loop(void *args);
165 static int AES_cbc_192_encrypt_loop(void *args);
166 static int AES_ige_128_encrypt_loop(void *args);
167 static int AES_cbc_256_encrypt_loop(void *args);
168 static int AES_ige_192_encrypt_loop(void *args);
169 static int AES_ige_256_encrypt_loop(void *args);
170 static int CRYPTO_gcm128_aad_loop(void *args);
171 static int RAND_bytes_loop(void *args);
172 static int EVP_Update_loop(void *args);
173 static int EVP_Update_loop_ccm(void *args);
174 static int EVP_Update_loop_aead(void *args);
175 static int EVP_Digest_loop(void *args);
176 #ifndef OPENSSL_NO_RSA
177 static int RSA_sign_loop(void *args);
178 static int RSA_verify_loop(void *args);
180 #ifndef OPENSSL_NO_DSA
181 static int DSA_sign_loop(void *args);
182 static int DSA_verify_loop(void *args);
184 #ifndef OPENSSL_NO_EC
185 static int ECDSA_sign_loop(void *args);
186 static int ECDSA_verify_loop(void *args);
187 static int EdDSA_sign_loop(void *args);
188 static int EdDSA_verify_loop(void *args);
191 static double Time_F(int s);
192 static void print_message(const char *s, long num, int length, int tm);
193 static void pkey_print_message(const char *str, const char *str2,
194 long num, unsigned int bits, int sec);
195 static void print_result(int alg, int run_no, int count, double time_used);
197 static int do_multi(int multi, int size_num);
200 static const int lengths_list[] = {
201 16, 64, 256, 1024, 8 * 1024, 16 * 1024
203 static const int *lengths = lengths_list;
205 static const int aead_lengths_list[] = {
206 2, 31, 136, 1024, 8 * 1024, 16 * 1024
214 static void alarmed(int sig)
216 signal(SIGALRM, alarmed);
220 static double Time_F(int s)
222 double ret = app_tminterval(s, usertime);
228 #elif defined(_WIN32)
232 static unsigned int lapse;
233 static volatile unsigned int schlock;
234 static void alarm_win32(unsigned int secs)
239 # define alarm alarm_win32
241 static DWORD WINAPI sleepy(VOID * arg)
249 static double Time_F(int s)
256 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
258 DWORD err = GetLastError();
259 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
263 Sleep(0); /* scheduler spinlock */
264 ret = app_tminterval(s, usertime);
266 ret = app_tminterval(s, usertime);
268 TerminateThread(thr, 0);
275 static double Time_F(int s)
277 return app_tminterval(s, usertime);
281 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
282 const openssl_speed_sec_t *seconds);
284 #define found(value, pairs, result)\
285 opt_found(value, result, pairs, OSSL_NELEM(pairs))
286 static int opt_found(const char *name, unsigned int *result,
287 const OPT_PAIR pairs[], unsigned int nbelem)
291 for (idx = 0; idx < nbelem; ++idx, pairs++)
292 if (strcmp(name, pairs->name) == 0) {
293 *result = pairs->retval;
299 typedef enum OPTION_choice {
300 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
301 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
302 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
303 OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD
306 const OPTIONS speed_options[] = {
307 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
308 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
309 {"help", OPT_HELP, '-', "Display this summary"},
310 {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
311 {"decrypt", OPT_DECRYPT, '-',
312 "Time decryption instead of encryption (only EVP)"},
313 {"aead", OPT_AEAD, '-',
314 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
316 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
317 {"mr", OPT_MR, '-', "Produce machine readable output"},
319 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
321 #ifndef OPENSSL_NO_ASYNC
322 {"async_jobs", OPT_ASYNCJOBS, 'p',
323 "Enable async mode and start specified number of jobs"},
326 #ifndef OPENSSL_NO_ENGINE
327 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
329 {"elapsed", OPT_ELAPSED, '-',
330 "Use wall-clock time instead of CPU user time as divisor"},
331 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
332 {"seconds", OPT_SECONDS, 'p',
333 "Run benchmarks for specified amount of seconds"},
334 {"bytes", OPT_BYTES, 'p',
335 "Run [non-PKI] benchmarks on custom-sized buffer"},
336 {"misalign", OPT_MISALIGN, 'p',
337 "Use specified offset to mis-align buffers"},
351 #define D_CBC_IDEA 10
352 #define D_CBC_SEED 11
356 #define D_CBC_CAST 15
357 #define D_CBC_128_AES 16
358 #define D_CBC_192_AES 17
359 #define D_CBC_256_AES 18
360 #define D_CBC_128_CML 19
361 #define D_CBC_192_CML 20
362 #define D_CBC_256_CML 21
366 #define D_WHIRLPOOL 25
367 #define D_IGE_128_AES 26
368 #define D_IGE_192_AES 27
369 #define D_IGE_256_AES 28
372 /* name of algorithms to test */
373 static const char *names[] = {
374 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
375 "des cbc", "des ede3", "idea cbc", "seed cbc",
376 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
377 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
378 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
379 "evp", "sha256", "sha512", "whirlpool",
380 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
383 #define ALGOR_NUM OSSL_NELEM(names)
385 /* list of configured algorithm (remaining) */
386 static const OPT_PAIR doit_choices[] = {
387 #ifndef OPENSSL_NO_MD2
390 #ifndef OPENSSL_NO_MDC2
393 #ifndef OPENSSL_NO_MD4
396 #ifndef OPENSSL_NO_MD5
401 {"sha256", D_SHA256},
402 {"sha512", D_SHA512},
403 #ifndef OPENSSL_NO_WHIRLPOOL
404 {"whirlpool", D_WHIRLPOOL},
406 #ifndef OPENSSL_NO_RMD160
407 {"ripemd", D_RMD160},
408 {"rmd160", D_RMD160},
409 {"ripemd160", D_RMD160},
411 #ifndef OPENSSL_NO_RC4
414 #ifndef OPENSSL_NO_DES
415 {"des-cbc", D_CBC_DES},
416 {"des-ede3", D_EDE3_DES},
418 {"aes-128-cbc", D_CBC_128_AES},
419 {"aes-192-cbc", D_CBC_192_AES},
420 {"aes-256-cbc", D_CBC_256_AES},
421 {"aes-128-ige", D_IGE_128_AES},
422 {"aes-192-ige", D_IGE_192_AES},
423 {"aes-256-ige", D_IGE_256_AES},
424 #ifndef OPENSSL_NO_RC2
425 {"rc2-cbc", D_CBC_RC2},
428 #ifndef OPENSSL_NO_RC5
429 {"rc5-cbc", D_CBC_RC5},
432 #ifndef OPENSSL_NO_IDEA
433 {"idea-cbc", D_CBC_IDEA},
434 {"idea", D_CBC_IDEA},
436 #ifndef OPENSSL_NO_SEED
437 {"seed-cbc", D_CBC_SEED},
438 {"seed", D_CBC_SEED},
440 #ifndef OPENSSL_NO_BF
441 {"bf-cbc", D_CBC_BF},
442 {"blowfish", D_CBC_BF},
445 #ifndef OPENSSL_NO_CAST
446 {"cast-cbc", D_CBC_CAST},
447 {"cast", D_CBC_CAST},
448 {"cast5", D_CBC_CAST},
454 static double results[ALGOR_NUM][OSSL_NELEM(lengths_list)];
456 #ifndef OPENSSL_NO_DSA
458 # define R_DSA_1024 1
459 # define R_DSA_2048 2
460 static const OPT_PAIR dsa_choices[] = {
461 {"dsa512", R_DSA_512},
462 {"dsa1024", R_DSA_1024},
463 {"dsa2048", R_DSA_2048}
465 # define DSA_NUM OSSL_NELEM(dsa_choices)
467 static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
468 #endif /* OPENSSL_NO_DSA */
476 #define R_RSA_15360 6
477 #ifndef OPENSSL_NO_RSA
478 static const OPT_PAIR rsa_choices[] = {
479 {"rsa512", R_RSA_512},
480 {"rsa1024", R_RSA_1024},
481 {"rsa2048", R_RSA_2048},
482 {"rsa3072", R_RSA_3072},
483 {"rsa4096", R_RSA_4096},
484 {"rsa7680", R_RSA_7680},
485 {"rsa15360", R_RSA_15360}
487 # define RSA_NUM OSSL_NELEM(rsa_choices)
489 static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
490 #endif /* OPENSSL_NO_RSA */
508 #define R_EC_BRP256R1 16
509 #define R_EC_BRP256T1 17
510 #define R_EC_BRP384R1 18
511 #define R_EC_BRP384T1 19
512 #define R_EC_BRP512R1 20
513 #define R_EC_BRP512T1 21
514 #define R_EC_X25519 22
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},
534 {"ecdsabrp256r1", R_EC_BRP256R1},
535 {"ecdsabrp256t1", R_EC_BRP256T1},
536 {"ecdsabrp384r1", R_EC_BRP384R1},
537 {"ecdsabrp384t1", R_EC_BRP384T1},
538 {"ecdsabrp512r1", R_EC_BRP512R1},
539 {"ecdsabrp512t1", R_EC_BRP512T1}
541 # define ECDSA_NUM OSSL_NELEM(ecdsa_choices)
543 static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
545 static const OPT_PAIR ecdh_choices[] = {
546 {"ecdhp160", R_EC_P160},
547 {"ecdhp192", R_EC_P192},
548 {"ecdhp224", R_EC_P224},
549 {"ecdhp256", R_EC_P256},
550 {"ecdhp384", R_EC_P384},
551 {"ecdhp521", R_EC_P521},
552 {"ecdhk163", R_EC_K163},
553 {"ecdhk233", R_EC_K233},
554 {"ecdhk283", R_EC_K283},
555 {"ecdhk409", R_EC_K409},
556 {"ecdhk571", R_EC_K571},
557 {"ecdhb163", R_EC_B163},
558 {"ecdhb233", R_EC_B233},
559 {"ecdhb283", R_EC_B283},
560 {"ecdhb409", R_EC_B409},
561 {"ecdhb571", R_EC_B571},
562 {"ecdhbrp256r1", R_EC_BRP256R1},
563 {"ecdhbrp256t1", R_EC_BRP256T1},
564 {"ecdhbrp384r1", R_EC_BRP384R1},
565 {"ecdhbrp384t1", R_EC_BRP384T1},
566 {"ecdhbrp512r1", R_EC_BRP512R1},
567 {"ecdhbrp512t1", R_EC_BRP512T1},
568 {"ecdhx25519", R_EC_X25519},
569 {"ecdhx448", R_EC_X448}
571 # define EC_NUM OSSL_NELEM(ecdh_choices)
573 static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
575 #define R_EC_Ed25519 0
577 static OPT_PAIR eddsa_choices[] = {
578 {"ed25519", R_EC_Ed25519},
579 {"ed448", R_EC_Ed448}
581 # define EdDSA_NUM OSSL_NELEM(eddsa_choices)
583 static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
584 #endif /* OPENSSL_NO_EC */
587 # define COND(d) (count < (d))
588 # define COUNT(d) (d)
590 # define COND(unused_cond) (run && count<0x7fffffff)
591 # define COUNT(d) (count)
594 typedef struct loopargs_st {
595 ASYNC_JOB *inprogress_job;
596 ASYNC_WAIT_CTX *wait_ctx;
599 unsigned char *buf_malloc;
600 unsigned char *buf2_malloc;
603 #ifndef OPENSSL_NO_RSA
604 RSA *rsa_key[RSA_NUM];
606 #ifndef OPENSSL_NO_DSA
607 DSA *dsa_key[DSA_NUM];
609 #ifndef OPENSSL_NO_EC
610 EC_KEY *ecdsa[ECDSA_NUM];
611 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
612 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
613 unsigned char *secret_a;
614 unsigned char *secret_b;
615 size_t outlen[EC_NUM];
619 GCM128_CONTEXT *gcm_ctx;
621 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
622 loopargs_t * loopargs);
624 static unsigned int testnum;
626 /* Nb of iterations to do per algorithm and key-size */
627 static long c[ALGOR_NUM][OSSL_NELEM(lengths_list)];
629 #ifndef OPENSSL_NO_MD2
630 static int EVP_Digest_MD2_loop(void *args)
632 loopargs_t *tempargs = *(loopargs_t **) args;
633 unsigned char *buf = tempargs->buf;
634 unsigned char md2[MD2_DIGEST_LENGTH];
637 for (count = 0; COND(c[D_MD2][testnum]); count++) {
638 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
646 #ifndef OPENSSL_NO_MDC2
647 static int EVP_Digest_MDC2_loop(void *args)
649 loopargs_t *tempargs = *(loopargs_t **) args;
650 unsigned char *buf = tempargs->buf;
651 unsigned char mdc2[MDC2_DIGEST_LENGTH];
654 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
655 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
663 #ifndef OPENSSL_NO_MD4
664 static int EVP_Digest_MD4_loop(void *args)
666 loopargs_t *tempargs = *(loopargs_t **) args;
667 unsigned char *buf = tempargs->buf;
668 unsigned char md4[MD4_DIGEST_LENGTH];
671 for (count = 0; COND(c[D_MD4][testnum]); count++) {
672 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
680 #ifndef OPENSSL_NO_MD5
681 static int MD5_loop(void *args)
683 loopargs_t *tempargs = *(loopargs_t **) args;
684 unsigned char *buf = tempargs->buf;
685 unsigned char md5[MD5_DIGEST_LENGTH];
687 for (count = 0; COND(c[D_MD5][testnum]); count++)
688 MD5(buf, lengths[testnum], md5);
692 static int HMAC_loop(void *args)
694 loopargs_t *tempargs = *(loopargs_t **) args;
695 unsigned char *buf = tempargs->buf;
696 HMAC_CTX *hctx = tempargs->hctx;
697 unsigned char hmac[MD5_DIGEST_LENGTH];
700 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
701 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
702 HMAC_Update(hctx, buf, lengths[testnum]);
703 HMAC_Final(hctx, hmac, NULL);
709 static int SHA1_loop(void *args)
711 loopargs_t *tempargs = *(loopargs_t **) args;
712 unsigned char *buf = tempargs->buf;
713 unsigned char sha[SHA_DIGEST_LENGTH];
715 for (count = 0; COND(c[D_SHA1][testnum]); count++)
716 SHA1(buf, lengths[testnum], sha);
720 static int SHA256_loop(void *args)
722 loopargs_t *tempargs = *(loopargs_t **) args;
723 unsigned char *buf = tempargs->buf;
724 unsigned char sha256[SHA256_DIGEST_LENGTH];
726 for (count = 0; COND(c[D_SHA256][testnum]); count++)
727 SHA256(buf, lengths[testnum], sha256);
731 static int SHA512_loop(void *args)
733 loopargs_t *tempargs = *(loopargs_t **) args;
734 unsigned char *buf = tempargs->buf;
735 unsigned char sha512[SHA512_DIGEST_LENGTH];
737 for (count = 0; COND(c[D_SHA512][testnum]); count++)
738 SHA512(buf, lengths[testnum], sha512);
742 #ifndef OPENSSL_NO_WHIRLPOOL
743 static int WHIRLPOOL_loop(void *args)
745 loopargs_t *tempargs = *(loopargs_t **) args;
746 unsigned char *buf = tempargs->buf;
747 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
749 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
750 WHIRLPOOL(buf, lengths[testnum], whirlpool);
755 #ifndef OPENSSL_NO_RMD160
756 static int EVP_Digest_RMD160_loop(void *args)
758 loopargs_t *tempargs = *(loopargs_t **) args;
759 unsigned char *buf = tempargs->buf;
760 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
762 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
763 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
764 NULL, EVP_ripemd160(), NULL))
771 #ifndef OPENSSL_NO_RC4
772 static RC4_KEY rc4_ks;
773 static int RC4_loop(void *args)
775 loopargs_t *tempargs = *(loopargs_t **) args;
776 unsigned char *buf = tempargs->buf;
778 for (count = 0; COND(c[D_RC4][testnum]); count++)
779 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
784 #ifndef OPENSSL_NO_DES
785 static unsigned char DES_iv[8];
786 static DES_key_schedule sch;
787 static DES_key_schedule sch2;
788 static DES_key_schedule sch3;
789 static int DES_ncbc_encrypt_loop(void *args)
791 loopargs_t *tempargs = *(loopargs_t **) args;
792 unsigned char *buf = tempargs->buf;
794 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
795 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
796 &DES_iv, DES_ENCRYPT);
800 static int DES_ede3_cbc_encrypt_loop(void *args)
802 loopargs_t *tempargs = *(loopargs_t **) args;
803 unsigned char *buf = tempargs->buf;
805 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
806 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
807 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
812 #define MAX_BLOCK_SIZE 128
814 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
815 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
816 static int AES_cbc_128_encrypt_loop(void *args)
818 loopargs_t *tempargs = *(loopargs_t **) args;
819 unsigned char *buf = tempargs->buf;
821 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
822 AES_cbc_encrypt(buf, buf,
823 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
827 static int AES_cbc_192_encrypt_loop(void *args)
829 loopargs_t *tempargs = *(loopargs_t **) args;
830 unsigned char *buf = tempargs->buf;
832 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
833 AES_cbc_encrypt(buf, buf,
834 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
838 static int AES_cbc_256_encrypt_loop(void *args)
840 loopargs_t *tempargs = *(loopargs_t **) args;
841 unsigned char *buf = tempargs->buf;
843 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
844 AES_cbc_encrypt(buf, buf,
845 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
849 static int AES_ige_128_encrypt_loop(void *args)
851 loopargs_t *tempargs = *(loopargs_t **) args;
852 unsigned char *buf = tempargs->buf;
853 unsigned char *buf2 = tempargs->buf2;
855 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
856 AES_ige_encrypt(buf, buf2,
857 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
861 static int AES_ige_192_encrypt_loop(void *args)
863 loopargs_t *tempargs = *(loopargs_t **) args;
864 unsigned char *buf = tempargs->buf;
865 unsigned char *buf2 = tempargs->buf2;
867 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
868 AES_ige_encrypt(buf, buf2,
869 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
873 static int AES_ige_256_encrypt_loop(void *args)
875 loopargs_t *tempargs = *(loopargs_t **) args;
876 unsigned char *buf = tempargs->buf;
877 unsigned char *buf2 = tempargs->buf2;
879 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
880 AES_ige_encrypt(buf, buf2,
881 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
885 static int CRYPTO_gcm128_aad_loop(void *args)
887 loopargs_t *tempargs = *(loopargs_t **) args;
888 unsigned char *buf = tempargs->buf;
889 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
891 for (count = 0; COND(c[D_GHASH][testnum]); count++)
892 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
896 static int RAND_bytes_loop(void *args)
898 loopargs_t *tempargs = *(loopargs_t **) args;
899 unsigned char *buf = tempargs->buf;
902 for (count = 0; COND(c[D_RAND][testnum]); count++)
903 RAND_bytes(buf, lengths[testnum]);
907 static long save_count = 0;
908 static int decrypt = 0;
909 static int EVP_Update_loop(void *args)
911 loopargs_t *tempargs = *(loopargs_t **) args;
912 unsigned char *buf = tempargs->buf;
913 EVP_CIPHER_CTX *ctx = tempargs->ctx;
916 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
919 for (count = 0; COND(nb_iter); count++) {
920 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
922 /* reset iv in case of counter overflow */
923 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
927 for (count = 0; COND(nb_iter); count++) {
928 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
930 /* reset iv in case of counter overflow */
931 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
936 EVP_DecryptFinal_ex(ctx, buf, &outl);
938 EVP_EncryptFinal_ex(ctx, buf, &outl);
943 * CCM does not support streaming. For the purpose of performance measurement,
944 * each message is encrypted using the same (key,iv)-pair. Do not use this
945 * code in your application.
947 static int EVP_Update_loop_ccm(void *args)
949 loopargs_t *tempargs = *(loopargs_t **) args;
950 unsigned char *buf = tempargs->buf;
951 EVP_CIPHER_CTX *ctx = tempargs->ctx;
953 unsigned char tag[12];
955 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
958 for (count = 0; COND(nb_iter); count++) {
959 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
961 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
962 /* counter is reset on every update */
963 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
966 for (count = 0; COND(nb_iter); count++) {
967 /* restore iv length field */
968 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
969 /* counter is reset on every update */
970 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
974 EVP_DecryptFinal_ex(ctx, buf, &outl);
976 EVP_EncryptFinal_ex(ctx, buf, &outl);
981 * To make AEAD benchmarking more relevant perform TLS-like operations,
982 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
983 * payload length is not actually limited by 16KB...
985 static int EVP_Update_loop_aead(void *args)
987 loopargs_t *tempargs = *(loopargs_t **) args;
988 unsigned char *buf = tempargs->buf;
989 EVP_CIPHER_CTX *ctx = tempargs->ctx;
991 unsigned char aad[13] = { 0xcc };
992 unsigned char faketag[16] = { 0xcc };
994 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
997 for (count = 0; COND(nb_iter); count++) {
998 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
999 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
1000 sizeof(faketag), faketag);
1001 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1002 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1003 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
1006 for (count = 0; COND(nb_iter); count++) {
1007 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
1008 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1009 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1010 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
1016 static const EVP_MD *evp_md = NULL;
1017 static int EVP_Digest_loop(void *args)
1019 loopargs_t *tempargs = *(loopargs_t **) args;
1020 unsigned char *buf = tempargs->buf;
1021 unsigned char md[EVP_MAX_MD_SIZE];
1024 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1027 for (count = 0; COND(nb_iter); count++) {
1028 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
1034 #ifndef OPENSSL_NO_RSA
1035 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1037 static int RSA_sign_loop(void *args)
1039 loopargs_t *tempargs = *(loopargs_t **) args;
1040 unsigned char *buf = tempargs->buf;
1041 unsigned char *buf2 = tempargs->buf2;
1042 unsigned int *rsa_num = &tempargs->siglen;
1043 RSA **rsa_key = tempargs->rsa_key;
1045 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1046 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1048 BIO_printf(bio_err, "RSA sign failure\n");
1049 ERR_print_errors(bio_err);
1057 static int RSA_verify_loop(void *args)
1059 loopargs_t *tempargs = *(loopargs_t **) args;
1060 unsigned char *buf = tempargs->buf;
1061 unsigned char *buf2 = tempargs->buf2;
1062 unsigned int rsa_num = tempargs->siglen;
1063 RSA **rsa_key = tempargs->rsa_key;
1065 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1067 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1069 BIO_printf(bio_err, "RSA verify failure\n");
1070 ERR_print_errors(bio_err);
1079 #ifndef OPENSSL_NO_DSA
1080 static long dsa_c[DSA_NUM][2];
1081 static int DSA_sign_loop(void *args)
1083 loopargs_t *tempargs = *(loopargs_t **) args;
1084 unsigned char *buf = tempargs->buf;
1085 unsigned char *buf2 = tempargs->buf2;
1086 DSA **dsa_key = tempargs->dsa_key;
1087 unsigned int *siglen = &tempargs->siglen;
1089 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1090 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1092 BIO_printf(bio_err, "DSA sign failure\n");
1093 ERR_print_errors(bio_err);
1101 static int DSA_verify_loop(void *args)
1103 loopargs_t *tempargs = *(loopargs_t **) args;
1104 unsigned char *buf = tempargs->buf;
1105 unsigned char *buf2 = tempargs->buf2;
1106 DSA **dsa_key = tempargs->dsa_key;
1107 unsigned int siglen = tempargs->siglen;
1109 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1110 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1112 BIO_printf(bio_err, "DSA verify failure\n");
1113 ERR_print_errors(bio_err);
1122 #ifndef OPENSSL_NO_EC
1123 static long ecdsa_c[ECDSA_NUM][2];
1124 static int ECDSA_sign_loop(void *args)
1126 loopargs_t *tempargs = *(loopargs_t **) args;
1127 unsigned char *buf = tempargs->buf;
1128 EC_KEY **ecdsa = tempargs->ecdsa;
1129 unsigned char *ecdsasig = tempargs->buf2;
1130 unsigned int *ecdsasiglen = &tempargs->siglen;
1132 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1133 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1135 BIO_printf(bio_err, "ECDSA sign failure\n");
1136 ERR_print_errors(bio_err);
1144 static int ECDSA_verify_loop(void *args)
1146 loopargs_t *tempargs = *(loopargs_t **) args;
1147 unsigned char *buf = tempargs->buf;
1148 EC_KEY **ecdsa = tempargs->ecdsa;
1149 unsigned char *ecdsasig = tempargs->buf2;
1150 unsigned int ecdsasiglen = tempargs->siglen;
1152 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1153 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1155 BIO_printf(bio_err, "ECDSA verify failure\n");
1156 ERR_print_errors(bio_err);
1164 /* ******************************************************************** */
1165 static long ecdh_c[EC_NUM][1];
1167 static int ECDH_EVP_derive_key_loop(void *args)
1169 loopargs_t *tempargs = *(loopargs_t **) args;
1170 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1171 unsigned char *derived_secret = tempargs->secret_a;
1173 size_t *outlen = &(tempargs->outlen[testnum]);
1175 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1176 EVP_PKEY_derive(ctx, derived_secret, outlen);
1181 static long eddsa_c[EdDSA_NUM][2];
1182 static int EdDSA_sign_loop(void *args)
1184 loopargs_t *tempargs = *(loopargs_t **) args;
1185 unsigned char *buf = tempargs->buf;
1186 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1187 unsigned char *eddsasig = tempargs->buf2;
1188 unsigned int *eddsasiglen = &tempargs->siglen;
1191 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1192 ret = EVP_DigestSign(edctx[testnum], eddsasig, (size_t *)eddsasiglen, buf, 20);
1194 BIO_printf(bio_err, "EdDSA sign failure\n");
1195 ERR_print_errors(bio_err);
1203 static int EdDSA_verify_loop(void *args)
1205 loopargs_t *tempargs = *(loopargs_t **) args;
1206 unsigned char *buf = tempargs->buf;
1207 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1208 unsigned char *eddsasig = tempargs->buf2;
1209 unsigned int eddsasiglen = tempargs->siglen;
1212 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1213 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasiglen, buf, 20);
1215 BIO_printf(bio_err, "EdDSA verify failure\n");
1216 ERR_print_errors(bio_err);
1223 #endif /* OPENSSL_NO_EC */
1225 static int run_benchmark(int async_jobs,
1226 int (*loop_function) (void *), loopargs_t * loopargs)
1228 int job_op_count = 0;
1229 int total_op_count = 0;
1230 int num_inprogress = 0;
1231 int error = 0, i = 0, ret = 0;
1232 OSSL_ASYNC_FD job_fd = 0;
1233 size_t num_job_fds = 0;
1237 if (async_jobs == 0) {
1238 return loop_function((void *)&loopargs);
1241 for (i = 0; i < async_jobs && !error; i++) {
1242 loopargs_t *looparg_item = loopargs + i;
1244 /* Copy pointer content (looparg_t item address) into async context */
1245 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1246 &job_op_count, loop_function,
1247 (void *)&looparg_item, sizeof(looparg_item));
1253 if (job_op_count == -1) {
1256 total_op_count += job_op_count;
1261 BIO_printf(bio_err, "Failure in the job\n");
1262 ERR_print_errors(bio_err);
1268 while (num_inprogress > 0) {
1269 #if defined(OPENSSL_SYS_WINDOWS)
1271 #elif defined(OPENSSL_SYS_UNIX)
1272 int select_result = 0;
1273 OSSL_ASYNC_FD max_fd = 0;
1276 FD_ZERO(&waitfdset);
1278 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1279 if (loopargs[i].inprogress_job == NULL)
1282 if (!ASYNC_WAIT_CTX_get_all_fds
1283 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1284 || num_job_fds > 1) {
1285 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1286 ERR_print_errors(bio_err);
1290 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1292 FD_SET(job_fd, &waitfdset);
1293 if (job_fd > max_fd)
1297 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1299 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1300 "Decrease the value of async_jobs\n",
1301 max_fd, FD_SETSIZE);
1302 ERR_print_errors(bio_err);
1307 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1308 if (select_result == -1 && errno == EINTR)
1311 if (select_result == -1) {
1312 BIO_printf(bio_err, "Failure in the select\n");
1313 ERR_print_errors(bio_err);
1318 if (select_result == 0)
1322 for (i = 0; i < async_jobs; i++) {
1323 if (loopargs[i].inprogress_job == NULL)
1326 if (!ASYNC_WAIT_CTX_get_all_fds
1327 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1328 || num_job_fds > 1) {
1329 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1330 ERR_print_errors(bio_err);
1334 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1337 #if defined(OPENSSL_SYS_UNIX)
1338 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1340 #elif defined(OPENSSL_SYS_WINDOWS)
1341 if (num_job_fds == 1
1342 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1347 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1348 loopargs[i].wait_ctx, &job_op_count,
1349 loop_function, (void *)(loopargs + i),
1350 sizeof(loopargs_t));
1355 if (job_op_count == -1) {
1358 total_op_count += job_op_count;
1361 loopargs[i].inprogress_job = NULL;
1366 loopargs[i].inprogress_job = NULL;
1367 BIO_printf(bio_err, "Failure in the job\n");
1368 ERR_print_errors(bio_err);
1375 return error ? -1 : total_op_count;
1378 int speed_main(int argc, char **argv)
1381 loopargs_t *loopargs = NULL;
1383 const char *engine_id = NULL;
1384 const EVP_CIPHER *evp_cipher = NULL;
1387 int async_init = 0, multiblock = 0, pr_header = 0;
1388 int doit[ALGOR_NUM] = { 0 };
1389 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1391 unsigned int size_num = OSSL_NELEM(lengths_list);
1392 unsigned int i, k, loop, loopargs_len = 0, async_jobs = 0;
1398 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1399 || !defined(OPENSSL_NO_EC)
1402 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1403 ECDSA_SECONDS, ECDH_SECONDS,
1406 /* What follows are the buffers and key material. */
1407 #ifndef OPENSSL_NO_RC5
1410 #ifndef OPENSSL_NO_RC2
1413 #ifndef OPENSSL_NO_IDEA
1414 IDEA_KEY_SCHEDULE idea_ks;
1416 #ifndef OPENSSL_NO_SEED
1417 SEED_KEY_SCHEDULE seed_ks;
1419 #ifndef OPENSSL_NO_BF
1422 #ifndef OPENSSL_NO_CAST
1425 static const unsigned char key16[16] = {
1426 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1427 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1429 static const unsigned char key24[24] = {
1430 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1431 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1432 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1434 static const unsigned char key32[32] = {
1435 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1436 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1437 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1438 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1440 #ifndef OPENSSL_NO_CAMELLIA
1441 static const unsigned char ckey24[24] = {
1442 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1443 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1444 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1446 static const unsigned char ckey32[32] = {
1447 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1448 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1449 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1450 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1452 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1454 #ifndef OPENSSL_NO_DES
1455 static DES_cblock key = {
1456 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1458 static DES_cblock key2 = {
1459 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1461 static DES_cblock key3 = {
1462 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1465 #ifndef OPENSSL_NO_RSA
1466 static const unsigned int rsa_bits[RSA_NUM] = {
1467 512, 1024, 2048, 3072, 4096, 7680, 15360
1469 static const unsigned char *rsa_data[RSA_NUM] = {
1470 test512, test1024, test2048, test3072, test4096, test7680, test15360
1472 static const int rsa_data_length[RSA_NUM] = {
1473 sizeof(test512), sizeof(test1024),
1474 sizeof(test2048), sizeof(test3072),
1475 sizeof(test4096), sizeof(test7680),
1478 int rsa_doit[RSA_NUM] = { 0 };
1479 int primes = RSA_DEFAULT_PRIME_NUM;
1481 #ifndef OPENSSL_NO_DSA
1482 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1483 int dsa_doit[DSA_NUM] = { 0 };
1485 #ifndef OPENSSL_NO_EC
1487 * We only test over the following curves as they are representative, To
1488 * add tests over more curves, simply add the curve NID and curve name to
1489 * the following arrays and increase the |ecdh_choices| list accordingly.
1491 static const struct {
1497 {"secp160r1", NID_secp160r1, 160},
1498 {"nistp192", NID_X9_62_prime192v1, 192},
1499 {"nistp224", NID_secp224r1, 224},
1500 {"nistp256", NID_X9_62_prime256v1, 256},
1501 {"nistp384", NID_secp384r1, 384},
1502 {"nistp521", NID_secp521r1, 521},
1504 {"nistk163", NID_sect163k1, 163},
1505 {"nistk233", NID_sect233k1, 233},
1506 {"nistk283", NID_sect283k1, 283},
1507 {"nistk409", NID_sect409k1, 409},
1508 {"nistk571", NID_sect571k1, 571},
1509 {"nistb163", NID_sect163r2, 163},
1510 {"nistb233", NID_sect233r1, 233},
1511 {"nistb283", NID_sect283r1, 283},
1512 {"nistb409", NID_sect409r1, 409},
1513 {"nistb571", NID_sect571r1, 571},
1514 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1515 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1516 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1517 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1518 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1519 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1520 /* Other and ECDH only ones */
1521 {"X25519", NID_X25519, 253},
1522 {"X448", NID_X448, 448}
1524 static const struct {
1528 unsigned int siglen;
1529 } test_ed_curves[] = {
1531 {"Ed25519", NID_ED25519, 253, 64},
1532 {"Ed448", NID_ED448, 456, 114}
1534 int ecdsa_doit[ECDSA_NUM] = { 0 };
1535 int ecdh_doit[EC_NUM] = { 0 };
1536 int eddsa_doit[EdDSA_NUM] = { 0 };
1537 OPENSSL_assert(OSSL_NELEM(test_curves) >= EC_NUM);
1538 OPENSSL_assert(OSSL_NELEM(test_ed_curves) >= EdDSA_NUM);
1539 #endif /* ndef OPENSSL_NO_EC */
1541 prog = opt_init(argc, argv, speed_options);
1542 while ((o = opt_next()) != OPT_EOF) {
1547 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1550 opt_help(speed_options);
1558 evp_cipher = EVP_get_cipherbyname(opt_arg());
1559 if (evp_cipher == NULL)
1560 evp_md = EVP_get_digestbyname(opt_arg());
1561 if (evp_cipher == NULL && evp_md == NULL) {
1563 "%s: %s is an unknown cipher or digest\n",
1574 * In a forked execution, an engine might need to be
1575 * initialised by each child process, not by the parent.
1576 * So store the name here and run setup_engine() later on.
1578 engine_id = opt_arg();
1582 multi = atoi(opt_arg());
1586 #ifndef OPENSSL_NO_ASYNC
1587 async_jobs = atoi(opt_arg());
1588 if (!ASYNC_is_capable()) {
1590 "%s: async_jobs specified but async not supported\n",
1594 if (async_jobs > 99999) {
1595 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1601 if (!opt_int(opt_arg(), &misalign))
1603 if (misalign > MISALIGN) {
1605 "%s: Maximum offset is %d\n", prog, MISALIGN);
1614 #ifdef OPENSSL_NO_MULTIBLOCK
1616 "%s: -mb specified but multi-block support is disabled\n",
1626 if (!opt_int(opt_arg(), &primes))
1630 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1631 = seconds.ecdh = seconds.eddsa = atoi(opt_arg());
1634 lengths_single = atoi(opt_arg());
1635 lengths = &lengths_single;
1643 argc = opt_num_rest();
1646 /* Remaining arguments are algorithms. */
1647 for (; *argv; argv++) {
1648 if (found(*argv, doit_choices, &i)) {
1652 #ifndef OPENSSL_NO_DES
1653 if (strcmp(*argv, "des") == 0) {
1654 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1658 if (strcmp(*argv, "sha") == 0) {
1659 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1662 #ifndef OPENSSL_NO_RSA
1663 if (strcmp(*argv, "openssl") == 0)
1665 if (strcmp(*argv, "rsa") == 0) {
1666 for (loop = 0; loop < OSSL_NELEM(rsa_doit); loop++)
1670 if (found(*argv, rsa_choices, &i)) {
1675 #ifndef OPENSSL_NO_DSA
1676 if (strcmp(*argv, "dsa") == 0) {
1677 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1678 dsa_doit[R_DSA_2048] = 1;
1681 if (found(*argv, dsa_choices, &i)) {
1686 if (strcmp(*argv, "aes") == 0) {
1687 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1690 #ifndef OPENSSL_NO_CAMELLIA
1691 if (strcmp(*argv, "camellia") == 0) {
1692 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1696 #ifndef OPENSSL_NO_EC
1697 if (strcmp(*argv, "ecdsa") == 0) {
1698 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1699 ecdsa_doit[loop] = 1;
1702 if (found(*argv, ecdsa_choices, &i)) {
1706 if (strcmp(*argv, "ecdh") == 0) {
1707 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1708 ecdh_doit[loop] = 1;
1711 if (found(*argv, ecdh_choices, &i)) {
1715 if (strcmp(*argv, "eddsa") == 0) {
1716 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1717 eddsa_doit[loop] = 1;
1720 if (found(*argv, eddsa_choices, &i)) {
1725 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1731 if (evp_cipher == NULL) {
1732 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1734 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1735 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1736 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1737 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1742 if (evp_cipher == NULL) {
1743 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1744 " capable cipher\n");
1746 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1747 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1748 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1749 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1751 } else if (async_jobs > 0) {
1752 BIO_printf(bio_err, "Async mode is not supported with -mb");
1757 /* Initialize the job pool if async mode is enabled */
1758 if (async_jobs > 0) {
1759 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1761 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1766 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1768 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1769 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1771 for (i = 0; i < loopargs_len; i++) {
1772 if (async_jobs > 0) {
1773 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1774 if (loopargs[i].wait_ctx == NULL) {
1775 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1780 buflen = lengths[size_num - 1];
1781 if (buflen < 36) /* size of random vector in RSA bencmark */
1783 buflen += MAX_MISALIGNMENT + 1;
1784 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1785 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1786 memset(loopargs[i].buf_malloc, 0, buflen);
1787 memset(loopargs[i].buf2_malloc, 0, buflen);
1789 /* Align the start of buffers on a 64 byte boundary */
1790 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1791 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1792 #ifndef OPENSSL_NO_EC
1793 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1794 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1799 if (multi && do_multi(multi, size_num))
1803 /* Initialize the engine after the fork */
1804 e = setup_engine(engine_id, 0);
1806 /* No parameters; turn on everything. */
1807 if ((argc == 0) && !doit[D_EVP]) {
1808 for (i = 0; i < ALGOR_NUM; i++)
1811 #ifndef OPENSSL_NO_RSA
1812 for (i = 0; i < RSA_NUM; i++)
1815 #ifndef OPENSSL_NO_DSA
1816 for (i = 0; i < DSA_NUM; i++)
1819 #ifndef OPENSSL_NO_EC
1820 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1821 ecdsa_doit[loop] = 1;
1822 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1823 ecdh_doit[loop] = 1;
1824 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1825 eddsa_doit[loop] = 1;
1828 for (i = 0; i < ALGOR_NUM; i++)
1832 if (usertime == 0 && !mr)
1834 "You have chosen to measure elapsed time "
1835 "instead of user CPU time.\n");
1837 #ifndef OPENSSL_NO_RSA
1838 for (i = 0; i < loopargs_len; i++) {
1839 if (primes > RSA_DEFAULT_PRIME_NUM) {
1840 /* for multi-prime RSA, skip this */
1843 for (k = 0; k < RSA_NUM; k++) {
1844 const unsigned char *p;
1847 loopargs[i].rsa_key[k] =
1848 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1849 if (loopargs[i].rsa_key[k] == NULL) {
1851 "internal error loading RSA key number %d\n", k);
1857 #ifndef OPENSSL_NO_DSA
1858 for (i = 0; i < loopargs_len; i++) {
1859 loopargs[i].dsa_key[0] = get_dsa(512);
1860 loopargs[i].dsa_key[1] = get_dsa(1024);
1861 loopargs[i].dsa_key[2] = get_dsa(2048);
1864 #ifndef OPENSSL_NO_DES
1865 DES_set_key_unchecked(&key, &sch);
1866 DES_set_key_unchecked(&key2, &sch2);
1867 DES_set_key_unchecked(&key3, &sch3);
1869 AES_set_encrypt_key(key16, 128, &aes_ks1);
1870 AES_set_encrypt_key(key24, 192, &aes_ks2);
1871 AES_set_encrypt_key(key32, 256, &aes_ks3);
1872 #ifndef OPENSSL_NO_CAMELLIA
1873 Camellia_set_key(key16, 128, &camellia_ks1);
1874 Camellia_set_key(ckey24, 192, &camellia_ks2);
1875 Camellia_set_key(ckey32, 256, &camellia_ks3);
1877 #ifndef OPENSSL_NO_IDEA
1878 IDEA_set_encrypt_key(key16, &idea_ks);
1880 #ifndef OPENSSL_NO_SEED
1881 SEED_set_key(key16, &seed_ks);
1883 #ifndef OPENSSL_NO_RC4
1884 RC4_set_key(&rc4_ks, 16, key16);
1886 #ifndef OPENSSL_NO_RC2
1887 RC2_set_key(&rc2_ks, 16, key16, 128);
1889 #ifndef OPENSSL_NO_RC5
1890 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1892 #ifndef OPENSSL_NO_BF
1893 BF_set_key(&bf_ks, 16, key16);
1895 #ifndef OPENSSL_NO_CAST
1896 CAST_set_key(&cast_ks, 16, key16);
1899 # ifndef OPENSSL_NO_DES
1900 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1906 for (it = count; it; it--)
1907 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1908 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1912 c[D_MD2][0] = count / 10;
1913 c[D_MDC2][0] = count / 10;
1914 c[D_MD4][0] = count;
1915 c[D_MD5][0] = count;
1916 c[D_HMAC][0] = count;
1917 c[D_SHA1][0] = count;
1918 c[D_RMD160][0] = count;
1919 c[D_RC4][0] = count * 5;
1920 c[D_CBC_DES][0] = count;
1921 c[D_EDE3_DES][0] = count / 3;
1922 c[D_CBC_IDEA][0] = count;
1923 c[D_CBC_SEED][0] = count;
1924 c[D_CBC_RC2][0] = count;
1925 c[D_CBC_RC5][0] = count;
1926 c[D_CBC_BF][0] = count;
1927 c[D_CBC_CAST][0] = count;
1928 c[D_CBC_128_AES][0] = count;
1929 c[D_CBC_192_AES][0] = count;
1930 c[D_CBC_256_AES][0] = count;
1931 c[D_CBC_128_CML][0] = count;
1932 c[D_CBC_192_CML][0] = count;
1933 c[D_CBC_256_CML][0] = count;
1934 c[D_SHA256][0] = count;
1935 c[D_SHA512][0] = count;
1936 c[D_WHIRLPOOL][0] = count;
1937 c[D_IGE_128_AES][0] = count;
1938 c[D_IGE_192_AES][0] = count;
1939 c[D_IGE_256_AES][0] = count;
1940 c[D_GHASH][0] = count;
1941 c[D_RAND][0] = count;
1943 for (i = 1; i < size_num; i++) {
1946 l0 = (long)lengths[0];
1947 l1 = (long)lengths[i];
1949 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1950 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1951 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1952 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1953 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1954 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1955 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1956 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1957 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1958 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1959 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1960 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
1962 l0 = (long)lengths[i - 1];
1964 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1965 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1966 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1967 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1968 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1969 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1970 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1971 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1972 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1973 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1974 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1975 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1976 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1977 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1978 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1979 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1980 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1981 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1984 # ifndef OPENSSL_NO_RSA
1985 rsa_c[R_RSA_512][0] = count / 2000;
1986 rsa_c[R_RSA_512][1] = count / 400;
1987 for (i = 1; i < RSA_NUM; i++) {
1988 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1989 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1990 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1993 if (rsa_c[i][0] == 0) {
1994 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2001 # ifndef OPENSSL_NO_DSA
2002 dsa_c[R_DSA_512][0] = count / 1000;
2003 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2004 for (i = 1; i < DSA_NUM; i++) {
2005 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2006 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2007 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2010 if (dsa_c[i][0] == 0) {
2011 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2018 # ifndef OPENSSL_NO_EC
2019 ecdsa_c[R_EC_P160][0] = count / 1000;
2020 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2021 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2022 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2023 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2024 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2027 if (ecdsa_c[i][0] == 0) {
2033 ecdsa_c[R_EC_K163][0] = count / 1000;
2034 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2035 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2036 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2037 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2038 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2041 if (ecdsa_c[i][0] == 0) {
2047 ecdsa_c[R_EC_B163][0] = count / 1000;
2048 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2049 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2050 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2051 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2052 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2055 if (ecdsa_c[i][0] == 0) {
2062 ecdh_c[R_EC_P160][0] = count / 1000;
2063 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2064 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2065 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2068 if (ecdh_c[i][0] == 0) {
2073 ecdh_c[R_EC_K163][0] = count / 1000;
2074 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2075 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2076 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2079 if (ecdh_c[i][0] == 0) {
2084 ecdh_c[R_EC_B163][0] = count / 1000;
2085 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2086 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2087 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2090 if (ecdh_c[i][0] == 0) {
2095 /* repeated code good to factorize */
2096 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2097 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2098 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2099 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2102 if (ecdh_c[i][0] == 0) {
2107 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2108 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2109 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2110 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2113 if (ecdh_c[i][0] == 0) {
2118 /* default iteration count for the last two EC Curves */
2119 ecdh_c[R_EC_X25519][0] = count / 1800;
2120 ecdh_c[R_EC_X448][0] = count / 7200;
2122 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2123 eddsa_c[R_EC_Ed448][0] = count / 7200;
2127 /* not worth fixing */
2128 # error "You cannot disable DES on systems without SIGALRM."
2129 # endif /* OPENSSL_NO_DES */
2131 signal(SIGALRM, alarmed);
2132 #endif /* SIGALRM */
2134 #ifndef OPENSSL_NO_MD2
2136 for (testnum = 0; testnum < size_num; testnum++) {
2137 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2140 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2142 print_result(D_MD2, testnum, count, d);
2146 #ifndef OPENSSL_NO_MDC2
2148 for (testnum = 0; testnum < size_num; testnum++) {
2149 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2152 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2154 print_result(D_MDC2, testnum, count, d);
2159 #ifndef OPENSSL_NO_MD4
2161 for (testnum = 0; testnum < size_num; testnum++) {
2162 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2165 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2167 print_result(D_MD4, testnum, count, d);
2172 #ifndef OPENSSL_NO_MD5
2174 for (testnum = 0; testnum < size_num; testnum++) {
2175 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2178 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2180 print_result(D_MD5, testnum, count, d);
2185 static const char hmac_key[] = "This is a key...";
2186 int len = strlen(hmac_key);
2188 for (i = 0; i < loopargs_len; i++) {
2189 loopargs[i].hctx = HMAC_CTX_new();
2190 if (loopargs[i].hctx == NULL) {
2191 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2195 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2197 for (testnum = 0; testnum < size_num; testnum++) {
2198 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2201 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2203 print_result(D_HMAC, testnum, count, d);
2205 for (i = 0; i < loopargs_len; i++) {
2206 HMAC_CTX_free(loopargs[i].hctx);
2211 for (testnum = 0; testnum < size_num; testnum++) {
2212 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2215 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2217 print_result(D_SHA1, testnum, count, d);
2220 if (doit[D_SHA256]) {
2221 for (testnum = 0; testnum < size_num; testnum++) {
2222 print_message(names[D_SHA256], c[D_SHA256][testnum],
2223 lengths[testnum], seconds.sym);
2225 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2227 print_result(D_SHA256, testnum, count, d);
2230 if (doit[D_SHA512]) {
2231 for (testnum = 0; testnum < size_num; testnum++) {
2232 print_message(names[D_SHA512], c[D_SHA512][testnum],
2233 lengths[testnum], seconds.sym);
2235 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2237 print_result(D_SHA512, testnum, count, d);
2240 #ifndef OPENSSL_NO_WHIRLPOOL
2241 if (doit[D_WHIRLPOOL]) {
2242 for (testnum = 0; testnum < size_num; testnum++) {
2243 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2244 lengths[testnum], seconds.sym);
2246 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2248 print_result(D_WHIRLPOOL, testnum, count, d);
2253 #ifndef OPENSSL_NO_RMD160
2254 if (doit[D_RMD160]) {
2255 for (testnum = 0; testnum < size_num; testnum++) {
2256 print_message(names[D_RMD160], c[D_RMD160][testnum],
2257 lengths[testnum], seconds.sym);
2259 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2261 print_result(D_RMD160, testnum, count, d);
2265 #ifndef OPENSSL_NO_RC4
2267 for (testnum = 0; testnum < size_num; testnum++) {
2268 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2271 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2273 print_result(D_RC4, testnum, count, d);
2277 #ifndef OPENSSL_NO_DES
2278 if (doit[D_CBC_DES]) {
2279 for (testnum = 0; testnum < size_num; testnum++) {
2280 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2281 lengths[testnum], seconds.sym);
2283 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2285 print_result(D_CBC_DES, testnum, count, d);
2289 if (doit[D_EDE3_DES]) {
2290 for (testnum = 0; testnum < size_num; testnum++) {
2291 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2292 lengths[testnum], seconds.sym);
2295 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2297 print_result(D_EDE3_DES, testnum, count, d);
2302 if (doit[D_CBC_128_AES]) {
2303 for (testnum = 0; testnum < size_num; testnum++) {
2304 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2305 lengths[testnum], seconds.sym);
2308 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2310 print_result(D_CBC_128_AES, testnum, count, d);
2313 if (doit[D_CBC_192_AES]) {
2314 for (testnum = 0; testnum < size_num; testnum++) {
2315 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2316 lengths[testnum], seconds.sym);
2319 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2321 print_result(D_CBC_192_AES, testnum, count, d);
2324 if (doit[D_CBC_256_AES]) {
2325 for (testnum = 0; testnum < size_num; testnum++) {
2326 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2327 lengths[testnum], seconds.sym);
2330 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2332 print_result(D_CBC_256_AES, testnum, count, d);
2336 if (doit[D_IGE_128_AES]) {
2337 for (testnum = 0; testnum < size_num; testnum++) {
2338 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2339 lengths[testnum], seconds.sym);
2342 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2344 print_result(D_IGE_128_AES, testnum, count, d);
2347 if (doit[D_IGE_192_AES]) {
2348 for (testnum = 0; testnum < size_num; testnum++) {
2349 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2350 lengths[testnum], seconds.sym);
2353 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2355 print_result(D_IGE_192_AES, testnum, count, d);
2358 if (doit[D_IGE_256_AES]) {
2359 for (testnum = 0; testnum < size_num; testnum++) {
2360 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2361 lengths[testnum], seconds.sym);
2364 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2366 print_result(D_IGE_256_AES, testnum, count, d);
2369 if (doit[D_GHASH]) {
2370 for (i = 0; i < loopargs_len; i++) {
2371 loopargs[i].gcm_ctx =
2372 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2373 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2374 (unsigned char *)"0123456789ab", 12);
2377 for (testnum = 0; testnum < size_num; testnum++) {
2378 print_message(names[D_GHASH], c[D_GHASH][testnum],
2379 lengths[testnum], seconds.sym);
2381 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2383 print_result(D_GHASH, testnum, count, d);
2385 for (i = 0; i < loopargs_len; i++)
2386 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2388 #ifndef OPENSSL_NO_CAMELLIA
2389 if (doit[D_CBC_128_CML]) {
2390 if (async_jobs > 0) {
2391 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2392 names[D_CBC_128_CML]);
2393 doit[D_CBC_128_CML] = 0;
2395 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2396 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2397 lengths[testnum], seconds.sym);
2399 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2400 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2401 (size_t)lengths[testnum], &camellia_ks1,
2402 iv, CAMELLIA_ENCRYPT);
2404 print_result(D_CBC_128_CML, testnum, count, d);
2407 if (doit[D_CBC_192_CML]) {
2408 if (async_jobs > 0) {
2409 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2410 names[D_CBC_192_CML]);
2411 doit[D_CBC_192_CML] = 0;
2413 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2414 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2415 lengths[testnum], seconds.sym);
2416 if (async_jobs > 0) {
2417 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2421 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2422 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2423 (size_t)lengths[testnum], &camellia_ks2,
2424 iv, CAMELLIA_ENCRYPT);
2426 print_result(D_CBC_192_CML, testnum, count, d);
2429 if (doit[D_CBC_256_CML]) {
2430 if (async_jobs > 0) {
2431 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2432 names[D_CBC_256_CML]);
2433 doit[D_CBC_256_CML] = 0;
2435 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2436 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2437 lengths[testnum], seconds.sym);
2439 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2440 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2441 (size_t)lengths[testnum], &camellia_ks3,
2442 iv, CAMELLIA_ENCRYPT);
2444 print_result(D_CBC_256_CML, testnum, count, d);
2448 #ifndef OPENSSL_NO_IDEA
2449 if (doit[D_CBC_IDEA]) {
2450 if (async_jobs > 0) {
2451 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2453 doit[D_CBC_IDEA] = 0;
2455 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2456 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2457 lengths[testnum], seconds.sym);
2459 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2460 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2461 (size_t)lengths[testnum], &idea_ks,
2464 print_result(D_CBC_IDEA, testnum, count, d);
2468 #ifndef OPENSSL_NO_SEED
2469 if (doit[D_CBC_SEED]) {
2470 if (async_jobs > 0) {
2471 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2473 doit[D_CBC_SEED] = 0;
2475 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2476 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2477 lengths[testnum], seconds.sym);
2479 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2480 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2481 (size_t)lengths[testnum], &seed_ks, iv, 1);
2483 print_result(D_CBC_SEED, testnum, count, d);
2487 #ifndef OPENSSL_NO_RC2
2488 if (doit[D_CBC_RC2]) {
2489 if (async_jobs > 0) {
2490 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2492 doit[D_CBC_RC2] = 0;
2494 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2495 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2496 lengths[testnum], seconds.sym);
2497 if (async_jobs > 0) {
2498 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2502 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2503 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2504 (size_t)lengths[testnum], &rc2_ks,
2507 print_result(D_CBC_RC2, testnum, count, d);
2511 #ifndef OPENSSL_NO_RC5
2512 if (doit[D_CBC_RC5]) {
2513 if (async_jobs > 0) {
2514 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2516 doit[D_CBC_RC5] = 0;
2518 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2519 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2520 lengths[testnum], seconds.sym);
2521 if (async_jobs > 0) {
2522 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2526 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2527 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2528 (size_t)lengths[testnum], &rc5_ks,
2531 print_result(D_CBC_RC5, testnum, count, d);
2535 #ifndef OPENSSL_NO_BF
2536 if (doit[D_CBC_BF]) {
2537 if (async_jobs > 0) {
2538 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2542 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2543 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2544 lengths[testnum], seconds.sym);
2546 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2547 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2548 (size_t)lengths[testnum], &bf_ks,
2551 print_result(D_CBC_BF, testnum, count, d);
2555 #ifndef OPENSSL_NO_CAST
2556 if (doit[D_CBC_CAST]) {
2557 if (async_jobs > 0) {
2558 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2560 doit[D_CBC_CAST] = 0;
2562 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2563 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2564 lengths[testnum], seconds.sym);
2566 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2567 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2568 (size_t)lengths[testnum], &cast_ks,
2571 print_result(D_CBC_CAST, testnum, count, d);
2576 for (testnum = 0; testnum < size_num; testnum++) {
2577 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2580 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2582 print_result(D_RAND, testnum, count, d);
2587 if (evp_cipher != NULL) {
2588 int (*loopfunc)(void *args) = EVP_Update_loop;
2590 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2591 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2592 multiblock_speed(evp_cipher, lengths_single, &seconds);
2597 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2599 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2600 loopfunc = EVP_Update_loop_ccm;
2601 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2602 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2603 loopfunc = EVP_Update_loop_aead;
2604 if (lengths == lengths_list) {
2605 lengths = aead_lengths_list;
2606 size_num = OSSL_NELEM(aead_lengths_list);
2610 for (testnum = 0; testnum < size_num; testnum++) {
2611 print_message(names[D_EVP], save_count, lengths[testnum],
2614 for (k = 0; k < loopargs_len; k++) {
2615 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2616 EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
2617 iv, decrypt ? 0 : 1);
2619 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2621 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2622 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2623 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2624 EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2625 loopargs[k].key, NULL, -1);
2626 OPENSSL_clear_free(loopargs[k].key, keylen);
2630 count = run_benchmark(async_jobs, loopfunc, loopargs);
2632 for (k = 0; k < loopargs_len; k++) {
2633 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2635 print_result(D_EVP, testnum, count, d);
2637 } else if (evp_md != NULL) {
2638 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2640 for (testnum = 0; testnum < size_num; testnum++) {
2641 print_message(names[D_EVP], save_count, lengths[testnum],
2644 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2646 print_result(D_EVP, testnum, count, d);
2651 for (i = 0; i < loopargs_len; i++)
2652 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2655 #ifndef OPENSSL_NO_RSA
2656 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2658 if (!rsa_doit[testnum])
2660 for (i = 0; i < loopargs_len; i++) {
2662 /* we haven't set keys yet, generate multi-prime RSA keys */
2663 BIGNUM *bn = BN_new();
2667 if (!BN_set_word(bn, RSA_F4)) {
2672 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2673 rsa_choices[testnum].name);
2675 loopargs[i].rsa_key[testnum] = RSA_new();
2676 if (loopargs[i].rsa_key[testnum] == NULL) {
2681 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2683 primes, bn, NULL)) {
2689 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2690 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2696 "RSA sign failure. No RSA sign will be done.\n");
2697 ERR_print_errors(bio_err);
2700 pkey_print_message("private", "rsa",
2701 rsa_c[testnum][0], rsa_bits[testnum],
2703 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2705 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2708 mr ? "+R1:%ld:%d:%.2f\n"
2709 : "%ld %u bits private RSA's in %.2fs\n",
2710 count, rsa_bits[testnum], d);
2711 rsa_results[testnum][0] = (double)count / d;
2715 for (i = 0; i < loopargs_len; i++) {
2716 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2717 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2723 "RSA verify failure. No RSA verify will be done.\n");
2724 ERR_print_errors(bio_err);
2725 rsa_doit[testnum] = 0;
2727 pkey_print_message("public", "rsa",
2728 rsa_c[testnum][1], rsa_bits[testnum],
2731 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2734 mr ? "+R2:%ld:%d:%.2f\n"
2735 : "%ld %u bits public RSA's in %.2fs\n",
2736 count, rsa_bits[testnum], d);
2737 rsa_results[testnum][1] = (double)count / d;
2740 if (rsa_count <= 1) {
2741 /* if longer than 10s, don't do any more */
2742 for (testnum++; testnum < RSA_NUM; testnum++)
2743 rsa_doit[testnum] = 0;
2746 #endif /* OPENSSL_NO_RSA */
2748 for (i = 0; i < loopargs_len; i++)
2749 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2752 #ifndef OPENSSL_NO_DSA
2753 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2755 if (!dsa_doit[testnum])
2758 /* DSA_generate_key(dsa_key[testnum]); */
2759 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2760 for (i = 0; i < loopargs_len; i++) {
2761 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2762 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2768 "DSA sign failure. No DSA sign will be done.\n");
2769 ERR_print_errors(bio_err);
2772 pkey_print_message("sign", "dsa",
2773 dsa_c[testnum][0], dsa_bits[testnum],
2776 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2779 mr ? "+R3:%ld:%u:%.2f\n"
2780 : "%ld %u bits DSA signs in %.2fs\n",
2781 count, dsa_bits[testnum], d);
2782 dsa_results[testnum][0] = (double)count / d;
2786 for (i = 0; i < loopargs_len; i++) {
2787 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2788 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2794 "DSA verify failure. No DSA verify will be done.\n");
2795 ERR_print_errors(bio_err);
2796 dsa_doit[testnum] = 0;
2798 pkey_print_message("verify", "dsa",
2799 dsa_c[testnum][1], dsa_bits[testnum],
2802 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2805 mr ? "+R4:%ld:%u:%.2f\n"
2806 : "%ld %u bits DSA verify in %.2fs\n",
2807 count, dsa_bits[testnum], d);
2808 dsa_results[testnum][1] = (double)count / d;
2811 if (rsa_count <= 1) {
2812 /* if longer than 10s, don't do any more */
2813 for (testnum++; testnum < DSA_NUM; testnum++)
2814 dsa_doit[testnum] = 0;
2817 #endif /* OPENSSL_NO_DSA */
2819 #ifndef OPENSSL_NO_EC
2820 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
2823 if (!ecdsa_doit[testnum])
2824 continue; /* Ignore Curve */
2825 for (i = 0; i < loopargs_len; i++) {
2826 loopargs[i].ecdsa[testnum] =
2827 EC_KEY_new_by_curve_name(test_curves[testnum].nid);
2828 if (loopargs[i].ecdsa[testnum] == NULL) {
2834 BIO_printf(bio_err, "ECDSA failure.\n");
2835 ERR_print_errors(bio_err);
2838 for (i = 0; i < loopargs_len; i++) {
2839 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2840 /* Perform ECDSA signature test */
2841 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2842 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2843 &loopargs[i].siglen,
2844 loopargs[i].ecdsa[testnum]);
2850 "ECDSA sign failure. No ECDSA sign will be done.\n");
2851 ERR_print_errors(bio_err);
2854 pkey_print_message("sign", "ecdsa",
2855 ecdsa_c[testnum][0],
2856 test_curves[testnum].bits, seconds.ecdsa);
2858 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2862 mr ? "+R5:%ld:%u:%.2f\n" :
2863 "%ld %u bits ECDSA signs in %.2fs \n",
2864 count, test_curves[testnum].bits, d);
2865 ecdsa_results[testnum][0] = (double)count / d;
2869 /* Perform ECDSA verification test */
2870 for (i = 0; i < loopargs_len; i++) {
2871 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2873 loopargs[i].ecdsa[testnum]);
2879 "ECDSA verify failure. No ECDSA verify will be done.\n");
2880 ERR_print_errors(bio_err);
2881 ecdsa_doit[testnum] = 0;
2883 pkey_print_message("verify", "ecdsa",
2884 ecdsa_c[testnum][1],
2885 test_curves[testnum].bits, seconds.ecdsa);
2887 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2890 mr ? "+R6:%ld:%u:%.2f\n"
2891 : "%ld %u bits ECDSA verify in %.2fs\n",
2892 count, test_curves[testnum].bits, d);
2893 ecdsa_results[testnum][1] = (double)count / d;
2896 if (rsa_count <= 1) {
2897 /* if longer than 10s, don't do any more */
2898 for (testnum++; testnum < EC_NUM; testnum++)
2899 ecdsa_doit[testnum] = 0;
2904 for (testnum = 0; testnum < EC_NUM; testnum++) {
2905 int ecdh_checks = 1;
2907 if (!ecdh_doit[testnum])
2910 for (i = 0; i < loopargs_len; i++) {
2911 EVP_PKEY_CTX *kctx = NULL;
2912 EVP_PKEY_CTX *test_ctx = NULL;
2913 EVP_PKEY_CTX *ctx = NULL;
2914 EVP_PKEY *key_A = NULL;
2915 EVP_PKEY *key_B = NULL;
2919 /* Ensure that the error queue is empty */
2920 if (ERR_peek_error()) {
2922 "WARNING: the error queue contains previous unhandled errors.\n");
2923 ERR_print_errors(bio_err);
2926 /* Let's try to create a ctx directly from the NID: this works for
2927 * curves like Curve25519 that are not implemented through the low
2928 * level EC interface.
2929 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2930 * then we set the curve by NID before deriving the actual keygen
2931 * ctx for that specific curve. */
2932 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum].nid, NULL); /* keygen ctx from NID */
2934 EVP_PKEY_CTX *pctx = NULL;
2935 EVP_PKEY *params = NULL;
2937 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2938 * "int_ctx_new:unsupported algorithm" error was added to the
2940 * We remove it from the error queue as we are handling it. */
2941 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2942 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2943 /* check that the error origin matches */
2944 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2945 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2946 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2947 ERR_get_error(); /* pop error from queue */
2948 if (ERR_peek_error()) {
2950 "Unhandled error in the error queue during ECDH init.\n");
2951 ERR_print_errors(bio_err);
2956 if ( /* Create the context for parameter generation */
2957 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2958 /* Initialise the parameter generation */
2959 !EVP_PKEY_paramgen_init(pctx) ||
2960 /* Set the curve by NID */
2961 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2964 /* Create the parameter object params */
2965 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2967 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2968 ERR_print_errors(bio_err);
2972 /* Create the context for the key generation */
2973 kctx = EVP_PKEY_CTX_new(params, NULL);
2975 EVP_PKEY_free(params);
2977 EVP_PKEY_CTX_free(pctx);
2980 if (kctx == NULL || /* keygen ctx is not null */
2981 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2983 BIO_printf(bio_err, "ECDH keygen failure.\n");
2984 ERR_print_errors(bio_err);
2989 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2990 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2991 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2992 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2993 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2994 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2995 outlen == 0 || /* ensure outlen is a valid size */
2996 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2998 BIO_printf(bio_err, "ECDH key generation failure.\n");
2999 ERR_print_errors(bio_err);
3004 /* Here we perform a test run, comparing the output of a*B and b*A;
3005 * we try this here and assume that further EVP_PKEY_derive calls
3006 * never fail, so we can skip checks in the actually benchmarked
3007 * code, for maximum performance. */
3008 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3009 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3010 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3011 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3012 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3013 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3014 test_outlen != outlen /* compare output length */ ) {
3016 BIO_printf(bio_err, "ECDH computation failure.\n");
3017 ERR_print_errors(bio_err);
3022 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3023 if (CRYPTO_memcmp(loopargs[i].secret_a,
3024 loopargs[i].secret_b, outlen)) {
3026 BIO_printf(bio_err, "ECDH computations don't match.\n");
3027 ERR_print_errors(bio_err);
3032 loopargs[i].ecdh_ctx[testnum] = ctx;
3033 loopargs[i].outlen[testnum] = outlen;
3035 EVP_PKEY_free(key_A);
3036 EVP_PKEY_free(key_B);
3037 EVP_PKEY_CTX_free(kctx);
3039 EVP_PKEY_CTX_free(test_ctx);
3042 if (ecdh_checks != 0) {
3043 pkey_print_message("", "ecdh",
3045 test_curves[testnum].bits, seconds.ecdh);
3048 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3051 mr ? "+R7:%ld:%d:%.2f\n" :
3052 "%ld %u-bits ECDH ops in %.2fs\n", count,
3053 test_curves[testnum].bits, d);
3054 ecdh_results[testnum][0] = (double)count / d;
3058 if (rsa_count <= 1) {
3059 /* if longer than 10s, don't do any more */
3060 for (testnum++; testnum < OSSL_NELEM(ecdh_doit); testnum++)
3061 ecdh_doit[testnum] = 0;
3065 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3067 EVP_PKEY *ed_pkey = NULL;
3068 EVP_PKEY_CTX *ed_pctx = NULL;
3070 if (!eddsa_doit[testnum])
3071 continue; /* Ignore Curve */
3072 for (i = 0; i < loopargs_len; i++) {
3073 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3074 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3079 if ((ed_pctx = EVP_PKEY_CTX_new_id(test_ed_curves[testnum].nid, NULL))
3081 || !EVP_PKEY_keygen_init(ed_pctx)
3082 || !EVP_PKEY_keygen(ed_pctx, &ed_pkey)) {
3084 EVP_PKEY_CTX_free(ed_pctx);
3087 EVP_PKEY_CTX_free(ed_pctx);
3089 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3092 EVP_PKEY_free(ed_pkey);
3095 EVP_PKEY_free(ed_pkey);
3098 BIO_printf(bio_err, "EdDSA failure.\n");
3099 ERR_print_errors(bio_err);
3102 for (i = 0; i < loopargs_len; i++) {
3103 /* Perform EdDSA signature test */
3104 loopargs[i].siglen = test_ed_curves[testnum].siglen;
3105 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3106 loopargs[i].buf2, (size_t *)&loopargs[i].siglen,
3107 loopargs[i].buf, 20);
3113 "EdDSA sign failure. No EdDSA sign will be done.\n");
3114 ERR_print_errors(bio_err);
3117 pkey_print_message("sign", test_ed_curves[testnum].name,
3118 eddsa_c[testnum][0],
3119 test_ed_curves[testnum].bits, seconds.eddsa);
3121 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3125 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3126 "%ld %u bits %s signs in %.2fs \n",
3127 count, test_ed_curves[testnum].bits,
3128 test_ed_curves[testnum].name, d);
3129 eddsa_results[testnum][0] = (double)count / d;
3133 /* Perform EdDSA verification test */
3134 for (i = 0; i < loopargs_len; i++) {
3135 st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
3136 loopargs[i].buf2, loopargs[i].siglen,
3137 loopargs[i].buf, 20);
3143 "EdDSA verify failure. No EdDSA verify will be done.\n");
3144 ERR_print_errors(bio_err);
3145 eddsa_doit[testnum] = 0;
3147 pkey_print_message("verify", test_ed_curves[testnum].name,
3148 eddsa_c[testnum][1],
3149 test_ed_curves[testnum].bits, seconds.eddsa);
3151 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3154 mr ? "+R9:%ld:%u:%s:%.2f\n"
3155 : "%ld %u bits %s verify in %.2fs\n",
3156 count, test_ed_curves[testnum].bits,
3157 test_ed_curves[testnum].name, d);
3158 eddsa_results[testnum][1] = (double)count / d;
3161 if (rsa_count <= 1) {
3162 /* if longer than 10s, don't do any more */
3163 for (testnum++; testnum < EdDSA_NUM; testnum++)
3164 eddsa_doit[testnum] = 0;
3169 #endif /* OPENSSL_NO_EC */
3174 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
3175 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3177 printf("%s ", BN_options());
3178 #ifndef OPENSSL_NO_MD2
3179 printf("%s ", MD2_options());
3181 #ifndef OPENSSL_NO_RC4
3182 printf("%s ", RC4_options());
3184 #ifndef OPENSSL_NO_DES
3185 printf("%s ", DES_options());
3187 printf("%s ", AES_options());
3188 #ifndef OPENSSL_NO_IDEA
3189 printf("%s ", IDEA_options());
3191 #ifndef OPENSSL_NO_BF
3192 printf("%s ", BF_options());
3194 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3202 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3205 for (testnum = 0; testnum < size_num; testnum++)
3206 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3210 for (k = 0; k < ALGOR_NUM; k++) {
3214 printf("+F:%u:%s", k, names[k]);
3216 printf("%-13s", names[k]);
3217 for (testnum = 0; testnum < size_num; testnum++) {
3218 if (results[k][testnum] > 10000 && !mr)
3219 printf(" %11.2fk", results[k][testnum] / 1e3);
3221 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3225 #ifndef OPENSSL_NO_RSA
3227 for (k = 0; k < RSA_NUM; k++) {
3230 if (testnum && !mr) {
3231 printf("%18ssign verify sign/s verify/s\n", " ");
3235 printf("+F2:%u:%u:%f:%f\n",
3236 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
3238 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3239 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3240 rsa_results[k][0], rsa_results[k][1]);
3243 #ifndef OPENSSL_NO_DSA
3245 for (k = 0; k < DSA_NUM; k++) {
3248 if (testnum && !mr) {
3249 printf("%18ssign verify sign/s verify/s\n", " ");
3253 printf("+F3:%u:%u:%f:%f\n",
3254 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3256 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3257 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3258 dsa_results[k][0], dsa_results[k][1]);
3261 #ifndef OPENSSL_NO_EC
3263 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3266 if (testnum && !mr) {
3267 printf("%30ssign verify sign/s verify/s\n", " ");
3272 printf("+F4:%u:%u:%f:%f\n",
3273 k, test_curves[k].bits,
3274 ecdsa_results[k][0], ecdsa_results[k][1]);
3276 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3277 test_curves[k].bits, test_curves[k].name,
3278 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3279 ecdsa_results[k][0], ecdsa_results[k][1]);
3283 for (k = 0; k < EC_NUM; k++) {
3286 if (testnum && !mr) {
3287 printf("%30sop op/s\n", " ");
3291 printf("+F5:%u:%u:%f:%f\n",
3292 k, test_curves[k].bits,
3293 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3296 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3297 test_curves[k].bits, test_curves[k].name,
3298 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3302 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
3305 if (testnum && !mr) {
3306 printf("%30ssign verify sign/s verify/s\n", " ");
3311 printf("+F6:%u:%u:%s:%f:%f\n",
3312 k, test_ed_curves[k].bits, test_ed_curves[k].name,
3313 eddsa_results[k][0], eddsa_results[k][1]);
3315 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3316 test_ed_curves[k].bits, test_ed_curves[k].name,
3317 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
3318 eddsa_results[k][0], eddsa_results[k][1]);
3325 ERR_print_errors(bio_err);
3326 for (i = 0; i < loopargs_len; i++) {
3327 OPENSSL_free(loopargs[i].buf_malloc);
3328 OPENSSL_free(loopargs[i].buf2_malloc);
3330 #ifndef OPENSSL_NO_RSA
3331 for (k = 0; k < RSA_NUM; k++)
3332 RSA_free(loopargs[i].rsa_key[k]);
3334 #ifndef OPENSSL_NO_DSA
3335 for (k = 0; k < DSA_NUM; k++)
3336 DSA_free(loopargs[i].dsa_key[k]);
3338 #ifndef OPENSSL_NO_EC
3339 for (k = 0; k < ECDSA_NUM; k++)
3340 EC_KEY_free(loopargs[i].ecdsa[k]);
3341 for (k = 0; k < EC_NUM; k++)
3342 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3343 for (k = 0; k < EdDSA_NUM; k++)
3344 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
3345 OPENSSL_free(loopargs[i].secret_a);
3346 OPENSSL_free(loopargs[i].secret_b);
3350 if (async_jobs > 0) {
3351 for (i = 0; i < loopargs_len; i++)
3352 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3356 ASYNC_cleanup_thread();
3358 OPENSSL_free(loopargs);
3363 static void print_message(const char *s, long num, int length, int tm)
3367 mr ? "+DT:%s:%d:%d\n"
3368 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3369 (void)BIO_flush(bio_err);
3373 mr ? "+DN:%s:%ld:%d\n"
3374 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3375 (void)BIO_flush(bio_err);
3379 static void pkey_print_message(const char *str, const char *str2, long num,
3380 unsigned int bits, int tm)
3384 mr ? "+DTP:%d:%s:%s:%d\n"
3385 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
3386 (void)BIO_flush(bio_err);
3390 mr ? "+DNP:%ld:%d:%s:%s\n"
3391 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
3392 (void)BIO_flush(bio_err);
3396 static void print_result(int alg, int run_no, int count, double time_used)
3399 BIO_puts(bio_err, "EVP error!\n");
3403 mr ? "+R:%d:%s:%f\n"
3404 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3405 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3409 static char *sstrsep(char **string, const char *delim)
3412 char *token = *string;
3417 memset(isdelim, 0, sizeof(isdelim));
3421 isdelim[(unsigned char)(*delim)] = 1;
3425 while (!isdelim[(unsigned char)(**string)]) {
3437 static int do_multi(int multi, int size_num)
3442 static char sep[] = ":";
3444 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
3445 for (n = 0; n < multi; ++n) {
3446 if (pipe(fd) == -1) {
3447 BIO_printf(bio_err, "pipe failure\n");
3451 (void)BIO_flush(bio_err);
3458 if (dup(fd[1]) == -1) {
3459 BIO_printf(bio_err, "dup failed\n");
3468 printf("Forked child %d\n", n);
3471 /* for now, assume the pipe is long enough to take all the output */
3472 for (n = 0; n < multi; ++n) {
3477 f = fdopen(fds[n], "r");
3478 while (fgets(buf, sizeof(buf), f)) {
3479 p = strchr(buf, '\n');
3482 if (buf[0] != '+') {
3484 "Don't understand line '%s' from child %d\n", buf,
3488 printf("Got: %s from %d\n", buf, n);
3489 if (strncmp(buf, "+F:", 3) == 0) {
3494 alg = atoi(sstrsep(&p, sep));
3496 for (j = 0; j < size_num; ++j)
3497 results[alg][j] += atof(sstrsep(&p, sep));
3498 } else if (strncmp(buf, "+F2:", 4) == 0) {
3503 k = atoi(sstrsep(&p, sep));
3506 d = atof(sstrsep(&p, sep));
3507 rsa_results[k][0] += d;
3509 d = atof(sstrsep(&p, sep));
3510 rsa_results[k][1] += d;
3512 # ifndef OPENSSL_NO_DSA
3513 else if (strncmp(buf, "+F3:", 4) == 0) {
3518 k = atoi(sstrsep(&p, sep));
3521 d = atof(sstrsep(&p, sep));
3522 dsa_results[k][0] += d;
3524 d = atof(sstrsep(&p, sep));
3525 dsa_results[k][1] += d;
3528 # ifndef OPENSSL_NO_EC
3529 else if (strncmp(buf, "+F4:", 4) == 0) {
3534 k = atoi(sstrsep(&p, sep));
3537 d = atof(sstrsep(&p, sep));
3538 ecdsa_results[k][0] += d;
3540 d = atof(sstrsep(&p, sep));
3541 ecdsa_results[k][1] += d;
3542 } else if (strncmp(buf, "+F5:", 4) == 0) {
3547 k = atoi(sstrsep(&p, sep));
3550 d = atof(sstrsep(&p, sep));
3551 ecdh_results[k][0] += d;
3552 } else if (strncmp(buf, "+F6:", 4) == 0) {
3557 k = atoi(sstrsep(&p, sep));
3560 d = atof(sstrsep(&p, sep));
3561 eddsa_results[k][0] += d;
3563 d = atof(sstrsep(&p, sep));
3564 eddsa_results[k][1] += d;
3568 else if (strncmp(buf, "+H:", 3) == 0) {
3571 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3582 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
3583 const openssl_speed_sec_t *seconds)
3585 static const int mblengths_list[] =
3586 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3587 const int *mblengths = mblengths_list;
3588 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
3589 const char *alg_name;
3590 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
3591 EVP_CIPHER_CTX *ctx;
3594 if (lengths_single) {
3595 mblengths = &lengths_single;
3599 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3600 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3601 ctx = EVP_CIPHER_CTX_new();
3602 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
3604 keylen = EVP_CIPHER_CTX_key_length(ctx);
3605 key = app_malloc(keylen, "evp_cipher key");
3606 EVP_CIPHER_CTX_rand_key(ctx, key);
3607 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
3608 OPENSSL_clear_free(key, keylen);
3610 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3611 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3613 for (j = 0; j < num; j++) {
3614 print_message(alg_name, 0, mblengths[j], seconds->sym);
3616 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3617 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3618 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3619 size_t len = mblengths[j];
3622 memset(aad, 0, 8); /* avoid uninitialized values */
3623 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3624 aad[9] = 3; /* version */
3626 aad[11] = 0; /* length */
3628 mb_param.out = NULL;
3631 mb_param.interleave = 8;
3633 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3634 sizeof(mb_param), &mb_param);
3640 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3641 sizeof(mb_param), &mb_param);
3645 RAND_bytes(out, 16);
3647 aad[11] = (unsigned char)(len >> 8);
3648 aad[12] = (unsigned char)(len);
3649 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3650 EVP_AEAD_TLS1_AAD_LEN, aad);
3651 EVP_Cipher(ctx, out, inp, len + pad);
3655 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3656 : "%d %s's in %.2fs\n", count, "evp", d);
3657 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3661 fprintf(stdout, "+H");
3662 for (j = 0; j < num; j++)
3663 fprintf(stdout, ":%d", mblengths[j]);
3664 fprintf(stdout, "\n");
3665 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3666 for (j = 0; j < num; j++)
3667 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3668 fprintf(stdout, "\n");
3671 "The 'numbers' are in 1000s of bytes per second processed.\n");
3672 fprintf(stdout, "type ");
3673 for (j = 0; j < num; j++)
3674 fprintf(stdout, "%7d bytes", mblengths[j]);
3675 fprintf(stdout, "\n");
3676 fprintf(stdout, "%-24s", alg_name);
3678 for (j = 0; j < num; j++) {
3679 if (results[D_EVP][j] > 10000)
3680 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3682 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3684 fprintf(stdout, "\n");
3689 EVP_CIPHER_CTX_free(ctx);