2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #define RSA_SECONDS 10
14 #define DSA_SECONDS 10
15 #define ECDSA_SECONDS 10
16 #define ECDH_SECONDS 10
17 #define EdDSA_SECONDS 10
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,
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"},
306 {"algorithm", 0, 0, "Algorithm(s) to test (optional; otherwise tests all)"},
311 D_MD2, D_MDC2, D_MD4, D_MD5 , D_HMAC, D_SHA1, D_RMD160, D_RC4,
312 D_CBC_DES, D_EDE3_DES, D_CBC_IDEA, D_CBC_SEED,
313 D_CBC_RC2, D_CBC_RC5, D_CBC_BF, D_CBC_CAST,
314 D_CBC_128_AES, D_CBC_192_AES, D_CBC_256_AES,
315 D_CBC_128_CML, D_CBC_192_CML, D_CBC_256_CML,
316 D_EVP, D_SHA256, D_SHA512, D_WHIRLPOOL,
317 D_IGE_128_AES, D_IGE_192_AES, D_IGE_256_AES,
318 D_GHASH, D_RAND, D_EVP_HMAC, D_EVP_CMAC, ALGOR_NUM
320 /* name of algorithms to test. MUST BE KEEP IN SYNC with above enum ! */
321 static const char *names[ALGOR_NUM] = {
322 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
323 "des cbc", "des ede3", "idea cbc", "seed cbc",
324 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
325 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
326 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
327 "evp", "sha256", "sha512", "whirlpool",
328 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
329 "rand", "hmac", "cmac"
332 /* list of configured algorithm (remaining), with some few alias */
333 static const OPT_PAIR doit_choices[] = {
334 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
337 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
340 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
343 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
345 # ifndef OPENSSL_NO_DEPRECATED_3_0
349 #ifndef OPENSSL_NO_DEPRECATED_3_0
351 {"sha256", D_SHA256},
352 {"sha512", D_SHA512},
354 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
355 {"whirlpool", D_WHIRLPOOL},
357 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
358 {"ripemd", D_RMD160},
359 {"rmd160", D_RMD160},
360 {"ripemd160", D_RMD160},
362 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
365 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
366 {"des-cbc", D_CBC_DES},
367 {"des-ede3", D_EDE3_DES},
369 #ifndef OPENSSL_NO_DEPRECATED_3_0
370 {"aes-128-cbc", D_CBC_128_AES},
371 {"aes-192-cbc", D_CBC_192_AES},
372 {"aes-256-cbc", D_CBC_256_AES},
373 {"aes-128-ige", D_IGE_128_AES},
374 {"aes-192-ige", D_IGE_192_AES},
375 {"aes-256-ige", D_IGE_256_AES},
377 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
378 {"rc2-cbc", D_CBC_RC2},
381 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
382 {"rc5-cbc", D_CBC_RC5},
385 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
386 {"idea-cbc", D_CBC_IDEA},
387 {"idea", D_CBC_IDEA},
389 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
390 {"seed-cbc", D_CBC_SEED},
391 {"seed", D_CBC_SEED},
393 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
394 {"bf-cbc", D_CBC_BF},
395 {"blowfish", D_CBC_BF},
398 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
399 {"cast-cbc", D_CBC_CAST},
400 {"cast", D_CBC_CAST},
401 {"cast5", D_CBC_CAST},
407 static double results[ALGOR_NUM][SIZE_NUM];
409 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
410 enum { R_DSA_512, R_DSA_1024, R_DSA_2048, DSA_NUM };
411 static const OPT_PAIR dsa_choices[DSA_NUM] = {
412 {"dsa512", R_DSA_512},
413 {"dsa1024", R_DSA_1024},
414 {"dsa2048", R_DSA_2048}
416 static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
417 #endif /* OPENSSL_NO_DSA */
419 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
421 R_RSA_512, R_RSA_1024, R_RSA_2048, R_RSA_3072, R_RSA_4096, R_RSA_7680,
424 static const OPT_PAIR rsa_choices[RSA_NUM] = {
425 {"rsa512", R_RSA_512},
426 {"rsa1024", R_RSA_1024},
427 {"rsa2048", R_RSA_2048},
428 {"rsa3072", R_RSA_3072},
429 {"rsa4096", R_RSA_4096},
430 {"rsa7680", R_RSA_7680},
431 {"rsa15360", R_RSA_15360}
434 static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
435 #endif /* OPENSSL_NO_RSA */
437 #ifndef OPENSSL_NO_EC
439 R_EC_P160, R_EC_P192, R_EC_P224, R_EC_P256, R_EC_P384, R_EC_P521,
440 # ifndef OPENSSL_NO_EC2M
441 R_EC_K163, R_EC_K233, R_EC_K283, R_EC_K409, R_EC_K571,
442 R_EC_B163, R_EC_B233, R_EC_B283, R_EC_B409, R_EC_B571,
444 R_EC_BRP256R1, R_EC_BRP256T1, R_EC_BRP384R1, R_EC_BRP384T1,
445 R_EC_BRP512R1, R_EC_BRP512T1, ECDSA_NUM
447 /* list of ecdsa curves */
448 static const OPT_PAIR ecdsa_choices[ECDSA_NUM] = {
449 {"ecdsap160", R_EC_P160},
450 {"ecdsap192", R_EC_P192},
451 {"ecdsap224", R_EC_P224},
452 {"ecdsap256", R_EC_P256},
453 {"ecdsap384", R_EC_P384},
454 {"ecdsap521", R_EC_P521},
455 # ifndef OPENSSL_NO_EC2M
456 {"ecdsak163", R_EC_K163},
457 {"ecdsak233", R_EC_K233},
458 {"ecdsak283", R_EC_K283},
459 {"ecdsak409", R_EC_K409},
460 {"ecdsak571", R_EC_K571},
461 {"ecdsab163", R_EC_B163},
462 {"ecdsab233", R_EC_B233},
463 {"ecdsab283", R_EC_B283},
464 {"ecdsab409", R_EC_B409},
465 {"ecdsab571", R_EC_B571},
467 {"ecdsabrp256r1", R_EC_BRP256R1},
468 {"ecdsabrp256t1", R_EC_BRP256T1},
469 {"ecdsabrp384r1", R_EC_BRP384R1},
470 {"ecdsabrp384t1", R_EC_BRP384T1},
471 {"ecdsabrp512r1", R_EC_BRP512R1},
472 {"ecdsabrp512t1", R_EC_BRP512T1}
474 enum { R_EC_X25519 = ECDSA_NUM, R_EC_X448, EC_NUM };
475 /* list of ecdh curves, extension of |ecdsa_choices| list above */
476 static const OPT_PAIR ecdh_choices[EC_NUM] = {
477 {"ecdhp160", R_EC_P160},
478 {"ecdhp192", R_EC_P192},
479 {"ecdhp224", R_EC_P224},
480 {"ecdhp256", R_EC_P256},
481 {"ecdhp384", R_EC_P384},
482 {"ecdhp521", R_EC_P521},
483 # ifndef OPENSSL_NO_EC2M
484 {"ecdhk163", R_EC_K163},
485 {"ecdhk233", R_EC_K233},
486 {"ecdhk283", R_EC_K283},
487 {"ecdhk409", R_EC_K409},
488 {"ecdhk571", R_EC_K571},
489 {"ecdhb163", R_EC_B163},
490 {"ecdhb233", R_EC_B233},
491 {"ecdhb283", R_EC_B283},
492 {"ecdhb409", R_EC_B409},
493 {"ecdhb571", R_EC_B571},
495 {"ecdhbrp256r1", R_EC_BRP256R1},
496 {"ecdhbrp256t1", R_EC_BRP256T1},
497 {"ecdhbrp384r1", R_EC_BRP384R1},
498 {"ecdhbrp384t1", R_EC_BRP384T1},
499 {"ecdhbrp512r1", R_EC_BRP512R1},
500 {"ecdhbrp512t1", R_EC_BRP512T1},
501 {"ecdhx25519", R_EC_X25519},
502 {"ecdhx448", R_EC_X448}
505 static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
506 static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
508 enum { R_EC_Ed25519, R_EC_Ed448, EdDSA_NUM };
509 static const OPT_PAIR eddsa_choices[EdDSA_NUM] = {
510 {"ed25519", R_EC_Ed25519},
511 {"ed448", R_EC_Ed448}
514 static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
516 # ifndef OPENSSL_NO_SM2
517 enum { R_EC_CURVESM2, SM2_NUM };
518 static const OPT_PAIR sm2_choices[SM2_NUM] = {
519 {"curveSM2", R_EC_CURVESM2}
521 # define SM2_ID "TLSv1.3+GM+Cipher+Suite"
522 # define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1
523 static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */
524 # endif /* OPENSSL_NO_SM2 */
525 #endif /* OPENSSL_NO_EC */
528 # define COND(d) (count < (d))
529 # define COUNT(d) (d)
531 # define COND(unused_cond) (run && count<0x7fffffff)
532 # define COUNT(d) (count)
535 typedef struct loopargs_st {
536 ASYNC_JOB *inprogress_job;
537 ASYNC_WAIT_CTX *wait_ctx;
540 unsigned char *buf_malloc;
541 unsigned char *buf2_malloc;
545 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
546 RSA *rsa_key[RSA_NUM];
548 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
549 DSA *dsa_key[DSA_NUM];
551 #ifndef OPENSSL_NO_EC
552 EC_KEY *ecdsa[ECDSA_NUM];
553 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
554 EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
555 # ifndef OPENSSL_NO_SM2
556 EVP_MD_CTX *sm2_ctx[SM2_NUM];
557 EVP_MD_CTX *sm2_vfy_ctx[SM2_NUM];
558 EVP_PKEY *sm2_pkey[SM2_NUM];
560 unsigned char *secret_a;
561 unsigned char *secret_b;
562 size_t outlen[EC_NUM];
565 #ifndef OPENSSL_NO_DEPRECATED_3_0
568 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
571 GCM128_CONTEXT *gcm_ctx;
573 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
574 loopargs_t * loopargs);
576 static unsigned int testnum;
578 /* Nb of iterations to do per algorithm and key-size */
579 static long c[ALGOR_NUM][SIZE_NUM];
581 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
582 static int EVP_Digest_MD2_loop(void *args)
584 loopargs_t *tempargs = *(loopargs_t **) args;
585 unsigned char *buf = tempargs->buf;
586 unsigned char md2[MD2_DIGEST_LENGTH];
589 for (count = 0; COND(c[D_MD2][testnum]); count++) {
590 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
598 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
599 static int EVP_Digest_MDC2_loop(void *args)
601 loopargs_t *tempargs = *(loopargs_t **) args;
602 unsigned char *buf = tempargs->buf;
603 unsigned char mdc2[MDC2_DIGEST_LENGTH];
606 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
607 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
615 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
616 static int EVP_Digest_MD4_loop(void *args)
618 loopargs_t *tempargs = *(loopargs_t **) args;
619 unsigned char *buf = tempargs->buf;
620 unsigned char md4[MD4_DIGEST_LENGTH];
623 for (count = 0; COND(c[D_MD4][testnum]); count++) {
624 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
632 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
633 static int MD5_loop(void *args)
635 loopargs_t *tempargs = *(loopargs_t **) args;
636 unsigned char *buf = tempargs->buf;
637 unsigned char md5[MD5_DIGEST_LENGTH];
639 for (count = 0; COND(c[D_MD5][testnum]); count++)
640 MD5(buf, lengths[testnum], md5);
644 # ifndef OPENSSL_NO_DEPRECATED_3_0
645 static int HMAC_loop(void *args)
647 loopargs_t *tempargs = *(loopargs_t **) args;
648 unsigned char *buf = tempargs->buf;
649 HMAC_CTX *hctx = tempargs->hctx;
650 unsigned char hmac[MD5_DIGEST_LENGTH];
653 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
654 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
655 HMAC_Update(hctx, buf, lengths[testnum]);
656 HMAC_Final(hctx, hmac, NULL);
663 #ifndef OPENSSL_NO_DEPRECATED_3_0
664 static int SHA1_loop(void *args)
666 loopargs_t *tempargs = *(loopargs_t **) args;
667 unsigned char *buf = tempargs->buf;
668 unsigned char sha[SHA_DIGEST_LENGTH];
670 for (count = 0; COND(c[D_SHA1][testnum]); count++)
671 SHA1(buf, lengths[testnum], sha);
675 static int SHA256_loop(void *args)
677 loopargs_t *tempargs = *(loopargs_t **) args;
678 unsigned char *buf = tempargs->buf;
679 unsigned char sha256[SHA256_DIGEST_LENGTH];
681 for (count = 0; COND(c[D_SHA256][testnum]); count++)
682 SHA256(buf, lengths[testnum], sha256);
686 static int SHA512_loop(void *args)
688 loopargs_t *tempargs = *(loopargs_t **) args;
689 unsigned char *buf = tempargs->buf;
690 unsigned char sha512[SHA512_DIGEST_LENGTH];
692 for (count = 0; COND(c[D_SHA512][testnum]); count++)
693 SHA512(buf, lengths[testnum], sha512);
698 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
699 static int WHIRLPOOL_loop(void *args)
701 loopargs_t *tempargs = *(loopargs_t **) args;
702 unsigned char *buf = tempargs->buf;
703 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
705 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
706 WHIRLPOOL(buf, lengths[testnum], whirlpool);
711 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
712 static int EVP_Digest_RMD160_loop(void *args)
714 loopargs_t *tempargs = *(loopargs_t **) args;
715 unsigned char *buf = tempargs->buf;
716 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
718 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
719 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
720 NULL, EVP_ripemd160(), NULL))
727 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
728 static RC4_KEY rc4_ks;
729 static int RC4_loop(void *args)
731 loopargs_t *tempargs = *(loopargs_t **) args;
732 unsigned char *buf = tempargs->buf;
734 for (count = 0; COND(c[D_RC4][testnum]); count++)
735 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
740 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
741 static unsigned char DES_iv[8];
742 static DES_key_schedule sch[3];
743 static int DES_ncbc_encrypt_loop(void *args)
745 loopargs_t *tempargs = *(loopargs_t **) args;
746 unsigned char *buf = tempargs->buf;
748 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
749 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch[0],
750 &DES_iv, DES_ENCRYPT);
754 static int DES_ede3_cbc_encrypt_loop(void *args)
756 loopargs_t *tempargs = *(loopargs_t **) args;
757 unsigned char *buf = tempargs->buf;
759 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
760 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
761 &sch[0], &sch[1], &sch[2], &DES_iv, DES_ENCRYPT);
766 #define MAX_BLOCK_SIZE 128
768 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
770 #ifndef OPENSSL_NO_DEPRECATED_3_0
771 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
772 static int AES_cbc_128_encrypt_loop(void *args)
774 loopargs_t *tempargs = *(loopargs_t **) args;
775 unsigned char *buf = tempargs->buf;
777 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
778 AES_cbc_encrypt(buf, buf,
779 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
783 static int AES_cbc_192_encrypt_loop(void *args)
785 loopargs_t *tempargs = *(loopargs_t **) args;
786 unsigned char *buf = tempargs->buf;
788 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
789 AES_cbc_encrypt(buf, buf,
790 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
794 static int AES_cbc_256_encrypt_loop(void *args)
796 loopargs_t *tempargs = *(loopargs_t **) args;
797 unsigned char *buf = tempargs->buf;
799 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
800 AES_cbc_encrypt(buf, buf,
801 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
805 static int AES_ige_128_encrypt_loop(void *args)
807 loopargs_t *tempargs = *(loopargs_t **) args;
808 unsigned char *buf = tempargs->buf;
809 unsigned char *buf2 = tempargs->buf2;
811 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
812 AES_ige_encrypt(buf, buf2,
813 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
817 static int AES_ige_192_encrypt_loop(void *args)
819 loopargs_t *tempargs = *(loopargs_t **) args;
820 unsigned char *buf = tempargs->buf;
821 unsigned char *buf2 = tempargs->buf2;
823 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
824 AES_ige_encrypt(buf, buf2,
825 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
829 static int AES_ige_256_encrypt_loop(void *args)
831 loopargs_t *tempargs = *(loopargs_t **) args;
832 unsigned char *buf = tempargs->buf;
833 unsigned char *buf2 = tempargs->buf2;
835 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
836 AES_ige_encrypt(buf, buf2,
837 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
841 static int CRYPTO_gcm128_aad_loop(void *args)
843 loopargs_t *tempargs = *(loopargs_t **) args;
844 unsigned char *buf = tempargs->buf;
845 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
847 for (count = 0; COND(c[D_GHASH][testnum]); count++)
848 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
853 static int RAND_bytes_loop(void *args)
855 loopargs_t *tempargs = *(loopargs_t **) args;
856 unsigned char *buf = tempargs->buf;
859 for (count = 0; COND(c[D_RAND][testnum]); count++)
860 RAND_bytes(buf, lengths[testnum]);
864 static int decrypt = 0;
865 static int EVP_Update_loop(void *args)
867 loopargs_t *tempargs = *(loopargs_t **) args;
868 unsigned char *buf = tempargs->buf;
869 EVP_CIPHER_CTX *ctx = tempargs->ctx;
873 for (count = 0; COND(c[D_EVP][testnum]); count++) {
874 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
876 /* reset iv in case of counter overflow */
877 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
881 for (count = 0; COND(c[D_EVP][testnum]); count++) {
882 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
884 /* reset iv in case of counter overflow */
885 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
890 EVP_DecryptFinal_ex(ctx, buf, &outl);
892 EVP_EncryptFinal_ex(ctx, buf, &outl);
897 * CCM does not support streaming. For the purpose of performance measurement,
898 * each message is encrypted using the same (key,iv)-pair. Do not use this
899 * code in your application.
901 static int EVP_Update_loop_ccm(void *args)
903 loopargs_t *tempargs = *(loopargs_t **) args;
904 unsigned char *buf = tempargs->buf;
905 EVP_CIPHER_CTX *ctx = tempargs->ctx;
907 unsigned char tag[12];
910 for (count = 0; COND(c[D_EVP][testnum]); count++) {
911 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
913 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
914 /* counter is reset on every update */
915 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
918 for (count = 0; COND(c[D_EVP][testnum]); count++) {
919 /* restore iv length field */
920 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
921 /* counter is reset on every update */
922 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
926 EVP_DecryptFinal_ex(ctx, buf, &outl);
928 EVP_EncryptFinal_ex(ctx, buf, &outl);
933 * To make AEAD benchmarking more relevant perform TLS-like operations,
934 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
935 * payload length is not actually limited by 16KB...
937 static int EVP_Update_loop_aead(void *args)
939 loopargs_t *tempargs = *(loopargs_t **) args;
940 unsigned char *buf = tempargs->buf;
941 EVP_CIPHER_CTX *ctx = tempargs->ctx;
943 unsigned char aad[13] = { 0xcc };
944 unsigned char faketag[16] = { 0xcc };
947 for (count = 0; COND(c[D_EVP][testnum]); count++) {
948 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
949 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
950 sizeof(faketag), faketag);
951 EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
952 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
953 EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
956 for (count = 0; COND(c[D_EVP][testnum]); count++) {
957 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
958 EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
959 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
960 EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
966 static const EVP_MD *evp_md = NULL;
967 static int EVP_Digest_loop(void *args)
969 loopargs_t *tempargs = *(loopargs_t **) args;
970 unsigned char *buf = tempargs->buf;
971 unsigned char md[EVP_MAX_MD_SIZE];
974 for (count = 0; COND(c[D_EVP][testnum]); count++) {
975 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
981 #ifndef OPENSSL_NO_DEPRECATED_3_0
982 static const EVP_MD *evp_hmac_md = NULL;
983 static char *evp_hmac_name = NULL;
984 static int EVP_HMAC_loop(void *args)
986 loopargs_t *tempargs = *(loopargs_t **) args;
987 unsigned char *buf = tempargs->buf;
988 unsigned char no_key[32];
991 for (count = 0; COND(c[D_EVP_HMAC][testnum]); count++) {
992 if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
1000 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1001 static const EVP_CIPHER *evp_cmac_cipher = NULL;
1002 static char *evp_cmac_name = NULL;
1004 static int EVP_CMAC_loop(void *args)
1006 loopargs_t *tempargs = *(loopargs_t **) args;
1007 unsigned char *buf = tempargs->buf;
1008 CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
1009 static const char key[16] = "This is a key...";
1010 unsigned char mac[16];
1011 size_t len = sizeof(mac);
1014 for (count = 0; COND(c[D_EVP_CMAC][testnum]); count++) {
1015 if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
1016 || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
1017 || !CMAC_Final(cmac_ctx, mac, &len))
1024 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1025 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
1027 static int RSA_sign_loop(void *args)
1029 loopargs_t *tempargs = *(loopargs_t **) args;
1030 unsigned char *buf = tempargs->buf;
1031 unsigned char *buf2 = tempargs->buf2;
1032 unsigned int *rsa_num = &tempargs->siglen;
1033 RSA **rsa_key = tempargs->rsa_key;
1035 for (count = 0; COND(rsa_c[testnum][0]); count++) {
1036 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1038 BIO_printf(bio_err, "RSA sign failure\n");
1039 ERR_print_errors(bio_err);
1047 static int RSA_verify_loop(void *args)
1049 loopargs_t *tempargs = *(loopargs_t **) args;
1050 unsigned char *buf = tempargs->buf;
1051 unsigned char *buf2 = tempargs->buf2;
1052 unsigned int rsa_num = tempargs->siglen;
1053 RSA **rsa_key = tempargs->rsa_key;
1055 for (count = 0; COND(rsa_c[testnum][1]); count++) {
1057 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
1059 BIO_printf(bio_err, "RSA verify failure\n");
1060 ERR_print_errors(bio_err);
1069 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1070 static long dsa_c[DSA_NUM][2];
1071 static int DSA_sign_loop(void *args)
1073 loopargs_t *tempargs = *(loopargs_t **) args;
1074 unsigned char *buf = tempargs->buf;
1075 unsigned char *buf2 = tempargs->buf2;
1076 DSA **dsa_key = tempargs->dsa_key;
1077 unsigned int *siglen = &tempargs->siglen;
1079 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1080 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1082 BIO_printf(bio_err, "DSA sign failure\n");
1083 ERR_print_errors(bio_err);
1091 static int DSA_verify_loop(void *args)
1093 loopargs_t *tempargs = *(loopargs_t **) args;
1094 unsigned char *buf = tempargs->buf;
1095 unsigned char *buf2 = tempargs->buf2;
1096 DSA **dsa_key = tempargs->dsa_key;
1097 unsigned int siglen = tempargs->siglen;
1099 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1100 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1102 BIO_printf(bio_err, "DSA verify failure\n");
1103 ERR_print_errors(bio_err);
1112 #ifndef OPENSSL_NO_EC
1113 # ifndef OPENSSL_NO_DEPRECATED_3_0
1114 static long ecdsa_c[ECDSA_NUM][2];
1115 static int ECDSA_sign_loop(void *args)
1117 loopargs_t *tempargs = *(loopargs_t **) args;
1118 unsigned char *buf = tempargs->buf;
1119 EC_KEY **ecdsa = tempargs->ecdsa;
1120 unsigned char *ecdsasig = tempargs->buf2;
1121 unsigned int *ecdsasiglen = &tempargs->siglen;
1123 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1124 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1126 BIO_printf(bio_err, "ECDSA sign failure\n");
1127 ERR_print_errors(bio_err);
1135 static int ECDSA_verify_loop(void *args)
1137 loopargs_t *tempargs = *(loopargs_t **) args;
1138 unsigned char *buf = tempargs->buf;
1139 EC_KEY **ecdsa = tempargs->ecdsa;
1140 unsigned char *ecdsasig = tempargs->buf2;
1141 unsigned int ecdsasiglen = tempargs->siglen;
1143 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1144 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1146 BIO_printf(bio_err, "ECDSA verify failure\n");
1147 ERR_print_errors(bio_err);
1156 /* ******************************************************************** */
1157 static long ecdh_c[EC_NUM][1];
1159 static int ECDH_EVP_derive_key_loop(void *args)
1161 loopargs_t *tempargs = *(loopargs_t **) args;
1162 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1163 unsigned char *derived_secret = tempargs->secret_a;
1165 size_t *outlen = &(tempargs->outlen[testnum]);
1167 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1168 EVP_PKEY_derive(ctx, derived_secret, outlen);
1173 static long eddsa_c[EdDSA_NUM][2];
1174 static int EdDSA_sign_loop(void *args)
1176 loopargs_t *tempargs = *(loopargs_t **) args;
1177 unsigned char *buf = tempargs->buf;
1178 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1179 unsigned char *eddsasig = tempargs->buf2;
1180 size_t *eddsasigsize = &tempargs->sigsize;
1183 for (count = 0; COND(eddsa_c[testnum][0]); count++) {
1184 ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1186 BIO_printf(bio_err, "EdDSA sign failure\n");
1187 ERR_print_errors(bio_err);
1195 static int EdDSA_verify_loop(void *args)
1197 loopargs_t *tempargs = *(loopargs_t **) args;
1198 unsigned char *buf = tempargs->buf;
1199 EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
1200 unsigned char *eddsasig = tempargs->buf2;
1201 size_t eddsasigsize = tempargs->sigsize;
1204 for (count = 0; COND(eddsa_c[testnum][1]); count++) {
1205 ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
1207 BIO_printf(bio_err, "EdDSA verify failure\n");
1208 ERR_print_errors(bio_err);
1216 # ifndef OPENSSL_NO_SM2
1217 static long sm2_c[SM2_NUM][2];
1218 static int SM2_sign_loop(void *args)
1220 loopargs_t *tempargs = *(loopargs_t **) args;
1221 unsigned char *buf = tempargs->buf;
1222 EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx;
1223 unsigned char *sm2sig = tempargs->buf2;
1224 size_t sm2sigsize = tempargs->sigsize;
1225 const size_t max_size = tempargs->sigsize;
1227 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1229 for (count = 0; COND(sm2_c[testnum][0]); count++) {
1230 if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(),
1231 NULL, sm2_pkey[testnum])) {
1232 BIO_printf(bio_err, "SM2 init sign failure\n");
1233 ERR_print_errors(bio_err);
1237 ret = EVP_DigestSign(sm2ctx[testnum], sm2sig, &sm2sigsize,
1240 BIO_printf(bio_err, "SM2 sign failure\n");
1241 ERR_print_errors(bio_err);
1245 /* update the latest returned size and always use the fixed buffer size */
1246 tempargs->sigsize = sm2sigsize;
1247 sm2sigsize = max_size;
1253 static int SM2_verify_loop(void *args)
1255 loopargs_t *tempargs = *(loopargs_t **) args;
1256 unsigned char *buf = tempargs->buf;
1257 EVP_MD_CTX **sm2ctx = tempargs->sm2_vfy_ctx;
1258 unsigned char *sm2sig = tempargs->buf2;
1259 size_t sm2sigsize = tempargs->sigsize;
1261 EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
1263 for (count = 0; COND(sm2_c[testnum][1]); count++) {
1264 if (!EVP_DigestVerifyInit(sm2ctx[testnum], NULL, EVP_sm3(),
1265 NULL, sm2_pkey[testnum])) {
1266 BIO_printf(bio_err, "SM2 verify init failure\n");
1267 ERR_print_errors(bio_err);
1271 ret = EVP_DigestVerify(sm2ctx[testnum], sm2sig, sm2sigsize,
1274 BIO_printf(bio_err, "SM2 verify failure\n");
1275 ERR_print_errors(bio_err);
1282 # endif /* OPENSSL_NO_SM2 */
1283 #endif /* OPENSSL_NO_EC */
1285 static int run_benchmark(int async_jobs,
1286 int (*loop_function) (void *), loopargs_t * loopargs)
1288 int job_op_count = 0;
1289 int total_op_count = 0;
1290 int num_inprogress = 0;
1291 int error = 0, i = 0, ret = 0;
1292 OSSL_ASYNC_FD job_fd = 0;
1293 size_t num_job_fds = 0;
1295 if (async_jobs == 0) {
1296 return loop_function((void *)&loopargs);
1299 for (i = 0; i < async_jobs && !error; i++) {
1300 loopargs_t *looparg_item = loopargs + i;
1302 /* Copy pointer content (looparg_t item address) into async context */
1303 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1304 &job_op_count, loop_function,
1305 (void *)&looparg_item, sizeof(looparg_item));
1311 if (job_op_count == -1) {
1314 total_op_count += job_op_count;
1319 BIO_printf(bio_err, "Failure in the job\n");
1320 ERR_print_errors(bio_err);
1326 while (num_inprogress > 0) {
1327 #if defined(OPENSSL_SYS_WINDOWS)
1329 #elif defined(OPENSSL_SYS_UNIX)
1330 int select_result = 0;
1331 OSSL_ASYNC_FD max_fd = 0;
1334 FD_ZERO(&waitfdset);
1336 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1337 if (loopargs[i].inprogress_job == NULL)
1340 if (!ASYNC_WAIT_CTX_get_all_fds
1341 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1342 || num_job_fds > 1) {
1343 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1344 ERR_print_errors(bio_err);
1348 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1350 FD_SET(job_fd, &waitfdset);
1351 if (job_fd > max_fd)
1355 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1357 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1358 "Decrease the value of async_jobs\n",
1359 max_fd, FD_SETSIZE);
1360 ERR_print_errors(bio_err);
1365 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1366 if (select_result == -1 && errno == EINTR)
1369 if (select_result == -1) {
1370 BIO_printf(bio_err, "Failure in the select\n");
1371 ERR_print_errors(bio_err);
1376 if (select_result == 0)
1380 for (i = 0; i < async_jobs; i++) {
1381 if (loopargs[i].inprogress_job == NULL)
1384 if (!ASYNC_WAIT_CTX_get_all_fds
1385 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1386 || num_job_fds > 1) {
1387 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1388 ERR_print_errors(bio_err);
1392 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1395 #if defined(OPENSSL_SYS_UNIX)
1396 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1398 #elif defined(OPENSSL_SYS_WINDOWS)
1399 if (num_job_fds == 1
1400 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1405 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1406 loopargs[i].wait_ctx, &job_op_count,
1407 loop_function, (void *)(loopargs + i),
1408 sizeof(loopargs_t));
1413 if (job_op_count == -1) {
1416 total_op_count += job_op_count;
1419 loopargs[i].inprogress_job = NULL;
1424 loopargs[i].inprogress_job = NULL;
1425 BIO_printf(bio_err, "Failure in the job\n");
1426 ERR_print_errors(bio_err);
1433 return error ? -1 : total_op_count;
1436 #define stop_it(do_it, test_num)\
1437 memset(do_it + test_num, 0, OSSL_NELEM(do_it) - test_num);
1439 int speed_main(int argc, char **argv)
1442 loopargs_t *loopargs = NULL;
1444 const char *engine_id = NULL;
1445 const EVP_CIPHER *evp_cipher = NULL;
1448 int async_init = 0, multiblock = 0, pr_header = 0;
1449 uint8_t doit[ALGOR_NUM] = { 0 };
1450 int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
1452 unsigned int size_num = SIZE_NUM;
1453 unsigned int i, k, loopargs_len = 0, async_jobs = 0;
1459 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1460 || !defined(OPENSSL_NO_EC)
1463 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1464 ECDSA_SECONDS, ECDH_SECONDS,
1465 EdDSA_SECONDS, SM2_SECONDS };
1467 /* What follows are the buffers and key material. */
1468 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1471 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1474 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1475 IDEA_KEY_SCHEDULE idea_ks;
1477 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1478 SEED_KEY_SCHEDULE seed_ks;
1480 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1483 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1486 #ifndef OPENSSL_NO_DEPRECATED_3_0
1487 static const unsigned char key16[16] = {
1488 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1489 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1491 static const unsigned char key24[24] = {
1492 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1493 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1494 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1496 static const unsigned char key32[32] = {
1497 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1498 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1499 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1500 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1503 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1504 CAMELLIA_KEY camellia_ks[3];
1506 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1507 static const struct {
1508 const unsigned char *data;
1509 unsigned int length;
1512 { test512, sizeof(test512), 512 },
1513 { test1024, sizeof(test1024), 1024 },
1514 { test2048, sizeof(test2048), 2048 },
1515 { test3072, sizeof(test3072), 3072 },
1516 { test4096, sizeof(test4096), 4092 },
1517 { test7680, sizeof(test7680), 7680 },
1518 { test15360, sizeof(test15360), 15360 }
1520 uint8_t rsa_doit[RSA_NUM] = { 0 };
1521 int primes = RSA_DEFAULT_PRIME_NUM;
1523 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1524 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1525 uint8_t dsa_doit[DSA_NUM] = { 0 };
1527 #ifndef OPENSSL_NO_EC
1528 typedef struct ec_curve_st {
1532 size_t sigsize; /* only used for EdDSA curves */
1535 * We only test over the following curves as they are representative, To
1536 * add tests over more curves, simply add the curve NID and curve name to
1537 * the following arrays and increase the |ecdh_choices| and |ecdsa_choices|
1538 * lists accordingly.
1540 static const EC_CURVE ec_curves[EC_NUM] = {
1542 {"secp160r1", NID_secp160r1, 160},
1543 {"nistp192", NID_X9_62_prime192v1, 192},
1544 {"nistp224", NID_secp224r1, 224},
1545 {"nistp256", NID_X9_62_prime256v1, 256},
1546 {"nistp384", NID_secp384r1, 384},
1547 {"nistp521", NID_secp521r1, 521},
1548 # ifndef OPENSSL_NO_EC2M
1550 {"nistk163", NID_sect163k1, 163},
1551 {"nistk233", NID_sect233k1, 233},
1552 {"nistk283", NID_sect283k1, 283},
1553 {"nistk409", NID_sect409k1, 409},
1554 {"nistk571", NID_sect571k1, 571},
1555 {"nistb163", NID_sect163r2, 163},
1556 {"nistb233", NID_sect233r1, 233},
1557 {"nistb283", NID_sect283r1, 283},
1558 {"nistb409", NID_sect409r1, 409},
1559 {"nistb571", NID_sect571r1, 571},
1561 {"brainpoolP256r1", NID_brainpoolP256r1, 256},
1562 {"brainpoolP256t1", NID_brainpoolP256t1, 256},
1563 {"brainpoolP384r1", NID_brainpoolP384r1, 384},
1564 {"brainpoolP384t1", NID_brainpoolP384t1, 384},
1565 {"brainpoolP512r1", NID_brainpoolP512r1, 512},
1566 {"brainpoolP512t1", NID_brainpoolP512t1, 512},
1567 /* Other and ECDH only ones */
1568 {"X25519", NID_X25519, 253},
1569 {"X448", NID_X448, 448}
1571 static const EC_CURVE ed_curves[EdDSA_NUM] = {
1573 {"Ed25519", NID_ED25519, 253, 64},
1574 {"Ed448", NID_ED448, 456, 114}
1576 # ifndef OPENSSL_NO_SM2
1577 static const EC_CURVE sm2_curves[SM2_NUM] = {
1579 {"CurveSM2", NID_sm2, 256}
1581 uint8_t sm2_doit[SM2_NUM] = { 0 };
1583 uint8_t ecdsa_doit[ECDSA_NUM] = { 0 };
1584 uint8_t ecdh_doit[EC_NUM] = { 0 };
1585 uint8_t eddsa_doit[EdDSA_NUM] = { 0 };
1587 /* checks declarated curves against choices list. */
1588 OPENSSL_assert(ed_curves[EdDSA_NUM - 1].nid == NID_ED448);
1589 OPENSSL_assert(strcmp(eddsa_choices[EdDSA_NUM - 1].name, "ed448") == 0);
1591 OPENSSL_assert(ec_curves[EC_NUM - 1].nid == NID_X448);
1592 OPENSSL_assert(strcmp(ecdh_choices[EC_NUM - 1].name, "ecdhx448") == 0);
1594 OPENSSL_assert(ec_curves[ECDSA_NUM - 1].nid == NID_brainpoolP512t1);
1595 OPENSSL_assert(strcmp(ecdsa_choices[ECDSA_NUM - 1].name, "ecdsabrp512t1") == 0);
1597 # ifndef OPENSSL_NO_SM2
1598 OPENSSL_assert(sm2_curves[SM2_NUM - 1].nid == NID_sm2);
1599 OPENSSL_assert(strcmp(sm2_choices[SM2_NUM - 1].name, "curveSM2") == 0);
1601 #endif /* ndef OPENSSL_NO_EC */
1603 prog = opt_init(argc, argv, speed_options);
1604 while ((o = opt_next()) != OPT_EOF) {
1609 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1612 opt_help(speed_options);
1620 evp_cipher = EVP_get_cipherbyname(opt_arg());
1621 if (evp_cipher == NULL)
1622 evp_md = EVP_get_digestbyname(opt_arg());
1623 if (evp_cipher == NULL && evp_md == NULL) {
1625 "%s: %s is an unknown cipher or digest\n",
1632 #ifndef OPENSSL_NO_DEPRECATED_3_0
1633 evp_hmac_md = EVP_get_digestbyname(opt_arg());
1634 if (evp_hmac_md == NULL) {
1635 BIO_printf(bio_err, "%s: %s is an unknown digest\n",
1639 doit[D_EVP_HMAC] = 1;
1643 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1644 evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
1645 if (evp_cmac_cipher == NULL) {
1646 BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
1650 doit[D_EVP_CMAC] = 1;
1658 * In a forked execution, an engine might need to be
1659 * initialised by each child process, not by the parent.
1660 * So store the name here and run setup_engine() later on.
1662 engine_id = opt_arg();
1666 multi = atoi(opt_arg());
1670 #ifndef OPENSSL_NO_ASYNC
1671 async_jobs = atoi(opt_arg());
1672 if (!ASYNC_is_capable()) {
1674 "%s: async_jobs specified but async not supported\n",
1678 if (async_jobs > 99999) {
1679 BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
1685 if (!opt_int(opt_arg(), &misalign))
1687 if (misalign > MISALIGN) {
1689 "%s: Maximum offset is %d\n", prog, MISALIGN);
1698 #ifdef OPENSSL_NO_MULTIBLOCK
1700 "%s: -mb specified but multi-block support is disabled\n",
1710 #ifndef OPENSSL_NO_DEPRECATED_3_0
1711 if (!opt_int(opt_arg(), &primes))
1716 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1717 = seconds.ecdh = seconds.eddsa
1718 = seconds.sm2 = atoi(opt_arg());
1721 lengths_single = atoi(opt_arg());
1722 lengths = &lengths_single;
1730 argc = opt_num_rest();
1733 /* Remaining arguments are algorithms. */
1734 for (; *argv; argv++) {
1735 const char *algo = *argv;
1737 if (opt_found(algo, doit_choices, &i)) {
1741 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1742 if (strcmp(algo, "des") == 0) {
1743 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1747 if (strcmp(algo, "sha") == 0) {
1748 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1751 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1752 if (strcmp(algo, "openssl") == 0) /* just for compatibility */
1754 if (strncmp(algo, "rsa", 3) == 0) {
1755 if (algo[3] == '\0') {
1756 memset(rsa_doit, 1, sizeof(rsa_doit));
1759 if (opt_found(algo, rsa_choices, &i)) {
1765 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1766 if (strncmp(algo, "dsa", 3) == 0) {
1767 if (algo[3] == '\0') {
1768 memset(dsa_doit, 1, sizeof(dsa_doit));
1771 if (opt_found(algo, dsa_choices, &i)) {
1777 #ifndef OPENSSL_NO_DEPRECATED_3_0
1778 if (strcmp(algo, "aes") == 0) {
1779 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1783 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1784 if (strcmp(algo, "camellia") == 0) {
1785 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1789 #ifndef OPENSSL_NO_EC
1790 if (strncmp(algo, "ecdsa", 5) == 0) {
1791 if (algo[5] == '\0') {
1792 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
1795 if (opt_found(algo, ecdsa_choices, &i)) {
1800 if (strncmp(algo, "ecdh", 4) == 0) {
1801 if (algo[4] == '\0') {
1802 memset(ecdh_doit, 1, sizeof(ecdh_doit));
1805 if (opt_found(algo, ecdh_choices, &i)) {
1810 if (strcmp(algo, "eddsa") == 0) {
1811 memset(eddsa_doit, 1, sizeof(eddsa_doit));
1814 if (opt_found(algo, eddsa_choices, &i)) {
1818 # ifndef OPENSSL_NO_SM2
1819 if (strcmp(algo, "sm2") == 0) {
1820 memset(sm2_doit, 1, sizeof(sm2_doit));
1823 if (opt_found(algo, sm2_choices, &i)) {
1828 #endif /* OPENSSL_NO_EC */
1829 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, algo);
1835 if (evp_cipher == NULL) {
1836 BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
1838 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1839 EVP_CIPH_FLAG_AEAD_CIPHER)) {
1840 BIO_printf(bio_err, "%s is not an AEAD cipher\n",
1841 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1846 if (evp_cipher == NULL) {
1847 BIO_printf(bio_err,"-mb can be used only with a multi-block"
1848 " capable cipher\n");
1850 } else if (!(EVP_CIPHER_flags(evp_cipher) &
1851 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1852 BIO_printf(bio_err, "%s is not a multi-block capable\n",
1853 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
1855 } else if (async_jobs > 0) {
1856 BIO_printf(bio_err, "Async mode is not supported with -mb");
1861 /* Initialize the job pool if async mode is enabled */
1862 if (async_jobs > 0) {
1863 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1865 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1870 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1872 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1873 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1875 for (i = 0; i < loopargs_len; i++) {
1876 if (async_jobs > 0) {
1877 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1878 if (loopargs[i].wait_ctx == NULL) {
1879 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1884 buflen = lengths[size_num - 1];
1885 if (buflen < 36) /* size of random vector in RSA benchmark */
1887 buflen += MAX_MISALIGNMENT + 1;
1888 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1889 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1890 memset(loopargs[i].buf_malloc, 0, buflen);
1891 memset(loopargs[i].buf2_malloc, 0, buflen);
1893 /* Align the start of buffers on a 64 byte boundary */
1894 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1895 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1896 #ifndef OPENSSL_NO_EC
1897 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1898 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1903 if (multi && do_multi(multi, size_num))
1907 /* Initialize the engine after the fork */
1908 e = setup_engine(engine_id, 0);
1910 /* No parameters; turn on everything. */
1911 if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
1912 memset(doit, 1, sizeof(doit));
1913 doit[D_EVP] = doit[D_EVP_HMAC] = doit[D_EVP_CMAC] = 0;
1914 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1915 memset(rsa_doit, 1, sizeof(rsa_doit));
1917 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1918 memset(dsa_doit, 1, sizeof(dsa_doit));
1920 #ifndef OPENSSL_NO_EC
1921 memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
1922 memset(ecdh_doit, 1, sizeof(ecdh_doit));
1923 memset(eddsa_doit, 1, sizeof(eddsa_doit));
1924 # ifndef OPENSSL_NO_SM2
1925 memset(sm2_doit, 1, sizeof(sm2_doit));
1929 for (i = 0; i < ALGOR_NUM; i++)
1933 if (usertime == 0 && !mr)
1935 "You have chosen to measure elapsed time "
1936 "instead of user CPU time.\n");
1938 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1939 for (i = 0; i < loopargs_len; i++) {
1940 if (primes > RSA_DEFAULT_PRIME_NUM) {
1941 /* for multi-prime RSA, skip this */
1944 for (k = 0; k < RSA_NUM; k++) {
1945 const unsigned char *p = rsa_keys[k].data;
1947 loopargs[i].rsa_key[k] =
1948 d2i_RSAPrivateKey(NULL, &p, rsa_keys[k].length);
1949 if (loopargs[i].rsa_key[k] == NULL) {
1951 "internal error loading RSA key number %d\n", k);
1957 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1958 for (i = 0; i < loopargs_len; i++) {
1959 loopargs[i].dsa_key[0] = get_dsa(512);
1960 loopargs[i].dsa_key[1] = get_dsa(1024);
1961 loopargs[i].dsa_key[2] = get_dsa(2048);
1964 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1965 if (doit[D_CBC_DES] || doit[D_EDE3_DES]) {
1966 static DES_cblock keys[] = {
1967 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }, /* keys[0] */
1968 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }, /* keys[1] */
1969 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 } /* keys[3] */
1971 DES_set_key_unchecked(&keys[0], &sch[0]);
1972 DES_set_key_unchecked(&keys[1], &sch[1]);
1973 DES_set_key_unchecked(&keys[2], &sch[2]);
1976 #ifndef OPENSSL_NO_DEPRECATED_3_0
1977 AES_set_encrypt_key(key16, 128, &aes_ks1);
1978 AES_set_encrypt_key(key24, 192, &aes_ks2);
1979 AES_set_encrypt_key(key32, 256, &aes_ks3);
1981 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1982 if (doit[D_CBC_128_CML] || doit[D_CBC_192_CML] || doit[D_CBC_256_CML]) {
1983 Camellia_set_key(key16, 128, &camellia_ks[0]);
1984 Camellia_set_key(key24, 192, &camellia_ks[1]);
1985 Camellia_set_key(key32, 256, &camellia_ks[2]);
1988 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1989 if (doit[D_CBC_IDEA])
1990 IDEA_set_encrypt_key(key16, &idea_ks);
1992 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1993 if (doit[D_CBC_SEED])
1994 SEED_set_key(key16, &seed_ks);
1996 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1998 RC4_set_key(&rc4_ks, 16, key16);
2000 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2001 if (doit[D_CBC_RC2])
2002 RC2_set_key(&rc2_ks, 16, key16, 128);
2004 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2005 if (doit[D_CBC_RC5])
2006 if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
2007 BIO_printf(bio_err, "Failed setting RC5 key\n");
2011 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2013 BF_set_key(&bf_ks, 16, key16);
2015 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2016 if (doit[D_CBC_CAST])
2017 CAST_set_key(&cast_ks, 16, key16);
2020 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2021 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
2027 for (it = count; it; it--)
2028 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
2029 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
2032 c[D_MD2][0] = count / 10;
2033 c[D_MDC2][0] = count / 10;
2034 c[D_MD4][0] = count;
2035 c[D_MD5][0] = count;
2036 c[D_HMAC][0] = count;
2037 c[D_SHA1][0] = count;
2038 c[D_RMD160][0] = count;
2039 c[D_RC4][0] = count * 5;
2040 c[D_CBC_DES][0] = count;
2041 c[D_EDE3_DES][0] = count / 3;
2042 c[D_CBC_IDEA][0] = count;
2043 c[D_CBC_SEED][0] = count;
2044 c[D_CBC_RC2][0] = count;
2045 c[D_CBC_RC5][0] = count;
2046 c[D_CBC_BF][0] = count;
2047 c[D_CBC_CAST][0] = count;
2048 c[D_CBC_128_AES][0] = count;
2049 c[D_CBC_192_AES][0] = count;
2050 c[D_CBC_256_AES][0] = count;
2051 c[D_CBC_128_CML][0] = count;
2052 c[D_CBC_192_CML][0] = count;
2053 c[D_CBC_256_CML][0] = count;
2054 c[D_EVP][0] = count;
2055 c[D_SHA256][0] = count;
2056 c[D_SHA512][0] = count;
2057 c[D_WHIRLPOOL][0] = count;
2058 c[D_IGE_128_AES][0] = count;
2059 c[D_IGE_192_AES][0] = count;
2060 c[D_IGE_256_AES][0] = count;
2061 c[D_GHASH][0] = count;
2062 c[D_RAND][0] = count;
2063 c[D_EVP_HMAC][0] = count;
2064 c[D_EVP_CMAC][0] = count;
2066 for (i = 1; i < size_num; i++) {
2067 long l0 = (long)lengths[0];
2068 long l1 = (long)lengths[i];
2070 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
2071 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
2072 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
2073 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
2074 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
2075 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
2076 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
2077 c[D_EVP][i] = = c[D_EVP][0] * 4 * l0 / l1;
2078 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
2079 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
2080 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
2081 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
2082 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
2083 c[D_EVP_HMAC][i] = = c[D_EVP_HMAC][0] * 4 * l0 / l1;
2084 c[D_EVP_CMAC][i] = = c[D_EVP_CMAC][0] * 4 * l0 / l1;
2086 l0 = (long)lengths[i - 1];
2088 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
2089 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
2090 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
2091 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
2092 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
2093 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
2094 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
2095 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
2096 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
2097 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
2098 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
2099 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
2100 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
2101 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
2102 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
2103 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
2104 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
2105 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
2108 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2109 rsa_c[R_RSA_512][0] = count / 2000;
2110 rsa_c[R_RSA_512][1] = count / 400;
2111 for (i = 1; i < RSA_NUM; i++) {
2112 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
2113 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
2114 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
2117 if (rsa_c[i][0] == 0) {
2118 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2125 # if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2126 dsa_c[R_DSA_512][0] = count / 1000;
2127 dsa_c[R_DSA_512][1] = count / 1000 / 2;
2128 for (i = 1; i < DSA_NUM; i++) {
2129 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
2130 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
2131 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
2134 if (dsa_c[i][0] == 0) {
2135 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
2142 # ifndef OPENSSL_NO_EC
2143 ecdsa_c[R_EC_P160][0] = count / 1000;
2144 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
2145 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2146 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2147 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2148 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2151 if (ecdsa_c[i][0] == 0) {
2157 # ifndef OPENSSL_NO_EC2M
2158 ecdsa_c[R_EC_K163][0] = count / 1000;
2159 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
2160 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2161 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2162 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2163 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2166 if (ecdsa_c[i][0] == 0) {
2172 ecdsa_c[R_EC_B163][0] = count / 1000;
2173 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
2174 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2175 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
2176 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
2177 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
2180 if (ecdsa_c[i][0] == 0) {
2188 ecdh_c[R_EC_P160][0] = count / 1000;
2189 for (i = R_EC_P192; i <= R_EC_P521; i++) {
2190 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2191 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2194 if (ecdh_c[i][0] == 0) {
2199 # ifndef OPENSSL_NO_EC2M
2200 ecdh_c[R_EC_K163][0] = count / 1000;
2201 for (i = R_EC_K233; i <= R_EC_K571; i++) {
2202 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2203 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2206 if (ecdh_c[i][0] == 0) {
2211 ecdh_c[R_EC_B163][0] = count / 1000;
2212 for (i = R_EC_B233; i <= R_EC_B571; i++) {
2213 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
2214 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2217 if (ecdh_c[i][0] == 0) {
2223 /* repeated code good to factorize */
2224 ecdh_c[R_EC_BRP256R1][0] = count / 1000;
2225 for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
2226 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2227 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2230 if (ecdh_c[i][0] == 0) {
2235 ecdh_c[R_EC_BRP256T1][0] = count / 1000;
2236 for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
2237 ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
2238 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
2241 if (ecdh_c[i][0] == 0) {
2246 /* default iteration count for the last two EC Curves */
2247 ecdh_c[R_EC_X25519][0] = count / 1800;
2248 ecdh_c[R_EC_X448][0] = count / 7200;
2250 eddsa_c[R_EC_Ed25519][0] = count / 1800;
2251 eddsa_c[R_EC_Ed448][0] = count / 7200;
2253 # ifndef OPENSSL_NO_SM2
2254 sm2_c[R_EC_SM2P256][0] = count / 1800;
2256 # endif /* OPENSSL_NO_EC */
2259 /* not worth fixing */
2260 # error "You cannot disable DES on systems without SIGALRM."
2261 # endif /* OPENSSL_NO_DES */
2263 signal(SIGALRM, alarmed);
2264 #endif /* SIGALRM */
2266 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2268 for (testnum = 0; testnum < size_num; testnum++) {
2269 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
2272 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
2274 print_result(D_MD2, testnum, count, d);
2278 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2280 for (testnum = 0; testnum < size_num; testnum++) {
2281 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
2284 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
2286 print_result(D_MDC2, testnum, count, d);
2293 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2295 for (testnum = 0; testnum < size_num; testnum++) {
2296 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
2299 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
2301 print_result(D_MD4, testnum, count, d);
2308 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2310 for (testnum = 0; testnum < size_num; testnum++) {
2311 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
2314 count = run_benchmark(async_jobs, MD5_loop, loopargs);
2316 print_result(D_MD5, testnum, count, d);
2320 # ifndef OPENSSL_NO_DEPRECATED_3_0
2322 static const char hmac_key[] = "This is a key...";
2323 int len = strlen(hmac_key);
2325 for (i = 0; i < loopargs_len; i++) {
2326 loopargs[i].hctx = HMAC_CTX_new();
2327 if (loopargs[i].hctx == NULL) {
2328 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
2332 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
2334 for (testnum = 0; testnum < size_num; testnum++) {
2335 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2338 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2340 print_result(D_HMAC, testnum, count, d);
2342 for (i = 0; i < loopargs_len; i++)
2343 HMAC_CTX_free(loopargs[i].hctx);
2347 #ifndef OPENSSL_NO_DEPRECATED_3_0
2349 for (testnum = 0; testnum < size_num; testnum++) {
2350 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2353 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2355 print_result(D_SHA1, testnum, count, d);
2358 if (doit[D_SHA256]) {
2359 for (testnum = 0; testnum < size_num; testnum++) {
2360 print_message(names[D_SHA256], c[D_SHA256][testnum],
2361 lengths[testnum], seconds.sym);
2363 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2365 print_result(D_SHA256, testnum, count, d);
2368 if (doit[D_SHA512]) {
2369 for (testnum = 0; testnum < size_num; testnum++) {
2370 print_message(names[D_SHA512], c[D_SHA512][testnum],
2371 lengths[testnum], seconds.sym);
2373 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2375 print_result(D_SHA512, testnum, count, d);
2379 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2380 if (doit[D_WHIRLPOOL]) {
2381 for (testnum = 0; testnum < size_num; testnum++) {
2382 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2383 lengths[testnum], seconds.sym);
2385 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2387 print_result(D_WHIRLPOOL, testnum, count, d);
2392 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2393 if (doit[D_RMD160]) {
2394 for (testnum = 0; testnum < size_num; testnum++) {
2395 print_message(names[D_RMD160], c[D_RMD160][testnum],
2396 lengths[testnum], seconds.sym);
2398 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2400 print_result(D_RMD160, testnum, count, d);
2406 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2408 for (testnum = 0; testnum < size_num; testnum++) {
2409 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2412 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2414 print_result(D_RC4, testnum, count, d);
2418 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2419 if (doit[D_CBC_DES]) {
2420 for (testnum = 0; testnum < size_num; testnum++) {
2421 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2422 lengths[testnum], seconds.sym);
2424 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2426 print_result(D_CBC_DES, testnum, count, d);
2430 if (doit[D_EDE3_DES]) {
2431 for (testnum = 0; testnum < size_num; testnum++) {
2432 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2433 lengths[testnum], seconds.sym);
2436 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2438 print_result(D_EDE3_DES, testnum, count, d);
2443 #ifndef OPENSSL_NO_DEPRECATED_3_0
2444 if (doit[D_CBC_128_AES]) {
2445 for (testnum = 0; testnum < size_num; testnum++) {
2446 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2447 lengths[testnum], seconds.sym);
2450 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2452 print_result(D_CBC_128_AES, testnum, count, d);
2455 if (doit[D_CBC_192_AES]) {
2456 for (testnum = 0; testnum < size_num; testnum++) {
2457 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2458 lengths[testnum], seconds.sym);
2461 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2463 print_result(D_CBC_192_AES, testnum, count, d);
2466 if (doit[D_CBC_256_AES]) {
2467 for (testnum = 0; testnum < size_num; testnum++) {
2468 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2469 lengths[testnum], seconds.sym);
2472 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2474 print_result(D_CBC_256_AES, testnum, count, d);
2479 if (doit[D_IGE_128_AES]) {
2480 for (testnum = 0; testnum < size_num; testnum++) {
2481 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2482 lengths[testnum], seconds.sym);
2485 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2487 print_result(D_IGE_128_AES, testnum, count, d);
2490 if (doit[D_IGE_192_AES]) {
2491 for (testnum = 0; testnum < size_num; testnum++) {
2492 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2493 lengths[testnum], seconds.sym);
2496 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2498 print_result(D_IGE_192_AES, testnum, count, d);
2501 if (doit[D_IGE_256_AES]) {
2502 for (testnum = 0; testnum < size_num; testnum++) {
2503 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2504 lengths[testnum], seconds.sym);
2507 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2509 print_result(D_IGE_256_AES, testnum, count, d);
2512 if (doit[D_GHASH]) {
2513 for (i = 0; i < loopargs_len; i++) {
2514 loopargs[i].gcm_ctx =
2515 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2516 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2517 (unsigned char *)"0123456789ab", 12);
2520 for (testnum = 0; testnum < size_num; testnum++) {
2521 print_message(names[D_GHASH], c[D_GHASH][testnum],
2522 lengths[testnum], seconds.sym);
2524 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2526 print_result(D_GHASH, testnum, count, d);
2528 for (i = 0; i < loopargs_len; i++)
2529 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2531 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
2532 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2533 if (doit[D_CBC_128_CML]) {
2534 if (async_jobs > 0) {
2535 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2536 names[D_CBC_128_CML]);
2537 doit[D_CBC_128_CML] = 0;
2539 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2540 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2541 lengths[testnum], seconds.sym);
2543 for (count = 0; COND(c[D_CBC_128_CML][testnum]); count++)
2544 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2545 (size_t)lengths[testnum], &camellia_ks[0],
2546 iv, CAMELLIA_ENCRYPT);
2548 print_result(D_CBC_128_CML, testnum, count, d);
2551 if (doit[D_CBC_192_CML]) {
2552 if (async_jobs > 0) {
2553 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2554 names[D_CBC_192_CML]);
2555 doit[D_CBC_192_CML] = 0;
2557 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2558 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2559 lengths[testnum], seconds.sym);
2560 if (async_jobs > 0) {
2561 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2565 for (count = 0; COND(c[D_CBC_192_CML][testnum]); count++)
2566 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2567 (size_t)lengths[testnum], &camellia_ks[1],
2568 iv, CAMELLIA_ENCRYPT);
2570 print_result(D_CBC_192_CML, testnum, count, d);
2573 if (doit[D_CBC_256_CML]) {
2574 if (async_jobs > 0) {
2575 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2576 names[D_CBC_256_CML]);
2577 doit[D_CBC_256_CML] = 0;
2579 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2580 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2581 lengths[testnum], seconds.sym);
2583 for (count = 0; COND(c[D_CBC_256_CML][testnum]); count++)
2584 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2585 (size_t)lengths[testnum], &camellia_ks[2],
2586 iv, CAMELLIA_ENCRYPT);
2588 print_result(D_CBC_256_CML, testnum, count, d);
2592 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2593 if (doit[D_CBC_IDEA]) {
2594 if (async_jobs > 0) {
2595 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2597 doit[D_CBC_IDEA] = 0;
2599 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2600 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2601 lengths[testnum], seconds.sym);
2603 for (count = 0; COND(c[D_CBC_IDEA][testnum]); count++)
2604 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2605 (size_t)lengths[testnum], &idea_ks,
2608 print_result(D_CBC_IDEA, testnum, count, d);
2612 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2613 if (doit[D_CBC_SEED]) {
2614 if (async_jobs > 0) {
2615 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2617 doit[D_CBC_SEED] = 0;
2619 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2620 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2621 lengths[testnum], seconds.sym);
2623 for (count = 0; COND(c[D_CBC_SEED][testnum]); count++)
2624 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2625 (size_t)lengths[testnum], &seed_ks, iv, 1);
2627 print_result(D_CBC_SEED, testnum, count, d);
2631 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2632 if (doit[D_CBC_RC2]) {
2633 if (async_jobs > 0) {
2634 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2636 doit[D_CBC_RC2] = 0;
2638 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2639 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2640 lengths[testnum], seconds.sym);
2641 if (async_jobs > 0) {
2642 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2646 for (count = 0; COND(c[D_CBC_RC2][testnum]); count++)
2647 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2648 (size_t)lengths[testnum], &rc2_ks,
2651 print_result(D_CBC_RC2, testnum, count, d);
2655 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2656 if (doit[D_CBC_RC5]) {
2657 if (async_jobs > 0) {
2658 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2660 doit[D_CBC_RC5] = 0;
2662 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2663 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2664 lengths[testnum], seconds.sym);
2665 if (async_jobs > 0) {
2666 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2670 for (count = 0; COND(c[D_CBC_RC5][testnum]); count++)
2671 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2672 (size_t)lengths[testnum], &rc5_ks,
2675 print_result(D_CBC_RC5, testnum, count, d);
2679 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2680 if (doit[D_CBC_BF]) {
2681 if (async_jobs > 0) {
2682 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2686 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2687 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2688 lengths[testnum], seconds.sym);
2690 for (count = 0; COND(c[D_CBC_BF][testnum]); count++)
2691 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2692 (size_t)lengths[testnum], &bf_ks,
2695 print_result(D_CBC_BF, testnum, count, d);
2699 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2700 if (doit[D_CBC_CAST]) {
2701 if (async_jobs > 0) {
2702 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2704 doit[D_CBC_CAST] = 0;
2706 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2707 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2708 lengths[testnum], seconds.sym);
2710 for (count = 0; COND(c[D_CBC_CAST][testnum]); count++)
2711 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2712 (size_t)lengths[testnum], &cast_ks,
2715 print_result(D_CBC_CAST, testnum, count, d);
2720 for (testnum = 0; testnum < size_num; testnum++) {
2721 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2724 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2726 print_result(D_RAND, testnum, count, d);
2731 if (evp_cipher != NULL) {
2732 int (*loopfunc) (void *) = EVP_Update_loop;
2734 if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
2735 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2736 multiblock_speed(evp_cipher, lengths_single, &seconds);
2741 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2743 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
2744 loopfunc = EVP_Update_loop_ccm;
2745 } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
2746 EVP_CIPH_FLAG_AEAD_CIPHER)) {
2747 loopfunc = EVP_Update_loop_aead;
2748 if (lengths == lengths_list) {
2749 lengths = aead_lengths_list;
2750 size_num = OSSL_NELEM(aead_lengths_list);
2754 for (testnum = 0; testnum < size_num; testnum++) {
2755 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2758 for (k = 0; k < loopargs_len; k++) {
2759 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2760 if (loopargs[k].ctx == NULL) {
2761 BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
2764 if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2765 NULL, iv, decrypt ? 0 : 1)) {
2766 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2767 ERR_print_errors(bio_err);
2771 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2773 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2774 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2775 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2776 if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2777 loopargs[k].key, NULL, -1)) {
2778 BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
2779 ERR_print_errors(bio_err);
2782 OPENSSL_clear_free(loopargs[k].key, keylen);
2784 /* SIV mode only allows for a single Update operation */
2785 if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
2786 EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
2790 count = run_benchmark(async_jobs, loopfunc, loopargs);
2792 for (k = 0; k < loopargs_len; k++) {
2793 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2795 print_result(D_EVP, testnum, count, d);
2797 } else if (evp_md != NULL) {
2798 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2800 for (testnum = 0; testnum < size_num; testnum++) {
2801 print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
2804 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2806 print_result(D_EVP, testnum, count, d);
2811 #ifndef OPENSSL_NO_DEPRECATED_3_0
2812 if (doit[D_EVP_HMAC] && evp_hmac_md != NULL) {
2813 const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
2815 evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
2817 sprintf(evp_hmac_name, "HMAC(%s)", md_name);
2818 names[D_EVP_HMAC] = evp_hmac_name;
2820 for (testnum = 0; testnum < size_num; testnum++) {
2821 print_message(names[D_EVP_HMAC], c[D_EVP_HMAC][testnum], lengths[testnum],
2824 count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
2826 print_result(D_EVP_HMAC, testnum, count, d);
2831 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2832 if (doit[D_EVP_CMAC] && evp_cmac_cipher != NULL) {
2833 const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
2835 evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
2837 sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
2838 names[D_EVP_CMAC] = evp_cmac_name;
2840 for (i = 0; i < loopargs_len; i++) {
2841 loopargs[i].cmac_ctx = CMAC_CTX_new();
2842 if (loopargs[i].cmac_ctx == NULL) {
2843 BIO_printf(bio_err, "CMAC malloc failure, exiting...");
2847 for (testnum = 0; testnum < size_num; testnum++) {
2848 print_message(names[D_EVP_CMAC], c[D_EVP_CMAC][testnum], lengths[testnum],
2851 count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
2853 print_result(D_EVP_CMAC, testnum, count, d);
2855 for (i = 0; i < loopargs_len; i++)
2856 CMAC_CTX_free(loopargs[i].cmac_ctx);
2860 for (i = 0; i < loopargs_len; i++)
2861 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2864 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2865 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2867 if (!rsa_doit[testnum])
2869 for (i = 0; i < loopargs_len; i++) {
2870 if (primes > RSA_DEFAULT_PRIME_NUM) {
2871 /* we haven't set keys yet, generate multi-prime RSA keys */
2872 BIGNUM *bn = BN_new();
2876 if (!BN_set_word(bn, RSA_F4)) {
2881 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2882 rsa_choices[testnum].name);
2884 loopargs[i].rsa_key[testnum] = RSA_new();
2885 if (loopargs[i].rsa_key[testnum] == NULL) {
2890 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2891 rsa_keys[testnum].bits,
2892 primes, bn, NULL)) {
2898 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2899 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2905 "RSA sign failure. No RSA sign will be done.\n");
2906 ERR_print_errors(bio_err);
2909 pkey_print_message("private", "rsa",
2910 rsa_c[testnum][0], rsa_keys[testnum].bits,
2912 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2914 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2917 mr ? "+R1:%ld:%d:%.2f\n"
2918 : "%ld %u bits private RSA's in %.2fs\n",
2919 count, rsa_keys[testnum].bits, d);
2920 rsa_results[testnum][0] = (double)count / d;
2924 for (i = 0; i < loopargs_len; i++) {
2925 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2926 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2932 "RSA verify failure. No RSA verify will be done.\n");
2933 ERR_print_errors(bio_err);
2934 rsa_doit[testnum] = 0;
2936 pkey_print_message("public", "rsa",
2937 rsa_c[testnum][1], rsa_keys[testnum].bits,
2940 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2943 mr ? "+R2:%ld:%d:%.2f\n"
2944 : "%ld %u bits public RSA's in %.2fs\n",
2945 count, rsa_keys[testnum].bits, d);
2946 rsa_results[testnum][1] = (double)count / d;
2949 if (rsa_count <= 1) {
2950 /* if longer than 10s, don't do any more */
2951 stop_it(rsa_doit, testnum);
2954 #endif /* OPENSSL_NO_RSA */
2956 for (i = 0; i < loopargs_len; i++)
2957 if (RAND_bytes(loopargs[i].buf, 36) <= 0)
2960 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2961 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2963 if (!dsa_doit[testnum])
2966 /* DSA_generate_key(dsa_key[testnum]); */
2967 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2968 for (i = 0; i < loopargs_len; i++) {
2969 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2970 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2976 "DSA sign failure. No DSA sign will be done.\n");
2977 ERR_print_errors(bio_err);
2980 pkey_print_message("sign", "dsa",
2981 dsa_c[testnum][0], dsa_bits[testnum],
2984 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2987 mr ? "+R3:%ld:%u:%.2f\n"
2988 : "%ld %u bits DSA signs in %.2fs\n",
2989 count, dsa_bits[testnum], d);
2990 dsa_results[testnum][0] = (double)count / d;
2994 for (i = 0; i < loopargs_len; i++) {
2995 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2996 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
3002 "DSA verify failure. No DSA verify will be done.\n");
3003 ERR_print_errors(bio_err);
3004 dsa_doit[testnum] = 0;
3006 pkey_print_message("verify", "dsa",
3007 dsa_c[testnum][1], dsa_bits[testnum],
3010 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
3013 mr ? "+R4:%ld:%u:%.2f\n"
3014 : "%ld %u bits DSA verify in %.2fs\n",
3015 count, dsa_bits[testnum], d);
3016 dsa_results[testnum][1] = (double)count / d;
3019 if (rsa_count <= 1) {
3020 /* if longer than 10s, don't do any more */
3021 stop_it(dsa_doit, testnum);
3024 #endif /* OPENSSL_NO_DSA */
3026 #ifndef OPENSSL_NO_EC
3027 # ifndef OPENSSL_NO_DEPRECATED_3_0
3028 for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
3031 if (!ecdsa_doit[testnum])
3032 continue; /* Ignore Curve */
3033 for (i = 0; i < loopargs_len; i++) {
3034 loopargs[i].ecdsa[testnum] =
3035 EC_KEY_new_by_curve_name(ec_curves[testnum].nid);
3036 if (loopargs[i].ecdsa[testnum] == NULL) {
3042 BIO_printf(bio_err, "ECDSA failure.\n");
3043 ERR_print_errors(bio_err);
3046 for (i = 0; i < loopargs_len; i++) {
3047 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
3048 /* Perform ECDSA signature test */
3049 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
3050 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
3051 &loopargs[i].siglen,
3052 loopargs[i].ecdsa[testnum]);
3058 "ECDSA sign failure. No ECDSA sign will be done.\n");
3059 ERR_print_errors(bio_err);
3062 pkey_print_message("sign", "ecdsa",
3063 ecdsa_c[testnum][0],
3064 ec_curves[testnum].bits, seconds.ecdsa);
3066 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
3070 mr ? "+R5:%ld:%u:%.2f\n" :
3071 "%ld %u bits ECDSA signs in %.2fs \n",
3072 count, ec_curves[testnum].bits, d);
3073 ecdsa_results[testnum][0] = (double)count / d;
3077 /* Perform ECDSA verification test */
3078 for (i = 0; i < loopargs_len; i++) {
3079 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
3081 loopargs[i].ecdsa[testnum]);
3087 "ECDSA verify failure. No ECDSA verify will be done.\n");
3088 ERR_print_errors(bio_err);
3089 ecdsa_doit[testnum] = 0;
3091 pkey_print_message("verify", "ecdsa",
3092 ecdsa_c[testnum][1],
3093 ec_curves[testnum].bits, seconds.ecdsa);
3095 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
3098 mr ? "+R6:%ld:%u:%.2f\n"
3099 : "%ld %u bits ECDSA verify in %.2fs\n",
3100 count, ec_curves[testnum].bits, d);
3101 ecdsa_results[testnum][1] = (double)count / d;
3104 if (rsa_count <= 1) {
3105 /* if longer than 10s, don't do any more */
3106 stop_it(ecdsa_doit, testnum);
3112 for (testnum = 0; testnum < EC_NUM; testnum++) {
3113 int ecdh_checks = 1;
3115 if (!ecdh_doit[testnum])
3118 for (i = 0; i < loopargs_len; i++) {
3119 EVP_PKEY_CTX *kctx = NULL;
3120 EVP_PKEY_CTX *test_ctx = NULL;
3121 EVP_PKEY_CTX *ctx = NULL;
3122 EVP_PKEY *key_A = NULL;
3123 EVP_PKEY *key_B = NULL;
3127 /* Ensure that the error queue is empty */
3128 if (ERR_peek_error()) {
3130 "WARNING: the error queue contains previous unhandled errors.\n");
3131 ERR_print_errors(bio_err);
3134 /* Let's try to create a ctx directly from the NID: this works for
3135 * curves like Curve25519 that are not implemented through the low
3136 * level EC interface.
3137 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
3138 * then we set the curve by NID before deriving the actual keygen
3139 * ctx for that specific curve. */
3140 kctx = EVP_PKEY_CTX_new_id(ec_curves[testnum].nid, NULL); /* keygen ctx from NID */
3142 EVP_PKEY_CTX *pctx = NULL;
3143 EVP_PKEY *params = NULL;
3145 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
3146 * "int_ctx_new:unsupported algorithm" error was added to the
3148 * We remove it from the error queue as we are handling it. */
3149 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
3150 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
3151 /* check that the error origin matches */
3152 ERR_GET_LIB(error) == ERR_LIB_EVP &&
3153 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
3154 ERR_get_error(); /* pop error from queue */
3155 if (ERR_peek_error()) {
3157 "Unhandled error in the error queue during ECDH init.\n");
3158 ERR_print_errors(bio_err);
3163 /* Create the context for parameter generation */
3164 if (!(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
3165 /* Initialise the parameter generation */
3166 !EVP_PKEY_paramgen_init(pctx) ||
3167 /* Set the curve by NID */
3168 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3171 /* Create the parameter object params */
3172 !EVP_PKEY_paramgen(pctx, ¶ms)) {
3174 BIO_printf(bio_err, "ECDH EC params init failure.\n");
3175 ERR_print_errors(bio_err);
3179 /* Create the context for the key generation */
3180 kctx = EVP_PKEY_CTX_new(params, NULL);
3182 EVP_PKEY_free(params);
3184 EVP_PKEY_CTX_free(pctx);
3187 if (kctx == NULL || /* keygen ctx is not null */
3188 EVP_PKEY_keygen_init(kctx) <= 0/* init keygen ctx */ ) {
3190 BIO_printf(bio_err, "ECDH keygen failure.\n");
3191 ERR_print_errors(bio_err);
3196 if (EVP_PKEY_keygen(kctx, &key_A) <= 0 || /* generate secret key A */
3197 EVP_PKEY_keygen(kctx, &key_B) <= 0 || /* generate secret key B */
3198 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
3199 EVP_PKEY_derive_init(ctx) <= 0 || /* init derivation ctx */
3200 EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 || /* set peer pubkey in ctx */
3201 EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 || /* determine max length */
3202 outlen == 0 || /* ensure outlen is a valid size */
3203 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
3205 BIO_printf(bio_err, "ECDH key generation failure.\n");
3206 ERR_print_errors(bio_err);
3211 /* Here we perform a test run, comparing the output of a*B and b*A;
3212 * we try this here and assume that further EVP_PKEY_derive calls
3213 * never fail, so we can skip checks in the actually benchmarked
3214 * code, for maximum performance. */
3215 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
3216 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
3217 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
3218 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
3219 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
3220 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
3221 test_outlen != outlen /* compare output length */ ) {
3223 BIO_printf(bio_err, "ECDH computation failure.\n");
3224 ERR_print_errors(bio_err);
3229 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3230 if (CRYPTO_memcmp(loopargs[i].secret_a,
3231 loopargs[i].secret_b, outlen)) {
3233 BIO_printf(bio_err, "ECDH computations don't match.\n");
3234 ERR_print_errors(bio_err);
3239 loopargs[i].ecdh_ctx[testnum] = ctx;
3240 loopargs[i].outlen[testnum] = outlen;
3242 EVP_PKEY_free(key_A);
3243 EVP_PKEY_free(key_B);
3244 EVP_PKEY_CTX_free(kctx);
3246 EVP_PKEY_CTX_free(test_ctx);
3249 if (ecdh_checks != 0) {
3250 pkey_print_message("", "ecdh",
3252 ec_curves[testnum].bits, seconds.ecdh);
3255 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
3258 mr ? "+R7:%ld:%d:%.2f\n" :
3259 "%ld %u-bits ECDH ops in %.2fs\n", count,
3260 ec_curves[testnum].bits, d);
3261 ecdh_results[testnum][0] = (double)count / d;
3265 if (rsa_count <= 1) {
3266 /* if longer than 10s, don't do any more */
3267 stop_it(ecdh_doit, testnum);
3271 for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
3273 EVP_PKEY *ed_pkey = NULL;
3274 EVP_PKEY_CTX *ed_pctx = NULL;
3276 if (!eddsa_doit[testnum])
3277 continue; /* Ignore Curve */
3278 for (i = 0; i < loopargs_len; i++) {
3279 loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
3280 if (loopargs[i].eddsa_ctx[testnum] == NULL) {
3285 if ((ed_pctx = EVP_PKEY_CTX_new_id(ed_curves[testnum].nid, NULL))
3287 || EVP_PKEY_keygen_init(ed_pctx) <= 0
3288 || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) {
3290 EVP_PKEY_CTX_free(ed_pctx);
3293 EVP_PKEY_CTX_free(ed_pctx);
3295 if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
3298 EVP_PKEY_free(ed_pkey);
3301 EVP_PKEY_free(ed_pkey);
3304 BIO_printf(bio_err, "EdDSA failure.\n");
3305 ERR_print_errors(bio_err);
3308 for (i = 0; i < loopargs_len; i++) {
3309 /* Perform EdDSA signature test */
3310 loopargs[i].sigsize = ed_curves[testnum].sigsize;
3311 st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
3312 loopargs[i].buf2, &loopargs[i].sigsize,
3313 loopargs[i].buf, 20);
3319 "EdDSA sign failure. No EdDSA sign will be done.\n");
3320 ERR_print_errors(bio_err);
3323 pkey_print_message("sign", ed_curves[testnum].name,
3324 eddsa_c[testnum][0],
3325 ed_curves[testnum].bits, seconds.eddsa);
3327 count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
3331 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3332 "%ld %u bits %s signs in %.2fs \n",
3333 count, ed_curves[testnum].bits,
3334 ed_curves[testnum].name, d);
3335 eddsa_results[testnum][0] = (double)count / d;
3339 /* Perform EdDSA verification test */
3340 for (i = 0; i < loopargs_len; i++) {
3341 st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
3342 loopargs[i].buf2, loopargs[i].sigsize,
3343 loopargs[i].buf, 20);
3349 "EdDSA verify failure. No EdDSA verify will be done.\n");
3350 ERR_print_errors(bio_err);
3351 eddsa_doit[testnum] = 0;
3353 pkey_print_message("verify", ed_curves[testnum].name,
3354 eddsa_c[testnum][1],
3355 ed_curves[testnum].bits, seconds.eddsa);
3357 count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
3360 mr ? "+R9:%ld:%u:%s:%.2f\n"
3361 : "%ld %u bits %s verify in %.2fs\n",
3362 count, ed_curves[testnum].bits,
3363 ed_curves[testnum].name, d);
3364 eddsa_results[testnum][1] = (double)count / d;
3367 if (rsa_count <= 1) {
3368 /* if longer than 10s, don't do any more */
3369 stop_it(eddsa_doit, testnum);
3374 # ifndef OPENSSL_NO_SM2
3375 for (testnum = 0; testnum < SM2_NUM; testnum++) {
3377 EVP_PKEY *sm2_pkey = NULL;
3379 if (!sm2_doit[testnum])
3380 continue; /* Ignore Curve */
3381 /* Init signing and verification */
3382 for (i = 0; i < loopargs_len; i++) {
3383 EVP_PKEY_CTX *sm2_pctx = NULL;
3384 EVP_PKEY_CTX *sm2_vfy_pctx = NULL;
3385 EVP_PKEY_CTX *pctx = NULL;
3388 loopargs[i].sm2_ctx[testnum] = EVP_MD_CTX_new();
3389 loopargs[i].sm2_vfy_ctx[testnum] = EVP_MD_CTX_new();
3390 if (loopargs[i].sm2_ctx[testnum] == NULL
3391 || loopargs[i].sm2_vfy_ctx[testnum] == NULL)
3394 /* SM2 keys are generated as normal EC keys with a special curve */
3395 st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) == NULL
3396 || EVP_PKEY_keygen_init(pctx) <= 0
3397 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
3398 sm2_curves[testnum].nid) <= 0
3399 || EVP_PKEY_keygen(pctx, &sm2_pkey) <= 0);
3400 EVP_PKEY_CTX_free(pctx);
3404 st = 0; /* set back to zero */
3405 /* attach it sooner to rely on main final cleanup */
3406 loopargs[i].sm2_pkey[testnum] = sm2_pkey;
3407 loopargs[i].sigsize = EVP_PKEY_size(sm2_pkey);
3409 sm2_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3410 sm2_vfy_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
3411 if (sm2_pctx == NULL || sm2_vfy_pctx == NULL) {
3412 EVP_PKEY_CTX_free(sm2_vfy_pctx);
3416 /* attach them directly to respective ctx */
3417 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_ctx[testnum], sm2_pctx);
3418 EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_vfy_ctx[testnum], sm2_vfy_pctx);
3421 * No need to allow user to set an explicit ID here, just use
3422 * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D.
3424 if (EVP_PKEY_CTX_set1_id(sm2_pctx, SM2_ID, SM2_ID_LEN) != 1
3425 || EVP_PKEY_CTX_set1_id(sm2_vfy_pctx, SM2_ID, SM2_ID_LEN) != 1)
3428 if (!EVP_DigestSignInit(loopargs[i].sm2_ctx[testnum], NULL,
3429 EVP_sm3(), NULL, sm2_pkey))
3431 if (!EVP_DigestVerifyInit(loopargs[i].sm2_vfy_ctx[testnum], NULL,
3432 EVP_sm3(), NULL, sm2_pkey))
3434 st = 1; /* mark loop as succeeded */
3437 BIO_printf(bio_err, "SM2 init failure.\n");
3438 ERR_print_errors(bio_err);
3441 for (i = 0; i < loopargs_len; i++) {
3442 size_t sm2_sigsize = loopargs[i].sigsize;
3444 /* Perform SM2 signature test */
3445 st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum],
3446 loopargs[i].buf2, &sm2_sigsize,
3447 loopargs[i].buf, 20);
3453 "SM2 sign failure. No SM2 sign will be done.\n");
3454 ERR_print_errors(bio_err);
3457 pkey_print_message("sign", sm2_curves[testnum].name,
3459 sm2_curves[testnum].bits, seconds.sm2);
3461 count = run_benchmark(async_jobs, SM2_sign_loop, loopargs);
3465 mr ? "+R8:%ld:%u:%s:%.2f\n" :
3466 "%ld %u bits %s signs in %.2fs \n",
3467 count, sm2_curves[testnum].bits,
3468 sm2_curves[testnum].name, d);
3469 sm2_results[testnum][0] = (double)count / d;
3473 /* Perform SM2 verification test */
3474 for (i = 0; i < loopargs_len; i++) {
3475 st = EVP_DigestVerify(loopargs[i].sm2_vfy_ctx[testnum],
3476 loopargs[i].buf2, loopargs[i].sigsize,
3477 loopargs[i].buf, 20);
3483 "SM2 verify failure. No SM2 verify will be done.\n");
3484 ERR_print_errors(bio_err);
3485 sm2_doit[testnum] = 0;
3487 pkey_print_message("verify", sm2_curves[testnum].name,
3489 sm2_curves[testnum].bits, seconds.sm2);
3491 count = run_benchmark(async_jobs, SM2_verify_loop, loopargs);
3494 mr ? "+R9:%ld:%u:%s:%.2f\n"
3495 : "%ld %u bits %s verify in %.2fs\n",
3496 count, sm2_curves[testnum].bits,
3497 sm2_curves[testnum].name, d);
3498 sm2_results[testnum][1] = (double)count / d;
3501 if (rsa_count <= 1) {
3502 /* if longer than 10s, don't do any more */
3503 for (testnum++; testnum < SM2_NUM; testnum++)
3504 sm2_doit[testnum] = 0;
3508 # endif /* OPENSSL_NO_SM2 */
3510 #endif /* OPENSSL_NO_EC */
3515 printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
3516 printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
3518 printf("%s ", BN_options());
3519 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3520 printf("%s ", MD2_options());
3522 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3523 printf("%s ", RC4_options());
3525 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3526 printf("%s ", DES_options());
3528 #ifndef OPENSSL_NO_DEPRECATED_3_0
3529 printf("%s ", AES_options());
3531 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3532 printf("%s ", IDEA_options());
3534 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3535 printf("%s ", BF_options());
3537 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3538 printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
3546 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3549 for (testnum = 0; testnum < size_num; testnum++)
3550 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
3554 for (k = 0; k < ALGOR_NUM; k++) {
3558 printf("+F:%u:%s", k, names[k]);
3560 printf("%-13s", names[k]);
3561 for (testnum = 0; testnum < size_num; testnum++) {
3562 if (results[k][testnum] > 10000 && !mr)
3563 printf(" %11.2fk", results[k][testnum] / 1e3);
3565 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
3569 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3571 for (k = 0; k < RSA_NUM; k++) {
3574 if (testnum && !mr) {
3575 printf("%18ssign verify sign/s verify/s\n", " ");
3579 printf("+F2:%u:%u:%f:%f\n",
3580 k, rsa_keys[k].bits, rsa_results[k][0], rsa_results[k][1]);
3582 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3583 rsa_keys[k].bits, 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
3584 rsa_results[k][0], rsa_results[k][1]);
3587 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3589 for (k = 0; k < DSA_NUM; k++) {
3592 if (testnum && !mr) {
3593 printf("%18ssign verify sign/s verify/s\n", " ");
3597 printf("+F3:%u:%u:%f:%f\n",
3598 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
3600 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3601 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
3602 dsa_results[k][0], dsa_results[k][1]);
3605 #ifndef OPENSSL_NO_EC
3607 for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
3610 if (testnum && !mr) {
3611 printf("%30ssign verify sign/s verify/s\n", " ");
3616 printf("+F4:%u:%u:%f:%f\n",
3617 k, ec_curves[k].bits,
3618 ecdsa_results[k][0], ecdsa_results[k][1]);
3620 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3621 ec_curves[k].bits, ec_curves[k].name,
3622 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
3623 ecdsa_results[k][0], ecdsa_results[k][1]);
3627 for (k = 0; k < EC_NUM; k++) {
3630 if (testnum && !mr) {
3631 printf("%30sop op/s\n", " ");
3635 printf("+F5:%u:%u:%f:%f\n",
3636 k, ec_curves[k].bits,
3637 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
3640 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3641 ec_curves[k].bits, ec_curves[k].name,
3642 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3646 for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
3649 if (testnum && !mr) {
3650 printf("%30ssign verify sign/s verify/s\n", " ");
3655 printf("+F6:%u:%u:%s:%f:%f\n",
3656 k, ed_curves[k].bits, ed_curves[k].name,
3657 eddsa_results[k][0], eddsa_results[k][1]);
3659 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3660 ed_curves[k].bits, ed_curves[k].name,
3661 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
3662 eddsa_results[k][0], eddsa_results[k][1]);
3665 # ifndef OPENSSL_NO_SM2
3667 for (k = 0; k < OSSL_NELEM(sm2_doit); k++) {
3670 if (testnum && !mr) {
3671 printf("%30ssign verify sign/s verify/s\n", " ");
3676 printf("+F6:%u:%u:%s:%f:%f\n",
3677 k, sm2_curves[k].bits, sm2_curves[k].name,
3678 sm2_results[k][0], sm2_results[k][1]);
3680 printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3681 sm2_curves[k].bits, sm2_curves[k].name,
3682 1.0 / sm2_results[k][0], 1.0 / sm2_results[k][1],
3683 sm2_results[k][0], sm2_results[k][1]);
3686 #endif /* OPENSSL_NO_EC */
3691 ERR_print_errors(bio_err);
3692 for (i = 0; i < loopargs_len; i++) {
3693 OPENSSL_free(loopargs[i].buf_malloc);
3694 OPENSSL_free(loopargs[i].buf2_malloc);
3696 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3697 for (k = 0; k < RSA_NUM; k++)
3698 RSA_free(loopargs[i].rsa_key[k]);
3700 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3701 for (k = 0; k < DSA_NUM; k++)
3702 DSA_free(loopargs[i].dsa_key[k]);
3704 #ifndef OPENSSL_NO_EC
3705 for (k = 0; k < ECDSA_NUM; k++)
3706 EC_KEY_free(loopargs[i].ecdsa[k]);
3707 for (k = 0; k < EC_NUM; k++)
3708 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3709 for (k = 0; k < EdDSA_NUM; k++)
3710 EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
3711 # ifndef OPENSSL_NO_SM2
3712 for (k = 0; k < SM2_NUM; k++) {
3713 EVP_PKEY_CTX *pctx = NULL;
3715 /* free signing ctx */
3716 if (loopargs[i].sm2_ctx[k] != NULL
3717 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_ctx[k])) != NULL)
3718 EVP_PKEY_CTX_free(pctx);
3719 EVP_MD_CTX_free(loopargs[i].sm2_ctx[k]);
3720 /* free verification ctx */
3721 if (loopargs[i].sm2_vfy_ctx[k] != NULL
3722 && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_vfy_ctx[k])) != NULL)
3723 EVP_PKEY_CTX_free(pctx);
3724 EVP_MD_CTX_free(loopargs[i].sm2_vfy_ctx[k]);
3726 EVP_PKEY_free(loopargs[i].sm2_pkey[k]);
3729 OPENSSL_free(loopargs[i].secret_a);
3730 OPENSSL_free(loopargs[i].secret_b);
3733 #ifndef OPENSSL_NO_DEPRECATED_3_0
3734 OPENSSL_free(evp_hmac_name);
3736 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3737 OPENSSL_free(evp_cmac_name);
3740 if (async_jobs > 0) {
3741 for (i = 0; i < loopargs_len; i++)
3742 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3746 ASYNC_cleanup_thread();
3748 OPENSSL_free(loopargs);
3753 static void print_message(const char *s, long num, int length, int tm)
3757 mr ? "+DT:%s:%d:%d\n"
3758 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3759 (void)BIO_flush(bio_err);
3764 mr ? "+DN:%s:%ld:%d\n"
3765 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3766 (void)BIO_flush(bio_err);
3770 static void pkey_print_message(const char *str, const char *str2, long num,
3771 unsigned int bits, int tm)
3775 mr ? "+DTP:%d:%s:%s:%d\n"
3776 : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
3777 (void)BIO_flush(bio_err);
3782 mr ? "+DNP:%ld:%d:%s:%s\n"
3783 : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
3784 (void)BIO_flush(bio_err);
3788 static void print_result(int alg, int run_no, int count, double time_used)
3791 BIO_printf(bio_err, "%s error!\n", names[alg]);
3792 ERR_print_errors(bio_err);
3793 /* exit(1); disable exit until default provider enabled */
3797 mr ? "+R:%d:%s:%f\n"
3798 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3799 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3803 static char *sstrsep(char **string, const char *delim)
3806 char *token = *string;
3811 memset(isdelim, 0, sizeof(isdelim));
3815 isdelim[(unsigned char)(*delim)] = 1;
3819 while (!isdelim[(unsigned char)(**string)]) {
3831 static int do_multi(int multi, int size_num)
3836 static char sep[] = ":";
3838 fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
3839 for (n = 0; n < multi; ++n) {
3840 if (pipe(fd) == -1) {
3841 BIO_printf(bio_err, "pipe failure\n");
3845 (void)BIO_flush(bio_err);
3852 if (dup(fd[1]) == -1) {
3853 BIO_printf(bio_err, "dup failed\n");
3862 printf("Forked child %d\n", n);
3865 /* for now, assume the pipe is long enough to take all the output */
3866 for (n = 0; n < multi; ++n) {
3871 f = fdopen(fds[n], "r");
3872 while (fgets(buf, sizeof(buf), f)) {
3873 p = strchr(buf, '\n');
3876 if (buf[0] != '+') {
3878 "Don't understand line '%s' from child %d\n", buf,
3882 printf("Got: %s from %d\n", buf, n);
3883 if (strncmp(buf, "+F:", 3) == 0) {
3888 alg = atoi(sstrsep(&p, sep));
3890 for (j = 0; j < size_num; ++j)
3891 results[alg][j] += atof(sstrsep(&p, sep));
3893 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3894 else if (strncmp(buf, "+F2:", 4) == 0) {
3899 k = atoi(sstrsep(&p, sep));
3902 d = atof(sstrsep(&p, sep));
3903 rsa_results[k][0] += d;
3905 d = atof(sstrsep(&p, sep));
3906 rsa_results[k][1] += d;
3909 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3910 else if (strncmp(buf, "+F3:", 4) == 0) {
3915 k = atoi(sstrsep(&p, sep));
3918 d = atof(sstrsep(&p, sep));
3919 dsa_results[k][0] += d;
3921 d = atof(sstrsep(&p, sep));
3922 dsa_results[k][1] += d;
3925 # ifndef OPENSSL_NO_EC
3926 else if (strncmp(buf, "+F4:", 4) == 0) {
3931 k = atoi(sstrsep(&p, sep));
3934 d = atof(sstrsep(&p, sep));
3935 ecdsa_results[k][0] += d;
3937 d = atof(sstrsep(&p, sep));
3938 ecdsa_results[k][1] += d;
3939 } else if (strncmp(buf, "+F5:", 4) == 0) {
3944 k = atoi(sstrsep(&p, sep));
3947 d = atof(sstrsep(&p, sep));
3948 ecdh_results[k][0] += d;
3949 } else if (strncmp(buf, "+F6:", 4) == 0) {
3954 k = atoi(sstrsep(&p, sep));
3958 d = atof(sstrsep(&p, sep));
3959 eddsa_results[k][0] += d;
3961 d = atof(sstrsep(&p, sep));
3962 eddsa_results[k][1] += d;
3964 # ifndef OPENSSL_NO_SM2
3965 else if (strncmp(buf, "+F7:", 4) == 0) {
3970 k = atoi(sstrsep(&p, sep));
3973 d = atof(sstrsep(&p, sep));
3974 sm2_results[k][0] += d;
3976 d = atof(sstrsep(&p, sep));
3977 sm2_results[k][1] += d;
3979 # endif /* OPENSSL_NO_SM2 */
3982 else if (strncmp(buf, "+H:", 3) == 0) {
3985 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3996 static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
3997 const openssl_speed_sec_t *seconds)
3999 static const int mblengths_list[] =
4000 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
4001 const int *mblengths = mblengths_list;
4002 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
4003 const char *alg_name;
4004 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
4005 EVP_CIPHER_CTX *ctx;
4008 if (lengths_single) {
4009 mblengths = &lengths_single;
4013 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
4014 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
4015 ctx = EVP_CIPHER_CTX_new();
4016 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
4018 keylen = EVP_CIPHER_CTX_key_length(ctx);
4019 key = app_malloc(keylen, "evp_cipher key");
4020 EVP_CIPHER_CTX_rand_key(ctx, key);
4021 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
4022 OPENSSL_clear_free(key, keylen);
4024 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
4025 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
4027 for (j = 0; j < num; j++) {
4028 print_message(alg_name, 0, mblengths[j], seconds->sym);
4030 for (count = 0; run && count < 0x7fffffff; count++) {
4031 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
4032 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
4033 size_t len = mblengths[j];
4036 memset(aad, 0, 8); /* avoid uninitialized values */
4037 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
4038 aad[9] = 3; /* version */
4040 aad[11] = 0; /* length */
4042 mb_param.out = NULL;
4045 mb_param.interleave = 8;
4047 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
4048 sizeof(mb_param), &mb_param);
4054 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
4055 sizeof(mb_param), &mb_param);
4059 RAND_bytes(out, 16);
4061 aad[11] = (unsigned char)(len >> 8);
4062 aad[12] = (unsigned char)(len);
4063 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
4064 EVP_AEAD_TLS1_AAD_LEN, aad);
4065 EVP_Cipher(ctx, out, inp, len + pad);
4069 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
4070 : "%d %s's in %.2fs\n", count, "evp", d);
4071 results[D_EVP][j] = ((double)count) / d * mblengths[j];
4075 fprintf(stdout, "+H");
4076 for (j = 0; j < num; j++)
4077 fprintf(stdout, ":%d", mblengths[j]);
4078 fprintf(stdout, "\n");
4079 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
4080 for (j = 0; j < num; j++)
4081 fprintf(stdout, ":%.2f", results[D_EVP][j]);
4082 fprintf(stdout, "\n");
4085 "The 'numbers' are in 1000s of bytes per second processed.\n");
4086 fprintf(stdout, "type ");
4087 for (j = 0; j < num; j++)
4088 fprintf(stdout, "%7d bytes", mblengths[j]);
4089 fprintf(stdout, "\n");
4090 fprintf(stdout, "%-24s", alg_name);
4092 for (j = 0; j < num; j++) {
4093 if (results[D_EVP][j] > 10000)
4094 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
4096 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
4098 fprintf(stdout, "\n");
4103 EVP_CIPHER_CTX_free(ctx);