2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #define RSA_SECONDS 10
14 #define DSA_SECONDS 10
15 #define ECDSA_SECONDS 10
16 #define ECDH_SECONDS 10
17 #define EdDSA_SECONDS 10
18 #define SM2_SECONDS 10
20 /* We need to use some deprecated APIs */
21 #define OPENSSL_SUPPRESS_DEPRECATED
29 #include <openssl/crypto.h>
30 #include <openssl/rand.h>
31 #include <openssl/err.h>
32 #include <openssl/evp.h>
33 #include <openssl/objects.h>
34 #include <openssl/async.h>
35 #if !defined(OPENSSL_SYS_MSDOS)
43 #include <openssl/bn.h>
44 #ifndef OPENSSL_NO_DES
45 # include <openssl/des.h>
47 #ifndef OPENSSL_NO_DEPRECATED_3_0
48 #include <openssl/aes.h>
50 #ifndef OPENSSL_NO_CAMELLIA
51 # include <openssl/camellia.h>
53 #ifndef OPENSSL_NO_MD2
54 # include <openssl/md2.h>
56 #ifndef OPENSSL_NO_MDC2
57 # include <openssl/mdc2.h>
59 #ifndef OPENSSL_NO_MD4
60 # include <openssl/md4.h>
62 #ifndef OPENSSL_NO_MD5
63 # include <openssl/md5.h>
65 #include <openssl/hmac.h>
66 #ifndef OPENSSL_NO_CMAC
67 #include <openssl/cmac.h>
69 #include <openssl/sha.h>
70 #ifndef OPENSSL_NO_RMD160
71 # include <openssl/ripemd.h>
73 #ifndef OPENSSL_NO_WHIRLPOOL
74 # include <openssl/whrlpool.h>
76 #ifndef OPENSSL_NO_RC4
77 # include <openssl/rc4.h>
79 #ifndef OPENSSL_NO_RC5
80 # include <openssl/rc5.h>
82 #ifndef OPENSSL_NO_RC2
83 # include <openssl/rc2.h>
85 #ifndef OPENSSL_NO_IDEA
86 # include <openssl/idea.h>
88 #ifndef OPENSSL_NO_SEED
89 # include <openssl/seed.h>
92 # include <openssl/blowfish.h>
94 #ifndef OPENSSL_NO_CAST
95 # include <openssl/cast.h>
97 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
98 # include <openssl/rsa.h>
99 # include "./testrsa.h"
101 #include <openssl/x509.h>
102 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
103 # include <openssl/dsa.h>
104 # include "./testdsa.h"
106 #ifndef OPENSSL_NO_EC
107 # include <openssl/ec.h>
109 #include <openssl/modes.h>
112 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
125 #define MAX_MISALIGNMENT 63
126 #define MAX_ECDH_SIZE 256
129 typedef struct openssl_speed_sec_st {
137 } openssl_speed_sec_t;
139 static volatile int run = 0;
141 static int mr = 0; /* machine-readeable output format to merge fork results */
142 static int usertime = 1;
144 static double Time_F(int s);
145 static void print_message(const char *s, long num, int length, int tm);
146 static void pkey_print_message(const char *str, const char *str2,
147 long num, unsigned int bits, int sec);
148 static void print_result(int alg, int run_no, int count, double time_used);
150 static int do_multi(int multi, int size_num);
153 static const int lengths_list[] = {
154 16, 64, 256, 1024, 8 * 1024, 16 * 1024
156 #define SIZE_NUM OSSL_NELEM(lengths_list)
157 static const int *lengths = lengths_list;
159 static const int aead_lengths_list[] = {
160 2, 31, 136, 1024, 8 * 1024, 16 * 1024
168 static void alarmed(int sig)
170 signal(SIGALRM, alarmed);
174 static double Time_F(int s)
176 double ret = app_tminterval(s, usertime);
182 #elif defined(_WIN32)
186 static unsigned int lapse;
187 static volatile unsigned int schlock;
188 static void alarm_win32(unsigned int secs)
193 # define alarm alarm_win32
195 static DWORD WINAPI sleepy(VOID * arg)
203 static double Time_F(int s)
210 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
212 DWORD err = GetLastError();
213 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
217 Sleep(0); /* scheduler spinlock */
218 ret = app_tminterval(s, usertime);
220 ret = app_tminterval(s, usertime);
222 TerminateThread(thr, 0);
229 static double Time_F(int s)
231 return app_tminterval(s, usertime);
235 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
236 const openssl_speed_sec_t *seconds);
238 static int opt_found(const char *name, unsigned int *result,
239 const OPT_PAIR pairs[], unsigned int nbelem)
243 for (idx = 0; idx < nbelem; ++idx, pairs++)
244 if (strcmp(name, pairs->name) == 0) {
245 *result = pairs->retval;
250 #define opt_found(value, pairs, result)\
251 opt_found(value, result, pairs, OSSL_NELEM(pairs))
253 typedef enum OPTION_choice {
254 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
255 OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
256 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM, OPT_PROV_ENUM,
257 OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC
260 const OPTIONS speed_options[] = {
261 {OPT_HELP_STR, 1, '-', "Usage: %s [options] [algorithm...]\n"},
263 OPT_SECTION("General"),
264 {"help", OPT_HELP, '-', "Display this summary"},
266 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
267 {"mr", OPT_MR, '-', "Produce machine readable output"},
269 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
271 #ifndef OPENSSL_NO_ASYNC
272 {"async_jobs", OPT_ASYNCJOBS, 'p',
273 "Enable async mode and start specified number of jobs"},
275 #ifndef OPENSSL_NO_ENGINE
276 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
278 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
280 OPT_SECTION("Selection"),
281 {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
282 #ifndef OPENSSL_NO_DEPRECATED_3_0
283 {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"},
285 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
286 {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"},
288 {"decrypt", OPT_DECRYPT, '-',
289 "Time decryption instead of encryption (only EVP)"},
290 {"aead", OPT_AEAD, '-',
291 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
293 OPT_SECTION("Timing"),
294 {"elapsed", OPT_ELAPSED, '-',
295 "Use wall-clock time instead of CPU user time as divisor"},
296 {"seconds", OPT_SECONDS, 'p',
297 "Run benchmarks for specified amount of seconds"},
298 {"bytes", OPT_BYTES, 'p',
299 "Run [non-PKI] benchmarks on custom-sized buffer"},
300 {"misalign", OPT_MISALIGN, 'p',
301 "Use specified offset to mis-align buffers"},
307 {"algorithm", 0, 0, "Algorithm(s) to test (optional; otherwise tests all)"},
312 D_MD2, D_MDC2, D_MD4, D_MD5 , D_HMAC, D_SHA1, D_RMD160, D_RC4,
313 D_CBC_DES, D_EDE3_DES, D_CBC_IDEA, D_CBC_SEED,
314 D_CBC_RC2, D_CBC_RC5, D_CBC_BF, D_CBC_CAST,
315 D_CBC_128_AES, D_CBC_192_AES, D_CBC_256_AES,
316 D_CBC_128_CML, D_CBC_192_CML, D_CBC_256_CML,
317 D_EVP, D_SHA256, D_SHA512, D_WHIRLPOOL,
318 D_IGE_128_AES, D_IGE_192_AES, D_IGE_256_AES,
319 D_GHASH, D_RAND, D_EVP_HMAC, D_EVP_CMAC, ALGOR_NUM
321 /* name of algorithms to test. MUST BE KEEP IN SYNC with above enum ! */
322 static const char *names[ALGOR_NUM] = {
323 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
324 "des cbc", "des ede3", "idea cbc", "seed cbc",
325 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
326 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
327 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
328 "evp", "sha256", "sha512", "whirlpool",
329 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
330 "rand", "hmac", "cmac"
333 /* list of configured algorithm (remaining), with some few alias */
334 static const OPT_PAIR doit_choices[] = {
335 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
338 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
341 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
344 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
346 # ifndef OPENSSL_NO_DEPRECATED_3_0
350 #ifndef OPENSSL_NO_DEPRECATED_3_0
352 {"sha256", D_SHA256},
353 {"sha512", D_SHA512},
355 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
356 {"whirlpool", D_WHIRLPOOL},
358 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
359 {"ripemd", D_RMD160},
360 {"rmd160", D_RMD160},
361 {"ripemd160", D_RMD160},
363 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
366 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
367 {"des-cbc", D_CBC_DES},
368 {"des-ede3", D_EDE3_DES},
370 #ifndef OPENSSL_NO_DEPRECATED_3_0
371 {"aes-128-cbc", D_CBC_128_AES},
372 {"aes-192-cbc", D_CBC_192_AES},
373 {"aes-256-cbc", D_CBC_256_AES},
374 {"aes-128-ige", D_IGE_128_AES},
375 {"aes-192-ige", D_IGE_192_AES},
376 {"aes-256-ige", D_IGE_256_AES},
378 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
379 {"rc2-cbc", D_CBC_RC2},
382 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
383 {"rc5-cbc", D_CBC_RC5},
386 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
387 {"idea-cbc", D_CBC_IDEA},
388 {"idea", D_CBC_IDEA},
390 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
391 {"seed-cbc", D_CBC_SEED},
392 {"seed", D_CBC_SEED},
394 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
395 {"bf-cbc", D_CBC_BF},
396 {"blowfish", D_CBC_BF},
399 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
400 {"cast-cbc", D_CBC_CAST},
401 {"cast", D_CBC_CAST},
402 {"cast5", D_CBC_CAST},
408 static double results[ALGOR_NUM][SIZE_NUM];
410 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
411 enum { R_DSA_512, R_DSA_1024, R_DSA_2048, DSA_NUM };
412 static const OPT_PAIR dsa_choices[DSA_NUM] = {
413 {"dsa512", R_DSA_512},
414 {"dsa1024", R_DSA_1024},
415 {"dsa2048", R_DSA_2048}
417 static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
418 #endif /* OPENSSL_NO_DSA */
420 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
422 R_RSA_512, R_RSA_1024, R_RSA_2048, R_RSA_3072, R_RSA_4096, R_RSA_7680,
425 static const OPT_PAIR rsa_choices[RSA_NUM] = {
426 {"rsa512", R_RSA_512},
427 {"rsa1024", R_RSA_1024},
428 {"rsa2048", R_RSA_2048},
429 {"rsa3072", R_RSA_3072},
430 {"rsa4096", R_RSA_4096},
431 {"rsa7680", R_RSA_7680},
432 {"rsa15360", R_RSA_15360}
435 static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
436 #endif /* OPENSSL_NO_RSA */
438 #ifndef OPENSSL_NO_EC
440 R_EC_P160, R_EC_P192, R_EC_P224, R_EC_P256, R_EC_P384, R_EC_P521,
441 # ifndef OPENSSL_NO_EC2M
442 R_EC_K163, R_EC_K233, R_EC_K283, R_EC_K409, R_EC_K571,
443 R_EC_B163, R_EC_B233, R_EC_B283, R_EC_B409, R_EC_B571,
445 R_EC_BRP256R1, R_EC_BRP256T1, R_EC_BRP384R1, R_EC_BRP384T1,
446 R_EC_BRP512R1, R_EC_BRP512T1, ECDSA_NUM
448 /* list of ecdsa curves */
449 static const OPT_PAIR ecdsa_choices[ECDSA_NUM] = {
450 {"ecdsap160", R_EC_P160},
451 {"ecdsap192", R_EC_P192},
452 {"ecdsap224", R_EC_P224},
453 {"ecdsap256", R_EC_P256},
454 {"ecdsap384", R_EC_P384},
455 {"ecdsap521", R_EC_P521},
456 # ifndef OPENSSL_NO_EC2M
457 {"ecdsak163", R_EC_K163},
458 {"ecdsak233", R_EC_K233},
459 {"ecdsak283", R_EC_K283},
460 {"ecdsak409", R_EC_K409},
461 {"ecdsak571", R_EC_K571},
462 {"ecdsab163", R_EC_B163},
463 {"ecdsab233", R_EC_B233},
464 {"ecdsab283", R_EC_B283},
465 {"ecdsab409", R_EC_B409},
466 {"ecdsab571", R_EC_B571},
468 {"ecdsabrp256r1", R_EC_BRP256R1},
469 {"ecdsabrp256t1", R_EC_BRP256T1},
470 {"ecdsabrp384r1", R_EC_BRP384R1},
471 {"ecdsabrp384t1", R_EC_BRP384T1},
472 {"ecdsabrp512r1", R_EC_BRP512R1},
473 {"ecdsabrp512t1", R_EC_BRP512T1}
475 enum { R_EC_X25519 = ECDSA_NUM, R_EC_X448, EC_NUM };
476 /* list of ecdh curves, extension of |ecdsa_choices| list above */
477 static const OPT_PAIR ecdh_choices[EC_NUM] = {
478 {"ecdhp160", R_EC_P160},
479 {"ecdhp192", R_EC_P192},
480 {"ecdhp224", R_EC_P224},
481 {"ecdhp256", R_EC_P256},
482 {"ecdhp384", R_EC_P384},
483 {"ecdhp521", R_EC_P521},
484 # ifndef OPENSSL_NO_EC2M
485 {"ecdhk163", R_EC_K163},
486 {"ecdhk233", R_EC_K233},
487 {"ecdhk283", R_EC_K283},
488 {"ecdhk409", R_EC_K409},
489 {"ecdhk571", R_EC_K571},
490 {"ecdhb163", R_EC_B163},
491 {"ecdhb233", R_EC_B233},
492 {"ecdhb283", R_EC_B283},
493 {"ecdhb409", R_EC_B409},
494 {"ecdhb571", R_EC_B571},
496 {"ecdhbrp256r1", R_EC_BRP256R1},
497 {"ecdhbrp256t1", R_EC_BRP256T1},
498 {"ecdhbrp384r1", R_EC_BRP384R1},
499 {"ecdhbrp384t1", R_EC_BRP384T1},
500 {"ecdhbrp512r1", R_EC_BRP512R1},
501 {"ecdhbrp512t1", R_EC_BRP512T1},
502 {"ecdhx25519", R_EC_X25519},
503 {"ecdhx448", R_EC_X448}
506 static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
507 static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
509 enum { R_EC_Ed25519, R_EC_Ed448, EdDSA_NUM };
510 static const OPT_PAIR eddsa_choices[EdDSA_NUM] = {
511 {"ed25519", R_EC_Ed25519},
512 {"ed448", R_EC_Ed448}
515 static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
517 # ifndef OPENSSL_NO_SM2
518 enum { R_EC_CURVESM2, SM2_NUM };
519 static const OPT_PAIR sm2_choices[SM2_NUM] = {
520 {"curveSM2", R_EC_CURVESM2}
522 # define SM2_ID "TLSv1.3+GM+Cipher+Suite"
523 # define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1
524 static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */
525 # endif /* OPENSSL_NO_SM2 */
526 #endif /* OPENSSL_NO_EC */
529 # define COND(d) (count < (d))
530 # define COUNT(d) (d)
532 # define COND(unused_cond) (run && count<0x7fffffff)
533 # define COUNT(d) (count)
536 typedef struct loopargs_st {
537 ASYNC_JOB *inprogress_job;
538 ASYNC_WAIT_CTX *wait_ctx;
541 unsigned char *buf_malloc;
542 unsigned char *buf2_malloc;
546 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
547 RSA *rsa_key[RSA_NUM];
549 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
550 DSA *dsa_key[DSA_NUM];
552 #ifndef OPENSSL_NO_EC
553 EC_KEY *ecdsa[ECDSA_NUM];
554 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
555 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
556 # ifndef OPENSSL_NO_SM2
557 EVP_MD_CTX *sm2_ctx[SM2_NUM];
558 EVP_MD_CTX *sm2_vfy_ctx[SM2_NUM];
559 EVP_PKEY *sm2_pkey[SM2_NUM];
561 unsigned char *secret_a;
562 unsigned char *secret_b;
563 size_t outlen[EC_NUM];
566 #ifndef OPENSSL_NO_DEPRECATED_3_0
569 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
572 GCM128_CONTEXT *gcm_ctx;
574 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
575 loopargs_t * loopargs);
577 static unsigned int testnum;
579 /* Nb of iterations to do per algorithm and key-size */
580 static long c[ALGOR_NUM][SIZE_NUM];
582 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
583 static int EVP_Digest_MD2_loop(void *args)
585 loopargs_t *tempargs = *(loopargs_t **) args;
586 unsigned char *buf = tempargs->buf;
587 unsigned char md2[MD2_DIGEST_LENGTH];
590 for (count = 0; COND(c[D_MD2][testnum]); count++) {
591 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
599 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
600 static int EVP_Digest_MDC2_loop(void *args)
602 loopargs_t *tempargs = *(loopargs_t **) args;
603 unsigned char *buf = tempargs->buf;
604 unsigned char mdc2[MDC2_DIGEST_LENGTH];
607 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
608 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
616 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
617 static int EVP_Digest_MD4_loop(void *args)
619 loopargs_t *tempargs = *(loopargs_t **) args;
620 unsigned char *buf = tempargs->buf;
621 unsigned char md4[MD4_DIGEST_LENGTH];
624 for (count = 0; COND(c[D_MD4][testnum]); count++) {
625 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
633 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
634 static int MD5_loop(void *args)
636 loopargs_t *tempargs = *(loopargs_t **) args;
637 unsigned char *buf = tempargs->buf;
638 unsigned char md5[MD5_DIGEST_LENGTH];
640 for (count = 0; COND(c[D_MD5][testnum]); count++)
641 MD5(buf, lengths[testnum], md5);
645 # ifndef OPENSSL_NO_DEPRECATED_3_0
646 static int HMAC_loop(void *args)
648 loopargs_t *tempargs = *(loopargs_t **) args;
649 unsigned char *buf = tempargs->buf;
650 HMAC_CTX *hctx = tempargs->hctx;
651 unsigned char hmac[MD5_DIGEST_LENGTH];
654 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
655 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
656 HMAC_Update(hctx, buf, lengths[testnum]);
657 HMAC_Final(hctx, hmac, NULL);
664 #ifndef OPENSSL_NO_DEPRECATED_3_0
665 static int SHA1_loop(void *args)
667 loopargs_t *tempargs = *(loopargs_t **) args;
668 unsigned char *buf = tempargs->buf;
669 unsigned char sha[SHA_DIGEST_LENGTH];
671 for (count = 0; COND(c[D_SHA1][testnum]); count++)
672 SHA1(buf, lengths[testnum], sha);
676 static int SHA256_loop(void *args)
678 loopargs_t *tempargs = *(loopargs_t **) args;
679 unsigned char *buf = tempargs->buf;
680 unsigned char sha256[SHA256_DIGEST_LENGTH];
682 for (count = 0; COND(c[D_SHA256][testnum]); count++)
683 SHA256(buf, lengths[testnum], sha256);
687 static int SHA512_loop(void *args)
689 loopargs_t *tempargs = *(loopargs_t **) args;
690 unsigned char *buf = tempargs->buf;
691 unsigned char sha512[SHA512_DIGEST_LENGTH];
693 for (count = 0; COND(c[D_SHA512][testnum]); count++)
694 SHA512(buf, lengths[testnum], sha512);
699 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
700 static int WHIRLPOOL_loop(void *args)
702 loopargs_t *tempargs = *(loopargs_t **) args;
703 unsigned char *buf = tempargs->buf;
704 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
706 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
707 WHIRLPOOL(buf, lengths[testnum], whirlpool);
712 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
713 static int EVP_Digest_RMD160_loop(void *args)
715 loopargs_t *tempargs = *(loopargs_t **) args;
716 unsigned char *buf = tempargs->buf;
717 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
719 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
720 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
721 NULL, EVP_ripemd160(), NULL))
728 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
729 static RC4_KEY rc4_ks;
730 static int RC4_loop(void *args)
732 loopargs_t *tempargs = *(loopargs_t **) args;
733 unsigned char *buf = tempargs->buf;
735 for (count = 0; COND(c[D_RC4][testnum]); count++)
736 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
741 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
742 static unsigned char DES_iv[8];
743 static DES_key_schedule sch[3];
744 static int DES_ncbc_encrypt_loop(void *args)
746 loopargs_t *tempargs = *(loopargs_t **) args;
747 unsigned char *buf = tempargs->buf;
749 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
750 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch[0],
751 &DES_iv, DES_ENCRYPT);
755 static int DES_ede3_cbc_encrypt_loop(void *args)
757 loopargs_t *tempargs = *(loopargs_t **) args;
758 unsigned char *buf = tempargs->buf;
760 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
761 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
762 &sch[0], &sch[1], &sch[2], &DES_iv, DES_ENCRYPT);
767 #define MAX_BLOCK_SIZE 128
769 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
771 #ifndef OPENSSL_NO_DEPRECATED_3_0
772 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
773 static int AES_cbc_128_encrypt_loop(void *args)
775 loopargs_t *tempargs = *(loopargs_t **) args;
776 unsigned char *buf = tempargs->buf;
778 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
779 AES_cbc_encrypt(buf, buf,
780 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
784 static int AES_cbc_192_encrypt_loop(void *args)
786 loopargs_t *tempargs = *(loopargs_t **) args;
787 unsigned char *buf = tempargs->buf;
789 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
790 AES_cbc_encrypt(buf, buf,
791 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
795 static int AES_cbc_256_encrypt_loop(void *args)
797 loopargs_t *tempargs = *(loopargs_t **) args;
798 unsigned char *buf = tempargs->buf;
800 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
801 AES_cbc_encrypt(buf, buf,
802 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
806 static int AES_ige_128_encrypt_loop(void *args)
808 loopargs_t *tempargs = *(loopargs_t **) args;
809 unsigned char *buf = tempargs->buf;
810 unsigned char *buf2 = tempargs->buf2;
812 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
813 AES_ige_encrypt(buf, buf2,
814 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
818 static int AES_ige_192_encrypt_loop(void *args)
820 loopargs_t *tempargs = *(loopargs_t **) args;
821 unsigned char *buf = tempargs->buf;
822 unsigned char *buf2 = tempargs->buf2;
824 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
825 AES_ige_encrypt(buf, buf2,
826 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
830 static int AES_ige_256_encrypt_loop(void *args)
832 loopargs_t *tempargs = *(loopargs_t **) args;
833 unsigned char *buf = tempargs->buf;
834 unsigned char *buf2 = tempargs->buf2;
836 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
837 AES_ige_encrypt(buf, buf2,
838 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
842 static int CRYPTO_gcm128_aad_loop(void *args)
844 loopargs_t *tempargs = *(loopargs_t **) args;
845 unsigned char *buf = tempargs->buf;
846 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
848 for (count = 0; COND(c[D_GHASH][testnum]); count++)
849 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
854 static int RAND_bytes_loop(void *args)
856 loopargs_t *tempargs = *(loopargs_t **) args;
857 unsigned char *buf = tempargs->buf;
860 for (count = 0; COND(c[D_RAND][testnum]); count++)
861 RAND_bytes(buf, lengths[testnum]);
865 static int decrypt = 0;
866 static int EVP_Update_loop(void *args)
868 loopargs_t *tempargs = *(loopargs_t **) args;
869 unsigned char *buf = tempargs->buf;
870 EVP_CIPHER_CTX *ctx = tempargs->ctx;
874 for (count = 0; COND(c[D_EVP][testnum]); count++) {
875 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
877 /* reset iv in case of counter overflow */
878 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
882 for (count = 0; COND(c[D_EVP][testnum]); count++) {
883 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
885 /* reset iv in case of counter overflow */
886 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
891 EVP_DecryptFinal_ex(ctx, buf, &outl);
893 EVP_EncryptFinal_ex(ctx, buf, &outl);
898 * CCM does not support streaming. For the purpose of performance measurement,
899 * each message is encrypted using the same (key,iv)-pair. Do not use this
900 * code in your application.
902 static int EVP_Update_loop_ccm(void *args)
904 loopargs_t *tempargs = *(loopargs_t **) args;
905 unsigned char *buf = tempargs->buf;
906 EVP_CIPHER_CTX *ctx = tempargs->ctx;
908 unsigned char tag[12];
911 for (count = 0; COND(c[D_EVP][testnum]); count++) {
912 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
914 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
915 /* counter is reset on every update */
916 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
919 for (count = 0; COND(c[D_EVP][testnum]); count++) {
920 /* restore iv length field */
921 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
922 /* counter is reset on every update */
923 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
927 EVP_DecryptFinal_ex(ctx, buf, &outl);
929 EVP_EncryptFinal_ex(ctx, buf, &outl);
934 * To make AEAD benchmarking more relevant perform TLS-like operations,
935 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
936 * payload length is not actually limited by 16KB...
938 static int EVP_Update_loop_aead(void *args)
940 loopargs_t *tempargs = *(loopargs_t **) args;
941 unsigned char *buf = tempargs->buf;
942 EVP_CIPHER_CTX *ctx = tempargs->ctx;
944 unsigned char aad[13] = { 0xcc };
945 unsigned char faketag[16] = { 0xcc };
948 for (count = 0; COND(c[D_EVP][testnum]); count++) {
949 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
950 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
951 sizeof(faketag), faketag);
952 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
953 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
954 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
957 for (count = 0; COND(c[D_EVP][testnum]); count++) {
958 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
959 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
960 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
961 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
967 static const EVP_MD *evp_md = NULL;
968 static int EVP_Digest_loop(void *args)
970 loopargs_t *tempargs = *(loopargs_t **) args;
971 unsigned char *buf = tempargs->buf;
972 unsigned char md[EVP_MAX_MD_SIZE];
975 for (count = 0; COND(c[D_EVP][testnum]); count++) {
976 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
982 #ifndef OPENSSL_NO_DEPRECATED_3_0
983 static const EVP_MD *evp_hmac_md = NULL;
984 static char *evp_hmac_name = NULL;
985 static int EVP_HMAC_loop(void *args)
987 loopargs_t *tempargs = *(loopargs_t **) args;
988 unsigned char *buf = tempargs->buf;
989 unsigned char no_key[32];
992 for (count = 0; COND(c[D_EVP_HMAC][testnum]); count++) {
993 if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
1001 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1002 static const EVP_CIPHER *evp_cmac_cipher = NULL;
1003 static char *evp_cmac_name = NULL;
1005 static int EVP_CMAC_loop(void *args)
1007 loopargs_t *tempargs = *(loopargs_t **) args;
1008 unsigned char *buf = tempargs->buf;
1009 CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
1010 static const char key[16] = "This is a key...";
1011 unsigned char mac[16];
1012 size_t len = sizeof(mac);
1015 for (count = 0; COND(c[D_EVP_CMAC][testnum]); count++) {
1016 if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
1017 || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
1018 || !CMAC_Final(cmac_ctx, mac, &len))
1025 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1026 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1028 static int RSA_sign_loop(void *args)
1030 loopargs_t *tempargs = *(loopargs_t **) args;
1031 unsigned char *buf = tempargs->buf;
1032 unsigned char *buf2 = tempargs->buf2;
1033 unsigned int *rsa_num = &tempargs->siglen;
1034 RSA **rsa_key = tempargs->rsa_key;
1036 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1037 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1039 BIO_printf(bio_err, "RSA sign failure\n");
1040 ERR_print_errors(bio_err);
1048 static int RSA_verify_loop(void *args)
1050 loopargs_t *tempargs = *(loopargs_t **) args;
1051 unsigned char *buf = tempargs->buf;
1052 unsigned char *buf2 = tempargs->buf2;
1053 unsigned int rsa_num = tempargs->siglen;
1054 RSA **rsa_key = tempargs->rsa_key;
1056 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1058 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1060 BIO_printf(bio_err, "RSA verify failure\n");
1061 ERR_print_errors(bio_err);
1070 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1071 static long dsa_c[DSA_NUM][2];
1072 static int DSA_sign_loop(void *args)
1074 loopargs_t *tempargs = *(loopargs_t **) args;
1075 unsigned char *buf = tempargs->buf;
1076 unsigned char *buf2 = tempargs->buf2;
1077 DSA **dsa_key = tempargs->dsa_key;
1078 unsigned int *siglen = &tempargs->siglen;
1080 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1081 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1083 BIO_printf(bio_err, "DSA sign failure\n");
1084 ERR_print_errors(bio_err);
1092 static int DSA_verify_loop(void *args)
1094 loopargs_t *tempargs = *(loopargs_t **) args;
1095 unsigned char *buf = tempargs->buf;
1096 unsigned char *buf2 = tempargs->buf2;
1097 DSA **dsa_key = tempargs->dsa_key;
1098 unsigned int siglen = tempargs->siglen;
1100 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1101 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1103 BIO_printf(bio_err, "DSA verify failure\n");
1104 ERR_print_errors(bio_err);
1113 #ifndef OPENSSL_NO_EC
1114 # ifndef OPENSSL_NO_DEPRECATED_3_0
1115 static long ecdsa_c[ECDSA_NUM][2];
1116 static int ECDSA_sign_loop(void *args)
1118 loopargs_t *tempargs = *(loopargs_t **) args;
1119 unsigned char *buf = tempargs->buf;
1120 EC_KEY **ecdsa = tempargs->ecdsa;
1121 unsigned char *ecdsasig = tempargs->buf2;
1122 unsigned int *ecdsasiglen = &tempargs->siglen;
1124 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1125 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1127 BIO_printf(bio_err, "ECDSA sign failure\n");
1128 ERR_print_errors(bio_err);
1136 static int ECDSA_verify_loop(void *args)
1138 loopargs_t *tempargs = *(loopargs_t **) args;
1139 unsigned char *buf = tempargs->buf;
1140 EC_KEY **ecdsa = tempargs->ecdsa;
1141 unsigned char *ecdsasig = tempargs->buf2;
1142 unsigned int ecdsasiglen = tempargs->siglen;
1144 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1145 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1147 BIO_printf(bio_err, "ECDSA verify failure\n");
1148 ERR_print_errors(bio_err);
1157 /* ******************************************************************** */
1158 static long ecdh_c[EC_NUM][1];
1160 static int ECDH_EVP_derive_key_loop(void *args)
1162 loopargs_t *tempargs = *(loopargs_t **) args;
1163 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1164 unsigned char *derived_secret = tempargs->secret_a;
1166 size_t *outlen = &(tempargs->outlen[testnum]);
1168 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1169 EVP_PKEY_derive(ctx, derived_secret, outlen);
1174 static long eddsa_c[EdDSA_NUM][2];
1175 static int EdDSA_sign_loop(void *args)
1177 loopargs_t *tempargs = *(loopargs_t **) args;
1178 unsigned char *buf = tempargs->buf;
1179 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1180 unsigned char *eddsasig = tempargs->buf2;
1181 size_t *eddsasigsize = &tempargs->sigsize;
1184 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1185 ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1187 BIO_printf(bio_err, "EdDSA sign failure\n");
1188 ERR_print_errors(bio_err);
1196 static int EdDSA_verify_loop(void *args)
1198 loopargs_t *tempargs = *(loopargs_t **) args;
1199 unsigned char *buf = tempargs->buf;
1200 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1201 unsigned char *eddsasig = tempargs->buf2;
1202 size_t eddsasigsize = tempargs->sigsize;
1205 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1206 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1208 BIO_printf(bio_err, "EdDSA verify failure\n");
1209 ERR_print_errors(bio_err);
1217 # ifndef OPENSSL_NO_SM2
1218 static long sm2_c[SM2_NUM][2];
1219 static int SM2_sign_loop(void *args)
1221 loopargs_t *tempargs = *(loopargs_t **) args;
1222 unsigned char *buf = tempargs->buf;
1223 EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx;
1224 unsigned char *sm2sig = tempargs->buf2;
1225 size_t sm2sigsize = tempargs->sigsize;
1226 const size_t max_size = tempargs->sigsize;
1228 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1230 for (count = 0; COND(sm2_c[testnum][0]); count++) {
1231 if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(),
1232 NULL, sm2_pkey[testnum])) {
1233 BIO_printf(bio_err, "SM2 init sign failure\n");
1234 ERR_print_errors(bio_err);
1238 ret = EVP_DigestSign(sm2ctx[testnum], sm2sig, &sm2sigsize,
1241 BIO_printf(bio_err, "SM2 sign failure\n");
1242 ERR_print_errors(bio_err);
1246 /* update the latest returned size and always use the fixed buffer size */
1247 tempargs->sigsize = sm2sigsize;
1248 sm2sigsize = max_size;
1254 static int SM2_verify_loop(void *args)
1256 loopargs_t *tempargs = *(loopargs_t **) args;
1257 unsigned char *buf = tempargs->buf;
1258 EVP_MD_CTX **sm2ctx = tempargs->sm2_vfy_ctx;
1259 unsigned char *sm2sig = tempargs->buf2;
1260 size_t sm2sigsize = tempargs->sigsize;
1262 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1264 for (count = 0; COND(sm2_c[testnum][1]); count++) {
1265 if (!EVP_DigestVerifyInit(sm2ctx[testnum], NULL, EVP_sm3(),
1266 NULL, sm2_pkey[testnum])) {
1267 BIO_printf(bio_err, "SM2 verify init failure\n");
1268 ERR_print_errors(bio_err);
1272 ret = EVP_DigestVerify(sm2ctx[testnum], sm2sig, sm2sigsize,
1275 BIO_printf(bio_err, "SM2 verify failure\n");
1276 ERR_print_errors(bio_err);
1283 # endif /* OPENSSL_NO_SM2 */
1284 #endif /* OPENSSL_NO_EC */
1286 static int run_benchmark(int async_jobs,
1287 int (*loop_function) (void *), loopargs_t * loopargs)
1289 int job_op_count = 0;
1290 int total_op_count = 0;
1291 int num_inprogress = 0;
1292 int error = 0, i = 0, ret = 0;
1293 OSSL_ASYNC_FD job_fd = 0;
1294 size_t num_job_fds = 0;
1296 if (async_jobs == 0) {
1297 return loop_function((void *)&loopargs);
1300 for (i = 0; i < async_jobs && !error; i++) {
1301 loopargs_t *looparg_item = loopargs + i;
1303 /* Copy pointer content (looparg_t item address) into async context */
1304 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1305 &job_op_count, loop_function,
1306 (void *)&looparg_item, sizeof(looparg_item));
1312 if (job_op_count == -1) {
1315 total_op_count += job_op_count;
1320 BIO_printf(bio_err, "Failure in the job\n");
1321 ERR_print_errors(bio_err);
1327 while (num_inprogress > 0) {
1328 #if defined(OPENSSL_SYS_WINDOWS)
1330 #elif defined(OPENSSL_SYS_UNIX)
1331 int select_result = 0;
1332 OSSL_ASYNC_FD max_fd = 0;
1335 FD_ZERO(&waitfdset);
1337 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1338 if (loopargs[i].inprogress_job == NULL)
1341 if (!ASYNC_WAIT_CTX_get_all_fds
1342 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1343 || num_job_fds > 1) {
1344 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1345 ERR_print_errors(bio_err);
1349 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1351 FD_SET(job_fd, &waitfdset);
1352 if (job_fd > max_fd)
1356 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1358 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1359 "Decrease the value of async_jobs\n",
1360 max_fd, FD_SETSIZE);
1361 ERR_print_errors(bio_err);
1366 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1367 if (select_result == -1 && errno == EINTR)
1370 if (select_result == -1) {
1371 BIO_printf(bio_err, "Failure in the select\n");
1372 ERR_print_errors(bio_err);
1377 if (select_result == 0)
1381 for (i = 0; i < async_jobs; i++) {
1382 if (loopargs[i].inprogress_job == NULL)
1385 if (!ASYNC_WAIT_CTX_get_all_fds
1386 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1387 || num_job_fds > 1) {
1388 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1389 ERR_print_errors(bio_err);
1393 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1396 #if defined(OPENSSL_SYS_UNIX)
1397 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1399 #elif defined(OPENSSL_SYS_WINDOWS)
1400 if (num_job_fds == 1
1401 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1406 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1407 loopargs[i].wait_ctx, &job_op_count,
1408 loop_function, (void *)(loopargs + i),
1409 sizeof(loopargs_t));
1414 if (job_op_count == -1) {
1417 total_op_count += job_op_count;
1420 loopargs[i].inprogress_job = NULL;
1425 loopargs[i].inprogress_job = NULL;
1426 BIO_printf(bio_err, "Failure in the job\n");
1427 ERR_print_errors(bio_err);
1434 return error ? -1 : total_op_count;
1437 #define stop_it(do_it, test_num)\
1438 memset(do_it + test_num, 0, OSSL_NELEM(do_it) - test_num);
1440 int speed_main(int argc, char **argv)
1443 loopargs_t *loopargs = NULL;
1445 const char *engine_id = NULL;
1446 const EVP_CIPHER *evp_cipher = NULL;
1449 int async_init = 0, multiblock = 0, pr_header = 0;
1450 uint8_t doit[ALGOR_NUM] = { 0 };
1451 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1453 unsigned int size_num = SIZE_NUM;
1454 unsigned int i, k, loopargs_len = 0, async_jobs = 0;
1460 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1461 || !defined(OPENSSL_NO_EC)
1464 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1465 ECDSA_SECONDS, ECDH_SECONDS,
1466 EdDSA_SECONDS, SM2_SECONDS };
1468 /* What follows are the buffers and key material. */
1469 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1472 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1475 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1476 IDEA_KEY_SCHEDULE idea_ks;
1478 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1479 SEED_KEY_SCHEDULE seed_ks;
1481 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1484 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1487 #ifndef OPENSSL_NO_DEPRECATED_3_0
1488 static const unsigned char key16[16] = {
1489 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1490 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1492 static const unsigned char key24[24] = {
1493 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1494 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1495 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1497 static const unsigned char key32[32] = {
1498 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1499 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1500 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1501 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1504 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1505 CAMELLIA_KEY camellia_ks[3];
1507 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1508 static const struct {
1509 const unsigned char *data;
1510 unsigned int length;
1513 { test512, sizeof(test512), 512 },
1514 { test1024, sizeof(test1024), 1024 },
1515 { test2048, sizeof(test2048), 2048 },
1516 { test3072, sizeof(test3072), 3072 },
1517 { test4096, sizeof(test4096), 4092 },
1518 { test7680, sizeof(test7680), 7680 },
1519 { test15360, sizeof(test15360), 15360 }
1521 uint8_t rsa_doit[RSA_NUM] = { 0 };
1522 int primes = RSA_DEFAULT_PRIME_NUM;
1524 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1525 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1526 uint8_t dsa_doit[DSA_NUM] = { 0 };
1528 #ifndef OPENSSL_NO_EC
1529 typedef struct ec_curve_st {
1533 size_t sigsize; /* only used for EdDSA curves */
1536 * We only test over the following curves as they are representative, To
1537 * add tests over more curves, simply add the curve NID and curve name to
1538 * the following arrays and increase the |ecdh_choices| and |ecdsa_choices|
1539 * lists accordingly.
1541 static const EC_CURVE ec_curves[EC_NUM] = {
1543 {"secp160r1", NID_secp160r1, 160},
1544 {"nistp192", NID_X9_62_prime192v1, 192},
1545 {"nistp224", NID_secp224r1, 224},
1546 {"nistp256", NID_X9_62_prime256v1, 256},
1547 {"nistp384", NID_secp384r1, 384},
1548 {"nistp521", NID_secp521r1, 521},
1549 # ifndef OPENSSL_NO_EC2M
1551 {"nistk163", NID_sect163k1, 163},
1552 {"nistk233", NID_sect233k1, 233},
1553 {"nistk283", NID_sect283k1, 283},
1554 {"nistk409", NID_sect409k1, 409},
1555 {"nistk571", NID_sect571k1, 571},
1556 {"nistb163", NID_sect163r2, 163},
1557 {"nistb233", NID_sect233r1, 233},
1558 {"nistb283", NID_sect283r1, 283},
1559 {"nistb409", NID_sect409r1, 409},
1560 {"nistb571", NID_sect571r1, 571},
1562 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1563 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1564 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1565 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1566 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1567 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1568 /* Other and ECDH only ones */
1569 {"X25519", NID_X25519, 253},
1570 {"X448", NID_X448, 448}
1572 static const EC_CURVE ed_curves[EdDSA_NUM] = {
1574 {"Ed25519", NID_ED25519, 253, 64},
1575 {"Ed448", NID_ED448, 456, 114}
1577 # ifndef OPENSSL_NO_SM2
1578 static const EC_CURVE sm2_curves[SM2_NUM] = {
1580 {"CurveSM2", NID_sm2, 256}
1582 uint8_t sm2_doit[SM2_NUM] = { 0 };
1584 uint8_t ecdsa_doit[ECDSA_NUM] = { 0 };
1585 uint8_t ecdh_doit[EC_NUM] = { 0 };
1586 uint8_t eddsa_doit[EdDSA_NUM] = { 0 };
1588 /* checks declarated curves against choices list. */
1589 OPENSSL_assert(ed_curves[EdDSA_NUM - 1].nid == NID_ED448);
1590 OPENSSL_assert(strcmp(eddsa_choices[EdDSA_NUM - 1].name, "ed448") == 0);
1592 OPENSSL_assert(ec_curves[EC_NUM - 1].nid == NID_X448);
1593 OPENSSL_assert(strcmp(ecdh_choices[EC_NUM - 1].name, "ecdhx448") == 0);
1595 OPENSSL_assert(ec_curves[ECDSA_NUM - 1].nid == NID_brainpoolP512t1);
1596 OPENSSL_assert(strcmp(ecdsa_choices[ECDSA_NUM - 1].name, "ecdsabrp512t1") == 0);
1598 # ifndef OPENSSL_NO_SM2
1599 OPENSSL_assert(sm2_curves[SM2_NUM - 1].nid == NID_sm2);
1600 OPENSSL_assert(strcmp(sm2_choices[SM2_NUM - 1].name, "curveSM2") == 0);
1602 #endif /* ndef OPENSSL_NO_EC */
1604 prog = opt_init(argc, argv, speed_options);
1605 while ((o = opt_next()) != OPT_EOF) {
1610 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1613 opt_help(speed_options);
1621 evp_cipher = EVP_get_cipherbyname(opt_arg());
1622 if (evp_cipher == NULL)
1623 evp_md = EVP_get_digestbyname(opt_arg());
1624 if (evp_cipher == NULL && evp_md == NULL) {
1626 "%s: %s is an unknown cipher or digest\n",
1633 #ifndef OPENSSL_NO_DEPRECATED_3_0
1634 evp_hmac_md = EVP_get_digestbyname(opt_arg());
1635 if (evp_hmac_md == NULL) {
1636 BIO_printf(bio_err, "%s: %s is an unknown digest\n",
1640 doit[D_EVP_HMAC] = 1;
1644 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1645 evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
1646 if (evp_cmac_cipher == NULL) {
1647 BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
1651 doit[D_EVP_CMAC] = 1;
1659 * In a forked execution, an engine might need to be
1660 * initialised by each child process, not by the parent.
1661 * So store the name here and run setup_engine() later on.
1663 engine_id = opt_arg();
1667 multi = atoi(opt_arg());
1671 #ifndef OPENSSL_NO_ASYNC
1672 async_jobs = atoi(opt_arg());
1673 if (!ASYNC_is_capable()) {
1675 "%s: async_jobs specified but async not supported\n",
1679 if (async_jobs > 99999) {
1680 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1686 if (!opt_int(opt_arg(), &misalign))
1688 if (misalign > MISALIGN) {
1690 "%s: Maximum offset is %d\n", prog, MISALIGN);
1699 #ifdef OPENSSL_NO_MULTIBLOCK
1701 "%s: -mb specified but multi-block support is disabled\n",
1710 case OPT_PROV_CASES:
1711 if (!opt_provider(o))
1715 #ifndef OPENSSL_NO_DEPRECATED_3_0
1716 if (!opt_int(opt_arg(), &primes))
1721 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1722 = seconds.ecdh = seconds.eddsa
1723 = seconds.sm2 = atoi(opt_arg());
1726 lengths_single = atoi(opt_arg());
1727 lengths = &lengths_single;
1735 argc = opt_num_rest();
1738 /* Remaining arguments are algorithms. */
1739 for (; *argv; argv++) {
1740 const char *algo = *argv;
1742 if (opt_found(algo, doit_choices, &i)) {
1746 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1747 if (strcmp(algo, "des") == 0) {
1748 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1752 if (strcmp(algo, "sha") == 0) {
1753 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1756 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1757 if (strcmp(algo, "openssl") == 0) /* just for compatibility */
1759 if (strncmp(algo, "rsa", 3) == 0) {
1760 if (algo[3] == '\0') {
1761 memset(rsa_doit, 1, sizeof(rsa_doit));
1764 if (opt_found(algo, rsa_choices, &i)) {
1770 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1771 if (strncmp(algo, "dsa", 3) == 0) {
1772 if (algo[3] == '\0') {
1773 memset(dsa_doit, 1, sizeof(dsa_doit));
1776 if (opt_found(algo, dsa_choices, &i)) {
1782 #ifndef OPENSSL_NO_DEPRECATED_3_0
1783 if (strcmp(algo, "aes") == 0) {
1784 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1788 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1789 if (strcmp(algo, "camellia") == 0) {
1790 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1794 #ifndef OPENSSL_NO_EC
1795 if (strncmp(algo, "ecdsa", 5) == 0) {
1796 if (algo[5] == '\0') {
1797 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
1800 if (opt_found(algo, ecdsa_choices, &i)) {
1805 if (strncmp(algo, "ecdh", 4) == 0) {
1806 if (algo[4] == '\0') {
1807 memset(ecdh_doit, 1, sizeof(ecdh_doit));
1810 if (opt_found(algo, ecdh_choices, &i)) {
1815 if (strcmp(algo, "eddsa") == 0) {
1816 memset(eddsa_doit, 1, sizeof(eddsa_doit));
1819 if (opt_found(algo, eddsa_choices, &i)) {
1823 # ifndef OPENSSL_NO_SM2
1824 if (strcmp(algo, "sm2") == 0) {
1825 memset(sm2_doit, 1, sizeof(sm2_doit));
1828 if (opt_found(algo, sm2_choices, &i)) {
1833 #endif /* OPENSSL_NO_EC */
1834 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, algo);
1840 if (evp_cipher == NULL) {
1841 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1843 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1844 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1845 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1846 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1851 if (evp_cipher == NULL) {
1852 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1853 " capable cipher\n");
1855 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1856 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1857 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1858 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1860 } else if (async_jobs > 0) {
1861 BIO_printf(bio_err, "Async mode is not supported with -mb");
1866 /* Initialize the job pool if async mode is enabled */
1867 if (async_jobs > 0) {
1868 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1870 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1875 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1877 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1878 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1880 for (i = 0; i < loopargs_len; i++) {
1881 if (async_jobs > 0) {
1882 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1883 if (loopargs[i].wait_ctx == NULL) {
1884 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1889 buflen = lengths[size_num - 1];
1890 if (buflen < 36) /* size of random vector in RSA benchmark */
1892 buflen += MAX_MISALIGNMENT + 1;
1893 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1894 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1895 memset(loopargs[i].buf_malloc, 0, buflen);
1896 memset(loopargs[i].buf2_malloc, 0, buflen);
1898 /* Align the start of buffers on a 64 byte boundary */
1899 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1900 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1901 #ifndef OPENSSL_NO_EC
1902 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1903 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1908 if (multi && do_multi(multi, size_num))
1912 /* Initialize the engine after the fork */
1913 e = setup_engine(engine_id, 0);
1915 /* No parameters; turn on everything. */
1916 if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
1917 memset(doit, 1, sizeof(doit));
1918 doit[D_EVP] = doit[D_EVP_HMAC] = doit[D_EVP_CMAC] = 0;
1919 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1920 memset(rsa_doit, 1, sizeof(rsa_doit));
1922 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1923 memset(dsa_doit, 1, sizeof(dsa_doit));
1925 #ifndef OPENSSL_NO_EC
1926 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
1927 memset(ecdh_doit, 1, sizeof(ecdh_doit));
1928 memset(eddsa_doit, 1, sizeof(eddsa_doit));
1929 # ifndef OPENSSL_NO_SM2
1930 memset(sm2_doit, 1, sizeof(sm2_doit));
1934 for (i = 0; i < ALGOR_NUM; i++)
1938 if (usertime == 0 && !mr)
1940 "You have chosen to measure elapsed time "
1941 "instead of user CPU time.\n");
1943 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1944 for (i = 0; i < loopargs_len; i++) {
1945 if (primes > RSA_DEFAULT_PRIME_NUM) {
1946 /* for multi-prime RSA, skip this */
1949 for (k = 0; k < RSA_NUM; k++) {
1950 const unsigned char *p = rsa_keys[k].data;
1952 loopargs[i].rsa_key[k] =
1953 d2i_RSAPrivateKey(NULL, &p, rsa_keys[k].length);
1954 if (loopargs[i].rsa_key[k] == NULL) {
1956 "internal error loading RSA key number %d\n", k);
1962 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1963 for (i = 0; i < loopargs_len; i++) {
1964 loopargs[i].dsa_key[0] = get_dsa(512);
1965 loopargs[i].dsa_key[1] = get_dsa(1024);
1966 loopargs[i].dsa_key[2] = get_dsa(2048);
1969 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1970 if (doit[D_CBC_DES] || doit[D_EDE3_DES]) {
1971 static DES_cblock keys[] = {
1972 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }, /* keys[0] */
1973 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }, /* keys[1] */
1974 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 } /* keys[3] */
1976 DES_set_key_unchecked(&keys[0], &sch[0]);
1977 DES_set_key_unchecked(&keys[1], &sch[1]);
1978 DES_set_key_unchecked(&keys[2], &sch[2]);
1981 #ifndef OPENSSL_NO_DEPRECATED_3_0
1982 AES_set_encrypt_key(key16, 128, &aes_ks1);
1983 AES_set_encrypt_key(key24, 192, &aes_ks2);
1984 AES_set_encrypt_key(key32, 256, &aes_ks3);
1986 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1987 if (doit[D_CBC_128_CML] || doit[D_CBC_192_CML] || doit[D_CBC_256_CML]) {
1988 Camellia_set_key(key16, 128, &camellia_ks[0]);
1989 Camellia_set_key(key24, 192, &camellia_ks[1]);
1990 Camellia_set_key(key32, 256, &camellia_ks[2]);
1993 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1994 if (doit[D_CBC_IDEA])
1995 IDEA_set_encrypt_key(key16, &idea_ks);
1997 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1998 if (doit[D_CBC_SEED])
1999 SEED_set_key(key16, &seed_ks);
2001 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2003 RC4_set_key(&rc4_ks, 16, key16);
2005 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2006 if (doit[D_CBC_RC2])
2007 RC2_set_key(&rc2_ks, 16, key16, 128);
2009 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2010 if (doit[D_CBC_RC5])
2011 if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
2012 BIO_printf(bio_err, "Failed setting RC5 key\n");
2016 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2018 BF_set_key(&bf_ks, 16, key16);
2020 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2021 if (doit[D_CBC_CAST])
2022 CAST_set_key(&cast_ks, 16, key16);
2025 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2026 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
2032 for (it = count; it; it--)
2033 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
2034 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
2037 c[D_MD2][0] = count / 10;
2038 c[D_MDC2][0] = count / 10;
2039 c[D_MD4][0] = count;
2040 c[D_MD5][0] = count;
2041 c[D_HMAC][0] = count;
2042 c[D_SHA1][0] = count;
2043 c[D_RMD160][0] = count;
2044 c[D_RC4][0] = count * 5;
2045 c[D_CBC_DES][0] = count;
2046 c[D_EDE3_DES][0] = count / 3;
2047 c[D_CBC_IDEA][0] = count;
2048 c[D_CBC_SEED][0] = count;
2049 c[D_CBC_RC2][0] = count;
2050 c[D_CBC_RC5][0] = count;
2051 c[D_CBC_BF][0] = count;
2052 c[D_CBC_CAST][0] = count;
2053 c[D_CBC_128_AES][0] = count;
2054 c[D_CBC_192_AES][0] = count;
2055 c[D_CBC_256_AES][0] = count;
2056 c[D_CBC_128_CML][0] = count;
2057 c[D_CBC_192_CML][0] = count;
2058 c[D_CBC_256_CML][0] = count;
2059 c[D_EVP][0] = count;
2060 c[D_SHA256][0] = count;
2061 c[D_SHA512][0] = count;
2062 c[D_WHIRLPOOL][0] = count;
2063 c[D_IGE_128_AES][0] = count;
2064 c[D_IGE_192_AES][0] = count;
2065 c[D_IGE_256_AES][0] = count;
2066 c[D_GHASH][0] = count;
2067 c[D_RAND][0] = count;
2068 c[D_EVP_HMAC][0] = count;
2069 c[D_EVP_CMAC][0] = count;
2071 for (i = 1; i < size_num; i++) {
2072 long l0 = (long)lengths[0];
2073 long l1 = (long)lengths[i];
2075 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
2076 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
2077 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
2078 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
2079 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
2080 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
2081 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
2082 c[D_EVP][i] = = c[D_EVP][0] * 4 * l0 / l1;
2083 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
2084 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
2085 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
2086 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
2087 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
2088 c[D_EVP_HMAC][i] = = c[D_EVP_HMAC][0] * 4 * l0 / l1;
2089 c[D_EVP_CMAC][i] = = c[D_EVP_CMAC][0] * 4 * l0 / l1;
2091 l0 = (long)lengths[i - 1];
2093 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
2094 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
2095 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
2096 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
2097 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
2098 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
2099 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
2100 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
2101 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
2102 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
2103 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
2104 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
2105 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
2106 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
2107 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
2108 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
2109 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
2110 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
2113 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2114 rsa_c[R_RSA_512][0] = count / 2000;
2115 rsa_c[R_RSA_512][1] = count / 400;
2116 for (i = 1; i < RSA_NUM; i++) {
2117 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
2118 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
2119 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
2122 if (rsa_c[i][0] == 0) {
2123 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2130 # if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2131 dsa_c[R_DSA_512][0] = count / 1000;
2132 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2133 for (i = 1; i < DSA_NUM; i++) {
2134 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2135 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2136 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2139 if (dsa_c[i][0] == 0) {
2140 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2147 # ifndef OPENSSL_NO_EC
2148 ecdsa_c[R_EC_P160][0] = count / 1000;
2149 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2150 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2151 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2152 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2153 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2156 if (ecdsa_c[i][0] == 0) {
2162 # ifndef OPENSSL_NO_EC2M
2163 ecdsa_c[R_EC_K163][0] = count / 1000;
2164 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2165 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2166 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2167 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2168 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2171 if (ecdsa_c[i][0] == 0) {
2177 ecdsa_c[R_EC_B163][0] = count / 1000;
2178 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2179 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2180 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2181 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2182 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2185 if (ecdsa_c[i][0] == 0) {
2193 ecdh_c[R_EC_P160][0] = count / 1000;
2194 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2195 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2196 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2199 if (ecdh_c[i][0] == 0) {
2204 # ifndef OPENSSL_NO_EC2M
2205 ecdh_c[R_EC_K163][0] = count / 1000;
2206 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2207 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2208 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2211 if (ecdh_c[i][0] == 0) {
2216 ecdh_c[R_EC_B163][0] = count / 1000;
2217 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2218 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2219 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2222 if (ecdh_c[i][0] == 0) {
2228 /* repeated code good to factorize */
2229 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2230 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2231 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2232 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2235 if (ecdh_c[i][0] == 0) {
2240 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2241 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2242 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2243 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2246 if (ecdh_c[i][0] == 0) {
2251 /* default iteration count for the last two EC Curves */
2252 ecdh_c[R_EC_X25519][0] = count / 1800;
2253 ecdh_c[R_EC_X448][0] = count / 7200;
2255 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2256 eddsa_c[R_EC_Ed448][0] = count / 7200;
2258 # ifndef OPENSSL_NO_SM2
2259 sm2_c[R_EC_SM2P256][0] = count / 1800;
2261 # endif /* OPENSSL_NO_EC */
2264 /* not worth fixing */
2265 # error "You cannot disable DES on systems without SIGALRM."
2266 # endif /* OPENSSL_NO_DES */
2268 signal(SIGALRM, alarmed);
2269 #endif /* SIGALRM */
2271 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2273 for (testnum = 0; testnum < size_num; testnum++) {
2274 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2277 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2279 print_result(D_MD2, testnum, count, d);
2283 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2285 for (testnum = 0; testnum < size_num; testnum++) {
2286 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2289 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2291 print_result(D_MDC2, testnum, count, d);
2298 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2300 for (testnum = 0; testnum < size_num; testnum++) {
2301 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2304 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2306 print_result(D_MD4, testnum, count, d);
2313 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2315 for (testnum = 0; testnum < size_num; testnum++) {
2316 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2319 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2321 print_result(D_MD5, testnum, count, d);
2325 # ifndef OPENSSL_NO_DEPRECATED_3_0
2327 static const char hmac_key[] = "This is a key...";
2328 int len = strlen(hmac_key);
2330 for (i = 0; i < loopargs_len; i++) {
2331 loopargs[i].hctx = HMAC_CTX_new();
2332 if (loopargs[i].hctx == NULL) {
2333 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2337 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2339 for (testnum = 0; testnum < size_num; testnum++) {
2340 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2343 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2345 print_result(D_HMAC, testnum, count, d);
2347 for (i = 0; i < loopargs_len; i++)
2348 HMAC_CTX_free(loopargs[i].hctx);
2352 #ifndef OPENSSL_NO_DEPRECATED_3_0
2354 for (testnum = 0; testnum < size_num; testnum++) {
2355 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2358 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2360 print_result(D_SHA1, testnum, count, d);
2363 if (doit[D_SHA256]) {
2364 for (testnum = 0; testnum < size_num; testnum++) {
2365 print_message(names[D_SHA256], c[D_SHA256][testnum],
2366 lengths[testnum], seconds.sym);
2368 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2370 print_result(D_SHA256, testnum, count, d);
2373 if (doit[D_SHA512]) {
2374 for (testnum = 0; testnum < size_num; testnum++) {
2375 print_message(names[D_SHA512], c[D_SHA512][testnum],
2376 lengths[testnum], seconds.sym);
2378 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2380 print_result(D_SHA512, testnum, count, d);
2384 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2385 if (doit[D_WHIRLPOOL]) {
2386 for (testnum = 0; testnum < size_num; testnum++) {
2387 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2388 lengths[testnum], seconds.sym);
2390 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2392 print_result(D_WHIRLPOOL, testnum, count, d);
2397 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2398 if (doit[D_RMD160]) {
2399 for (testnum = 0; testnum < size_num; testnum++) {
2400 print_message(names[D_RMD160], c[D_RMD160][testnum],
2401 lengths[testnum], seconds.sym);
2403 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2405 print_result(D_RMD160, testnum, count, d);
2411 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2413 for (testnum = 0; testnum < size_num; testnum++) {
2414 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2417 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2419 print_result(D_RC4, testnum, count, d);
2423 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2424 if (doit[D_CBC_DES]) {
2425 for (testnum = 0; testnum < size_num; testnum++) {
2426 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2427 lengths[testnum], seconds.sym);
2429 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2431 print_result(D_CBC_DES, testnum, count, d);
2435 if (doit[D_EDE3_DES]) {
2436 for (testnum = 0; testnum < size_num; testnum++) {
2437 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2438 lengths[testnum], seconds.sym);
2441 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2443 print_result(D_EDE3_DES, testnum, count, d);
2448 #ifndef OPENSSL_NO_DEPRECATED_3_0
2449 if (doit[D_CBC_128_AES]) {
2450 for (testnum = 0; testnum < size_num; testnum++) {
2451 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2452 lengths[testnum], seconds.sym);
2455 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2457 print_result(D_CBC_128_AES, testnum, count, d);
2460 if (doit[D_CBC_192_AES]) {
2461 for (testnum = 0; testnum < size_num; testnum++) {
2462 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2463 lengths[testnum], seconds.sym);
2466 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2468 print_result(D_CBC_192_AES, testnum, count, d);
2471 if (doit[D_CBC_256_AES]) {
2472 for (testnum = 0; testnum < size_num; testnum++) {
2473 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2474 lengths[testnum], seconds.sym);
2477 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2479 print_result(D_CBC_256_AES, testnum, count, d);
2484 if (doit[D_IGE_128_AES]) {
2485 for (testnum = 0; testnum < size_num; testnum++) {
2486 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2487 lengths[testnum], seconds.sym);
2490 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2492 print_result(D_IGE_128_AES, testnum, count, d);
2495 if (doit[D_IGE_192_AES]) {
2496 for (testnum = 0; testnum < size_num; testnum++) {
2497 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2498 lengths[testnum], seconds.sym);
2501 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2503 print_result(D_IGE_192_AES, testnum, count, d);
2506 if (doit[D_IGE_256_AES]) {
2507 for (testnum = 0; testnum < size_num; testnum++) {
2508 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2509 lengths[testnum], seconds.sym);
2512 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2514 print_result(D_IGE_256_AES, testnum, count, d);
2517 if (doit[D_GHASH]) {
2518 for (i = 0; i < loopargs_len; i++) {
2519 loopargs[i].gcm_ctx =
2520 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2521 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2522 (unsigned char *)"0123456789ab", 12);
2525 for (testnum = 0; testnum < size_num; testnum++) {
2526 print_message(names[D_GHASH], c[D_GHASH][testnum],
2527 lengths[testnum], seconds.sym);
2529 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2531 print_result(D_GHASH, testnum, count, d);
2533 for (i = 0; i < loopargs_len; i++)
2534 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2536 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
2537 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2538 if (doit[D_CBC_128_CML]) {
2539 if (async_jobs > 0) {
2540 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2541 names[D_CBC_128_CML]);
2542 doit[D_CBC_128_CML] = 0;
2544 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2545 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2546 lengths[testnum], seconds.sym);
2548 for (count = 0; COND(c[D_CBC_128_CML][testnum]); count++)
2549 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2550 (size_t)lengths[testnum], &camellia_ks[0],
2551 iv, CAMELLIA_ENCRYPT);
2553 print_result(D_CBC_128_CML, testnum, count, d);
2556 if (doit[D_CBC_192_CML]) {
2557 if (async_jobs > 0) {
2558 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2559 names[D_CBC_192_CML]);
2560 doit[D_CBC_192_CML] = 0;
2562 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2563 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2564 lengths[testnum], seconds.sym);
2565 if (async_jobs > 0) {
2566 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2570 for (count = 0; COND(c[D_CBC_192_CML][testnum]); count++)
2571 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2572 (size_t)lengths[testnum], &camellia_ks[1],
2573 iv, CAMELLIA_ENCRYPT);
2575 print_result(D_CBC_192_CML, testnum, count, d);
2578 if (doit[D_CBC_256_CML]) {
2579 if (async_jobs > 0) {
2580 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2581 names[D_CBC_256_CML]);
2582 doit[D_CBC_256_CML] = 0;
2584 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2585 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2586 lengths[testnum], seconds.sym);
2588 for (count = 0; COND(c[D_CBC_256_CML][testnum]); count++)
2589 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2590 (size_t)lengths[testnum], &camellia_ks[2],
2591 iv, CAMELLIA_ENCRYPT);
2593 print_result(D_CBC_256_CML, testnum, count, d);
2597 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2598 if (doit[D_CBC_IDEA]) {
2599 if (async_jobs > 0) {
2600 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2602 doit[D_CBC_IDEA] = 0;
2604 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2605 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2606 lengths[testnum], seconds.sym);
2608 for (count = 0; COND(c[D_CBC_IDEA][testnum]); count++)
2609 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2610 (size_t)lengths[testnum], &idea_ks,
2613 print_result(D_CBC_IDEA, testnum, count, d);
2617 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2618 if (doit[D_CBC_SEED]) {
2619 if (async_jobs > 0) {
2620 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2622 doit[D_CBC_SEED] = 0;
2624 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2625 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2626 lengths[testnum], seconds.sym);
2628 for (count = 0; COND(c[D_CBC_SEED][testnum]); count++)
2629 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2630 (size_t)lengths[testnum], &seed_ks, iv, 1);
2632 print_result(D_CBC_SEED, testnum, count, d);
2636 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2637 if (doit[D_CBC_RC2]) {
2638 if (async_jobs > 0) {
2639 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2641 doit[D_CBC_RC2] = 0;
2643 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2644 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2645 lengths[testnum], seconds.sym);
2646 if (async_jobs > 0) {
2647 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2651 for (count = 0; COND(c[D_CBC_RC2][testnum]); count++)
2652 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2653 (size_t)lengths[testnum], &rc2_ks,
2656 print_result(D_CBC_RC2, testnum, count, d);
2660 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2661 if (doit[D_CBC_RC5]) {
2662 if (async_jobs > 0) {
2663 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2665 doit[D_CBC_RC5] = 0;
2667 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2668 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2669 lengths[testnum], seconds.sym);
2670 if (async_jobs > 0) {
2671 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2675 for (count = 0; COND(c[D_CBC_RC5][testnum]); count++)
2676 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2677 (size_t)lengths[testnum], &rc5_ks,
2680 print_result(D_CBC_RC5, testnum, count, d);
2684 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2685 if (doit[D_CBC_BF]) {
2686 if (async_jobs > 0) {
2687 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2691 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2692 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2693 lengths[testnum], seconds.sym);
2695 for (count = 0; COND(c[D_CBC_BF][testnum]); count++)
2696 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2697 (size_t)lengths[testnum], &bf_ks,
2700 print_result(D_CBC_BF, testnum, count, d);
2704 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2705 if (doit[D_CBC_CAST]) {
2706 if (async_jobs > 0) {
2707 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2709 doit[D_CBC_CAST] = 0;
2711 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2712 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2713 lengths[testnum], seconds.sym);
2715 for (count = 0; COND(c[D_CBC_CAST][testnum]); count++)
2716 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2717 (size_t)lengths[testnum], &cast_ks,
2720 print_result(D_CBC_CAST, testnum, count, d);
2725 for (testnum = 0; testnum < size_num; testnum++) {
2726 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2729 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2731 print_result(D_RAND, testnum, count, d);
2736 if (evp_cipher != NULL) {
2737 int (*loopfunc) (void *) = EVP_Update_loop;
2739 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2740 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2741 multiblock_speed(evp_cipher, lengths_single, &seconds);
2746 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2748 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2749 loopfunc = EVP_Update_loop_ccm;
2750 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2751 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2752 loopfunc = EVP_Update_loop_aead;
2753 if (lengths == lengths_list) {
2754 lengths = aead_lengths_list;
2755 size_num = OSSL_NELEM(aead_lengths_list);
2759 for (testnum = 0; testnum < size_num; testnum++) {
2760 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2763 for (k = 0; k < loopargs_len; k++) {
2764 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2765 if (loopargs[k].ctx == NULL) {
2766 BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
2769 if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2770 NULL, iv, decrypt ? 0 : 1)) {
2771 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2772 ERR_print_errors(bio_err);
2776 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2778 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2779 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2780 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2781 if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2782 loopargs[k].key, NULL, -1)) {
2783 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2784 ERR_print_errors(bio_err);
2787 OPENSSL_clear_free(loopargs[k].key, keylen);
2789 /* SIV mode only allows for a single Update operation */
2790 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
2791 EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
2795 count = run_benchmark(async_jobs, loopfunc, loopargs);
2797 for (k = 0; k < loopargs_len; k++) {
2798 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2800 print_result(D_EVP, testnum, count, d);
2802 } else if (evp_md != NULL) {
2803 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2805 for (testnum = 0; testnum < size_num; testnum++) {
2806 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2809 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2811 print_result(D_EVP, testnum, count, d);
2816 #ifndef OPENSSL_NO_DEPRECATED_3_0
2817 if (doit[D_EVP_HMAC] && evp_hmac_md != NULL) {
2818 const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
2820 evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
2822 sprintf(evp_hmac_name, "HMAC(%s)", md_name);
2823 names[D_EVP_HMAC] = evp_hmac_name;
2825 for (testnum = 0; testnum < size_num; testnum++) {
2826 print_message(names[D_EVP_HMAC], c[D_EVP_HMAC][testnum], lengths[testnum],
2829 count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
2831 print_result(D_EVP_HMAC, testnum, count, d);
2836 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2837 if (doit[D_EVP_CMAC] && evp_cmac_cipher != NULL) {
2838 const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
2840 evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
2842 sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
2843 names[D_EVP_CMAC] = evp_cmac_name;
2845 for (i = 0; i < loopargs_len; i++) {
2846 loopargs[i].cmac_ctx = CMAC_CTX_new();
2847 if (loopargs[i].cmac_ctx == NULL) {
2848 BIO_printf(bio_err, "CMAC malloc failure, exiting...");
2852 for (testnum = 0; testnum < size_num; testnum++) {
2853 print_message(names[D_EVP_CMAC], c[D_EVP_CMAC][testnum], lengths[testnum],
2856 count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
2858 print_result(D_EVP_CMAC, testnum, count, d);
2860 for (i = 0; i < loopargs_len; i++)
2861 CMAC_CTX_free(loopargs[i].cmac_ctx);
2865 for (i = 0; i < loopargs_len; i++)
2866 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2869 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2870 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2872 if (!rsa_doit[testnum])
2874 for (i = 0; i < loopargs_len; i++) {
2875 if (primes > RSA_DEFAULT_PRIME_NUM) {
2876 /* we haven't set keys yet, generate multi-prime RSA keys */
2877 BIGNUM *bn = BN_new();
2881 if (!BN_set_word(bn, RSA_F4)) {
2886 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2887 rsa_choices[testnum].name);
2889 loopargs[i].rsa_key[testnum] = RSA_new();
2890 if (loopargs[i].rsa_key[testnum] == NULL) {
2895 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2896 rsa_keys[testnum].bits,
2897 primes, bn, NULL)) {
2903 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2904 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2910 "RSA sign failure. No RSA sign will be done.\n");
2911 ERR_print_errors(bio_err);
2914 pkey_print_message("private", "rsa",
2915 rsa_c[testnum][0], rsa_keys[testnum].bits,
2917 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2919 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2922 mr ? "+R1:%ld:%d:%.2f\n"
2923 : "%ld %u bits private RSA's in %.2fs\n",
2924 count, rsa_keys[testnum].bits, d);
2925 rsa_results[testnum][0] = (double)count / d;
2929 for (i = 0; i < loopargs_len; i++) {
2930 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2931 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2937 "RSA verify failure. No RSA verify will be done.\n");
2938 ERR_print_errors(bio_err);
2939 rsa_doit[testnum] = 0;
2941 pkey_print_message("public", "rsa",
2942 rsa_c[testnum][1], rsa_keys[testnum].bits,
2945 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2948 mr ? "+R2:%ld:%d:%.2f\n"
2949 : "%ld %u bits public RSA's in %.2fs\n",
2950 count, rsa_keys[testnum].bits, d);
2951 rsa_results[testnum][1] = (double)count / d;
2954 if (rsa_count <= 1) {
2955 /* if longer than 10s, don't do any more */
2956 stop_it(rsa_doit, testnum);
2959 #endif /* OPENSSL_NO_RSA */
2961 for (i = 0; i < loopargs_len; i++)
2962 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2965 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2966 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2968 if (!dsa_doit[testnum])
2971 /* DSA_generate_key(dsa_key[testnum]); */
2972 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2973 for (i = 0; i < loopargs_len; i++) {
2974 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2975 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2981 "DSA sign failure. No DSA sign will be done.\n");
2982 ERR_print_errors(bio_err);
2985 pkey_print_message("sign", "dsa",
2986 dsa_c[testnum][0], dsa_bits[testnum],
2989 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2992 mr ? "+R3:%ld:%u:%.2f\n"
2993 : "%ld %u bits DSA signs in %.2fs\n",
2994 count, dsa_bits[testnum], d);
2995 dsa_results[testnum][0] = (double)count / d;
2999 for (i = 0; i < loopargs_len; i++) {
3000 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3001 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
3007 "DSA verify failure. No DSA verify will be done.\n");
3008 ERR_print_errors(bio_err);
3009 dsa_doit[testnum] = 0;
3011 pkey_print_message("verify", "dsa",
3012 dsa_c[testnum][1], dsa_bits[testnum],
3015 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
3018 mr ? "+R4:%ld:%u:%.2f\n"
3019 : "%ld %u bits DSA verify in %.2fs\n",
3020 count, dsa_bits[testnum], d);
3021 dsa_results[testnum][1] = (double)count / d;
3024 if (rsa_count <= 1) {
3025 /* if longer than 10s, don't do any more */
3026 stop_it(dsa_doit, testnum);
3029 #endif /* OPENSSL_NO_DSA */
3031 #ifndef OPENSSL_NO_EC
3032 # ifndef OPENSSL_NO_DEPRECATED_3_0
3033 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
3036 if (!ecdsa_doit[testnum])
3037 continue; /* Ignore Curve */
3038 for (i = 0; i < loopargs_len; i++) {
3039 loopargs[i].ecdsa[testnum] =
3040 EC_KEY_new_by_curve_name(ec_curves[testnum].nid);
3041 if (loopargs[i].ecdsa[testnum] == NULL) {
3047 BIO_printf(bio_err, "ECDSA failure.\n");
3048 ERR_print_errors(bio_err);
3051 for (i = 0; i < loopargs_len; i++) {
3052 /* Perform ECDSA signature test */
3053 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
3054 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
3055 &loopargs[i].siglen,
3056 loopargs[i].ecdsa[testnum]);
3062 "ECDSA sign failure. No ECDSA sign will be done.\n");
3063 ERR_print_errors(bio_err);
3066 pkey_print_message("sign", "ecdsa",
3067 ecdsa_c[testnum][0],
3068 ec_curves[testnum].bits, seconds.ecdsa);
3070 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
3074 mr ? "+R5:%ld:%u:%.2f\n" :
3075 "%ld %u bits ECDSA signs in %.2fs \n",
3076 count, ec_curves[testnum].bits, d);
3077 ecdsa_results[testnum][0] = (double)count / d;
3081 /* Perform ECDSA verification test */
3082 for (i = 0; i < loopargs_len; i++) {
3083 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3085 loopargs[i].ecdsa[testnum]);
3091 "ECDSA verify failure. No ECDSA verify will be done.\n");
3092 ERR_print_errors(bio_err);
3093 ecdsa_doit[testnum] = 0;
3095 pkey_print_message("verify", "ecdsa",
3096 ecdsa_c[testnum][1],
3097 ec_curves[testnum].bits, seconds.ecdsa);
3099 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
3102 mr ? "+R6:%ld:%u:%.2f\n"
3103 : "%ld %u bits ECDSA verify in %.2fs\n",
3104 count, ec_curves[testnum].bits, d);
3105 ecdsa_results[testnum][1] = (double)count / d;
3108 if (rsa_count <= 1) {
3109 /* if longer than 10s, don't do any more */
3110 stop_it(ecdsa_doit, testnum);
3116 for (testnum = 0; testnum < EC_NUM; testnum++) {
3117 int ecdh_checks = 1;
3119 if (!ecdh_doit[testnum])
3122 for (i = 0; i < loopargs_len; i++) {
3123 EVP_PKEY_CTX *kctx = NULL;
3124 EVP_PKEY_CTX *test_ctx = NULL;
3125 EVP_PKEY_CTX *ctx = NULL;
3126 EVP_PKEY *key_A = NULL;
3127 EVP_PKEY *key_B = NULL;
3131 /* Ensure that the error queue is empty */
3132 if (ERR_peek_error()) {
3134 "WARNING: the error queue contains previous unhandled errors.\n");
3135 ERR_print_errors(bio_err);
3138 /* Let's try to create a ctx directly from the NID: this works for
3139 * curves like Curve25519 that are not implemented through the low
3140 * level EC interface.
3141 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
3142 * then we set the curve by NID before deriving the actual keygen
3143 * ctx for that specific curve. */
3144 kctx = EVP_PKEY_CTX_new_id(ec_curves[testnum].nid, NULL); /* keygen ctx from NID */
3146 EVP_PKEY_CTX *pctx = NULL;
3147 EVP_PKEY *params = NULL;
3149 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
3150 * "int_ctx_new:unsupported algorithm" error was added to the
3152 * We remove it from the error queue as we are handling it. */
3153 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
3154 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
3155 /* check that the error origin matches */
3156 ERR_GET_LIB(error) == ERR_LIB_EVP &&
3157 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
3158 ERR_get_error(); /* pop error from queue */
3159 if (ERR_peek_error()) {
3161 "Unhandled error in the error queue during ECDH init.\n");
3162 ERR_print_errors(bio_err);
3167 /* Create the context for parameter generation */
3168 if (!(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
3169 /* Initialise the parameter generation */
3170 !EVP_PKEY_paramgen_init(pctx) ||
3171 /* Set the curve by NID */
3172 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3175 /* Create the parameter object params */
3176 !EVP_PKEY_paramgen(pctx, ¶ms)) {
3178 BIO_printf(bio_err, "ECDH EC params init failure.\n");
3179 ERR_print_errors(bio_err);
3183 /* Create the context for the key generation */
3184 kctx = EVP_PKEY_CTX_new(params, NULL);
3186 EVP_PKEY_free(params);
3188 EVP_PKEY_CTX_free(pctx);
3191 if (kctx == NULL || /* keygen ctx is not null */
3192 EVP_PKEY_keygen_init(kctx) <= 0/* init keygen ctx */ ) {
3194 BIO_printf(bio_err, "ECDH keygen failure.\n");
3195 ERR_print_errors(bio_err);
3200 if (EVP_PKEY_keygen(kctx, &key_A) <= 0 || /* generate secret key A */
3201 EVP_PKEY_keygen(kctx, &key_B) <= 0 || /* generate secret key B */
3202 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
3203 EVP_PKEY_derive_init(ctx) <= 0 || /* init derivation ctx */
3204 EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 || /* set peer pubkey in ctx */
3205 EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 || /* determine max length */
3206 outlen == 0 || /* ensure outlen is a valid size */
3207 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
3209 BIO_printf(bio_err, "ECDH key generation failure.\n");
3210 ERR_print_errors(bio_err);
3215 /* Here we perform a test run, comparing the output of a*B and b*A;
3216 * we try this here and assume that further EVP_PKEY_derive calls
3217 * never fail, so we can skip checks in the actually benchmarked
3218 * code, for maximum performance. */
3219 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3220 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3221 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3222 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3223 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3224 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3225 test_outlen != outlen /* compare output length */ ) {
3227 BIO_printf(bio_err, "ECDH computation failure.\n");
3228 ERR_print_errors(bio_err);
3233 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3234 if (CRYPTO_memcmp(loopargs[i].secret_a,
3235 loopargs[i].secret_b, outlen)) {
3237 BIO_printf(bio_err, "ECDH computations don't match.\n");
3238 ERR_print_errors(bio_err);
3243 loopargs[i].ecdh_ctx[testnum] = ctx;
3244 loopargs[i].outlen[testnum] = outlen;
3246 EVP_PKEY_free(key_A);
3247 EVP_PKEY_free(key_B);
3248 EVP_PKEY_CTX_free(kctx);
3250 EVP_PKEY_CTX_free(test_ctx);
3253 if (ecdh_checks != 0) {
3254 pkey_print_message("", "ecdh",
3256 ec_curves[testnum].bits, seconds.ecdh);
3259 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3262 mr ? "+R7:%ld:%d:%.2f\n" :
3263 "%ld %u-bits ECDH ops in %.2fs\n", count,
3264 ec_curves[testnum].bits, d);
3265 ecdh_results[testnum][0] = (double)count / d;
3269 if (rsa_count <= 1) {
3270 /* if longer than 10s, don't do any more */
3271 stop_it(ecdh_doit, testnum);
3275 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3277 EVP_PKEY *ed_pkey = NULL;
3278 EVP_PKEY_CTX *ed_pctx = NULL;
3280 if (!eddsa_doit[testnum])
3281 continue; /* Ignore Curve */
3282 for (i = 0; i < loopargs_len; i++) {
3283 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3284 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3289 if ((ed_pctx = EVP_PKEY_CTX_new_id(ed_curves[testnum].nid, NULL))
3291 || EVP_PKEY_keygen_init(ed_pctx) <= 0
3292 || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) {
3294 EVP_PKEY_CTX_free(ed_pctx);
3297 EVP_PKEY_CTX_free(ed_pctx);
3299 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3302 EVP_PKEY_free(ed_pkey);
3305 EVP_PKEY_free(ed_pkey);
3308 BIO_printf(bio_err, "EdDSA failure.\n");
3309 ERR_print_errors(bio_err);
3312 for (i = 0; i < loopargs_len; i++) {
3313 /* Perform EdDSA signature test */
3314 loopargs[i].sigsize = ed_curves[testnum].sigsize;
3315 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3316 loopargs[i].buf2, &loopargs[i].sigsize,
3317 loopargs[i].buf, 20);
3323 "EdDSA sign failure. No EdDSA sign will be done.\n");
3324 ERR_print_errors(bio_err);
3327 pkey_print_message("sign", ed_curves[testnum].name,
3328 eddsa_c[testnum][0],
3329 ed_curves[testnum].bits, seconds.eddsa);
3331 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3335 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3336 "%ld %u bits %s signs in %.2fs \n",
3337 count, ed_curves[testnum].bits,
3338 ed_curves[testnum].name, d);
3339 eddsa_results[testnum][0] = (double)count / d;
3343 /* Perform EdDSA verification test */
3344 for (i = 0; i < loopargs_len; i++) {
3345 st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
3346 loopargs[i].buf2, loopargs[i].sigsize,
3347 loopargs[i].buf, 20);
3353 "EdDSA verify failure. No EdDSA verify will be done.\n");
3354 ERR_print_errors(bio_err);
3355 eddsa_doit[testnum] = 0;
3357 pkey_print_message("verify", ed_curves[testnum].name,
3358 eddsa_c[testnum][1],
3359 ed_curves[testnum].bits, seconds.eddsa);
3361 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3364 mr ? "+R9:%ld:%u:%s:%.2f\n"
3365 : "%ld %u bits %s verify in %.2fs\n",
3366 count, ed_curves[testnum].bits,
3367 ed_curves[testnum].name, d);
3368 eddsa_results[testnum][1] = (double)count / d;
3371 if (rsa_count <= 1) {
3372 /* if longer than 10s, don't do any more */
3373 stop_it(eddsa_doit, testnum);
3378 # ifndef OPENSSL_NO_SM2
3379 for (testnum = 0; testnum < SM2_NUM; testnum++) {
3381 EVP_PKEY *sm2_pkey = NULL;
3383 if (!sm2_doit[testnum])
3384 continue; /* Ignore Curve */
3385 /* Init signing and verification */
3386 for (i = 0; i < loopargs_len; i++) {
3387 EVP_PKEY_CTX *sm2_pctx = NULL;
3388 EVP_PKEY_CTX *sm2_vfy_pctx = NULL;
3389 EVP_PKEY_CTX *pctx = NULL;
3392 loopargs[i].sm2_ctx[testnum] = EVP_MD_CTX_new();
3393 loopargs[i].sm2_vfy_ctx[testnum] = EVP_MD_CTX_new();
3394 if (loopargs[i].sm2_ctx[testnum] == NULL
3395 || loopargs[i].sm2_vfy_ctx[testnum] == NULL)
3398 /* SM2 keys are generated as normal EC keys with a special curve */
3399 st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) == NULL
3400 || EVP_PKEY_keygen_init(pctx) <= 0
3401 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3402 sm2_curves[testnum].nid) <= 0
3403 || EVP_PKEY_keygen(pctx, &sm2_pkey) <= 0);
3404 EVP_PKEY_CTX_free(pctx);
3408 st = 0; /* set back to zero */
3409 /* attach it sooner to rely on main final cleanup */
3410 loopargs[i].sm2_pkey[testnum] = sm2_pkey;
3411 loopargs[i].sigsize = EVP_PKEY_size(sm2_pkey);
3413 sm2_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3414 sm2_vfy_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3415 if (sm2_pctx == NULL || sm2_vfy_pctx == NULL) {
3416 EVP_PKEY_CTX_free(sm2_vfy_pctx);
3420 /* attach them directly to respective ctx */
3421 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_ctx[testnum], sm2_pctx);
3422 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_vfy_ctx[testnum], sm2_vfy_pctx);
3425 * No need to allow user to set an explicit ID here, just use
3426 * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D.
3428 if (EVP_PKEY_CTX_set1_id(sm2_pctx, SM2_ID, SM2_ID_LEN) != 1
3429 || EVP_PKEY_CTX_set1_id(sm2_vfy_pctx, SM2_ID, SM2_ID_LEN) != 1)
3432 if (!EVP_DigestSignInit(loopargs[i].sm2_ctx[testnum], NULL,
3433 EVP_sm3(), NULL, sm2_pkey))
3435 if (!EVP_DigestVerifyInit(loopargs[i].sm2_vfy_ctx[testnum], NULL,
3436 EVP_sm3(), NULL, sm2_pkey))
3438 st = 1; /* mark loop as succeeded */
3441 BIO_printf(bio_err, "SM2 init failure.\n");
3442 ERR_print_errors(bio_err);
3445 for (i = 0; i < loopargs_len; i++) {
3446 size_t sm2_sigsize = loopargs[i].sigsize;
3448 /* Perform SM2 signature test */
3449 st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum],
3450 loopargs[i].buf2, &sm2_sigsize,
3451 loopargs[i].buf, 20);
3457 "SM2 sign failure. No SM2 sign will be done.\n");
3458 ERR_print_errors(bio_err);
3461 pkey_print_message("sign", sm2_curves[testnum].name,
3463 sm2_curves[testnum].bits, seconds.sm2);
3465 count = run_benchmark(async_jobs, SM2_sign_loop, loopargs);
3469 mr ? "+R10:%ld:%u:%s:%.2f\n" :
3470 "%ld %u bits %s signs in %.2fs \n",
3471 count, sm2_curves[testnum].bits,
3472 sm2_curves[testnum].name, d);
3473 sm2_results[testnum][0] = (double)count / d;
3477 /* Perform SM2 verification test */
3478 for (i = 0; i < loopargs_len; i++) {
3479 st = EVP_DigestVerify(loopargs[i].sm2_vfy_ctx[testnum],
3480 loopargs[i].buf2, loopargs[i].sigsize,
3481 loopargs[i].buf, 20);
3487 "SM2 verify failure. No SM2 verify will be done.\n");
3488 ERR_print_errors(bio_err);
3489 sm2_doit[testnum] = 0;
3491 pkey_print_message("verify", sm2_curves[testnum].name,
3493 sm2_curves[testnum].bits, seconds.sm2);
3495 count = run_benchmark(async_jobs, SM2_verify_loop, loopargs);
3498 mr ? "+R11:%ld:%u:%s:%.2f\n"
3499 : "%ld %u bits %s verify in %.2fs\n",
3500 count, sm2_curves[testnum].bits,
3501 sm2_curves[testnum].name, d);
3502 sm2_results[testnum][1] = (double)count / d;
3505 if (rsa_count <= 1) {
3506 /* if longer than 10s, don't do any more */
3507 for (testnum++; testnum < SM2_NUM; testnum++)
3508 sm2_doit[testnum] = 0;
3512 # endif /* OPENSSL_NO_SM2 */
3514 #endif /* OPENSSL_NO_EC */
3519 printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
3520 printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3522 printf("%s ", BN_options());
3523 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3524 printf("%s ", MD2_options());
3526 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3527 printf("%s ", RC4_options());
3529 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3530 printf("%s ", DES_options());
3532 #ifndef OPENSSL_NO_DEPRECATED_3_0
3533 printf("%s ", AES_options());
3535 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3536 printf("%s ", IDEA_options());
3538 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3539 printf("%s ", BF_options());
3541 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3542 printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
3550 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3553 for (testnum = 0; testnum < size_num; testnum++)
3554 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3558 for (k = 0; k < ALGOR_NUM; k++) {
3562 printf("+F:%u:%s", k, names[k]);
3564 printf("%-13s", names[k]);
3565 for (testnum = 0; testnum < size_num; testnum++) {
3566 if (results[k][testnum] > 10000 && !mr)
3567 printf(" %11.2fk", results[k][testnum] / 1e3);
3569 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3573 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3575 for (k = 0; k < RSA_NUM; k++) {
3578 if (testnum && !mr) {
3579 printf("%18ssign verify sign/s verify/s\n", " ");
3583 printf("+F2:%u:%u:%f:%f\n",
3584 k, rsa_keys[k].bits, rsa_results[k][0], rsa_results[k][1]);
3586 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3587 rsa_keys[k].bits, 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3588 rsa_results[k][0], rsa_results[k][1]);
3591 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3593 for (k = 0; k < DSA_NUM; k++) {
3596 if (testnum && !mr) {
3597 printf("%18ssign verify sign/s verify/s\n", " ");
3601 printf("+F3:%u:%u:%f:%f\n",
3602 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3604 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3605 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3606 dsa_results[k][0], dsa_results[k][1]);
3609 #ifndef OPENSSL_NO_EC
3611 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3614 if (testnum && !mr) {
3615 printf("%30ssign verify sign/s verify/s\n", " ");
3620 printf("+F4:%u:%u:%f:%f\n",
3621 k, ec_curves[k].bits,
3622 ecdsa_results[k][0], ecdsa_results[k][1]);
3624 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3625 ec_curves[k].bits, ec_curves[k].name,
3626 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3627 ecdsa_results[k][0], ecdsa_results[k][1]);
3631 for (k = 0; k < EC_NUM; k++) {
3634 if (testnum && !mr) {
3635 printf("%30sop op/s\n", " ");
3639 printf("+F5:%u:%u:%f:%f\n",
3640 k, ec_curves[k].bits,
3641 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3644 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3645 ec_curves[k].bits, ec_curves[k].name,
3646 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3650 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
3653 if (testnum && !mr) {
3654 printf("%30ssign verify sign/s verify/s\n", " ");
3659 printf("+F6:%u:%u:%s:%f:%f\n",
3660 k, ed_curves[k].bits, ed_curves[k].name,
3661 eddsa_results[k][0], eddsa_results[k][1]);
3663 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3664 ed_curves[k].bits, ed_curves[k].name,
3665 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
3666 eddsa_results[k][0], eddsa_results[k][1]);
3669 # ifndef OPENSSL_NO_SM2
3671 for (k = 0; k < OSSL_NELEM(sm2_doit); k++) {
3674 if (testnum && !mr) {
3675 printf("%30ssign verify sign/s verify/s\n", " ");
3680 printf("+F7:%u:%u:%s:%f:%f\n",
3681 k, sm2_curves[k].bits, sm2_curves[k].name,
3682 sm2_results[k][0], sm2_results[k][1]);
3684 printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3685 sm2_curves[k].bits, sm2_curves[k].name,
3686 1.0 / sm2_results[k][0], 1.0 / sm2_results[k][1],
3687 sm2_results[k][0], sm2_results[k][1]);
3690 #endif /* OPENSSL_NO_EC */
3695 ERR_print_errors(bio_err);
3696 for (i = 0; i < loopargs_len; i++) {
3697 OPENSSL_free(loopargs[i].buf_malloc);
3698 OPENSSL_free(loopargs[i].buf2_malloc);
3700 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3701 for (k = 0; k < RSA_NUM; k++)
3702 RSA_free(loopargs[i].rsa_key[k]);
3704 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3705 for (k = 0; k < DSA_NUM; k++)
3706 DSA_free(loopargs[i].dsa_key[k]);
3708 #ifndef OPENSSL_NO_EC
3709 for (k = 0; k < ECDSA_NUM; k++)
3710 EC_KEY_free(loopargs[i].ecdsa[k]);
3711 for (k = 0; k < EC_NUM; k++)
3712 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3713 for (k = 0; k < EdDSA_NUM; k++)
3714 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
3715 # ifndef OPENSSL_NO_SM2
3716 for (k = 0; k < SM2_NUM; k++) {
3717 EVP_PKEY_CTX *pctx = NULL;
3719 /* free signing ctx */
3720 if (loopargs[i].sm2_ctx[k] != NULL
3721 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_ctx[k])) != NULL)
3722 EVP_PKEY_CTX_free(pctx);
3723 EVP_MD_CTX_free(loopargs[i].sm2_ctx[k]);
3724 /* free verification ctx */
3725 if (loopargs[i].sm2_vfy_ctx[k] != NULL
3726 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_vfy_ctx[k])) != NULL)
3727 EVP_PKEY_CTX_free(pctx);
3728 EVP_MD_CTX_free(loopargs[i].sm2_vfy_ctx[k]);
3730 EVP_PKEY_free(loopargs[i].sm2_pkey[k]);
3733 OPENSSL_free(loopargs[i].secret_a);
3734 OPENSSL_free(loopargs[i].secret_b);
3737 #ifndef OPENSSL_NO_DEPRECATED_3_0
3738 OPENSSL_free(evp_hmac_name);
3740 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3741 OPENSSL_free(evp_cmac_name);
3744 if (async_jobs > 0) {
3745 for (i = 0; i < loopargs_len; i++)
3746 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3750 ASYNC_cleanup_thread();
3752 OPENSSL_free(loopargs);
3757 static void print_message(const char *s, long num, int length, int tm)
3761 mr ? "+DT:%s:%d:%d\n"
3762 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3763 (void)BIO_flush(bio_err);
3768 mr ? "+DN:%s:%ld:%d\n"
3769 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3770 (void)BIO_flush(bio_err);
3774 static void pkey_print_message(const char *str, const char *str2, long num,
3775 unsigned int bits, int tm)
3779 mr ? "+DTP:%d:%s:%s:%d\n"
3780 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
3781 (void)BIO_flush(bio_err);
3786 mr ? "+DNP:%ld:%d:%s:%s\n"
3787 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
3788 (void)BIO_flush(bio_err);
3792 static void print_result(int alg, int run_no, int count, double time_used)
3795 BIO_printf(bio_err, "%s error!\n", names[alg]);
3796 ERR_print_errors(bio_err);
3797 /* exit(1); disable exit until default provider enabled */
3801 mr ? "+R:%d:%s:%f\n"
3802 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3803 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3807 static char *sstrsep(char **string, const char *delim)
3810 char *token = *string;
3815 memset(isdelim, 0, sizeof(isdelim));
3819 isdelim[(unsigned char)(*delim)] = 1;
3823 while (!isdelim[(unsigned char)(**string)]) {
3835 static int do_multi(int multi, int size_num)
3840 static char sep[] = ":";
3842 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
3843 for (n = 0; n < multi; ++n) {
3844 if (pipe(fd) == -1) {
3845 BIO_printf(bio_err, "pipe failure\n");
3849 (void)BIO_flush(bio_err);
3856 if (dup(fd[1]) == -1) {
3857 BIO_printf(bio_err, "dup failed\n");
3866 printf("Forked child %d\n", n);
3869 /* for now, assume the pipe is long enough to take all the output */
3870 for (n = 0; n < multi; ++n) {
3875 f = fdopen(fds[n], "r");
3876 while (fgets(buf, sizeof(buf), f)) {
3877 p = strchr(buf, '\n');
3880 if (buf[0] != '+') {
3882 "Don't understand line '%s' from child %d\n", buf,
3886 printf("Got: %s from %d\n", buf, n);
3887 if (strncmp(buf, "+F:", 3) == 0) {
3892 alg = atoi(sstrsep(&p, sep));
3894 for (j = 0; j < size_num; ++j)
3895 results[alg][j] += atof(sstrsep(&p, sep));
3897 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3898 else if (strncmp(buf, "+F2:", 4) == 0) {
3903 k = atoi(sstrsep(&p, sep));
3906 d = atof(sstrsep(&p, sep));
3907 rsa_results[k][0] += d;
3909 d = atof(sstrsep(&p, sep));
3910 rsa_results[k][1] += d;
3913 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3914 else if (strncmp(buf, "+F3:", 4) == 0) {
3919 k = atoi(sstrsep(&p, sep));
3922 d = atof(sstrsep(&p, sep));
3923 dsa_results[k][0] += d;
3925 d = atof(sstrsep(&p, sep));
3926 dsa_results[k][1] += d;
3929 # ifndef OPENSSL_NO_EC
3930 else if (strncmp(buf, "+F4:", 4) == 0) {
3935 k = atoi(sstrsep(&p, sep));
3938 d = atof(sstrsep(&p, sep));
3939 ecdsa_results[k][0] += d;
3941 d = atof(sstrsep(&p, sep));
3942 ecdsa_results[k][1] += d;
3943 } else if (strncmp(buf, "+F5:", 4) == 0) {
3948 k = atoi(sstrsep(&p, sep));
3951 d = atof(sstrsep(&p, sep));
3952 ecdh_results[k][0] += d;
3953 } else if (strncmp(buf, "+F6:", 4) == 0) {
3958 k = atoi(sstrsep(&p, sep));
3962 d = atof(sstrsep(&p, sep));
3963 eddsa_results[k][0] += d;
3965 d = atof(sstrsep(&p, sep));
3966 eddsa_results[k][1] += d;
3968 # ifndef OPENSSL_NO_SM2
3969 else if (strncmp(buf, "+F7:", 4) == 0) {
3974 k = atoi(sstrsep(&p, sep));
3978 d = atof(sstrsep(&p, sep));
3979 sm2_results[k][0] += d;
3981 d = atof(sstrsep(&p, sep));
3982 sm2_results[k][1] += d;
3984 # endif /* OPENSSL_NO_SM2 */
3987 else if (strncmp(buf, "+H:", 3) == 0) {
3990 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
4001 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
4002 const openssl_speed_sec_t *seconds)
4004 static const int mblengths_list[] =
4005 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
4006 const int *mblengths = mblengths_list;
4007 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
4008 const char *alg_name;
4009 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
4010 EVP_CIPHER_CTX *ctx;
4013 if (lengths_single) {
4014 mblengths = &lengths_single;
4018 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
4019 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
4020 ctx = EVP_CIPHER_CTX_new();
4021 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
4023 keylen = EVP_CIPHER_CTX_key_length(ctx);
4024 key = app_malloc(keylen, "evp_cipher key");
4025 EVP_CIPHER_CTX_rand_key(ctx, key);
4026 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
4027 OPENSSL_clear_free(key, keylen);
4029 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
4030 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
4032 for (j = 0; j < num; j++) {
4033 print_message(alg_name, 0, mblengths[j], seconds->sym);
4035 for (count = 0; run && count < 0x7fffffff; count++) {
4036 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
4037 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
4038 size_t len = mblengths[j];
4041 memset(aad, 0, 8); /* avoid uninitialized values */
4042 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
4043 aad[9] = 3; /* version */
4045 aad[11] = 0; /* length */
4047 mb_param.out = NULL;
4050 mb_param.interleave = 8;
4052 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
4053 sizeof(mb_param), &mb_param);
4059 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
4060 sizeof(mb_param), &mb_param);
4064 RAND_bytes(out, 16);
4066 aad[11] = (unsigned char)(len >> 8);
4067 aad[12] = (unsigned char)(len);
4068 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
4069 EVP_AEAD_TLS1_AAD_LEN, aad);
4070 EVP_Cipher(ctx, out, inp, len + pad);
4074 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
4075 : "%d %s's in %.2fs\n", count, "evp", d);
4076 results[D_EVP][j] = ((double)count) / d * mblengths[j];
4080 fprintf(stdout, "+H");
4081 for (j = 0; j < num; j++)
4082 fprintf(stdout, ":%d", mblengths[j]);
4083 fprintf(stdout, "\n");
4084 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
4085 for (j = 0; j < num; j++)
4086 fprintf(stdout, ":%.2f", results[D_EVP][j]);
4087 fprintf(stdout, "\n");
4090 "The 'numbers' are in 1000s of bytes per second processed.\n");
4091 fprintf(stdout, "type ");
4092 for (j = 0; j < num; j++)
4093 fprintf(stdout, "%7d bytes", mblengths[j]);
4094 fprintf(stdout, "\n");
4095 fprintf(stdout, "%-24s", alg_name);
4097 for (j = 0; j < num; j++) {
4098 if (results[D_EVP][j] > 10000)
4099 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
4101 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
4103 fprintf(stdout, "\n");
4108 EVP_CIPHER_CTX_free(ctx);