2 * Copyright 1995-2020 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
18 #define SM2_SECONDS 10
19 #define FFDH_SECONDS 10
21 /* We need to use some deprecated APIs */
22 #define OPENSSL_SUPPRESS_DEPRECATED
30 #include <openssl/crypto.h>
31 #include <openssl/rand.h>
32 #include <openssl/err.h>
33 #include <openssl/evp.h>
34 #include <openssl/objects.h>
35 #include <openssl/async.h>
36 #if !defined(OPENSSL_SYS_MSDOS)
44 #include <openssl/bn.h>
45 #ifndef OPENSSL_NO_DES
46 # include <openssl/des.h>
48 #ifndef OPENSSL_NO_DEPRECATED_3_0
49 #include <openssl/aes.h>
51 #ifndef OPENSSL_NO_CAMELLIA
52 # include <openssl/camellia.h>
54 #ifndef OPENSSL_NO_MD2
55 # include <openssl/md2.h>
57 #ifndef OPENSSL_NO_MDC2
58 # include <openssl/mdc2.h>
60 #ifndef OPENSSL_NO_MD4
61 # include <openssl/md4.h>
63 #ifndef OPENSSL_NO_MD5
64 # include <openssl/md5.h>
66 #include <openssl/hmac.h>
67 #ifndef OPENSSL_NO_CMAC
68 #include <openssl/cmac.h>
70 #include <openssl/sha.h>
71 #ifndef OPENSSL_NO_RMD160
72 # include <openssl/ripemd.h>
74 #ifndef OPENSSL_NO_WHIRLPOOL
75 # include <openssl/whrlpool.h>
77 #ifndef OPENSSL_NO_RC4
78 # include <openssl/rc4.h>
80 #ifndef OPENSSL_NO_RC5
81 # include <openssl/rc5.h>
83 #ifndef OPENSSL_NO_RC2
84 # include <openssl/rc2.h>
86 #ifndef OPENSSL_NO_IDEA
87 # include <openssl/idea.h>
89 #ifndef OPENSSL_NO_SEED
90 # include <openssl/seed.h>
93 # include <openssl/blowfish.h>
95 #ifndef OPENSSL_NO_CAST
96 # include <openssl/cast.h>
98 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
99 # include <openssl/rsa.h>
100 # include "./testrsa.h"
102 #ifndef OPENSSL_NO_DH
103 # include <openssl/dh.h>
105 #include <openssl/x509.h>
106 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
107 # include <openssl/dsa.h>
108 # include "./testdsa.h"
110 #ifndef OPENSSL_NO_EC
111 # include <openssl/ec.h>
113 #include <openssl/modes.h>
116 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
129 #define MAX_MISALIGNMENT 63
130 #define MAX_ECDH_SIZE 256
132 #define MAX_FFDH_SIZE 1024
134 typedef struct openssl_speed_sec_st {
143 } openssl_speed_sec_t;
145 static volatile int run = 0;
147 static int mr = 0; /* machine-readeable output format to merge fork results */
148 static int usertime = 1;
150 static double Time_F(int s);
151 static void print_message(const char *s, long num, int length, int tm);
152 static void pkey_print_message(const char *str, const char *str2,
153 long num, unsigned int bits, int sec);
154 static void print_result(int alg, int run_no, int count, double time_used);
156 static int do_multi(int multi, int size_num);
159 static const int lengths_list[] = {
160 16, 64, 256, 1024, 8 * 1024, 16 * 1024
162 #define SIZE_NUM OSSL_NELEM(lengths_list)
163 static const int *lengths = lengths_list;
165 static const int aead_lengths_list[] = {
166 2, 31, 136, 1024, 8 * 1024, 16 * 1024
174 static void alarmed(int sig)
176 signal(SIGALRM, alarmed);
180 static double Time_F(int s)
182 double ret = app_tminterval(s, usertime);
188 #elif defined(_WIN32)
192 static unsigned int lapse;
193 static volatile unsigned int schlock;
194 static void alarm_win32(unsigned int secs)
199 # define alarm alarm_win32
201 static DWORD WINAPI sleepy(VOID * arg)
209 static double Time_F(int s)
216 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
218 DWORD err = GetLastError();
219 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
223 Sleep(0); /* scheduler spinlock */
224 ret = app_tminterval(s, usertime);
226 ret = app_tminterval(s, usertime);
228 TerminateThread(thr, 0);
235 static double Time_F(int s)
237 return app_tminterval(s, usertime);
241 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
242 const openssl_speed_sec_t *seconds);
244 static int opt_found(const char *name, unsigned int *result,
245 const OPT_PAIR pairs[], unsigned int nbelem)
249 for (idx = 0; idx < nbelem; ++idx, pairs++)
250 if (strcmp(name, pairs->name) == 0) {
251 *result = pairs->retval;
256 #define opt_found(value, pairs, result)\
257 opt_found(value, result, pairs, OSSL_NELEM(pairs))
259 typedef enum OPTION_choice {
260 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
261 OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
262 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM, OPT_PROV_ENUM,
263 OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC
266 const OPTIONS speed_options[] = {
267 {OPT_HELP_STR, 1, '-', "Usage: %s [options] [algorithm...]\n"},
269 OPT_SECTION("General"),
270 {"help", OPT_HELP, '-', "Display this summary"},
272 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
273 {"mr", OPT_MR, '-', "Produce machine readable output"},
275 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
277 #ifndef OPENSSL_NO_ASYNC
278 {"async_jobs", OPT_ASYNCJOBS, 'p',
279 "Enable async mode and start specified number of jobs"},
281 #ifndef OPENSSL_NO_ENGINE
282 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
284 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
286 OPT_SECTION("Selection"),
287 {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
288 #ifndef OPENSSL_NO_DEPRECATED_3_0
289 {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"},
291 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
292 {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"},
294 {"decrypt", OPT_DECRYPT, '-',
295 "Time decryption instead of encryption (only EVP)"},
296 {"aead", OPT_AEAD, '-',
297 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
299 OPT_SECTION("Timing"),
300 {"elapsed", OPT_ELAPSED, '-',
301 "Use wall-clock time instead of CPU user time as divisor"},
302 {"seconds", OPT_SECONDS, 'p',
303 "Run benchmarks for specified amount of seconds"},
304 {"bytes", OPT_BYTES, 'p',
305 "Run [non-PKI] benchmarks on custom-sized buffer"},
306 {"misalign", OPT_MISALIGN, 'p',
307 "Use specified offset to mis-align buffers"},
313 {"algorithm", 0, 0, "Algorithm(s) to test (optional; otherwise tests all)"},
318 D_MD2, D_MDC2, D_MD4, D_MD5 , D_HMAC, D_SHA1, D_RMD160, D_RC4,
319 D_CBC_DES, D_EDE3_DES, D_CBC_IDEA, D_CBC_SEED,
320 D_CBC_RC2, D_CBC_RC5, D_CBC_BF, D_CBC_CAST,
321 D_CBC_128_AES, D_CBC_192_AES, D_CBC_256_AES,
322 D_CBC_128_CML, D_CBC_192_CML, D_CBC_256_CML,
323 D_EVP, D_SHA256, D_SHA512, D_WHIRLPOOL,
324 D_IGE_128_AES, D_IGE_192_AES, D_IGE_256_AES,
325 D_GHASH, D_RAND, D_EVP_HMAC, D_EVP_CMAC, ALGOR_NUM
327 /* name of algorithms to test. MUST BE KEEP IN SYNC with above enum ! */
328 static const char *names[ALGOR_NUM] = {
329 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
330 "des cbc", "des ede3", "idea cbc", "seed cbc",
331 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
332 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
333 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
334 "evp", "sha256", "sha512", "whirlpool",
335 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
336 "rand", "hmac", "cmac"
339 /* list of configured algorithm (remaining), with some few alias */
340 static const OPT_PAIR doit_choices[] = {
341 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
344 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
347 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
350 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
352 # ifndef OPENSSL_NO_DEPRECATED_3_0
356 #ifndef OPENSSL_NO_DEPRECATED_3_0
358 {"sha256", D_SHA256},
359 {"sha512", D_SHA512},
361 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
362 {"whirlpool", D_WHIRLPOOL},
364 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
365 {"ripemd", D_RMD160},
366 {"rmd160", D_RMD160},
367 {"ripemd160", D_RMD160},
369 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
372 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
373 {"des-cbc", D_CBC_DES},
374 {"des-ede3", D_EDE3_DES},
376 #ifndef OPENSSL_NO_DEPRECATED_3_0
377 {"aes-128-cbc", D_CBC_128_AES},
378 {"aes-192-cbc", D_CBC_192_AES},
379 {"aes-256-cbc", D_CBC_256_AES},
380 {"aes-128-ige", D_IGE_128_AES},
381 {"aes-192-ige", D_IGE_192_AES},
382 {"aes-256-ige", D_IGE_256_AES},
384 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
385 {"rc2-cbc", D_CBC_RC2},
388 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
389 {"rc5-cbc", D_CBC_RC5},
392 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
393 {"idea-cbc", D_CBC_IDEA},
394 {"idea", D_CBC_IDEA},
396 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
397 {"seed-cbc", D_CBC_SEED},
398 {"seed", D_CBC_SEED},
400 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
401 {"bf-cbc", D_CBC_BF},
402 {"blowfish", D_CBC_BF},
405 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
406 {"cast-cbc", D_CBC_CAST},
407 {"cast", D_CBC_CAST},
408 {"cast5", D_CBC_CAST},
414 static double results[ALGOR_NUM][SIZE_NUM];
416 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
417 enum { R_DSA_512, R_DSA_1024, R_DSA_2048, DSA_NUM };
418 static const OPT_PAIR dsa_choices[DSA_NUM] = {
419 {"dsa512", R_DSA_512},
420 {"dsa1024", R_DSA_1024},
421 {"dsa2048", R_DSA_2048}
423 static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
424 #endif /* OPENSSL_NO_DSA */
426 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
428 R_RSA_512, R_RSA_1024, R_RSA_2048, R_RSA_3072, R_RSA_4096, R_RSA_7680,
431 static const OPT_PAIR rsa_choices[RSA_NUM] = {
432 {"rsa512", R_RSA_512},
433 {"rsa1024", R_RSA_1024},
434 {"rsa2048", R_RSA_2048},
435 {"rsa3072", R_RSA_3072},
436 {"rsa4096", R_RSA_4096},
437 {"rsa7680", R_RSA_7680},
438 {"rsa15360", R_RSA_15360}
441 static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
442 #endif /* OPENSSL_NO_RSA */
444 #ifndef OPENSSL_NO_DH
446 R_FFDH_2048, R_FFDH_3072, R_FFDH_4096, R_FFDH_6144, R_FFDH_8192, FFDH_NUM
449 static const OPT_PAIR ffdh_choices[FFDH_NUM] = {
450 {"ffdh2048", R_FFDH_2048},
451 {"ffdh3072", R_FFDH_3072},
452 {"ffdh4096", R_FFDH_4096},
453 {"ffdh6144", R_FFDH_6144},
454 {"ffdh8192", R_FFDH_8192},
457 static double ffdh_results[FFDH_NUM][1]; /* 1 op: derivation */
458 #endif /* OPENSSL_NO_DH */
460 #ifndef OPENSSL_NO_EC
462 R_EC_P160, R_EC_P192, R_EC_P224, R_EC_P256, R_EC_P384, R_EC_P521,
463 # ifndef OPENSSL_NO_EC2M
464 R_EC_K163, R_EC_K233, R_EC_K283, R_EC_K409, R_EC_K571,
465 R_EC_B163, R_EC_B233, R_EC_B283, R_EC_B409, R_EC_B571,
467 R_EC_BRP256R1, R_EC_BRP256T1, R_EC_BRP384R1, R_EC_BRP384T1,
468 R_EC_BRP512R1, R_EC_BRP512T1, ECDSA_NUM
470 /* list of ecdsa curves */
471 static const OPT_PAIR ecdsa_choices[ECDSA_NUM] = {
472 {"ecdsap160", R_EC_P160},
473 {"ecdsap192", R_EC_P192},
474 {"ecdsap224", R_EC_P224},
475 {"ecdsap256", R_EC_P256},
476 {"ecdsap384", R_EC_P384},
477 {"ecdsap521", R_EC_P521},
478 # ifndef OPENSSL_NO_EC2M
479 {"ecdsak163", R_EC_K163},
480 {"ecdsak233", R_EC_K233},
481 {"ecdsak283", R_EC_K283},
482 {"ecdsak409", R_EC_K409},
483 {"ecdsak571", R_EC_K571},
484 {"ecdsab163", R_EC_B163},
485 {"ecdsab233", R_EC_B233},
486 {"ecdsab283", R_EC_B283},
487 {"ecdsab409", R_EC_B409},
488 {"ecdsab571", R_EC_B571},
490 {"ecdsabrp256r1", R_EC_BRP256R1},
491 {"ecdsabrp256t1", R_EC_BRP256T1},
492 {"ecdsabrp384r1", R_EC_BRP384R1},
493 {"ecdsabrp384t1", R_EC_BRP384T1},
494 {"ecdsabrp512r1", R_EC_BRP512R1},
495 {"ecdsabrp512t1", R_EC_BRP512T1}
497 enum { R_EC_X25519 = ECDSA_NUM, R_EC_X448, EC_NUM };
498 /* list of ecdh curves, extension of |ecdsa_choices| list above */
499 static const OPT_PAIR ecdh_choices[EC_NUM] = {
500 {"ecdhp160", R_EC_P160},
501 {"ecdhp192", R_EC_P192},
502 {"ecdhp224", R_EC_P224},
503 {"ecdhp256", R_EC_P256},
504 {"ecdhp384", R_EC_P384},
505 {"ecdhp521", R_EC_P521},
506 # ifndef OPENSSL_NO_EC2M
507 {"ecdhk163", R_EC_K163},
508 {"ecdhk233", R_EC_K233},
509 {"ecdhk283", R_EC_K283},
510 {"ecdhk409", R_EC_K409},
511 {"ecdhk571", R_EC_K571},
512 {"ecdhb163", R_EC_B163},
513 {"ecdhb233", R_EC_B233},
514 {"ecdhb283", R_EC_B283},
515 {"ecdhb409", R_EC_B409},
516 {"ecdhb571", R_EC_B571},
518 {"ecdhbrp256r1", R_EC_BRP256R1},
519 {"ecdhbrp256t1", R_EC_BRP256T1},
520 {"ecdhbrp384r1", R_EC_BRP384R1},
521 {"ecdhbrp384t1", R_EC_BRP384T1},
522 {"ecdhbrp512r1", R_EC_BRP512R1},
523 {"ecdhbrp512t1", R_EC_BRP512T1},
524 {"ecdhx25519", R_EC_X25519},
525 {"ecdhx448", R_EC_X448}
528 static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
529 static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
531 enum { R_EC_Ed25519, R_EC_Ed448, EdDSA_NUM };
532 static const OPT_PAIR eddsa_choices[EdDSA_NUM] = {
533 {"ed25519", R_EC_Ed25519},
534 {"ed448", R_EC_Ed448}
537 static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
539 # ifndef OPENSSL_NO_SM2
540 enum { R_EC_CURVESM2, SM2_NUM };
541 static const OPT_PAIR sm2_choices[SM2_NUM] = {
542 {"curveSM2", R_EC_CURVESM2}
544 # define SM2_ID "TLSv1.3+GM+Cipher+Suite"
545 # define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1
546 static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */
547 # endif /* OPENSSL_NO_SM2 */
548 #endif /* OPENSSL_NO_EC */
551 # define COND(d) (count < (d))
552 # define COUNT(d) (d)
554 # define COND(unused_cond) (run && count<0x7fffffff)
555 # define COUNT(d) (count)
558 typedef struct loopargs_st {
559 ASYNC_JOB *inprogress_job;
560 ASYNC_WAIT_CTX *wait_ctx;
563 unsigned char *buf_malloc;
564 unsigned char *buf2_malloc;
568 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
569 RSA *rsa_key[RSA_NUM];
571 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
572 DSA *dsa_key[DSA_NUM];
574 #ifndef OPENSSL_NO_EC
575 EC_KEY *ecdsa[ECDSA_NUM];
576 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
577 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
578 # ifndef OPENSSL_NO_SM2
579 EVP_MD_CTX *sm2_ctx[SM2_NUM];
580 EVP_MD_CTX *sm2_vfy_ctx[SM2_NUM];
581 EVP_PKEY *sm2_pkey[SM2_NUM];
583 unsigned char *secret_a;
584 unsigned char *secret_b;
585 size_t outlen[EC_NUM];
587 #ifndef OPENSSL_NO_DH
588 EVP_PKEY_CTX *ffdh_ctx[FFDH_NUM];
589 unsigned char *secret_ff_a;
590 unsigned char *secret_ff_b;
593 #ifndef OPENSSL_NO_DEPRECATED_3_0
596 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
599 GCM128_CONTEXT *gcm_ctx;
601 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
602 loopargs_t * loopargs);
604 static unsigned int testnum;
606 /* Nb of iterations to do per algorithm and key-size */
607 static long c[ALGOR_NUM][SIZE_NUM];
609 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
610 static int EVP_Digest_MD2_loop(void *args)
612 loopargs_t *tempargs = *(loopargs_t **) args;
613 unsigned char *buf = tempargs->buf;
614 unsigned char md2[MD2_DIGEST_LENGTH];
617 for (count = 0; COND(c[D_MD2][testnum]); count++) {
618 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
626 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
627 static int EVP_Digest_MDC2_loop(void *args)
629 loopargs_t *tempargs = *(loopargs_t **) args;
630 unsigned char *buf = tempargs->buf;
631 unsigned char mdc2[MDC2_DIGEST_LENGTH];
634 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
635 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
643 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
644 static int EVP_Digest_MD4_loop(void *args)
646 loopargs_t *tempargs = *(loopargs_t **) args;
647 unsigned char *buf = tempargs->buf;
648 unsigned char md4[MD4_DIGEST_LENGTH];
651 for (count = 0; COND(c[D_MD4][testnum]); count++) {
652 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
660 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
661 static int MD5_loop(void *args)
663 loopargs_t *tempargs = *(loopargs_t **) args;
664 unsigned char *buf = tempargs->buf;
665 unsigned char md5[MD5_DIGEST_LENGTH];
667 for (count = 0; COND(c[D_MD5][testnum]); count++)
668 MD5(buf, lengths[testnum], md5);
672 # ifndef OPENSSL_NO_DEPRECATED_3_0
673 static int HMAC_loop(void *args)
675 loopargs_t *tempargs = *(loopargs_t **) args;
676 unsigned char *buf = tempargs->buf;
677 HMAC_CTX *hctx = tempargs->hctx;
678 unsigned char hmac[MD5_DIGEST_LENGTH];
681 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
682 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
683 HMAC_Update(hctx, buf, lengths[testnum]);
684 HMAC_Final(hctx, hmac, NULL);
691 #ifndef OPENSSL_NO_DEPRECATED_3_0
692 static int SHA1_loop(void *args)
694 loopargs_t *tempargs = *(loopargs_t **) args;
695 unsigned char *buf = tempargs->buf;
696 unsigned char sha[SHA_DIGEST_LENGTH];
698 for (count = 0; COND(c[D_SHA1][testnum]); count++)
699 SHA1(buf, lengths[testnum], sha);
703 static int SHA256_loop(void *args)
705 loopargs_t *tempargs = *(loopargs_t **) args;
706 unsigned char *buf = tempargs->buf;
707 unsigned char sha256[SHA256_DIGEST_LENGTH];
709 for (count = 0; COND(c[D_SHA256][testnum]); count++)
710 SHA256(buf, lengths[testnum], sha256);
714 static int SHA512_loop(void *args)
716 loopargs_t *tempargs = *(loopargs_t **) args;
717 unsigned char *buf = tempargs->buf;
718 unsigned char sha512[SHA512_DIGEST_LENGTH];
720 for (count = 0; COND(c[D_SHA512][testnum]); count++)
721 SHA512(buf, lengths[testnum], sha512);
726 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
727 static int WHIRLPOOL_loop(void *args)
729 loopargs_t *tempargs = *(loopargs_t **) args;
730 unsigned char *buf = tempargs->buf;
731 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
733 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
734 WHIRLPOOL(buf, lengths[testnum], whirlpool);
739 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
740 static int EVP_Digest_RMD160_loop(void *args)
742 loopargs_t *tempargs = *(loopargs_t **) args;
743 unsigned char *buf = tempargs->buf;
744 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
746 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
747 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
748 NULL, EVP_ripemd160(), NULL))
755 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
756 static RC4_KEY rc4_ks;
757 static int RC4_loop(void *args)
759 loopargs_t *tempargs = *(loopargs_t **) args;
760 unsigned char *buf = tempargs->buf;
762 for (count = 0; COND(c[D_RC4][testnum]); count++)
763 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
768 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
769 static unsigned char DES_iv[8];
770 static DES_key_schedule sch[3];
771 static int DES_ncbc_encrypt_loop(void *args)
773 loopargs_t *tempargs = *(loopargs_t **) args;
774 unsigned char *buf = tempargs->buf;
776 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
777 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch[0],
778 &DES_iv, DES_ENCRYPT);
782 static int DES_ede3_cbc_encrypt_loop(void *args)
784 loopargs_t *tempargs = *(loopargs_t **) args;
785 unsigned char *buf = tempargs->buf;
787 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
788 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
789 &sch[0], &sch[1], &sch[2], &DES_iv, DES_ENCRYPT);
794 #define MAX_BLOCK_SIZE 128
796 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
798 #ifndef OPENSSL_NO_DEPRECATED_3_0
799 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
800 static int AES_cbc_128_encrypt_loop(void *args)
802 loopargs_t *tempargs = *(loopargs_t **) args;
803 unsigned char *buf = tempargs->buf;
805 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
806 AES_cbc_encrypt(buf, buf,
807 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
811 static int AES_cbc_192_encrypt_loop(void *args)
813 loopargs_t *tempargs = *(loopargs_t **) args;
814 unsigned char *buf = tempargs->buf;
816 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
817 AES_cbc_encrypt(buf, buf,
818 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
822 static int AES_cbc_256_encrypt_loop(void *args)
824 loopargs_t *tempargs = *(loopargs_t **) args;
825 unsigned char *buf = tempargs->buf;
827 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
828 AES_cbc_encrypt(buf, buf,
829 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
833 static int AES_ige_128_encrypt_loop(void *args)
835 loopargs_t *tempargs = *(loopargs_t **) args;
836 unsigned char *buf = tempargs->buf;
837 unsigned char *buf2 = tempargs->buf2;
839 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
840 AES_ige_encrypt(buf, buf2,
841 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
845 static int AES_ige_192_encrypt_loop(void *args)
847 loopargs_t *tempargs = *(loopargs_t **) args;
848 unsigned char *buf = tempargs->buf;
849 unsigned char *buf2 = tempargs->buf2;
851 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
852 AES_ige_encrypt(buf, buf2,
853 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
857 static int AES_ige_256_encrypt_loop(void *args)
859 loopargs_t *tempargs = *(loopargs_t **) args;
860 unsigned char *buf = tempargs->buf;
861 unsigned char *buf2 = tempargs->buf2;
863 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
864 AES_ige_encrypt(buf, buf2,
865 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
869 static int CRYPTO_gcm128_aad_loop(void *args)
871 loopargs_t *tempargs = *(loopargs_t **) args;
872 unsigned char *buf = tempargs->buf;
873 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
875 for (count = 0; COND(c[D_GHASH][testnum]); count++)
876 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
881 static int RAND_bytes_loop(void *args)
883 loopargs_t *tempargs = *(loopargs_t **) args;
884 unsigned char *buf = tempargs->buf;
887 for (count = 0; COND(c[D_RAND][testnum]); count++)
888 RAND_bytes(buf, lengths[testnum]);
892 static int decrypt = 0;
893 static int EVP_Update_loop(void *args)
895 loopargs_t *tempargs = *(loopargs_t **) args;
896 unsigned char *buf = tempargs->buf;
897 EVP_CIPHER_CTX *ctx = tempargs->ctx;
901 for (count = 0; COND(c[D_EVP][testnum]); count++) {
902 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
904 /* reset iv in case of counter overflow */
905 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
909 for (count = 0; COND(c[D_EVP][testnum]); count++) {
910 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
912 /* reset iv in case of counter overflow */
913 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
918 EVP_DecryptFinal_ex(ctx, buf, &outl);
920 EVP_EncryptFinal_ex(ctx, buf, &outl);
925 * CCM does not support streaming. For the purpose of performance measurement,
926 * each message is encrypted using the same (key,iv)-pair. Do not use this
927 * code in your application.
929 static int EVP_Update_loop_ccm(void *args)
931 loopargs_t *tempargs = *(loopargs_t **) args;
932 unsigned char *buf = tempargs->buf;
933 EVP_CIPHER_CTX *ctx = tempargs->ctx;
935 unsigned char tag[12];
938 for (count = 0; COND(c[D_EVP][testnum]); count++) {
939 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
941 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
942 /* counter is reset on every update */
943 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
946 for (count = 0; COND(c[D_EVP][testnum]); count++) {
947 /* restore iv length field */
948 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
949 /* counter is reset on every update */
950 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
954 EVP_DecryptFinal_ex(ctx, buf, &outl);
956 EVP_EncryptFinal_ex(ctx, buf, &outl);
961 * To make AEAD benchmarking more relevant perform TLS-like operations,
962 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
963 * payload length is not actually limited by 16KB...
965 static int EVP_Update_loop_aead(void *args)
967 loopargs_t *tempargs = *(loopargs_t **) args;
968 unsigned char *buf = tempargs->buf;
969 EVP_CIPHER_CTX *ctx = tempargs->ctx;
971 unsigned char aad[13] = { 0xcc };
972 unsigned char faketag[16] = { 0xcc };
975 for (count = 0; COND(c[D_EVP][testnum]); count++) {
976 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
977 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
978 sizeof(faketag), faketag);
979 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
980 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
981 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
984 for (count = 0; COND(c[D_EVP][testnum]); count++) {
985 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
986 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
987 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
988 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
994 static const EVP_MD *evp_md = NULL;
995 static int EVP_Digest_loop(void *args)
997 loopargs_t *tempargs = *(loopargs_t **) args;
998 unsigned char *buf = tempargs->buf;
999 unsigned char md[EVP_MAX_MD_SIZE];
1002 for (count = 0; COND(c[D_EVP][testnum]); count++) {
1003 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
1009 #ifndef OPENSSL_NO_DEPRECATED_3_0
1010 static const EVP_MD *evp_hmac_md = NULL;
1011 static char *evp_hmac_name = NULL;
1012 static int EVP_HMAC_loop(void *args)
1014 loopargs_t *tempargs = *(loopargs_t **) args;
1015 unsigned char *buf = tempargs->buf;
1016 unsigned char no_key[32];
1019 for (count = 0; COND(c[D_EVP_HMAC][testnum]); count++) {
1020 if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
1021 NULL, NULL) == NULL)
1028 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1029 static const EVP_CIPHER *evp_cmac_cipher = NULL;
1030 static char *evp_cmac_name = NULL;
1032 static int EVP_CMAC_loop(void *args)
1034 loopargs_t *tempargs = *(loopargs_t **) args;
1035 unsigned char *buf = tempargs->buf;
1036 CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
1037 static const char key[16] = "This is a key...";
1038 unsigned char mac[16];
1039 size_t len = sizeof(mac);
1042 for (count = 0; COND(c[D_EVP_CMAC][testnum]); count++) {
1043 if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
1044 || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
1045 || !CMAC_Final(cmac_ctx, mac, &len))
1052 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1053 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1055 static int RSA_sign_loop(void *args)
1057 loopargs_t *tempargs = *(loopargs_t **) args;
1058 unsigned char *buf = tempargs->buf;
1059 unsigned char *buf2 = tempargs->buf2;
1060 unsigned int *rsa_num = &tempargs->siglen;
1061 RSA **rsa_key = tempargs->rsa_key;
1063 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1064 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1066 BIO_printf(bio_err, "RSA sign failure\n");
1067 ERR_print_errors(bio_err);
1075 static int RSA_verify_loop(void *args)
1077 loopargs_t *tempargs = *(loopargs_t **) args;
1078 unsigned char *buf = tempargs->buf;
1079 unsigned char *buf2 = tempargs->buf2;
1080 unsigned int rsa_num = tempargs->siglen;
1081 RSA **rsa_key = tempargs->rsa_key;
1083 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1085 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1087 BIO_printf(bio_err, "RSA verify failure\n");
1088 ERR_print_errors(bio_err);
1097 #ifndef OPENSSL_NO_DH
1098 static long ffdh_c[FFDH_NUM][1];
1100 static int FFDH_derive_key_loop(void *args)
1102 loopargs_t *tempargs = *(loopargs_t **) args;
1103 EVP_PKEY_CTX *ffdh_ctx = tempargs->ffdh_ctx[testnum];
1104 unsigned char *derived_secret = tempargs->secret_ff_a;
1105 size_t outlen = MAX_FFDH_SIZE;
1108 for (count = 0; COND(ffdh_c[testnum][0]); count++)
1109 EVP_PKEY_derive(ffdh_ctx, derived_secret, &outlen);
1113 #endif /* OPENSSL_NO_DH */
1115 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1116 static long dsa_c[DSA_NUM][2];
1117 static int DSA_sign_loop(void *args)
1119 loopargs_t *tempargs = *(loopargs_t **) args;
1120 unsigned char *buf = tempargs->buf;
1121 unsigned char *buf2 = tempargs->buf2;
1122 DSA **dsa_key = tempargs->dsa_key;
1123 unsigned int *siglen = &tempargs->siglen;
1125 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1126 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1128 BIO_printf(bio_err, "DSA sign failure\n");
1129 ERR_print_errors(bio_err);
1137 static int DSA_verify_loop(void *args)
1139 loopargs_t *tempargs = *(loopargs_t **) args;
1140 unsigned char *buf = tempargs->buf;
1141 unsigned char *buf2 = tempargs->buf2;
1142 DSA **dsa_key = tempargs->dsa_key;
1143 unsigned int siglen = tempargs->siglen;
1145 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1146 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1148 BIO_printf(bio_err, "DSA verify failure\n");
1149 ERR_print_errors(bio_err);
1158 #ifndef OPENSSL_NO_EC
1159 # ifndef OPENSSL_NO_DEPRECATED_3_0
1160 static long ecdsa_c[ECDSA_NUM][2];
1161 static int ECDSA_sign_loop(void *args)
1163 loopargs_t *tempargs = *(loopargs_t **) args;
1164 unsigned char *buf = tempargs->buf;
1165 EC_KEY **ecdsa = tempargs->ecdsa;
1166 unsigned char *ecdsasig = tempargs->buf2;
1167 unsigned int *ecdsasiglen = &tempargs->siglen;
1169 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1170 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1172 BIO_printf(bio_err, "ECDSA sign failure\n");
1173 ERR_print_errors(bio_err);
1181 static int ECDSA_verify_loop(void *args)
1183 loopargs_t *tempargs = *(loopargs_t **) args;
1184 unsigned char *buf = tempargs->buf;
1185 EC_KEY **ecdsa = tempargs->ecdsa;
1186 unsigned char *ecdsasig = tempargs->buf2;
1187 unsigned int ecdsasiglen = tempargs->siglen;
1189 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1190 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1192 BIO_printf(bio_err, "ECDSA verify failure\n");
1193 ERR_print_errors(bio_err);
1202 /* ******************************************************************** */
1203 static long ecdh_c[EC_NUM][1];
1205 static int ECDH_EVP_derive_key_loop(void *args)
1207 loopargs_t *tempargs = *(loopargs_t **) args;
1208 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1209 unsigned char *derived_secret = tempargs->secret_a;
1211 size_t *outlen = &(tempargs->outlen[testnum]);
1213 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1214 EVP_PKEY_derive(ctx, derived_secret, outlen);
1219 static long eddsa_c[EdDSA_NUM][2];
1220 static int EdDSA_sign_loop(void *args)
1222 loopargs_t *tempargs = *(loopargs_t **) args;
1223 unsigned char *buf = tempargs->buf;
1224 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1225 unsigned char *eddsasig = tempargs->buf2;
1226 size_t *eddsasigsize = &tempargs->sigsize;
1229 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1230 ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1232 BIO_printf(bio_err, "EdDSA sign failure\n");
1233 ERR_print_errors(bio_err);
1241 static int EdDSA_verify_loop(void *args)
1243 loopargs_t *tempargs = *(loopargs_t **) args;
1244 unsigned char *buf = tempargs->buf;
1245 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1246 unsigned char *eddsasig = tempargs->buf2;
1247 size_t eddsasigsize = tempargs->sigsize;
1250 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1251 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1253 BIO_printf(bio_err, "EdDSA verify failure\n");
1254 ERR_print_errors(bio_err);
1262 # ifndef OPENSSL_NO_SM2
1263 static long sm2_c[SM2_NUM][2];
1264 static int SM2_sign_loop(void *args)
1266 loopargs_t *tempargs = *(loopargs_t **) args;
1267 unsigned char *buf = tempargs->buf;
1268 EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx;
1269 unsigned char *sm2sig = tempargs->buf2;
1270 size_t sm2sigsize = tempargs->sigsize;
1271 const size_t max_size = tempargs->sigsize;
1273 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1275 for (count = 0; COND(sm2_c[testnum][0]); count++) {
1276 if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(),
1277 NULL, sm2_pkey[testnum])) {
1278 BIO_printf(bio_err, "SM2 init sign failure\n");
1279 ERR_print_errors(bio_err);
1283 ret = EVP_DigestSign(sm2ctx[testnum], sm2sig, &sm2sigsize,
1286 BIO_printf(bio_err, "SM2 sign failure\n");
1287 ERR_print_errors(bio_err);
1291 /* update the latest returned size and always use the fixed buffer size */
1292 tempargs->sigsize = sm2sigsize;
1293 sm2sigsize = max_size;
1299 static int SM2_verify_loop(void *args)
1301 loopargs_t *tempargs = *(loopargs_t **) args;
1302 unsigned char *buf = tempargs->buf;
1303 EVP_MD_CTX **sm2ctx = tempargs->sm2_vfy_ctx;
1304 unsigned char *sm2sig = tempargs->buf2;
1305 size_t sm2sigsize = tempargs->sigsize;
1307 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1309 for (count = 0; COND(sm2_c[testnum][1]); count++) {
1310 if (!EVP_DigestVerifyInit(sm2ctx[testnum], NULL, EVP_sm3(),
1311 NULL, sm2_pkey[testnum])) {
1312 BIO_printf(bio_err, "SM2 verify init failure\n");
1313 ERR_print_errors(bio_err);
1317 ret = EVP_DigestVerify(sm2ctx[testnum], sm2sig, sm2sigsize,
1320 BIO_printf(bio_err, "SM2 verify failure\n");
1321 ERR_print_errors(bio_err);
1328 # endif /* OPENSSL_NO_SM2 */
1329 #endif /* OPENSSL_NO_EC */
1331 static int run_benchmark(int async_jobs,
1332 int (*loop_function) (void *), loopargs_t * loopargs)
1334 int job_op_count = 0;
1335 int total_op_count = 0;
1336 int num_inprogress = 0;
1337 int error = 0, i = 0, ret = 0;
1338 OSSL_ASYNC_FD job_fd = 0;
1339 size_t num_job_fds = 0;
1341 if (async_jobs == 0) {
1342 return loop_function((void *)&loopargs);
1345 for (i = 0; i < async_jobs && !error; i++) {
1346 loopargs_t *looparg_item = loopargs + i;
1348 /* Copy pointer content (looparg_t item address) into async context */
1349 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1350 &job_op_count, loop_function,
1351 (void *)&looparg_item, sizeof(looparg_item));
1357 if (job_op_count == -1) {
1360 total_op_count += job_op_count;
1365 BIO_printf(bio_err, "Failure in the job\n");
1366 ERR_print_errors(bio_err);
1372 while (num_inprogress > 0) {
1373 #if defined(OPENSSL_SYS_WINDOWS)
1375 #elif defined(OPENSSL_SYS_UNIX)
1376 int select_result = 0;
1377 OSSL_ASYNC_FD max_fd = 0;
1380 FD_ZERO(&waitfdset);
1382 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1383 if (loopargs[i].inprogress_job == NULL)
1386 if (!ASYNC_WAIT_CTX_get_all_fds
1387 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1388 || num_job_fds > 1) {
1389 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1390 ERR_print_errors(bio_err);
1394 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1396 FD_SET(job_fd, &waitfdset);
1397 if (job_fd > max_fd)
1401 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1403 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1404 "Decrease the value of async_jobs\n",
1405 max_fd, FD_SETSIZE);
1406 ERR_print_errors(bio_err);
1411 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1412 if (select_result == -1 && errno == EINTR)
1415 if (select_result == -1) {
1416 BIO_printf(bio_err, "Failure in the select\n");
1417 ERR_print_errors(bio_err);
1422 if (select_result == 0)
1426 for (i = 0; i < async_jobs; i++) {
1427 if (loopargs[i].inprogress_job == NULL)
1430 if (!ASYNC_WAIT_CTX_get_all_fds
1431 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1432 || num_job_fds > 1) {
1433 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1434 ERR_print_errors(bio_err);
1438 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1441 #if defined(OPENSSL_SYS_UNIX)
1442 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1444 #elif defined(OPENSSL_SYS_WINDOWS)
1445 if (num_job_fds == 1
1446 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1451 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1452 loopargs[i].wait_ctx, &job_op_count,
1453 loop_function, (void *)(loopargs + i),
1454 sizeof(loopargs_t));
1459 if (job_op_count == -1) {
1462 total_op_count += job_op_count;
1465 loopargs[i].inprogress_job = NULL;
1470 loopargs[i].inprogress_job = NULL;
1471 BIO_printf(bio_err, "Failure in the job\n");
1472 ERR_print_errors(bio_err);
1479 return error ? -1 : total_op_count;
1482 #define stop_it(do_it, test_num)\
1483 memset(do_it + test_num, 0, OSSL_NELEM(do_it) - test_num);
1485 int speed_main(int argc, char **argv)
1488 loopargs_t *loopargs = NULL;
1490 const char *engine_id = NULL;
1491 const EVP_CIPHER *evp_cipher = NULL;
1494 int async_init = 0, multiblock = 0, pr_header = 0;
1495 uint8_t doit[ALGOR_NUM] = { 0 };
1496 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1498 unsigned int size_num = SIZE_NUM;
1499 unsigned int i, k, loopargs_len = 0, async_jobs = 0;
1505 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1506 || !defined(OPENSSL_NO_EC)
1509 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1510 ECDSA_SECONDS, ECDH_SECONDS,
1511 EdDSA_SECONDS, SM2_SECONDS,
1514 /* What follows are the buffers and key material. */
1515 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1518 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1521 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1522 IDEA_KEY_SCHEDULE idea_ks;
1524 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1525 SEED_KEY_SCHEDULE seed_ks;
1527 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1530 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1533 #ifndef OPENSSL_NO_DEPRECATED_3_0
1534 static const unsigned char key16[16] = {
1535 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1536 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1538 static const unsigned char key24[24] = {
1539 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1540 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1541 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1543 static const unsigned char key32[32] = {
1544 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1545 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1546 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1547 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1550 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1551 CAMELLIA_KEY camellia_ks[3];
1553 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1554 static const struct {
1555 const unsigned char *data;
1556 unsigned int length;
1559 { test512, sizeof(test512), 512 },
1560 { test1024, sizeof(test1024), 1024 },
1561 { test2048, sizeof(test2048), 2048 },
1562 { test3072, sizeof(test3072), 3072 },
1563 { test4096, sizeof(test4096), 4092 },
1564 { test7680, sizeof(test7680), 7680 },
1565 { test15360, sizeof(test15360), 15360 }
1567 uint8_t rsa_doit[RSA_NUM] = { 0 };
1568 int primes = RSA_DEFAULT_PRIME_NUM;
1570 #ifndef OPENSSL_NO_DH
1571 typedef struct ffdh_params_st {
1577 static const FFDH_PARAMS ffdh_params[FFDH_NUM] = {
1578 {"ffdh2048", NID_ffdhe2048, 2048},
1579 {"ffdh3072", NID_ffdhe3072, 3072},
1580 {"ffdh4096", NID_ffdhe4096, 4096},
1581 {"ffdh6144", NID_ffdhe6144, 6144},
1582 {"ffdh8192", NID_ffdhe8192, 8192}
1584 uint8_t ffdh_doit[FFDH_NUM] = { 0 };
1586 #endif /* OPENSSL_NO_DH */
1587 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1588 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1589 uint8_t dsa_doit[DSA_NUM] = { 0 };
1591 #ifndef OPENSSL_NO_EC
1592 typedef struct ec_curve_st {
1596 size_t sigsize; /* only used for EdDSA curves */
1599 * We only test over the following curves as they are representative, To
1600 * add tests over more curves, simply add the curve NID and curve name to
1601 * the following arrays and increase the |ecdh_choices| and |ecdsa_choices|
1602 * lists accordingly.
1604 static const EC_CURVE ec_curves[EC_NUM] = {
1606 {"secp160r1", NID_secp160r1, 160},
1607 {"nistp192", NID_X9_62_prime192v1, 192},
1608 {"nistp224", NID_secp224r1, 224},
1609 {"nistp256", NID_X9_62_prime256v1, 256},
1610 {"nistp384", NID_secp384r1, 384},
1611 {"nistp521", NID_secp521r1, 521},
1612 # ifndef OPENSSL_NO_EC2M
1614 {"nistk163", NID_sect163k1, 163},
1615 {"nistk233", NID_sect233k1, 233},
1616 {"nistk283", NID_sect283k1, 283},
1617 {"nistk409", NID_sect409k1, 409},
1618 {"nistk571", NID_sect571k1, 571},
1619 {"nistb163", NID_sect163r2, 163},
1620 {"nistb233", NID_sect233r1, 233},
1621 {"nistb283", NID_sect283r1, 283},
1622 {"nistb409", NID_sect409r1, 409},
1623 {"nistb571", NID_sect571r1, 571},
1625 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1626 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1627 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1628 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1629 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1630 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1631 /* Other and ECDH only ones */
1632 {"X25519", NID_X25519, 253},
1633 {"X448", NID_X448, 448}
1635 static const EC_CURVE ed_curves[EdDSA_NUM] = {
1637 {"Ed25519", NID_ED25519, 253, 64},
1638 {"Ed448", NID_ED448, 456, 114}
1640 # ifndef OPENSSL_NO_SM2
1641 static const EC_CURVE sm2_curves[SM2_NUM] = {
1643 {"CurveSM2", NID_sm2, 256}
1645 uint8_t sm2_doit[SM2_NUM] = { 0 };
1647 uint8_t ecdsa_doit[ECDSA_NUM] = { 0 };
1648 uint8_t ecdh_doit[EC_NUM] = { 0 };
1649 uint8_t eddsa_doit[EdDSA_NUM] = { 0 };
1651 /* checks declarated curves against choices list. */
1652 OPENSSL_assert(ed_curves[EdDSA_NUM - 1].nid == NID_ED448);
1653 OPENSSL_assert(strcmp(eddsa_choices[EdDSA_NUM - 1].name, "ed448") == 0);
1655 OPENSSL_assert(ec_curves[EC_NUM - 1].nid == NID_X448);
1656 OPENSSL_assert(strcmp(ecdh_choices[EC_NUM - 1].name, "ecdhx448") == 0);
1658 OPENSSL_assert(ec_curves[ECDSA_NUM - 1].nid == NID_brainpoolP512t1);
1659 OPENSSL_assert(strcmp(ecdsa_choices[ECDSA_NUM - 1].name, "ecdsabrp512t1") == 0);
1661 # ifndef OPENSSL_NO_SM2
1662 OPENSSL_assert(sm2_curves[SM2_NUM - 1].nid == NID_sm2);
1663 OPENSSL_assert(strcmp(sm2_choices[SM2_NUM - 1].name, "curveSM2") == 0);
1665 #endif /* ndef OPENSSL_NO_EC */
1667 prog = opt_init(argc, argv, speed_options);
1668 while ((o = opt_next()) != OPT_EOF) {
1673 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1676 opt_help(speed_options);
1684 evp_cipher = EVP_get_cipherbyname(opt_arg());
1685 if (evp_cipher == NULL)
1686 evp_md = EVP_get_digestbyname(opt_arg());
1687 if (evp_cipher == NULL && evp_md == NULL) {
1689 "%s: %s is an unknown cipher or digest\n",
1696 #ifndef OPENSSL_NO_DEPRECATED_3_0
1697 evp_hmac_md = EVP_get_digestbyname(opt_arg());
1698 if (evp_hmac_md == NULL) {
1699 BIO_printf(bio_err, "%s: %s is an unknown digest\n",
1703 doit[D_EVP_HMAC] = 1;
1707 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1708 evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
1709 if (evp_cmac_cipher == NULL) {
1710 BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
1714 doit[D_EVP_CMAC] = 1;
1722 * In a forked execution, an engine might need to be
1723 * initialised by each child process, not by the parent.
1724 * So store the name here and run setup_engine() later on.
1726 engine_id = opt_arg();
1730 multi = atoi(opt_arg());
1734 #ifndef OPENSSL_NO_ASYNC
1735 async_jobs = atoi(opt_arg());
1736 if (!ASYNC_is_capable()) {
1738 "%s: async_jobs specified but async not supported\n",
1742 if (async_jobs > 99999) {
1743 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1749 if (!opt_int(opt_arg(), &misalign))
1751 if (misalign > MISALIGN) {
1753 "%s: Maximum offset is %d\n", prog, MISALIGN);
1762 #ifdef OPENSSL_NO_MULTIBLOCK
1764 "%s: -mb specified but multi-block support is disabled\n",
1773 case OPT_PROV_CASES:
1774 if (!opt_provider(o))
1778 #ifndef OPENSSL_NO_DEPRECATED_3_0
1779 if (!opt_int(opt_arg(), &primes))
1784 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1785 = seconds.ecdh = seconds.eddsa
1786 = seconds.sm2 = seconds.ffdh = atoi(opt_arg());
1789 lengths_single = atoi(opt_arg());
1790 lengths = &lengths_single;
1798 argc = opt_num_rest();
1801 /* Remaining arguments are algorithms. */
1802 for (; *argv; argv++) {
1803 const char *algo = *argv;
1805 if (opt_found(algo, doit_choices, &i)) {
1809 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1810 if (strcmp(algo, "des") == 0) {
1811 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1815 if (strcmp(algo, "sha") == 0) {
1816 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1819 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1820 if (strcmp(algo, "openssl") == 0) /* just for compatibility */
1822 if (strncmp(algo, "rsa", 3) == 0) {
1823 if (algo[3] == '\0') {
1824 memset(rsa_doit, 1, sizeof(rsa_doit));
1827 if (opt_found(algo, rsa_choices, &i)) {
1833 #ifndef OPENSSL_NO_DH
1834 if (strncmp(algo, "ffdh", 4) == 0) {
1835 if (algo[4] == '\0') {
1836 memset(ffdh_doit, 1, sizeof(ffdh_doit));
1839 if (opt_found(algo, ffdh_choices, &i)) {
1845 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1846 if (strncmp(algo, "dsa", 3) == 0) {
1847 if (algo[3] == '\0') {
1848 memset(dsa_doit, 1, sizeof(dsa_doit));
1851 if (opt_found(algo, dsa_choices, &i)) {
1857 #ifndef OPENSSL_NO_DEPRECATED_3_0
1858 if (strcmp(algo, "aes") == 0) {
1859 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1863 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1864 if (strcmp(algo, "camellia") == 0) {
1865 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1869 #ifndef OPENSSL_NO_EC
1870 if (strncmp(algo, "ecdsa", 5) == 0) {
1871 if (algo[5] == '\0') {
1872 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
1875 if (opt_found(algo, ecdsa_choices, &i)) {
1880 if (strncmp(algo, "ecdh", 4) == 0) {
1881 if (algo[4] == '\0') {
1882 memset(ecdh_doit, 1, sizeof(ecdh_doit));
1885 if (opt_found(algo, ecdh_choices, &i)) {
1890 if (strcmp(algo, "eddsa") == 0) {
1891 memset(eddsa_doit, 1, sizeof(eddsa_doit));
1894 if (opt_found(algo, eddsa_choices, &i)) {
1898 # ifndef OPENSSL_NO_SM2
1899 if (strcmp(algo, "sm2") == 0) {
1900 memset(sm2_doit, 1, sizeof(sm2_doit));
1903 if (opt_found(algo, sm2_choices, &i)) {
1908 #endif /* OPENSSL_NO_EC */
1909 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, algo);
1915 if (evp_cipher == NULL) {
1916 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1918 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1919 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1920 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1921 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1926 if (evp_cipher == NULL) {
1927 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1928 " capable cipher\n");
1930 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1931 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1932 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1933 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1935 } else if (async_jobs > 0) {
1936 BIO_printf(bio_err, "Async mode is not supported with -mb");
1941 /* Initialize the job pool if async mode is enabled */
1942 if (async_jobs > 0) {
1943 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1945 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1950 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1952 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1953 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1955 for (i = 0; i < loopargs_len; i++) {
1956 if (async_jobs > 0) {
1957 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1958 if (loopargs[i].wait_ctx == NULL) {
1959 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1964 buflen = lengths[size_num - 1];
1965 if (buflen < 36) /* size of random vector in RSA benchmark */
1967 buflen += MAX_MISALIGNMENT + 1;
1968 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1969 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1970 memset(loopargs[i].buf_malloc, 0, buflen);
1971 memset(loopargs[i].buf2_malloc, 0, buflen);
1973 /* Align the start of buffers on a 64 byte boundary */
1974 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1975 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1976 #ifndef OPENSSL_NO_EC
1977 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1978 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1980 #ifndef OPENSSL_NO_DH
1981 loopargs[i].secret_ff_a = app_malloc(MAX_FFDH_SIZE, "FFDH secret a");
1982 loopargs[i].secret_ff_b = app_malloc(MAX_FFDH_SIZE, "FFDH secret b");
1987 if (multi && do_multi(multi, size_num))
1991 /* Initialize the engine after the fork */
1992 e = setup_engine(engine_id, 0);
1994 /* No parameters; turn on everything. */
1995 if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
1996 memset(doit, 1, sizeof(doit));
1997 doit[D_EVP] = doit[D_EVP_HMAC] = doit[D_EVP_CMAC] = 0;
1998 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1999 memset(rsa_doit, 1, sizeof(rsa_doit));
2001 #ifndef OPENSSL_NO_DH
2002 memset(ffdh_doit, 1, sizeof(ffdh_doit));
2004 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2005 memset(dsa_doit, 1, sizeof(dsa_doit));
2007 #ifndef OPENSSL_NO_EC
2008 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
2009 memset(ecdh_doit, 1, sizeof(ecdh_doit));
2010 memset(eddsa_doit, 1, sizeof(eddsa_doit));
2011 # ifndef OPENSSL_NO_SM2
2012 memset(sm2_doit, 1, sizeof(sm2_doit));
2016 for (i = 0; i < ALGOR_NUM; i++)
2020 if (usertime == 0 && !mr)
2022 "You have chosen to measure elapsed time "
2023 "instead of user CPU time.\n");
2025 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2026 for (i = 0; i < loopargs_len; i++) {
2027 if (primes > RSA_DEFAULT_PRIME_NUM) {
2028 /* for multi-prime RSA, skip this */
2031 for (k = 0; k < RSA_NUM; k++) {
2032 const unsigned char *p = rsa_keys[k].data;
2034 loopargs[i].rsa_key[k] =
2035 d2i_RSAPrivateKey(NULL, &p, rsa_keys[k].length);
2036 if (loopargs[i].rsa_key[k] == NULL) {
2038 "internal error loading RSA key number %d\n", k);
2044 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2045 for (i = 0; i < loopargs_len; i++) {
2046 loopargs[i].dsa_key[0] = get_dsa(512);
2047 loopargs[i].dsa_key[1] = get_dsa(1024);
2048 loopargs[i].dsa_key[2] = get_dsa(2048);
2051 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2052 if (doit[D_CBC_DES] || doit[D_EDE3_DES]) {
2053 static DES_cblock keys[] = {
2054 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }, /* keys[0] */
2055 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }, /* keys[1] */
2056 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 } /* keys[3] */
2058 DES_set_key_unchecked(&keys[0], &sch[0]);
2059 DES_set_key_unchecked(&keys[1], &sch[1]);
2060 DES_set_key_unchecked(&keys[2], &sch[2]);
2063 #ifndef OPENSSL_NO_DEPRECATED_3_0
2064 AES_set_encrypt_key(key16, 128, &aes_ks1);
2065 AES_set_encrypt_key(key24, 192, &aes_ks2);
2066 AES_set_encrypt_key(key32, 256, &aes_ks3);
2068 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2069 if (doit[D_CBC_128_CML] || doit[D_CBC_192_CML] || doit[D_CBC_256_CML]) {
2070 Camellia_set_key(key16, 128, &camellia_ks[0]);
2071 Camellia_set_key(key24, 192, &camellia_ks[1]);
2072 Camellia_set_key(key32, 256, &camellia_ks[2]);
2075 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2076 if (doit[D_CBC_IDEA])
2077 IDEA_set_encrypt_key(key16, &idea_ks);
2079 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2080 if (doit[D_CBC_SEED])
2081 SEED_set_key(key16, &seed_ks);
2083 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2085 RC4_set_key(&rc4_ks, 16, key16);
2087 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2088 if (doit[D_CBC_RC2])
2089 RC2_set_key(&rc2_ks, 16, key16, 128);
2091 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2092 if (doit[D_CBC_RC5])
2093 if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
2094 BIO_printf(bio_err, "Failed setting RC5 key\n");
2098 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2100 BF_set_key(&bf_ks, 16, key16);
2102 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2103 if (doit[D_CBC_CAST])
2104 CAST_set_key(&cast_ks, 16, key16);
2107 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2108 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
2114 for (it = count; it; it--)
2115 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
2116 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
2119 c[D_MD2][0] = count / 10;
2120 c[D_MDC2][0] = count / 10;
2121 c[D_MD4][0] = count;
2122 c[D_MD5][0] = count;
2123 c[D_HMAC][0] = count;
2124 c[D_SHA1][0] = count;
2125 c[D_RMD160][0] = count;
2126 c[D_RC4][0] = count * 5;
2127 c[D_CBC_DES][0] = count;
2128 c[D_EDE3_DES][0] = count / 3;
2129 c[D_CBC_IDEA][0] = count;
2130 c[D_CBC_SEED][0] = count;
2131 c[D_CBC_RC2][0] = count;
2132 c[D_CBC_RC5][0] = count;
2133 c[D_CBC_BF][0] = count;
2134 c[D_CBC_CAST][0] = count;
2135 c[D_CBC_128_AES][0] = count;
2136 c[D_CBC_192_AES][0] = count;
2137 c[D_CBC_256_AES][0] = count;
2138 c[D_CBC_128_CML][0] = count;
2139 c[D_CBC_192_CML][0] = count;
2140 c[D_CBC_256_CML][0] = count;
2141 c[D_EVP][0] = count;
2142 c[D_SHA256][0] = count;
2143 c[D_SHA512][0] = count;
2144 c[D_WHIRLPOOL][0] = count;
2145 c[D_IGE_128_AES][0] = count;
2146 c[D_IGE_192_AES][0] = count;
2147 c[D_IGE_256_AES][0] = count;
2148 c[D_GHASH][0] = count;
2149 c[D_RAND][0] = count;
2150 c[D_EVP_HMAC][0] = count;
2151 c[D_EVP_CMAC][0] = count;
2153 for (i = 1; i < size_num; i++) {
2154 long l0 = (long)lengths[0];
2155 long l1 = (long)lengths[i];
2157 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
2158 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
2159 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
2160 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
2161 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
2162 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
2163 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
2164 c[D_EVP][i] = = c[D_EVP][0] * 4 * l0 / l1;
2165 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
2166 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
2167 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
2168 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
2169 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
2170 c[D_EVP_HMAC][i] = = c[D_EVP_HMAC][0] * 4 * l0 / l1;
2171 c[D_EVP_CMAC][i] = = c[D_EVP_CMAC][0] * 4 * l0 / l1;
2173 l0 = (long)lengths[i - 1];
2175 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
2176 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
2177 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
2178 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
2179 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
2180 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
2181 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
2182 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
2183 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
2184 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
2185 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
2186 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
2187 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
2188 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
2189 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
2190 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
2191 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
2192 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
2195 # if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2196 rsa_c[R_RSA_512][0] = count / 2000;
2197 rsa_c[R_RSA_512][1] = count / 400;
2198 for (i = 1; i < RSA_NUM; i++) {
2199 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
2200 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
2201 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
2204 if (rsa_c[i][0] == 0) {
2205 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2212 # if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2213 dsa_c[R_DSA_512][0] = count / 1000;
2214 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2215 for (i = 1; i < DSA_NUM; i++) {
2216 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2217 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2218 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2221 if (dsa_c[i][0] == 0) {
2222 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2229 # ifndef OPENSSL_NO_EC
2230 ecdsa_c[R_EC_P160][0] = count / 1000;
2231 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2232 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2233 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2234 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2235 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2238 if (ecdsa_c[i][0] == 0) {
2244 # ifndef OPENSSL_NO_EC2M
2245 ecdsa_c[R_EC_K163][0] = count / 1000;
2246 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2247 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2248 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2249 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2250 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2253 if (ecdsa_c[i][0] == 0) {
2259 ecdsa_c[R_EC_B163][0] = count / 1000;
2260 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2261 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2262 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2263 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2264 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2267 if (ecdsa_c[i][0] == 0) {
2275 ecdh_c[R_EC_P160][0] = count / 1000;
2276 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2277 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2278 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2281 if (ecdh_c[i][0] == 0) {
2286 # ifndef OPENSSL_NO_EC2M
2287 ecdh_c[R_EC_K163][0] = count / 1000;
2288 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2289 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2290 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2293 if (ecdh_c[i][0] == 0) {
2298 ecdh_c[R_EC_B163][0] = count / 1000;
2299 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2300 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2301 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2304 if (ecdh_c[i][0] == 0) {
2310 /* repeated code good to factorize */
2311 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2312 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2313 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2314 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2317 if (ecdh_c[i][0] == 0) {
2322 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2323 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2324 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2325 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2328 if (ecdh_c[i][0] == 0) {
2333 /* default iteration count for the last two EC Curves */
2334 ecdh_c[R_EC_X25519][0] = count / 1800;
2335 ecdh_c[R_EC_X448][0] = count / 7200;
2337 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2338 eddsa_c[R_EC_Ed448][0] = count / 7200;
2340 # ifndef OPENSSL_NO_SM2
2341 sm2_c[R_EC_SM2P256][0] = count / 1800;
2343 # endif /* OPENSSL_NO_EC */
2345 # ifndef OPENSSL_NO_DH
2346 ffdh_c[R_FFDH_2048][0] = count / 1000;
2347 for (i = R_FFDH_3072; i <= R_FFDH_8192; i++) {
2348 ffdh_c[i][0] = ffdh_c[i - 1][0] / 2;
2349 if (ffdh_doit[i] <= 1 && ffdh_c[i][0] == 0) {
2352 if (ffdh_c[i][0] == 0)
2356 # endif /* OPENSSL_NO_DH */
2359 /* not worth fixing */
2360 # error "You cannot disable DES on systems without SIGALRM."
2361 # endif /* OPENSSL_NO_DES */
2363 signal(SIGALRM, alarmed);
2364 #endif /* SIGALRM */
2366 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2368 for (testnum = 0; testnum < size_num; testnum++) {
2369 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2372 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2374 print_result(D_MD2, testnum, count, d);
2378 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2380 for (testnum = 0; testnum < size_num; testnum++) {
2381 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2384 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2386 print_result(D_MDC2, testnum, count, d);
2393 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2395 for (testnum = 0; testnum < size_num; testnum++) {
2396 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2399 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2401 print_result(D_MD4, testnum, count, d);
2408 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2410 for (testnum = 0; testnum < size_num; testnum++) {
2411 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2414 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2416 print_result(D_MD5, testnum, count, d);
2420 # ifndef OPENSSL_NO_DEPRECATED_3_0
2422 static const char hmac_key[] = "This is a key...";
2423 int len = strlen(hmac_key);
2425 for (i = 0; i < loopargs_len; i++) {
2426 loopargs[i].hctx = HMAC_CTX_new();
2427 if (loopargs[i].hctx == NULL) {
2428 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2432 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2434 for (testnum = 0; testnum < size_num; testnum++) {
2435 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2438 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2440 print_result(D_HMAC, testnum, count, d);
2442 for (i = 0; i < loopargs_len; i++)
2443 HMAC_CTX_free(loopargs[i].hctx);
2447 #ifndef OPENSSL_NO_DEPRECATED_3_0
2449 for (testnum = 0; testnum < size_num; testnum++) {
2450 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2453 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2455 print_result(D_SHA1, testnum, count, d);
2458 if (doit[D_SHA256]) {
2459 for (testnum = 0; testnum < size_num; testnum++) {
2460 print_message(names[D_SHA256], c[D_SHA256][testnum],
2461 lengths[testnum], seconds.sym);
2463 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2465 print_result(D_SHA256, testnum, count, d);
2468 if (doit[D_SHA512]) {
2469 for (testnum = 0; testnum < size_num; testnum++) {
2470 print_message(names[D_SHA512], c[D_SHA512][testnum],
2471 lengths[testnum], seconds.sym);
2473 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2475 print_result(D_SHA512, testnum, count, d);
2479 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2480 if (doit[D_WHIRLPOOL]) {
2481 for (testnum = 0; testnum < size_num; testnum++) {
2482 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2483 lengths[testnum], seconds.sym);
2485 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2487 print_result(D_WHIRLPOOL, testnum, count, d);
2492 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2493 if (doit[D_RMD160]) {
2494 for (testnum = 0; testnum < size_num; testnum++) {
2495 print_message(names[D_RMD160], c[D_RMD160][testnum],
2496 lengths[testnum], seconds.sym);
2498 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2500 print_result(D_RMD160, testnum, count, d);
2506 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2508 for (testnum = 0; testnum < size_num; testnum++) {
2509 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2512 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2514 print_result(D_RC4, testnum, count, d);
2518 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2519 if (doit[D_CBC_DES]) {
2520 for (testnum = 0; testnum < size_num; testnum++) {
2521 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2522 lengths[testnum], seconds.sym);
2524 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2526 print_result(D_CBC_DES, testnum, count, d);
2530 if (doit[D_EDE3_DES]) {
2531 for (testnum = 0; testnum < size_num; testnum++) {
2532 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2533 lengths[testnum], seconds.sym);
2536 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2538 print_result(D_EDE3_DES, testnum, count, d);
2543 #ifndef OPENSSL_NO_DEPRECATED_3_0
2544 if (doit[D_CBC_128_AES]) {
2545 for (testnum = 0; testnum < size_num; testnum++) {
2546 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2547 lengths[testnum], seconds.sym);
2550 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2552 print_result(D_CBC_128_AES, testnum, count, d);
2555 if (doit[D_CBC_192_AES]) {
2556 for (testnum = 0; testnum < size_num; testnum++) {
2557 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2558 lengths[testnum], seconds.sym);
2561 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2563 print_result(D_CBC_192_AES, testnum, count, d);
2566 if (doit[D_CBC_256_AES]) {
2567 for (testnum = 0; testnum < size_num; testnum++) {
2568 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2569 lengths[testnum], seconds.sym);
2572 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2574 print_result(D_CBC_256_AES, testnum, count, d);
2579 if (doit[D_IGE_128_AES]) {
2580 for (testnum = 0; testnum < size_num; testnum++) {
2581 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2582 lengths[testnum], seconds.sym);
2585 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2587 print_result(D_IGE_128_AES, testnum, count, d);
2590 if (doit[D_IGE_192_AES]) {
2591 for (testnum = 0; testnum < size_num; testnum++) {
2592 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2593 lengths[testnum], seconds.sym);
2596 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2598 print_result(D_IGE_192_AES, testnum, count, d);
2601 if (doit[D_IGE_256_AES]) {
2602 for (testnum = 0; testnum < size_num; testnum++) {
2603 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2604 lengths[testnum], seconds.sym);
2607 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2609 print_result(D_IGE_256_AES, testnum, count, d);
2612 if (doit[D_GHASH]) {
2613 for (i = 0; i < loopargs_len; i++) {
2614 loopargs[i].gcm_ctx =
2615 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2616 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2617 (unsigned char *)"0123456789ab", 12);
2620 for (testnum = 0; testnum < size_num; testnum++) {
2621 print_message(names[D_GHASH], c[D_GHASH][testnum],
2622 lengths[testnum], seconds.sym);
2624 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2626 print_result(D_GHASH, testnum, count, d);
2628 for (i = 0; i < loopargs_len; i++)
2629 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2631 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
2632 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2633 if (doit[D_CBC_128_CML]) {
2634 if (async_jobs > 0) {
2635 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2636 names[D_CBC_128_CML]);
2637 doit[D_CBC_128_CML] = 0;
2639 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2640 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2641 lengths[testnum], seconds.sym);
2643 for (count = 0; COND(c[D_CBC_128_CML][testnum]); count++)
2644 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2645 (size_t)lengths[testnum], &camellia_ks[0],
2646 iv, CAMELLIA_ENCRYPT);
2648 print_result(D_CBC_128_CML, testnum, count, d);
2651 if (doit[D_CBC_192_CML]) {
2652 if (async_jobs > 0) {
2653 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2654 names[D_CBC_192_CML]);
2655 doit[D_CBC_192_CML] = 0;
2657 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2658 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2659 lengths[testnum], seconds.sym);
2660 if (async_jobs > 0) {
2661 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2665 for (count = 0; COND(c[D_CBC_192_CML][testnum]); count++)
2666 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2667 (size_t)lengths[testnum], &camellia_ks[1],
2668 iv, CAMELLIA_ENCRYPT);
2670 print_result(D_CBC_192_CML, testnum, count, d);
2673 if (doit[D_CBC_256_CML]) {
2674 if (async_jobs > 0) {
2675 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2676 names[D_CBC_256_CML]);
2677 doit[D_CBC_256_CML] = 0;
2679 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2680 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2681 lengths[testnum], seconds.sym);
2683 for (count = 0; COND(c[D_CBC_256_CML][testnum]); count++)
2684 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2685 (size_t)lengths[testnum], &camellia_ks[2],
2686 iv, CAMELLIA_ENCRYPT);
2688 print_result(D_CBC_256_CML, testnum, count, d);
2692 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2693 if (doit[D_CBC_IDEA]) {
2694 if (async_jobs > 0) {
2695 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2697 doit[D_CBC_IDEA] = 0;
2699 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2700 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2701 lengths[testnum], seconds.sym);
2703 for (count = 0; COND(c[D_CBC_IDEA][testnum]); count++)
2704 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2705 (size_t)lengths[testnum], &idea_ks,
2708 print_result(D_CBC_IDEA, testnum, count, d);
2712 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2713 if (doit[D_CBC_SEED]) {
2714 if (async_jobs > 0) {
2715 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2717 doit[D_CBC_SEED] = 0;
2719 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2720 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2721 lengths[testnum], seconds.sym);
2723 for (count = 0; COND(c[D_CBC_SEED][testnum]); count++)
2724 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2725 (size_t)lengths[testnum], &seed_ks, iv, 1);
2727 print_result(D_CBC_SEED, testnum, count, d);
2731 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2732 if (doit[D_CBC_RC2]) {
2733 if (async_jobs > 0) {
2734 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2736 doit[D_CBC_RC2] = 0;
2738 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2739 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2740 lengths[testnum], seconds.sym);
2741 if (async_jobs > 0) {
2742 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2746 for (count = 0; COND(c[D_CBC_RC2][testnum]); count++)
2747 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2748 (size_t)lengths[testnum], &rc2_ks,
2751 print_result(D_CBC_RC2, testnum, count, d);
2755 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2756 if (doit[D_CBC_RC5]) {
2757 if (async_jobs > 0) {
2758 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2760 doit[D_CBC_RC5] = 0;
2762 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2763 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2764 lengths[testnum], seconds.sym);
2765 if (async_jobs > 0) {
2766 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2770 for (count = 0; COND(c[D_CBC_RC5][testnum]); count++)
2771 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2772 (size_t)lengths[testnum], &rc5_ks,
2775 print_result(D_CBC_RC5, testnum, count, d);
2779 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2780 if (doit[D_CBC_BF]) {
2781 if (async_jobs > 0) {
2782 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2786 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2787 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2788 lengths[testnum], seconds.sym);
2790 for (count = 0; COND(c[D_CBC_BF][testnum]); count++)
2791 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2792 (size_t)lengths[testnum], &bf_ks,
2795 print_result(D_CBC_BF, testnum, count, d);
2799 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2800 if (doit[D_CBC_CAST]) {
2801 if (async_jobs > 0) {
2802 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2804 doit[D_CBC_CAST] = 0;
2806 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2807 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2808 lengths[testnum], seconds.sym);
2810 for (count = 0; COND(c[D_CBC_CAST][testnum]); count++)
2811 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2812 (size_t)lengths[testnum], &cast_ks,
2815 print_result(D_CBC_CAST, testnum, count, d);
2820 for (testnum = 0; testnum < size_num; testnum++) {
2821 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2824 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2826 print_result(D_RAND, testnum, count, d);
2831 if (evp_cipher != NULL) {
2832 int (*loopfunc) (void *) = EVP_Update_loop;
2834 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2835 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2836 multiblock_speed(evp_cipher, lengths_single, &seconds);
2841 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2843 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2844 loopfunc = EVP_Update_loop_ccm;
2845 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2846 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2847 loopfunc = EVP_Update_loop_aead;
2848 if (lengths == lengths_list) {
2849 lengths = aead_lengths_list;
2850 size_num = OSSL_NELEM(aead_lengths_list);
2854 for (testnum = 0; testnum < size_num; testnum++) {
2855 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2858 for (k = 0; k < loopargs_len; k++) {
2859 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2860 if (loopargs[k].ctx == NULL) {
2861 BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
2864 if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2865 NULL, iv, decrypt ? 0 : 1)) {
2866 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2867 ERR_print_errors(bio_err);
2871 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2873 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2874 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2875 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2876 if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2877 loopargs[k].key, NULL, -1)) {
2878 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2879 ERR_print_errors(bio_err);
2882 OPENSSL_clear_free(loopargs[k].key, keylen);
2884 /* SIV mode only allows for a single Update operation */
2885 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
2886 EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
2890 count = run_benchmark(async_jobs, loopfunc, loopargs);
2892 for (k = 0; k < loopargs_len; k++) {
2893 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2895 print_result(D_EVP, testnum, count, d);
2897 } else if (evp_md != NULL) {
2898 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2900 for (testnum = 0; testnum < size_num; testnum++) {
2901 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2904 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2906 print_result(D_EVP, testnum, count, d);
2911 #ifndef OPENSSL_NO_DEPRECATED_3_0
2912 if (doit[D_EVP_HMAC] && evp_hmac_md != NULL) {
2913 const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
2915 evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
2917 sprintf(evp_hmac_name, "HMAC(%s)", md_name);
2918 names[D_EVP_HMAC] = evp_hmac_name;
2920 for (testnum = 0; testnum < size_num; testnum++) {
2921 print_message(names[D_EVP_HMAC], c[D_EVP_HMAC][testnum], lengths[testnum],
2924 count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
2926 print_result(D_EVP_HMAC, testnum, count, d);
2931 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2932 if (doit[D_EVP_CMAC] && evp_cmac_cipher != NULL) {
2933 const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
2935 evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
2937 sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
2938 names[D_EVP_CMAC] = evp_cmac_name;
2940 for (i = 0; i < loopargs_len; i++) {
2941 loopargs[i].cmac_ctx = CMAC_CTX_new();
2942 if (loopargs[i].cmac_ctx == NULL) {
2943 BIO_printf(bio_err, "CMAC malloc failure, exiting...");
2947 for (testnum = 0; testnum < size_num; testnum++) {
2948 print_message(names[D_EVP_CMAC], c[D_EVP_CMAC][testnum], lengths[testnum],
2951 count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
2953 print_result(D_EVP_CMAC, testnum, count, d);
2955 for (i = 0; i < loopargs_len; i++)
2956 CMAC_CTX_free(loopargs[i].cmac_ctx);
2960 for (i = 0; i < loopargs_len; i++)
2961 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2964 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2965 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2967 if (!rsa_doit[testnum])
2969 for (i = 0; i < loopargs_len; i++) {
2970 if (primes > RSA_DEFAULT_PRIME_NUM) {
2971 /* we haven't set keys yet, generate multi-prime RSA keys */
2972 BIGNUM *bn = BN_new();
2976 if (!BN_set_word(bn, RSA_F4)) {
2981 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2982 rsa_choices[testnum].name);
2984 loopargs[i].rsa_key[testnum] = RSA_new();
2985 if (loopargs[i].rsa_key[testnum] == NULL) {
2990 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2991 rsa_keys[testnum].bits,
2992 primes, bn, NULL)) {
2998 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2999 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
3005 "RSA sign failure. No RSA sign will be done.\n");
3006 ERR_print_errors(bio_err);
3009 pkey_print_message("private", "rsa",
3010 rsa_c[testnum][0], rsa_keys[testnum].bits,
3012 /* RSA_blinding_on(rsa_key[testnum],NULL); */
3014 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
3017 mr ? "+R1:%ld:%d:%.2f\n"
3018 : "%ld %u bits private RSA's in %.2fs\n",
3019 count, rsa_keys[testnum].bits, d);
3020 rsa_results[testnum][0] = (double)count / d;
3024 for (i = 0; i < loopargs_len; i++) {
3025 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
3026 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
3032 "RSA verify failure. No RSA verify will be done.\n");
3033 ERR_print_errors(bio_err);
3034 rsa_doit[testnum] = 0;
3036 pkey_print_message("public", "rsa",
3037 rsa_c[testnum][1], rsa_keys[testnum].bits,
3040 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
3043 mr ? "+R2:%ld:%d:%.2f\n"
3044 : "%ld %u bits public RSA's in %.2fs\n",
3045 count, rsa_keys[testnum].bits, d);
3046 rsa_results[testnum][1] = (double)count / d;
3049 if (rsa_count <= 1) {
3050 /* if longer than 10s, don't do any more */
3051 stop_it(rsa_doit, testnum);
3054 #endif /* OPENSSL_NO_RSA */
3056 for (i = 0; i < loopargs_len; i++)
3057 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
3060 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3061 for (testnum = 0; testnum < DSA_NUM; testnum++) {
3063 if (!dsa_doit[testnum])
3066 /* DSA_generate_key(dsa_key[testnum]); */
3067 /* DSA_sign_setup(dsa_key[testnum],NULL); */
3068 for (i = 0; i < loopargs_len; i++) {
3069 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
3070 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
3076 "DSA sign failure. No DSA sign will be done.\n");
3077 ERR_print_errors(bio_err);
3080 pkey_print_message("sign", "dsa",
3081 dsa_c[testnum][0], dsa_bits[testnum],
3084 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
3087 mr ? "+R3:%ld:%u:%.2f\n"
3088 : "%ld %u bits DSA signs in %.2fs\n",
3089 count, dsa_bits[testnum], d);
3090 dsa_results[testnum][0] = (double)count / d;
3094 for (i = 0; i < loopargs_len; i++) {
3095 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3096 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
3102 "DSA verify failure. No DSA verify will be done.\n");
3103 ERR_print_errors(bio_err);
3104 dsa_doit[testnum] = 0;
3106 pkey_print_message("verify", "dsa",
3107 dsa_c[testnum][1], dsa_bits[testnum],
3110 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
3113 mr ? "+R4:%ld:%u:%.2f\n"
3114 : "%ld %u bits DSA verify in %.2fs\n",
3115 count, dsa_bits[testnum], d);
3116 dsa_results[testnum][1] = (double)count / d;
3119 if (rsa_count <= 1) {
3120 /* if longer than 10s, don't do any more */
3121 stop_it(dsa_doit, testnum);
3124 #endif /* OPENSSL_NO_DSA */
3126 #ifndef OPENSSL_NO_EC
3127 # ifndef OPENSSL_NO_DEPRECATED_3_0
3128 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
3131 if (!ecdsa_doit[testnum])
3132 continue; /* Ignore Curve */
3133 for (i = 0; i < loopargs_len; i++) {
3134 loopargs[i].ecdsa[testnum] =
3135 EC_KEY_new_by_curve_name(ec_curves[testnum].nid);
3136 if (loopargs[i].ecdsa[testnum] == NULL) {
3142 BIO_printf(bio_err, "ECDSA failure.\n");
3143 ERR_print_errors(bio_err);
3146 for (i = 0; i < loopargs_len; i++) {
3147 /* Perform ECDSA signature test */
3148 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
3149 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
3150 &loopargs[i].siglen,
3151 loopargs[i].ecdsa[testnum]);
3157 "ECDSA sign failure. No ECDSA sign will be done.\n");
3158 ERR_print_errors(bio_err);
3161 pkey_print_message("sign", "ecdsa",
3162 ecdsa_c[testnum][0],
3163 ec_curves[testnum].bits, seconds.ecdsa);
3165 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
3169 mr ? "+R5:%ld:%u:%.2f\n" :
3170 "%ld %u bits ECDSA signs in %.2fs \n",
3171 count, ec_curves[testnum].bits, d);
3172 ecdsa_results[testnum][0] = (double)count / d;
3176 /* Perform ECDSA verification test */
3177 for (i = 0; i < loopargs_len; i++) {
3178 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3180 loopargs[i].ecdsa[testnum]);
3186 "ECDSA verify failure. No ECDSA verify will be done.\n");
3187 ERR_print_errors(bio_err);
3188 ecdsa_doit[testnum] = 0;
3190 pkey_print_message("verify", "ecdsa",
3191 ecdsa_c[testnum][1],
3192 ec_curves[testnum].bits, seconds.ecdsa);
3194 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
3197 mr ? "+R6:%ld:%u:%.2f\n"
3198 : "%ld %u bits ECDSA verify in %.2fs\n",
3199 count, ec_curves[testnum].bits, d);
3200 ecdsa_results[testnum][1] = (double)count / d;
3203 if (rsa_count <= 1) {
3204 /* if longer than 10s, don't do any more */
3205 stop_it(ecdsa_doit, testnum);
3211 for (testnum = 0; testnum < EC_NUM; testnum++) {
3212 int ecdh_checks = 1;
3214 if (!ecdh_doit[testnum])
3217 for (i = 0; i < loopargs_len; i++) {
3218 EVP_PKEY_CTX *kctx = NULL;
3219 EVP_PKEY_CTX *test_ctx = NULL;
3220 EVP_PKEY_CTX *ctx = NULL;
3221 EVP_PKEY *key_A = NULL;
3222 EVP_PKEY *key_B = NULL;
3226 /* Ensure that the error queue is empty */
3227 if (ERR_peek_error()) {
3229 "WARNING: the error queue contains previous unhandled errors.\n");
3230 ERR_print_errors(bio_err);
3233 /* Let's try to create a ctx directly from the NID: this works for
3234 * curves like Curve25519 that are not implemented through the low
3235 * level EC interface.
3236 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
3237 * then we set the curve by NID before deriving the actual keygen
3238 * ctx for that specific curve. */
3239 kctx = EVP_PKEY_CTX_new_id(ec_curves[testnum].nid, NULL); /* keygen ctx from NID */
3241 EVP_PKEY_CTX *pctx = NULL;
3242 EVP_PKEY *params = NULL;
3244 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
3245 * "int_ctx_new:unsupported algorithm" error was added to the
3247 * We remove it from the error queue as we are handling it. */
3248 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
3249 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
3250 /* check that the error origin matches */
3251 ERR_GET_LIB(error) == ERR_LIB_EVP &&
3252 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
3253 ERR_get_error(); /* pop error from queue */
3254 if (ERR_peek_error()) {
3256 "Unhandled error in the error queue during ECDH init.\n");
3257 ERR_print_errors(bio_err);
3262 /* Create the context for parameter generation */
3263 if (!(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
3264 /* Initialise the parameter generation */
3265 !EVP_PKEY_paramgen_init(pctx) ||
3266 /* Set the curve by NID */
3267 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3270 /* Create the parameter object params */
3271 !EVP_PKEY_paramgen(pctx, ¶ms)) {
3273 BIO_printf(bio_err, "ECDH EC params init failure.\n");
3274 ERR_print_errors(bio_err);
3278 /* Create the context for the key generation */
3279 kctx = EVP_PKEY_CTX_new(params, NULL);
3281 EVP_PKEY_free(params);
3283 EVP_PKEY_CTX_free(pctx);
3286 if (kctx == NULL || /* keygen ctx is not null */
3287 EVP_PKEY_keygen_init(kctx) <= 0/* init keygen ctx */ ) {
3289 BIO_printf(bio_err, "ECDH keygen failure.\n");
3290 ERR_print_errors(bio_err);
3295 if (EVP_PKEY_keygen(kctx, &key_A) <= 0 || /* generate secret key A */
3296 EVP_PKEY_keygen(kctx, &key_B) <= 0 || /* generate secret key B */
3297 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
3298 EVP_PKEY_derive_init(ctx) <= 0 || /* init derivation ctx */
3299 EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 || /* set peer pubkey in ctx */
3300 EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 || /* determine max length */
3301 outlen == 0 || /* ensure outlen is a valid size */
3302 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
3304 BIO_printf(bio_err, "ECDH key generation failure.\n");
3305 ERR_print_errors(bio_err);
3310 /* Here we perform a test run, comparing the output of a*B and b*A;
3311 * we try this here and assume that further EVP_PKEY_derive calls
3312 * never fail, so we can skip checks in the actually benchmarked
3313 * code, for maximum performance. */
3314 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3315 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3316 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3317 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3318 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3319 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3320 test_outlen != outlen /* compare output length */ ) {
3322 BIO_printf(bio_err, "ECDH computation failure.\n");
3323 ERR_print_errors(bio_err);
3328 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3329 if (CRYPTO_memcmp(loopargs[i].secret_a,
3330 loopargs[i].secret_b, outlen)) {
3332 BIO_printf(bio_err, "ECDH computations don't match.\n");
3333 ERR_print_errors(bio_err);
3338 loopargs[i].ecdh_ctx[testnum] = ctx;
3339 loopargs[i].outlen[testnum] = outlen;
3341 EVP_PKEY_free(key_A);
3342 EVP_PKEY_free(key_B);
3343 EVP_PKEY_CTX_free(kctx);
3345 EVP_PKEY_CTX_free(test_ctx);
3348 if (ecdh_checks != 0) {
3349 pkey_print_message("", "ecdh",
3351 ec_curves[testnum].bits, seconds.ecdh);
3354 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3357 mr ? "+R7:%ld:%d:%.2f\n" :
3358 "%ld %u-bits ECDH ops in %.2fs\n", count,
3359 ec_curves[testnum].bits, d);
3360 ecdh_results[testnum][0] = (double)count / d;
3364 if (rsa_count <= 1) {
3365 /* if longer than 10s, don't do any more */
3366 stop_it(ecdh_doit, testnum);
3370 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3372 EVP_PKEY *ed_pkey = NULL;
3373 EVP_PKEY_CTX *ed_pctx = NULL;
3375 if (!eddsa_doit[testnum])
3376 continue; /* Ignore Curve */
3377 for (i = 0; i < loopargs_len; i++) {
3378 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3379 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3384 if ((ed_pctx = EVP_PKEY_CTX_new_id(ed_curves[testnum].nid, NULL))
3386 || EVP_PKEY_keygen_init(ed_pctx) <= 0
3387 || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) {
3389 EVP_PKEY_CTX_free(ed_pctx);
3392 EVP_PKEY_CTX_free(ed_pctx);
3394 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3397 EVP_PKEY_free(ed_pkey);
3400 EVP_PKEY_free(ed_pkey);
3403 BIO_printf(bio_err, "EdDSA failure.\n");
3404 ERR_print_errors(bio_err);
3407 for (i = 0; i < loopargs_len; i++) {
3408 /* Perform EdDSA signature test */
3409 loopargs[i].sigsize = ed_curves[testnum].sigsize;
3410 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3411 loopargs[i].buf2, &loopargs[i].sigsize,
3412 loopargs[i].buf, 20);
3418 "EdDSA sign failure. No EdDSA sign will be done.\n");
3419 ERR_print_errors(bio_err);
3422 pkey_print_message("sign", ed_curves[testnum].name,
3423 eddsa_c[testnum][0],
3424 ed_curves[testnum].bits, seconds.eddsa);
3426 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3430 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3431 "%ld %u bits %s signs in %.2fs \n",
3432 count, ed_curves[testnum].bits,
3433 ed_curves[testnum].name, d);
3434 eddsa_results[testnum][0] = (double)count / d;
3438 /* Perform EdDSA verification test */
3439 for (i = 0; i < loopargs_len; i++) {
3440 st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
3441 loopargs[i].buf2, loopargs[i].sigsize,
3442 loopargs[i].buf, 20);
3448 "EdDSA verify failure. No EdDSA verify will be done.\n");
3449 ERR_print_errors(bio_err);
3450 eddsa_doit[testnum] = 0;
3452 pkey_print_message("verify", ed_curves[testnum].name,
3453 eddsa_c[testnum][1],
3454 ed_curves[testnum].bits, seconds.eddsa);
3456 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3459 mr ? "+R9:%ld:%u:%s:%.2f\n"
3460 : "%ld %u bits %s verify in %.2fs\n",
3461 count, ed_curves[testnum].bits,
3462 ed_curves[testnum].name, d);
3463 eddsa_results[testnum][1] = (double)count / d;
3466 if (rsa_count <= 1) {
3467 /* if longer than 10s, don't do any more */
3468 stop_it(eddsa_doit, testnum);
3473 # ifndef OPENSSL_NO_SM2
3474 for (testnum = 0; testnum < SM2_NUM; testnum++) {
3476 EVP_PKEY *sm2_pkey = NULL;
3478 if (!sm2_doit[testnum])
3479 continue; /* Ignore Curve */
3480 /* Init signing and verification */
3481 for (i = 0; i < loopargs_len; i++) {
3482 EVP_PKEY_CTX *sm2_pctx = NULL;
3483 EVP_PKEY_CTX *sm2_vfy_pctx = NULL;
3484 EVP_PKEY_CTX *pctx = NULL;
3487 loopargs[i].sm2_ctx[testnum] = EVP_MD_CTX_new();
3488 loopargs[i].sm2_vfy_ctx[testnum] = EVP_MD_CTX_new();
3489 if (loopargs[i].sm2_ctx[testnum] == NULL
3490 || loopargs[i].sm2_vfy_ctx[testnum] == NULL)
3493 /* SM2 keys are generated as normal EC keys with a special curve */
3494 st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) == NULL
3495 || EVP_PKEY_keygen_init(pctx) <= 0
3496 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3497 sm2_curves[testnum].nid) <= 0
3498 || EVP_PKEY_keygen(pctx, &sm2_pkey) <= 0);
3499 EVP_PKEY_CTX_free(pctx);
3503 st = 0; /* set back to zero */
3504 /* attach it sooner to rely on main final cleanup */
3505 loopargs[i].sm2_pkey[testnum] = sm2_pkey;
3506 loopargs[i].sigsize = EVP_PKEY_size(sm2_pkey);
3508 sm2_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3509 sm2_vfy_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3510 if (sm2_pctx == NULL || sm2_vfy_pctx == NULL) {
3511 EVP_PKEY_CTX_free(sm2_vfy_pctx);
3515 /* attach them directly to respective ctx */
3516 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_ctx[testnum], sm2_pctx);
3517 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_vfy_ctx[testnum], sm2_vfy_pctx);
3520 * No need to allow user to set an explicit ID here, just use
3521 * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D.
3523 if (EVP_PKEY_CTX_set1_id(sm2_pctx, SM2_ID, SM2_ID_LEN) != 1
3524 || EVP_PKEY_CTX_set1_id(sm2_vfy_pctx, SM2_ID, SM2_ID_LEN) != 1)
3527 if (!EVP_DigestSignInit(loopargs[i].sm2_ctx[testnum], NULL,
3528 EVP_sm3(), NULL, sm2_pkey))
3530 if (!EVP_DigestVerifyInit(loopargs[i].sm2_vfy_ctx[testnum], NULL,
3531 EVP_sm3(), NULL, sm2_pkey))
3533 st = 1; /* mark loop as succeeded */
3536 BIO_printf(bio_err, "SM2 init failure.\n");
3537 ERR_print_errors(bio_err);
3540 for (i = 0; i < loopargs_len; i++) {
3541 size_t sm2_sigsize = loopargs[i].sigsize;
3543 /* Perform SM2 signature test */
3544 st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum],
3545 loopargs[i].buf2, &sm2_sigsize,
3546 loopargs[i].buf, 20);
3552 "SM2 sign failure. No SM2 sign will be done.\n");
3553 ERR_print_errors(bio_err);
3556 pkey_print_message("sign", sm2_curves[testnum].name,
3558 sm2_curves[testnum].bits, seconds.sm2);
3560 count = run_benchmark(async_jobs, SM2_sign_loop, loopargs);
3564 mr ? "+R10:%ld:%u:%s:%.2f\n" :
3565 "%ld %u bits %s signs in %.2fs \n",
3566 count, sm2_curves[testnum].bits,
3567 sm2_curves[testnum].name, d);
3568 sm2_results[testnum][0] = (double)count / d;
3572 /* Perform SM2 verification test */
3573 for (i = 0; i < loopargs_len; i++) {
3574 st = EVP_DigestVerify(loopargs[i].sm2_vfy_ctx[testnum],
3575 loopargs[i].buf2, loopargs[i].sigsize,
3576 loopargs[i].buf, 20);
3582 "SM2 verify failure. No SM2 verify will be done.\n");
3583 ERR_print_errors(bio_err);
3584 sm2_doit[testnum] = 0;
3586 pkey_print_message("verify", sm2_curves[testnum].name,
3588 sm2_curves[testnum].bits, seconds.sm2);
3590 count = run_benchmark(async_jobs, SM2_verify_loop, loopargs);
3593 mr ? "+R11:%ld:%u:%s:%.2f\n"
3594 : "%ld %u bits %s verify in %.2fs\n",
3595 count, sm2_curves[testnum].bits,
3596 sm2_curves[testnum].name, d);
3597 sm2_results[testnum][1] = (double)count / d;
3600 if (rsa_count <= 1) {
3601 /* if longer than 10s, don't do any more */
3602 for (testnum++; testnum < SM2_NUM; testnum++)
3603 sm2_doit[testnum] = 0;
3607 # endif /* OPENSSL_NO_SM2 */
3608 #endif /* OPENSSL_NO_EC */
3610 #ifndef OPENSSL_NO_DH
3611 for (testnum = 0; testnum < FFDH_NUM; testnum++) {
3612 int ffdh_checks = 1;
3614 if (!ffdh_doit[testnum])
3617 for (i = 0; i < loopargs_len; i++) {
3618 EVP_PKEY *pkey_A = NULL;
3619 EVP_PKEY *pkey_B = NULL;
3620 EVP_PKEY_CTX *ffdh_ctx = NULL;
3621 EVP_PKEY_CTX *test_ctx = NULL;
3625 /* Ensure that the error queue is empty */
3626 if (ERR_peek_error()) {
3628 "WARNING: the error queue contains previous unhandled errors.\n");
3629 ERR_print_errors(bio_err);
3632 pkey_A = EVP_PKEY_new();
3634 BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n");
3635 ERR_print_errors(bio_err);
3640 pkey_B = EVP_PKEY_new();
3642 BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n");
3643 ERR_print_errors(bio_err);
3649 ffdh_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DH, NULL);
3651 BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
3652 ERR_print_errors(bio_err);
3658 if (EVP_PKEY_keygen_init(ffdh_ctx) <= 0) {
3659 BIO_printf(bio_err, "Error while initialising EVP_PKEY_CTX.\n");
3660 ERR_print_errors(bio_err);
3665 if (EVP_PKEY_CTX_set_dh_nid(ffdh_ctx, ffdh_params[testnum].nid) <= 0) {
3666 BIO_printf(bio_err, "Error setting DH key size for keygen.\n");
3667 ERR_print_errors(bio_err);
3673 if (EVP_PKEY_keygen(ffdh_ctx, &pkey_A) <= 0 ||
3674 EVP_PKEY_keygen(ffdh_ctx, &pkey_B) <= 0) {
3675 BIO_printf(bio_err, "FFDH key generation failure.\n");
3676 ERR_print_errors(bio_err);
3682 EVP_PKEY_CTX_free(ffdh_ctx);
3684 /* check if the derivation works correctly both ways so that
3685 * we know if future derive calls will fail, and we can skip
3686 * error checking in benchmarked code */
3687 ffdh_ctx = EVP_PKEY_CTX_new(pkey_A, NULL);
3689 BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
3690 ERR_print_errors(bio_err);
3695 if (EVP_PKEY_derive_init(ffdh_ctx) <= 0) {
3696 BIO_printf(bio_err, "FFDH derivation context init failure.\n");
3697 ERR_print_errors(bio_err);
3702 if (EVP_PKEY_derive_set_peer(ffdh_ctx, pkey_B) <= 0) {
3703 BIO_printf(bio_err, "Assigning peer key for derivation failed.\n");
3704 ERR_print_errors(bio_err);
3709 if (EVP_PKEY_derive(ffdh_ctx, NULL, &secret_size) <= 0) {
3710 BIO_printf(bio_err, "Checking size of shared secret failed.\n");
3711 ERR_print_errors(bio_err);
3716 if (secret_size > MAX_FFDH_SIZE) {
3717 BIO_printf(bio_err, "Assertion failure: shared secret too large.\n");
3722 if (EVP_PKEY_derive(ffdh_ctx,
3723 loopargs[i].secret_ff_a,
3724 &secret_size) <= 0) {
3725 BIO_printf(bio_err, "Shared secret derive failure.\n");
3726 ERR_print_errors(bio_err);
3731 /* Now check from side B */
3732 test_ctx = EVP_PKEY_CTX_new(pkey_B, NULL);
3734 BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
3735 ERR_print_errors(bio_err);
3740 if (!EVP_PKEY_derive_init(test_ctx) ||
3741 !EVP_PKEY_derive_set_peer(test_ctx, pkey_A) ||
3742 !EVP_PKEY_derive(test_ctx, NULL, &test_out) ||
3743 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_ff_b, &test_out) ||
3744 test_out != secret_size) {
3745 BIO_printf(bio_err, "FFDH computation failure.\n");
3751 /* compare the computed secrets */
3752 if (CRYPTO_memcmp(loopargs[i].secret_ff_a,
3753 loopargs[i].secret_ff_b, secret_size)) {
3754 BIO_printf(bio_err, "FFDH computations don't match.\n");
3755 ERR_print_errors(bio_err);
3761 loopargs[i].ffdh_ctx[testnum] = ffdh_ctx;
3763 EVP_PKEY_free(pkey_A);
3765 EVP_PKEY_free(pkey_B);
3767 EVP_PKEY_CTX_free(test_ctx);
3770 if (ffdh_checks != 0) {
3771 pkey_print_message("", "ffdh", ffdh_c[testnum][0],
3772 ffdh_params[testnum].bits, seconds.ffdh);
3775 run_benchmark(async_jobs, FFDH_derive_key_loop, loopargs);
3778 mr ? "+R12:%ld:%d:%.2f\n" :
3779 "%ld %u-bits FFDH ops in %.2fs\n", count,
3780 ffdh_params[testnum].bits, d);
3781 ffdh_results[testnum][0] = (double)count / d;
3784 if (rsa_count <= 1) {
3785 /* if longer than 10s, don't do any more */
3786 stop_it(ffdh_doit, testnum);
3789 #endif /* OPENSSL_NO_DH */
3794 printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
3795 printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3797 printf("%s ", BN_options());
3798 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3799 printf("%s ", MD2_options());
3801 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3802 printf("%s ", RC4_options());
3804 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3805 printf("%s ", DES_options());
3807 #ifndef OPENSSL_NO_DEPRECATED_3_0
3808 printf("%s ", AES_options());
3810 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3811 printf("%s ", IDEA_options());
3813 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3814 printf("%s ", BF_options());
3816 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3817 printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
3825 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3828 for (testnum = 0; testnum < size_num; testnum++)
3829 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3833 for (k = 0; k < ALGOR_NUM; k++) {
3837 printf("+F:%u:%s", k, names[k]);
3839 printf("%-13s", names[k]);
3840 for (testnum = 0; testnum < size_num; testnum++) {
3841 if (results[k][testnum] > 10000 && !mr)
3842 printf(" %11.2fk", results[k][testnum] / 1e3);
3844 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3848 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3850 for (k = 0; k < RSA_NUM; k++) {
3853 if (testnum && !mr) {
3854 printf("%18ssign verify sign/s verify/s\n", " ");
3858 printf("+F2:%u:%u:%f:%f\n",
3859 k, rsa_keys[k].bits, rsa_results[k][0], rsa_results[k][1]);
3861 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3862 rsa_keys[k].bits, 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3863 rsa_results[k][0], rsa_results[k][1]);
3866 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3868 for (k = 0; k < DSA_NUM; k++) {
3871 if (testnum && !mr) {
3872 printf("%18ssign verify sign/s verify/s\n", " ");
3876 printf("+F3:%u:%u:%f:%f\n",
3877 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3879 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3880 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3881 dsa_results[k][0], dsa_results[k][1]);
3884 #ifndef OPENSSL_NO_EC
3886 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3889 if (testnum && !mr) {
3890 printf("%30ssign verify sign/s verify/s\n", " ");
3895 printf("+F4:%u:%u:%f:%f\n",
3896 k, ec_curves[k].bits,
3897 ecdsa_results[k][0], ecdsa_results[k][1]);
3899 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3900 ec_curves[k].bits, ec_curves[k].name,
3901 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3902 ecdsa_results[k][0], ecdsa_results[k][1]);
3906 for (k = 0; k < EC_NUM; k++) {
3909 if (testnum && !mr) {
3910 printf("%30sop op/s\n", " ");
3914 printf("+F5:%u:%u:%f:%f\n",
3915 k, ec_curves[k].bits,
3916 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3919 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3920 ec_curves[k].bits, ec_curves[k].name,
3921 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3925 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
3928 if (testnum && !mr) {
3929 printf("%30ssign verify sign/s verify/s\n", " ");
3934 printf("+F6:%u:%u:%s:%f:%f\n",
3935 k, ed_curves[k].bits, ed_curves[k].name,
3936 eddsa_results[k][0], eddsa_results[k][1]);
3938 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3939 ed_curves[k].bits, ed_curves[k].name,
3940 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
3941 eddsa_results[k][0], eddsa_results[k][1]);
3944 # ifndef OPENSSL_NO_SM2
3946 for (k = 0; k < OSSL_NELEM(sm2_doit); k++) {
3949 if (testnum && !mr) {
3950 printf("%30ssign verify sign/s verify/s\n", " ");
3955 printf("+F7:%u:%u:%s:%f:%f\n",
3956 k, sm2_curves[k].bits, sm2_curves[k].name,
3957 sm2_results[k][0], sm2_results[k][1]);
3959 printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3960 sm2_curves[k].bits, sm2_curves[k].name,
3961 1.0 / sm2_results[k][0], 1.0 / sm2_results[k][1],
3962 sm2_results[k][0], sm2_results[k][1]);
3965 #endif /* OPENSSL_NO_EC */
3966 #ifndef OPENSSL_NO_DH
3968 for (k = 0; k < FFDH_NUM; k++) {
3971 if (testnum && !mr) {
3972 printf("%23sop op/s\n", " ");
3976 printf("+F8:%u:%u:%f:%f\n",
3977 k, ffdh_params[k].bits,
3978 ffdh_results[k][0], 1.0 / ffdh_results[k][0]);
3981 printf("%4u bits ffdh %8.4fs %8.1f\n",
3982 ffdh_params[k].bits,
3983 1.0 / ffdh_results[k][0], ffdh_results[k][0]);
3985 #endif /* OPENSSL_NO_DH */
3990 ERR_print_errors(bio_err);
3991 for (i = 0; i < loopargs_len; i++) {
3992 OPENSSL_free(loopargs[i].buf_malloc);
3993 OPENSSL_free(loopargs[i].buf2_malloc);
3995 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3996 for (k = 0; k < RSA_NUM; k++)
3997 RSA_free(loopargs[i].rsa_key[k]);
3999 #ifndef OPENSSL_NO_DH
4000 OPENSSL_free(loopargs[i].secret_ff_a);
4001 OPENSSL_free(loopargs[i].secret_ff_b);
4002 for (k = 0; k < FFDH_NUM; k++) {
4003 EVP_PKEY_CTX_free(loopargs[i].ffdh_ctx[k]);
4006 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4007 for (k = 0; k < DSA_NUM; k++)
4008 DSA_free(loopargs[i].dsa_key[k]);
4010 #ifndef OPENSSL_NO_EC
4011 for (k = 0; k < ECDSA_NUM; k++)
4012 EC_KEY_free(loopargs[i].ecdsa[k]);
4013 for (k = 0; k < EC_NUM; k++)
4014 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
4015 for (k = 0; k < EdDSA_NUM; k++)
4016 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
4017 # ifndef OPENSSL_NO_SM2
4018 for (k = 0; k < SM2_NUM; k++) {
4019 EVP_PKEY_CTX *pctx = NULL;
4021 /* free signing ctx */
4022 if (loopargs[i].sm2_ctx[k] != NULL
4023 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_ctx[k])) != NULL)
4024 EVP_PKEY_CTX_free(pctx);
4025 EVP_MD_CTX_free(loopargs[i].sm2_ctx[k]);
4026 /* free verification ctx */
4027 if (loopargs[i].sm2_vfy_ctx[k] != NULL
4028 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_vfy_ctx[k])) != NULL)
4029 EVP_PKEY_CTX_free(pctx);
4030 EVP_MD_CTX_free(loopargs[i].sm2_vfy_ctx[k]);
4032 EVP_PKEY_free(loopargs[i].sm2_pkey[k]);
4035 OPENSSL_free(loopargs[i].secret_a);
4036 OPENSSL_free(loopargs[i].secret_b);
4039 #ifndef OPENSSL_NO_DEPRECATED_3_0
4040 OPENSSL_free(evp_hmac_name);
4042 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4043 OPENSSL_free(evp_cmac_name);
4046 if (async_jobs > 0) {
4047 for (i = 0; i < loopargs_len; i++)
4048 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
4052 ASYNC_cleanup_thread();
4054 OPENSSL_free(loopargs);
4059 static void print_message(const char *s, long num, int length, int tm)
4063 mr ? "+DT:%s:%d:%d\n"
4064 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
4065 (void)BIO_flush(bio_err);
4070 mr ? "+DN:%s:%ld:%d\n"
4071 : "Doing %s %ld times on %d size blocks: ", s, num, length);
4072 (void)BIO_flush(bio_err);
4076 static void pkey_print_message(const char *str, const char *str2, long num,
4077 unsigned int bits, int tm)
4081 mr ? "+DTP:%d:%s:%s:%d\n"
4082 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
4083 (void)BIO_flush(bio_err);
4088 mr ? "+DNP:%ld:%d:%s:%s\n"
4089 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
4090 (void)BIO_flush(bio_err);
4094 static void print_result(int alg, int run_no, int count, double time_used)
4097 BIO_printf(bio_err, "%s error!\n", names[alg]);
4098 ERR_print_errors(bio_err);
4099 /* exit(1); disable exit until default provider enabled */
4103 mr ? "+R:%d:%s:%f\n"
4104 : "%d %s's in %.2fs\n", count, names[alg], time_used);
4105 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
4109 static char *sstrsep(char **string, const char *delim)
4112 char *token = *string;
4117 memset(isdelim, 0, sizeof(isdelim));
4121 isdelim[(unsigned char)(*delim)] = 1;
4125 while (!isdelim[(unsigned char)(**string)]) {
4137 static int do_multi(int multi, int size_num)
4142 static char sep[] = ":";
4144 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
4145 for (n = 0; n < multi; ++n) {
4146 if (pipe(fd) == -1) {
4147 BIO_printf(bio_err, "pipe failure\n");
4151 (void)BIO_flush(bio_err);
4158 if (dup(fd[1]) == -1) {
4159 BIO_printf(bio_err, "dup failed\n");
4168 printf("Forked child %d\n", n);
4171 /* for now, assume the pipe is long enough to take all the output */
4172 for (n = 0; n < multi; ++n) {
4177 f = fdopen(fds[n], "r");
4178 while (fgets(buf, sizeof(buf), f)) {
4179 p = strchr(buf, '\n');
4182 if (buf[0] != '+') {
4184 "Don't understand line '%s' from child %d\n", buf,
4188 printf("Got: %s from %d\n", buf, n);
4189 if (strncmp(buf, "+F:", 3) == 0) {
4194 alg = atoi(sstrsep(&p, sep));
4196 for (j = 0; j < size_num; ++j)
4197 results[alg][j] += atof(sstrsep(&p, sep));
4199 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4200 else if (strncmp(buf, "+F2:", 4) == 0) {
4205 k = atoi(sstrsep(&p, sep));
4208 d = atof(sstrsep(&p, sep));
4209 rsa_results[k][0] += d;
4211 d = atof(sstrsep(&p, sep));
4212 rsa_results[k][1] += d;
4215 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4216 else if (strncmp(buf, "+F3:", 4) == 0) {
4221 k = atoi(sstrsep(&p, sep));
4224 d = atof(sstrsep(&p, sep));
4225 dsa_results[k][0] += d;
4227 d = atof(sstrsep(&p, sep));
4228 dsa_results[k][1] += d;
4231 # ifndef OPENSSL_NO_EC
4232 else if (strncmp(buf, "+F4:", 4) == 0) {
4237 k = atoi(sstrsep(&p, sep));
4240 d = atof(sstrsep(&p, sep));
4241 ecdsa_results[k][0] += d;
4243 d = atof(sstrsep(&p, sep));
4244 ecdsa_results[k][1] += d;
4245 } else if (strncmp(buf, "+F5:", 4) == 0) {
4250 k = atoi(sstrsep(&p, sep));
4253 d = atof(sstrsep(&p, sep));
4254 ecdh_results[k][0] += d;
4255 } else if (strncmp(buf, "+F6:", 4) == 0) {
4260 k = atoi(sstrsep(&p, sep));
4264 d = atof(sstrsep(&p, sep));
4265 eddsa_results[k][0] += d;
4267 d = atof(sstrsep(&p, sep));
4268 eddsa_results[k][1] += d;
4270 # ifndef OPENSSL_NO_SM2
4271 else if (strncmp(buf, "+F7:", 4) == 0) {
4276 k = atoi(sstrsep(&p, sep));
4280 d = atof(sstrsep(&p, sep));
4281 sm2_results[k][0] += d;
4283 d = atof(sstrsep(&p, sep));
4284 sm2_results[k][1] += d;
4286 # endif /* OPENSSL_NO_SM2 */
4287 # endif /* OPENSSL_NO_EC */
4288 # ifndef OPENSSL_NO_DH
4289 else if (strncmp(buf, "+F8:", 4) == 0) {
4294 k = atoi(sstrsep(&p, sep));
4297 d = atof(sstrsep(&p, sep));
4298 ffdh_results[k][0] += d;
4300 # endif /* OPENSSL_NO_DH */
4302 else if (strncmp(buf, "+H:", 3) == 0) {
4305 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
4316 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
4317 const openssl_speed_sec_t *seconds)
4319 static const int mblengths_list[] =
4320 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
4321 const int *mblengths = mblengths_list;
4322 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
4323 const char *alg_name;
4324 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
4325 EVP_CIPHER_CTX *ctx;
4328 if (lengths_single) {
4329 mblengths = &lengths_single;
4333 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
4334 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
4335 ctx = EVP_CIPHER_CTX_new();
4336 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
4338 keylen = EVP_CIPHER_CTX_key_length(ctx);
4339 key = app_malloc(keylen, "evp_cipher key");
4340 EVP_CIPHER_CTX_rand_key(ctx, key);
4341 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
4342 OPENSSL_clear_free(key, keylen);
4344 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
4345 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
4347 for (j = 0; j < num; j++) {
4348 print_message(alg_name, 0, mblengths[j], seconds->sym);
4350 for (count = 0; run && count < 0x7fffffff; count++) {
4351 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
4352 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
4353 size_t len = mblengths[j];
4356 memset(aad, 0, 8); /* avoid uninitialized values */
4357 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
4358 aad[9] = 3; /* version */
4360 aad[11] = 0; /* length */
4362 mb_param.out = NULL;
4365 mb_param.interleave = 8;
4367 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
4368 sizeof(mb_param), &mb_param);
4374 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
4375 sizeof(mb_param), &mb_param);
4379 RAND_bytes(out, 16);
4381 aad[11] = (unsigned char)(len >> 8);
4382 aad[12] = (unsigned char)(len);
4383 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
4384 EVP_AEAD_TLS1_AAD_LEN, aad);
4385 EVP_Cipher(ctx, out, inp, len + pad);
4389 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
4390 : "%d %s's in %.2fs\n", count, "evp", d);
4391 results[D_EVP][j] = ((double)count) / d * mblengths[j];
4395 fprintf(stdout, "+H");
4396 for (j = 0; j < num; j++)
4397 fprintf(stdout, ":%d", mblengths[j]);
4398 fprintf(stdout, "\n");
4399 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
4400 for (j = 0; j < num; j++)
4401 fprintf(stdout, ":%.2f", results[D_EVP][j]);
4402 fprintf(stdout, "\n");
4405 "The 'numbers' are in 1000s of bytes per second processed.\n");
4406 fprintf(stdout, "type ");
4407 for (j = 0; j < num; j++)
4408 fprintf(stdout, "%7d bytes", mblengths[j]);
4409 fprintf(stdout, "\n");
4410 fprintf(stdout, "%-24s", alg_name);
4412 for (j = 0; j < num; j++) {
4413 if (results[D_EVP][j] > 10000)
4414 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
4416 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
4418 fprintf(stdout, "\n");
4423 EVP_CIPHER_CTX_free(ctx);