2 * Copyright 1995-2019 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) || defined(OPENSSL_SYS_VXWORKS)
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;
604 #ifndef OPENSSL_NO_RSA
605 RSA *rsa_key[RSA_NUM];
607 #ifndef OPENSSL_NO_DSA
608 DSA *dsa_key[DSA_NUM];
610 #ifndef OPENSSL_NO_EC
611 EC_KEY *ecdsa[ECDSA_NUM];
612 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
613 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
614 unsigned char *secret_a;
615 unsigned char *secret_b;
616 size_t outlen[EC_NUM];
620 GCM128_CONTEXT *gcm_ctx;
622 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
623 loopargs_t * loopargs);
625 static unsigned int testnum;
627 /* Nb of iterations to do per algorithm and key-size */
628 static long c[ALGOR_NUM][OSSL_NELEM(lengths_list)];
630 #ifndef OPENSSL_NO_MD2
631 static int EVP_Digest_MD2_loop(void *args)
633 loopargs_t *tempargs = *(loopargs_t **) args;
634 unsigned char *buf = tempargs->buf;
635 unsigned char md2[MD2_DIGEST_LENGTH];
638 for (count = 0; COND(c[D_MD2][testnum]); count++) {
639 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
647 #ifndef OPENSSL_NO_MDC2
648 static int EVP_Digest_MDC2_loop(void *args)
650 loopargs_t *tempargs = *(loopargs_t **) args;
651 unsigned char *buf = tempargs->buf;
652 unsigned char mdc2[MDC2_DIGEST_LENGTH];
655 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
656 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
664 #ifndef OPENSSL_NO_MD4
665 static int EVP_Digest_MD4_loop(void *args)
667 loopargs_t *tempargs = *(loopargs_t **) args;
668 unsigned char *buf = tempargs->buf;
669 unsigned char md4[MD4_DIGEST_LENGTH];
672 for (count = 0; COND(c[D_MD4][testnum]); count++) {
673 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
681 #ifndef OPENSSL_NO_MD5
682 static int MD5_loop(void *args)
684 loopargs_t *tempargs = *(loopargs_t **) args;
685 unsigned char *buf = tempargs->buf;
686 unsigned char md5[MD5_DIGEST_LENGTH];
688 for (count = 0; COND(c[D_MD5][testnum]); count++)
689 MD5(buf, lengths[testnum], md5);
693 static int HMAC_loop(void *args)
695 loopargs_t *tempargs = *(loopargs_t **) args;
696 unsigned char *buf = tempargs->buf;
697 HMAC_CTX *hctx = tempargs->hctx;
698 unsigned char hmac[MD5_DIGEST_LENGTH];
701 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
702 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
703 HMAC_Update(hctx, buf, lengths[testnum]);
704 HMAC_Final(hctx, hmac, NULL);
710 static int SHA1_loop(void *args)
712 loopargs_t *tempargs = *(loopargs_t **) args;
713 unsigned char *buf = tempargs->buf;
714 unsigned char sha[SHA_DIGEST_LENGTH];
716 for (count = 0; COND(c[D_SHA1][testnum]); count++)
717 SHA1(buf, lengths[testnum], sha);
721 static int SHA256_loop(void *args)
723 loopargs_t *tempargs = *(loopargs_t **) args;
724 unsigned char *buf = tempargs->buf;
725 unsigned char sha256[SHA256_DIGEST_LENGTH];
727 for (count = 0; COND(c[D_SHA256][testnum]); count++)
728 SHA256(buf, lengths[testnum], sha256);
732 static int SHA512_loop(void *args)
734 loopargs_t *tempargs = *(loopargs_t **) args;
735 unsigned char *buf = tempargs->buf;
736 unsigned char sha512[SHA512_DIGEST_LENGTH];
738 for (count = 0; COND(c[D_SHA512][testnum]); count++)
739 SHA512(buf, lengths[testnum], sha512);
743 #ifndef OPENSSL_NO_WHIRLPOOL
744 static int WHIRLPOOL_loop(void *args)
746 loopargs_t *tempargs = *(loopargs_t **) args;
747 unsigned char *buf = tempargs->buf;
748 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
750 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
751 WHIRLPOOL(buf, lengths[testnum], whirlpool);
756 #ifndef OPENSSL_NO_RMD160
757 static int EVP_Digest_RMD160_loop(void *args)
759 loopargs_t *tempargs = *(loopargs_t **) args;
760 unsigned char *buf = tempargs->buf;
761 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
763 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
764 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
765 NULL, EVP_ripemd160(), NULL))
772 #ifndef OPENSSL_NO_RC4
773 static RC4_KEY rc4_ks;
774 static int RC4_loop(void *args)
776 loopargs_t *tempargs = *(loopargs_t **) args;
777 unsigned char *buf = tempargs->buf;
779 for (count = 0; COND(c[D_RC4][testnum]); count++)
780 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
785 #ifndef OPENSSL_NO_DES
786 static unsigned char DES_iv[8];
787 static DES_key_schedule sch;
788 static DES_key_schedule sch2;
789 static DES_key_schedule sch3;
790 static int DES_ncbc_encrypt_loop(void *args)
792 loopargs_t *tempargs = *(loopargs_t **) args;
793 unsigned char *buf = tempargs->buf;
795 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
796 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
797 &DES_iv, DES_ENCRYPT);
801 static int DES_ede3_cbc_encrypt_loop(void *args)
803 loopargs_t *tempargs = *(loopargs_t **) args;
804 unsigned char *buf = tempargs->buf;
806 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
807 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
808 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
813 #define MAX_BLOCK_SIZE 128
815 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
816 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
817 static int AES_cbc_128_encrypt_loop(void *args)
819 loopargs_t *tempargs = *(loopargs_t **) args;
820 unsigned char *buf = tempargs->buf;
822 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
823 AES_cbc_encrypt(buf, buf,
824 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
828 static int AES_cbc_192_encrypt_loop(void *args)
830 loopargs_t *tempargs = *(loopargs_t **) args;
831 unsigned char *buf = tempargs->buf;
833 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
834 AES_cbc_encrypt(buf, buf,
835 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
839 static int AES_cbc_256_encrypt_loop(void *args)
841 loopargs_t *tempargs = *(loopargs_t **) args;
842 unsigned char *buf = tempargs->buf;
844 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
845 AES_cbc_encrypt(buf, buf,
846 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
850 static int AES_ige_128_encrypt_loop(void *args)
852 loopargs_t *tempargs = *(loopargs_t **) args;
853 unsigned char *buf = tempargs->buf;
854 unsigned char *buf2 = tempargs->buf2;
856 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
857 AES_ige_encrypt(buf, buf2,
858 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
862 static int AES_ige_192_encrypt_loop(void *args)
864 loopargs_t *tempargs = *(loopargs_t **) args;
865 unsigned char *buf = tempargs->buf;
866 unsigned char *buf2 = tempargs->buf2;
868 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
869 AES_ige_encrypt(buf, buf2,
870 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
874 static int AES_ige_256_encrypt_loop(void *args)
876 loopargs_t *tempargs = *(loopargs_t **) args;
877 unsigned char *buf = tempargs->buf;
878 unsigned char *buf2 = tempargs->buf2;
880 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
881 AES_ige_encrypt(buf, buf2,
882 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
886 static int CRYPTO_gcm128_aad_loop(void *args)
888 loopargs_t *tempargs = *(loopargs_t **) args;
889 unsigned char *buf = tempargs->buf;
890 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
892 for (count = 0; COND(c[D_GHASH][testnum]); count++)
893 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
897 static int RAND_bytes_loop(void *args)
899 loopargs_t *tempargs = *(loopargs_t **) args;
900 unsigned char *buf = tempargs->buf;
903 for (count = 0; COND(c[D_RAND][testnum]); count++)
904 RAND_bytes(buf, lengths[testnum]);
908 static long save_count = 0;
909 static int decrypt = 0;
910 static int EVP_Update_loop(void *args)
912 loopargs_t *tempargs = *(loopargs_t **) args;
913 unsigned char *buf = tempargs->buf;
914 EVP_CIPHER_CTX *ctx = tempargs->ctx;
917 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
920 for (count = 0; COND(nb_iter); count++) {
921 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
923 /* reset iv in case of counter overflow */
924 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
928 for (count = 0; COND(nb_iter); count++) {
929 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
931 /* reset iv in case of counter overflow */
932 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
937 EVP_DecryptFinal_ex(ctx, buf, &outl);
939 EVP_EncryptFinal_ex(ctx, buf, &outl);
944 * CCM does not support streaming. For the purpose of performance measurement,
945 * each message is encrypted using the same (key,iv)-pair. Do not use this
946 * code in your application.
948 static int EVP_Update_loop_ccm(void *args)
950 loopargs_t *tempargs = *(loopargs_t **) args;
951 unsigned char *buf = tempargs->buf;
952 EVP_CIPHER_CTX *ctx = tempargs->ctx;
954 unsigned char tag[12];
956 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
959 for (count = 0; COND(nb_iter); count++) {
960 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
962 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
963 /* counter is reset on every update */
964 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
967 for (count = 0; COND(nb_iter); count++) {
968 /* restore iv length field */
969 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
970 /* counter is reset on every update */
971 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
975 EVP_DecryptFinal_ex(ctx, buf, &outl);
977 EVP_EncryptFinal_ex(ctx, buf, &outl);
982 * To make AEAD benchmarking more relevant perform TLS-like operations,
983 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
984 * payload length is not actually limited by 16KB...
986 static int EVP_Update_loop_aead(void *args)
988 loopargs_t *tempargs = *(loopargs_t **) args;
989 unsigned char *buf = tempargs->buf;
990 EVP_CIPHER_CTX *ctx = tempargs->ctx;
992 unsigned char aad[13] = { 0xcc };
993 unsigned char faketag[16] = { 0xcc };
995 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
998 for (count = 0; COND(nb_iter); count++) {
999 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
1000 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
1001 sizeof(faketag), faketag);
1002 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1003 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1004 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
1007 for (count = 0; COND(nb_iter); count++) {
1008 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
1009 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1010 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1011 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
1017 static const EVP_MD *evp_md = NULL;
1018 static int EVP_Digest_loop(void *args)
1020 loopargs_t *tempargs = *(loopargs_t **) args;
1021 unsigned char *buf = tempargs->buf;
1022 unsigned char md[EVP_MAX_MD_SIZE];
1025 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1028 for (count = 0; COND(nb_iter); count++) {
1029 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
1035 #ifndef OPENSSL_NO_RSA
1036 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1038 static int RSA_sign_loop(void *args)
1040 loopargs_t *tempargs = *(loopargs_t **) args;
1041 unsigned char *buf = tempargs->buf;
1042 unsigned char *buf2 = tempargs->buf2;
1043 unsigned int *rsa_num = &tempargs->siglen;
1044 RSA **rsa_key = tempargs->rsa_key;
1046 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1047 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1049 BIO_printf(bio_err, "RSA sign failure\n");
1050 ERR_print_errors(bio_err);
1058 static int RSA_verify_loop(void *args)
1060 loopargs_t *tempargs = *(loopargs_t **) args;
1061 unsigned char *buf = tempargs->buf;
1062 unsigned char *buf2 = tempargs->buf2;
1063 unsigned int rsa_num = tempargs->siglen;
1064 RSA **rsa_key = tempargs->rsa_key;
1066 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1068 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1070 BIO_printf(bio_err, "RSA verify failure\n");
1071 ERR_print_errors(bio_err);
1080 #ifndef OPENSSL_NO_DSA
1081 static long dsa_c[DSA_NUM][2];
1082 static int DSA_sign_loop(void *args)
1084 loopargs_t *tempargs = *(loopargs_t **) args;
1085 unsigned char *buf = tempargs->buf;
1086 unsigned char *buf2 = tempargs->buf2;
1087 DSA **dsa_key = tempargs->dsa_key;
1088 unsigned int *siglen = &tempargs->siglen;
1090 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1091 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1093 BIO_printf(bio_err, "DSA sign failure\n");
1094 ERR_print_errors(bio_err);
1102 static int DSA_verify_loop(void *args)
1104 loopargs_t *tempargs = *(loopargs_t **) args;
1105 unsigned char *buf = tempargs->buf;
1106 unsigned char *buf2 = tempargs->buf2;
1107 DSA **dsa_key = tempargs->dsa_key;
1108 unsigned int siglen = tempargs->siglen;
1110 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1111 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1113 BIO_printf(bio_err, "DSA verify failure\n");
1114 ERR_print_errors(bio_err);
1123 #ifndef OPENSSL_NO_EC
1124 static long ecdsa_c[ECDSA_NUM][2];
1125 static int ECDSA_sign_loop(void *args)
1127 loopargs_t *tempargs = *(loopargs_t **) args;
1128 unsigned char *buf = tempargs->buf;
1129 EC_KEY **ecdsa = tempargs->ecdsa;
1130 unsigned char *ecdsasig = tempargs->buf2;
1131 unsigned int *ecdsasiglen = &tempargs->siglen;
1133 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1134 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1136 BIO_printf(bio_err, "ECDSA sign failure\n");
1137 ERR_print_errors(bio_err);
1145 static int ECDSA_verify_loop(void *args)
1147 loopargs_t *tempargs = *(loopargs_t **) args;
1148 unsigned char *buf = tempargs->buf;
1149 EC_KEY **ecdsa = tempargs->ecdsa;
1150 unsigned char *ecdsasig = tempargs->buf2;
1151 unsigned int ecdsasiglen = tempargs->siglen;
1153 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1154 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1156 BIO_printf(bio_err, "ECDSA verify failure\n");
1157 ERR_print_errors(bio_err);
1165 /* ******************************************************************** */
1166 static long ecdh_c[EC_NUM][1];
1168 static int ECDH_EVP_derive_key_loop(void *args)
1170 loopargs_t *tempargs = *(loopargs_t **) args;
1171 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1172 unsigned char *derived_secret = tempargs->secret_a;
1174 size_t *outlen = &(tempargs->outlen[testnum]);
1176 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1177 EVP_PKEY_derive(ctx, derived_secret, outlen);
1182 static long eddsa_c[EdDSA_NUM][2];
1183 static int EdDSA_sign_loop(void *args)
1185 loopargs_t *tempargs = *(loopargs_t **) args;
1186 unsigned char *buf = tempargs->buf;
1187 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1188 unsigned char *eddsasig = tempargs->buf2;
1189 size_t *eddsasigsize = &tempargs->sigsize;
1192 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1193 ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1195 BIO_printf(bio_err, "EdDSA sign failure\n");
1196 ERR_print_errors(bio_err);
1204 static int EdDSA_verify_loop(void *args)
1206 loopargs_t *tempargs = *(loopargs_t **) args;
1207 unsigned char *buf = tempargs->buf;
1208 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1209 unsigned char *eddsasig = tempargs->buf2;
1210 size_t eddsasigsize = tempargs->sigsize;
1213 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1214 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1216 BIO_printf(bio_err, "EdDSA verify failure\n");
1217 ERR_print_errors(bio_err);
1224 #endif /* OPENSSL_NO_EC */
1226 static int run_benchmark(int async_jobs,
1227 int (*loop_function) (void *), loopargs_t * loopargs)
1229 int job_op_count = 0;
1230 int total_op_count = 0;
1231 int num_inprogress = 0;
1232 int error = 0, i = 0, ret = 0;
1233 OSSL_ASYNC_FD job_fd = 0;
1234 size_t num_job_fds = 0;
1238 if (async_jobs == 0) {
1239 return loop_function((void *)&loopargs);
1242 for (i = 0; i < async_jobs && !error; i++) {
1243 loopargs_t *looparg_item = loopargs + i;
1245 /* Copy pointer content (looparg_t item address) into async context */
1246 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1247 &job_op_count, loop_function,
1248 (void *)&looparg_item, sizeof(looparg_item));
1254 if (job_op_count == -1) {
1257 total_op_count += job_op_count;
1262 BIO_printf(bio_err, "Failure in the job\n");
1263 ERR_print_errors(bio_err);
1269 while (num_inprogress > 0) {
1270 #if defined(OPENSSL_SYS_WINDOWS)
1272 #elif defined(OPENSSL_SYS_UNIX)
1273 int select_result = 0;
1274 OSSL_ASYNC_FD max_fd = 0;
1277 FD_ZERO(&waitfdset);
1279 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1280 if (loopargs[i].inprogress_job == NULL)
1283 if (!ASYNC_WAIT_CTX_get_all_fds
1284 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1285 || num_job_fds > 1) {
1286 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1287 ERR_print_errors(bio_err);
1291 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1293 FD_SET(job_fd, &waitfdset);
1294 if (job_fd > max_fd)
1298 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1300 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1301 "Decrease the value of async_jobs\n",
1302 max_fd, FD_SETSIZE);
1303 ERR_print_errors(bio_err);
1308 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1309 if (select_result == -1 && errno == EINTR)
1312 if (select_result == -1) {
1313 BIO_printf(bio_err, "Failure in the select\n");
1314 ERR_print_errors(bio_err);
1319 if (select_result == 0)
1323 for (i = 0; i < async_jobs; i++) {
1324 if (loopargs[i].inprogress_job == NULL)
1327 if (!ASYNC_WAIT_CTX_get_all_fds
1328 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1329 || num_job_fds > 1) {
1330 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1331 ERR_print_errors(bio_err);
1335 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1338 #if defined(OPENSSL_SYS_UNIX)
1339 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1341 #elif defined(OPENSSL_SYS_WINDOWS)
1342 if (num_job_fds == 1
1343 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1348 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1349 loopargs[i].wait_ctx, &job_op_count,
1350 loop_function, (void *)(loopargs + i),
1351 sizeof(loopargs_t));
1356 if (job_op_count == -1) {
1359 total_op_count += job_op_count;
1362 loopargs[i].inprogress_job = NULL;
1367 loopargs[i].inprogress_job = NULL;
1368 BIO_printf(bio_err, "Failure in the job\n");
1369 ERR_print_errors(bio_err);
1376 return error ? -1 : total_op_count;
1379 int speed_main(int argc, char **argv)
1382 loopargs_t *loopargs = NULL;
1384 const char *engine_id = NULL;
1385 const EVP_CIPHER *evp_cipher = NULL;
1388 int async_init = 0, multiblock = 0, pr_header = 0;
1389 int doit[ALGOR_NUM] = { 0 };
1390 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1392 unsigned int size_num = OSSL_NELEM(lengths_list);
1393 unsigned int i, k, loop, loopargs_len = 0, async_jobs = 0;
1399 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1400 || !defined(OPENSSL_NO_EC)
1403 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1404 ECDSA_SECONDS, ECDH_SECONDS,
1407 /* What follows are the buffers and key material. */
1408 #ifndef OPENSSL_NO_RC5
1411 #ifndef OPENSSL_NO_RC2
1414 #ifndef OPENSSL_NO_IDEA
1415 IDEA_KEY_SCHEDULE idea_ks;
1417 #ifndef OPENSSL_NO_SEED
1418 SEED_KEY_SCHEDULE seed_ks;
1420 #ifndef OPENSSL_NO_BF
1423 #ifndef OPENSSL_NO_CAST
1426 static const unsigned char key16[16] = {
1427 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1428 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1430 static const unsigned char key24[24] = {
1431 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1432 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1433 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1435 static const unsigned char key32[32] = {
1436 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1437 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1438 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1439 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1441 #ifndef OPENSSL_NO_CAMELLIA
1442 static const unsigned char ckey24[24] = {
1443 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1444 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1445 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1447 static const unsigned char ckey32[32] = {
1448 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1449 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1450 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1451 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1453 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1455 #ifndef OPENSSL_NO_DES
1456 static DES_cblock key = {
1457 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1459 static DES_cblock key2 = {
1460 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1462 static DES_cblock key3 = {
1463 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1466 #ifndef OPENSSL_NO_RSA
1467 static const unsigned int rsa_bits[RSA_NUM] = {
1468 512, 1024, 2048, 3072, 4096, 7680, 15360
1470 static const unsigned char *rsa_data[RSA_NUM] = {
1471 test512, test1024, test2048, test3072, test4096, test7680, test15360
1473 static const int rsa_data_length[RSA_NUM] = {
1474 sizeof(test512), sizeof(test1024),
1475 sizeof(test2048), sizeof(test3072),
1476 sizeof(test4096), sizeof(test7680),
1479 int rsa_doit[RSA_NUM] = { 0 };
1480 int primes = RSA_DEFAULT_PRIME_NUM;
1482 #ifndef OPENSSL_NO_DSA
1483 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1484 int dsa_doit[DSA_NUM] = { 0 };
1486 #ifndef OPENSSL_NO_EC
1488 * We only test over the following curves as they are representative, To
1489 * add tests over more curves, simply add the curve NID and curve name to
1490 * the following arrays and increase the |ecdh_choices| list accordingly.
1492 static const struct {
1498 {"secp160r1", NID_secp160r1, 160},
1499 {"nistp192", NID_X9_62_prime192v1, 192},
1500 {"nistp224", NID_secp224r1, 224},
1501 {"nistp256", NID_X9_62_prime256v1, 256},
1502 {"nistp384", NID_secp384r1, 384},
1503 {"nistp521", NID_secp521r1, 521},
1505 {"nistk163", NID_sect163k1, 163},
1506 {"nistk233", NID_sect233k1, 233},
1507 {"nistk283", NID_sect283k1, 283},
1508 {"nistk409", NID_sect409k1, 409},
1509 {"nistk571", NID_sect571k1, 571},
1510 {"nistb163", NID_sect163r2, 163},
1511 {"nistb233", NID_sect233r1, 233},
1512 {"nistb283", NID_sect283r1, 283},
1513 {"nistb409", NID_sect409r1, 409},
1514 {"nistb571", NID_sect571r1, 571},
1515 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1516 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1517 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1518 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1519 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1520 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1521 /* Other and ECDH only ones */
1522 {"X25519", NID_X25519, 253},
1523 {"X448", NID_X448, 448}
1525 static const struct {
1530 } test_ed_curves[] = {
1532 {"Ed25519", NID_ED25519, 253, 64},
1533 {"Ed448", NID_ED448, 456, 114}
1535 int ecdsa_doit[ECDSA_NUM] = { 0 };
1536 int ecdh_doit[EC_NUM] = { 0 };
1537 int eddsa_doit[EdDSA_NUM] = { 0 };
1538 OPENSSL_assert(OSSL_NELEM(test_curves) >= EC_NUM);
1539 OPENSSL_assert(OSSL_NELEM(test_ed_curves) >= EdDSA_NUM);
1540 #endif /* ndef OPENSSL_NO_EC */
1542 prog = opt_init(argc, argv, speed_options);
1543 while ((o = opt_next()) != OPT_EOF) {
1548 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1551 opt_help(speed_options);
1559 evp_cipher = EVP_get_cipherbyname(opt_arg());
1560 if (evp_cipher == NULL)
1561 evp_md = EVP_get_digestbyname(opt_arg());
1562 if (evp_cipher == NULL && evp_md == NULL) {
1564 "%s: %s is an unknown cipher or digest\n",
1575 * In a forked execution, an engine might need to be
1576 * initialised by each child process, not by the parent.
1577 * So store the name here and run setup_engine() later on.
1579 engine_id = opt_arg();
1583 multi = atoi(opt_arg());
1587 #ifndef OPENSSL_NO_ASYNC
1588 async_jobs = atoi(opt_arg());
1589 if (!ASYNC_is_capable()) {
1591 "%s: async_jobs specified but async not supported\n",
1595 if (async_jobs > 99999) {
1596 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1602 if (!opt_int(opt_arg(), &misalign))
1604 if (misalign > MISALIGN) {
1606 "%s: Maximum offset is %d\n", prog, MISALIGN);
1615 #ifdef OPENSSL_NO_MULTIBLOCK
1617 "%s: -mb specified but multi-block support is disabled\n",
1627 if (!opt_int(opt_arg(), &primes))
1631 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1632 = seconds.ecdh = seconds.eddsa = atoi(opt_arg());
1635 lengths_single = atoi(opt_arg());
1636 lengths = &lengths_single;
1644 argc = opt_num_rest();
1647 /* Remaining arguments are algorithms. */
1648 for (; *argv; argv++) {
1649 if (found(*argv, doit_choices, &i)) {
1653 #ifndef OPENSSL_NO_DES
1654 if (strcmp(*argv, "des") == 0) {
1655 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1659 if (strcmp(*argv, "sha") == 0) {
1660 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1663 #ifndef OPENSSL_NO_RSA
1664 if (strcmp(*argv, "openssl") == 0)
1666 if (strcmp(*argv, "rsa") == 0) {
1667 for (loop = 0; loop < OSSL_NELEM(rsa_doit); loop++)
1671 if (found(*argv, rsa_choices, &i)) {
1676 #ifndef OPENSSL_NO_DSA
1677 if (strcmp(*argv, "dsa") == 0) {
1678 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1679 dsa_doit[R_DSA_2048] = 1;
1682 if (found(*argv, dsa_choices, &i)) {
1687 if (strcmp(*argv, "aes") == 0) {
1688 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1691 #ifndef OPENSSL_NO_CAMELLIA
1692 if (strcmp(*argv, "camellia") == 0) {
1693 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1697 #ifndef OPENSSL_NO_EC
1698 if (strcmp(*argv, "ecdsa") == 0) {
1699 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1700 ecdsa_doit[loop] = 1;
1703 if (found(*argv, ecdsa_choices, &i)) {
1707 if (strcmp(*argv, "ecdh") == 0) {
1708 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1709 ecdh_doit[loop] = 1;
1712 if (found(*argv, ecdh_choices, &i)) {
1716 if (strcmp(*argv, "eddsa") == 0) {
1717 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1718 eddsa_doit[loop] = 1;
1721 if (found(*argv, eddsa_choices, &i)) {
1726 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1732 if (evp_cipher == NULL) {
1733 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1735 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1736 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1737 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1738 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1743 if (evp_cipher == NULL) {
1744 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1745 " capable cipher\n");
1747 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1748 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1749 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1750 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1752 } else if (async_jobs > 0) {
1753 BIO_printf(bio_err, "Async mode is not supported with -mb");
1758 /* Initialize the job pool if async mode is enabled */
1759 if (async_jobs > 0) {
1760 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1762 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1767 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1769 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1770 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1772 for (i = 0; i < loopargs_len; i++) {
1773 if (async_jobs > 0) {
1774 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1775 if (loopargs[i].wait_ctx == NULL) {
1776 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1781 buflen = lengths[size_num - 1];
1782 if (buflen < 36) /* size of random vector in RSA bencmark */
1784 buflen += MAX_MISALIGNMENT + 1;
1785 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1786 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1787 memset(loopargs[i].buf_malloc, 0, buflen);
1788 memset(loopargs[i].buf2_malloc, 0, buflen);
1790 /* Align the start of buffers on a 64 byte boundary */
1791 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1792 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1793 #ifndef OPENSSL_NO_EC
1794 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1795 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1800 if (multi && do_multi(multi, size_num))
1804 /* Initialize the engine after the fork */
1805 e = setup_engine(engine_id, 0);
1807 /* No parameters; turn on everything. */
1808 if ((argc == 0) && !doit[D_EVP]) {
1809 for (i = 0; i < ALGOR_NUM; i++)
1812 #ifndef OPENSSL_NO_RSA
1813 for (i = 0; i < RSA_NUM; i++)
1816 #ifndef OPENSSL_NO_DSA
1817 for (i = 0; i < DSA_NUM; i++)
1820 #ifndef OPENSSL_NO_EC
1821 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1822 ecdsa_doit[loop] = 1;
1823 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1824 ecdh_doit[loop] = 1;
1825 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1826 eddsa_doit[loop] = 1;
1829 for (i = 0; i < ALGOR_NUM; i++)
1833 if (usertime == 0 && !mr)
1835 "You have chosen to measure elapsed time "
1836 "instead of user CPU time.\n");
1838 #ifndef OPENSSL_NO_RSA
1839 for (i = 0; i < loopargs_len; i++) {
1840 if (primes > RSA_DEFAULT_PRIME_NUM) {
1841 /* for multi-prime RSA, skip this */
1844 for (k = 0; k < RSA_NUM; k++) {
1845 const unsigned char *p;
1848 loopargs[i].rsa_key[k] =
1849 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1850 if (loopargs[i].rsa_key[k] == NULL) {
1852 "internal error loading RSA key number %d\n", k);
1858 #ifndef OPENSSL_NO_DSA
1859 for (i = 0; i < loopargs_len; i++) {
1860 loopargs[i].dsa_key[0] = get_dsa(512);
1861 loopargs[i].dsa_key[1] = get_dsa(1024);
1862 loopargs[i].dsa_key[2] = get_dsa(2048);
1865 #ifndef OPENSSL_NO_DES
1866 DES_set_key_unchecked(&key, &sch);
1867 DES_set_key_unchecked(&key2, &sch2);
1868 DES_set_key_unchecked(&key3, &sch3);
1870 AES_set_encrypt_key(key16, 128, &aes_ks1);
1871 AES_set_encrypt_key(key24, 192, &aes_ks2);
1872 AES_set_encrypt_key(key32, 256, &aes_ks3);
1873 #ifndef OPENSSL_NO_CAMELLIA
1874 Camellia_set_key(key16, 128, &camellia_ks1);
1875 Camellia_set_key(ckey24, 192, &camellia_ks2);
1876 Camellia_set_key(ckey32, 256, &camellia_ks3);
1878 #ifndef OPENSSL_NO_IDEA
1879 IDEA_set_encrypt_key(key16, &idea_ks);
1881 #ifndef OPENSSL_NO_SEED
1882 SEED_set_key(key16, &seed_ks);
1884 #ifndef OPENSSL_NO_RC4
1885 RC4_set_key(&rc4_ks, 16, key16);
1887 #ifndef OPENSSL_NO_RC2
1888 RC2_set_key(&rc2_ks, 16, key16, 128);
1890 #ifndef OPENSSL_NO_RC5
1891 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1893 #ifndef OPENSSL_NO_BF
1894 BF_set_key(&bf_ks, 16, key16);
1896 #ifndef OPENSSL_NO_CAST
1897 CAST_set_key(&cast_ks, 16, key16);
1900 # ifndef OPENSSL_NO_DES
1901 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1907 for (it = count; it; it--)
1908 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1909 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1913 c[D_MD2][0] = count / 10;
1914 c[D_MDC2][0] = count / 10;
1915 c[D_MD4][0] = count;
1916 c[D_MD5][0] = count;
1917 c[D_HMAC][0] = count;
1918 c[D_SHA1][0] = count;
1919 c[D_RMD160][0] = count;
1920 c[D_RC4][0] = count * 5;
1921 c[D_CBC_DES][0] = count;
1922 c[D_EDE3_DES][0] = count / 3;
1923 c[D_CBC_IDEA][0] = count;
1924 c[D_CBC_SEED][0] = count;
1925 c[D_CBC_RC2][0] = count;
1926 c[D_CBC_RC5][0] = count;
1927 c[D_CBC_BF][0] = count;
1928 c[D_CBC_CAST][0] = count;
1929 c[D_CBC_128_AES][0] = count;
1930 c[D_CBC_192_AES][0] = count;
1931 c[D_CBC_256_AES][0] = count;
1932 c[D_CBC_128_CML][0] = count;
1933 c[D_CBC_192_CML][0] = count;
1934 c[D_CBC_256_CML][0] = count;
1935 c[D_SHA256][0] = count;
1936 c[D_SHA512][0] = count;
1937 c[D_WHIRLPOOL][0] = count;
1938 c[D_IGE_128_AES][0] = count;
1939 c[D_IGE_192_AES][0] = count;
1940 c[D_IGE_256_AES][0] = count;
1941 c[D_GHASH][0] = count;
1942 c[D_RAND][0] = count;
1944 for (i = 1; i < size_num; i++) {
1947 l0 = (long)lengths[0];
1948 l1 = (long)lengths[i];
1950 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1951 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1952 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1953 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1954 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1955 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1956 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1957 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1958 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1959 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1960 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1961 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
1963 l0 = (long)lengths[i - 1];
1965 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1966 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1967 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1968 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1969 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1970 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1971 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1972 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1973 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1974 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1975 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1976 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1977 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1978 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1979 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1980 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1981 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1982 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1985 # ifndef OPENSSL_NO_RSA
1986 rsa_c[R_RSA_512][0] = count / 2000;
1987 rsa_c[R_RSA_512][1] = count / 400;
1988 for (i = 1; i < RSA_NUM; i++) {
1989 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1990 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1991 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1994 if (rsa_c[i][0] == 0) {
1995 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2002 # ifndef OPENSSL_NO_DSA
2003 dsa_c[R_DSA_512][0] = count / 1000;
2004 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2005 for (i = 1; i < DSA_NUM; i++) {
2006 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2007 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2008 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2011 if (dsa_c[i][0] == 0) {
2012 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2019 # ifndef OPENSSL_NO_EC
2020 ecdsa_c[R_EC_P160][0] = count / 1000;
2021 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2022 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2023 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2024 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2025 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2028 if (ecdsa_c[i][0] == 0) {
2034 ecdsa_c[R_EC_K163][0] = count / 1000;
2035 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2036 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2037 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2038 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2039 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2042 if (ecdsa_c[i][0] == 0) {
2048 ecdsa_c[R_EC_B163][0] = count / 1000;
2049 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2050 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2051 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2052 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2053 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2056 if (ecdsa_c[i][0] == 0) {
2063 ecdh_c[R_EC_P160][0] = count / 1000;
2064 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2065 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2066 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2069 if (ecdh_c[i][0] == 0) {
2074 ecdh_c[R_EC_K163][0] = count / 1000;
2075 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2076 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2077 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2080 if (ecdh_c[i][0] == 0) {
2085 ecdh_c[R_EC_B163][0] = count / 1000;
2086 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2087 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2088 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2091 if (ecdh_c[i][0] == 0) {
2096 /* repeated code good to factorize */
2097 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2098 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2099 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2100 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2103 if (ecdh_c[i][0] == 0) {
2108 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2109 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2110 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2111 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2114 if (ecdh_c[i][0] == 0) {
2119 /* default iteration count for the last two EC Curves */
2120 ecdh_c[R_EC_X25519][0] = count / 1800;
2121 ecdh_c[R_EC_X448][0] = count / 7200;
2123 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2124 eddsa_c[R_EC_Ed448][0] = count / 7200;
2128 /* not worth fixing */
2129 # error "You cannot disable DES on systems without SIGALRM."
2130 # endif /* OPENSSL_NO_DES */
2132 signal(SIGALRM, alarmed);
2133 #endif /* SIGALRM */
2135 #ifndef OPENSSL_NO_MD2
2137 for (testnum = 0; testnum < size_num; testnum++) {
2138 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2141 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2143 print_result(D_MD2, testnum, count, d);
2147 #ifndef OPENSSL_NO_MDC2
2149 for (testnum = 0; testnum < size_num; testnum++) {
2150 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2153 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2155 print_result(D_MDC2, testnum, count, d);
2160 #ifndef OPENSSL_NO_MD4
2162 for (testnum = 0; testnum < size_num; testnum++) {
2163 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2166 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2168 print_result(D_MD4, testnum, count, d);
2173 #ifndef OPENSSL_NO_MD5
2175 for (testnum = 0; testnum < size_num; testnum++) {
2176 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2179 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2181 print_result(D_MD5, testnum, count, d);
2186 static const char hmac_key[] = "This is a key...";
2187 int len = strlen(hmac_key);
2189 for (i = 0; i < loopargs_len; i++) {
2190 loopargs[i].hctx = HMAC_CTX_new();
2191 if (loopargs[i].hctx == NULL) {
2192 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2196 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2198 for (testnum = 0; testnum < size_num; testnum++) {
2199 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2202 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2204 print_result(D_HMAC, testnum, count, d);
2206 for (i = 0; i < loopargs_len; i++) {
2207 HMAC_CTX_free(loopargs[i].hctx);
2212 for (testnum = 0; testnum < size_num; testnum++) {
2213 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2216 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2218 print_result(D_SHA1, testnum, count, d);
2221 if (doit[D_SHA256]) {
2222 for (testnum = 0; testnum < size_num; testnum++) {
2223 print_message(names[D_SHA256], c[D_SHA256][testnum],
2224 lengths[testnum], seconds.sym);
2226 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2228 print_result(D_SHA256, testnum, count, d);
2231 if (doit[D_SHA512]) {
2232 for (testnum = 0; testnum < size_num; testnum++) {
2233 print_message(names[D_SHA512], c[D_SHA512][testnum],
2234 lengths[testnum], seconds.sym);
2236 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2238 print_result(D_SHA512, testnum, count, d);
2241 #ifndef OPENSSL_NO_WHIRLPOOL
2242 if (doit[D_WHIRLPOOL]) {
2243 for (testnum = 0; testnum < size_num; testnum++) {
2244 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2245 lengths[testnum], seconds.sym);
2247 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2249 print_result(D_WHIRLPOOL, testnum, count, d);
2254 #ifndef OPENSSL_NO_RMD160
2255 if (doit[D_RMD160]) {
2256 for (testnum = 0; testnum < size_num; testnum++) {
2257 print_message(names[D_RMD160], c[D_RMD160][testnum],
2258 lengths[testnum], seconds.sym);
2260 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2262 print_result(D_RMD160, testnum, count, d);
2266 #ifndef OPENSSL_NO_RC4
2268 for (testnum = 0; testnum < size_num; testnum++) {
2269 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2272 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2274 print_result(D_RC4, testnum, count, d);
2278 #ifndef OPENSSL_NO_DES
2279 if (doit[D_CBC_DES]) {
2280 for (testnum = 0; testnum < size_num; testnum++) {
2281 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2282 lengths[testnum], seconds.sym);
2284 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2286 print_result(D_CBC_DES, testnum, count, d);
2290 if (doit[D_EDE3_DES]) {
2291 for (testnum = 0; testnum < size_num; testnum++) {
2292 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2293 lengths[testnum], seconds.sym);
2296 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2298 print_result(D_EDE3_DES, testnum, count, d);
2303 if (doit[D_CBC_128_AES]) {
2304 for (testnum = 0; testnum < size_num; testnum++) {
2305 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2306 lengths[testnum], seconds.sym);
2309 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2311 print_result(D_CBC_128_AES, testnum, count, d);
2314 if (doit[D_CBC_192_AES]) {
2315 for (testnum = 0; testnum < size_num; testnum++) {
2316 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2317 lengths[testnum], seconds.sym);
2320 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2322 print_result(D_CBC_192_AES, testnum, count, d);
2325 if (doit[D_CBC_256_AES]) {
2326 for (testnum = 0; testnum < size_num; testnum++) {
2327 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2328 lengths[testnum], seconds.sym);
2331 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2333 print_result(D_CBC_256_AES, testnum, count, d);
2337 if (doit[D_IGE_128_AES]) {
2338 for (testnum = 0; testnum < size_num; testnum++) {
2339 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2340 lengths[testnum], seconds.sym);
2343 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2345 print_result(D_IGE_128_AES, testnum, count, d);
2348 if (doit[D_IGE_192_AES]) {
2349 for (testnum = 0; testnum < size_num; testnum++) {
2350 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2351 lengths[testnum], seconds.sym);
2354 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2356 print_result(D_IGE_192_AES, testnum, count, d);
2359 if (doit[D_IGE_256_AES]) {
2360 for (testnum = 0; testnum < size_num; testnum++) {
2361 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2362 lengths[testnum], seconds.sym);
2365 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2367 print_result(D_IGE_256_AES, testnum, count, d);
2370 if (doit[D_GHASH]) {
2371 for (i = 0; i < loopargs_len; i++) {
2372 loopargs[i].gcm_ctx =
2373 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2374 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2375 (unsigned char *)"0123456789ab", 12);
2378 for (testnum = 0; testnum < size_num; testnum++) {
2379 print_message(names[D_GHASH], c[D_GHASH][testnum],
2380 lengths[testnum], seconds.sym);
2382 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2384 print_result(D_GHASH, testnum, count, d);
2386 for (i = 0; i < loopargs_len; i++)
2387 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2389 #ifndef OPENSSL_NO_CAMELLIA
2390 if (doit[D_CBC_128_CML]) {
2391 if (async_jobs > 0) {
2392 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2393 names[D_CBC_128_CML]);
2394 doit[D_CBC_128_CML] = 0;
2396 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2397 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2398 lengths[testnum], seconds.sym);
2400 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2401 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2402 (size_t)lengths[testnum], &camellia_ks1,
2403 iv, CAMELLIA_ENCRYPT);
2405 print_result(D_CBC_128_CML, testnum, count, d);
2408 if (doit[D_CBC_192_CML]) {
2409 if (async_jobs > 0) {
2410 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2411 names[D_CBC_192_CML]);
2412 doit[D_CBC_192_CML] = 0;
2414 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2415 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2416 lengths[testnum], seconds.sym);
2417 if (async_jobs > 0) {
2418 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2422 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2423 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2424 (size_t)lengths[testnum], &camellia_ks2,
2425 iv, CAMELLIA_ENCRYPT);
2427 print_result(D_CBC_192_CML, testnum, count, d);
2430 if (doit[D_CBC_256_CML]) {
2431 if (async_jobs > 0) {
2432 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2433 names[D_CBC_256_CML]);
2434 doit[D_CBC_256_CML] = 0;
2436 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2437 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2438 lengths[testnum], seconds.sym);
2440 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2441 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2442 (size_t)lengths[testnum], &camellia_ks3,
2443 iv, CAMELLIA_ENCRYPT);
2445 print_result(D_CBC_256_CML, testnum, count, d);
2449 #ifndef OPENSSL_NO_IDEA
2450 if (doit[D_CBC_IDEA]) {
2451 if (async_jobs > 0) {
2452 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2454 doit[D_CBC_IDEA] = 0;
2456 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2457 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2458 lengths[testnum], seconds.sym);
2460 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2461 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2462 (size_t)lengths[testnum], &idea_ks,
2465 print_result(D_CBC_IDEA, testnum, count, d);
2469 #ifndef OPENSSL_NO_SEED
2470 if (doit[D_CBC_SEED]) {
2471 if (async_jobs > 0) {
2472 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2474 doit[D_CBC_SEED] = 0;
2476 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2477 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2478 lengths[testnum], seconds.sym);
2480 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2481 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2482 (size_t)lengths[testnum], &seed_ks, iv, 1);
2484 print_result(D_CBC_SEED, testnum, count, d);
2488 #ifndef OPENSSL_NO_RC2
2489 if (doit[D_CBC_RC2]) {
2490 if (async_jobs > 0) {
2491 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2493 doit[D_CBC_RC2] = 0;
2495 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2496 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2497 lengths[testnum], seconds.sym);
2498 if (async_jobs > 0) {
2499 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2503 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2504 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2505 (size_t)lengths[testnum], &rc2_ks,
2508 print_result(D_CBC_RC2, testnum, count, d);
2512 #ifndef OPENSSL_NO_RC5
2513 if (doit[D_CBC_RC5]) {
2514 if (async_jobs > 0) {
2515 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2517 doit[D_CBC_RC5] = 0;
2519 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2520 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2521 lengths[testnum], seconds.sym);
2522 if (async_jobs > 0) {
2523 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2527 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2528 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2529 (size_t)lengths[testnum], &rc5_ks,
2532 print_result(D_CBC_RC5, testnum, count, d);
2536 #ifndef OPENSSL_NO_BF
2537 if (doit[D_CBC_BF]) {
2538 if (async_jobs > 0) {
2539 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2543 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2544 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2545 lengths[testnum], seconds.sym);
2547 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2548 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2549 (size_t)lengths[testnum], &bf_ks,
2552 print_result(D_CBC_BF, testnum, count, d);
2556 #ifndef OPENSSL_NO_CAST
2557 if (doit[D_CBC_CAST]) {
2558 if (async_jobs > 0) {
2559 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2561 doit[D_CBC_CAST] = 0;
2563 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2564 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2565 lengths[testnum], seconds.sym);
2567 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2568 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2569 (size_t)lengths[testnum], &cast_ks,
2572 print_result(D_CBC_CAST, testnum, count, d);
2577 for (testnum = 0; testnum < size_num; testnum++) {
2578 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2581 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2583 print_result(D_RAND, testnum, count, d);
2588 if (evp_cipher != NULL) {
2589 int (*loopfunc)(void *args) = EVP_Update_loop;
2591 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2592 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2593 multiblock_speed(evp_cipher, lengths_single, &seconds);
2598 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2600 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2601 loopfunc = EVP_Update_loop_ccm;
2602 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2603 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2604 loopfunc = EVP_Update_loop_aead;
2605 if (lengths == lengths_list) {
2606 lengths = aead_lengths_list;
2607 size_num = OSSL_NELEM(aead_lengths_list);
2611 for (testnum = 0; testnum < size_num; testnum++) {
2612 print_message(names[D_EVP], save_count, lengths[testnum],
2615 for (k = 0; k < loopargs_len; k++) {
2616 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2617 EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
2618 iv, decrypt ? 0 : 1);
2620 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2622 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2623 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2624 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2625 EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2626 loopargs[k].key, NULL, -1);
2627 OPENSSL_clear_free(loopargs[k].key, keylen);
2631 count = run_benchmark(async_jobs, loopfunc, loopargs);
2633 for (k = 0; k < loopargs_len; k++) {
2634 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2636 print_result(D_EVP, testnum, count, d);
2638 } else if (evp_md != NULL) {
2639 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2641 for (testnum = 0; testnum < size_num; testnum++) {
2642 print_message(names[D_EVP], save_count, lengths[testnum],
2645 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2647 print_result(D_EVP, testnum, count, d);
2652 for (i = 0; i < loopargs_len; i++)
2653 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2656 #ifndef OPENSSL_NO_RSA
2657 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2659 if (!rsa_doit[testnum])
2661 for (i = 0; i < loopargs_len; i++) {
2663 /* we haven't set keys yet, generate multi-prime RSA keys */
2664 BIGNUM *bn = BN_new();
2668 if (!BN_set_word(bn, RSA_F4)) {
2673 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2674 rsa_choices[testnum].name);
2676 loopargs[i].rsa_key[testnum] = RSA_new();
2677 if (loopargs[i].rsa_key[testnum] == NULL) {
2682 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2684 primes, bn, NULL)) {
2690 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2691 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2697 "RSA sign failure. No RSA sign will be done.\n");
2698 ERR_print_errors(bio_err);
2701 pkey_print_message("private", "rsa",
2702 rsa_c[testnum][0], rsa_bits[testnum],
2704 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2706 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2709 mr ? "+R1:%ld:%d:%.2f\n"
2710 : "%ld %u bits private RSA's in %.2fs\n",
2711 count, rsa_bits[testnum], d);
2712 rsa_results[testnum][0] = (double)count / d;
2716 for (i = 0; i < loopargs_len; i++) {
2717 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2718 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2724 "RSA verify failure. No RSA verify will be done.\n");
2725 ERR_print_errors(bio_err);
2726 rsa_doit[testnum] = 0;
2728 pkey_print_message("public", "rsa",
2729 rsa_c[testnum][1], rsa_bits[testnum],
2732 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2735 mr ? "+R2:%ld:%d:%.2f\n"
2736 : "%ld %u bits public RSA's in %.2fs\n",
2737 count, rsa_bits[testnum], d);
2738 rsa_results[testnum][1] = (double)count / d;
2741 if (rsa_count <= 1) {
2742 /* if longer than 10s, don't do any more */
2743 for (testnum++; testnum < RSA_NUM; testnum++)
2744 rsa_doit[testnum] = 0;
2747 #endif /* OPENSSL_NO_RSA */
2749 for (i = 0; i < loopargs_len; i++)
2750 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2753 #ifndef OPENSSL_NO_DSA
2754 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2756 if (!dsa_doit[testnum])
2759 /* DSA_generate_key(dsa_key[testnum]); */
2760 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2761 for (i = 0; i < loopargs_len; i++) {
2762 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2763 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2769 "DSA sign failure. No DSA sign will be done.\n");
2770 ERR_print_errors(bio_err);
2773 pkey_print_message("sign", "dsa",
2774 dsa_c[testnum][0], dsa_bits[testnum],
2777 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2780 mr ? "+R3:%ld:%u:%.2f\n"
2781 : "%ld %u bits DSA signs in %.2fs\n",
2782 count, dsa_bits[testnum], d);
2783 dsa_results[testnum][0] = (double)count / d;
2787 for (i = 0; i < loopargs_len; i++) {
2788 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2789 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2795 "DSA verify failure. No DSA verify will be done.\n");
2796 ERR_print_errors(bio_err);
2797 dsa_doit[testnum] = 0;
2799 pkey_print_message("verify", "dsa",
2800 dsa_c[testnum][1], dsa_bits[testnum],
2803 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2806 mr ? "+R4:%ld:%u:%.2f\n"
2807 : "%ld %u bits DSA verify in %.2fs\n",
2808 count, dsa_bits[testnum], d);
2809 dsa_results[testnum][1] = (double)count / d;
2812 if (rsa_count <= 1) {
2813 /* if longer than 10s, don't do any more */
2814 for (testnum++; testnum < DSA_NUM; testnum++)
2815 dsa_doit[testnum] = 0;
2818 #endif /* OPENSSL_NO_DSA */
2820 #ifndef OPENSSL_NO_EC
2821 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
2824 if (!ecdsa_doit[testnum])
2825 continue; /* Ignore Curve */
2826 for (i = 0; i < loopargs_len; i++) {
2827 loopargs[i].ecdsa[testnum] =
2828 EC_KEY_new_by_curve_name(test_curves[testnum].nid);
2829 if (loopargs[i].ecdsa[testnum] == NULL) {
2835 BIO_printf(bio_err, "ECDSA failure.\n");
2836 ERR_print_errors(bio_err);
2839 for (i = 0; i < loopargs_len; i++) {
2840 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2841 /* Perform ECDSA signature test */
2842 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2843 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2844 &loopargs[i].siglen,
2845 loopargs[i].ecdsa[testnum]);
2851 "ECDSA sign failure. No ECDSA sign will be done.\n");
2852 ERR_print_errors(bio_err);
2855 pkey_print_message("sign", "ecdsa",
2856 ecdsa_c[testnum][0],
2857 test_curves[testnum].bits, seconds.ecdsa);
2859 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2863 mr ? "+R5:%ld:%u:%.2f\n" :
2864 "%ld %u bits ECDSA signs in %.2fs \n",
2865 count, test_curves[testnum].bits, d);
2866 ecdsa_results[testnum][0] = (double)count / d;
2870 /* Perform ECDSA verification test */
2871 for (i = 0; i < loopargs_len; i++) {
2872 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2874 loopargs[i].ecdsa[testnum]);
2880 "ECDSA verify failure. No ECDSA verify will be done.\n");
2881 ERR_print_errors(bio_err);
2882 ecdsa_doit[testnum] = 0;
2884 pkey_print_message("verify", "ecdsa",
2885 ecdsa_c[testnum][1],
2886 test_curves[testnum].bits, seconds.ecdsa);
2888 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2891 mr ? "+R6:%ld:%u:%.2f\n"
2892 : "%ld %u bits ECDSA verify in %.2fs\n",
2893 count, test_curves[testnum].bits, d);
2894 ecdsa_results[testnum][1] = (double)count / d;
2897 if (rsa_count <= 1) {
2898 /* if longer than 10s, don't do any more */
2899 for (testnum++; testnum < ECDSA_NUM; testnum++)
2900 ecdsa_doit[testnum] = 0;
2905 for (testnum = 0; testnum < EC_NUM; testnum++) {
2906 int ecdh_checks = 1;
2908 if (!ecdh_doit[testnum])
2911 for (i = 0; i < loopargs_len; i++) {
2912 EVP_PKEY_CTX *kctx = NULL;
2913 EVP_PKEY_CTX *test_ctx = NULL;
2914 EVP_PKEY_CTX *ctx = NULL;
2915 EVP_PKEY *key_A = NULL;
2916 EVP_PKEY *key_B = NULL;
2920 /* Ensure that the error queue is empty */
2921 if (ERR_peek_error()) {
2923 "WARNING: the error queue contains previous unhandled errors.\n");
2924 ERR_print_errors(bio_err);
2927 /* Let's try to create a ctx directly from the NID: this works for
2928 * curves like Curve25519 that are not implemented through the low
2929 * level EC interface.
2930 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2931 * then we set the curve by NID before deriving the actual keygen
2932 * ctx for that specific curve. */
2933 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum].nid, NULL); /* keygen ctx from NID */
2935 EVP_PKEY_CTX *pctx = NULL;
2936 EVP_PKEY *params = NULL;
2938 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2939 * "int_ctx_new:unsupported algorithm" error was added to the
2941 * We remove it from the error queue as we are handling it. */
2942 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2943 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2944 /* check that the error origin matches */
2945 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2946 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2947 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2948 ERR_get_error(); /* pop error from queue */
2949 if (ERR_peek_error()) {
2951 "Unhandled error in the error queue during ECDH init.\n");
2952 ERR_print_errors(bio_err);
2957 if ( /* Create the context for parameter generation */
2958 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2959 /* Initialise the parameter generation */
2960 !EVP_PKEY_paramgen_init(pctx) ||
2961 /* Set the curve by NID */
2962 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2965 /* Create the parameter object params */
2966 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2968 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2969 ERR_print_errors(bio_err);
2973 /* Create the context for the key generation */
2974 kctx = EVP_PKEY_CTX_new(params, NULL);
2976 EVP_PKEY_free(params);
2978 EVP_PKEY_CTX_free(pctx);
2981 if (kctx == NULL || /* keygen ctx is not null */
2982 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2984 BIO_printf(bio_err, "ECDH keygen failure.\n");
2985 ERR_print_errors(bio_err);
2990 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2991 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2992 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2993 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2994 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2995 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2996 outlen == 0 || /* ensure outlen is a valid size */
2997 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2999 BIO_printf(bio_err, "ECDH key generation failure.\n");
3000 ERR_print_errors(bio_err);
3005 /* Here we perform a test run, comparing the output of a*B and b*A;
3006 * we try this here and assume that further EVP_PKEY_derive calls
3007 * never fail, so we can skip checks in the actually benchmarked
3008 * code, for maximum performance. */
3009 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3010 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3011 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3012 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3013 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3014 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3015 test_outlen != outlen /* compare output length */ ) {
3017 BIO_printf(bio_err, "ECDH computation failure.\n");
3018 ERR_print_errors(bio_err);
3023 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3024 if (CRYPTO_memcmp(loopargs[i].secret_a,
3025 loopargs[i].secret_b, outlen)) {
3027 BIO_printf(bio_err, "ECDH computations don't match.\n");
3028 ERR_print_errors(bio_err);
3033 loopargs[i].ecdh_ctx[testnum] = ctx;
3034 loopargs[i].outlen[testnum] = outlen;
3036 EVP_PKEY_free(key_A);
3037 EVP_PKEY_free(key_B);
3038 EVP_PKEY_CTX_free(kctx);
3040 EVP_PKEY_CTX_free(test_ctx);
3043 if (ecdh_checks != 0) {
3044 pkey_print_message("", "ecdh",
3046 test_curves[testnum].bits, seconds.ecdh);
3049 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3052 mr ? "+R7:%ld:%d:%.2f\n" :
3053 "%ld %u-bits ECDH ops in %.2fs\n", count,
3054 test_curves[testnum].bits, d);
3055 ecdh_results[testnum][0] = (double)count / d;
3059 if (rsa_count <= 1) {
3060 /* if longer than 10s, don't do any more */
3061 for (testnum++; testnum < OSSL_NELEM(ecdh_doit); testnum++)
3062 ecdh_doit[testnum] = 0;
3066 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3068 EVP_PKEY *ed_pkey = NULL;
3069 EVP_PKEY_CTX *ed_pctx = NULL;
3071 if (!eddsa_doit[testnum])
3072 continue; /* Ignore Curve */
3073 for (i = 0; i < loopargs_len; i++) {
3074 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3075 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3080 if ((ed_pctx = EVP_PKEY_CTX_new_id(test_ed_curves[testnum].nid, NULL))
3082 || !EVP_PKEY_keygen_init(ed_pctx)
3083 || !EVP_PKEY_keygen(ed_pctx, &ed_pkey)) {
3085 EVP_PKEY_CTX_free(ed_pctx);
3088 EVP_PKEY_CTX_free(ed_pctx);
3090 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3093 EVP_PKEY_free(ed_pkey);
3096 EVP_PKEY_free(ed_pkey);
3099 BIO_printf(bio_err, "EdDSA failure.\n");
3100 ERR_print_errors(bio_err);
3103 for (i = 0; i < loopargs_len; i++) {
3104 /* Perform EdDSA signature test */
3105 loopargs[i].sigsize = test_ed_curves[testnum].sigsize;
3106 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3107 loopargs[i].buf2, &loopargs[i].sigsize,
3108 loopargs[i].buf, 20);
3114 "EdDSA sign failure. No EdDSA sign will be done.\n");
3115 ERR_print_errors(bio_err);
3118 pkey_print_message("sign", test_ed_curves[testnum].name,
3119 eddsa_c[testnum][0],
3120 test_ed_curves[testnum].bits, seconds.eddsa);
3122 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3126 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3127 "%ld %u bits %s signs in %.2fs \n",
3128 count, test_ed_curves[testnum].bits,
3129 test_ed_curves[testnum].name, d);
3130 eddsa_results[testnum][0] = (double)count / d;
3134 /* Perform EdDSA verification test */
3135 for (i = 0; i < loopargs_len; i++) {
3136 st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
3137 loopargs[i].buf2, loopargs[i].sigsize,
3138 loopargs[i].buf, 20);
3144 "EdDSA verify failure. No EdDSA verify will be done.\n");
3145 ERR_print_errors(bio_err);
3146 eddsa_doit[testnum] = 0;
3148 pkey_print_message("verify", test_ed_curves[testnum].name,
3149 eddsa_c[testnum][1],
3150 test_ed_curves[testnum].bits, seconds.eddsa);
3152 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3155 mr ? "+R9:%ld:%u:%s:%.2f\n"
3156 : "%ld %u bits %s verify in %.2fs\n",
3157 count, test_ed_curves[testnum].bits,
3158 test_ed_curves[testnum].name, d);
3159 eddsa_results[testnum][1] = (double)count / d;
3162 if (rsa_count <= 1) {
3163 /* if longer than 10s, don't do any more */
3164 for (testnum++; testnum < EdDSA_NUM; testnum++)
3165 eddsa_doit[testnum] = 0;
3170 #endif /* OPENSSL_NO_EC */
3175 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
3176 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3178 printf("%s ", BN_options());
3179 #ifndef OPENSSL_NO_MD2
3180 printf("%s ", MD2_options());
3182 #ifndef OPENSSL_NO_RC4
3183 printf("%s ", RC4_options());
3185 #ifndef OPENSSL_NO_DES
3186 printf("%s ", DES_options());
3188 printf("%s ", AES_options());
3189 #ifndef OPENSSL_NO_IDEA
3190 printf("%s ", IDEA_options());
3192 #ifndef OPENSSL_NO_BF
3193 printf("%s ", BF_options());
3195 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3203 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3206 for (testnum = 0; testnum < size_num; testnum++)
3207 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3211 for (k = 0; k < ALGOR_NUM; k++) {
3215 printf("+F:%u:%s", k, names[k]);
3217 printf("%-13s", names[k]);
3218 for (testnum = 0; testnum < size_num; testnum++) {
3219 if (results[k][testnum] > 10000 && !mr)
3220 printf(" %11.2fk", results[k][testnum] / 1e3);
3222 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3226 #ifndef OPENSSL_NO_RSA
3228 for (k = 0; k < RSA_NUM; k++) {
3231 if (testnum && !mr) {
3232 printf("%18ssign verify sign/s verify/s\n", " ");
3236 printf("+F2:%u:%u:%f:%f\n",
3237 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
3239 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3240 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3241 rsa_results[k][0], rsa_results[k][1]);
3244 #ifndef OPENSSL_NO_DSA
3246 for (k = 0; k < DSA_NUM; k++) {
3249 if (testnum && !mr) {
3250 printf("%18ssign verify sign/s verify/s\n", " ");
3254 printf("+F3:%u:%u:%f:%f\n",
3255 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3257 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3258 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3259 dsa_results[k][0], dsa_results[k][1]);
3262 #ifndef OPENSSL_NO_EC
3264 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3267 if (testnum && !mr) {
3268 printf("%30ssign verify sign/s verify/s\n", " ");
3273 printf("+F4:%u:%u:%f:%f\n",
3274 k, test_curves[k].bits,
3275 ecdsa_results[k][0], ecdsa_results[k][1]);
3277 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3278 test_curves[k].bits, test_curves[k].name,
3279 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3280 ecdsa_results[k][0], ecdsa_results[k][1]);
3284 for (k = 0; k < EC_NUM; k++) {
3287 if (testnum && !mr) {
3288 printf("%30sop op/s\n", " ");
3292 printf("+F5:%u:%u:%f:%f\n",
3293 k, test_curves[k].bits,
3294 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3297 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3298 test_curves[k].bits, test_curves[k].name,
3299 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3303 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
3306 if (testnum && !mr) {
3307 printf("%30ssign verify sign/s verify/s\n", " ");
3312 printf("+F6:%u:%u:%s:%f:%f\n",
3313 k, test_ed_curves[k].bits, test_ed_curves[k].name,
3314 eddsa_results[k][0], eddsa_results[k][1]);
3316 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3317 test_ed_curves[k].bits, test_ed_curves[k].name,
3318 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
3319 eddsa_results[k][0], eddsa_results[k][1]);
3326 ERR_print_errors(bio_err);
3327 for (i = 0; i < loopargs_len; i++) {
3328 OPENSSL_free(loopargs[i].buf_malloc);
3329 OPENSSL_free(loopargs[i].buf2_malloc);
3331 #ifndef OPENSSL_NO_RSA
3332 for (k = 0; k < RSA_NUM; k++)
3333 RSA_free(loopargs[i].rsa_key[k]);
3335 #ifndef OPENSSL_NO_DSA
3336 for (k = 0; k < DSA_NUM; k++)
3337 DSA_free(loopargs[i].dsa_key[k]);
3339 #ifndef OPENSSL_NO_EC
3340 for (k = 0; k < ECDSA_NUM; k++)
3341 EC_KEY_free(loopargs[i].ecdsa[k]);
3342 for (k = 0; k < EC_NUM; k++)
3343 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3344 for (k = 0; k < EdDSA_NUM; k++)
3345 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
3346 OPENSSL_free(loopargs[i].secret_a);
3347 OPENSSL_free(loopargs[i].secret_b);
3351 if (async_jobs > 0) {
3352 for (i = 0; i < loopargs_len; i++)
3353 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3357 ASYNC_cleanup_thread();
3359 OPENSSL_free(loopargs);
3364 static void print_message(const char *s, long num, int length, int tm)
3368 mr ? "+DT:%s:%d:%d\n"
3369 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3370 (void)BIO_flush(bio_err);
3374 mr ? "+DN:%s:%ld:%d\n"
3375 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3376 (void)BIO_flush(bio_err);
3380 static void pkey_print_message(const char *str, const char *str2, long num,
3381 unsigned int bits, int tm)
3385 mr ? "+DTP:%d:%s:%s:%d\n"
3386 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
3387 (void)BIO_flush(bio_err);
3391 mr ? "+DNP:%ld:%d:%s:%s\n"
3392 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
3393 (void)BIO_flush(bio_err);
3397 static void print_result(int alg, int run_no, int count, double time_used)
3400 BIO_puts(bio_err, "EVP error!\n");
3404 mr ? "+R:%d:%s:%f\n"
3405 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3406 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3410 static char *sstrsep(char **string, const char *delim)
3413 char *token = *string;
3418 memset(isdelim, 0, sizeof(isdelim));
3422 isdelim[(unsigned char)(*delim)] = 1;
3426 while (!isdelim[(unsigned char)(**string)]) {
3438 static int do_multi(int multi, int size_num)
3443 static char sep[] = ":";
3445 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
3446 for (n = 0; n < multi; ++n) {
3447 if (pipe(fd) == -1) {
3448 BIO_printf(bio_err, "pipe failure\n");
3452 (void)BIO_flush(bio_err);
3459 if (dup(fd[1]) == -1) {
3460 BIO_printf(bio_err, "dup failed\n");
3469 printf("Forked child %d\n", n);
3472 /* for now, assume the pipe is long enough to take all the output */
3473 for (n = 0; n < multi; ++n) {
3478 f = fdopen(fds[n], "r");
3479 while (fgets(buf, sizeof(buf), f)) {
3480 p = strchr(buf, '\n');
3483 if (buf[0] != '+') {
3485 "Don't understand line '%s' from child %d\n", buf,
3489 printf("Got: %s from %d\n", buf, n);
3490 if (strncmp(buf, "+F:", 3) == 0) {
3495 alg = atoi(sstrsep(&p, sep));
3497 for (j = 0; j < size_num; ++j)
3498 results[alg][j] += atof(sstrsep(&p, sep));
3499 } else if (strncmp(buf, "+F2:", 4) == 0) {
3504 k = atoi(sstrsep(&p, sep));
3507 d = atof(sstrsep(&p, sep));
3508 rsa_results[k][0] += d;
3510 d = atof(sstrsep(&p, sep));
3511 rsa_results[k][1] += d;
3513 # ifndef OPENSSL_NO_DSA
3514 else if (strncmp(buf, "+F3:", 4) == 0) {
3519 k = atoi(sstrsep(&p, sep));
3522 d = atof(sstrsep(&p, sep));
3523 dsa_results[k][0] += d;
3525 d = atof(sstrsep(&p, sep));
3526 dsa_results[k][1] += d;
3529 # ifndef OPENSSL_NO_EC
3530 else if (strncmp(buf, "+F4:", 4) == 0) {
3535 k = atoi(sstrsep(&p, sep));
3538 d = atof(sstrsep(&p, sep));
3539 ecdsa_results[k][0] += d;
3541 d = atof(sstrsep(&p, sep));
3542 ecdsa_results[k][1] += d;
3543 } else if (strncmp(buf, "+F5:", 4) == 0) {
3548 k = atoi(sstrsep(&p, sep));
3551 d = atof(sstrsep(&p, sep));
3552 ecdh_results[k][0] += d;
3553 } else if (strncmp(buf, "+F6:", 4) == 0) {
3558 k = atoi(sstrsep(&p, sep));
3561 d = atof(sstrsep(&p, sep));
3562 eddsa_results[k][0] += d;
3564 d = atof(sstrsep(&p, sep));
3565 eddsa_results[k][1] += d;
3569 else if (strncmp(buf, "+H:", 3) == 0) {
3572 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3583 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
3584 const openssl_speed_sec_t *seconds)
3586 static const int mblengths_list[] =
3587 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3588 const int *mblengths = mblengths_list;
3589 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
3590 const char *alg_name;
3591 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
3592 EVP_CIPHER_CTX *ctx;
3595 if (lengths_single) {
3596 mblengths = &lengths_single;
3600 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3601 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3602 ctx = EVP_CIPHER_CTX_new();
3603 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
3605 keylen = EVP_CIPHER_CTX_key_length(ctx);
3606 key = app_malloc(keylen, "evp_cipher key");
3607 EVP_CIPHER_CTX_rand_key(ctx, key);
3608 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
3609 OPENSSL_clear_free(key, keylen);
3611 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3612 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3614 for (j = 0; j < num; j++) {
3615 print_message(alg_name, 0, mblengths[j], seconds->sym);
3617 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3618 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3619 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3620 size_t len = mblengths[j];
3623 memset(aad, 0, 8); /* avoid uninitialized values */
3624 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3625 aad[9] = 3; /* version */
3627 aad[11] = 0; /* length */
3629 mb_param.out = NULL;
3632 mb_param.interleave = 8;
3634 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3635 sizeof(mb_param), &mb_param);
3641 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3642 sizeof(mb_param), &mb_param);
3646 RAND_bytes(out, 16);
3648 aad[11] = (unsigned char)(len >> 8);
3649 aad[12] = (unsigned char)(len);
3650 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3651 EVP_AEAD_TLS1_AAD_LEN, aad);
3652 EVP_Cipher(ctx, out, inp, len + pad);
3656 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3657 : "%d %s's in %.2fs\n", count, "evp", d);
3658 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3662 fprintf(stdout, "+H");
3663 for (j = 0; j < num; j++)
3664 fprintf(stdout, ":%d", mblengths[j]);
3665 fprintf(stdout, "\n");
3666 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3667 for (j = 0; j < num; j++)
3668 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3669 fprintf(stdout, "\n");
3672 "The 'numbers' are in 1000s of bytes per second processed.\n");
3673 fprintf(stdout, "type ");
3674 for (j = 0; j < num; j++)
3675 fprintf(stdout, "%7d bytes", mblengths[j]);
3676 fprintf(stdout, "\n");
3677 fprintf(stdout, "%-24s", alg_name);
3679 for (j = 0; j < num; j++) {
3680 if (results[D_EVP][j] > 10000)
3681 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3683 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3685 fprintf(stdout, "\n");
3690 EVP_CIPHER_CTX_free(ctx);