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 Apache License 2.0 (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)
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 #ifndef OPENSSL_NO_CMAC
61 #include <openssl/cmac.h>
63 #include <openssl/sha.h>
64 #ifndef OPENSSL_NO_RMD160
65 # include <openssl/ripemd.h>
67 #ifndef OPENSSL_NO_WHIRLPOOL
68 # include <openssl/whrlpool.h>
70 #ifndef OPENSSL_NO_RC4
71 # include <openssl/rc4.h>
73 #ifndef OPENSSL_NO_RC5
74 # include <openssl/rc5.h>
76 #ifndef OPENSSL_NO_RC2
77 # include <openssl/rc2.h>
79 #ifndef OPENSSL_NO_IDEA
80 # include <openssl/idea.h>
82 #ifndef OPENSSL_NO_SEED
83 # include <openssl/seed.h>
86 # include <openssl/blowfish.h>
88 #ifndef OPENSSL_NO_CAST
89 # include <openssl/cast.h>
91 #ifndef OPENSSL_NO_RSA
92 # include <openssl/rsa.h>
93 # include "./testrsa.h"
95 #include <openssl/x509.h>
96 #ifndef OPENSSL_NO_DSA
97 # include <openssl/dsa.h>
98 # include "./testdsa.h"
100 #ifndef OPENSSL_NO_EC
101 # include <openssl/ec.h>
103 #include <openssl/modes.h>
106 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
119 #define MAX_MISALIGNMENT 63
120 #define MAX_ECDH_SIZE 256
123 typedef struct openssl_speed_sec_st {
130 } openssl_speed_sec_t;
132 static volatile int run = 0;
135 static int usertime = 1;
137 #ifndef OPENSSL_NO_MD2
138 static int EVP_Digest_MD2_loop(void *args);
141 #ifndef OPENSSL_NO_MDC2
142 static int EVP_Digest_MDC2_loop(void *args);
144 #ifndef OPENSSL_NO_MD4
145 static int EVP_Digest_MD4_loop(void *args);
147 #ifndef OPENSSL_NO_MD5
148 static int MD5_loop(void *args);
149 static int HMAC_loop(void *args);
151 static int SHA1_loop(void *args);
152 static int SHA256_loop(void *args);
153 static int SHA512_loop(void *args);
154 #ifndef OPENSSL_NO_WHIRLPOOL
155 static int WHIRLPOOL_loop(void *args);
157 #ifndef OPENSSL_NO_RMD160
158 static int EVP_Digest_RMD160_loop(void *args);
160 #ifndef OPENSSL_NO_RC4
161 static int RC4_loop(void *args);
163 #ifndef OPENSSL_NO_DES
164 static int DES_ncbc_encrypt_loop(void *args);
165 static int DES_ede3_cbc_encrypt_loop(void *args);
167 static int AES_cbc_128_encrypt_loop(void *args);
168 static int AES_cbc_192_encrypt_loop(void *args);
169 static int AES_cbc_256_encrypt_loop(void *args);
171 static int AES_ige_128_encrypt_loop(void *args);
172 static int AES_ige_192_encrypt_loop(void *args);
173 static int AES_ige_256_encrypt_loop(void *args);
175 static int CRYPTO_gcm128_aad_loop(void *args);
176 static int RAND_bytes_loop(void *args);
177 static int EVP_Update_loop(void *args);
178 static int EVP_Update_loop_ccm(void *args);
179 static int EVP_Update_loop_aead(void *args);
180 static int EVP_Digest_loop(void *args);
181 #ifndef OPENSSL_NO_RSA
182 static int RSA_sign_loop(void *args);
183 static int RSA_verify_loop(void *args);
185 #ifndef OPENSSL_NO_DSA
186 static int DSA_sign_loop(void *args);
187 static int DSA_verify_loop(void *args);
189 #ifndef OPENSSL_NO_EC
190 static int ECDSA_sign_loop(void *args);
191 static int ECDSA_verify_loop(void *args);
192 static int EdDSA_sign_loop(void *args);
193 static int EdDSA_verify_loop(void *args);
196 static double Time_F(int s);
197 static void print_message(const char *s, long num, int length, int tm);
198 static void pkey_print_message(const char *str, const char *str2,
199 long num, unsigned int bits, int sec);
200 static void print_result(int alg, int run_no, int count, double time_used);
202 static int do_multi(int multi, int size_num);
205 static const int lengths_list[] = {
206 16, 64, 256, 1024, 8 * 1024, 16 * 1024
208 static const int *lengths = lengths_list;
210 static const int aead_lengths_list[] = {
211 2, 31, 136, 1024, 8 * 1024, 16 * 1024
219 static void alarmed(int sig)
221 signal(SIGALRM, alarmed);
225 static double Time_F(int s)
227 double ret = app_tminterval(s, usertime);
233 #elif defined(_WIN32)
237 static unsigned int lapse;
238 static volatile unsigned int schlock;
239 static void alarm_win32(unsigned int secs)
244 # define alarm alarm_win32
246 static DWORD WINAPI sleepy(VOID * arg)
254 static double Time_F(int s)
261 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
263 DWORD err = GetLastError();
264 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
268 Sleep(0); /* scheduler spinlock */
269 ret = app_tminterval(s, usertime);
271 ret = app_tminterval(s, usertime);
273 TerminateThread(thr, 0);
280 static double Time_F(int s)
282 return app_tminterval(s, usertime);
286 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
287 const openssl_speed_sec_t *seconds);
289 #define found(value, pairs, result)\
290 opt_found(value, result, pairs, OSSL_NELEM(pairs))
291 static int opt_found(const char *name, unsigned int *result,
292 const OPT_PAIR pairs[], unsigned int nbelem)
296 for (idx = 0; idx < nbelem; ++idx, pairs++)
297 if (strcmp(name, pairs->name) == 0) {
298 *result = pairs->retval;
304 typedef enum OPTION_choice {
305 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
306 OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
307 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
308 OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC
311 const OPTIONS speed_options[] = {
312 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
313 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
314 {"help", OPT_HELP, '-', "Display this summary"},
315 {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
316 {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"},
317 #ifndef OPENSSL_NO_CMAC
318 {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"},
320 {"decrypt", OPT_DECRYPT, '-',
321 "Time decryption instead of encryption (only EVP)"},
322 {"aead", OPT_AEAD, '-',
323 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
325 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
326 {"mr", OPT_MR, '-', "Produce machine readable output"},
328 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
330 #ifndef OPENSSL_NO_ASYNC
331 {"async_jobs", OPT_ASYNCJOBS, 'p',
332 "Enable async mode and start specified number of jobs"},
335 #ifndef OPENSSL_NO_ENGINE
336 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
338 {"elapsed", OPT_ELAPSED, '-',
339 "Use wall-clock time instead of CPU user time as divisor"},
340 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
341 {"seconds", OPT_SECONDS, 'p',
342 "Run benchmarks for specified amount of seconds"},
343 {"bytes", OPT_BYTES, 'p',
344 "Run [non-PKI] benchmarks on custom-sized buffer"},
345 {"misalign", OPT_MISALIGN, 'p',
346 "Use specified offset to mis-align buffers"},
360 #define D_CBC_IDEA 10
361 #define D_CBC_SEED 11
365 #define D_CBC_CAST 15
366 #define D_CBC_128_AES 16
367 #define D_CBC_192_AES 17
368 #define D_CBC_256_AES 18
369 #define D_CBC_128_CML 19
370 #define D_CBC_192_CML 20
371 #define D_CBC_256_CML 21
375 #define D_WHIRLPOOL 25
376 #define D_IGE_128_AES 26
377 #define D_IGE_192_AES 27
378 #define D_IGE_256_AES 28
381 #define D_EVP_HMAC 31
382 #define D_EVP_CMAC 32
384 /* name of algorithms to test */
385 static const char *names[] = {
386 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
387 "des cbc", "des ede3", "idea cbc", "seed cbc",
388 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
389 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
390 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
391 "evp", "sha256", "sha512", "whirlpool",
392 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
393 "rand", "hmac", "cmac"
395 #define ALGOR_NUM OSSL_NELEM(names)
397 /* list of configured algorithm (remaining) */
398 static const OPT_PAIR doit_choices[] = {
399 #ifndef OPENSSL_NO_MD2
402 #ifndef OPENSSL_NO_MDC2
405 #ifndef OPENSSL_NO_MD4
408 #ifndef OPENSSL_NO_MD5
413 {"sha256", D_SHA256},
414 {"sha512", D_SHA512},
415 #ifndef OPENSSL_NO_WHIRLPOOL
416 {"whirlpool", D_WHIRLPOOL},
418 #ifndef OPENSSL_NO_RMD160
419 {"ripemd", D_RMD160},
420 {"rmd160", D_RMD160},
421 {"ripemd160", D_RMD160},
423 #ifndef OPENSSL_NO_RC4
426 #ifndef OPENSSL_NO_DES
427 {"des-cbc", D_CBC_DES},
428 {"des-ede3", D_EDE3_DES},
430 {"aes-128-cbc", D_CBC_128_AES},
431 {"aes-192-cbc", D_CBC_192_AES},
432 {"aes-256-cbc", D_CBC_256_AES},
434 {"aes-128-ige", D_IGE_128_AES},
435 {"aes-192-ige", D_IGE_192_AES},
436 {"aes-256-ige", D_IGE_256_AES},
438 #ifndef OPENSSL_NO_RC2
439 {"rc2-cbc", D_CBC_RC2},
442 #ifndef OPENSSL_NO_RC5
443 {"rc5-cbc", D_CBC_RC5},
446 #ifndef OPENSSL_NO_IDEA
447 {"idea-cbc", D_CBC_IDEA},
448 {"idea", D_CBC_IDEA},
450 #ifndef OPENSSL_NO_SEED
451 {"seed-cbc", D_CBC_SEED},
452 {"seed", D_CBC_SEED},
454 #ifndef OPENSSL_NO_BF
455 {"bf-cbc", D_CBC_BF},
456 {"blowfish", D_CBC_BF},
459 #ifndef OPENSSL_NO_CAST
460 {"cast-cbc", D_CBC_CAST},
461 {"cast", D_CBC_CAST},
462 {"cast5", D_CBC_CAST},
468 static double results[ALGOR_NUM][OSSL_NELEM(lengths_list)];
470 #ifndef OPENSSL_NO_DSA
472 # define R_DSA_1024 1
473 # define R_DSA_2048 2
474 static const OPT_PAIR dsa_choices[] = {
475 {"dsa512", R_DSA_512},
476 {"dsa1024", R_DSA_1024},
477 {"dsa2048", R_DSA_2048}
479 # define DSA_NUM OSSL_NELEM(dsa_choices)
481 static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
482 #endif /* OPENSSL_NO_DSA */
490 #define R_RSA_15360 6
491 #ifndef OPENSSL_NO_RSA
492 static const OPT_PAIR rsa_choices[] = {
493 {"rsa512", R_RSA_512},
494 {"rsa1024", R_RSA_1024},
495 {"rsa2048", R_RSA_2048},
496 {"rsa3072", R_RSA_3072},
497 {"rsa4096", R_RSA_4096},
498 {"rsa7680", R_RSA_7680},
499 {"rsa15360", R_RSA_15360}
501 # define RSA_NUM OSSL_NELEM(rsa_choices)
503 static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
504 #endif /* OPENSSL_NO_RSA */
513 #ifndef OPENSSL_NO_EC2M
535 #ifndef OPENSSL_NO_EC
536 static OPT_PAIR ecdsa_choices[] = {
537 {"ecdsap160", R_EC_P160},
538 {"ecdsap192", R_EC_P192},
539 {"ecdsap224", R_EC_P224},
540 {"ecdsap256", R_EC_P256},
541 {"ecdsap384", R_EC_P384},
542 {"ecdsap521", R_EC_P521},
543 # ifndef OPENSSL_NO_EC2M
544 {"ecdsak163", R_EC_K163},
545 {"ecdsak233", R_EC_K233},
546 {"ecdsak283", R_EC_K283},
547 {"ecdsak409", R_EC_K409},
548 {"ecdsak571", R_EC_K571},
549 {"ecdsab163", R_EC_B163},
550 {"ecdsab233", R_EC_B233},
551 {"ecdsab283", R_EC_B283},
552 {"ecdsab409", R_EC_B409},
553 {"ecdsab571", R_EC_B571},
555 {"ecdsabrp256r1", R_EC_BRP256R1},
556 {"ecdsabrp256t1", R_EC_BRP256T1},
557 {"ecdsabrp384r1", R_EC_BRP384R1},
558 {"ecdsabrp384t1", R_EC_BRP384T1},
559 {"ecdsabrp512r1", R_EC_BRP512R1},
560 {"ecdsabrp512t1", R_EC_BRP512T1}
562 # define ECDSA_NUM OSSL_NELEM(ecdsa_choices)
564 static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
566 static const OPT_PAIR ecdh_choices[] = {
567 {"ecdhp160", R_EC_P160},
568 {"ecdhp192", R_EC_P192},
569 {"ecdhp224", R_EC_P224},
570 {"ecdhp256", R_EC_P256},
571 {"ecdhp384", R_EC_P384},
572 {"ecdhp521", R_EC_P521},
573 # ifndef OPENSSL_NO_EC2M
574 {"ecdhk163", R_EC_K163},
575 {"ecdhk233", R_EC_K233},
576 {"ecdhk283", R_EC_K283},
577 {"ecdhk409", R_EC_K409},
578 {"ecdhk571", R_EC_K571},
579 {"ecdhb163", R_EC_B163},
580 {"ecdhb233", R_EC_B233},
581 {"ecdhb283", R_EC_B283},
582 {"ecdhb409", R_EC_B409},
583 {"ecdhb571", R_EC_B571},
585 {"ecdhbrp256r1", R_EC_BRP256R1},
586 {"ecdhbrp256t1", R_EC_BRP256T1},
587 {"ecdhbrp384r1", R_EC_BRP384R1},
588 {"ecdhbrp384t1", R_EC_BRP384T1},
589 {"ecdhbrp512r1", R_EC_BRP512R1},
590 {"ecdhbrp512t1", R_EC_BRP512T1},
591 {"ecdhx25519", R_EC_X25519},
592 {"ecdhx448", R_EC_X448}
594 # define EC_NUM OSSL_NELEM(ecdh_choices)
596 static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
598 #define R_EC_Ed25519 0
600 static OPT_PAIR eddsa_choices[] = {
601 {"ed25519", R_EC_Ed25519},
602 {"ed448", R_EC_Ed448}
604 # define EdDSA_NUM OSSL_NELEM(eddsa_choices)
606 static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
607 #endif /* OPENSSL_NO_EC */
610 # define COND(d) (count < (d))
611 # define COUNT(d) (d)
613 # define COND(unused_cond) (run && count<0x7fffffff)
614 # define COUNT(d) (count)
617 typedef struct loopargs_st {
618 ASYNC_JOB *inprogress_job;
619 ASYNC_WAIT_CTX *wait_ctx;
622 unsigned char *buf_malloc;
623 unsigned char *buf2_malloc;
627 #ifndef OPENSSL_NO_RSA
628 RSA *rsa_key[RSA_NUM];
630 #ifndef OPENSSL_NO_DSA
631 DSA *dsa_key[DSA_NUM];
633 #ifndef OPENSSL_NO_EC
634 EC_KEY *ecdsa[ECDSA_NUM];
635 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
636 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
637 unsigned char *secret_a;
638 unsigned char *secret_b;
639 size_t outlen[EC_NUM];
643 #ifndef OPENSSL_NO_CMAC
646 GCM128_CONTEXT *gcm_ctx;
648 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
649 loopargs_t * loopargs);
651 static unsigned int testnum;
653 /* Nb of iterations to do per algorithm and key-size */
654 static long c[ALGOR_NUM][OSSL_NELEM(lengths_list)];
656 #ifndef OPENSSL_NO_MD2
657 static int EVP_Digest_MD2_loop(void *args)
659 loopargs_t *tempargs = *(loopargs_t **) args;
660 unsigned char *buf = tempargs->buf;
661 unsigned char md2[MD2_DIGEST_LENGTH];
664 for (count = 0; COND(c[D_MD2][testnum]); count++) {
665 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
673 #ifndef OPENSSL_NO_MDC2
674 static int EVP_Digest_MDC2_loop(void *args)
676 loopargs_t *tempargs = *(loopargs_t **) args;
677 unsigned char *buf = tempargs->buf;
678 unsigned char mdc2[MDC2_DIGEST_LENGTH];
681 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
682 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
690 #ifndef OPENSSL_NO_MD4
691 static int EVP_Digest_MD4_loop(void *args)
693 loopargs_t *tempargs = *(loopargs_t **) args;
694 unsigned char *buf = tempargs->buf;
695 unsigned char md4[MD4_DIGEST_LENGTH];
698 for (count = 0; COND(c[D_MD4][testnum]); count++) {
699 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
707 #ifndef OPENSSL_NO_MD5
708 static int MD5_loop(void *args)
710 loopargs_t *tempargs = *(loopargs_t **) args;
711 unsigned char *buf = tempargs->buf;
712 unsigned char md5[MD5_DIGEST_LENGTH];
714 for (count = 0; COND(c[D_MD5][testnum]); count++)
715 MD5(buf, lengths[testnum], md5);
719 static int HMAC_loop(void *args)
721 loopargs_t *tempargs = *(loopargs_t **) args;
722 unsigned char *buf = tempargs->buf;
723 HMAC_CTX *hctx = tempargs->hctx;
724 unsigned char hmac[MD5_DIGEST_LENGTH];
727 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
728 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
729 HMAC_Update(hctx, buf, lengths[testnum]);
730 HMAC_Final(hctx, hmac, NULL);
736 static int SHA1_loop(void *args)
738 loopargs_t *tempargs = *(loopargs_t **) args;
739 unsigned char *buf = tempargs->buf;
740 unsigned char sha[SHA_DIGEST_LENGTH];
742 for (count = 0; COND(c[D_SHA1][testnum]); count++)
743 SHA1(buf, lengths[testnum], sha);
747 static int SHA256_loop(void *args)
749 loopargs_t *tempargs = *(loopargs_t **) args;
750 unsigned char *buf = tempargs->buf;
751 unsigned char sha256[SHA256_DIGEST_LENGTH];
753 for (count = 0; COND(c[D_SHA256][testnum]); count++)
754 SHA256(buf, lengths[testnum], sha256);
758 static int SHA512_loop(void *args)
760 loopargs_t *tempargs = *(loopargs_t **) args;
761 unsigned char *buf = tempargs->buf;
762 unsigned char sha512[SHA512_DIGEST_LENGTH];
764 for (count = 0; COND(c[D_SHA512][testnum]); count++)
765 SHA512(buf, lengths[testnum], sha512);
769 #ifndef OPENSSL_NO_WHIRLPOOL
770 static int WHIRLPOOL_loop(void *args)
772 loopargs_t *tempargs = *(loopargs_t **) args;
773 unsigned char *buf = tempargs->buf;
774 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
776 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
777 WHIRLPOOL(buf, lengths[testnum], whirlpool);
782 #ifndef OPENSSL_NO_RMD160
783 static int EVP_Digest_RMD160_loop(void *args)
785 loopargs_t *tempargs = *(loopargs_t **) args;
786 unsigned char *buf = tempargs->buf;
787 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
789 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
790 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
791 NULL, EVP_ripemd160(), NULL))
798 #ifndef OPENSSL_NO_RC4
799 static RC4_KEY rc4_ks;
800 static int RC4_loop(void *args)
802 loopargs_t *tempargs = *(loopargs_t **) args;
803 unsigned char *buf = tempargs->buf;
805 for (count = 0; COND(c[D_RC4][testnum]); count++)
806 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
811 #ifndef OPENSSL_NO_DES
812 static unsigned char DES_iv[8];
813 static DES_key_schedule sch;
814 static DES_key_schedule sch2;
815 static DES_key_schedule sch3;
816 static int DES_ncbc_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_DES][testnum]); count++)
822 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
823 &DES_iv, DES_ENCRYPT);
827 static int DES_ede3_cbc_encrypt_loop(void *args)
829 loopargs_t *tempargs = *(loopargs_t **) args;
830 unsigned char *buf = tempargs->buf;
832 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
833 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
834 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
839 #define MAX_BLOCK_SIZE 128
841 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
842 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
843 static int AES_cbc_128_encrypt_loop(void *args)
845 loopargs_t *tempargs = *(loopargs_t **) args;
846 unsigned char *buf = tempargs->buf;
848 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
849 AES_cbc_encrypt(buf, buf,
850 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
854 static int AES_cbc_192_encrypt_loop(void *args)
856 loopargs_t *tempargs = *(loopargs_t **) args;
857 unsigned char *buf = tempargs->buf;
859 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
860 AES_cbc_encrypt(buf, buf,
861 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
865 static int AES_cbc_256_encrypt_loop(void *args)
867 loopargs_t *tempargs = *(loopargs_t **) args;
868 unsigned char *buf = tempargs->buf;
870 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
871 AES_cbc_encrypt(buf, buf,
872 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
877 static int AES_ige_128_encrypt_loop(void *args)
879 loopargs_t *tempargs = *(loopargs_t **) args;
880 unsigned char *buf = tempargs->buf;
881 unsigned char *buf2 = tempargs->buf2;
883 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
884 AES_ige_encrypt(buf, buf2,
885 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
889 static int AES_ige_192_encrypt_loop(void *args)
891 loopargs_t *tempargs = *(loopargs_t **) args;
892 unsigned char *buf = tempargs->buf;
893 unsigned char *buf2 = tempargs->buf2;
895 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
896 AES_ige_encrypt(buf, buf2,
897 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
901 static int AES_ige_256_encrypt_loop(void *args)
903 loopargs_t *tempargs = *(loopargs_t **) args;
904 unsigned char *buf = tempargs->buf;
905 unsigned char *buf2 = tempargs->buf2;
907 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
908 AES_ige_encrypt(buf, buf2,
909 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
914 static int CRYPTO_gcm128_aad_loop(void *args)
916 loopargs_t *tempargs = *(loopargs_t **) args;
917 unsigned char *buf = tempargs->buf;
918 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
920 for (count = 0; COND(c[D_GHASH][testnum]); count++)
921 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
925 static int RAND_bytes_loop(void *args)
927 loopargs_t *tempargs = *(loopargs_t **) args;
928 unsigned char *buf = tempargs->buf;
931 for (count = 0; COND(c[D_RAND][testnum]); count++)
932 RAND_bytes(buf, lengths[testnum]);
936 static long save_count = 0;
937 static int decrypt = 0;
938 static int EVP_Update_loop(void *args)
940 loopargs_t *tempargs = *(loopargs_t **) args;
941 unsigned char *buf = tempargs->buf;
942 EVP_CIPHER_CTX *ctx = tempargs->ctx;
945 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
948 for (count = 0; COND(nb_iter); count++) {
949 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
951 /* reset iv in case of counter overflow */
952 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
956 for (count = 0; COND(nb_iter); count++) {
957 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
959 /* reset iv in case of counter overflow */
960 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
965 EVP_DecryptFinal_ex(ctx, buf, &outl);
967 EVP_EncryptFinal_ex(ctx, buf, &outl);
972 * CCM does not support streaming. For the purpose of performance measurement,
973 * each message is encrypted using the same (key,iv)-pair. Do not use this
974 * code in your application.
976 static int EVP_Update_loop_ccm(void *args)
978 loopargs_t *tempargs = *(loopargs_t **) args;
979 unsigned char *buf = tempargs->buf;
980 EVP_CIPHER_CTX *ctx = tempargs->ctx;
982 unsigned char tag[12];
984 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
987 for (count = 0; COND(nb_iter); count++) {
988 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
990 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
991 /* counter is reset on every update */
992 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
995 for (count = 0; COND(nb_iter); count++) {
996 /* restore iv length field */
997 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
998 /* counter is reset on every update */
999 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1003 EVP_DecryptFinal_ex(ctx, buf, &outl);
1005 EVP_EncryptFinal_ex(ctx, buf, &outl);
1010 * To make AEAD benchmarking more relevant perform TLS-like operations,
1011 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
1012 * payload length is not actually limited by 16KB...
1014 static int EVP_Update_loop_aead(void *args)
1016 loopargs_t *tempargs = *(loopargs_t **) args;
1017 unsigned char *buf = tempargs->buf;
1018 EVP_CIPHER_CTX *ctx = tempargs->ctx;
1020 unsigned char aad[13] = { 0xcc };
1021 unsigned char faketag[16] = { 0xcc };
1023 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1026 for (count = 0; COND(nb_iter); count++) {
1027 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
1028 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
1029 sizeof(faketag), faketag);
1030 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1031 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1032 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
1035 for (count = 0; COND(nb_iter); count++) {
1036 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
1037 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1038 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1039 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
1045 static const EVP_MD *evp_md = NULL;
1046 static int EVP_Digest_loop(void *args)
1048 loopargs_t *tempargs = *(loopargs_t **) args;
1049 unsigned char *buf = tempargs->buf;
1050 unsigned char md[EVP_MAX_MD_SIZE];
1053 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1056 for (count = 0; COND(nb_iter); count++) {
1057 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
1063 static const EVP_MD *evp_hmac_md = NULL;
1064 static char *evp_hmac_name = NULL;
1065 static int EVP_HMAC_loop(void *args)
1067 loopargs_t *tempargs = *(loopargs_t **) args;
1068 unsigned char *buf = tempargs->buf;
1069 unsigned char no_key[32];
1072 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1075 for (count = 0; COND(nb_iter); count++) {
1076 if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
1077 NULL, NULL) == NULL)
1083 #ifndef OPENSSL_NO_CMAC
1084 static const EVP_CIPHER *evp_cmac_cipher = NULL;
1085 static char *evp_cmac_name = NULL;
1087 static int EVP_CMAC_loop(void *args)
1089 loopargs_t *tempargs = *(loopargs_t **) args;
1090 unsigned char *buf = tempargs->buf;
1091 CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
1092 static const char key[16] = "This is a key...";
1093 unsigned char mac[16];
1094 size_t len = sizeof(mac);
1097 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1100 for (count = 0; COND(nb_iter); count++) {
1101 if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
1102 || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
1103 || !CMAC_Final(cmac_ctx, mac, &len))
1110 #ifndef OPENSSL_NO_RSA
1111 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1113 static int RSA_sign_loop(void *args)
1115 loopargs_t *tempargs = *(loopargs_t **) args;
1116 unsigned char *buf = tempargs->buf;
1117 unsigned char *buf2 = tempargs->buf2;
1118 unsigned int *rsa_num = &tempargs->siglen;
1119 RSA **rsa_key = tempargs->rsa_key;
1121 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1122 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1124 BIO_printf(bio_err, "RSA sign failure\n");
1125 ERR_print_errors(bio_err);
1133 static int RSA_verify_loop(void *args)
1135 loopargs_t *tempargs = *(loopargs_t **) args;
1136 unsigned char *buf = tempargs->buf;
1137 unsigned char *buf2 = tempargs->buf2;
1138 unsigned int rsa_num = tempargs->siglen;
1139 RSA **rsa_key = tempargs->rsa_key;
1141 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1143 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1145 BIO_printf(bio_err, "RSA verify failure\n");
1146 ERR_print_errors(bio_err);
1155 #ifndef OPENSSL_NO_DSA
1156 static long dsa_c[DSA_NUM][2];
1157 static int DSA_sign_loop(void *args)
1159 loopargs_t *tempargs = *(loopargs_t **) args;
1160 unsigned char *buf = tempargs->buf;
1161 unsigned char *buf2 = tempargs->buf2;
1162 DSA **dsa_key = tempargs->dsa_key;
1163 unsigned int *siglen = &tempargs->siglen;
1165 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1166 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1168 BIO_printf(bio_err, "DSA sign failure\n");
1169 ERR_print_errors(bio_err);
1177 static int DSA_verify_loop(void *args)
1179 loopargs_t *tempargs = *(loopargs_t **) args;
1180 unsigned char *buf = tempargs->buf;
1181 unsigned char *buf2 = tempargs->buf2;
1182 DSA **dsa_key = tempargs->dsa_key;
1183 unsigned int siglen = tempargs->siglen;
1185 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1186 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1188 BIO_printf(bio_err, "DSA verify failure\n");
1189 ERR_print_errors(bio_err);
1198 #ifndef OPENSSL_NO_EC
1199 static long ecdsa_c[ECDSA_NUM][2];
1200 static int ECDSA_sign_loop(void *args)
1202 loopargs_t *tempargs = *(loopargs_t **) args;
1203 unsigned char *buf = tempargs->buf;
1204 EC_KEY **ecdsa = tempargs->ecdsa;
1205 unsigned char *ecdsasig = tempargs->buf2;
1206 unsigned int *ecdsasiglen = &tempargs->siglen;
1208 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1209 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1211 BIO_printf(bio_err, "ECDSA sign failure\n");
1212 ERR_print_errors(bio_err);
1220 static int ECDSA_verify_loop(void *args)
1222 loopargs_t *tempargs = *(loopargs_t **) args;
1223 unsigned char *buf = tempargs->buf;
1224 EC_KEY **ecdsa = tempargs->ecdsa;
1225 unsigned char *ecdsasig = tempargs->buf2;
1226 unsigned int ecdsasiglen = tempargs->siglen;
1228 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1229 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1231 BIO_printf(bio_err, "ECDSA verify failure\n");
1232 ERR_print_errors(bio_err);
1240 /* ******************************************************************** */
1241 static long ecdh_c[EC_NUM][1];
1243 static int ECDH_EVP_derive_key_loop(void *args)
1245 loopargs_t *tempargs = *(loopargs_t **) args;
1246 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1247 unsigned char *derived_secret = tempargs->secret_a;
1249 size_t *outlen = &(tempargs->outlen[testnum]);
1251 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1252 EVP_PKEY_derive(ctx, derived_secret, outlen);
1257 static long eddsa_c[EdDSA_NUM][2];
1258 static int EdDSA_sign_loop(void *args)
1260 loopargs_t *tempargs = *(loopargs_t **) args;
1261 unsigned char *buf = tempargs->buf;
1262 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1263 unsigned char *eddsasig = tempargs->buf2;
1264 size_t *eddsasigsize = &tempargs->sigsize;
1267 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1268 ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1270 BIO_printf(bio_err, "EdDSA sign failure\n");
1271 ERR_print_errors(bio_err);
1279 static int EdDSA_verify_loop(void *args)
1281 loopargs_t *tempargs = *(loopargs_t **) args;
1282 unsigned char *buf = tempargs->buf;
1283 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1284 unsigned char *eddsasig = tempargs->buf2;
1285 size_t eddsasigsize = tempargs->sigsize;
1288 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1289 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1291 BIO_printf(bio_err, "EdDSA verify failure\n");
1292 ERR_print_errors(bio_err);
1299 #endif /* OPENSSL_NO_EC */
1301 static int run_benchmark(int async_jobs,
1302 int (*loop_function) (void *), loopargs_t * loopargs)
1304 int job_op_count = 0;
1305 int total_op_count = 0;
1306 int num_inprogress = 0;
1307 int error = 0, i = 0, ret = 0;
1308 OSSL_ASYNC_FD job_fd = 0;
1309 size_t num_job_fds = 0;
1313 if (async_jobs == 0) {
1314 return loop_function((void *)&loopargs);
1317 for (i = 0; i < async_jobs && !error; i++) {
1318 loopargs_t *looparg_item = loopargs + i;
1320 /* Copy pointer content (looparg_t item address) into async context */
1321 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1322 &job_op_count, loop_function,
1323 (void *)&looparg_item, sizeof(looparg_item));
1329 if (job_op_count == -1) {
1332 total_op_count += job_op_count;
1337 BIO_printf(bio_err, "Failure in the job\n");
1338 ERR_print_errors(bio_err);
1344 while (num_inprogress > 0) {
1345 #if defined(OPENSSL_SYS_WINDOWS)
1347 #elif defined(OPENSSL_SYS_UNIX)
1348 int select_result = 0;
1349 OSSL_ASYNC_FD max_fd = 0;
1352 FD_ZERO(&waitfdset);
1354 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1355 if (loopargs[i].inprogress_job == NULL)
1358 if (!ASYNC_WAIT_CTX_get_all_fds
1359 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1360 || num_job_fds > 1) {
1361 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1362 ERR_print_errors(bio_err);
1366 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1368 FD_SET(job_fd, &waitfdset);
1369 if (job_fd > max_fd)
1373 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1375 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1376 "Decrease the value of async_jobs\n",
1377 max_fd, FD_SETSIZE);
1378 ERR_print_errors(bio_err);
1383 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1384 if (select_result == -1 && errno == EINTR)
1387 if (select_result == -1) {
1388 BIO_printf(bio_err, "Failure in the select\n");
1389 ERR_print_errors(bio_err);
1394 if (select_result == 0)
1398 for (i = 0; i < async_jobs; i++) {
1399 if (loopargs[i].inprogress_job == NULL)
1402 if (!ASYNC_WAIT_CTX_get_all_fds
1403 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1404 || num_job_fds > 1) {
1405 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1406 ERR_print_errors(bio_err);
1410 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1413 #if defined(OPENSSL_SYS_UNIX)
1414 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1416 #elif defined(OPENSSL_SYS_WINDOWS)
1417 if (num_job_fds == 1
1418 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1423 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1424 loopargs[i].wait_ctx, &job_op_count,
1425 loop_function, (void *)(loopargs + i),
1426 sizeof(loopargs_t));
1431 if (job_op_count == -1) {
1434 total_op_count += job_op_count;
1437 loopargs[i].inprogress_job = NULL;
1442 loopargs[i].inprogress_job = NULL;
1443 BIO_printf(bio_err, "Failure in the job\n");
1444 ERR_print_errors(bio_err);
1451 return error ? -1 : total_op_count;
1454 int speed_main(int argc, char **argv)
1457 loopargs_t *loopargs = NULL;
1459 const char *engine_id = NULL;
1460 const EVP_CIPHER *evp_cipher = NULL;
1463 int async_init = 0, multiblock = 0, pr_header = 0;
1464 int doit[ALGOR_NUM] = { 0 };
1465 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1467 unsigned int size_num = OSSL_NELEM(lengths_list);
1468 unsigned int i, k, loop, loopargs_len = 0, async_jobs = 0;
1474 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1475 || !defined(OPENSSL_NO_EC)
1478 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1479 ECDSA_SECONDS, ECDH_SECONDS,
1482 /* What follows are the buffers and key material. */
1483 #ifndef OPENSSL_NO_RC5
1486 #ifndef OPENSSL_NO_RC2
1489 #ifndef OPENSSL_NO_IDEA
1490 IDEA_KEY_SCHEDULE idea_ks;
1492 #ifndef OPENSSL_NO_SEED
1493 SEED_KEY_SCHEDULE seed_ks;
1495 #ifndef OPENSSL_NO_BF
1498 #ifndef OPENSSL_NO_CAST
1501 static const unsigned char key16[16] = {
1502 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1503 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1505 static const unsigned char key24[24] = {
1506 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1507 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1508 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1510 static const unsigned char key32[32] = {
1511 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1512 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1513 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1514 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1516 #ifndef OPENSSL_NO_CAMELLIA
1517 static const unsigned char ckey24[24] = {
1518 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1519 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1520 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1522 static const unsigned char ckey32[32] = {
1523 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1524 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1525 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1526 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1528 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1530 #ifndef OPENSSL_NO_DES
1531 static DES_cblock key = {
1532 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1534 static DES_cblock key2 = {
1535 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1537 static DES_cblock key3 = {
1538 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1541 #ifndef OPENSSL_NO_RSA
1542 static const unsigned int rsa_bits[RSA_NUM] = {
1543 512, 1024, 2048, 3072, 4096, 7680, 15360
1545 static const unsigned char *rsa_data[RSA_NUM] = {
1546 test512, test1024, test2048, test3072, test4096, test7680, test15360
1548 static const int rsa_data_length[RSA_NUM] = {
1549 sizeof(test512), sizeof(test1024),
1550 sizeof(test2048), sizeof(test3072),
1551 sizeof(test4096), sizeof(test7680),
1554 int rsa_doit[RSA_NUM] = { 0 };
1555 int primes = RSA_DEFAULT_PRIME_NUM;
1557 #ifndef OPENSSL_NO_DSA
1558 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1559 int dsa_doit[DSA_NUM] = { 0 };
1561 #ifndef OPENSSL_NO_EC
1563 * We only test over the following curves as they are representative, To
1564 * add tests over more curves, simply add the curve NID and curve name to
1565 * the following arrays and increase the |ecdh_choices| list accordingly.
1567 static const struct {
1573 {"secp160r1", NID_secp160r1, 160},
1574 {"nistp192", NID_X9_62_prime192v1, 192},
1575 {"nistp224", NID_secp224r1, 224},
1576 {"nistp256", NID_X9_62_prime256v1, 256},
1577 {"nistp384", NID_secp384r1, 384},
1578 {"nistp521", NID_secp521r1, 521},
1579 # ifndef OPENSSL_NO_EC2M
1581 {"nistk163", NID_sect163k1, 163},
1582 {"nistk233", NID_sect233k1, 233},
1583 {"nistk283", NID_sect283k1, 283},
1584 {"nistk409", NID_sect409k1, 409},
1585 {"nistk571", NID_sect571k1, 571},
1586 {"nistb163", NID_sect163r2, 163},
1587 {"nistb233", NID_sect233r1, 233},
1588 {"nistb283", NID_sect283r1, 283},
1589 {"nistb409", NID_sect409r1, 409},
1590 {"nistb571", NID_sect571r1, 571},
1592 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1593 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1594 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1595 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1596 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1597 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1598 /* Other and ECDH only ones */
1599 {"X25519", NID_X25519, 253},
1600 {"X448", NID_X448, 448}
1602 static const struct {
1607 } test_ed_curves[] = {
1609 {"Ed25519", NID_ED25519, 253, 64},
1610 {"Ed448", NID_ED448, 456, 114}
1612 int ecdsa_doit[ECDSA_NUM] = { 0 };
1613 int ecdh_doit[EC_NUM] = { 0 };
1614 int eddsa_doit[EdDSA_NUM] = { 0 };
1615 OPENSSL_assert(OSSL_NELEM(test_curves) >= EC_NUM);
1616 OPENSSL_assert(OSSL_NELEM(test_ed_curves) >= EdDSA_NUM);
1617 #endif /* ndef OPENSSL_NO_EC */
1619 prog = opt_init(argc, argv, speed_options);
1620 while ((o = opt_next()) != OPT_EOF) {
1625 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1628 opt_help(speed_options);
1636 evp_cipher = EVP_get_cipherbyname(opt_arg());
1637 if (evp_cipher == NULL)
1638 evp_md = EVP_get_digestbyname(opt_arg());
1639 if (evp_cipher == NULL && evp_md == NULL) {
1641 "%s: %s is an unknown cipher or digest\n",
1648 evp_hmac_md = EVP_get_digestbyname(opt_arg());
1649 if (evp_hmac_md == NULL) {
1650 BIO_printf(bio_err, "%s: %s is an unknown digest\n",
1654 doit[D_EVP_HMAC] = 1;
1657 #ifndef OPENSSL_NO_CMAC
1658 evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
1659 if (evp_cmac_cipher == NULL) {
1660 BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
1664 doit[D_EVP_CMAC] = 1;
1672 * In a forked execution, an engine might need to be
1673 * initialised by each child process, not by the parent.
1674 * So store the name here and run setup_engine() later on.
1676 engine_id = opt_arg();
1680 multi = atoi(opt_arg());
1684 #ifndef OPENSSL_NO_ASYNC
1685 async_jobs = atoi(opt_arg());
1686 if (!ASYNC_is_capable()) {
1688 "%s: async_jobs specified but async not supported\n",
1692 if (async_jobs > 99999) {
1693 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1699 if (!opt_int(opt_arg(), &misalign))
1701 if (misalign > MISALIGN) {
1703 "%s: Maximum offset is %d\n", prog, MISALIGN);
1712 #ifdef OPENSSL_NO_MULTIBLOCK
1714 "%s: -mb specified but multi-block support is disabled\n",
1724 if (!opt_int(opt_arg(), &primes))
1728 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1729 = seconds.ecdh = seconds.eddsa = atoi(opt_arg());
1732 lengths_single = atoi(opt_arg());
1733 lengths = &lengths_single;
1741 argc = opt_num_rest();
1744 /* Remaining arguments are algorithms. */
1745 for (; *argv; argv++) {
1746 if (found(*argv, doit_choices, &i)) {
1750 #ifndef OPENSSL_NO_DES
1751 if (strcmp(*argv, "des") == 0) {
1752 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1756 if (strcmp(*argv, "sha") == 0) {
1757 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1760 #ifndef OPENSSL_NO_RSA
1761 if (strcmp(*argv, "openssl") == 0)
1763 if (strcmp(*argv, "rsa") == 0) {
1764 for (loop = 0; loop < OSSL_NELEM(rsa_doit); loop++)
1768 if (found(*argv, rsa_choices, &i)) {
1773 #ifndef OPENSSL_NO_DSA
1774 if (strcmp(*argv, "dsa") == 0) {
1775 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1776 dsa_doit[R_DSA_2048] = 1;
1779 if (found(*argv, dsa_choices, &i)) {
1784 if (strcmp(*argv, "aes") == 0) {
1785 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1788 #ifndef OPENSSL_NO_CAMELLIA
1789 if (strcmp(*argv, "camellia") == 0) {
1790 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1794 #ifndef OPENSSL_NO_EC
1795 if (strcmp(*argv, "ecdsa") == 0) {
1796 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1797 ecdsa_doit[loop] = 1;
1800 if (found(*argv, ecdsa_choices, &i)) {
1804 if (strcmp(*argv, "ecdh") == 0) {
1805 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1806 ecdh_doit[loop] = 1;
1809 if (found(*argv, ecdh_choices, &i)) {
1813 if (strcmp(*argv, "eddsa") == 0) {
1814 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1815 eddsa_doit[loop] = 1;
1818 if (found(*argv, eddsa_choices, &i)) {
1823 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1829 if (evp_cipher == NULL) {
1830 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1832 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1833 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1834 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1835 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1840 if (evp_cipher == NULL) {
1841 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1842 " capable cipher\n");
1844 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1845 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1846 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1847 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1849 } else if (async_jobs > 0) {
1850 BIO_printf(bio_err, "Async mode is not supported with -mb");
1855 /* Initialize the job pool if async mode is enabled */
1856 if (async_jobs > 0) {
1857 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1859 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1864 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1866 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1867 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1869 for (i = 0; i < loopargs_len; i++) {
1870 if (async_jobs > 0) {
1871 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1872 if (loopargs[i].wait_ctx == NULL) {
1873 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1878 buflen = lengths[size_num - 1];
1879 if (buflen < 36) /* size of random vector in RSA benchmark */
1881 buflen += MAX_MISALIGNMENT + 1;
1882 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1883 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1884 memset(loopargs[i].buf_malloc, 0, buflen);
1885 memset(loopargs[i].buf2_malloc, 0, buflen);
1887 /* Align the start of buffers on a 64 byte boundary */
1888 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1889 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1890 #ifndef OPENSSL_NO_EC
1891 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1892 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1897 if (multi && do_multi(multi, size_num))
1901 /* Initialize the engine after the fork */
1902 e = setup_engine(engine_id, 0);
1904 /* No parameters; turn on everything. */
1905 if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
1906 for (i = 0; i < ALGOR_NUM; i++)
1907 if (i != D_EVP && i != D_EVP_HMAC && i != D_EVP_CMAC)
1909 #ifndef OPENSSL_NO_RSA
1910 for (i = 0; i < RSA_NUM; i++)
1913 #ifndef OPENSSL_NO_DSA
1914 for (i = 0; i < DSA_NUM; i++)
1917 #ifndef OPENSSL_NO_EC
1918 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1919 ecdsa_doit[loop] = 1;
1920 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1921 ecdh_doit[loop] = 1;
1922 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1923 eddsa_doit[loop] = 1;
1926 for (i = 0; i < ALGOR_NUM; i++)
1930 if (usertime == 0 && !mr)
1932 "You have chosen to measure elapsed time "
1933 "instead of user CPU time.\n");
1935 #ifndef OPENSSL_NO_RSA
1936 for (i = 0; i < loopargs_len; i++) {
1937 if (primes > RSA_DEFAULT_PRIME_NUM) {
1938 /* for multi-prime RSA, skip this */
1941 for (k = 0; k < RSA_NUM; k++) {
1942 const unsigned char *p;
1945 loopargs[i].rsa_key[k] =
1946 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1947 if (loopargs[i].rsa_key[k] == NULL) {
1949 "internal error loading RSA key number %d\n", k);
1955 #ifndef OPENSSL_NO_DSA
1956 for (i = 0; i < loopargs_len; i++) {
1957 loopargs[i].dsa_key[0] = get_dsa(512);
1958 loopargs[i].dsa_key[1] = get_dsa(1024);
1959 loopargs[i].dsa_key[2] = get_dsa(2048);
1962 #ifndef OPENSSL_NO_DES
1963 DES_set_key_unchecked(&key, &sch);
1964 DES_set_key_unchecked(&key2, &sch2);
1965 DES_set_key_unchecked(&key3, &sch3);
1967 AES_set_encrypt_key(key16, 128, &aes_ks1);
1968 AES_set_encrypt_key(key24, 192, &aes_ks2);
1969 AES_set_encrypt_key(key32, 256, &aes_ks3);
1970 #ifndef OPENSSL_NO_CAMELLIA
1971 Camellia_set_key(key16, 128, &camellia_ks1);
1972 Camellia_set_key(ckey24, 192, &camellia_ks2);
1973 Camellia_set_key(ckey32, 256, &camellia_ks3);
1975 #ifndef OPENSSL_NO_IDEA
1976 IDEA_set_encrypt_key(key16, &idea_ks);
1978 #ifndef OPENSSL_NO_SEED
1979 SEED_set_key(key16, &seed_ks);
1981 #ifndef OPENSSL_NO_RC4
1982 RC4_set_key(&rc4_ks, 16, key16);
1984 #ifndef OPENSSL_NO_RC2
1985 RC2_set_key(&rc2_ks, 16, key16, 128);
1987 #ifndef OPENSSL_NO_RC5
1988 if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
1989 BIO_printf(bio_err, "Failed setting RC5 key\n");
1993 #ifndef OPENSSL_NO_BF
1994 BF_set_key(&bf_ks, 16, key16);
1996 #ifndef OPENSSL_NO_CAST
1997 CAST_set_key(&cast_ks, 16, key16);
2000 # ifndef OPENSSL_NO_DES
2001 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
2007 for (it = count; it; it--)
2008 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
2009 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
2013 c[D_MD2][0] = count / 10;
2014 c[D_MDC2][0] = count / 10;
2015 c[D_MD4][0] = count;
2016 c[D_MD5][0] = count;
2017 c[D_HMAC][0] = count;
2018 c[D_SHA1][0] = count;
2019 c[D_RMD160][0] = count;
2020 c[D_RC4][0] = count * 5;
2021 c[D_CBC_DES][0] = count;
2022 c[D_EDE3_DES][0] = count / 3;
2023 c[D_CBC_IDEA][0] = count;
2024 c[D_CBC_SEED][0] = count;
2025 c[D_CBC_RC2][0] = count;
2026 c[D_CBC_RC5][0] = count;
2027 c[D_CBC_BF][0] = count;
2028 c[D_CBC_CAST][0] = count;
2029 c[D_CBC_128_AES][0] = count;
2030 c[D_CBC_192_AES][0] = count;
2031 c[D_CBC_256_AES][0] = count;
2032 c[D_CBC_128_CML][0] = count;
2033 c[D_CBC_192_CML][0] = count;
2034 c[D_CBC_256_CML][0] = count;
2035 c[D_SHA256][0] = count;
2036 c[D_SHA512][0] = count;
2037 c[D_WHIRLPOOL][0] = count;
2038 c[D_IGE_128_AES][0] = count;
2039 c[D_IGE_192_AES][0] = count;
2040 c[D_IGE_256_AES][0] = count;
2041 c[D_GHASH][0] = count;
2042 c[D_RAND][0] = count;
2044 for (i = 1; i < size_num; i++) {
2047 l0 = (long)lengths[0];
2048 l1 = (long)lengths[i];
2050 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
2051 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
2052 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
2053 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
2054 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
2055 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
2056 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
2057 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
2058 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
2059 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
2060 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
2061 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
2063 l0 = (long)lengths[i - 1];
2065 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
2066 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
2067 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
2068 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
2069 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
2070 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
2071 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
2072 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
2073 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
2074 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
2075 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
2076 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
2077 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
2078 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
2079 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
2080 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
2081 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
2082 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
2085 # ifndef OPENSSL_NO_RSA
2086 rsa_c[R_RSA_512][0] = count / 2000;
2087 rsa_c[R_RSA_512][1] = count / 400;
2088 for (i = 1; i < RSA_NUM; i++) {
2089 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
2090 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
2091 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
2094 if (rsa_c[i][0] == 0) {
2095 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2102 # ifndef OPENSSL_NO_DSA
2103 dsa_c[R_DSA_512][0] = count / 1000;
2104 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2105 for (i = 1; i < DSA_NUM; i++) {
2106 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2107 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2108 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2111 if (dsa_c[i][0] == 0) {
2112 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2119 # ifndef OPENSSL_NO_EC
2120 ecdsa_c[R_EC_P160][0] = count / 1000;
2121 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2122 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2123 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2124 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2125 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2128 if (ecdsa_c[i][0] == 0) {
2134 # ifndef OPENSSL_NO_EC2M
2135 ecdsa_c[R_EC_K163][0] = count / 1000;
2136 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2137 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2138 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2139 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2140 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2143 if (ecdsa_c[i][0] == 0) {
2149 ecdsa_c[R_EC_B163][0] = count / 1000;
2150 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2151 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2152 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2153 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2154 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2157 if (ecdsa_c[i][0] == 0) {
2165 ecdh_c[R_EC_P160][0] = count / 1000;
2166 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2167 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2168 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2171 if (ecdh_c[i][0] == 0) {
2176 # ifndef OPENSSL_NO_EC2M
2177 ecdh_c[R_EC_K163][0] = count / 1000;
2178 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2179 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2180 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2183 if (ecdh_c[i][0] == 0) {
2188 ecdh_c[R_EC_B163][0] = count / 1000;
2189 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2190 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2191 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2194 if (ecdh_c[i][0] == 0) {
2200 /* repeated code good to factorize */
2201 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2202 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2203 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2204 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2207 if (ecdh_c[i][0] == 0) {
2212 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2213 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2214 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2215 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2218 if (ecdh_c[i][0] == 0) {
2223 /* default iteration count for the last two EC Curves */
2224 ecdh_c[R_EC_X25519][0] = count / 1800;
2225 ecdh_c[R_EC_X448][0] = count / 7200;
2227 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2228 eddsa_c[R_EC_Ed448][0] = count / 7200;
2232 /* not worth fixing */
2233 # error "You cannot disable DES on systems without SIGALRM."
2234 # endif /* OPENSSL_NO_DES */
2236 signal(SIGALRM, alarmed);
2237 #endif /* SIGALRM */
2239 #ifndef OPENSSL_NO_MD2
2241 for (testnum = 0; testnum < size_num; testnum++) {
2242 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2245 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2247 print_result(D_MD2, testnum, count, d);
2251 #ifndef OPENSSL_NO_MDC2
2253 for (testnum = 0; testnum < size_num; testnum++) {
2254 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2257 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2259 print_result(D_MDC2, testnum, count, d);
2264 #ifndef OPENSSL_NO_MD4
2266 for (testnum = 0; testnum < size_num; testnum++) {
2267 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2270 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2272 print_result(D_MD4, testnum, count, d);
2277 #ifndef OPENSSL_NO_MD5
2279 for (testnum = 0; testnum < size_num; testnum++) {
2280 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2283 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2285 print_result(D_MD5, testnum, count, d);
2290 static const char hmac_key[] = "This is a key...";
2291 int len = strlen(hmac_key);
2293 for (i = 0; i < loopargs_len; i++) {
2294 loopargs[i].hctx = HMAC_CTX_new();
2295 if (loopargs[i].hctx == NULL) {
2296 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2300 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2302 for (testnum = 0; testnum < size_num; testnum++) {
2303 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2306 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2308 print_result(D_HMAC, testnum, count, d);
2310 for (i = 0; i < loopargs_len; i++) {
2311 HMAC_CTX_free(loopargs[i].hctx);
2316 for (testnum = 0; testnum < size_num; testnum++) {
2317 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2320 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2322 print_result(D_SHA1, testnum, count, d);
2325 if (doit[D_SHA256]) {
2326 for (testnum = 0; testnum < size_num; testnum++) {
2327 print_message(names[D_SHA256], c[D_SHA256][testnum],
2328 lengths[testnum], seconds.sym);
2330 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2332 print_result(D_SHA256, testnum, count, d);
2335 if (doit[D_SHA512]) {
2336 for (testnum = 0; testnum < size_num; testnum++) {
2337 print_message(names[D_SHA512], c[D_SHA512][testnum],
2338 lengths[testnum], seconds.sym);
2340 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2342 print_result(D_SHA512, testnum, count, d);
2345 #ifndef OPENSSL_NO_WHIRLPOOL
2346 if (doit[D_WHIRLPOOL]) {
2347 for (testnum = 0; testnum < size_num; testnum++) {
2348 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2349 lengths[testnum], seconds.sym);
2351 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2353 print_result(D_WHIRLPOOL, testnum, count, d);
2358 #ifndef OPENSSL_NO_RMD160
2359 if (doit[D_RMD160]) {
2360 for (testnum = 0; testnum < size_num; testnum++) {
2361 print_message(names[D_RMD160], c[D_RMD160][testnum],
2362 lengths[testnum], seconds.sym);
2364 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2366 print_result(D_RMD160, testnum, count, d);
2370 #ifndef OPENSSL_NO_RC4
2372 for (testnum = 0; testnum < size_num; testnum++) {
2373 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2376 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2378 print_result(D_RC4, testnum, count, d);
2382 #ifndef OPENSSL_NO_DES
2383 if (doit[D_CBC_DES]) {
2384 for (testnum = 0; testnum < size_num; testnum++) {
2385 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2386 lengths[testnum], seconds.sym);
2388 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2390 print_result(D_CBC_DES, testnum, count, d);
2394 if (doit[D_EDE3_DES]) {
2395 for (testnum = 0; testnum < size_num; testnum++) {
2396 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2397 lengths[testnum], seconds.sym);
2400 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2402 print_result(D_EDE3_DES, testnum, count, d);
2407 if (doit[D_CBC_128_AES]) {
2408 for (testnum = 0; testnum < size_num; testnum++) {
2409 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2410 lengths[testnum], seconds.sym);
2413 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2415 print_result(D_CBC_128_AES, testnum, count, d);
2418 if (doit[D_CBC_192_AES]) {
2419 for (testnum = 0; testnum < size_num; testnum++) {
2420 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2421 lengths[testnum], seconds.sym);
2424 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2426 print_result(D_CBC_192_AES, testnum, count, d);
2429 if (doit[D_CBC_256_AES]) {
2430 for (testnum = 0; testnum < size_num; testnum++) {
2431 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2432 lengths[testnum], seconds.sym);
2435 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2437 print_result(D_CBC_256_AES, testnum, count, d);
2442 if (doit[D_IGE_128_AES]) {
2443 for (testnum = 0; testnum < size_num; testnum++) {
2444 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2445 lengths[testnum], seconds.sym);
2448 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2450 print_result(D_IGE_128_AES, testnum, count, d);
2453 if (doit[D_IGE_192_AES]) {
2454 for (testnum = 0; testnum < size_num; testnum++) {
2455 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2456 lengths[testnum], seconds.sym);
2459 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2461 print_result(D_IGE_192_AES, testnum, count, d);
2464 if (doit[D_IGE_256_AES]) {
2465 for (testnum = 0; testnum < size_num; testnum++) {
2466 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2467 lengths[testnum], seconds.sym);
2470 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2472 print_result(D_IGE_256_AES, testnum, count, d);
2476 if (doit[D_GHASH]) {
2477 for (i = 0; i < loopargs_len; i++) {
2478 loopargs[i].gcm_ctx =
2479 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2480 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2481 (unsigned char *)"0123456789ab", 12);
2484 for (testnum = 0; testnum < size_num; testnum++) {
2485 print_message(names[D_GHASH], c[D_GHASH][testnum],
2486 lengths[testnum], seconds.sym);
2488 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2490 print_result(D_GHASH, testnum, count, d);
2492 for (i = 0; i < loopargs_len; i++)
2493 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2495 #ifndef OPENSSL_NO_CAMELLIA
2496 if (doit[D_CBC_128_CML]) {
2497 if (async_jobs > 0) {
2498 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2499 names[D_CBC_128_CML]);
2500 doit[D_CBC_128_CML] = 0;
2502 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2503 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2504 lengths[testnum], seconds.sym);
2506 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2507 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2508 (size_t)lengths[testnum], &camellia_ks1,
2509 iv, CAMELLIA_ENCRYPT);
2511 print_result(D_CBC_128_CML, testnum, count, d);
2514 if (doit[D_CBC_192_CML]) {
2515 if (async_jobs > 0) {
2516 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2517 names[D_CBC_192_CML]);
2518 doit[D_CBC_192_CML] = 0;
2520 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2521 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2522 lengths[testnum], seconds.sym);
2523 if (async_jobs > 0) {
2524 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2528 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2529 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2530 (size_t)lengths[testnum], &camellia_ks2,
2531 iv, CAMELLIA_ENCRYPT);
2533 print_result(D_CBC_192_CML, testnum, count, d);
2536 if (doit[D_CBC_256_CML]) {
2537 if (async_jobs > 0) {
2538 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2539 names[D_CBC_256_CML]);
2540 doit[D_CBC_256_CML] = 0;
2542 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2543 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2544 lengths[testnum], seconds.sym);
2546 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2547 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2548 (size_t)lengths[testnum], &camellia_ks3,
2549 iv, CAMELLIA_ENCRYPT);
2551 print_result(D_CBC_256_CML, testnum, count, d);
2555 #ifndef OPENSSL_NO_IDEA
2556 if (doit[D_CBC_IDEA]) {
2557 if (async_jobs > 0) {
2558 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2560 doit[D_CBC_IDEA] = 0;
2562 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2563 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2564 lengths[testnum], seconds.sym);
2566 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2567 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2568 (size_t)lengths[testnum], &idea_ks,
2571 print_result(D_CBC_IDEA, testnum, count, d);
2575 #ifndef OPENSSL_NO_SEED
2576 if (doit[D_CBC_SEED]) {
2577 if (async_jobs > 0) {
2578 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2580 doit[D_CBC_SEED] = 0;
2582 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2583 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2584 lengths[testnum], seconds.sym);
2586 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2587 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2588 (size_t)lengths[testnum], &seed_ks, iv, 1);
2590 print_result(D_CBC_SEED, testnum, count, d);
2594 #ifndef OPENSSL_NO_RC2
2595 if (doit[D_CBC_RC2]) {
2596 if (async_jobs > 0) {
2597 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2599 doit[D_CBC_RC2] = 0;
2601 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2602 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2603 lengths[testnum], seconds.sym);
2604 if (async_jobs > 0) {
2605 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2609 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2610 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2611 (size_t)lengths[testnum], &rc2_ks,
2614 print_result(D_CBC_RC2, testnum, count, d);
2618 #ifndef OPENSSL_NO_RC5
2619 if (doit[D_CBC_RC5]) {
2620 if (async_jobs > 0) {
2621 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2623 doit[D_CBC_RC5] = 0;
2625 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2626 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2627 lengths[testnum], seconds.sym);
2628 if (async_jobs > 0) {
2629 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2633 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2634 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2635 (size_t)lengths[testnum], &rc5_ks,
2638 print_result(D_CBC_RC5, testnum, count, d);
2642 #ifndef OPENSSL_NO_BF
2643 if (doit[D_CBC_BF]) {
2644 if (async_jobs > 0) {
2645 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2649 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2650 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2651 lengths[testnum], seconds.sym);
2653 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2654 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2655 (size_t)lengths[testnum], &bf_ks,
2658 print_result(D_CBC_BF, testnum, count, d);
2662 #ifndef OPENSSL_NO_CAST
2663 if (doit[D_CBC_CAST]) {
2664 if (async_jobs > 0) {
2665 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2667 doit[D_CBC_CAST] = 0;
2669 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2670 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2671 lengths[testnum], seconds.sym);
2673 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2674 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2675 (size_t)lengths[testnum], &cast_ks,
2678 print_result(D_CBC_CAST, testnum, count, d);
2683 for (testnum = 0; testnum < size_num; testnum++) {
2684 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2687 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2689 print_result(D_RAND, testnum, count, d);
2694 if (evp_cipher != NULL) {
2695 int (*loopfunc)(void *args) = EVP_Update_loop;
2697 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2698 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2699 multiblock_speed(evp_cipher, lengths_single, &seconds);
2704 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2706 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2707 loopfunc = EVP_Update_loop_ccm;
2708 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2709 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2710 loopfunc = EVP_Update_loop_aead;
2711 if (lengths == lengths_list) {
2712 lengths = aead_lengths_list;
2713 size_num = OSSL_NELEM(aead_lengths_list);
2717 for (testnum = 0; testnum < size_num; testnum++) {
2718 print_message(names[D_EVP], save_count, lengths[testnum],
2721 for (k = 0; k < loopargs_len; k++) {
2722 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2723 if (loopargs[k].ctx == NULL) {
2724 BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
2727 if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2728 NULL, iv, decrypt ? 0 : 1)) {
2729 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2730 ERR_print_errors(bio_err);
2734 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2736 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2737 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2738 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2739 if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2740 loopargs[k].key, NULL, -1)) {
2741 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2742 ERR_print_errors(bio_err);
2745 OPENSSL_clear_free(loopargs[k].key, keylen);
2747 /* SIV mode only allows for a single Update operation */
2748 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
2749 EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
2753 count = run_benchmark(async_jobs, loopfunc, loopargs);
2755 for (k = 0; k < loopargs_len; k++) {
2756 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2758 print_result(D_EVP, testnum, count, d);
2760 } else if (evp_md != NULL) {
2761 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2763 for (testnum = 0; testnum < size_num; testnum++) {
2764 print_message(names[D_EVP], save_count, lengths[testnum],
2767 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2769 print_result(D_EVP, testnum, count, d);
2774 if (doit[D_EVP_HMAC]) {
2775 if (evp_hmac_md != NULL) {
2776 const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
2777 evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
2779 sprintf(evp_hmac_name, "HMAC(%s)", md_name);
2780 names[D_EVP_HMAC] = evp_hmac_name;
2782 for (testnum = 0; testnum < size_num; testnum++) {
2783 print_message(names[D_EVP_HMAC], save_count, lengths[testnum],
2786 count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
2788 print_result(D_EVP_HMAC, testnum, count, d);
2793 #ifndef OPENSSL_NO_CMAC
2794 if (doit[D_EVP_CMAC]) {
2795 if (evp_cmac_cipher != NULL) {
2796 const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
2797 evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
2799 sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
2800 names[D_EVP_CMAC] = evp_cmac_name;
2802 for (i = 0; i < loopargs_len; i++) {
2803 loopargs[i].cmac_ctx = CMAC_CTX_new();
2804 if (loopargs[i].cmac_ctx == NULL) {
2805 BIO_printf(bio_err, "CMAC malloc failure, exiting...");
2809 for (testnum = 0; testnum < size_num; testnum++) {
2810 print_message(names[D_EVP_CMAC], save_count, lengths[testnum],
2813 count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
2815 print_result(D_EVP_CMAC, testnum, count, d);
2817 for (i = 0; i < loopargs_len; i++)
2818 CMAC_CTX_free(loopargs[i].cmac_ctx);
2823 for (i = 0; i < loopargs_len; i++)
2824 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2827 #ifndef OPENSSL_NO_RSA
2828 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2830 if (!rsa_doit[testnum])
2832 for (i = 0; i < loopargs_len; i++) {
2834 /* we haven't set keys yet, generate multi-prime RSA keys */
2835 BIGNUM *bn = BN_new();
2839 if (!BN_set_word(bn, RSA_F4)) {
2844 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2845 rsa_choices[testnum].name);
2847 loopargs[i].rsa_key[testnum] = RSA_new();
2848 if (loopargs[i].rsa_key[testnum] == NULL) {
2853 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2855 primes, bn, NULL)) {
2861 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2862 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2868 "RSA sign failure. No RSA sign will be done.\n");
2869 ERR_print_errors(bio_err);
2872 pkey_print_message("private", "rsa",
2873 rsa_c[testnum][0], rsa_bits[testnum],
2875 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2877 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2880 mr ? "+R1:%ld:%d:%.2f\n"
2881 : "%ld %u bits private RSA's in %.2fs\n",
2882 count, rsa_bits[testnum], d);
2883 rsa_results[testnum][0] = (double)count / d;
2887 for (i = 0; i < loopargs_len; i++) {
2888 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2889 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2895 "RSA verify failure. No RSA verify will be done.\n");
2896 ERR_print_errors(bio_err);
2897 rsa_doit[testnum] = 0;
2899 pkey_print_message("public", "rsa",
2900 rsa_c[testnum][1], rsa_bits[testnum],
2903 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2906 mr ? "+R2:%ld:%d:%.2f\n"
2907 : "%ld %u bits public RSA's in %.2fs\n",
2908 count, rsa_bits[testnum], d);
2909 rsa_results[testnum][1] = (double)count / d;
2912 if (rsa_count <= 1) {
2913 /* if longer than 10s, don't do any more */
2914 for (testnum++; testnum < RSA_NUM; testnum++)
2915 rsa_doit[testnum] = 0;
2918 #endif /* OPENSSL_NO_RSA */
2920 for (i = 0; i < loopargs_len; i++)
2921 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2924 #ifndef OPENSSL_NO_DSA
2925 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2927 if (!dsa_doit[testnum])
2930 /* DSA_generate_key(dsa_key[testnum]); */
2931 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2932 for (i = 0; i < loopargs_len; i++) {
2933 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2934 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2940 "DSA sign failure. No DSA sign will be done.\n");
2941 ERR_print_errors(bio_err);
2944 pkey_print_message("sign", "dsa",
2945 dsa_c[testnum][0], dsa_bits[testnum],
2948 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2951 mr ? "+R3:%ld:%u:%.2f\n"
2952 : "%ld %u bits DSA signs in %.2fs\n",
2953 count, dsa_bits[testnum], d);
2954 dsa_results[testnum][0] = (double)count / d;
2958 for (i = 0; i < loopargs_len; i++) {
2959 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2960 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2966 "DSA verify failure. No DSA verify will be done.\n");
2967 ERR_print_errors(bio_err);
2968 dsa_doit[testnum] = 0;
2970 pkey_print_message("verify", "dsa",
2971 dsa_c[testnum][1], dsa_bits[testnum],
2974 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2977 mr ? "+R4:%ld:%u:%.2f\n"
2978 : "%ld %u bits DSA verify in %.2fs\n",
2979 count, dsa_bits[testnum], d);
2980 dsa_results[testnum][1] = (double)count / d;
2983 if (rsa_count <= 1) {
2984 /* if longer than 10s, don't do any more */
2985 for (testnum++; testnum < DSA_NUM; testnum++)
2986 dsa_doit[testnum] = 0;
2989 #endif /* OPENSSL_NO_DSA */
2991 #ifndef OPENSSL_NO_EC
2992 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
2995 if (!ecdsa_doit[testnum])
2996 continue; /* Ignore Curve */
2997 for (i = 0; i < loopargs_len; i++) {
2998 loopargs[i].ecdsa[testnum] =
2999 EC_KEY_new_by_curve_name(test_curves[testnum].nid);
3000 if (loopargs[i].ecdsa[testnum] == NULL) {
3006 BIO_printf(bio_err, "ECDSA failure.\n");
3007 ERR_print_errors(bio_err);
3010 for (i = 0; i < loopargs_len; i++) {
3011 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
3012 /* Perform ECDSA signature test */
3013 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
3014 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
3015 &loopargs[i].siglen,
3016 loopargs[i].ecdsa[testnum]);
3022 "ECDSA sign failure. No ECDSA sign will be done.\n");
3023 ERR_print_errors(bio_err);
3026 pkey_print_message("sign", "ecdsa",
3027 ecdsa_c[testnum][0],
3028 test_curves[testnum].bits, seconds.ecdsa);
3030 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
3034 mr ? "+R5:%ld:%u:%.2f\n" :
3035 "%ld %u bits ECDSA signs in %.2fs \n",
3036 count, test_curves[testnum].bits, d);
3037 ecdsa_results[testnum][0] = (double)count / d;
3041 /* Perform ECDSA verification test */
3042 for (i = 0; i < loopargs_len; i++) {
3043 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3045 loopargs[i].ecdsa[testnum]);
3051 "ECDSA verify failure. No ECDSA verify will be done.\n");
3052 ERR_print_errors(bio_err);
3053 ecdsa_doit[testnum] = 0;
3055 pkey_print_message("verify", "ecdsa",
3056 ecdsa_c[testnum][1],
3057 test_curves[testnum].bits, seconds.ecdsa);
3059 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
3062 mr ? "+R6:%ld:%u:%.2f\n"
3063 : "%ld %u bits ECDSA verify in %.2fs\n",
3064 count, test_curves[testnum].bits, d);
3065 ecdsa_results[testnum][1] = (double)count / d;
3068 if (rsa_count <= 1) {
3069 /* if longer than 10s, don't do any more */
3070 for (testnum++; testnum < ECDSA_NUM; testnum++)
3071 ecdsa_doit[testnum] = 0;
3076 for (testnum = 0; testnum < EC_NUM; testnum++) {
3077 int ecdh_checks = 1;
3079 if (!ecdh_doit[testnum])
3082 for (i = 0; i < loopargs_len; i++) {
3083 EVP_PKEY_CTX *kctx = NULL;
3084 EVP_PKEY_CTX *test_ctx = NULL;
3085 EVP_PKEY_CTX *ctx = NULL;
3086 EVP_PKEY *key_A = NULL;
3087 EVP_PKEY *key_B = NULL;
3091 /* Ensure that the error queue is empty */
3092 if (ERR_peek_error()) {
3094 "WARNING: the error queue contains previous unhandled errors.\n");
3095 ERR_print_errors(bio_err);
3098 /* Let's try to create a ctx directly from the NID: this works for
3099 * curves like Curve25519 that are not implemented through the low
3100 * level EC interface.
3101 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
3102 * then we set the curve by NID before deriving the actual keygen
3103 * ctx for that specific curve. */
3104 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum].nid, NULL); /* keygen ctx from NID */
3106 EVP_PKEY_CTX *pctx = NULL;
3107 EVP_PKEY *params = NULL;
3109 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
3110 * "int_ctx_new:unsupported algorithm" error was added to the
3112 * We remove it from the error queue as we are handling it. */
3113 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
3114 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
3115 /* check that the error origin matches */
3116 ERR_GET_LIB(error) == ERR_LIB_EVP &&
3117 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
3118 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
3119 ERR_get_error(); /* pop error from queue */
3120 if (ERR_peek_error()) {
3122 "Unhandled error in the error queue during ECDH init.\n");
3123 ERR_print_errors(bio_err);
3128 if ( /* Create the context for parameter generation */
3129 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
3130 /* Initialise the parameter generation */
3131 !EVP_PKEY_paramgen_init(pctx) ||
3132 /* Set the curve by NID */
3133 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3136 /* Create the parameter object params */
3137 !EVP_PKEY_paramgen(pctx, ¶ms)) {
3139 BIO_printf(bio_err, "ECDH EC params init failure.\n");
3140 ERR_print_errors(bio_err);
3144 /* Create the context for the key generation */
3145 kctx = EVP_PKEY_CTX_new(params, NULL);
3147 EVP_PKEY_free(params);
3149 EVP_PKEY_CTX_free(pctx);
3152 if (kctx == NULL || /* keygen ctx is not null */
3153 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
3155 BIO_printf(bio_err, "ECDH keygen failure.\n");
3156 ERR_print_errors(bio_err);
3161 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
3162 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
3163 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
3164 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
3165 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
3166 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
3167 outlen == 0 || /* ensure outlen is a valid size */
3168 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
3170 BIO_printf(bio_err, "ECDH key generation failure.\n");
3171 ERR_print_errors(bio_err);
3176 /* Here we perform a test run, comparing the output of a*B and b*A;
3177 * we try this here and assume that further EVP_PKEY_derive calls
3178 * never fail, so we can skip checks in the actually benchmarked
3179 * code, for maximum performance. */
3180 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3181 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3182 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3183 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3184 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3185 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3186 test_outlen != outlen /* compare output length */ ) {
3188 BIO_printf(bio_err, "ECDH computation failure.\n");
3189 ERR_print_errors(bio_err);
3194 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3195 if (CRYPTO_memcmp(loopargs[i].secret_a,
3196 loopargs[i].secret_b, outlen)) {
3198 BIO_printf(bio_err, "ECDH computations don't match.\n");
3199 ERR_print_errors(bio_err);
3204 loopargs[i].ecdh_ctx[testnum] = ctx;
3205 loopargs[i].outlen[testnum] = outlen;
3207 EVP_PKEY_free(key_A);
3208 EVP_PKEY_free(key_B);
3209 EVP_PKEY_CTX_free(kctx);
3211 EVP_PKEY_CTX_free(test_ctx);
3214 if (ecdh_checks != 0) {
3215 pkey_print_message("", "ecdh",
3217 test_curves[testnum].bits, seconds.ecdh);
3220 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3223 mr ? "+R7:%ld:%d:%.2f\n" :
3224 "%ld %u-bits ECDH ops in %.2fs\n", count,
3225 test_curves[testnum].bits, d);
3226 ecdh_results[testnum][0] = (double)count / d;
3230 if (rsa_count <= 1) {
3231 /* if longer than 10s, don't do any more */
3232 for (testnum++; testnum < OSSL_NELEM(ecdh_doit); testnum++)
3233 ecdh_doit[testnum] = 0;
3237 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3239 EVP_PKEY *ed_pkey = NULL;
3240 EVP_PKEY_CTX *ed_pctx = NULL;
3242 if (!eddsa_doit[testnum])
3243 continue; /* Ignore Curve */
3244 for (i = 0; i < loopargs_len; i++) {
3245 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3246 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3251 if ((ed_pctx = EVP_PKEY_CTX_new_id(test_ed_curves[testnum].nid, NULL))
3253 || !EVP_PKEY_keygen_init(ed_pctx)
3254 || !EVP_PKEY_keygen(ed_pctx, &ed_pkey)) {
3256 EVP_PKEY_CTX_free(ed_pctx);
3259 EVP_PKEY_CTX_free(ed_pctx);
3261 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3264 EVP_PKEY_free(ed_pkey);
3267 EVP_PKEY_free(ed_pkey);
3270 BIO_printf(bio_err, "EdDSA failure.\n");
3271 ERR_print_errors(bio_err);
3274 for (i = 0; i < loopargs_len; i++) {
3275 /* Perform EdDSA signature test */
3276 loopargs[i].sigsize = test_ed_curves[testnum].sigsize;
3277 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3278 loopargs[i].buf2, &loopargs[i].sigsize,
3279 loopargs[i].buf, 20);
3285 "EdDSA sign failure. No EdDSA sign will be done.\n");
3286 ERR_print_errors(bio_err);
3289 pkey_print_message("sign", test_ed_curves[testnum].name,
3290 eddsa_c[testnum][0],
3291 test_ed_curves[testnum].bits, seconds.eddsa);
3293 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3297 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3298 "%ld %u bits %s signs in %.2fs \n",
3299 count, test_ed_curves[testnum].bits,
3300 test_ed_curves[testnum].name, d);
3301 eddsa_results[testnum][0] = (double)count / d;
3305 /* Perform EdDSA verification test */
3306 for (i = 0; i < loopargs_len; i++) {
3307 st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
3308 loopargs[i].buf2, loopargs[i].sigsize,
3309 loopargs[i].buf, 20);
3315 "EdDSA verify failure. No EdDSA verify will be done.\n");
3316 ERR_print_errors(bio_err);
3317 eddsa_doit[testnum] = 0;
3319 pkey_print_message("verify", test_ed_curves[testnum].name,
3320 eddsa_c[testnum][1],
3321 test_ed_curves[testnum].bits, seconds.eddsa);
3323 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3326 mr ? "+R9:%ld:%u:%s:%.2f\n"
3327 : "%ld %u bits %s verify in %.2fs\n",
3328 count, test_ed_curves[testnum].bits,
3329 test_ed_curves[testnum].name, d);
3330 eddsa_results[testnum][1] = (double)count / d;
3333 if (rsa_count <= 1) {
3334 /* if longer than 10s, don't do any more */
3335 for (testnum++; testnum < EdDSA_NUM; testnum++)
3336 eddsa_doit[testnum] = 0;
3341 #endif /* OPENSSL_NO_EC */
3346 printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
3347 printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3349 printf("%s ", BN_options());
3350 #ifndef OPENSSL_NO_MD2
3351 printf("%s ", MD2_options());
3353 #ifndef OPENSSL_NO_RC4
3354 printf("%s ", RC4_options());
3356 #ifndef OPENSSL_NO_DES
3357 printf("%s ", DES_options());
3359 printf("%s ", AES_options());
3360 #ifndef OPENSSL_NO_IDEA
3361 printf("%s ", IDEA_options());
3363 #ifndef OPENSSL_NO_BF
3364 printf("%s ", BF_options());
3366 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3374 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3377 for (testnum = 0; testnum < size_num; testnum++)
3378 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3382 for (k = 0; k < ALGOR_NUM; k++) {
3386 printf("+F:%u:%s", k, names[k]);
3388 printf("%-13s", names[k]);
3389 for (testnum = 0; testnum < size_num; testnum++) {
3390 if (results[k][testnum] > 10000 && !mr)
3391 printf(" %11.2fk", results[k][testnum] / 1e3);
3393 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3397 #ifndef OPENSSL_NO_RSA
3399 for (k = 0; k < RSA_NUM; k++) {
3402 if (testnum && !mr) {
3403 printf("%18ssign verify sign/s verify/s\n", " ");
3407 printf("+F2:%u:%u:%f:%f\n",
3408 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
3410 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3411 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3412 rsa_results[k][0], rsa_results[k][1]);
3415 #ifndef OPENSSL_NO_DSA
3417 for (k = 0; k < DSA_NUM; k++) {
3420 if (testnum && !mr) {
3421 printf("%18ssign verify sign/s verify/s\n", " ");
3425 printf("+F3:%u:%u:%f:%f\n",
3426 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3428 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3429 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3430 dsa_results[k][0], dsa_results[k][1]);
3433 #ifndef OPENSSL_NO_EC
3435 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3438 if (testnum && !mr) {
3439 printf("%30ssign verify sign/s verify/s\n", " ");
3444 printf("+F4:%u:%u:%f:%f\n",
3445 k, test_curves[k].bits,
3446 ecdsa_results[k][0], ecdsa_results[k][1]);
3448 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3449 test_curves[k].bits, test_curves[k].name,
3450 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3451 ecdsa_results[k][0], ecdsa_results[k][1]);
3455 for (k = 0; k < EC_NUM; k++) {
3458 if (testnum && !mr) {
3459 printf("%30sop op/s\n", " ");
3463 printf("+F5:%u:%u:%f:%f\n",
3464 k, test_curves[k].bits,
3465 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3468 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3469 test_curves[k].bits, test_curves[k].name,
3470 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3474 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
3477 if (testnum && !mr) {
3478 printf("%30ssign verify sign/s verify/s\n", " ");
3483 printf("+F6:%u:%u:%s:%f:%f\n",
3484 k, test_ed_curves[k].bits, test_ed_curves[k].name,
3485 eddsa_results[k][0], eddsa_results[k][1]);
3487 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3488 test_ed_curves[k].bits, test_ed_curves[k].name,
3489 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
3490 eddsa_results[k][0], eddsa_results[k][1]);
3497 ERR_print_errors(bio_err);
3498 for (i = 0; i < loopargs_len; i++) {
3499 OPENSSL_free(loopargs[i].buf_malloc);
3500 OPENSSL_free(loopargs[i].buf2_malloc);
3502 #ifndef OPENSSL_NO_RSA
3503 for (k = 0; k < RSA_NUM; k++)
3504 RSA_free(loopargs[i].rsa_key[k]);
3506 #ifndef OPENSSL_NO_DSA
3507 for (k = 0; k < DSA_NUM; k++)
3508 DSA_free(loopargs[i].dsa_key[k]);
3510 #ifndef OPENSSL_NO_EC
3511 for (k = 0; k < ECDSA_NUM; k++)
3512 EC_KEY_free(loopargs[i].ecdsa[k]);
3513 for (k = 0; k < EC_NUM; k++)
3514 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3515 for (k = 0; k < EdDSA_NUM; k++)
3516 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
3517 OPENSSL_free(loopargs[i].secret_a);
3518 OPENSSL_free(loopargs[i].secret_b);
3521 OPENSSL_free(evp_hmac_name);
3522 #ifndef OPENSSL_NO_CMAC
3523 OPENSSL_free(evp_cmac_name);
3526 if (async_jobs > 0) {
3527 for (i = 0; i < loopargs_len; i++)
3528 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3532 ASYNC_cleanup_thread();
3534 OPENSSL_free(loopargs);
3539 static void print_message(const char *s, long num, int length, int tm)
3543 mr ? "+DT:%s:%d:%d\n"
3544 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3545 (void)BIO_flush(bio_err);
3549 mr ? "+DN:%s:%ld:%d\n"
3550 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3551 (void)BIO_flush(bio_err);
3555 static void pkey_print_message(const char *str, const char *str2, long num,
3556 unsigned int bits, int tm)
3560 mr ? "+DTP:%d:%s:%s:%d\n"
3561 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
3562 (void)BIO_flush(bio_err);
3566 mr ? "+DNP:%ld:%d:%s:%s\n"
3567 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
3568 (void)BIO_flush(bio_err);
3572 static void print_result(int alg, int run_no, int count, double time_used)
3575 BIO_puts(bio_err, "EVP error!\n");
3579 mr ? "+R:%d:%s:%f\n"
3580 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3581 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3585 static char *sstrsep(char **string, const char *delim)
3588 char *token = *string;
3593 memset(isdelim, 0, sizeof(isdelim));
3597 isdelim[(unsigned char)(*delim)] = 1;
3601 while (!isdelim[(unsigned char)(**string)]) {
3613 static int do_multi(int multi, int size_num)
3618 static char sep[] = ":";
3620 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
3621 for (n = 0; n < multi; ++n) {
3622 if (pipe(fd) == -1) {
3623 BIO_printf(bio_err, "pipe failure\n");
3627 (void)BIO_flush(bio_err);
3634 if (dup(fd[1]) == -1) {
3635 BIO_printf(bio_err, "dup failed\n");
3644 printf("Forked child %d\n", n);
3647 /* for now, assume the pipe is long enough to take all the output */
3648 for (n = 0; n < multi; ++n) {
3653 f = fdopen(fds[n], "r");
3654 while (fgets(buf, sizeof(buf), f)) {
3655 p = strchr(buf, '\n');
3658 if (buf[0] != '+') {
3660 "Don't understand line '%s' from child %d\n", buf,
3664 printf("Got: %s from %d\n", buf, n);
3665 if (strncmp(buf, "+F:", 3) == 0) {
3670 alg = atoi(sstrsep(&p, sep));
3672 for (j = 0; j < size_num; ++j)
3673 results[alg][j] += atof(sstrsep(&p, sep));
3674 } else if (strncmp(buf, "+F2:", 4) == 0) {
3679 k = atoi(sstrsep(&p, sep));
3682 d = atof(sstrsep(&p, sep));
3683 rsa_results[k][0] += d;
3685 d = atof(sstrsep(&p, sep));
3686 rsa_results[k][1] += d;
3688 # ifndef OPENSSL_NO_DSA
3689 else if (strncmp(buf, "+F3:", 4) == 0) {
3694 k = atoi(sstrsep(&p, sep));
3697 d = atof(sstrsep(&p, sep));
3698 dsa_results[k][0] += d;
3700 d = atof(sstrsep(&p, sep));
3701 dsa_results[k][1] += d;
3704 # ifndef OPENSSL_NO_EC
3705 else if (strncmp(buf, "+F4:", 4) == 0) {
3710 k = atoi(sstrsep(&p, sep));
3713 d = atof(sstrsep(&p, sep));
3714 ecdsa_results[k][0] += d;
3716 d = atof(sstrsep(&p, sep));
3717 ecdsa_results[k][1] += d;
3718 } else if (strncmp(buf, "+F5:", 4) == 0) {
3723 k = atoi(sstrsep(&p, sep));
3726 d = atof(sstrsep(&p, sep));
3727 ecdh_results[k][0] += d;
3728 } else if (strncmp(buf, "+F6:", 4) == 0) {
3733 k = atoi(sstrsep(&p, sep));
3736 d = atof(sstrsep(&p, sep));
3737 eddsa_results[k][0] += d;
3739 d = atof(sstrsep(&p, sep));
3740 eddsa_results[k][1] += d;
3744 else if (strncmp(buf, "+H:", 3) == 0) {
3747 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3758 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
3759 const openssl_speed_sec_t *seconds)
3761 static const int mblengths_list[] =
3762 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3763 const int *mblengths = mblengths_list;
3764 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
3765 const char *alg_name;
3766 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
3767 EVP_CIPHER_CTX *ctx;
3770 if (lengths_single) {
3771 mblengths = &lengths_single;
3775 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3776 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3777 ctx = EVP_CIPHER_CTX_new();
3778 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
3780 keylen = EVP_CIPHER_CTX_key_length(ctx);
3781 key = app_malloc(keylen, "evp_cipher key");
3782 EVP_CIPHER_CTX_rand_key(ctx, key);
3783 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
3784 OPENSSL_clear_free(key, keylen);
3786 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3787 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3789 for (j = 0; j < num; j++) {
3790 print_message(alg_name, 0, mblengths[j], seconds->sym);
3792 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3793 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3794 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3795 size_t len = mblengths[j];
3798 memset(aad, 0, 8); /* avoid uninitialized values */
3799 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3800 aad[9] = 3; /* version */
3802 aad[11] = 0; /* length */
3804 mb_param.out = NULL;
3807 mb_param.interleave = 8;
3809 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3810 sizeof(mb_param), &mb_param);
3816 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3817 sizeof(mb_param), &mb_param);
3821 RAND_bytes(out, 16);
3823 aad[11] = (unsigned char)(len >> 8);
3824 aad[12] = (unsigned char)(len);
3825 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3826 EVP_AEAD_TLS1_AAD_LEN, aad);
3827 EVP_Cipher(ctx, out, inp, len + pad);
3831 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3832 : "%d %s's in %.2fs\n", count, "evp", d);
3833 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3837 fprintf(stdout, "+H");
3838 for (j = 0; j < num; j++)
3839 fprintf(stdout, ":%d", mblengths[j]);
3840 fprintf(stdout, "\n");
3841 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3842 for (j = 0; j < num; j++)
3843 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3844 fprintf(stdout, "\n");
3847 "The 'numbers' are in 1000s of bytes per second processed.\n");
3848 fprintf(stdout, "type ");
3849 for (j = 0; j < num; j++)
3850 fprintf(stdout, "%7d bytes", mblengths[j]);
3851 fprintf(stdout, "\n");
3852 fprintf(stdout, "%-24s", alg_name);
3854 for (j = 0; j < num; j++) {
3855 if (results[D_EVP][j] > 10000)
3856 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3858 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3860 fprintf(stdout, "\n");
3865 EVP_CIPHER_CTX_free(ctx);