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)
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 #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_ige_128_encrypt_loop(void *args);
170 static int AES_cbc_256_encrypt_loop(void *args);
171 static int AES_ige_192_encrypt_loop(void *args);
172 static int AES_ige_256_encrypt_loop(void *args);
173 static int CRYPTO_gcm128_aad_loop(void *args);
174 static int RAND_bytes_loop(void *args);
175 static int EVP_Update_loop(void *args);
176 static int EVP_Update_loop_ccm(void *args);
177 static int EVP_Update_loop_aead(void *args);
178 static int EVP_Digest_loop(void *args);
179 #ifndef OPENSSL_NO_RSA
180 static int RSA_sign_loop(void *args);
181 static int RSA_verify_loop(void *args);
183 #ifndef OPENSSL_NO_DSA
184 static int DSA_sign_loop(void *args);
185 static int DSA_verify_loop(void *args);
187 #ifndef OPENSSL_NO_EC
188 static int ECDSA_sign_loop(void *args);
189 static int ECDSA_verify_loop(void *args);
190 static int EdDSA_sign_loop(void *args);
191 static int EdDSA_verify_loop(void *args);
194 static double Time_F(int s);
195 static void print_message(const char *s, long num, int length, int tm);
196 static void pkey_print_message(const char *str, const char *str2,
197 long num, unsigned int bits, int sec);
198 static void print_result(int alg, int run_no, int count, double time_used);
200 static int do_multi(int multi, int size_num);
203 static const int lengths_list[] = {
204 16, 64, 256, 1024, 8 * 1024, 16 * 1024
206 static const int *lengths = lengths_list;
208 static const int aead_lengths_list[] = {
209 2, 31, 136, 1024, 8 * 1024, 16 * 1024
217 static void alarmed(int sig)
219 signal(SIGALRM, alarmed);
223 static double Time_F(int s)
225 double ret = app_tminterval(s, usertime);
231 #elif defined(_WIN32)
235 static unsigned int lapse;
236 static volatile unsigned int schlock;
237 static void alarm_win32(unsigned int secs)
242 # define alarm alarm_win32
244 static DWORD WINAPI sleepy(VOID * arg)
252 static double Time_F(int s)
259 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
261 DWORD err = GetLastError();
262 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
266 Sleep(0); /* scheduler spinlock */
267 ret = app_tminterval(s, usertime);
269 ret = app_tminterval(s, usertime);
271 TerminateThread(thr, 0);
278 static double Time_F(int s)
280 return app_tminterval(s, usertime);
284 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
285 const openssl_speed_sec_t *seconds);
287 #define found(value, pairs, result)\
288 opt_found(value, result, pairs, OSSL_NELEM(pairs))
289 static int opt_found(const char *name, unsigned int *result,
290 const OPT_PAIR pairs[], unsigned int nbelem)
294 for (idx = 0; idx < nbelem; ++idx, pairs++)
295 if (strcmp(name, pairs->name) == 0) {
296 *result = pairs->retval;
302 typedef enum OPTION_choice {
303 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
304 OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
305 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
306 OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC
309 const OPTIONS speed_options[] = {
310 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
311 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
312 {"help", OPT_HELP, '-', "Display this summary"},
313 {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
314 {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"},
315 #ifndef OPENSSL_NO_CMAC
316 {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"},
318 {"decrypt", OPT_DECRYPT, '-',
319 "Time decryption instead of encryption (only EVP)"},
320 {"aead", OPT_AEAD, '-',
321 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
323 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
324 {"mr", OPT_MR, '-', "Produce machine readable output"},
326 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
328 #ifndef OPENSSL_NO_ASYNC
329 {"async_jobs", OPT_ASYNCJOBS, 'p',
330 "Enable async mode and start specified number of jobs"},
333 #ifndef OPENSSL_NO_ENGINE
334 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
336 {"elapsed", OPT_ELAPSED, '-',
337 "Use wall-clock time instead of CPU user time as divisor"},
338 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
339 {"seconds", OPT_SECONDS, 'p',
340 "Run benchmarks for specified amount of seconds"},
341 {"bytes", OPT_BYTES, 'p',
342 "Run [non-PKI] benchmarks on custom-sized buffer"},
343 {"misalign", OPT_MISALIGN, 'p',
344 "Use specified offset to mis-align buffers"},
358 #define D_CBC_IDEA 10
359 #define D_CBC_SEED 11
363 #define D_CBC_CAST 15
364 #define D_CBC_128_AES 16
365 #define D_CBC_192_AES 17
366 #define D_CBC_256_AES 18
367 #define D_CBC_128_CML 19
368 #define D_CBC_192_CML 20
369 #define D_CBC_256_CML 21
373 #define D_WHIRLPOOL 25
374 #define D_IGE_128_AES 26
375 #define D_IGE_192_AES 27
376 #define D_IGE_256_AES 28
379 #define D_EVP_HMAC 31
380 #define D_EVP_CMAC 32
382 /* name of algorithms to test */
383 static const char *names[] = {
384 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
385 "des cbc", "des ede3", "idea cbc", "seed cbc",
386 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
387 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
388 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
389 "evp", "sha256", "sha512", "whirlpool",
390 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
391 "rand", "hmac", "cmac"
393 #define ALGOR_NUM OSSL_NELEM(names)
395 /* list of configured algorithm (remaining) */
396 static const OPT_PAIR doit_choices[] = {
397 #ifndef OPENSSL_NO_MD2
400 #ifndef OPENSSL_NO_MDC2
403 #ifndef OPENSSL_NO_MD4
406 #ifndef OPENSSL_NO_MD5
411 {"sha256", D_SHA256},
412 {"sha512", D_SHA512},
413 #ifndef OPENSSL_NO_WHIRLPOOL
414 {"whirlpool", D_WHIRLPOOL},
416 #ifndef OPENSSL_NO_RMD160
417 {"ripemd", D_RMD160},
418 {"rmd160", D_RMD160},
419 {"ripemd160", D_RMD160},
421 #ifndef OPENSSL_NO_RC4
424 #ifndef OPENSSL_NO_DES
425 {"des-cbc", D_CBC_DES},
426 {"des-ede3", D_EDE3_DES},
428 {"aes-128-cbc", D_CBC_128_AES},
429 {"aes-192-cbc", D_CBC_192_AES},
430 {"aes-256-cbc", D_CBC_256_AES},
431 {"aes-128-ige", D_IGE_128_AES},
432 {"aes-192-ige", D_IGE_192_AES},
433 {"aes-256-ige", D_IGE_256_AES},
434 #ifndef OPENSSL_NO_RC2
435 {"rc2-cbc", D_CBC_RC2},
438 #ifndef OPENSSL_NO_RC5
439 {"rc5-cbc", D_CBC_RC5},
442 #ifndef OPENSSL_NO_IDEA
443 {"idea-cbc", D_CBC_IDEA},
444 {"idea", D_CBC_IDEA},
446 #ifndef OPENSSL_NO_SEED
447 {"seed-cbc", D_CBC_SEED},
448 {"seed", D_CBC_SEED},
450 #ifndef OPENSSL_NO_BF
451 {"bf-cbc", D_CBC_BF},
452 {"blowfish", D_CBC_BF},
455 #ifndef OPENSSL_NO_CAST
456 {"cast-cbc", D_CBC_CAST},
457 {"cast", D_CBC_CAST},
458 {"cast5", D_CBC_CAST},
464 static double results[ALGOR_NUM][OSSL_NELEM(lengths_list)];
466 #ifndef OPENSSL_NO_DSA
468 # define R_DSA_1024 1
469 # define R_DSA_2048 2
470 static const OPT_PAIR dsa_choices[] = {
471 {"dsa512", R_DSA_512},
472 {"dsa1024", R_DSA_1024},
473 {"dsa2048", R_DSA_2048}
475 # define DSA_NUM OSSL_NELEM(dsa_choices)
477 static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
478 #endif /* OPENSSL_NO_DSA */
486 #define R_RSA_15360 6
487 #ifndef OPENSSL_NO_RSA
488 static const OPT_PAIR rsa_choices[] = {
489 {"rsa512", R_RSA_512},
490 {"rsa1024", R_RSA_1024},
491 {"rsa2048", R_RSA_2048},
492 {"rsa3072", R_RSA_3072},
493 {"rsa4096", R_RSA_4096},
494 {"rsa7680", R_RSA_7680},
495 {"rsa15360", R_RSA_15360}
497 # define RSA_NUM OSSL_NELEM(rsa_choices)
499 static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
500 #endif /* OPENSSL_NO_RSA */
509 #ifndef OPENSSL_NO_EC2M
531 #ifndef OPENSSL_NO_EC
532 static OPT_PAIR ecdsa_choices[] = {
533 {"ecdsap160", R_EC_P160},
534 {"ecdsap192", R_EC_P192},
535 {"ecdsap224", R_EC_P224},
536 {"ecdsap256", R_EC_P256},
537 {"ecdsap384", R_EC_P384},
538 {"ecdsap521", R_EC_P521},
539 # ifndef OPENSSL_NO_EC2M
540 {"ecdsak163", R_EC_K163},
541 {"ecdsak233", R_EC_K233},
542 {"ecdsak283", R_EC_K283},
543 {"ecdsak409", R_EC_K409},
544 {"ecdsak571", R_EC_K571},
545 {"ecdsab163", R_EC_B163},
546 {"ecdsab233", R_EC_B233},
547 {"ecdsab283", R_EC_B283},
548 {"ecdsab409", R_EC_B409},
549 {"ecdsab571", R_EC_B571},
551 {"ecdsabrp256r1", R_EC_BRP256R1},
552 {"ecdsabrp256t1", R_EC_BRP256T1},
553 {"ecdsabrp384r1", R_EC_BRP384R1},
554 {"ecdsabrp384t1", R_EC_BRP384T1},
555 {"ecdsabrp512r1", R_EC_BRP512R1},
556 {"ecdsabrp512t1", R_EC_BRP512T1}
558 # define ECDSA_NUM OSSL_NELEM(ecdsa_choices)
560 static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
562 static const OPT_PAIR ecdh_choices[] = {
563 {"ecdhp160", R_EC_P160},
564 {"ecdhp192", R_EC_P192},
565 {"ecdhp224", R_EC_P224},
566 {"ecdhp256", R_EC_P256},
567 {"ecdhp384", R_EC_P384},
568 {"ecdhp521", R_EC_P521},
569 # ifndef OPENSSL_NO_EC2M
570 {"ecdhk163", R_EC_K163},
571 {"ecdhk233", R_EC_K233},
572 {"ecdhk283", R_EC_K283},
573 {"ecdhk409", R_EC_K409},
574 {"ecdhk571", R_EC_K571},
575 {"ecdhb163", R_EC_B163},
576 {"ecdhb233", R_EC_B233},
577 {"ecdhb283", R_EC_B283},
578 {"ecdhb409", R_EC_B409},
579 {"ecdhb571", R_EC_B571},
581 {"ecdhbrp256r1", R_EC_BRP256R1},
582 {"ecdhbrp256t1", R_EC_BRP256T1},
583 {"ecdhbrp384r1", R_EC_BRP384R1},
584 {"ecdhbrp384t1", R_EC_BRP384T1},
585 {"ecdhbrp512r1", R_EC_BRP512R1},
586 {"ecdhbrp512t1", R_EC_BRP512T1},
587 {"ecdhx25519", R_EC_X25519},
588 {"ecdhx448", R_EC_X448}
590 # define EC_NUM OSSL_NELEM(ecdh_choices)
592 static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
594 #define R_EC_Ed25519 0
596 static OPT_PAIR eddsa_choices[] = {
597 {"ed25519", R_EC_Ed25519},
598 {"ed448", R_EC_Ed448}
600 # define EdDSA_NUM OSSL_NELEM(eddsa_choices)
602 static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
603 #endif /* OPENSSL_NO_EC */
606 # define COND(d) (count < (d))
607 # define COUNT(d) (d)
609 # define COND(unused_cond) (run && count<0x7fffffff)
610 # define COUNT(d) (count)
613 typedef struct loopargs_st {
614 ASYNC_JOB *inprogress_job;
615 ASYNC_WAIT_CTX *wait_ctx;
618 unsigned char *buf_malloc;
619 unsigned char *buf2_malloc;
623 #ifndef OPENSSL_NO_RSA
624 RSA *rsa_key[RSA_NUM];
626 #ifndef OPENSSL_NO_DSA
627 DSA *dsa_key[DSA_NUM];
629 #ifndef OPENSSL_NO_EC
630 EC_KEY *ecdsa[ECDSA_NUM];
631 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
632 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
633 unsigned char *secret_a;
634 unsigned char *secret_b;
635 size_t outlen[EC_NUM];
639 #ifndef OPENSSL_NO_CMAC
642 GCM128_CONTEXT *gcm_ctx;
644 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
645 loopargs_t * loopargs);
647 static unsigned int testnum;
649 /* Nb of iterations to do per algorithm and key-size */
650 static long c[ALGOR_NUM][OSSL_NELEM(lengths_list)];
652 #ifndef OPENSSL_NO_MD2
653 static int EVP_Digest_MD2_loop(void *args)
655 loopargs_t *tempargs = *(loopargs_t **) args;
656 unsigned char *buf = tempargs->buf;
657 unsigned char md2[MD2_DIGEST_LENGTH];
660 for (count = 0; COND(c[D_MD2][testnum]); count++) {
661 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
669 #ifndef OPENSSL_NO_MDC2
670 static int EVP_Digest_MDC2_loop(void *args)
672 loopargs_t *tempargs = *(loopargs_t **) args;
673 unsigned char *buf = tempargs->buf;
674 unsigned char mdc2[MDC2_DIGEST_LENGTH];
677 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
678 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
686 #ifndef OPENSSL_NO_MD4
687 static int EVP_Digest_MD4_loop(void *args)
689 loopargs_t *tempargs = *(loopargs_t **) args;
690 unsigned char *buf = tempargs->buf;
691 unsigned char md4[MD4_DIGEST_LENGTH];
694 for (count = 0; COND(c[D_MD4][testnum]); count++) {
695 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
703 #ifndef OPENSSL_NO_MD5
704 static int MD5_loop(void *args)
706 loopargs_t *tempargs = *(loopargs_t **) args;
707 unsigned char *buf = tempargs->buf;
708 unsigned char md5[MD5_DIGEST_LENGTH];
710 for (count = 0; COND(c[D_MD5][testnum]); count++)
711 MD5(buf, lengths[testnum], md5);
715 static int HMAC_loop(void *args)
717 loopargs_t *tempargs = *(loopargs_t **) args;
718 unsigned char *buf = tempargs->buf;
719 HMAC_CTX *hctx = tempargs->hctx;
720 unsigned char hmac[MD5_DIGEST_LENGTH];
723 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
724 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
725 HMAC_Update(hctx, buf, lengths[testnum]);
726 HMAC_Final(hctx, hmac, NULL);
732 static int SHA1_loop(void *args)
734 loopargs_t *tempargs = *(loopargs_t **) args;
735 unsigned char *buf = tempargs->buf;
736 unsigned char sha[SHA_DIGEST_LENGTH];
738 for (count = 0; COND(c[D_SHA1][testnum]); count++)
739 SHA1(buf, lengths[testnum], sha);
743 static int SHA256_loop(void *args)
745 loopargs_t *tempargs = *(loopargs_t **) args;
746 unsigned char *buf = tempargs->buf;
747 unsigned char sha256[SHA256_DIGEST_LENGTH];
749 for (count = 0; COND(c[D_SHA256][testnum]); count++)
750 SHA256(buf, lengths[testnum], sha256);
754 static int SHA512_loop(void *args)
756 loopargs_t *tempargs = *(loopargs_t **) args;
757 unsigned char *buf = tempargs->buf;
758 unsigned char sha512[SHA512_DIGEST_LENGTH];
760 for (count = 0; COND(c[D_SHA512][testnum]); count++)
761 SHA512(buf, lengths[testnum], sha512);
765 #ifndef OPENSSL_NO_WHIRLPOOL
766 static int WHIRLPOOL_loop(void *args)
768 loopargs_t *tempargs = *(loopargs_t **) args;
769 unsigned char *buf = tempargs->buf;
770 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
772 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
773 WHIRLPOOL(buf, lengths[testnum], whirlpool);
778 #ifndef OPENSSL_NO_RMD160
779 static int EVP_Digest_RMD160_loop(void *args)
781 loopargs_t *tempargs = *(loopargs_t **) args;
782 unsigned char *buf = tempargs->buf;
783 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
785 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
786 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
787 NULL, EVP_ripemd160(), NULL))
794 #ifndef OPENSSL_NO_RC4
795 static RC4_KEY rc4_ks;
796 static int RC4_loop(void *args)
798 loopargs_t *tempargs = *(loopargs_t **) args;
799 unsigned char *buf = tempargs->buf;
801 for (count = 0; COND(c[D_RC4][testnum]); count++)
802 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
807 #ifndef OPENSSL_NO_DES
808 static unsigned char DES_iv[8];
809 static DES_key_schedule sch;
810 static DES_key_schedule sch2;
811 static DES_key_schedule sch3;
812 static int DES_ncbc_encrypt_loop(void *args)
814 loopargs_t *tempargs = *(loopargs_t **) args;
815 unsigned char *buf = tempargs->buf;
817 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
818 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
819 &DES_iv, DES_ENCRYPT);
823 static int DES_ede3_cbc_encrypt_loop(void *args)
825 loopargs_t *tempargs = *(loopargs_t **) args;
826 unsigned char *buf = tempargs->buf;
828 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
829 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
830 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
835 #define MAX_BLOCK_SIZE 128
837 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
838 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
839 static int AES_cbc_128_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_128_AES][testnum]); count++)
845 AES_cbc_encrypt(buf, buf,
846 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
850 static int AES_cbc_192_encrypt_loop(void *args)
852 loopargs_t *tempargs = *(loopargs_t **) args;
853 unsigned char *buf = tempargs->buf;
855 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
856 AES_cbc_encrypt(buf, buf,
857 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
861 static int AES_cbc_256_encrypt_loop(void *args)
863 loopargs_t *tempargs = *(loopargs_t **) args;
864 unsigned char *buf = tempargs->buf;
866 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
867 AES_cbc_encrypt(buf, buf,
868 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
872 static int AES_ige_128_encrypt_loop(void *args)
874 loopargs_t *tempargs = *(loopargs_t **) args;
875 unsigned char *buf = tempargs->buf;
876 unsigned char *buf2 = tempargs->buf2;
878 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
879 AES_ige_encrypt(buf, buf2,
880 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
884 static int AES_ige_192_encrypt_loop(void *args)
886 loopargs_t *tempargs = *(loopargs_t **) args;
887 unsigned char *buf = tempargs->buf;
888 unsigned char *buf2 = tempargs->buf2;
890 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
891 AES_ige_encrypt(buf, buf2,
892 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
896 static int AES_ige_256_encrypt_loop(void *args)
898 loopargs_t *tempargs = *(loopargs_t **) args;
899 unsigned char *buf = tempargs->buf;
900 unsigned char *buf2 = tempargs->buf2;
902 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
903 AES_ige_encrypt(buf, buf2,
904 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
908 static int CRYPTO_gcm128_aad_loop(void *args)
910 loopargs_t *tempargs = *(loopargs_t **) args;
911 unsigned char *buf = tempargs->buf;
912 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
914 for (count = 0; COND(c[D_GHASH][testnum]); count++)
915 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
919 static int RAND_bytes_loop(void *args)
921 loopargs_t *tempargs = *(loopargs_t **) args;
922 unsigned char *buf = tempargs->buf;
925 for (count = 0; COND(c[D_RAND][testnum]); count++)
926 RAND_bytes(buf, lengths[testnum]);
930 static long save_count = 0;
931 static int decrypt = 0;
932 static int EVP_Update_loop(void *args)
934 loopargs_t *tempargs = *(loopargs_t **) args;
935 unsigned char *buf = tempargs->buf;
936 EVP_CIPHER_CTX *ctx = tempargs->ctx;
939 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
942 for (count = 0; COND(nb_iter); count++) {
943 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
945 /* reset iv in case of counter overflow */
946 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
950 for (count = 0; COND(nb_iter); count++) {
951 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
953 /* reset iv in case of counter overflow */
954 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
959 EVP_DecryptFinal_ex(ctx, buf, &outl);
961 EVP_EncryptFinal_ex(ctx, buf, &outl);
966 * CCM does not support streaming. For the purpose of performance measurement,
967 * each message is encrypted using the same (key,iv)-pair. Do not use this
968 * code in your application.
970 static int EVP_Update_loop_ccm(void *args)
972 loopargs_t *tempargs = *(loopargs_t **) args;
973 unsigned char *buf = tempargs->buf;
974 EVP_CIPHER_CTX *ctx = tempargs->ctx;
976 unsigned char tag[12];
978 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
981 for (count = 0; COND(nb_iter); count++) {
982 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
984 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
985 /* counter is reset on every update */
986 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
989 for (count = 0; COND(nb_iter); count++) {
990 /* restore iv length field */
991 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
992 /* counter is reset on every update */
993 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
997 EVP_DecryptFinal_ex(ctx, buf, &outl);
999 EVP_EncryptFinal_ex(ctx, buf, &outl);
1004 * To make AEAD benchmarking more relevant perform TLS-like operations,
1005 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
1006 * payload length is not actually limited by 16KB...
1008 static int EVP_Update_loop_aead(void *args)
1010 loopargs_t *tempargs = *(loopargs_t **) args;
1011 unsigned char *buf = tempargs->buf;
1012 EVP_CIPHER_CTX *ctx = tempargs->ctx;
1014 unsigned char aad[13] = { 0xcc };
1015 unsigned char faketag[16] = { 0xcc };
1017 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1020 for (count = 0; COND(nb_iter); count++) {
1021 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
1022 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
1023 sizeof(faketag), faketag);
1024 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1025 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1026 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
1029 for (count = 0; COND(nb_iter); count++) {
1030 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
1031 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1032 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1033 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
1039 static const EVP_MD *evp_md = NULL;
1040 static int EVP_Digest_loop(void *args)
1042 loopargs_t *tempargs = *(loopargs_t **) args;
1043 unsigned char *buf = tempargs->buf;
1044 unsigned char md[EVP_MAX_MD_SIZE];
1047 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1050 for (count = 0; COND(nb_iter); count++) {
1051 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
1057 static const EVP_MD *evp_hmac_md = NULL;
1058 static char *evp_hmac_name = NULL;
1059 static int EVP_HMAC_loop(void *args)
1061 loopargs_t *tempargs = *(loopargs_t **) args;
1062 unsigned char *buf = tempargs->buf;
1063 unsigned char no_key[32];
1066 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1069 for (count = 0; COND(nb_iter); count++) {
1070 if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
1071 NULL, NULL) == NULL)
1077 #ifndef OPENSSL_NO_CMAC
1078 static const EVP_CIPHER *evp_cmac_cipher = NULL;
1079 static char *evp_cmac_name = NULL;
1081 static int EVP_CMAC_loop(void *args)
1083 loopargs_t *tempargs = *(loopargs_t **) args;
1084 unsigned char *buf = tempargs->buf;
1085 CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
1086 static const char key[16] = "This is a key...";
1087 unsigned char mac[16];
1088 size_t len = sizeof(mac);
1091 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
1094 for (count = 0; COND(nb_iter); count++) {
1095 if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
1096 || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
1097 || !CMAC_Final(cmac_ctx, mac, &len))
1104 #ifndef OPENSSL_NO_RSA
1105 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1107 static int RSA_sign_loop(void *args)
1109 loopargs_t *tempargs = *(loopargs_t **) args;
1110 unsigned char *buf = tempargs->buf;
1111 unsigned char *buf2 = tempargs->buf2;
1112 unsigned int *rsa_num = &tempargs->siglen;
1113 RSA **rsa_key = tempargs->rsa_key;
1115 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1116 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1118 BIO_printf(bio_err, "RSA sign failure\n");
1119 ERR_print_errors(bio_err);
1127 static int RSA_verify_loop(void *args)
1129 loopargs_t *tempargs = *(loopargs_t **) args;
1130 unsigned char *buf = tempargs->buf;
1131 unsigned char *buf2 = tempargs->buf2;
1132 unsigned int rsa_num = tempargs->siglen;
1133 RSA **rsa_key = tempargs->rsa_key;
1135 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1137 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1139 BIO_printf(bio_err, "RSA verify failure\n");
1140 ERR_print_errors(bio_err);
1149 #ifndef OPENSSL_NO_DSA
1150 static long dsa_c[DSA_NUM][2];
1151 static int DSA_sign_loop(void *args)
1153 loopargs_t *tempargs = *(loopargs_t **) args;
1154 unsigned char *buf = tempargs->buf;
1155 unsigned char *buf2 = tempargs->buf2;
1156 DSA **dsa_key = tempargs->dsa_key;
1157 unsigned int *siglen = &tempargs->siglen;
1159 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1160 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1162 BIO_printf(bio_err, "DSA sign failure\n");
1163 ERR_print_errors(bio_err);
1171 static int DSA_verify_loop(void *args)
1173 loopargs_t *tempargs = *(loopargs_t **) args;
1174 unsigned char *buf = tempargs->buf;
1175 unsigned char *buf2 = tempargs->buf2;
1176 DSA **dsa_key = tempargs->dsa_key;
1177 unsigned int siglen = tempargs->siglen;
1179 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1180 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1182 BIO_printf(bio_err, "DSA verify failure\n");
1183 ERR_print_errors(bio_err);
1192 #ifndef OPENSSL_NO_EC
1193 static long ecdsa_c[ECDSA_NUM][2];
1194 static int ECDSA_sign_loop(void *args)
1196 loopargs_t *tempargs = *(loopargs_t **) args;
1197 unsigned char *buf = tempargs->buf;
1198 EC_KEY **ecdsa = tempargs->ecdsa;
1199 unsigned char *ecdsasig = tempargs->buf2;
1200 unsigned int *ecdsasiglen = &tempargs->siglen;
1202 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1203 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1205 BIO_printf(bio_err, "ECDSA sign failure\n");
1206 ERR_print_errors(bio_err);
1214 static int ECDSA_verify_loop(void *args)
1216 loopargs_t *tempargs = *(loopargs_t **) args;
1217 unsigned char *buf = tempargs->buf;
1218 EC_KEY **ecdsa = tempargs->ecdsa;
1219 unsigned char *ecdsasig = tempargs->buf2;
1220 unsigned int ecdsasiglen = tempargs->siglen;
1222 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1223 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1225 BIO_printf(bio_err, "ECDSA verify failure\n");
1226 ERR_print_errors(bio_err);
1234 /* ******************************************************************** */
1235 static long ecdh_c[EC_NUM][1];
1237 static int ECDH_EVP_derive_key_loop(void *args)
1239 loopargs_t *tempargs = *(loopargs_t **) args;
1240 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1241 unsigned char *derived_secret = tempargs->secret_a;
1243 size_t *outlen = &(tempargs->outlen[testnum]);
1245 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1246 EVP_PKEY_derive(ctx, derived_secret, outlen);
1251 static long eddsa_c[EdDSA_NUM][2];
1252 static int EdDSA_sign_loop(void *args)
1254 loopargs_t *tempargs = *(loopargs_t **) args;
1255 unsigned char *buf = tempargs->buf;
1256 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1257 unsigned char *eddsasig = tempargs->buf2;
1258 size_t *eddsasigsize = &tempargs->sigsize;
1261 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1262 ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1264 BIO_printf(bio_err, "EdDSA sign failure\n");
1265 ERR_print_errors(bio_err);
1273 static int EdDSA_verify_loop(void *args)
1275 loopargs_t *tempargs = *(loopargs_t **) args;
1276 unsigned char *buf = tempargs->buf;
1277 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1278 unsigned char *eddsasig = tempargs->buf2;
1279 size_t eddsasigsize = tempargs->sigsize;
1282 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1283 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1285 BIO_printf(bio_err, "EdDSA verify failure\n");
1286 ERR_print_errors(bio_err);
1293 #endif /* OPENSSL_NO_EC */
1295 static int run_benchmark(int async_jobs,
1296 int (*loop_function) (void *), loopargs_t * loopargs)
1298 int job_op_count = 0;
1299 int total_op_count = 0;
1300 int num_inprogress = 0;
1301 int error = 0, i = 0, ret = 0;
1302 OSSL_ASYNC_FD job_fd = 0;
1303 size_t num_job_fds = 0;
1307 if (async_jobs == 0) {
1308 return loop_function((void *)&loopargs);
1311 for (i = 0; i < async_jobs && !error; i++) {
1312 loopargs_t *looparg_item = loopargs + i;
1314 /* Copy pointer content (looparg_t item address) into async context */
1315 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1316 &job_op_count, loop_function,
1317 (void *)&looparg_item, sizeof(looparg_item));
1323 if (job_op_count == -1) {
1326 total_op_count += job_op_count;
1331 BIO_printf(bio_err, "Failure in the job\n");
1332 ERR_print_errors(bio_err);
1338 while (num_inprogress > 0) {
1339 #if defined(OPENSSL_SYS_WINDOWS)
1341 #elif defined(OPENSSL_SYS_UNIX)
1342 int select_result = 0;
1343 OSSL_ASYNC_FD max_fd = 0;
1346 FD_ZERO(&waitfdset);
1348 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1349 if (loopargs[i].inprogress_job == NULL)
1352 if (!ASYNC_WAIT_CTX_get_all_fds
1353 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1354 || num_job_fds > 1) {
1355 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1356 ERR_print_errors(bio_err);
1360 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1362 FD_SET(job_fd, &waitfdset);
1363 if (job_fd > max_fd)
1367 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1369 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1370 "Decrease the value of async_jobs\n",
1371 max_fd, FD_SETSIZE);
1372 ERR_print_errors(bio_err);
1377 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1378 if (select_result == -1 && errno == EINTR)
1381 if (select_result == -1) {
1382 BIO_printf(bio_err, "Failure in the select\n");
1383 ERR_print_errors(bio_err);
1388 if (select_result == 0)
1392 for (i = 0; i < async_jobs; i++) {
1393 if (loopargs[i].inprogress_job == NULL)
1396 if (!ASYNC_WAIT_CTX_get_all_fds
1397 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1398 || num_job_fds > 1) {
1399 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1400 ERR_print_errors(bio_err);
1404 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1407 #if defined(OPENSSL_SYS_UNIX)
1408 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1410 #elif defined(OPENSSL_SYS_WINDOWS)
1411 if (num_job_fds == 1
1412 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1417 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1418 loopargs[i].wait_ctx, &job_op_count,
1419 loop_function, (void *)(loopargs + i),
1420 sizeof(loopargs_t));
1425 if (job_op_count == -1) {
1428 total_op_count += job_op_count;
1431 loopargs[i].inprogress_job = NULL;
1436 loopargs[i].inprogress_job = NULL;
1437 BIO_printf(bio_err, "Failure in the job\n");
1438 ERR_print_errors(bio_err);
1445 return error ? -1 : total_op_count;
1448 int speed_main(int argc, char **argv)
1451 loopargs_t *loopargs = NULL;
1453 const char *engine_id = NULL;
1454 const EVP_CIPHER *evp_cipher = NULL;
1457 int async_init = 0, multiblock = 0, pr_header = 0;
1458 int doit[ALGOR_NUM] = { 0 };
1459 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1461 unsigned int size_num = OSSL_NELEM(lengths_list);
1462 unsigned int i, k, loop, loopargs_len = 0, async_jobs = 0;
1468 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1469 || !defined(OPENSSL_NO_EC)
1472 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1473 ECDSA_SECONDS, ECDH_SECONDS,
1476 /* What follows are the buffers and key material. */
1477 #ifndef OPENSSL_NO_RC5
1480 #ifndef OPENSSL_NO_RC2
1483 #ifndef OPENSSL_NO_IDEA
1484 IDEA_KEY_SCHEDULE idea_ks;
1486 #ifndef OPENSSL_NO_SEED
1487 SEED_KEY_SCHEDULE seed_ks;
1489 #ifndef OPENSSL_NO_BF
1492 #ifndef OPENSSL_NO_CAST
1495 static const unsigned char key16[16] = {
1496 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1497 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1499 static const unsigned char key24[24] = {
1500 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1501 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1502 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1504 static const unsigned char key32[32] = {
1505 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1506 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1507 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1508 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1510 #ifndef OPENSSL_NO_CAMELLIA
1511 static const unsigned char ckey24[24] = {
1512 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1513 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1514 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1516 static const unsigned char ckey32[32] = {
1517 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1518 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1519 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1520 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1522 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1524 #ifndef OPENSSL_NO_DES
1525 static DES_cblock key = {
1526 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1528 static DES_cblock key2 = {
1529 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1531 static DES_cblock key3 = {
1532 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1535 #ifndef OPENSSL_NO_RSA
1536 static const unsigned int rsa_bits[RSA_NUM] = {
1537 512, 1024, 2048, 3072, 4096, 7680, 15360
1539 static const unsigned char *rsa_data[RSA_NUM] = {
1540 test512, test1024, test2048, test3072, test4096, test7680, test15360
1542 static const int rsa_data_length[RSA_NUM] = {
1543 sizeof(test512), sizeof(test1024),
1544 sizeof(test2048), sizeof(test3072),
1545 sizeof(test4096), sizeof(test7680),
1548 int rsa_doit[RSA_NUM] = { 0 };
1549 int primes = RSA_DEFAULT_PRIME_NUM;
1551 #ifndef OPENSSL_NO_DSA
1552 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1553 int dsa_doit[DSA_NUM] = { 0 };
1555 #ifndef OPENSSL_NO_EC
1557 * We only test over the following curves as they are representative, To
1558 * add tests over more curves, simply add the curve NID and curve name to
1559 * the following arrays and increase the |ecdh_choices| list accordingly.
1561 static const struct {
1567 {"secp160r1", NID_secp160r1, 160},
1568 {"nistp192", NID_X9_62_prime192v1, 192},
1569 {"nistp224", NID_secp224r1, 224},
1570 {"nistp256", NID_X9_62_prime256v1, 256},
1571 {"nistp384", NID_secp384r1, 384},
1572 {"nistp521", NID_secp521r1, 521},
1573 # ifndef OPENSSL_NO_EC2M
1575 {"nistk163", NID_sect163k1, 163},
1576 {"nistk233", NID_sect233k1, 233},
1577 {"nistk283", NID_sect283k1, 283},
1578 {"nistk409", NID_sect409k1, 409},
1579 {"nistk571", NID_sect571k1, 571},
1580 {"nistb163", NID_sect163r2, 163},
1581 {"nistb233", NID_sect233r1, 233},
1582 {"nistb283", NID_sect283r1, 283},
1583 {"nistb409", NID_sect409r1, 409},
1584 {"nistb571", NID_sect571r1, 571},
1586 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1587 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1588 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1589 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1590 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1591 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1592 /* Other and ECDH only ones */
1593 {"X25519", NID_X25519, 253},
1594 {"X448", NID_X448, 448}
1596 static const struct {
1601 } test_ed_curves[] = {
1603 {"Ed25519", NID_ED25519, 253, 64},
1604 {"Ed448", NID_ED448, 456, 114}
1606 int ecdsa_doit[ECDSA_NUM] = { 0 };
1607 int ecdh_doit[EC_NUM] = { 0 };
1608 int eddsa_doit[EdDSA_NUM] = { 0 };
1609 OPENSSL_assert(OSSL_NELEM(test_curves) >= EC_NUM);
1610 OPENSSL_assert(OSSL_NELEM(test_ed_curves) >= EdDSA_NUM);
1611 #endif /* ndef OPENSSL_NO_EC */
1613 prog = opt_init(argc, argv, speed_options);
1614 while ((o = opt_next()) != OPT_EOF) {
1619 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1622 opt_help(speed_options);
1630 evp_cipher = EVP_get_cipherbyname(opt_arg());
1631 if (evp_cipher == NULL)
1632 evp_md = EVP_get_digestbyname(opt_arg());
1633 if (evp_cipher == NULL && evp_md == NULL) {
1635 "%s: %s is an unknown cipher or digest\n",
1642 evp_hmac_md = EVP_get_digestbyname(opt_arg());
1643 if (evp_hmac_md == NULL) {
1644 BIO_printf(bio_err, "%s: %s is an unknown digest\n",
1648 doit[D_EVP_HMAC] = 1;
1651 #ifndef OPENSSL_NO_CMAC
1652 evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
1653 if (evp_cmac_cipher == NULL) {
1654 BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
1658 doit[D_EVP_CMAC] = 1;
1666 * In a forked execution, an engine might need to be
1667 * initialised by each child process, not by the parent.
1668 * So store the name here and run setup_engine() later on.
1670 engine_id = opt_arg();
1674 multi = atoi(opt_arg());
1678 #ifndef OPENSSL_NO_ASYNC
1679 async_jobs = atoi(opt_arg());
1680 if (!ASYNC_is_capable()) {
1682 "%s: async_jobs specified but async not supported\n",
1686 if (async_jobs > 99999) {
1687 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1693 if (!opt_int(opt_arg(), &misalign))
1695 if (misalign > MISALIGN) {
1697 "%s: Maximum offset is %d\n", prog, MISALIGN);
1706 #ifdef OPENSSL_NO_MULTIBLOCK
1708 "%s: -mb specified but multi-block support is disabled\n",
1718 if (!opt_int(opt_arg(), &primes))
1722 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1723 = seconds.ecdh = seconds.eddsa = atoi(opt_arg());
1726 lengths_single = atoi(opt_arg());
1727 lengths = &lengths_single;
1735 argc = opt_num_rest();
1738 /* Remaining arguments are algorithms. */
1739 for (; *argv; argv++) {
1740 if (found(*argv, doit_choices, &i)) {
1744 #ifndef OPENSSL_NO_DES
1745 if (strcmp(*argv, "des") == 0) {
1746 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1750 if (strcmp(*argv, "sha") == 0) {
1751 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1754 #ifndef OPENSSL_NO_RSA
1755 if (strcmp(*argv, "openssl") == 0)
1757 if (strcmp(*argv, "rsa") == 0) {
1758 for (loop = 0; loop < OSSL_NELEM(rsa_doit); loop++)
1762 if (found(*argv, rsa_choices, &i)) {
1767 #ifndef OPENSSL_NO_DSA
1768 if (strcmp(*argv, "dsa") == 0) {
1769 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1770 dsa_doit[R_DSA_2048] = 1;
1773 if (found(*argv, dsa_choices, &i)) {
1778 if (strcmp(*argv, "aes") == 0) {
1779 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1782 #ifndef OPENSSL_NO_CAMELLIA
1783 if (strcmp(*argv, "camellia") == 0) {
1784 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1788 #ifndef OPENSSL_NO_EC
1789 if (strcmp(*argv, "ecdsa") == 0) {
1790 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1791 ecdsa_doit[loop] = 1;
1794 if (found(*argv, ecdsa_choices, &i)) {
1798 if (strcmp(*argv, "ecdh") == 0) {
1799 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1800 ecdh_doit[loop] = 1;
1803 if (found(*argv, ecdh_choices, &i)) {
1807 if (strcmp(*argv, "eddsa") == 0) {
1808 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1809 eddsa_doit[loop] = 1;
1812 if (found(*argv, eddsa_choices, &i)) {
1817 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1823 if (evp_cipher == NULL) {
1824 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1826 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1827 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1828 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1829 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1834 if (evp_cipher == NULL) {
1835 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1836 " capable cipher\n");
1838 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1839 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1840 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1841 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1843 } else if (async_jobs > 0) {
1844 BIO_printf(bio_err, "Async mode is not supported with -mb");
1849 /* Initialize the job pool if async mode is enabled */
1850 if (async_jobs > 0) {
1851 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1853 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1858 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1860 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1861 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1863 for (i = 0; i < loopargs_len; i++) {
1864 if (async_jobs > 0) {
1865 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1866 if (loopargs[i].wait_ctx == NULL) {
1867 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1872 buflen = lengths[size_num - 1];
1873 if (buflen < 36) /* size of random vector in RSA bencmark */
1875 buflen += MAX_MISALIGNMENT + 1;
1876 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1877 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1878 memset(loopargs[i].buf_malloc, 0, buflen);
1879 memset(loopargs[i].buf2_malloc, 0, buflen);
1881 /* Align the start of buffers on a 64 byte boundary */
1882 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1883 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1884 #ifndef OPENSSL_NO_EC
1885 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1886 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1891 if (multi && do_multi(multi, size_num))
1895 /* Initialize the engine after the fork */
1896 e = setup_engine(engine_id, 0);
1898 /* No parameters; turn on everything. */
1899 if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
1900 for (i = 0; i < ALGOR_NUM; i++)
1901 if (i != D_EVP && i != D_EVP_HMAC && i != D_EVP_CMAC)
1903 #ifndef OPENSSL_NO_RSA
1904 for (i = 0; i < RSA_NUM; i++)
1907 #ifndef OPENSSL_NO_DSA
1908 for (i = 0; i < DSA_NUM; i++)
1911 #ifndef OPENSSL_NO_EC
1912 for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
1913 ecdsa_doit[loop] = 1;
1914 for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
1915 ecdh_doit[loop] = 1;
1916 for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
1917 eddsa_doit[loop] = 1;
1920 for (i = 0; i < ALGOR_NUM; i++)
1924 if (usertime == 0 && !mr)
1926 "You have chosen to measure elapsed time "
1927 "instead of user CPU time.\n");
1929 #ifndef OPENSSL_NO_RSA
1930 for (i = 0; i < loopargs_len; i++) {
1931 if (primes > RSA_DEFAULT_PRIME_NUM) {
1932 /* for multi-prime RSA, skip this */
1935 for (k = 0; k < RSA_NUM; k++) {
1936 const unsigned char *p;
1939 loopargs[i].rsa_key[k] =
1940 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1941 if (loopargs[i].rsa_key[k] == NULL) {
1943 "internal error loading RSA key number %d\n", k);
1949 #ifndef OPENSSL_NO_DSA
1950 for (i = 0; i < loopargs_len; i++) {
1951 loopargs[i].dsa_key[0] = get_dsa(512);
1952 loopargs[i].dsa_key[1] = get_dsa(1024);
1953 loopargs[i].dsa_key[2] = get_dsa(2048);
1956 #ifndef OPENSSL_NO_DES
1957 DES_set_key_unchecked(&key, &sch);
1958 DES_set_key_unchecked(&key2, &sch2);
1959 DES_set_key_unchecked(&key3, &sch3);
1961 AES_set_encrypt_key(key16, 128, &aes_ks1);
1962 AES_set_encrypt_key(key24, 192, &aes_ks2);
1963 AES_set_encrypt_key(key32, 256, &aes_ks3);
1964 #ifndef OPENSSL_NO_CAMELLIA
1965 Camellia_set_key(key16, 128, &camellia_ks1);
1966 Camellia_set_key(ckey24, 192, &camellia_ks2);
1967 Camellia_set_key(ckey32, 256, &camellia_ks3);
1969 #ifndef OPENSSL_NO_IDEA
1970 IDEA_set_encrypt_key(key16, &idea_ks);
1972 #ifndef OPENSSL_NO_SEED
1973 SEED_set_key(key16, &seed_ks);
1975 #ifndef OPENSSL_NO_RC4
1976 RC4_set_key(&rc4_ks, 16, key16);
1978 #ifndef OPENSSL_NO_RC2
1979 RC2_set_key(&rc2_ks, 16, key16, 128);
1981 #ifndef OPENSSL_NO_RC5
1982 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1984 #ifndef OPENSSL_NO_BF
1985 BF_set_key(&bf_ks, 16, key16);
1987 #ifndef OPENSSL_NO_CAST
1988 CAST_set_key(&cast_ks, 16, key16);
1991 # ifndef OPENSSL_NO_DES
1992 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1998 for (it = count; it; it--)
1999 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
2000 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
2004 c[D_MD2][0] = count / 10;
2005 c[D_MDC2][0] = count / 10;
2006 c[D_MD4][0] = count;
2007 c[D_MD5][0] = count;
2008 c[D_HMAC][0] = count;
2009 c[D_SHA1][0] = count;
2010 c[D_RMD160][0] = count;
2011 c[D_RC4][0] = count * 5;
2012 c[D_CBC_DES][0] = count;
2013 c[D_EDE3_DES][0] = count / 3;
2014 c[D_CBC_IDEA][0] = count;
2015 c[D_CBC_SEED][0] = count;
2016 c[D_CBC_RC2][0] = count;
2017 c[D_CBC_RC5][0] = count;
2018 c[D_CBC_BF][0] = count;
2019 c[D_CBC_CAST][0] = count;
2020 c[D_CBC_128_AES][0] = count;
2021 c[D_CBC_192_AES][0] = count;
2022 c[D_CBC_256_AES][0] = count;
2023 c[D_CBC_128_CML][0] = count;
2024 c[D_CBC_192_CML][0] = count;
2025 c[D_CBC_256_CML][0] = count;
2026 c[D_SHA256][0] = count;
2027 c[D_SHA512][0] = count;
2028 c[D_WHIRLPOOL][0] = count;
2029 c[D_IGE_128_AES][0] = count;
2030 c[D_IGE_192_AES][0] = count;
2031 c[D_IGE_256_AES][0] = count;
2032 c[D_GHASH][0] = count;
2033 c[D_RAND][0] = count;
2035 for (i = 1; i < size_num; i++) {
2038 l0 = (long)lengths[0];
2039 l1 = (long)lengths[i];
2041 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
2042 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
2043 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
2044 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
2045 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
2046 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
2047 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
2048 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
2049 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
2050 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
2051 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
2052 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
2054 l0 = (long)lengths[i - 1];
2056 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
2057 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
2058 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
2059 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
2060 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
2061 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
2062 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
2063 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
2064 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
2065 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
2066 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
2067 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
2068 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
2069 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
2070 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
2071 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
2072 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
2073 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
2076 # ifndef OPENSSL_NO_RSA
2077 rsa_c[R_RSA_512][0] = count / 2000;
2078 rsa_c[R_RSA_512][1] = count / 400;
2079 for (i = 1; i < RSA_NUM; i++) {
2080 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
2081 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
2082 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
2085 if (rsa_c[i][0] == 0) {
2086 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2093 # ifndef OPENSSL_NO_DSA
2094 dsa_c[R_DSA_512][0] = count / 1000;
2095 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2096 for (i = 1; i < DSA_NUM; i++) {
2097 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2098 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2099 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2102 if (dsa_c[i][0] == 0) {
2103 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2110 # ifndef OPENSSL_NO_EC
2111 ecdsa_c[R_EC_P160][0] = count / 1000;
2112 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2113 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2114 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2115 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2116 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2119 if (ecdsa_c[i][0] == 0) {
2125 # ifndef OPENSSL_NO_EC2M
2126 ecdsa_c[R_EC_K163][0] = count / 1000;
2127 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2128 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2129 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2130 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2131 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2134 if (ecdsa_c[i][0] == 0) {
2140 ecdsa_c[R_EC_B163][0] = count / 1000;
2141 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2142 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2143 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2144 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2145 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2148 if (ecdsa_c[i][0] == 0) {
2156 ecdh_c[R_EC_P160][0] = count / 1000;
2157 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2158 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2159 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2162 if (ecdh_c[i][0] == 0) {
2167 # ifndef OPENSSL_NO_EC2M
2168 ecdh_c[R_EC_K163][0] = count / 1000;
2169 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2170 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2171 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2174 if (ecdh_c[i][0] == 0) {
2179 ecdh_c[R_EC_B163][0] = count / 1000;
2180 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2181 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2182 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2185 if (ecdh_c[i][0] == 0) {
2191 /* repeated code good to factorize */
2192 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2193 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2194 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2195 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2198 if (ecdh_c[i][0] == 0) {
2203 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2204 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2205 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2206 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2209 if (ecdh_c[i][0] == 0) {
2214 /* default iteration count for the last two EC Curves */
2215 ecdh_c[R_EC_X25519][0] = count / 1800;
2216 ecdh_c[R_EC_X448][0] = count / 7200;
2218 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2219 eddsa_c[R_EC_Ed448][0] = count / 7200;
2223 /* not worth fixing */
2224 # error "You cannot disable DES on systems without SIGALRM."
2225 # endif /* OPENSSL_NO_DES */
2227 signal(SIGALRM, alarmed);
2228 #endif /* SIGALRM */
2230 #ifndef OPENSSL_NO_MD2
2232 for (testnum = 0; testnum < size_num; testnum++) {
2233 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2236 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2238 print_result(D_MD2, testnum, count, d);
2242 #ifndef OPENSSL_NO_MDC2
2244 for (testnum = 0; testnum < size_num; testnum++) {
2245 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2248 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2250 print_result(D_MDC2, testnum, count, d);
2255 #ifndef OPENSSL_NO_MD4
2257 for (testnum = 0; testnum < size_num; testnum++) {
2258 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2261 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2263 print_result(D_MD4, testnum, count, d);
2268 #ifndef OPENSSL_NO_MD5
2270 for (testnum = 0; testnum < size_num; testnum++) {
2271 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2274 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2276 print_result(D_MD5, testnum, count, d);
2281 static const char hmac_key[] = "This is a key...";
2282 int len = strlen(hmac_key);
2284 for (i = 0; i < loopargs_len; i++) {
2285 loopargs[i].hctx = HMAC_CTX_new();
2286 if (loopargs[i].hctx == NULL) {
2287 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2291 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2293 for (testnum = 0; testnum < size_num; testnum++) {
2294 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2297 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2299 print_result(D_HMAC, testnum, count, d);
2301 for (i = 0; i < loopargs_len; i++) {
2302 HMAC_CTX_free(loopargs[i].hctx);
2307 for (testnum = 0; testnum < size_num; testnum++) {
2308 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2311 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2313 print_result(D_SHA1, testnum, count, d);
2316 if (doit[D_SHA256]) {
2317 for (testnum = 0; testnum < size_num; testnum++) {
2318 print_message(names[D_SHA256], c[D_SHA256][testnum],
2319 lengths[testnum], seconds.sym);
2321 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2323 print_result(D_SHA256, testnum, count, d);
2326 if (doit[D_SHA512]) {
2327 for (testnum = 0; testnum < size_num; testnum++) {
2328 print_message(names[D_SHA512], c[D_SHA512][testnum],
2329 lengths[testnum], seconds.sym);
2331 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2333 print_result(D_SHA512, testnum, count, d);
2336 #ifndef OPENSSL_NO_WHIRLPOOL
2337 if (doit[D_WHIRLPOOL]) {
2338 for (testnum = 0; testnum < size_num; testnum++) {
2339 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2340 lengths[testnum], seconds.sym);
2342 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2344 print_result(D_WHIRLPOOL, testnum, count, d);
2349 #ifndef OPENSSL_NO_RMD160
2350 if (doit[D_RMD160]) {
2351 for (testnum = 0; testnum < size_num; testnum++) {
2352 print_message(names[D_RMD160], c[D_RMD160][testnum],
2353 lengths[testnum], seconds.sym);
2355 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2357 print_result(D_RMD160, testnum, count, d);
2361 #ifndef OPENSSL_NO_RC4
2363 for (testnum = 0; testnum < size_num; testnum++) {
2364 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2367 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2369 print_result(D_RC4, testnum, count, d);
2373 #ifndef OPENSSL_NO_DES
2374 if (doit[D_CBC_DES]) {
2375 for (testnum = 0; testnum < size_num; testnum++) {
2376 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2377 lengths[testnum], seconds.sym);
2379 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2381 print_result(D_CBC_DES, testnum, count, d);
2385 if (doit[D_EDE3_DES]) {
2386 for (testnum = 0; testnum < size_num; testnum++) {
2387 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2388 lengths[testnum], seconds.sym);
2391 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2393 print_result(D_EDE3_DES, testnum, count, d);
2398 if (doit[D_CBC_128_AES]) {
2399 for (testnum = 0; testnum < size_num; testnum++) {
2400 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2401 lengths[testnum], seconds.sym);
2404 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2406 print_result(D_CBC_128_AES, testnum, count, d);
2409 if (doit[D_CBC_192_AES]) {
2410 for (testnum = 0; testnum < size_num; testnum++) {
2411 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2412 lengths[testnum], seconds.sym);
2415 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2417 print_result(D_CBC_192_AES, testnum, count, d);
2420 if (doit[D_CBC_256_AES]) {
2421 for (testnum = 0; testnum < size_num; testnum++) {
2422 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2423 lengths[testnum], seconds.sym);
2426 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2428 print_result(D_CBC_256_AES, testnum, count, d);
2432 if (doit[D_IGE_128_AES]) {
2433 for (testnum = 0; testnum < size_num; testnum++) {
2434 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2435 lengths[testnum], seconds.sym);
2438 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2440 print_result(D_IGE_128_AES, testnum, count, d);
2443 if (doit[D_IGE_192_AES]) {
2444 for (testnum = 0; testnum < size_num; testnum++) {
2445 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2446 lengths[testnum], seconds.sym);
2449 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2451 print_result(D_IGE_192_AES, testnum, count, d);
2454 if (doit[D_IGE_256_AES]) {
2455 for (testnum = 0; testnum < size_num; testnum++) {
2456 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2457 lengths[testnum], seconds.sym);
2460 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2462 print_result(D_IGE_256_AES, testnum, count, d);
2465 if (doit[D_GHASH]) {
2466 for (i = 0; i < loopargs_len; i++) {
2467 loopargs[i].gcm_ctx =
2468 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2469 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2470 (unsigned char *)"0123456789ab", 12);
2473 for (testnum = 0; testnum < size_num; testnum++) {
2474 print_message(names[D_GHASH], c[D_GHASH][testnum],
2475 lengths[testnum], seconds.sym);
2477 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2479 print_result(D_GHASH, testnum, count, d);
2481 for (i = 0; i < loopargs_len; i++)
2482 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2484 #ifndef OPENSSL_NO_CAMELLIA
2485 if (doit[D_CBC_128_CML]) {
2486 if (async_jobs > 0) {
2487 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2488 names[D_CBC_128_CML]);
2489 doit[D_CBC_128_CML] = 0;
2491 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2492 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2493 lengths[testnum], seconds.sym);
2495 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2496 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2497 (size_t)lengths[testnum], &camellia_ks1,
2498 iv, CAMELLIA_ENCRYPT);
2500 print_result(D_CBC_128_CML, testnum, count, d);
2503 if (doit[D_CBC_192_CML]) {
2504 if (async_jobs > 0) {
2505 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2506 names[D_CBC_192_CML]);
2507 doit[D_CBC_192_CML] = 0;
2509 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2510 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2511 lengths[testnum], seconds.sym);
2512 if (async_jobs > 0) {
2513 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2517 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2518 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2519 (size_t)lengths[testnum], &camellia_ks2,
2520 iv, CAMELLIA_ENCRYPT);
2522 print_result(D_CBC_192_CML, testnum, count, d);
2525 if (doit[D_CBC_256_CML]) {
2526 if (async_jobs > 0) {
2527 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2528 names[D_CBC_256_CML]);
2529 doit[D_CBC_256_CML] = 0;
2531 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2532 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2533 lengths[testnum], seconds.sym);
2535 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2536 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2537 (size_t)lengths[testnum], &camellia_ks3,
2538 iv, CAMELLIA_ENCRYPT);
2540 print_result(D_CBC_256_CML, testnum, count, d);
2544 #ifndef OPENSSL_NO_IDEA
2545 if (doit[D_CBC_IDEA]) {
2546 if (async_jobs > 0) {
2547 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2549 doit[D_CBC_IDEA] = 0;
2551 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2552 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2553 lengths[testnum], seconds.sym);
2555 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2556 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2557 (size_t)lengths[testnum], &idea_ks,
2560 print_result(D_CBC_IDEA, testnum, count, d);
2564 #ifndef OPENSSL_NO_SEED
2565 if (doit[D_CBC_SEED]) {
2566 if (async_jobs > 0) {
2567 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2569 doit[D_CBC_SEED] = 0;
2571 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2572 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2573 lengths[testnum], seconds.sym);
2575 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2576 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2577 (size_t)lengths[testnum], &seed_ks, iv, 1);
2579 print_result(D_CBC_SEED, testnum, count, d);
2583 #ifndef OPENSSL_NO_RC2
2584 if (doit[D_CBC_RC2]) {
2585 if (async_jobs > 0) {
2586 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2588 doit[D_CBC_RC2] = 0;
2590 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2591 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2592 lengths[testnum], seconds.sym);
2593 if (async_jobs > 0) {
2594 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2598 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2599 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2600 (size_t)lengths[testnum], &rc2_ks,
2603 print_result(D_CBC_RC2, testnum, count, d);
2607 #ifndef OPENSSL_NO_RC5
2608 if (doit[D_CBC_RC5]) {
2609 if (async_jobs > 0) {
2610 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2612 doit[D_CBC_RC5] = 0;
2614 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2615 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2616 lengths[testnum], seconds.sym);
2617 if (async_jobs > 0) {
2618 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2622 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2623 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2624 (size_t)lengths[testnum], &rc5_ks,
2627 print_result(D_CBC_RC5, testnum, count, d);
2631 #ifndef OPENSSL_NO_BF
2632 if (doit[D_CBC_BF]) {
2633 if (async_jobs > 0) {
2634 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2638 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2639 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2640 lengths[testnum], seconds.sym);
2642 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2643 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2644 (size_t)lengths[testnum], &bf_ks,
2647 print_result(D_CBC_BF, testnum, count, d);
2651 #ifndef OPENSSL_NO_CAST
2652 if (doit[D_CBC_CAST]) {
2653 if (async_jobs > 0) {
2654 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2656 doit[D_CBC_CAST] = 0;
2658 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2659 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2660 lengths[testnum], seconds.sym);
2662 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2663 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2664 (size_t)lengths[testnum], &cast_ks,
2667 print_result(D_CBC_CAST, testnum, count, d);
2672 for (testnum = 0; testnum < size_num; testnum++) {
2673 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2676 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2678 print_result(D_RAND, testnum, count, d);
2683 if (evp_cipher != NULL) {
2684 int (*loopfunc)(void *args) = EVP_Update_loop;
2686 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2687 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2688 multiblock_speed(evp_cipher, lengths_single, &seconds);
2693 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2695 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2696 loopfunc = EVP_Update_loop_ccm;
2697 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2698 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2699 loopfunc = EVP_Update_loop_aead;
2700 if (lengths == lengths_list) {
2701 lengths = aead_lengths_list;
2702 size_num = OSSL_NELEM(aead_lengths_list);
2706 for (testnum = 0; testnum < size_num; testnum++) {
2707 print_message(names[D_EVP], save_count, lengths[testnum],
2710 for (k = 0; k < loopargs_len; k++) {
2711 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2712 EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
2713 iv, decrypt ? 0 : 1);
2715 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2717 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2718 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2719 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2720 EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2721 loopargs[k].key, NULL, -1);
2722 OPENSSL_clear_free(loopargs[k].key, keylen);
2724 /* SIV mode only allows for a single Update operation */
2725 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
2726 EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
2730 count = run_benchmark(async_jobs, loopfunc, loopargs);
2732 for (k = 0; k < loopargs_len; k++) {
2733 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2735 print_result(D_EVP, testnum, count, d);
2737 } else if (evp_md != NULL) {
2738 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2740 for (testnum = 0; testnum < size_num; testnum++) {
2741 print_message(names[D_EVP], save_count, lengths[testnum],
2744 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2746 print_result(D_EVP, testnum, count, d);
2751 if (doit[D_EVP_HMAC]) {
2752 if (evp_hmac_md != NULL) {
2753 const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
2754 evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
2756 sprintf(evp_hmac_name, "HMAC(%s)", md_name);
2757 names[D_EVP_HMAC] = evp_hmac_name;
2759 for (testnum = 0; testnum < size_num; testnum++) {
2760 print_message(names[D_EVP_HMAC], save_count, lengths[testnum],
2763 count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
2765 print_result(D_EVP_HMAC, testnum, count, d);
2770 #ifndef OPENSSL_NO_CMAC
2771 if (doit[D_EVP_CMAC]) {
2772 if (evp_cmac_cipher != NULL) {
2773 const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
2774 evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
2776 sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
2777 names[D_EVP_CMAC] = evp_cmac_name;
2779 for (i = 0; i < loopargs_len; i++) {
2780 loopargs[i].cmac_ctx = CMAC_CTX_new();
2781 if (loopargs[i].cmac_ctx == NULL) {
2782 BIO_printf(bio_err, "CMAC malloc failure, exiting...");
2786 for (testnum = 0; testnum < size_num; testnum++) {
2787 print_message(names[D_EVP_CMAC], save_count, lengths[testnum],
2790 count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
2792 print_result(D_EVP_CMAC, testnum, count, d);
2794 for (i = 0; i < loopargs_len; i++)
2795 CMAC_CTX_free(loopargs[i].cmac_ctx);
2800 for (i = 0; i < loopargs_len; i++)
2801 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2804 #ifndef OPENSSL_NO_RSA
2805 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2807 if (!rsa_doit[testnum])
2809 for (i = 0; i < loopargs_len; i++) {
2811 /* we haven't set keys yet, generate multi-prime RSA keys */
2812 BIGNUM *bn = BN_new();
2816 if (!BN_set_word(bn, RSA_F4)) {
2821 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2822 rsa_choices[testnum].name);
2824 loopargs[i].rsa_key[testnum] = RSA_new();
2825 if (loopargs[i].rsa_key[testnum] == NULL) {
2830 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2832 primes, bn, NULL)) {
2838 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2839 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2845 "RSA sign failure. No RSA sign will be done.\n");
2846 ERR_print_errors(bio_err);
2849 pkey_print_message("private", "rsa",
2850 rsa_c[testnum][0], rsa_bits[testnum],
2852 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2854 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2857 mr ? "+R1:%ld:%d:%.2f\n"
2858 : "%ld %u bits private RSA's in %.2fs\n",
2859 count, rsa_bits[testnum], d);
2860 rsa_results[testnum][0] = (double)count / d;
2864 for (i = 0; i < loopargs_len; i++) {
2865 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2866 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2872 "RSA verify failure. No RSA verify will be done.\n");
2873 ERR_print_errors(bio_err);
2874 rsa_doit[testnum] = 0;
2876 pkey_print_message("public", "rsa",
2877 rsa_c[testnum][1], rsa_bits[testnum],
2880 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2883 mr ? "+R2:%ld:%d:%.2f\n"
2884 : "%ld %u bits public RSA's in %.2fs\n",
2885 count, rsa_bits[testnum], d);
2886 rsa_results[testnum][1] = (double)count / d;
2889 if (rsa_count <= 1) {
2890 /* if longer than 10s, don't do any more */
2891 for (testnum++; testnum < RSA_NUM; testnum++)
2892 rsa_doit[testnum] = 0;
2895 #endif /* OPENSSL_NO_RSA */
2897 for (i = 0; i < loopargs_len; i++)
2898 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2901 #ifndef OPENSSL_NO_DSA
2902 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2904 if (!dsa_doit[testnum])
2907 /* DSA_generate_key(dsa_key[testnum]); */
2908 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2909 for (i = 0; i < loopargs_len; i++) {
2910 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2911 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2917 "DSA sign failure. No DSA sign will be done.\n");
2918 ERR_print_errors(bio_err);
2921 pkey_print_message("sign", "dsa",
2922 dsa_c[testnum][0], dsa_bits[testnum],
2925 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2928 mr ? "+R3:%ld:%u:%.2f\n"
2929 : "%ld %u bits DSA signs in %.2fs\n",
2930 count, dsa_bits[testnum], d);
2931 dsa_results[testnum][0] = (double)count / d;
2935 for (i = 0; i < loopargs_len; i++) {
2936 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2937 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2943 "DSA verify failure. No DSA verify will be done.\n");
2944 ERR_print_errors(bio_err);
2945 dsa_doit[testnum] = 0;
2947 pkey_print_message("verify", "dsa",
2948 dsa_c[testnum][1], dsa_bits[testnum],
2951 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2954 mr ? "+R4:%ld:%u:%.2f\n"
2955 : "%ld %u bits DSA verify in %.2fs\n",
2956 count, dsa_bits[testnum], d);
2957 dsa_results[testnum][1] = (double)count / d;
2960 if (rsa_count <= 1) {
2961 /* if longer than 10s, don't do any more */
2962 for (testnum++; testnum < DSA_NUM; testnum++)
2963 dsa_doit[testnum] = 0;
2966 #endif /* OPENSSL_NO_DSA */
2968 #ifndef OPENSSL_NO_EC
2969 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
2972 if (!ecdsa_doit[testnum])
2973 continue; /* Ignore Curve */
2974 for (i = 0; i < loopargs_len; i++) {
2975 loopargs[i].ecdsa[testnum] =
2976 EC_KEY_new_by_curve_name(test_curves[testnum].nid);
2977 if (loopargs[i].ecdsa[testnum] == NULL) {
2983 BIO_printf(bio_err, "ECDSA failure.\n");
2984 ERR_print_errors(bio_err);
2987 for (i = 0; i < loopargs_len; i++) {
2988 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2989 /* Perform ECDSA signature test */
2990 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2991 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2992 &loopargs[i].siglen,
2993 loopargs[i].ecdsa[testnum]);
2999 "ECDSA sign failure. No ECDSA sign will be done.\n");
3000 ERR_print_errors(bio_err);
3003 pkey_print_message("sign", "ecdsa",
3004 ecdsa_c[testnum][0],
3005 test_curves[testnum].bits, seconds.ecdsa);
3007 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
3011 mr ? "+R5:%ld:%u:%.2f\n" :
3012 "%ld %u bits ECDSA signs in %.2fs \n",
3013 count, test_curves[testnum].bits, d);
3014 ecdsa_results[testnum][0] = (double)count / d;
3018 /* Perform ECDSA verification test */
3019 for (i = 0; i < loopargs_len; i++) {
3020 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3022 loopargs[i].ecdsa[testnum]);
3028 "ECDSA verify failure. No ECDSA verify will be done.\n");
3029 ERR_print_errors(bio_err);
3030 ecdsa_doit[testnum] = 0;
3032 pkey_print_message("verify", "ecdsa",
3033 ecdsa_c[testnum][1],
3034 test_curves[testnum].bits, seconds.ecdsa);
3036 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
3039 mr ? "+R6:%ld:%u:%.2f\n"
3040 : "%ld %u bits ECDSA verify in %.2fs\n",
3041 count, test_curves[testnum].bits, d);
3042 ecdsa_results[testnum][1] = (double)count / d;
3045 if (rsa_count <= 1) {
3046 /* if longer than 10s, don't do any more */
3047 for (testnum++; testnum < ECDSA_NUM; testnum++)
3048 ecdsa_doit[testnum] = 0;
3053 for (testnum = 0; testnum < EC_NUM; testnum++) {
3054 int ecdh_checks = 1;
3056 if (!ecdh_doit[testnum])
3059 for (i = 0; i < loopargs_len; i++) {
3060 EVP_PKEY_CTX *kctx = NULL;
3061 EVP_PKEY_CTX *test_ctx = NULL;
3062 EVP_PKEY_CTX *ctx = NULL;
3063 EVP_PKEY *key_A = NULL;
3064 EVP_PKEY *key_B = NULL;
3068 /* Ensure that the error queue is empty */
3069 if (ERR_peek_error()) {
3071 "WARNING: the error queue contains previous unhandled errors.\n");
3072 ERR_print_errors(bio_err);
3075 /* Let's try to create a ctx directly from the NID: this works for
3076 * curves like Curve25519 that are not implemented through the low
3077 * level EC interface.
3078 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
3079 * then we set the curve by NID before deriving the actual keygen
3080 * ctx for that specific curve. */
3081 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum].nid, NULL); /* keygen ctx from NID */
3083 EVP_PKEY_CTX *pctx = NULL;
3084 EVP_PKEY *params = NULL;
3086 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
3087 * "int_ctx_new:unsupported algorithm" error was added to the
3089 * We remove it from the error queue as we are handling it. */
3090 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
3091 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
3092 /* check that the error origin matches */
3093 ERR_GET_LIB(error) == ERR_LIB_EVP &&
3094 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
3095 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
3096 ERR_get_error(); /* pop error from queue */
3097 if (ERR_peek_error()) {
3099 "Unhandled error in the error queue during ECDH init.\n");
3100 ERR_print_errors(bio_err);
3105 if ( /* Create the context for parameter generation */
3106 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
3107 /* Initialise the parameter generation */
3108 !EVP_PKEY_paramgen_init(pctx) ||
3109 /* Set the curve by NID */
3110 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3113 /* Create the parameter object params */
3114 !EVP_PKEY_paramgen(pctx, ¶ms)) {
3116 BIO_printf(bio_err, "ECDH EC params init failure.\n");
3117 ERR_print_errors(bio_err);
3121 /* Create the context for the key generation */
3122 kctx = EVP_PKEY_CTX_new(params, NULL);
3124 EVP_PKEY_free(params);
3126 EVP_PKEY_CTX_free(pctx);
3129 if (kctx == NULL || /* keygen ctx is not null */
3130 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
3132 BIO_printf(bio_err, "ECDH keygen failure.\n");
3133 ERR_print_errors(bio_err);
3138 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
3139 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
3140 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
3141 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
3142 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
3143 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
3144 outlen == 0 || /* ensure outlen is a valid size */
3145 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
3147 BIO_printf(bio_err, "ECDH key generation failure.\n");
3148 ERR_print_errors(bio_err);
3153 /* Here we perform a test run, comparing the output of a*B and b*A;
3154 * we try this here and assume that further EVP_PKEY_derive calls
3155 * never fail, so we can skip checks in the actually benchmarked
3156 * code, for maximum performance. */
3157 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3158 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3159 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3160 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3161 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3162 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3163 test_outlen != outlen /* compare output length */ ) {
3165 BIO_printf(bio_err, "ECDH computation failure.\n");
3166 ERR_print_errors(bio_err);
3171 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3172 if (CRYPTO_memcmp(loopargs[i].secret_a,
3173 loopargs[i].secret_b, outlen)) {
3175 BIO_printf(bio_err, "ECDH computations don't match.\n");
3176 ERR_print_errors(bio_err);
3181 loopargs[i].ecdh_ctx[testnum] = ctx;
3182 loopargs[i].outlen[testnum] = outlen;
3184 EVP_PKEY_free(key_A);
3185 EVP_PKEY_free(key_B);
3186 EVP_PKEY_CTX_free(kctx);
3188 EVP_PKEY_CTX_free(test_ctx);
3191 if (ecdh_checks != 0) {
3192 pkey_print_message("", "ecdh",
3194 test_curves[testnum].bits, seconds.ecdh);
3197 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3200 mr ? "+R7:%ld:%d:%.2f\n" :
3201 "%ld %u-bits ECDH ops in %.2fs\n", count,
3202 test_curves[testnum].bits, d);
3203 ecdh_results[testnum][0] = (double)count / d;
3207 if (rsa_count <= 1) {
3208 /* if longer than 10s, don't do any more */
3209 for (testnum++; testnum < OSSL_NELEM(ecdh_doit); testnum++)
3210 ecdh_doit[testnum] = 0;
3214 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3216 EVP_PKEY *ed_pkey = NULL;
3217 EVP_PKEY_CTX *ed_pctx = NULL;
3219 if (!eddsa_doit[testnum])
3220 continue; /* Ignore Curve */
3221 for (i = 0; i < loopargs_len; i++) {
3222 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3223 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3228 if ((ed_pctx = EVP_PKEY_CTX_new_id(test_ed_curves[testnum].nid, NULL))
3230 || !EVP_PKEY_keygen_init(ed_pctx)
3231 || !EVP_PKEY_keygen(ed_pctx, &ed_pkey)) {
3233 EVP_PKEY_CTX_free(ed_pctx);
3236 EVP_PKEY_CTX_free(ed_pctx);
3238 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3241 EVP_PKEY_free(ed_pkey);
3244 EVP_PKEY_free(ed_pkey);
3247 BIO_printf(bio_err, "EdDSA failure.\n");
3248 ERR_print_errors(bio_err);
3251 for (i = 0; i < loopargs_len; i++) {
3252 /* Perform EdDSA signature test */
3253 loopargs[i].sigsize = test_ed_curves[testnum].sigsize;
3254 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3255 loopargs[i].buf2, &loopargs[i].sigsize,
3256 loopargs[i].buf, 20);
3262 "EdDSA sign failure. No EdDSA sign will be done.\n");
3263 ERR_print_errors(bio_err);
3266 pkey_print_message("sign", test_ed_curves[testnum].name,
3267 eddsa_c[testnum][0],
3268 test_ed_curves[testnum].bits, seconds.eddsa);
3270 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3274 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3275 "%ld %u bits %s signs in %.2fs \n",
3276 count, test_ed_curves[testnum].bits,
3277 test_ed_curves[testnum].name, d);
3278 eddsa_results[testnum][0] = (double)count / d;
3282 /* Perform EdDSA verification test */
3283 for (i = 0; i < loopargs_len; i++) {
3284 st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
3285 loopargs[i].buf2, loopargs[i].sigsize,
3286 loopargs[i].buf, 20);
3292 "EdDSA verify failure. No EdDSA verify will be done.\n");
3293 ERR_print_errors(bio_err);
3294 eddsa_doit[testnum] = 0;
3296 pkey_print_message("verify", test_ed_curves[testnum].name,
3297 eddsa_c[testnum][1],
3298 test_ed_curves[testnum].bits, seconds.eddsa);
3300 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3303 mr ? "+R9:%ld:%u:%s:%.2f\n"
3304 : "%ld %u bits %s verify in %.2fs\n",
3305 count, test_ed_curves[testnum].bits,
3306 test_ed_curves[testnum].name, d);
3307 eddsa_results[testnum][1] = (double)count / d;
3310 if (rsa_count <= 1) {
3311 /* if longer than 10s, don't do any more */
3312 for (testnum++; testnum < EdDSA_NUM; testnum++)
3313 eddsa_doit[testnum] = 0;
3318 #endif /* OPENSSL_NO_EC */
3323 printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
3324 printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3326 printf("%s ", BN_options());
3327 #ifndef OPENSSL_NO_MD2
3328 printf("%s ", MD2_options());
3330 #ifndef OPENSSL_NO_RC4
3331 printf("%s ", RC4_options());
3333 #ifndef OPENSSL_NO_DES
3334 printf("%s ", DES_options());
3336 printf("%s ", AES_options());
3337 #ifndef OPENSSL_NO_IDEA
3338 printf("%s ", IDEA_options());
3340 #ifndef OPENSSL_NO_BF
3341 printf("%s ", BF_options());
3343 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3351 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3354 for (testnum = 0; testnum < size_num; testnum++)
3355 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3359 for (k = 0; k < ALGOR_NUM; k++) {
3363 printf("+F:%u:%s", k, names[k]);
3365 printf("%-13s", names[k]);
3366 for (testnum = 0; testnum < size_num; testnum++) {
3367 if (results[k][testnum] > 10000 && !mr)
3368 printf(" %11.2fk", results[k][testnum] / 1e3);
3370 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3374 #ifndef OPENSSL_NO_RSA
3376 for (k = 0; k < RSA_NUM; k++) {
3379 if (testnum && !mr) {
3380 printf("%18ssign verify sign/s verify/s\n", " ");
3384 printf("+F2:%u:%u:%f:%f\n",
3385 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
3387 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3388 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3389 rsa_results[k][0], rsa_results[k][1]);
3392 #ifndef OPENSSL_NO_DSA
3394 for (k = 0; k < DSA_NUM; k++) {
3397 if (testnum && !mr) {
3398 printf("%18ssign verify sign/s verify/s\n", " ");
3402 printf("+F3:%u:%u:%f:%f\n",
3403 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3405 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3406 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3407 dsa_results[k][0], dsa_results[k][1]);
3410 #ifndef OPENSSL_NO_EC
3412 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3415 if (testnum && !mr) {
3416 printf("%30ssign verify sign/s verify/s\n", " ");
3421 printf("+F4:%u:%u:%f:%f\n",
3422 k, test_curves[k].bits,
3423 ecdsa_results[k][0], ecdsa_results[k][1]);
3425 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3426 test_curves[k].bits, test_curves[k].name,
3427 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3428 ecdsa_results[k][0], ecdsa_results[k][1]);
3432 for (k = 0; k < EC_NUM; k++) {
3435 if (testnum && !mr) {
3436 printf("%30sop op/s\n", " ");
3440 printf("+F5:%u:%u:%f:%f\n",
3441 k, test_curves[k].bits,
3442 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3445 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3446 test_curves[k].bits, test_curves[k].name,
3447 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3451 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
3454 if (testnum && !mr) {
3455 printf("%30ssign verify sign/s verify/s\n", " ");
3460 printf("+F6:%u:%u:%s:%f:%f\n",
3461 k, test_ed_curves[k].bits, test_ed_curves[k].name,
3462 eddsa_results[k][0], eddsa_results[k][1]);
3464 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3465 test_ed_curves[k].bits, test_ed_curves[k].name,
3466 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
3467 eddsa_results[k][0], eddsa_results[k][1]);
3474 ERR_print_errors(bio_err);
3475 for (i = 0; i < loopargs_len; i++) {
3476 OPENSSL_free(loopargs[i].buf_malloc);
3477 OPENSSL_free(loopargs[i].buf2_malloc);
3479 #ifndef OPENSSL_NO_RSA
3480 for (k = 0; k < RSA_NUM; k++)
3481 RSA_free(loopargs[i].rsa_key[k]);
3483 #ifndef OPENSSL_NO_DSA
3484 for (k = 0; k < DSA_NUM; k++)
3485 DSA_free(loopargs[i].dsa_key[k]);
3487 #ifndef OPENSSL_NO_EC
3488 for (k = 0; k < ECDSA_NUM; k++)
3489 EC_KEY_free(loopargs[i].ecdsa[k]);
3490 for (k = 0; k < EC_NUM; k++)
3491 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3492 for (k = 0; k < EdDSA_NUM; k++)
3493 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
3494 OPENSSL_free(loopargs[i].secret_a);
3495 OPENSSL_free(loopargs[i].secret_b);
3498 OPENSSL_free(evp_hmac_name);
3499 #ifndef OPENSSL_NO_CMAC
3500 OPENSSL_free(evp_cmac_name);
3503 if (async_jobs > 0) {
3504 for (i = 0; i < loopargs_len; i++)
3505 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3509 ASYNC_cleanup_thread();
3511 OPENSSL_free(loopargs);
3516 static void print_message(const char *s, long num, int length, int tm)
3520 mr ? "+DT:%s:%d:%d\n"
3521 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3522 (void)BIO_flush(bio_err);
3526 mr ? "+DN:%s:%ld:%d\n"
3527 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3528 (void)BIO_flush(bio_err);
3532 static void pkey_print_message(const char *str, const char *str2, long num,
3533 unsigned int bits, int tm)
3537 mr ? "+DTP:%d:%s:%s:%d\n"
3538 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
3539 (void)BIO_flush(bio_err);
3543 mr ? "+DNP:%ld:%d:%s:%s\n"
3544 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
3545 (void)BIO_flush(bio_err);
3549 static void print_result(int alg, int run_no, int count, double time_used)
3552 BIO_puts(bio_err, "EVP error!\n");
3556 mr ? "+R:%d:%s:%f\n"
3557 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3558 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3562 static char *sstrsep(char **string, const char *delim)
3565 char *token = *string;
3570 memset(isdelim, 0, sizeof(isdelim));
3574 isdelim[(unsigned char)(*delim)] = 1;
3578 while (!isdelim[(unsigned char)(**string)]) {
3590 static int do_multi(int multi, int size_num)
3595 static char sep[] = ":";
3597 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
3598 for (n = 0; n < multi; ++n) {
3599 if (pipe(fd) == -1) {
3600 BIO_printf(bio_err, "pipe failure\n");
3604 (void)BIO_flush(bio_err);
3611 if (dup(fd[1]) == -1) {
3612 BIO_printf(bio_err, "dup failed\n");
3621 printf("Forked child %d\n", n);
3624 /* for now, assume the pipe is long enough to take all the output */
3625 for (n = 0; n < multi; ++n) {
3630 f = fdopen(fds[n], "r");
3631 while (fgets(buf, sizeof(buf), f)) {
3632 p = strchr(buf, '\n');
3635 if (buf[0] != '+') {
3637 "Don't understand line '%s' from child %d\n", buf,
3641 printf("Got: %s from %d\n", buf, n);
3642 if (strncmp(buf, "+F:", 3) == 0) {
3647 alg = atoi(sstrsep(&p, sep));
3649 for (j = 0; j < size_num; ++j)
3650 results[alg][j] += atof(sstrsep(&p, sep));
3651 } else if (strncmp(buf, "+F2:", 4) == 0) {
3656 k = atoi(sstrsep(&p, sep));
3659 d = atof(sstrsep(&p, sep));
3660 rsa_results[k][0] += d;
3662 d = atof(sstrsep(&p, sep));
3663 rsa_results[k][1] += d;
3665 # ifndef OPENSSL_NO_DSA
3666 else if (strncmp(buf, "+F3:", 4) == 0) {
3671 k = atoi(sstrsep(&p, sep));
3674 d = atof(sstrsep(&p, sep));
3675 dsa_results[k][0] += d;
3677 d = atof(sstrsep(&p, sep));
3678 dsa_results[k][1] += d;
3681 # ifndef OPENSSL_NO_EC
3682 else if (strncmp(buf, "+F4:", 4) == 0) {
3687 k = atoi(sstrsep(&p, sep));
3690 d = atof(sstrsep(&p, sep));
3691 ecdsa_results[k][0] += d;
3693 d = atof(sstrsep(&p, sep));
3694 ecdsa_results[k][1] += d;
3695 } else if (strncmp(buf, "+F5:", 4) == 0) {
3700 k = atoi(sstrsep(&p, sep));
3703 d = atof(sstrsep(&p, sep));
3704 ecdh_results[k][0] += d;
3705 } else if (strncmp(buf, "+F6:", 4) == 0) {
3710 k = atoi(sstrsep(&p, sep));
3713 d = atof(sstrsep(&p, sep));
3714 eddsa_results[k][0] += d;
3716 d = atof(sstrsep(&p, sep));
3717 eddsa_results[k][1] += d;
3721 else if (strncmp(buf, "+H:", 3) == 0) {
3724 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3735 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
3736 const openssl_speed_sec_t *seconds)
3738 static const int mblengths_list[] =
3739 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3740 const int *mblengths = mblengths_list;
3741 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
3742 const char *alg_name;
3743 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
3744 EVP_CIPHER_CTX *ctx;
3747 if (lengths_single) {
3748 mblengths = &lengths_single;
3752 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3753 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3754 ctx = EVP_CIPHER_CTX_new();
3755 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
3757 keylen = EVP_CIPHER_CTX_key_length(ctx);
3758 key = app_malloc(keylen, "evp_cipher key");
3759 EVP_CIPHER_CTX_rand_key(ctx, key);
3760 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
3761 OPENSSL_clear_free(key, keylen);
3763 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3764 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3766 for (j = 0; j < num; j++) {
3767 print_message(alg_name, 0, mblengths[j], seconds->sym);
3769 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3770 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3771 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3772 size_t len = mblengths[j];
3775 memset(aad, 0, 8); /* avoid uninitialized values */
3776 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3777 aad[9] = 3; /* version */
3779 aad[11] = 0; /* length */
3781 mb_param.out = NULL;
3784 mb_param.interleave = 8;
3786 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3787 sizeof(mb_param), &mb_param);
3793 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3794 sizeof(mb_param), &mb_param);
3798 RAND_bytes(out, 16);
3800 aad[11] = (unsigned char)(len >> 8);
3801 aad[12] = (unsigned char)(len);
3802 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3803 EVP_AEAD_TLS1_AAD_LEN, aad);
3804 EVP_Cipher(ctx, out, inp, len + pad);
3808 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3809 : "%d %s's in %.2fs\n", count, "evp", d);
3810 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3814 fprintf(stdout, "+H");
3815 for (j = 0; j < num; j++)
3816 fprintf(stdout, ":%d", mblengths[j]);
3817 fprintf(stdout, "\n");
3818 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3819 for (j = 0; j < num; j++)
3820 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3821 fprintf(stdout, "\n");
3824 "The 'numbers' are in 1000s of bytes per second processed.\n");
3825 fprintf(stdout, "type ");
3826 for (j = 0; j < num; j++)
3827 fprintf(stdout, "%7d bytes", mblengths[j]);
3828 fprintf(stdout, "\n");
3829 fprintf(stdout, "%-24s", alg_name);
3831 for (j = 0; j < num; j++) {
3832 if (results[D_EVP][j] > 10000)
3833 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3835 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3837 fprintf(stdout, "\n");
3842 EVP_CIPHER_CTX_free(ctx);