2 * Copyright 1995-2021 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)
41 # if defined(OPENSSL_TANDEM_FLOSS)
42 # include <floss.h(floss_fork)>
50 #include <openssl/bn.h>
51 #ifndef OPENSSL_NO_DES
52 # include <openssl/des.h>
54 #ifndef OPENSSL_NO_DEPRECATED_3_0
55 #include <openssl/aes.h>
57 #ifndef OPENSSL_NO_CAMELLIA
58 # include <openssl/camellia.h>
60 #ifndef OPENSSL_NO_MD2
61 # include <openssl/md2.h>
63 #ifndef OPENSSL_NO_MDC2
64 # include <openssl/mdc2.h>
66 #ifndef OPENSSL_NO_MD4
67 # include <openssl/md4.h>
69 #ifndef OPENSSL_NO_MD5
70 # include <openssl/md5.h>
72 #include <openssl/hmac.h>
73 #ifndef OPENSSL_NO_CMAC
74 #include <openssl/cmac.h>
76 #include <openssl/sha.h>
77 #ifndef OPENSSL_NO_RMD160
78 # include <openssl/ripemd.h>
80 #ifndef OPENSSL_NO_WHIRLPOOL
81 # include <openssl/whrlpool.h>
83 #ifndef OPENSSL_NO_RC4
84 # include <openssl/rc4.h>
86 #ifndef OPENSSL_NO_RC5
87 # include <openssl/rc5.h>
89 #ifndef OPENSSL_NO_RC2
90 # include <openssl/rc2.h>
92 #ifndef OPENSSL_NO_IDEA
93 # include <openssl/idea.h>
95 #ifndef OPENSSL_NO_SEED
96 # include <openssl/seed.h>
99 # include <openssl/blowfish.h>
101 #ifndef OPENSSL_NO_CAST
102 # include <openssl/cast.h>
104 #ifndef OPENSSL_NO_DEPRECATED_3_0
105 # include <openssl/rsa.h>
106 # include "./testrsa.h"
108 #ifndef OPENSSL_NO_DH
109 # include <openssl/dh.h>
111 #include <openssl/x509.h>
112 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
113 # include <openssl/dsa.h>
114 # include "./testdsa.h"
116 #ifndef OPENSSL_NO_EC
117 # include <openssl/ec.h>
119 #include <openssl/modes.h>
122 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
135 #define MAX_MISALIGNMENT 63
136 #define MAX_ECDH_SIZE 256
138 #define MAX_FFDH_SIZE 1024
140 typedef struct openssl_speed_sec_st {
149 } openssl_speed_sec_t;
151 static volatile int run = 0;
153 static int mr = 0; /* machine-readeable output format to merge fork results */
154 static int usertime = 1;
156 static double Time_F(int s);
157 static void print_message(const char *s, long num, int length, int tm);
158 #if !defined(OPENSSL_NO_DEPRECATED_3_0) \
159 || !defined(OPENSSL_NO_DSA) \
160 || !defined(OPENSSL_NO_DH) \
161 || !defined(OPENSSL_NO_EC)
162 static void pkey_print_message(const char *str, const char *str2,
163 long num, unsigned int bits, int sec);
165 static void print_result(int alg, int run_no, int count, double time_used);
167 static int do_multi(int multi, int size_num);
170 static const int lengths_list[] = {
171 16, 64, 256, 1024, 8 * 1024, 16 * 1024
173 #define SIZE_NUM OSSL_NELEM(lengths_list)
174 static const int *lengths = lengths_list;
176 static const int aead_lengths_list[] = {
177 2, 31, 136, 1024, 8 * 1024, 16 * 1024
185 static void alarmed(int sig)
187 signal(SIGALRM, alarmed);
191 static double Time_F(int s)
193 double ret = app_tminterval(s, usertime);
199 #elif defined(_WIN32)
203 static unsigned int lapse;
204 static volatile unsigned int schlock;
205 static void alarm_win32(unsigned int secs)
210 # define alarm alarm_win32
212 static DWORD WINAPI sleepy(VOID * arg)
220 static double Time_F(int s)
227 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
229 DWORD err = GetLastError();
230 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
234 Sleep(0); /* scheduler spinlock */
235 ret = app_tminterval(s, usertime);
237 ret = app_tminterval(s, usertime);
239 TerminateThread(thr, 0);
246 static double Time_F(int s)
248 return app_tminterval(s, usertime);
252 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
253 const openssl_speed_sec_t *seconds);
255 static int opt_found(const char *name, unsigned int *result,
256 const OPT_PAIR pairs[], unsigned int nbelem)
260 for (idx = 0; idx < nbelem; ++idx, pairs++)
261 if (strcmp(name, pairs->name) == 0) {
262 *result = pairs->retval;
267 #define opt_found(value, pairs, result)\
268 opt_found(value, result, pairs, OSSL_NELEM(pairs))
270 typedef enum OPTION_choice {
271 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
272 OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
273 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM, OPT_PROV_ENUM,
274 OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC
277 const OPTIONS speed_options[] = {
278 {OPT_HELP_STR, 1, '-', "Usage: %s [options] [algorithm...]\n"},
280 OPT_SECTION("General"),
281 {"help", OPT_HELP, '-', "Display this summary"},
283 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
284 {"mr", OPT_MR, '-', "Produce machine readable output"},
286 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
288 #ifndef OPENSSL_NO_ASYNC
289 {"async_jobs", OPT_ASYNCJOBS, 'p',
290 "Enable async mode and start specified number of jobs"},
292 #ifndef OPENSSL_NO_ENGINE
293 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
295 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
297 OPT_SECTION("Selection"),
298 {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
299 #ifndef OPENSSL_NO_DEPRECATED_3_0
300 {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"},
302 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
303 {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"},
305 {"decrypt", OPT_DECRYPT, '-',
306 "Time decryption instead of encryption (only EVP)"},
307 {"aead", OPT_AEAD, '-',
308 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
310 OPT_SECTION("Timing"),
311 {"elapsed", OPT_ELAPSED, '-',
312 "Use wall-clock time instead of CPU user time as divisor"},
313 {"seconds", OPT_SECONDS, 'p',
314 "Run benchmarks for specified amount of seconds"},
315 {"bytes", OPT_BYTES, 'p',
316 "Run [non-PKI] benchmarks on custom-sized buffer"},
317 {"misalign", OPT_MISALIGN, 'p',
318 "Use specified offset to mis-align buffers"},
324 {"algorithm", 0, 0, "Algorithm(s) to test (optional; otherwise tests all)"},
329 D_MD2, D_MDC2, D_MD4, D_MD5 , D_HMAC, D_SHA1, D_RMD160, D_RC4,
330 D_CBC_DES, D_EDE3_DES, D_CBC_IDEA, D_CBC_SEED,
331 D_CBC_RC2, D_CBC_RC5, D_CBC_BF, D_CBC_CAST,
332 D_CBC_128_AES, D_CBC_192_AES, D_CBC_256_AES,
333 D_CBC_128_CML, D_CBC_192_CML, D_CBC_256_CML,
334 D_EVP, D_SHA256, D_SHA512, D_WHIRLPOOL,
335 D_IGE_128_AES, D_IGE_192_AES, D_IGE_256_AES,
336 D_GHASH, D_RAND, D_EVP_HMAC, D_EVP_CMAC, ALGOR_NUM
338 /* name of algorithms to test. MUST BE KEEP IN SYNC with above enum ! */
339 static const char *names[ALGOR_NUM] = {
340 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
341 "des cbc", "des ede3", "idea cbc", "seed cbc",
342 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
343 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
344 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
345 "evp", "sha256", "sha512", "whirlpool",
346 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
347 "rand", "hmac", "cmac"
350 /* list of configured algorithm (remaining), with some few alias */
351 static const OPT_PAIR doit_choices[] = {
352 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
355 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
358 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
361 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
363 # ifndef OPENSSL_NO_DEPRECATED_3_0
367 #ifndef OPENSSL_NO_DEPRECATED_3_0
369 {"sha256", D_SHA256},
370 {"sha512", D_SHA512},
372 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
373 {"whirlpool", D_WHIRLPOOL},
375 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
376 {"ripemd", D_RMD160},
377 {"rmd160", D_RMD160},
378 {"ripemd160", D_RMD160},
380 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
383 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
384 {"des-cbc", D_CBC_DES},
385 {"des-ede3", D_EDE3_DES},
387 #ifndef OPENSSL_NO_DEPRECATED_3_0
388 {"aes-128-cbc", D_CBC_128_AES},
389 {"aes-192-cbc", D_CBC_192_AES},
390 {"aes-256-cbc", D_CBC_256_AES},
391 {"aes-128-ige", D_IGE_128_AES},
392 {"aes-192-ige", D_IGE_192_AES},
393 {"aes-256-ige", D_IGE_256_AES},
395 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
396 {"rc2-cbc", D_CBC_RC2},
399 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
400 {"rc5-cbc", D_CBC_RC5},
403 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
404 {"idea-cbc", D_CBC_IDEA},
405 {"idea", D_CBC_IDEA},
407 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
408 {"seed-cbc", D_CBC_SEED},
409 {"seed", D_CBC_SEED},
411 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
412 {"bf-cbc", D_CBC_BF},
413 {"blowfish", D_CBC_BF},
416 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
417 {"cast-cbc", D_CBC_CAST},
418 {"cast", D_CBC_CAST},
419 {"cast5", D_CBC_CAST},
425 static double results[ALGOR_NUM][SIZE_NUM];
427 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
428 enum { R_DSA_512, R_DSA_1024, R_DSA_2048, DSA_NUM };
429 static const OPT_PAIR dsa_choices[DSA_NUM] = {
430 {"dsa512", R_DSA_512},
431 {"dsa1024", R_DSA_1024},
432 {"dsa2048", R_DSA_2048}
434 static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
435 #endif /* OPENSSL_NO_DSA */
437 #ifndef OPENSSL_NO_DEPRECATED_3_0
439 R_RSA_512, R_RSA_1024, R_RSA_2048, R_RSA_3072, R_RSA_4096, R_RSA_7680,
442 static const OPT_PAIR rsa_choices[RSA_NUM] = {
443 {"rsa512", R_RSA_512},
444 {"rsa1024", R_RSA_1024},
445 {"rsa2048", R_RSA_2048},
446 {"rsa3072", R_RSA_3072},
447 {"rsa4096", R_RSA_4096},
448 {"rsa7680", R_RSA_7680},
449 {"rsa15360", R_RSA_15360}
452 static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
453 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
455 #ifndef OPENSSL_NO_DH
457 R_FFDH_2048, R_FFDH_3072, R_FFDH_4096, R_FFDH_6144, R_FFDH_8192, FFDH_NUM
460 static const OPT_PAIR ffdh_choices[FFDH_NUM] = {
461 {"ffdh2048", R_FFDH_2048},
462 {"ffdh3072", R_FFDH_3072},
463 {"ffdh4096", R_FFDH_4096},
464 {"ffdh6144", R_FFDH_6144},
465 {"ffdh8192", R_FFDH_8192},
468 static double ffdh_results[FFDH_NUM][1]; /* 1 op: derivation */
469 #endif /* OPENSSL_NO_DH */
471 #ifndef OPENSSL_NO_EC
473 R_EC_P160, R_EC_P192, R_EC_P224, R_EC_P256, R_EC_P384, R_EC_P521,
474 # ifndef OPENSSL_NO_EC2M
475 R_EC_K163, R_EC_K233, R_EC_K283, R_EC_K409, R_EC_K571,
476 R_EC_B163, R_EC_B233, R_EC_B283, R_EC_B409, R_EC_B571,
478 R_EC_BRP256R1, R_EC_BRP256T1, R_EC_BRP384R1, R_EC_BRP384T1,
479 R_EC_BRP512R1, R_EC_BRP512T1, ECDSA_NUM
481 /* list of ecdsa curves */
482 static const OPT_PAIR ecdsa_choices[ECDSA_NUM] = {
483 {"ecdsap160", R_EC_P160},
484 {"ecdsap192", R_EC_P192},
485 {"ecdsap224", R_EC_P224},
486 {"ecdsap256", R_EC_P256},
487 {"ecdsap384", R_EC_P384},
488 {"ecdsap521", R_EC_P521},
489 # ifndef OPENSSL_NO_EC2M
490 {"ecdsak163", R_EC_K163},
491 {"ecdsak233", R_EC_K233},
492 {"ecdsak283", R_EC_K283},
493 {"ecdsak409", R_EC_K409},
494 {"ecdsak571", R_EC_K571},
495 {"ecdsab163", R_EC_B163},
496 {"ecdsab233", R_EC_B233},
497 {"ecdsab283", R_EC_B283},
498 {"ecdsab409", R_EC_B409},
499 {"ecdsab571", R_EC_B571},
501 {"ecdsabrp256r1", R_EC_BRP256R1},
502 {"ecdsabrp256t1", R_EC_BRP256T1},
503 {"ecdsabrp384r1", R_EC_BRP384R1},
504 {"ecdsabrp384t1", R_EC_BRP384T1},
505 {"ecdsabrp512r1", R_EC_BRP512R1},
506 {"ecdsabrp512t1", R_EC_BRP512T1}
508 enum { R_EC_X25519 = ECDSA_NUM, R_EC_X448, EC_NUM };
509 /* list of ecdh curves, extension of |ecdsa_choices| list above */
510 static const OPT_PAIR ecdh_choices[EC_NUM] = {
511 {"ecdhp160", R_EC_P160},
512 {"ecdhp192", R_EC_P192},
513 {"ecdhp224", R_EC_P224},
514 {"ecdhp256", R_EC_P256},
515 {"ecdhp384", R_EC_P384},
516 {"ecdhp521", R_EC_P521},
517 # ifndef OPENSSL_NO_EC2M
518 {"ecdhk163", R_EC_K163},
519 {"ecdhk233", R_EC_K233},
520 {"ecdhk283", R_EC_K283},
521 {"ecdhk409", R_EC_K409},
522 {"ecdhk571", R_EC_K571},
523 {"ecdhb163", R_EC_B163},
524 {"ecdhb233", R_EC_B233},
525 {"ecdhb283", R_EC_B283},
526 {"ecdhb409", R_EC_B409},
527 {"ecdhb571", R_EC_B571},
529 {"ecdhbrp256r1", R_EC_BRP256R1},
530 {"ecdhbrp256t1", R_EC_BRP256T1},
531 {"ecdhbrp384r1", R_EC_BRP384R1},
532 {"ecdhbrp384t1", R_EC_BRP384T1},
533 {"ecdhbrp512r1", R_EC_BRP512R1},
534 {"ecdhbrp512t1", R_EC_BRP512T1},
535 {"ecdhx25519", R_EC_X25519},
536 {"ecdhx448", R_EC_X448}
539 static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
540 static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
542 enum { R_EC_Ed25519, R_EC_Ed448, EdDSA_NUM };
543 static const OPT_PAIR eddsa_choices[EdDSA_NUM] = {
544 {"ed25519", R_EC_Ed25519},
545 {"ed448", R_EC_Ed448}
548 static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
550 # ifndef OPENSSL_NO_SM2
551 enum { R_EC_CURVESM2, SM2_NUM };
552 static const OPT_PAIR sm2_choices[SM2_NUM] = {
553 {"curveSM2", R_EC_CURVESM2}
555 # define SM2_ID "TLSv1.3+GM+Cipher+Suite"
556 # define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1
557 static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */
558 # endif /* OPENSSL_NO_SM2 */
559 #endif /* OPENSSL_NO_EC */
562 # define COND(d) (count < (d))
563 # define COUNT(d) (d)
565 # define COND(unused_cond) (run && count<0x7fffffff)
566 # define COUNT(d) (count)
569 typedef struct loopargs_st {
570 ASYNC_JOB *inprogress_job;
571 ASYNC_WAIT_CTX *wait_ctx;
574 unsigned char *buf_malloc;
575 unsigned char *buf2_malloc;
579 #ifndef OPENSSL_NO_DEPRECATED_3_0
580 RSA *rsa_key[RSA_NUM];
582 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
583 DSA *dsa_key[DSA_NUM];
585 #ifndef OPENSSL_NO_EC
586 # ifndef OPENSSL_NO_DEPRECATED_3_0
587 EC_KEY *ecdsa[ECDSA_NUM];
589 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
590 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
591 EVP_MD_CTX *eddsa_ctx2[EdDSA_NUM];
592 # ifndef OPENSSL_NO_SM2
593 EVP_MD_CTX *sm2_ctx[SM2_NUM];
594 EVP_MD_CTX *sm2_vfy_ctx[SM2_NUM];
595 EVP_PKEY *sm2_pkey[SM2_NUM];
597 unsigned char *secret_a;
598 unsigned char *secret_b;
599 size_t outlen[EC_NUM];
601 #ifndef OPENSSL_NO_DH
602 EVP_PKEY_CTX *ffdh_ctx[FFDH_NUM];
603 unsigned char *secret_ff_a;
604 unsigned char *secret_ff_b;
607 #ifndef OPENSSL_NO_DEPRECATED_3_0
610 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
613 GCM128_CONTEXT *gcm_ctx;
615 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
616 loopargs_t * loopargs);
618 static unsigned int testnum;
620 /* Nb of iterations to do per algorithm and key-size */
621 static long c[ALGOR_NUM][SIZE_NUM];
623 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
624 static int EVP_Digest_MD2_loop(void *args)
626 loopargs_t *tempargs = *(loopargs_t **) args;
627 unsigned char *buf = tempargs->buf;
628 unsigned char md2[MD2_DIGEST_LENGTH];
631 for (count = 0; COND(c[D_MD2][testnum]); count++) {
632 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
640 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
641 static int EVP_Digest_MDC2_loop(void *args)
643 loopargs_t *tempargs = *(loopargs_t **) args;
644 unsigned char *buf = tempargs->buf;
645 unsigned char mdc2[MDC2_DIGEST_LENGTH];
648 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
649 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
657 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
658 static int EVP_Digest_MD4_loop(void *args)
660 loopargs_t *tempargs = *(loopargs_t **) args;
661 unsigned char *buf = tempargs->buf;
662 unsigned char md4[MD4_DIGEST_LENGTH];
665 for (count = 0; COND(c[D_MD4][testnum]); count++) {
666 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
674 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
675 static int MD5_loop(void *args)
677 loopargs_t *tempargs = *(loopargs_t **) args;
678 unsigned char *buf = tempargs->buf;
679 unsigned char md5[MD5_DIGEST_LENGTH];
681 for (count = 0; COND(c[D_MD5][testnum]); count++)
682 MD5(buf, lengths[testnum], md5);
686 # ifndef OPENSSL_NO_DEPRECATED_3_0
687 static int HMAC_loop(void *args)
689 loopargs_t *tempargs = *(loopargs_t **) args;
690 unsigned char *buf = tempargs->buf;
691 HMAC_CTX *hctx = tempargs->hctx;
692 unsigned char hmac[MD5_DIGEST_LENGTH];
695 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
696 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
697 HMAC_Update(hctx, buf, lengths[testnum]);
698 HMAC_Final(hctx, hmac, NULL);
705 #ifndef OPENSSL_NO_DEPRECATED_3_0
706 static int SHA1_loop(void *args)
708 loopargs_t *tempargs = *(loopargs_t **) args;
709 unsigned char *buf = tempargs->buf;
710 unsigned char sha[SHA_DIGEST_LENGTH];
712 for (count = 0; COND(c[D_SHA1][testnum]); count++)
713 SHA1(buf, lengths[testnum], sha);
717 static int SHA256_loop(void *args)
719 loopargs_t *tempargs = *(loopargs_t **) args;
720 unsigned char *buf = tempargs->buf;
721 unsigned char sha256[SHA256_DIGEST_LENGTH];
723 for (count = 0; COND(c[D_SHA256][testnum]); count++)
724 SHA256(buf, lengths[testnum], sha256);
728 static int SHA512_loop(void *args)
730 loopargs_t *tempargs = *(loopargs_t **) args;
731 unsigned char *buf = tempargs->buf;
732 unsigned char sha512[SHA512_DIGEST_LENGTH];
734 for (count = 0; COND(c[D_SHA512][testnum]); count++)
735 SHA512(buf, lengths[testnum], sha512);
740 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
741 static int WHIRLPOOL_loop(void *args)
743 loopargs_t *tempargs = *(loopargs_t **) args;
744 unsigned char *buf = tempargs->buf;
745 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
747 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
748 WHIRLPOOL(buf, lengths[testnum], whirlpool);
753 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
754 static int EVP_Digest_RMD160_loop(void *args)
756 loopargs_t *tempargs = *(loopargs_t **) args;
757 unsigned char *buf = tempargs->buf;
758 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
760 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
761 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
762 NULL, EVP_ripemd160(), NULL))
769 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
770 static RC4_KEY rc4_ks;
771 static int RC4_loop(void *args)
773 loopargs_t *tempargs = *(loopargs_t **) args;
774 unsigned char *buf = tempargs->buf;
776 for (count = 0; COND(c[D_RC4][testnum]); count++)
777 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
782 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
783 static unsigned char DES_iv[8];
784 static DES_key_schedule sch[3];
785 static int DES_ncbc_encrypt_loop(void *args)
787 loopargs_t *tempargs = *(loopargs_t **) args;
788 unsigned char *buf = tempargs->buf;
790 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
791 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch[0],
792 &DES_iv, DES_ENCRYPT);
796 static int DES_ede3_cbc_encrypt_loop(void *args)
798 loopargs_t *tempargs = *(loopargs_t **) args;
799 unsigned char *buf = tempargs->buf;
801 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
802 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
803 &sch[0], &sch[1], &sch[2], &DES_iv, DES_ENCRYPT);
808 #define MAX_BLOCK_SIZE 128
810 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
812 #ifndef OPENSSL_NO_DEPRECATED_3_0
813 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
814 static int AES_cbc_128_encrypt_loop(void *args)
816 loopargs_t *tempargs = *(loopargs_t **) args;
817 unsigned char *buf = tempargs->buf;
819 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
820 AES_cbc_encrypt(buf, buf,
821 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
825 static int AES_cbc_192_encrypt_loop(void *args)
827 loopargs_t *tempargs = *(loopargs_t **) args;
828 unsigned char *buf = tempargs->buf;
830 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
831 AES_cbc_encrypt(buf, buf,
832 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
836 static int AES_cbc_256_encrypt_loop(void *args)
838 loopargs_t *tempargs = *(loopargs_t **) args;
839 unsigned char *buf = tempargs->buf;
841 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
842 AES_cbc_encrypt(buf, buf,
843 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
847 static int AES_ige_128_encrypt_loop(void *args)
849 loopargs_t *tempargs = *(loopargs_t **) args;
850 unsigned char *buf = tempargs->buf;
851 unsigned char *buf2 = tempargs->buf2;
853 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
854 AES_ige_encrypt(buf, buf2,
855 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
859 static int AES_ige_192_encrypt_loop(void *args)
861 loopargs_t *tempargs = *(loopargs_t **) args;
862 unsigned char *buf = tempargs->buf;
863 unsigned char *buf2 = tempargs->buf2;
865 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
866 AES_ige_encrypt(buf, buf2,
867 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
871 static int AES_ige_256_encrypt_loop(void *args)
873 loopargs_t *tempargs = *(loopargs_t **) args;
874 unsigned char *buf = tempargs->buf;
875 unsigned char *buf2 = tempargs->buf2;
877 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
878 AES_ige_encrypt(buf, buf2,
879 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
883 static int CRYPTO_gcm128_aad_loop(void *args)
885 loopargs_t *tempargs = *(loopargs_t **) args;
886 unsigned char *buf = tempargs->buf;
887 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
889 for (count = 0; COND(c[D_GHASH][testnum]); count++)
890 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
895 static int RAND_bytes_loop(void *args)
897 loopargs_t *tempargs = *(loopargs_t **) args;
898 unsigned char *buf = tempargs->buf;
901 for (count = 0; COND(c[D_RAND][testnum]); count++)
902 RAND_bytes(buf, lengths[testnum]);
906 static int decrypt = 0;
907 static int EVP_Update_loop(void *args)
909 loopargs_t *tempargs = *(loopargs_t **) args;
910 unsigned char *buf = tempargs->buf;
911 EVP_CIPHER_CTX *ctx = tempargs->ctx;
915 for (count = 0; COND(c[D_EVP][testnum]); count++) {
916 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
918 /* reset iv in case of counter overflow */
919 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
923 for (count = 0; COND(c[D_EVP][testnum]); count++) {
924 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
926 /* reset iv in case of counter overflow */
927 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
932 EVP_DecryptFinal_ex(ctx, buf, &outl);
934 EVP_EncryptFinal_ex(ctx, buf, &outl);
939 * CCM does not support streaming. For the purpose of performance measurement,
940 * each message is encrypted using the same (key,iv)-pair. Do not use this
941 * code in your application.
943 static int EVP_Update_loop_ccm(void *args)
945 loopargs_t *tempargs = *(loopargs_t **) args;
946 unsigned char *buf = tempargs->buf;
947 EVP_CIPHER_CTX *ctx = tempargs->ctx;
949 unsigned char tag[12];
952 for (count = 0; COND(c[D_EVP][testnum]); count++) {
953 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
955 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
956 /* counter is reset on every update */
957 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
960 for (count = 0; COND(c[D_EVP][testnum]); count++) {
961 /* restore iv length field */
962 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
963 /* counter is reset on every update */
964 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
968 EVP_DecryptFinal_ex(ctx, buf, &outl);
970 EVP_EncryptFinal_ex(ctx, buf, &outl);
975 * To make AEAD benchmarking more relevant perform TLS-like operations,
976 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
977 * payload length is not actually limited by 16KB...
979 static int EVP_Update_loop_aead(void *args)
981 loopargs_t *tempargs = *(loopargs_t **) args;
982 unsigned char *buf = tempargs->buf;
983 EVP_CIPHER_CTX *ctx = tempargs->ctx;
985 unsigned char aad[13] = { 0xcc };
986 unsigned char faketag[16] = { 0xcc };
989 for (count = 0; COND(c[D_EVP][testnum]); count++) {
990 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
991 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
992 sizeof(faketag), faketag);
993 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
994 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
995 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
998 for (count = 0; COND(c[D_EVP][testnum]); count++) {
999 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
1000 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
1001 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
1002 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
1008 static EVP_MD *evp_md = NULL;
1009 static int fetched_alg = 0;
1011 static int EVP_Digest_loop(void *args)
1013 loopargs_t *tempargs = *(loopargs_t **) args;
1014 unsigned char *buf = tempargs->buf;
1015 unsigned char md[EVP_MAX_MD_SIZE];
1018 for (count = 0; COND(c[D_EVP][testnum]); count++) {
1019 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
1025 #ifndef OPENSSL_NO_DEPRECATED_3_0
1026 static const EVP_MD *evp_hmac_md = NULL;
1027 static char *evp_hmac_name = NULL;
1028 static int EVP_HMAC_loop(void *args)
1030 loopargs_t *tempargs = *(loopargs_t **) args;
1031 unsigned char *buf = tempargs->buf;
1032 unsigned char no_key[32];
1035 for (count = 0; COND(c[D_EVP_HMAC][testnum]); count++) {
1036 if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
1037 NULL, NULL) == NULL)
1044 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1045 static const EVP_CIPHER *evp_cmac_cipher = NULL;
1046 static char *evp_cmac_name = NULL;
1048 static int EVP_CMAC_loop(void *args)
1050 loopargs_t *tempargs = *(loopargs_t **) args;
1051 unsigned char *buf = tempargs->buf;
1052 CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
1053 static const char key[16] = "This is a key...";
1054 unsigned char mac[16];
1055 size_t len = sizeof(mac);
1058 for (count = 0; COND(c[D_EVP_CMAC][testnum]); count++) {
1059 if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
1060 || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
1061 || !CMAC_Final(cmac_ctx, mac, &len))
1068 #ifndef OPENSSL_NO_DEPRECATED_3_0
1069 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1071 static int RSA_sign_loop(void *args)
1073 loopargs_t *tempargs = *(loopargs_t **) args;
1074 unsigned char *buf = tempargs->buf;
1075 unsigned char *buf2 = tempargs->buf2;
1076 unsigned int *rsa_num = &tempargs->siglen;
1077 RSA **rsa_key = tempargs->rsa_key;
1079 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1080 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1082 BIO_printf(bio_err, "RSA sign failure\n");
1083 ERR_print_errors(bio_err);
1091 static int RSA_verify_loop(void *args)
1093 loopargs_t *tempargs = *(loopargs_t **) args;
1094 unsigned char *buf = tempargs->buf;
1095 unsigned char *buf2 = tempargs->buf2;
1096 unsigned int rsa_num = tempargs->siglen;
1097 RSA **rsa_key = tempargs->rsa_key;
1099 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1101 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1103 BIO_printf(bio_err, "RSA verify failure\n");
1104 ERR_print_errors(bio_err);
1113 #ifndef OPENSSL_NO_DH
1114 static long ffdh_c[FFDH_NUM][1];
1116 static int FFDH_derive_key_loop(void *args)
1118 loopargs_t *tempargs = *(loopargs_t **) args;
1119 EVP_PKEY_CTX *ffdh_ctx = tempargs->ffdh_ctx[testnum];
1120 unsigned char *derived_secret = tempargs->secret_ff_a;
1121 size_t outlen = MAX_FFDH_SIZE;
1124 for (count = 0; COND(ffdh_c[testnum][0]); count++)
1125 EVP_PKEY_derive(ffdh_ctx, derived_secret, &outlen);
1129 #endif /* OPENSSL_NO_DH */
1131 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1132 static long dsa_c[DSA_NUM][2];
1133 static int DSA_sign_loop(void *args)
1135 loopargs_t *tempargs = *(loopargs_t **) args;
1136 unsigned char *buf = tempargs->buf;
1137 unsigned char *buf2 = tempargs->buf2;
1138 DSA **dsa_key = tempargs->dsa_key;
1139 unsigned int *siglen = &tempargs->siglen;
1141 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1142 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1144 BIO_printf(bio_err, "DSA sign failure\n");
1145 ERR_print_errors(bio_err);
1153 static int DSA_verify_loop(void *args)
1155 loopargs_t *tempargs = *(loopargs_t **) args;
1156 unsigned char *buf = tempargs->buf;
1157 unsigned char *buf2 = tempargs->buf2;
1158 DSA **dsa_key = tempargs->dsa_key;
1159 unsigned int siglen = tempargs->siglen;
1161 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1162 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1164 BIO_printf(bio_err, "DSA verify failure\n");
1165 ERR_print_errors(bio_err);
1174 #ifndef OPENSSL_NO_EC
1175 # ifndef OPENSSL_NO_DEPRECATED_3_0
1176 static long ecdsa_c[ECDSA_NUM][2];
1177 static int ECDSA_sign_loop(void *args)
1179 loopargs_t *tempargs = *(loopargs_t **) args;
1180 unsigned char *buf = tempargs->buf;
1181 EC_KEY **ecdsa = tempargs->ecdsa;
1182 unsigned char *ecdsasig = tempargs->buf2;
1183 unsigned int *ecdsasiglen = &tempargs->siglen;
1185 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1186 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1188 BIO_printf(bio_err, "ECDSA sign failure\n");
1189 ERR_print_errors(bio_err);
1197 static int ECDSA_verify_loop(void *args)
1199 loopargs_t *tempargs = *(loopargs_t **) args;
1200 unsigned char *buf = tempargs->buf;
1201 EC_KEY **ecdsa = tempargs->ecdsa;
1202 unsigned char *ecdsasig = tempargs->buf2;
1203 unsigned int ecdsasiglen = tempargs->siglen;
1205 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1206 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1208 BIO_printf(bio_err, "ECDSA verify failure\n");
1209 ERR_print_errors(bio_err);
1218 /* ******************************************************************** */
1219 static long ecdh_c[EC_NUM][1];
1221 static int ECDH_EVP_derive_key_loop(void *args)
1223 loopargs_t *tempargs = *(loopargs_t **) args;
1224 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1225 unsigned char *derived_secret = tempargs->secret_a;
1227 size_t *outlen = &(tempargs->outlen[testnum]);
1229 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1230 EVP_PKEY_derive(ctx, derived_secret, outlen);
1235 static long eddsa_c[EdDSA_NUM][2];
1236 static int EdDSA_sign_loop(void *args)
1238 loopargs_t *tempargs = *(loopargs_t **) args;
1239 unsigned char *buf = tempargs->buf;
1240 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1241 unsigned char *eddsasig = tempargs->buf2;
1242 size_t *eddsasigsize = &tempargs->sigsize;
1245 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1246 ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1248 BIO_printf(bio_err, "EdDSA sign failure\n");
1249 ERR_print_errors(bio_err);
1257 static int EdDSA_verify_loop(void *args)
1259 loopargs_t *tempargs = *(loopargs_t **) args;
1260 unsigned char *buf = tempargs->buf;
1261 EVP_MD_CTX **edctx = tempargs->eddsa_ctx2;
1262 unsigned char *eddsasig = tempargs->buf2;
1263 size_t eddsasigsize = tempargs->sigsize;
1266 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1267 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1269 BIO_printf(bio_err, "EdDSA verify failure\n");
1270 ERR_print_errors(bio_err);
1278 # ifndef OPENSSL_NO_SM2
1279 static long sm2_c[SM2_NUM][2];
1280 static int SM2_sign_loop(void *args)
1282 loopargs_t *tempargs = *(loopargs_t **) args;
1283 unsigned char *buf = tempargs->buf;
1284 EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx;
1285 unsigned char *sm2sig = tempargs->buf2;
1288 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1289 const size_t max_size = EVP_PKEY_size(sm2_pkey[testnum]);
1291 for (count = 0; COND(sm2_c[testnum][0]); count++) {
1292 sm2sigsize = max_size;
1294 if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(),
1295 NULL, sm2_pkey[testnum])) {
1296 BIO_printf(bio_err, "SM2 init sign failure\n");
1297 ERR_print_errors(bio_err);
1301 ret = EVP_DigestSign(sm2ctx[testnum], sm2sig, &sm2sigsize,
1304 BIO_printf(bio_err, "SM2 sign failure\n");
1305 ERR_print_errors(bio_err);
1309 /* update the latest returned size and always use the fixed buffer size */
1310 tempargs->sigsize = sm2sigsize;
1316 static int SM2_verify_loop(void *args)
1318 loopargs_t *tempargs = *(loopargs_t **) args;
1319 unsigned char *buf = tempargs->buf;
1320 EVP_MD_CTX **sm2ctx = tempargs->sm2_vfy_ctx;
1321 unsigned char *sm2sig = tempargs->buf2;
1322 size_t sm2sigsize = tempargs->sigsize;
1324 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1326 for (count = 0; COND(sm2_c[testnum][1]); count++) {
1327 if (!EVP_DigestVerifyInit(sm2ctx[testnum], NULL, EVP_sm3(),
1328 NULL, sm2_pkey[testnum])) {
1329 BIO_printf(bio_err, "SM2 verify init failure\n");
1330 ERR_print_errors(bio_err);
1334 ret = EVP_DigestVerify(sm2ctx[testnum], sm2sig, sm2sigsize,
1337 BIO_printf(bio_err, "SM2 verify failure\n");
1338 ERR_print_errors(bio_err);
1345 # endif /* OPENSSL_NO_SM2 */
1346 #endif /* OPENSSL_NO_EC */
1348 static int run_benchmark(int async_jobs,
1349 int (*loop_function) (void *), loopargs_t * loopargs)
1351 int job_op_count = 0;
1352 int total_op_count = 0;
1353 int num_inprogress = 0;
1354 int error = 0, i = 0, ret = 0;
1355 OSSL_ASYNC_FD job_fd = 0;
1356 size_t num_job_fds = 0;
1358 if (async_jobs == 0) {
1359 return loop_function((void *)&loopargs);
1362 for (i = 0; i < async_jobs && !error; i++) {
1363 loopargs_t *looparg_item = loopargs + i;
1365 /* Copy pointer content (looparg_t item address) into async context */
1366 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1367 &job_op_count, loop_function,
1368 (void *)&looparg_item, sizeof(looparg_item));
1374 if (job_op_count == -1) {
1377 total_op_count += job_op_count;
1382 BIO_printf(bio_err, "Failure in the job\n");
1383 ERR_print_errors(bio_err);
1389 while (num_inprogress > 0) {
1390 #if defined(OPENSSL_SYS_WINDOWS)
1392 #elif defined(OPENSSL_SYS_UNIX)
1393 int select_result = 0;
1394 OSSL_ASYNC_FD max_fd = 0;
1397 FD_ZERO(&waitfdset);
1399 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1400 if (loopargs[i].inprogress_job == NULL)
1403 if (!ASYNC_WAIT_CTX_get_all_fds
1404 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1405 || num_job_fds > 1) {
1406 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1407 ERR_print_errors(bio_err);
1411 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1413 FD_SET(job_fd, &waitfdset);
1414 if (job_fd > max_fd)
1418 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1420 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1421 "Decrease the value of async_jobs\n",
1422 max_fd, FD_SETSIZE);
1423 ERR_print_errors(bio_err);
1428 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1429 if (select_result == -1 && errno == EINTR)
1432 if (select_result == -1) {
1433 BIO_printf(bio_err, "Failure in the select\n");
1434 ERR_print_errors(bio_err);
1439 if (select_result == 0)
1443 for (i = 0; i < async_jobs; i++) {
1444 if (loopargs[i].inprogress_job == NULL)
1447 if (!ASYNC_WAIT_CTX_get_all_fds
1448 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1449 || num_job_fds > 1) {
1450 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1451 ERR_print_errors(bio_err);
1455 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1458 #if defined(OPENSSL_SYS_UNIX)
1459 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1461 #elif defined(OPENSSL_SYS_WINDOWS)
1462 if (num_job_fds == 1
1463 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1468 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1469 loopargs[i].wait_ctx, &job_op_count,
1470 loop_function, (void *)(loopargs + i),
1471 sizeof(loopargs_t));
1476 if (job_op_count == -1) {
1479 total_op_count += job_op_count;
1482 loopargs[i].inprogress_job = NULL;
1487 loopargs[i].inprogress_job = NULL;
1488 BIO_printf(bio_err, "Failure in the job\n");
1489 ERR_print_errors(bio_err);
1496 return error ? -1 : total_op_count;
1499 static EVP_MD *obtain_md(const char *name)
1503 /* Look through providers' digests */
1505 md = EVP_MD_fetch(NULL, name, NULL);
1512 return (EVP_MD *)EVP_get_digestbyname(name);
1515 static EVP_CIPHER *obtain_cipher(const char *name)
1517 EVP_CIPHER *cipher = NULL;
1519 /* Look through providers' ciphers */
1521 cipher = EVP_CIPHER_fetch(NULL, name, NULL);
1523 if (cipher != NULL) {
1528 return (EVP_CIPHER *)EVP_get_cipherbyname(name);
1531 #define stop_it(do_it, test_num)\
1532 memset(do_it + test_num, 0, OSSL_NELEM(do_it) - test_num);
1534 int speed_main(int argc, char **argv)
1537 loopargs_t *loopargs = NULL;
1539 const char *engine_id = NULL;
1540 EVP_CIPHER *evp_cipher = NULL;
1543 int async_init = 0, multiblock = 0, pr_header = 0;
1544 uint8_t doit[ALGOR_NUM] = { 0 };
1545 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1547 unsigned int size_num = SIZE_NUM;
1548 unsigned int i, k, loopargs_len = 0, async_jobs = 0;
1554 #if !defined(OPENSSL_NO_DEPRECATED_3_0) \
1555 || !defined(OPENSSL_NO_DSA) \
1556 || !defined(OPENSSL_NO_DH) \
1557 || !defined(OPENSSL_NO_EC)
1560 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1561 ECDSA_SECONDS, ECDH_SECONDS,
1562 EdDSA_SECONDS, SM2_SECONDS,
1565 /* What follows are the buffers and key material. */
1566 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1569 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1572 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1573 IDEA_KEY_SCHEDULE idea_ks;
1575 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1576 SEED_KEY_SCHEDULE seed_ks;
1578 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1581 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1584 #ifndef OPENSSL_NO_DEPRECATED_3_0
1585 static const unsigned char key16[16] = {
1586 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1587 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1589 static const unsigned char key24[24] = {
1590 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1591 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1592 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1594 static const unsigned char key32[32] = {
1595 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1596 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1597 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1598 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1601 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1602 CAMELLIA_KEY camellia_ks[3];
1604 #ifndef OPENSSL_NO_DEPRECATED_3_0
1605 static const struct {
1606 const unsigned char *data;
1607 unsigned int length;
1610 { test512, sizeof(test512), 512 },
1611 { test1024, sizeof(test1024), 1024 },
1612 { test2048, sizeof(test2048), 2048 },
1613 { test3072, sizeof(test3072), 3072 },
1614 { test4096, sizeof(test4096), 4092 },
1615 { test7680, sizeof(test7680), 7680 },
1616 { test15360, sizeof(test15360), 15360 }
1618 uint8_t rsa_doit[RSA_NUM] = { 0 };
1619 int primes = RSA_DEFAULT_PRIME_NUM;
1621 #ifndef OPENSSL_NO_DH
1622 typedef struct ffdh_params_st {
1628 static const FFDH_PARAMS ffdh_params[FFDH_NUM] = {
1629 {"ffdh2048", NID_ffdhe2048, 2048},
1630 {"ffdh3072", NID_ffdhe3072, 3072},
1631 {"ffdh4096", NID_ffdhe4096, 4096},
1632 {"ffdh6144", NID_ffdhe6144, 6144},
1633 {"ffdh8192", NID_ffdhe8192, 8192}
1635 uint8_t ffdh_doit[FFDH_NUM] = { 0 };
1637 #endif /* OPENSSL_NO_DH */
1638 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1639 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1640 uint8_t dsa_doit[DSA_NUM] = { 0 };
1642 #ifndef OPENSSL_NO_EC
1643 typedef struct ec_curve_st {
1647 size_t sigsize; /* only used for EdDSA curves */
1650 * We only test over the following curves as they are representative, To
1651 * add tests over more curves, simply add the curve NID and curve name to
1652 * the following arrays and increase the |ecdh_choices| and |ecdsa_choices|
1653 * lists accordingly.
1655 static const EC_CURVE ec_curves[EC_NUM] = {
1657 {"secp160r1", NID_secp160r1, 160},
1658 {"nistp192", NID_X9_62_prime192v1, 192},
1659 {"nistp224", NID_secp224r1, 224},
1660 {"nistp256", NID_X9_62_prime256v1, 256},
1661 {"nistp384", NID_secp384r1, 384},
1662 {"nistp521", NID_secp521r1, 521},
1663 # ifndef OPENSSL_NO_EC2M
1665 {"nistk163", NID_sect163k1, 163},
1666 {"nistk233", NID_sect233k1, 233},
1667 {"nistk283", NID_sect283k1, 283},
1668 {"nistk409", NID_sect409k1, 409},
1669 {"nistk571", NID_sect571k1, 571},
1670 {"nistb163", NID_sect163r2, 163},
1671 {"nistb233", NID_sect233r1, 233},
1672 {"nistb283", NID_sect283r1, 283},
1673 {"nistb409", NID_sect409r1, 409},
1674 {"nistb571", NID_sect571r1, 571},
1676 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1677 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1678 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1679 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1680 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1681 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1682 /* Other and ECDH only ones */
1683 {"X25519", NID_X25519, 253},
1684 {"X448", NID_X448, 448}
1686 static const EC_CURVE ed_curves[EdDSA_NUM] = {
1688 {"Ed25519", NID_ED25519, 253, 64},
1689 {"Ed448", NID_ED448, 456, 114}
1691 # ifndef OPENSSL_NO_SM2
1692 static const EC_CURVE sm2_curves[SM2_NUM] = {
1694 {"CurveSM2", NID_sm2, 256}
1696 uint8_t sm2_doit[SM2_NUM] = { 0 };
1698 uint8_t ecdsa_doit[ECDSA_NUM] = { 0 };
1699 uint8_t ecdh_doit[EC_NUM] = { 0 };
1700 uint8_t eddsa_doit[EdDSA_NUM] = { 0 };
1702 /* checks declarated curves against choices list. */
1703 OPENSSL_assert(ed_curves[EdDSA_NUM - 1].nid == NID_ED448);
1704 OPENSSL_assert(strcmp(eddsa_choices[EdDSA_NUM - 1].name, "ed448") == 0);
1706 OPENSSL_assert(ec_curves[EC_NUM - 1].nid == NID_X448);
1707 OPENSSL_assert(strcmp(ecdh_choices[EC_NUM - 1].name, "ecdhx448") == 0);
1709 OPENSSL_assert(ec_curves[ECDSA_NUM - 1].nid == NID_brainpoolP512t1);
1710 OPENSSL_assert(strcmp(ecdsa_choices[ECDSA_NUM - 1].name, "ecdsabrp512t1") == 0);
1712 # ifndef OPENSSL_NO_SM2
1713 OPENSSL_assert(sm2_curves[SM2_NUM - 1].nid == NID_sm2);
1714 OPENSSL_assert(strcmp(sm2_choices[SM2_NUM - 1].name, "curveSM2") == 0);
1716 #endif /* ndef OPENSSL_NO_EC */
1718 prog = opt_init(argc, argv, speed_options);
1719 while ((o = opt_next()) != OPT_EOF) {
1724 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1727 opt_help(speed_options);
1735 BIO_printf(bio_err, "%s: -evp option cannot be used more than once\n", prog);
1739 evp_cipher = obtain_cipher(opt_arg());
1740 if (evp_cipher == NULL)
1741 evp_md = obtain_md(opt_arg());
1742 if (evp_cipher == NULL && evp_md == NULL) {
1744 "%s: %s is an unknown cipher or digest\n",
1751 #ifndef OPENSSL_NO_DEPRECATED_3_0
1752 evp_hmac_md = EVP_get_digestbyname(opt_arg());
1753 if (evp_hmac_md == NULL) {
1754 BIO_printf(bio_err, "%s: %s is an unknown digest\n",
1758 doit[D_EVP_HMAC] = 1;
1762 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1763 evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
1764 if (evp_cmac_cipher == NULL) {
1765 BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
1769 doit[D_EVP_CMAC] = 1;
1777 * In a forked execution, an engine might need to be
1778 * initialised by each child process, not by the parent.
1779 * So store the name here and run setup_engine() later on.
1781 engine_id = opt_arg();
1785 multi = atoi(opt_arg());
1789 #ifndef OPENSSL_NO_ASYNC
1790 async_jobs = atoi(opt_arg());
1791 if (!ASYNC_is_capable()) {
1793 "%s: async_jobs specified but async not supported\n",
1797 if (async_jobs > 99999) {
1798 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1804 if (!opt_int(opt_arg(), &misalign))
1806 if (misalign > MISALIGN) {
1808 "%s: Maximum offset is %d\n", prog, MISALIGN);
1817 #ifdef OPENSSL_NO_MULTIBLOCK
1819 "%s: -mb specified but multi-block support is disabled\n",
1828 case OPT_PROV_CASES:
1829 if (!opt_provider(o))
1833 #ifndef OPENSSL_NO_DEPRECATED_3_0
1834 if (!opt_int(opt_arg(), &primes))
1839 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1840 = seconds.ecdh = seconds.eddsa
1841 = seconds.sm2 = seconds.ffdh = atoi(opt_arg());
1844 lengths_single = atoi(opt_arg());
1845 lengths = &lengths_single;
1854 /* Remaining arguments are algorithms. */
1855 argc = opt_num_rest();
1859 for (; *argv; argv++) {
1860 const char *algo = *argv;
1862 if (opt_found(algo, doit_choices, &i)) {
1866 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1867 if (strcmp(algo, "des") == 0) {
1868 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1872 if (strcmp(algo, "sha") == 0) {
1873 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1876 #ifndef OPENSSL_NO_DEPRECATED_3_0
1877 if (strcmp(algo, "openssl") == 0) /* just for compatibility */
1879 if (strncmp(algo, "rsa", 3) == 0) {
1880 if (algo[3] == '\0') {
1881 memset(rsa_doit, 1, sizeof(rsa_doit));
1884 if (opt_found(algo, rsa_choices, &i)) {
1890 #ifndef OPENSSL_NO_DH
1891 if (strncmp(algo, "ffdh", 4) == 0) {
1892 if (algo[4] == '\0') {
1893 memset(ffdh_doit, 1, sizeof(ffdh_doit));
1896 if (opt_found(algo, ffdh_choices, &i)) {
1902 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1903 if (strncmp(algo, "dsa", 3) == 0) {
1904 if (algo[3] == '\0') {
1905 memset(dsa_doit, 1, sizeof(dsa_doit));
1908 if (opt_found(algo, dsa_choices, &i)) {
1914 #ifndef OPENSSL_NO_DEPRECATED_3_0
1915 if (strcmp(algo, "aes") == 0) {
1916 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1920 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1921 if (strcmp(algo, "camellia") == 0) {
1922 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1926 #ifndef OPENSSL_NO_EC
1927 if (strncmp(algo, "ecdsa", 5) == 0) {
1928 if (algo[5] == '\0') {
1929 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
1932 if (opt_found(algo, ecdsa_choices, &i)) {
1937 if (strncmp(algo, "ecdh", 4) == 0) {
1938 if (algo[4] == '\0') {
1939 memset(ecdh_doit, 1, sizeof(ecdh_doit));
1942 if (opt_found(algo, ecdh_choices, &i)) {
1947 if (strcmp(algo, "eddsa") == 0) {
1948 memset(eddsa_doit, 1, sizeof(eddsa_doit));
1951 if (opt_found(algo, eddsa_choices, &i)) {
1955 # ifndef OPENSSL_NO_SM2
1956 if (strcmp(algo, "sm2") == 0) {
1957 memset(sm2_doit, 1, sizeof(sm2_doit));
1960 if (opt_found(algo, sm2_choices, &i)) {
1965 #endif /* OPENSSL_NO_EC */
1966 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, algo);
1972 if (evp_cipher == NULL) {
1973 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1975 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1976 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1977 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1978 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1983 if (evp_cipher == NULL) {
1984 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1985 " capable cipher\n");
1987 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1988 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1989 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1990 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1992 } else if (async_jobs > 0) {
1993 BIO_printf(bio_err, "Async mode is not supported with -mb");
1998 /* Initialize the job pool if async mode is enabled */
1999 if (async_jobs > 0) {
2000 async_init = ASYNC_init_thread(async_jobs, async_jobs);
2002 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
2007 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
2009 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
2010 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
2012 for (i = 0; i < loopargs_len; i++) {
2013 if (async_jobs > 0) {
2014 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
2015 if (loopargs[i].wait_ctx == NULL) {
2016 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
2021 buflen = lengths[size_num - 1];
2022 if (buflen < 36) /* size of random vector in RSA benchmark */
2024 buflen += MAX_MISALIGNMENT + 1;
2025 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
2026 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
2027 memset(loopargs[i].buf_malloc, 0, buflen);
2028 memset(loopargs[i].buf2_malloc, 0, buflen);
2030 /* Align the start of buffers on a 64 byte boundary */
2031 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
2032 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
2033 #ifndef OPENSSL_NO_EC
2034 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
2035 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
2037 #ifndef OPENSSL_NO_DH
2038 loopargs[i].secret_ff_a = app_malloc(MAX_FFDH_SIZE, "FFDH secret a");
2039 loopargs[i].secret_ff_b = app_malloc(MAX_FFDH_SIZE, "FFDH secret b");
2044 if (multi && do_multi(multi, size_num))
2048 /* Initialize the engine after the fork */
2049 e = setup_engine(engine_id, 0);
2051 /* No parameters; turn on everything. */
2052 if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
2053 memset(doit, 1, sizeof(doit));
2054 doit[D_EVP] = doit[D_EVP_HMAC] = doit[D_EVP_CMAC] = 0;
2055 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2058 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2061 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2064 #ifndef OPENSSL_NO_DEPRECATED_3_0
2065 memset(rsa_doit, 1, sizeof(rsa_doit));
2067 #ifndef OPENSSL_NO_DH
2068 memset(ffdh_doit, 1, sizeof(ffdh_doit));
2070 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2071 memset(dsa_doit, 1, sizeof(dsa_doit));
2073 #ifndef OPENSSL_NO_EC
2074 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
2075 memset(ecdh_doit, 1, sizeof(ecdh_doit));
2076 memset(eddsa_doit, 1, sizeof(eddsa_doit));
2077 # ifndef OPENSSL_NO_SM2
2078 memset(sm2_doit, 1, sizeof(sm2_doit));
2082 for (i = 0; i < ALGOR_NUM; i++)
2086 if (usertime == 0 && !mr)
2088 "You have chosen to measure elapsed time "
2089 "instead of user CPU time.\n");
2091 #ifndef OPENSSL_NO_DEPRECATED_3_0
2092 for (i = 0; i < loopargs_len; i++) {
2093 if (primes > RSA_DEFAULT_PRIME_NUM) {
2094 /* for multi-prime RSA, skip this */
2097 for (k = 0; k < RSA_NUM; k++) {
2098 const unsigned char *p = rsa_keys[k].data;
2100 loopargs[i].rsa_key[k] =
2101 d2i_RSAPrivateKey(NULL, &p, rsa_keys[k].length);
2102 if (loopargs[i].rsa_key[k] == NULL) {
2104 "internal error loading RSA key number %d\n", k);
2110 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2111 for (i = 0; i < loopargs_len; i++) {
2112 loopargs[i].dsa_key[0] = get_dsa(512);
2113 loopargs[i].dsa_key[1] = get_dsa(1024);
2114 loopargs[i].dsa_key[2] = get_dsa(2048);
2117 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2118 if (doit[D_CBC_DES] || doit[D_EDE3_DES]) {
2119 static DES_cblock keys[] = {
2120 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }, /* keys[0] */
2121 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }, /* keys[1] */
2122 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 } /* keys[3] */
2124 DES_set_key_unchecked(&keys[0], &sch[0]);
2125 DES_set_key_unchecked(&keys[1], &sch[1]);
2126 DES_set_key_unchecked(&keys[2], &sch[2]);
2129 #ifndef OPENSSL_NO_DEPRECATED_3_0
2130 AES_set_encrypt_key(key16, 128, &aes_ks1);
2131 AES_set_encrypt_key(key24, 192, &aes_ks2);
2132 AES_set_encrypt_key(key32, 256, &aes_ks3);
2134 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2135 if (doit[D_CBC_128_CML] || doit[D_CBC_192_CML] || doit[D_CBC_256_CML]) {
2136 Camellia_set_key(key16, 128, &camellia_ks[0]);
2137 Camellia_set_key(key24, 192, &camellia_ks[1]);
2138 Camellia_set_key(key32, 256, &camellia_ks[2]);
2141 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2142 if (doit[D_CBC_IDEA])
2143 IDEA_set_encrypt_key(key16, &idea_ks);
2145 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2146 if (doit[D_CBC_SEED])
2147 SEED_set_key(key16, &seed_ks);
2149 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2151 RC4_set_key(&rc4_ks, 16, key16);
2153 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2154 if (doit[D_CBC_RC2])
2155 RC2_set_key(&rc2_ks, 16, key16, 128);
2157 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2158 if (doit[D_CBC_RC5])
2159 if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
2160 BIO_printf(bio_err, "Failed setting RC5 key\n");
2164 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2166 BF_set_key(&bf_ks, 16, key16);
2168 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2169 if (doit[D_CBC_CAST])
2170 CAST_set_key(&cast_ks, 16, key16);
2173 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2174 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
2180 for (it = count; it; it--)
2181 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
2182 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
2185 c[D_MD2][0] = count / 10;
2186 c[D_MDC2][0] = count / 10;
2187 c[D_MD4][0] = count;
2188 c[D_MD5][0] = count;
2189 c[D_HMAC][0] = count;
2190 c[D_SHA1][0] = count;
2191 c[D_RMD160][0] = count;
2192 c[D_RC4][0] = count * 5;
2193 c[D_CBC_DES][0] = count;
2194 c[D_EDE3_DES][0] = count / 3;
2195 c[D_CBC_IDEA][0] = count;
2196 c[D_CBC_SEED][0] = count;
2197 c[D_CBC_RC2][0] = count;
2198 c[D_CBC_RC5][0] = count;
2199 c[D_CBC_BF][0] = count;
2200 c[D_CBC_CAST][0] = count;
2201 c[D_CBC_128_AES][0] = count;
2202 c[D_CBC_192_AES][0] = count;
2203 c[D_CBC_256_AES][0] = count;
2204 c[D_CBC_128_CML][0] = count;
2205 c[D_CBC_192_CML][0] = count;
2206 c[D_CBC_256_CML][0] = count;
2207 c[D_EVP][0] = count;
2208 c[D_SHA256][0] = count;
2209 c[D_SHA512][0] = count;
2210 c[D_WHIRLPOOL][0] = count;
2211 c[D_IGE_128_AES][0] = count;
2212 c[D_IGE_192_AES][0] = count;
2213 c[D_IGE_256_AES][0] = count;
2214 c[D_GHASH][0] = count;
2215 c[D_RAND][0] = count;
2216 c[D_EVP_HMAC][0] = count;
2217 c[D_EVP_CMAC][0] = count;
2219 for (i = 1; i < size_num; i++) {
2220 long l0 = (long)lengths[0];
2221 long l1 = (long)lengths[i];
2223 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
2224 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
2225 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
2226 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
2227 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
2228 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
2229 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
2230 c[D_EVP][i] = = c[D_EVP][0] * 4 * l0 / l1;
2231 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
2232 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
2233 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
2234 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
2235 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
2236 c[D_EVP_HMAC][i] = = c[D_EVP_HMAC][0] * 4 * l0 / l1;
2237 c[D_EVP_CMAC][i] = = c[D_EVP_CMAC][0] * 4 * l0 / l1;
2239 l0 = (long)lengths[i - 1];
2241 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
2242 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
2243 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
2244 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
2245 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
2246 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
2247 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
2248 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
2249 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
2250 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
2251 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
2252 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
2253 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
2254 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
2255 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
2256 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
2257 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
2258 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
2261 # ifndef OPENSSL_NO_DEPRECATED_3_0
2262 rsa_c[R_RSA_512][0] = count / 2000;
2263 rsa_c[R_RSA_512][1] = count / 400;
2264 for (i = 1; i < RSA_NUM; i++) {
2265 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
2266 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
2267 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
2270 if (rsa_c[i][0] == 0) {
2271 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2278 # if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2279 dsa_c[R_DSA_512][0] = count / 1000;
2280 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2281 for (i = 1; i < DSA_NUM; i++) {
2282 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2283 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2284 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2287 if (dsa_c[i][0] == 0) {
2288 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2295 # ifndef OPENSSL_NO_EC
2296 ecdsa_c[R_EC_P160][0] = count / 1000;
2297 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2298 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2299 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2300 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2301 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2304 if (ecdsa_c[i][0] == 0) {
2310 # ifndef OPENSSL_NO_EC2M
2311 ecdsa_c[R_EC_K163][0] = count / 1000;
2312 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2313 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2314 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2315 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2316 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2319 if (ecdsa_c[i][0] == 0) {
2325 ecdsa_c[R_EC_B163][0] = count / 1000;
2326 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2327 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2328 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2329 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2330 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2333 if (ecdsa_c[i][0] == 0) {
2341 ecdh_c[R_EC_P160][0] = count / 1000;
2342 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2343 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2344 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2347 if (ecdh_c[i][0] == 0) {
2352 # ifndef OPENSSL_NO_EC2M
2353 ecdh_c[R_EC_K163][0] = count / 1000;
2354 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2355 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2356 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2359 if (ecdh_c[i][0] == 0) {
2364 ecdh_c[R_EC_B163][0] = count / 1000;
2365 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2366 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2367 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2370 if (ecdh_c[i][0] == 0) {
2376 /* repeated code good to factorize */
2377 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2378 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2379 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2380 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2383 if (ecdh_c[i][0] == 0) {
2388 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2389 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2390 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2391 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2394 if (ecdh_c[i][0] == 0) {
2399 /* default iteration count for the last two EC Curves */
2400 ecdh_c[R_EC_X25519][0] = count / 1800;
2401 ecdh_c[R_EC_X448][0] = count / 7200;
2403 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2404 eddsa_c[R_EC_Ed448][0] = count / 7200;
2406 # ifndef OPENSSL_NO_SM2
2407 sm2_c[R_EC_SM2P256][0] = count / 1800;
2409 # endif /* OPENSSL_NO_EC */
2411 # ifndef OPENSSL_NO_DH
2412 ffdh_c[R_FFDH_2048][0] = count / 1000;
2413 for (i = R_FFDH_3072; i <= R_FFDH_8192; i++) {
2414 ffdh_c[i][0] = ffdh_c[i - 1][0] / 2;
2415 if (ffdh_doit[i] <= 1 && ffdh_c[i][0] == 0) {
2418 if (ffdh_c[i][0] == 0)
2422 # endif /* OPENSSL_NO_DH */
2425 /* not worth fixing */
2426 # error "You cannot disable DES on systems without SIGALRM."
2427 # endif /* OPENSSL_NO_DES */
2429 signal(SIGALRM, alarmed);
2430 #endif /* SIGALRM */
2432 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2434 for (testnum = 0; testnum < size_num; testnum++) {
2435 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2438 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2440 print_result(D_MD2, testnum, count, d);
2444 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2446 for (testnum = 0; testnum < size_num; testnum++) {
2447 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2450 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2452 print_result(D_MDC2, testnum, count, d);
2459 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2461 for (testnum = 0; testnum < size_num; testnum++) {
2462 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2465 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2467 print_result(D_MD4, testnum, count, d);
2474 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2476 for (testnum = 0; testnum < size_num; testnum++) {
2477 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2480 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2482 print_result(D_MD5, testnum, count, d);
2486 # ifndef OPENSSL_NO_DEPRECATED_3_0
2488 static const char hmac_key[] = "This is a key...";
2489 int len = strlen(hmac_key);
2491 for (i = 0; i < loopargs_len; i++) {
2492 loopargs[i].hctx = HMAC_CTX_new();
2493 if (loopargs[i].hctx == NULL) {
2494 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2498 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2500 for (testnum = 0; testnum < size_num; testnum++) {
2501 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2504 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2506 print_result(D_HMAC, testnum, count, d);
2508 for (i = 0; i < loopargs_len; i++)
2509 HMAC_CTX_free(loopargs[i].hctx);
2513 #ifndef OPENSSL_NO_DEPRECATED_3_0
2515 for (testnum = 0; testnum < size_num; testnum++) {
2516 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2519 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2521 print_result(D_SHA1, testnum, count, d);
2524 if (doit[D_SHA256]) {
2525 for (testnum = 0; testnum < size_num; testnum++) {
2526 print_message(names[D_SHA256], c[D_SHA256][testnum],
2527 lengths[testnum], seconds.sym);
2529 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2531 print_result(D_SHA256, testnum, count, d);
2534 if (doit[D_SHA512]) {
2535 for (testnum = 0; testnum < size_num; testnum++) {
2536 print_message(names[D_SHA512], c[D_SHA512][testnum],
2537 lengths[testnum], seconds.sym);
2539 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2541 print_result(D_SHA512, testnum, count, d);
2545 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2546 if (doit[D_WHIRLPOOL]) {
2547 for (testnum = 0; testnum < size_num; testnum++) {
2548 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2549 lengths[testnum], seconds.sym);
2551 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2553 print_result(D_WHIRLPOOL, testnum, count, d);
2558 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2559 if (doit[D_RMD160]) {
2560 for (testnum = 0; testnum < size_num; testnum++) {
2561 print_message(names[D_RMD160], c[D_RMD160][testnum],
2562 lengths[testnum], seconds.sym);
2564 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2566 print_result(D_RMD160, testnum, count, d);
2572 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2574 for (testnum = 0; testnum < size_num; testnum++) {
2575 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2578 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2580 print_result(D_RC4, testnum, count, d);
2584 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2585 if (doit[D_CBC_DES]) {
2586 for (testnum = 0; testnum < size_num; testnum++) {
2587 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2588 lengths[testnum], seconds.sym);
2590 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2592 print_result(D_CBC_DES, testnum, count, d);
2596 if (doit[D_EDE3_DES]) {
2597 for (testnum = 0; testnum < size_num; testnum++) {
2598 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2599 lengths[testnum], seconds.sym);
2602 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2604 print_result(D_EDE3_DES, testnum, count, d);
2609 #ifndef OPENSSL_NO_DEPRECATED_3_0
2610 if (doit[D_CBC_128_AES]) {
2611 for (testnum = 0; testnum < size_num; testnum++) {
2612 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2613 lengths[testnum], seconds.sym);
2616 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2618 print_result(D_CBC_128_AES, testnum, count, d);
2621 if (doit[D_CBC_192_AES]) {
2622 for (testnum = 0; testnum < size_num; testnum++) {
2623 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2624 lengths[testnum], seconds.sym);
2627 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2629 print_result(D_CBC_192_AES, testnum, count, d);
2632 if (doit[D_CBC_256_AES]) {
2633 for (testnum = 0; testnum < size_num; testnum++) {
2634 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2635 lengths[testnum], seconds.sym);
2638 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2640 print_result(D_CBC_256_AES, testnum, count, d);
2645 if (doit[D_IGE_128_AES]) {
2646 for (testnum = 0; testnum < size_num; testnum++) {
2647 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2648 lengths[testnum], seconds.sym);
2651 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2653 print_result(D_IGE_128_AES, testnum, count, d);
2656 if (doit[D_IGE_192_AES]) {
2657 for (testnum = 0; testnum < size_num; testnum++) {
2658 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2659 lengths[testnum], seconds.sym);
2662 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2664 print_result(D_IGE_192_AES, testnum, count, d);
2667 if (doit[D_IGE_256_AES]) {
2668 for (testnum = 0; testnum < size_num; testnum++) {
2669 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2670 lengths[testnum], seconds.sym);
2673 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2675 print_result(D_IGE_256_AES, testnum, count, d);
2678 if (doit[D_GHASH]) {
2679 for (i = 0; i < loopargs_len; i++) {
2680 loopargs[i].gcm_ctx =
2681 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2682 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2683 (unsigned char *)"0123456789ab", 12);
2686 for (testnum = 0; testnum < size_num; testnum++) {
2687 print_message(names[D_GHASH], c[D_GHASH][testnum],
2688 lengths[testnum], seconds.sym);
2690 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2692 print_result(D_GHASH, testnum, count, d);
2694 for (i = 0; i < loopargs_len; i++)
2695 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2697 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
2698 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2699 if (doit[D_CBC_128_CML]) {
2700 if (async_jobs > 0) {
2701 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2702 names[D_CBC_128_CML]);
2703 doit[D_CBC_128_CML] = 0;
2705 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2706 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2707 lengths[testnum], seconds.sym);
2709 for (count = 0; COND(c[D_CBC_128_CML][testnum]); count++)
2710 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2711 (size_t)lengths[testnum], &camellia_ks[0],
2712 iv, CAMELLIA_ENCRYPT);
2714 print_result(D_CBC_128_CML, testnum, count, d);
2717 if (doit[D_CBC_192_CML]) {
2718 if (async_jobs > 0) {
2719 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2720 names[D_CBC_192_CML]);
2721 doit[D_CBC_192_CML] = 0;
2723 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2724 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2725 lengths[testnum], seconds.sym);
2726 if (async_jobs > 0) {
2727 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2731 for (count = 0; COND(c[D_CBC_192_CML][testnum]); count++)
2732 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2733 (size_t)lengths[testnum], &camellia_ks[1],
2734 iv, CAMELLIA_ENCRYPT);
2736 print_result(D_CBC_192_CML, testnum, count, d);
2739 if (doit[D_CBC_256_CML]) {
2740 if (async_jobs > 0) {
2741 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2742 names[D_CBC_256_CML]);
2743 doit[D_CBC_256_CML] = 0;
2745 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2746 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2747 lengths[testnum], seconds.sym);
2749 for (count = 0; COND(c[D_CBC_256_CML][testnum]); count++)
2750 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2751 (size_t)lengths[testnum], &camellia_ks[2],
2752 iv, CAMELLIA_ENCRYPT);
2754 print_result(D_CBC_256_CML, testnum, count, d);
2758 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2759 if (doit[D_CBC_IDEA]) {
2760 if (async_jobs > 0) {
2761 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2763 doit[D_CBC_IDEA] = 0;
2765 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2766 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2767 lengths[testnum], seconds.sym);
2769 for (count = 0; COND(c[D_CBC_IDEA][testnum]); count++)
2770 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2771 (size_t)lengths[testnum], &idea_ks,
2774 print_result(D_CBC_IDEA, testnum, count, d);
2778 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2779 if (doit[D_CBC_SEED]) {
2780 if (async_jobs > 0) {
2781 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2783 doit[D_CBC_SEED] = 0;
2785 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2786 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2787 lengths[testnum], seconds.sym);
2789 for (count = 0; COND(c[D_CBC_SEED][testnum]); count++)
2790 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2791 (size_t)lengths[testnum], &seed_ks, iv, 1);
2793 print_result(D_CBC_SEED, testnum, count, d);
2797 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2798 if (doit[D_CBC_RC2]) {
2799 if (async_jobs > 0) {
2800 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2802 doit[D_CBC_RC2] = 0;
2804 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2805 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2806 lengths[testnum], seconds.sym);
2807 if (async_jobs > 0) {
2808 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2812 for (count = 0; COND(c[D_CBC_RC2][testnum]); count++)
2813 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2814 (size_t)lengths[testnum], &rc2_ks,
2817 print_result(D_CBC_RC2, testnum, count, d);
2821 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2822 if (doit[D_CBC_RC5]) {
2823 if (async_jobs > 0) {
2824 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2826 doit[D_CBC_RC5] = 0;
2828 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2829 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2830 lengths[testnum], seconds.sym);
2831 if (async_jobs > 0) {
2832 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2836 for (count = 0; COND(c[D_CBC_RC5][testnum]); count++)
2837 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2838 (size_t)lengths[testnum], &rc5_ks,
2841 print_result(D_CBC_RC5, testnum, count, d);
2845 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2846 if (doit[D_CBC_BF]) {
2847 if (async_jobs > 0) {
2848 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2852 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2853 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2854 lengths[testnum], seconds.sym);
2856 for (count = 0; COND(c[D_CBC_BF][testnum]); count++)
2857 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2858 (size_t)lengths[testnum], &bf_ks,
2861 print_result(D_CBC_BF, testnum, count, d);
2865 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2866 if (doit[D_CBC_CAST]) {
2867 if (async_jobs > 0) {
2868 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2870 doit[D_CBC_CAST] = 0;
2872 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2873 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2874 lengths[testnum], seconds.sym);
2876 for (count = 0; COND(c[D_CBC_CAST][testnum]); count++)
2877 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2878 (size_t)lengths[testnum], &cast_ks,
2881 print_result(D_CBC_CAST, testnum, count, d);
2886 for (testnum = 0; testnum < size_num; testnum++) {
2887 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2890 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2892 print_result(D_RAND, testnum, count, d);
2897 if (evp_cipher != NULL) {
2898 int (*loopfunc) (void *) = EVP_Update_loop;
2900 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2901 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2902 multiblock_speed(evp_cipher, lengths_single, &seconds);
2907 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2909 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2910 loopfunc = EVP_Update_loop_ccm;
2911 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2912 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2913 loopfunc = EVP_Update_loop_aead;
2914 if (lengths == lengths_list) {
2915 lengths = aead_lengths_list;
2916 size_num = OSSL_NELEM(aead_lengths_list);
2920 for (testnum = 0; testnum < size_num; testnum++) {
2921 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2924 for (k = 0; k < loopargs_len; k++) {
2925 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2926 if (loopargs[k].ctx == NULL) {
2927 BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
2930 if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2931 NULL, iv, decrypt ? 0 : 1)) {
2932 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2933 ERR_print_errors(bio_err);
2937 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2939 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2940 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2941 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2942 if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2943 loopargs[k].key, NULL, -1)) {
2944 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2945 ERR_print_errors(bio_err);
2948 OPENSSL_clear_free(loopargs[k].key, keylen);
2950 /* SIV mode only allows for a single Update operation */
2951 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
2952 EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
2956 count = run_benchmark(async_jobs, loopfunc, loopargs);
2958 for (k = 0; k < loopargs_len; k++) {
2959 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2961 print_result(D_EVP, testnum, count, d);
2963 } else if (evp_md != NULL) {
2964 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2966 for (testnum = 0; testnum < size_num; testnum++) {
2967 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2970 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2972 print_result(D_EVP, testnum, count, d);
2977 #ifndef OPENSSL_NO_DEPRECATED_3_0
2978 if (doit[D_EVP_HMAC] && evp_hmac_md != NULL) {
2979 const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
2981 evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
2983 sprintf(evp_hmac_name, "HMAC(%s)", md_name);
2984 names[D_EVP_HMAC] = evp_hmac_name;
2986 for (testnum = 0; testnum < size_num; testnum++) {
2987 print_message(names[D_EVP_HMAC], c[D_EVP_HMAC][testnum], lengths[testnum],
2990 count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
2992 print_result(D_EVP_HMAC, testnum, count, d);
2997 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2998 if (doit[D_EVP_CMAC] && evp_cmac_cipher != NULL) {
2999 const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
3001 evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
3003 sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
3004 names[D_EVP_CMAC] = evp_cmac_name;
3006 for (i = 0; i < loopargs_len; i++) {
3007 loopargs[i].cmac_ctx = CMAC_CTX_new();
3008 if (loopargs[i].cmac_ctx == NULL) {
3009 BIO_printf(bio_err, "CMAC malloc failure, exiting...");
3013 for (testnum = 0; testnum < size_num; testnum++) {
3014 print_message(names[D_EVP_CMAC], c[D_EVP_CMAC][testnum], lengths[testnum],
3017 count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
3019 print_result(D_EVP_CMAC, testnum, count, d);
3021 for (i = 0; i < loopargs_len; i++)
3022 CMAC_CTX_free(loopargs[i].cmac_ctx);
3026 for (i = 0; i < loopargs_len; i++)
3027 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
3030 #ifndef OPENSSL_NO_DEPRECATED_3_0
3031 for (testnum = 0; testnum < RSA_NUM; testnum++) {
3033 if (!rsa_doit[testnum])
3035 for (i = 0; i < loopargs_len; i++) {
3036 if (primes > RSA_DEFAULT_PRIME_NUM) {
3037 /* we haven't set keys yet, generate multi-prime RSA keys */
3038 BIGNUM *bn = BN_new();
3042 if (!BN_set_word(bn, RSA_F4)) {
3047 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
3048 rsa_choices[testnum].name);
3050 loopargs[i].rsa_key[testnum] = RSA_new();
3051 if (loopargs[i].rsa_key[testnum] == NULL) {
3056 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
3057 rsa_keys[testnum].bits,
3058 primes, bn, NULL)) {
3064 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
3065 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
3071 "RSA sign failure. No RSA sign will be done.\n");
3072 ERR_print_errors(bio_err);
3075 pkey_print_message("private", "rsa",
3076 rsa_c[testnum][0], rsa_keys[testnum].bits,
3078 /* RSA_blinding_on(rsa_key[testnum],NULL); */
3080 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
3083 mr ? "+R1:%ld:%d:%.2f\n"
3084 : "%ld %u bits private RSA's in %.2fs\n",
3085 count, rsa_keys[testnum].bits, d);
3086 rsa_results[testnum][0] = (double)count / d;
3090 for (i = 0; i < loopargs_len; i++) {
3091 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
3092 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
3098 "RSA verify failure. No RSA verify will be done.\n");
3099 ERR_print_errors(bio_err);
3100 rsa_doit[testnum] = 0;
3102 pkey_print_message("public", "rsa",
3103 rsa_c[testnum][1], rsa_keys[testnum].bits,
3106 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
3109 mr ? "+R2:%ld:%d:%.2f\n"
3110 : "%ld %u bits public RSA's in %.2fs\n",
3111 count, rsa_keys[testnum].bits, d);
3112 rsa_results[testnum][1] = (double)count / d;
3115 if (op_count <= 1) {
3116 /* if longer than 10s, don't do any more */
3117 stop_it(rsa_doit, testnum);
3120 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
3122 for (i = 0; i < loopargs_len; i++)
3123 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
3126 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3127 for (testnum = 0; testnum < DSA_NUM; testnum++) {
3129 if (!dsa_doit[testnum])
3132 /* DSA_generate_key(dsa_key[testnum]); */
3133 /* DSA_sign_setup(dsa_key[testnum],NULL); */
3134 for (i = 0; i < loopargs_len; i++) {
3135 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
3136 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
3142 "DSA sign failure. No DSA sign will be done.\n");
3143 ERR_print_errors(bio_err);
3146 pkey_print_message("sign", "dsa",
3147 dsa_c[testnum][0], dsa_bits[testnum],
3150 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
3153 mr ? "+R3:%ld:%u:%.2f\n"
3154 : "%ld %u bits DSA signs in %.2fs\n",
3155 count, dsa_bits[testnum], d);
3156 dsa_results[testnum][0] = (double)count / d;
3160 for (i = 0; i < loopargs_len; i++) {
3161 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3162 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
3168 "DSA verify failure. No DSA verify will be done.\n");
3169 ERR_print_errors(bio_err);
3170 dsa_doit[testnum] = 0;
3172 pkey_print_message("verify", "dsa",
3173 dsa_c[testnum][1], dsa_bits[testnum],
3176 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
3179 mr ? "+R4:%ld:%u:%.2f\n"
3180 : "%ld %u bits DSA verify in %.2fs\n",
3181 count, dsa_bits[testnum], d);
3182 dsa_results[testnum][1] = (double)count / d;
3185 if (op_count <= 1) {
3186 /* if longer than 10s, don't do any more */
3187 stop_it(dsa_doit, testnum);
3190 #endif /* OPENSSL_NO_DSA */
3192 #ifndef OPENSSL_NO_EC
3193 # ifndef OPENSSL_NO_DEPRECATED_3_0
3194 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
3197 if (!ecdsa_doit[testnum])
3198 continue; /* Ignore Curve */
3199 for (i = 0; i < loopargs_len; i++) {
3200 loopargs[i].ecdsa[testnum] =
3201 EC_KEY_new_by_curve_name(ec_curves[testnum].nid);
3202 if (loopargs[i].ecdsa[testnum] == NULL) {
3208 BIO_printf(bio_err, "ECDSA failure.\n");
3209 ERR_print_errors(bio_err);
3212 for (i = 0; i < loopargs_len; i++) {
3213 /* Perform ECDSA signature test */
3214 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
3215 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
3216 &loopargs[i].siglen,
3217 loopargs[i].ecdsa[testnum]);
3223 "ECDSA sign failure. No ECDSA sign will be done.\n");
3224 ERR_print_errors(bio_err);
3227 pkey_print_message("sign", "ecdsa",
3228 ecdsa_c[testnum][0],
3229 ec_curves[testnum].bits, seconds.ecdsa);
3231 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
3235 mr ? "+R5:%ld:%u:%.2f\n" :
3236 "%ld %u bits ECDSA signs in %.2fs \n",
3237 count, ec_curves[testnum].bits, d);
3238 ecdsa_results[testnum][0] = (double)count / d;
3242 /* Perform ECDSA verification test */
3243 for (i = 0; i < loopargs_len; i++) {
3244 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3246 loopargs[i].ecdsa[testnum]);
3252 "ECDSA verify failure. No ECDSA verify will be done.\n");
3253 ERR_print_errors(bio_err);
3254 ecdsa_doit[testnum] = 0;
3256 pkey_print_message("verify", "ecdsa",
3257 ecdsa_c[testnum][1],
3258 ec_curves[testnum].bits, seconds.ecdsa);
3260 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
3263 mr ? "+R6:%ld:%u:%.2f\n"
3264 : "%ld %u bits ECDSA verify in %.2fs\n",
3265 count, ec_curves[testnum].bits, d);
3266 ecdsa_results[testnum][1] = (double)count / d;
3269 if (op_count <= 1) {
3270 /* if longer than 10s, don't do any more */
3271 stop_it(ecdsa_doit, testnum);
3275 # endif /* OPENSSL_NO_DEPRECATED_3_0 */
3277 for (testnum = 0; testnum < EC_NUM; testnum++) {
3278 int ecdh_checks = 1;
3280 if (!ecdh_doit[testnum])
3283 for (i = 0; i < loopargs_len; i++) {
3284 EVP_PKEY_CTX *kctx = NULL;
3285 EVP_PKEY_CTX *test_ctx = NULL;
3286 EVP_PKEY_CTX *ctx = NULL;
3287 EVP_PKEY *key_A = NULL;
3288 EVP_PKEY *key_B = NULL;
3292 /* Ensure that the error queue is empty */
3293 if (ERR_peek_error()) {
3295 "WARNING: the error queue contains previous unhandled errors.\n");
3296 ERR_print_errors(bio_err);
3299 /* Let's try to create a ctx directly from the NID: this works for
3300 * curves like Curve25519 that are not implemented through the low
3301 * level EC interface.
3302 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
3303 * then we set the curve by NID before deriving the actual keygen
3304 * ctx for that specific curve. */
3305 kctx = EVP_PKEY_CTX_new_id(ec_curves[testnum].nid, NULL); /* keygen ctx from NID */
3307 EVP_PKEY_CTX *pctx = NULL;
3308 EVP_PKEY *params = NULL;
3310 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
3311 * "int_ctx_new:unsupported algorithm" error was added to the
3313 * We remove it from the error queue as we are handling it. */
3314 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
3315 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
3316 /* check that the error origin matches */
3317 ERR_GET_LIB(error) == ERR_LIB_EVP &&
3318 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
3319 ERR_get_error(); /* pop error from queue */
3320 if (ERR_peek_error()) {
3322 "Unhandled error in the error queue during ECDH init.\n");
3323 ERR_print_errors(bio_err);
3328 /* Create the context for parameter generation */
3329 if (!(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
3330 /* Initialise the parameter generation */
3331 !EVP_PKEY_paramgen_init(pctx) ||
3332 /* Set the curve by NID */
3333 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3336 /* Create the parameter object params */
3337 !EVP_PKEY_paramgen(pctx, ¶ms)) {
3339 BIO_printf(bio_err, "ECDH EC params init failure.\n");
3340 ERR_print_errors(bio_err);
3344 /* Create the context for the key generation */
3345 kctx = EVP_PKEY_CTX_new(params, NULL);
3347 EVP_PKEY_free(params);
3349 EVP_PKEY_CTX_free(pctx);
3352 if (kctx == NULL || /* keygen ctx is not null */
3353 EVP_PKEY_keygen_init(kctx) <= 0/* init keygen ctx */ ) {
3355 BIO_printf(bio_err, "ECDH keygen failure.\n");
3356 ERR_print_errors(bio_err);
3361 if (EVP_PKEY_keygen(kctx, &key_A) <= 0 || /* generate secret key A */
3362 EVP_PKEY_keygen(kctx, &key_B) <= 0 || /* generate secret key B */
3363 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
3364 EVP_PKEY_derive_init(ctx) <= 0 || /* init derivation ctx */
3365 EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 || /* set peer pubkey in ctx */
3366 EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 || /* determine max length */
3367 outlen == 0 || /* ensure outlen is a valid size */
3368 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
3370 BIO_printf(bio_err, "ECDH key generation failure.\n");
3371 ERR_print_errors(bio_err);
3376 /* Here we perform a test run, comparing the output of a*B and b*A;
3377 * we try this here and assume that further EVP_PKEY_derive calls
3378 * never fail, so we can skip checks in the actually benchmarked
3379 * code, for maximum performance. */
3380 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3381 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3382 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3383 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3384 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3385 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3386 test_outlen != outlen /* compare output length */ ) {
3388 BIO_printf(bio_err, "ECDH computation failure.\n");
3389 ERR_print_errors(bio_err);
3394 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3395 if (CRYPTO_memcmp(loopargs[i].secret_a,
3396 loopargs[i].secret_b, outlen)) {
3398 BIO_printf(bio_err, "ECDH computations don't match.\n");
3399 ERR_print_errors(bio_err);
3404 loopargs[i].ecdh_ctx[testnum] = ctx;
3405 loopargs[i].outlen[testnum] = outlen;
3407 EVP_PKEY_free(key_A);
3408 EVP_PKEY_free(key_B);
3409 EVP_PKEY_CTX_free(kctx);
3411 EVP_PKEY_CTX_free(test_ctx);
3414 if (ecdh_checks != 0) {
3415 pkey_print_message("", "ecdh",
3417 ec_curves[testnum].bits, seconds.ecdh);
3420 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3423 mr ? "+R7:%ld:%d:%.2f\n" :
3424 "%ld %u-bits ECDH ops in %.2fs\n", count,
3425 ec_curves[testnum].bits, d);
3426 ecdh_results[testnum][0] = (double)count / d;
3430 if (op_count <= 1) {
3431 /* if longer than 10s, don't do any more */
3432 stop_it(ecdh_doit, testnum);
3436 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3438 EVP_PKEY *ed_pkey = NULL;
3439 EVP_PKEY_CTX *ed_pctx = NULL;
3441 if (!eddsa_doit[testnum])
3442 continue; /* Ignore Curve */
3443 for (i = 0; i < loopargs_len; i++) {
3444 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3445 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3449 loopargs[i].eddsa_ctx2[testnum] = EVP_MD_CTX_new();
3450 if (loopargs[i].eddsa_ctx2[testnum] == NULL) {
3455 if ((ed_pctx = EVP_PKEY_CTX_new_id(ed_curves[testnum].nid, NULL))
3457 || EVP_PKEY_keygen_init(ed_pctx) <= 0
3458 || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) {
3460 EVP_PKEY_CTX_free(ed_pctx);
3463 EVP_PKEY_CTX_free(ed_pctx);
3465 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3468 EVP_PKEY_free(ed_pkey);
3471 if (!EVP_DigestVerifyInit(loopargs[i].eddsa_ctx2[testnum], NULL,
3472 NULL, NULL, ed_pkey)) {
3474 EVP_PKEY_free(ed_pkey);
3478 EVP_PKEY_free(ed_pkey);
3482 BIO_printf(bio_err, "EdDSA failure.\n");
3483 ERR_print_errors(bio_err);
3486 for (i = 0; i < loopargs_len; i++) {
3487 /* Perform EdDSA signature test */
3488 loopargs[i].sigsize = ed_curves[testnum].sigsize;
3489 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3490 loopargs[i].buf2, &loopargs[i].sigsize,
3491 loopargs[i].buf, 20);
3497 "EdDSA sign failure. No EdDSA sign will be done.\n");
3498 ERR_print_errors(bio_err);
3501 pkey_print_message("sign", ed_curves[testnum].name,
3502 eddsa_c[testnum][0],
3503 ed_curves[testnum].bits, seconds.eddsa);
3505 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3509 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3510 "%ld %u bits %s signs in %.2fs \n",
3511 count, ed_curves[testnum].bits,
3512 ed_curves[testnum].name, d);
3513 eddsa_results[testnum][0] = (double)count / d;
3516 /* Perform EdDSA verification test */
3517 for (i = 0; i < loopargs_len; i++) {
3518 st = EVP_DigestVerify(loopargs[i].eddsa_ctx2[testnum],
3519 loopargs[i].buf2, loopargs[i].sigsize,
3520 loopargs[i].buf, 20);
3526 "EdDSA verify failure. No EdDSA verify will be done.\n");
3527 ERR_print_errors(bio_err);
3528 eddsa_doit[testnum] = 0;
3530 pkey_print_message("verify", ed_curves[testnum].name,
3531 eddsa_c[testnum][1],
3532 ed_curves[testnum].bits, seconds.eddsa);
3534 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3537 mr ? "+R9:%ld:%u:%s:%.2f\n"
3538 : "%ld %u bits %s verify in %.2fs\n",
3539 count, ed_curves[testnum].bits,
3540 ed_curves[testnum].name, d);
3541 eddsa_results[testnum][1] = (double)count / d;
3544 if (op_count <= 1) {
3545 /* if longer than 10s, don't do any more */
3546 stop_it(eddsa_doit, testnum);
3551 # ifndef OPENSSL_NO_SM2
3552 for (testnum = 0; testnum < SM2_NUM; testnum++) {
3554 EVP_PKEY *sm2_pkey = NULL;
3556 if (!sm2_doit[testnum])
3557 continue; /* Ignore Curve */
3558 /* Init signing and verification */
3559 for (i = 0; i < loopargs_len; i++) {
3560 EVP_PKEY_CTX *sm2_pctx = NULL;
3561 EVP_PKEY_CTX *sm2_vfy_pctx = NULL;
3562 EVP_PKEY_CTX *pctx = NULL;
3565 loopargs[i].sm2_ctx[testnum] = EVP_MD_CTX_new();
3566 loopargs[i].sm2_vfy_ctx[testnum] = EVP_MD_CTX_new();
3567 if (loopargs[i].sm2_ctx[testnum] == NULL
3568 || loopargs[i].sm2_vfy_ctx[testnum] == NULL)
3573 st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_SM2, NULL)) == NULL
3574 || EVP_PKEY_keygen_init(pctx) <= 0
3575 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3576 sm2_curves[testnum].nid) <= 0
3577 || EVP_PKEY_keygen(pctx, &sm2_pkey) <= 0);
3578 EVP_PKEY_CTX_free(pctx);
3582 st = 0; /* set back to zero */
3583 /* attach it sooner to rely on main final cleanup */
3584 loopargs[i].sm2_pkey[testnum] = sm2_pkey;
3585 loopargs[i].sigsize = EVP_PKEY_size(sm2_pkey);
3587 sm2_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3588 sm2_vfy_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3589 if (sm2_pctx == NULL || sm2_vfy_pctx == NULL) {
3590 EVP_PKEY_CTX_free(sm2_vfy_pctx);
3594 /* attach them directly to respective ctx */
3595 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_ctx[testnum], sm2_pctx);
3596 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_vfy_ctx[testnum], sm2_vfy_pctx);
3599 * No need to allow user to set an explicit ID here, just use
3600 * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D.
3602 if (EVP_PKEY_CTX_set1_id(sm2_pctx, SM2_ID, SM2_ID_LEN) != 1
3603 || EVP_PKEY_CTX_set1_id(sm2_vfy_pctx, SM2_ID, SM2_ID_LEN) != 1)
3606 if (!EVP_DigestSignInit(loopargs[i].sm2_ctx[testnum], NULL,
3607 EVP_sm3(), NULL, sm2_pkey))
3609 if (!EVP_DigestVerifyInit(loopargs[i].sm2_vfy_ctx[testnum], NULL,
3610 EVP_sm3(), NULL, sm2_pkey))
3612 st = 1; /* mark loop as succeeded */
3615 BIO_printf(bio_err, "SM2 init failure.\n");
3616 ERR_print_errors(bio_err);
3619 for (i = 0; i < loopargs_len; i++) {
3620 /* Perform SM2 signature test */
3621 st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum],
3622 loopargs[i].buf2, &loopargs[i].sigsize,
3623 loopargs[i].buf, 20);
3629 "SM2 sign failure. No SM2 sign will be done.\n");
3630 ERR_print_errors(bio_err);
3633 pkey_print_message("sign", sm2_curves[testnum].name,
3635 sm2_curves[testnum].bits, seconds.sm2);
3637 count = run_benchmark(async_jobs, SM2_sign_loop, loopargs);
3641 mr ? "+R10:%ld:%u:%s:%.2f\n" :
3642 "%ld %u bits %s signs in %.2fs \n",
3643 count, sm2_curves[testnum].bits,
3644 sm2_curves[testnum].name, d);
3645 sm2_results[testnum][0] = (double)count / d;
3649 /* Perform SM2 verification test */
3650 for (i = 0; i < loopargs_len; i++) {
3651 st = EVP_DigestVerify(loopargs[i].sm2_vfy_ctx[testnum],
3652 loopargs[i].buf2, loopargs[i].sigsize,
3653 loopargs[i].buf, 20);
3659 "SM2 verify failure. No SM2 verify will be done.\n");
3660 ERR_print_errors(bio_err);
3661 sm2_doit[testnum] = 0;
3663 pkey_print_message("verify", sm2_curves[testnum].name,
3665 sm2_curves[testnum].bits, seconds.sm2);
3667 count = run_benchmark(async_jobs, SM2_verify_loop, loopargs);
3670 mr ? "+R11:%ld:%u:%s:%.2f\n"
3671 : "%ld %u bits %s verify in %.2fs\n",
3672 count, sm2_curves[testnum].bits,
3673 sm2_curves[testnum].name, d);
3674 sm2_results[testnum][1] = (double)count / d;
3677 if (op_count <= 1) {
3678 /* if longer than 10s, don't do any more */
3679 for (testnum++; testnum < SM2_NUM; testnum++)
3680 sm2_doit[testnum] = 0;
3684 # endif /* OPENSSL_NO_SM2 */
3685 #endif /* OPENSSL_NO_EC */
3687 #ifndef OPENSSL_NO_DH
3688 for (testnum = 0; testnum < FFDH_NUM; testnum++) {
3689 int ffdh_checks = 1;
3691 if (!ffdh_doit[testnum])
3694 for (i = 0; i < loopargs_len; i++) {
3695 EVP_PKEY *pkey_A = NULL;
3696 EVP_PKEY *pkey_B = NULL;
3697 EVP_PKEY_CTX *ffdh_ctx = NULL;
3698 EVP_PKEY_CTX *test_ctx = NULL;
3702 /* Ensure that the error queue is empty */
3703 if (ERR_peek_error()) {
3705 "WARNING: the error queue contains previous unhandled errors.\n");
3706 ERR_print_errors(bio_err);
3709 pkey_A = EVP_PKEY_new();
3711 BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n");
3712 ERR_print_errors(bio_err);
3717 pkey_B = EVP_PKEY_new();
3719 BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n");
3720 ERR_print_errors(bio_err);
3726 ffdh_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DH, NULL);
3728 BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
3729 ERR_print_errors(bio_err);
3735 if (EVP_PKEY_keygen_init(ffdh_ctx) <= 0) {
3736 BIO_printf(bio_err, "Error while initialising EVP_PKEY_CTX.\n");
3737 ERR_print_errors(bio_err);
3742 if (EVP_PKEY_CTX_set_dh_nid(ffdh_ctx, ffdh_params[testnum].nid) <= 0) {
3743 BIO_printf(bio_err, "Error setting DH key size for keygen.\n");
3744 ERR_print_errors(bio_err);
3750 if (EVP_PKEY_keygen(ffdh_ctx, &pkey_A) <= 0 ||
3751 EVP_PKEY_keygen(ffdh_ctx, &pkey_B) <= 0) {
3752 BIO_printf(bio_err, "FFDH key generation failure.\n");
3753 ERR_print_errors(bio_err);
3759 EVP_PKEY_CTX_free(ffdh_ctx);
3761 /* check if the derivation works correctly both ways so that
3762 * we know if future derive calls will fail, and we can skip
3763 * error checking in benchmarked code */
3764 ffdh_ctx = EVP_PKEY_CTX_new(pkey_A, NULL);
3766 BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
3767 ERR_print_errors(bio_err);
3772 if (EVP_PKEY_derive_init(ffdh_ctx) <= 0) {
3773 BIO_printf(bio_err, "FFDH derivation context init failure.\n");
3774 ERR_print_errors(bio_err);
3779 if (EVP_PKEY_derive_set_peer(ffdh_ctx, pkey_B) <= 0) {
3780 BIO_printf(bio_err, "Assigning peer key for derivation failed.\n");
3781 ERR_print_errors(bio_err);
3786 if (EVP_PKEY_derive(ffdh_ctx, NULL, &secret_size) <= 0) {
3787 BIO_printf(bio_err, "Checking size of shared secret failed.\n");
3788 ERR_print_errors(bio_err);
3793 if (secret_size > MAX_FFDH_SIZE) {
3794 BIO_printf(bio_err, "Assertion failure: shared secret too large.\n");
3799 if (EVP_PKEY_derive(ffdh_ctx,
3800 loopargs[i].secret_ff_a,
3801 &secret_size) <= 0) {
3802 BIO_printf(bio_err, "Shared secret derive failure.\n");
3803 ERR_print_errors(bio_err);
3808 /* Now check from side B */
3809 test_ctx = EVP_PKEY_CTX_new(pkey_B, NULL);
3811 BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
3812 ERR_print_errors(bio_err);
3817 if (!EVP_PKEY_derive_init(test_ctx) ||
3818 !EVP_PKEY_derive_set_peer(test_ctx, pkey_A) ||
3819 !EVP_PKEY_derive(test_ctx, NULL, &test_out) ||
3820 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_ff_b, &test_out) ||
3821 test_out != secret_size) {
3822 BIO_printf(bio_err, "FFDH computation failure.\n");
3828 /* compare the computed secrets */
3829 if (CRYPTO_memcmp(loopargs[i].secret_ff_a,
3830 loopargs[i].secret_ff_b, secret_size)) {
3831 BIO_printf(bio_err, "FFDH computations don't match.\n");
3832 ERR_print_errors(bio_err);
3838 loopargs[i].ffdh_ctx[testnum] = ffdh_ctx;
3840 EVP_PKEY_free(pkey_A);
3842 EVP_PKEY_free(pkey_B);
3844 EVP_PKEY_CTX_free(test_ctx);
3847 if (ffdh_checks != 0) {
3848 pkey_print_message("", "ffdh", ffdh_c[testnum][0],
3849 ffdh_params[testnum].bits, seconds.ffdh);
3852 run_benchmark(async_jobs, FFDH_derive_key_loop, loopargs);
3855 mr ? "+R12:%ld:%d:%.2f\n" :
3856 "%ld %u-bits FFDH ops in %.2fs\n", count,
3857 ffdh_params[testnum].bits, d);
3858 ffdh_results[testnum][0] = (double)count / d;
3861 if (op_count <= 1) {
3862 /* if longer than 10s, don't do any more */
3863 stop_it(ffdh_doit, testnum);
3866 #endif /* OPENSSL_NO_DH */
3871 printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
3872 printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3874 printf("%s ", BN_options());
3875 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3876 printf("%s ", MD2_options());
3878 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3879 printf("%s ", RC4_options());
3881 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3882 printf("%s ", DES_options());
3884 #ifndef OPENSSL_NO_DEPRECATED_3_0
3885 printf("%s ", AES_options());
3887 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3888 printf("%s ", IDEA_options());
3890 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3891 printf("%s ", BF_options());
3893 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3894 printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
3902 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3905 for (testnum = 0; testnum < size_num; testnum++)
3906 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3910 for (k = 0; k < ALGOR_NUM; k++) {
3914 printf("+F:%u:%s", k, names[k]);
3916 printf("%-13s", names[k]);
3917 for (testnum = 0; testnum < size_num; testnum++) {
3918 if (results[k][testnum] > 10000 && !mr)
3919 printf(" %11.2fk", results[k][testnum] / 1e3);
3921 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3925 #ifndef OPENSSL_NO_DEPRECATED_3_0
3927 for (k = 0; k < RSA_NUM; k++) {
3930 if (testnum && !mr) {
3931 printf("%18ssign verify sign/s verify/s\n", " ");
3935 printf("+F2:%u:%u:%f:%f\n",
3936 k, rsa_keys[k].bits, rsa_results[k][0], rsa_results[k][1]);
3938 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3939 rsa_keys[k].bits, 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3940 rsa_results[k][0], rsa_results[k][1]);
3943 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3945 for (k = 0; k < DSA_NUM; k++) {
3948 if (testnum && !mr) {
3949 printf("%18ssign verify sign/s verify/s\n", " ");
3953 printf("+F3:%u:%u:%f:%f\n",
3954 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3956 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3957 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3958 dsa_results[k][0], dsa_results[k][1]);
3961 #ifndef OPENSSL_NO_EC
3963 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3966 if (testnum && !mr) {
3967 printf("%30ssign verify sign/s verify/s\n", " ");
3972 printf("+F4:%u:%u:%f:%f\n",
3973 k, ec_curves[k].bits,
3974 ecdsa_results[k][0], ecdsa_results[k][1]);
3976 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3977 ec_curves[k].bits, ec_curves[k].name,
3978 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3979 ecdsa_results[k][0], ecdsa_results[k][1]);
3983 for (k = 0; k < EC_NUM; k++) {
3986 if (testnum && !mr) {
3987 printf("%30sop op/s\n", " ");
3991 printf("+F5:%u:%u:%f:%f\n",
3992 k, ec_curves[k].bits,
3993 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3996 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3997 ec_curves[k].bits, ec_curves[k].name,
3998 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
4002 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
4005 if (testnum && !mr) {
4006 printf("%30ssign verify sign/s verify/s\n", " ");
4011 printf("+F6:%u:%u:%s:%f:%f\n",
4012 k, ed_curves[k].bits, ed_curves[k].name,
4013 eddsa_results[k][0], eddsa_results[k][1]);
4015 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
4016 ed_curves[k].bits, ed_curves[k].name,
4017 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
4018 eddsa_results[k][0], eddsa_results[k][1]);
4021 # ifndef OPENSSL_NO_SM2
4023 for (k = 0; k < OSSL_NELEM(sm2_doit); k++) {
4026 if (testnum && !mr) {
4027 printf("%30ssign verify sign/s verify/s\n", " ");
4032 printf("+F7:%u:%u:%s:%f:%f\n",
4033 k, sm2_curves[k].bits, sm2_curves[k].name,
4034 sm2_results[k][0], sm2_results[k][1]);
4036 printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
4037 sm2_curves[k].bits, sm2_curves[k].name,
4038 1.0 / sm2_results[k][0], 1.0 / sm2_results[k][1],
4039 sm2_results[k][0], sm2_results[k][1]);
4042 #endif /* OPENSSL_NO_EC */
4043 #ifndef OPENSSL_NO_DH
4045 for (k = 0; k < FFDH_NUM; k++) {
4048 if (testnum && !mr) {
4049 printf("%23sop op/s\n", " ");
4053 printf("+F8:%u:%u:%f:%f\n",
4054 k, ffdh_params[k].bits,
4055 ffdh_results[k][0], 1.0 / ffdh_results[k][0]);
4058 printf("%4u bits ffdh %8.4fs %8.1f\n",
4059 ffdh_params[k].bits,
4060 1.0 / ffdh_results[k][0], ffdh_results[k][0]);
4062 #endif /* OPENSSL_NO_DH */
4067 ERR_print_errors(bio_err);
4068 for (i = 0; i < loopargs_len; i++) {
4069 OPENSSL_free(loopargs[i].buf_malloc);
4070 OPENSSL_free(loopargs[i].buf2_malloc);
4072 #ifndef OPENSSL_NO_DEPRECATED_3_0
4073 for (k = 0; k < RSA_NUM; k++)
4074 RSA_free(loopargs[i].rsa_key[k]);
4076 #ifndef OPENSSL_NO_DH
4077 OPENSSL_free(loopargs[i].secret_ff_a);
4078 OPENSSL_free(loopargs[i].secret_ff_b);
4079 for (k = 0; k < FFDH_NUM; k++) {
4080 EVP_PKEY_CTX_free(loopargs[i].ffdh_ctx[k]);
4083 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4084 for (k = 0; k < DSA_NUM; k++)
4085 DSA_free(loopargs[i].dsa_key[k]);
4087 #ifndef OPENSSL_NO_EC
4088 # if !defined(OPENSSL_NO_DEPRECATED_3_0)
4089 for (k = 0; k < ECDSA_NUM; k++)
4090 EC_KEY_free(loopargs[i].ecdsa[k]);
4092 for (k = 0; k < EC_NUM; k++)
4093 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
4094 for (k = 0; k < EdDSA_NUM; k++) {
4095 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
4096 EVP_MD_CTX_free(loopargs[i].eddsa_ctx2[k]);
4098 # ifndef OPENSSL_NO_SM2
4099 for (k = 0; k < SM2_NUM; k++) {
4100 EVP_PKEY_CTX *pctx = NULL;
4102 /* free signing ctx */
4103 if (loopargs[i].sm2_ctx[k] != NULL
4104 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_ctx[k])) != NULL)
4105 EVP_PKEY_CTX_free(pctx);
4106 EVP_MD_CTX_free(loopargs[i].sm2_ctx[k]);
4107 /* free verification ctx */
4108 if (loopargs[i].sm2_vfy_ctx[k] != NULL
4109 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_vfy_ctx[k])) != NULL)
4110 EVP_PKEY_CTX_free(pctx);
4111 EVP_MD_CTX_free(loopargs[i].sm2_vfy_ctx[k]);
4113 EVP_PKEY_free(loopargs[i].sm2_pkey[k]);
4116 OPENSSL_free(loopargs[i].secret_a);
4117 OPENSSL_free(loopargs[i].secret_b);
4120 #ifndef OPENSSL_NO_DEPRECATED_3_0
4121 OPENSSL_free(evp_hmac_name);
4123 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4124 OPENSSL_free(evp_cmac_name);
4127 if (async_jobs > 0) {
4128 for (i = 0; i < loopargs_len; i++)
4129 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
4133 ASYNC_cleanup_thread();
4135 OPENSSL_free(loopargs);
4138 EVP_MD_free(evp_md);
4139 EVP_CIPHER_free(evp_cipher);
4144 static void print_message(const char *s, long num, int length, int tm)
4148 mr ? "+DT:%s:%d:%d\n"
4149 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
4150 (void)BIO_flush(bio_err);
4155 mr ? "+DN:%s:%ld:%d\n"
4156 : "Doing %s %ld times on %d size blocks: ", s, num, length);
4157 (void)BIO_flush(bio_err);
4161 #if !defined(OPENSSL_NO_DEPRECATED_3_0) \
4162 || !defined(OPENSSL_NO_DSA) \
4163 || !defined(OPENSSL_NO_DH) \
4164 || !defined(OPENSSL_NO_EC)
4165 static void pkey_print_message(const char *str, const char *str2, long num,
4166 unsigned int bits, int tm)
4170 mr ? "+DTP:%d:%s:%s:%d\n"
4171 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
4172 (void)BIO_flush(bio_err);
4177 mr ? "+DNP:%ld:%d:%s:%s\n"
4178 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
4179 (void)BIO_flush(bio_err);
4184 static void print_result(int alg, int run_no, int count, double time_used)
4187 BIO_printf(bio_err, "%s error!\n", names[alg]);
4188 ERR_print_errors(bio_err);
4189 /* exit(1); disable exit until default provider enabled */
4193 mr ? "+R:%d:%s:%f\n"
4194 : "%d %s's in %.2fs\n", count, names[alg], time_used);
4195 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
4199 static char *sstrsep(char **string, const char *delim)
4202 char *token = *string;
4207 memset(isdelim, 0, sizeof(isdelim));
4211 isdelim[(unsigned char)(*delim)] = 1;
4215 while (!isdelim[(unsigned char)(**string)]) {
4227 static int do_multi(int multi, int size_num)
4232 static char sep[] = ":";
4234 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
4235 for (n = 0; n < multi; ++n) {
4236 if (pipe(fd) == -1) {
4237 BIO_printf(bio_err, "pipe failure\n");
4241 (void)BIO_flush(bio_err);
4248 if (dup(fd[1]) == -1) {
4249 BIO_printf(bio_err, "dup failed\n");
4258 printf("Forked child %d\n", n);
4261 /* for now, assume the pipe is long enough to take all the output */
4262 for (n = 0; n < multi; ++n) {
4267 f = fdopen(fds[n], "r");
4268 while (fgets(buf, sizeof(buf), f)) {
4269 p = strchr(buf, '\n');
4272 if (buf[0] != '+') {
4274 "Don't understand line '%s' from child %d\n", buf,
4278 printf("Got: %s from %d\n", buf, n);
4279 if (strncmp(buf, "+F:", 3) == 0) {
4284 alg = atoi(sstrsep(&p, sep));
4286 for (j = 0; j < size_num; ++j)
4287 results[alg][j] += atof(sstrsep(&p, sep));
4289 #ifndef OPENSSL_NO_DEPRECATED_3_0
4290 else if (strncmp(buf, "+F2:", 4) == 0) {
4295 k = atoi(sstrsep(&p, sep));
4298 d = atof(sstrsep(&p, sep));
4299 rsa_results[k][0] += d;
4301 d = atof(sstrsep(&p, sep));
4302 rsa_results[k][1] += d;
4305 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4306 else if (strncmp(buf, "+F3:", 4) == 0) {
4311 k = atoi(sstrsep(&p, sep));
4314 d = atof(sstrsep(&p, sep));
4315 dsa_results[k][0] += d;
4317 d = atof(sstrsep(&p, sep));
4318 dsa_results[k][1] += d;
4321 # ifndef OPENSSL_NO_EC
4322 else if (strncmp(buf, "+F4:", 4) == 0) {
4327 k = atoi(sstrsep(&p, sep));
4330 d = atof(sstrsep(&p, sep));
4331 ecdsa_results[k][0] += d;
4333 d = atof(sstrsep(&p, sep));
4334 ecdsa_results[k][1] += d;
4335 } else if (strncmp(buf, "+F5:", 4) == 0) {
4340 k = atoi(sstrsep(&p, sep));
4343 d = atof(sstrsep(&p, sep));
4344 ecdh_results[k][0] += d;
4345 } else if (strncmp(buf, "+F6:", 4) == 0) {
4350 k = atoi(sstrsep(&p, sep));
4354 d = atof(sstrsep(&p, sep));
4355 eddsa_results[k][0] += d;
4357 d = atof(sstrsep(&p, sep));
4358 eddsa_results[k][1] += d;
4360 # ifndef OPENSSL_NO_SM2
4361 else if (strncmp(buf, "+F7:", 4) == 0) {
4366 k = atoi(sstrsep(&p, sep));
4370 d = atof(sstrsep(&p, sep));
4371 sm2_results[k][0] += d;
4373 d = atof(sstrsep(&p, sep));
4374 sm2_results[k][1] += d;
4376 # endif /* OPENSSL_NO_SM2 */
4377 # endif /* OPENSSL_NO_EC */
4378 # ifndef OPENSSL_NO_DH
4379 else if (strncmp(buf, "+F8:", 4) == 0) {
4384 k = atoi(sstrsep(&p, sep));
4387 d = atof(sstrsep(&p, sep));
4388 ffdh_results[k][0] += d;
4390 # endif /* OPENSSL_NO_DH */
4392 else if (strncmp(buf, "+H:", 3) == 0) {
4395 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
4406 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
4407 const openssl_speed_sec_t *seconds)
4409 static const int mblengths_list[] =
4410 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
4411 const int *mblengths = mblengths_list;
4412 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
4413 const char *alg_name;
4414 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
4415 EVP_CIPHER_CTX *ctx;
4418 if (lengths_single) {
4419 mblengths = &lengths_single;
4423 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
4424 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
4425 ctx = EVP_CIPHER_CTX_new();
4426 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
4428 keylen = EVP_CIPHER_CTX_key_length(ctx);
4429 key = app_malloc(keylen, "evp_cipher key");
4430 EVP_CIPHER_CTX_rand_key(ctx, key);
4431 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
4432 OPENSSL_clear_free(key, keylen);
4434 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
4435 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
4437 for (j = 0; j < num; j++) {
4438 print_message(alg_name, 0, mblengths[j], seconds->sym);
4440 for (count = 0; run && count < 0x7fffffff; count++) {
4441 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
4442 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
4443 size_t len = mblengths[j];
4446 memset(aad, 0, 8); /* avoid uninitialized values */
4447 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
4448 aad[9] = 3; /* version */
4450 aad[11] = 0; /* length */
4452 mb_param.out = NULL;
4455 mb_param.interleave = 8;
4457 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
4458 sizeof(mb_param), &mb_param);
4464 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
4465 sizeof(mb_param), &mb_param);
4469 RAND_bytes(out, 16);
4471 aad[11] = (unsigned char)(len >> 8);
4472 aad[12] = (unsigned char)(len);
4473 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
4474 EVP_AEAD_TLS1_AAD_LEN, aad);
4475 EVP_Cipher(ctx, out, inp, len + pad);
4479 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
4480 : "%d %s's in %.2fs\n", count, "evp", d);
4481 results[D_EVP][j] = ((double)count) / d * mblengths[j];
4485 fprintf(stdout, "+H");
4486 for (j = 0; j < num; j++)
4487 fprintf(stdout, ":%d", mblengths[j]);
4488 fprintf(stdout, "\n");
4489 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
4490 for (j = 0; j < num; j++)
4491 fprintf(stdout, ":%.2f", results[D_EVP][j]);
4492 fprintf(stdout, "\n");
4495 "The 'numbers' are in 1000s of bytes per second processed.\n");
4496 fprintf(stdout, "type ");
4497 for (j = 0; j < num; j++)
4498 fprintf(stdout, "%7d bytes", mblengths[j]);
4499 fprintf(stdout, "\n");
4500 fprintf(stdout, "%-24s", alg_name);
4502 for (j = 0; j < num; j++) {
4503 if (results[D_EVP][j] > 10000)
4504 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
4506 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
4508 fprintf(stdout, "\n");
4513 EVP_CIPHER_CTX_free(ctx);