2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #define RSA_SECONDS 10
14 #define DSA_SECONDS 10
15 #define ECDSA_SECONDS 10
16 #define ECDH_SECONDS 10
17 #define EdDSA_SECONDS 10
18 #define SM2_SECONDS 10
19 #define FFDH_SECONDS 10
21 /* We need to use some deprecated APIs */
22 #define OPENSSL_SUPPRESS_DEPRECATED
30 #include <openssl/crypto.h>
31 #include <openssl/rand.h>
32 #include <openssl/err.h>
33 #include <openssl/evp.h>
34 #include <openssl/objects.h>
35 #include <openssl/async.h>
36 #if !defined(OPENSSL_SYS_MSDOS)
41 # if defined(OPENSSL_TANDEM_FLOSS)
42 # include <floss.h(floss_fork)>
50 #include <openssl/bn.h>
51 #ifndef OPENSSL_NO_DES
52 # include <openssl/des.h>
54 #ifndef OPENSSL_NO_DEPRECATED_3_0
55 #include <openssl/aes.h>
57 #ifndef OPENSSL_NO_CAMELLIA
58 # include <openssl/camellia.h>
60 #ifndef OPENSSL_NO_MD2
61 # include <openssl/md2.h>
63 #ifndef OPENSSL_NO_MDC2
64 # include <openssl/mdc2.h>
66 #ifndef OPENSSL_NO_MD4
67 # include <openssl/md4.h>
69 #ifndef OPENSSL_NO_MD5
70 # include <openssl/md5.h>
72 #include <openssl/hmac.h>
73 #ifndef OPENSSL_NO_CMAC
74 #include <openssl/cmac.h>
76 #include <openssl/sha.h>
77 #ifndef OPENSSL_NO_RMD160
78 # include <openssl/ripemd.h>
80 #ifndef OPENSSL_NO_WHIRLPOOL
81 # include <openssl/whrlpool.h>
83 #ifndef OPENSSL_NO_RC4
84 # include <openssl/rc4.h>
86 #ifndef OPENSSL_NO_RC5
87 # include <openssl/rc5.h>
89 #ifndef OPENSSL_NO_RC2
90 # include <openssl/rc2.h>
92 #ifndef OPENSSL_NO_IDEA
93 # include <openssl/idea.h>
95 #ifndef OPENSSL_NO_SEED
96 # include <openssl/seed.h>
99 # include <openssl/blowfish.h>
101 #ifndef OPENSSL_NO_CAST
102 # include <openssl/cast.h>
104 #ifndef OPENSSL_NO_DEPRECATED_3_0
105 # include <openssl/rsa.h>
106 # include "./testrsa.h"
108 #ifndef OPENSSL_NO_DH
109 # include <openssl/dh.h>
111 #include <openssl/x509.h>
112 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
113 # include <openssl/dsa.h>
114 # include "./testdsa.h"
116 #ifndef OPENSSL_NO_EC
117 # include <openssl/ec.h>
119 #include <openssl/modes.h>
122 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
135 #define MAX_MISALIGNMENT 63
136 #define MAX_ECDH_SIZE 256
138 #define MAX_FFDH_SIZE 1024
140 typedef struct openssl_speed_sec_st
{
149 } openssl_speed_sec_t
;
151 static volatile int run
= 0;
153 static int mr
= 0; /* machine-readeable output format to merge fork results */
154 static int usertime
= 1;
156 static double Time_F(int s
);
157 static void print_message(const char *s
, long num
, int length
, int tm
);
158 #if !defined(OPENSSL_NO_DEPRECATED_3_0) \
159 || !defined(OPENSSL_NO_DSA) \
160 || !defined(OPENSSL_NO_DH) \
161 || !defined(OPENSSL_NO_EC)
162 static void pkey_print_message(const char *str
, const char *str2
,
163 long num
, unsigned int bits
, int sec
);
165 static void print_result(int alg
, int run_no
, int count
, double time_used
);
167 static int do_multi(int multi
, int size_num
);
170 static const int lengths_list
[] = {
171 16, 64, 256, 1024, 8 * 1024, 16 * 1024
173 #define SIZE_NUM OSSL_NELEM(lengths_list)
174 static const int *lengths
= lengths_list
;
176 static const int aead_lengths_list
[] = {
177 2, 31, 136, 1024, 8 * 1024, 16 * 1024
185 static void alarmed(int sig
)
187 signal(SIGALRM
, alarmed
);
191 static double Time_F(int s
)
193 double ret
= app_tminterval(s
, usertime
);
199 #elif defined(_WIN32)
203 static unsigned int lapse
;
204 static volatile unsigned int schlock
;
205 static void alarm_win32(unsigned int secs
)
210 # define alarm alarm_win32
212 static DWORD WINAPI
sleepy(VOID
* arg
)
220 static double Time_F(int s
)
227 thr
= CreateThread(NULL
, 4096, sleepy
, NULL
, 0, NULL
);
229 DWORD err
= GetLastError();
230 BIO_printf(bio_err
, "unable to CreateThread (%lu)", err
);
234 Sleep(0); /* scheduler spinlock */
235 ret
= app_tminterval(s
, usertime
);
237 ret
= app_tminterval(s
, usertime
);
239 TerminateThread(thr
, 0);
246 static double Time_F(int s
)
248 return app_tminterval(s
, usertime
);
252 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
, int lengths_single
,
253 const openssl_speed_sec_t
*seconds
);
255 static int opt_found(const char *name
, unsigned int *result
,
256 const OPT_PAIR pairs
[], unsigned int nbelem
)
260 for (idx
= 0; idx
< nbelem
; ++idx
, pairs
++)
261 if (strcmp(name
, pairs
->name
) == 0) {
262 *result
= pairs
->retval
;
267 #define opt_found(value, pairs, result)\
268 opt_found(value, result, pairs, OSSL_NELEM(pairs))
270 typedef enum OPTION_choice
{
271 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
272 OPT_ELAPSED
, OPT_EVP
, OPT_HMAC
, OPT_DECRYPT
, OPT_ENGINE
, OPT_MULTI
,
273 OPT_MR
, OPT_MB
, OPT_MISALIGN
, OPT_ASYNCJOBS
, OPT_R_ENUM
, OPT_PROV_ENUM
,
274 OPT_PRIMES
, OPT_SECONDS
, OPT_BYTES
, OPT_AEAD
, OPT_CMAC
277 const OPTIONS speed_options
[] = {
278 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] [algorithm...]\n"},
280 OPT_SECTION("General"),
281 {"help", OPT_HELP
, '-', "Display this summary"},
283 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
284 {"mr", OPT_MR
, '-', "Produce machine readable output"},
286 {"multi", OPT_MULTI
, 'p', "Run benchmarks in parallel"},
288 #ifndef OPENSSL_NO_ASYNC
289 {"async_jobs", OPT_ASYNCJOBS
, 'p',
290 "Enable async mode and start specified number of jobs"},
292 #ifndef OPENSSL_NO_ENGINE
293 {"engine", OPT_ENGINE
, 's', "Use engine, possibly a hardware device"},
295 {"primes", OPT_PRIMES
, 'p', "Specify number of primes (for RSA only)"},
297 OPT_SECTION("Selection"),
298 {"evp", OPT_EVP
, 's', "Use EVP-named cipher or digest"},
299 #ifndef OPENSSL_NO_DEPRECATED_3_0
300 {"hmac", OPT_HMAC
, 's', "HMAC using EVP-named digest"},
302 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
303 {"cmac", OPT_CMAC
, 's', "CMAC using EVP-named cipher"},
305 {"decrypt", OPT_DECRYPT
, '-',
306 "Time decryption instead of encryption (only EVP)"},
307 {"aead", OPT_AEAD
, '-',
308 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
310 OPT_SECTION("Timing"),
311 {"elapsed", OPT_ELAPSED
, '-',
312 "Use wall-clock time instead of CPU user time as divisor"},
313 {"seconds", OPT_SECONDS
, 'p',
314 "Run benchmarks for specified amount of seconds"},
315 {"bytes", OPT_BYTES
, 'p',
316 "Run [non-PKI] benchmarks on custom-sized buffer"},
317 {"misalign", OPT_MISALIGN
, 'p',
318 "Use specified offset to mis-align buffers"},
324 {"algorithm", 0, 0, "Algorithm(s) to test (optional; otherwise tests all)"},
329 D_MD2
, D_MDC2
, D_MD4
, D_MD5
, D_HMAC
, D_SHA1
, D_RMD160
, D_RC4
,
330 D_CBC_DES
, D_EDE3_DES
, D_CBC_IDEA
, D_CBC_SEED
,
331 D_CBC_RC2
, D_CBC_RC5
, D_CBC_BF
, D_CBC_CAST
,
332 D_CBC_128_AES
, D_CBC_192_AES
, D_CBC_256_AES
,
333 D_CBC_128_CML
, D_CBC_192_CML
, D_CBC_256_CML
,
334 D_EVP
, D_SHA256
, D_SHA512
, D_WHIRLPOOL
,
335 D_IGE_128_AES
, D_IGE_192_AES
, D_IGE_256_AES
,
336 D_GHASH
, D_RAND
, D_EVP_HMAC
, D_EVP_CMAC
, ALGOR_NUM
338 /* name of algorithms to test. MUST BE KEEP IN SYNC with above enum ! */
339 static const char *names
[ALGOR_NUM
] = {
340 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
341 "des cbc", "des ede3", "idea cbc", "seed cbc",
342 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
343 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
344 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
345 "evp", "sha256", "sha512", "whirlpool",
346 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
347 "rand", "hmac", "cmac"
350 /* list of configured algorithm (remaining), with some few alias */
351 static const OPT_PAIR doit_choices
[] = {
352 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
355 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
358 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
361 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
363 # ifndef OPENSSL_NO_DEPRECATED_3_0
367 #ifndef OPENSSL_NO_DEPRECATED_3_0
369 {"sha256", D_SHA256
},
370 {"sha512", D_SHA512
},
372 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
373 {"whirlpool", D_WHIRLPOOL
},
375 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
376 {"ripemd", D_RMD160
},
377 {"rmd160", D_RMD160
},
378 {"ripemd160", D_RMD160
},
380 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
383 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
384 {"des-cbc", D_CBC_DES
},
385 {"des-ede3", D_EDE3_DES
},
387 #ifndef OPENSSL_NO_DEPRECATED_3_0
388 {"aes-128-cbc", D_CBC_128_AES
},
389 {"aes-192-cbc", D_CBC_192_AES
},
390 {"aes-256-cbc", D_CBC_256_AES
},
391 {"aes-128-ige", D_IGE_128_AES
},
392 {"aes-192-ige", D_IGE_192_AES
},
393 {"aes-256-ige", D_IGE_256_AES
},
395 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
396 {"rc2-cbc", D_CBC_RC2
},
399 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
400 {"rc5-cbc", D_CBC_RC5
},
403 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
404 {"idea-cbc", D_CBC_IDEA
},
405 {"idea", D_CBC_IDEA
},
407 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
408 {"seed-cbc", D_CBC_SEED
},
409 {"seed", D_CBC_SEED
},
411 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
412 {"bf-cbc", D_CBC_BF
},
413 {"blowfish", D_CBC_BF
},
416 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
417 {"cast-cbc", D_CBC_CAST
},
418 {"cast", D_CBC_CAST
},
419 {"cast5", D_CBC_CAST
},
425 static double results
[ALGOR_NUM
][SIZE_NUM
];
427 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
428 enum { R_DSA_512
, R_DSA_1024
, R_DSA_2048
, DSA_NUM
};
429 static const OPT_PAIR dsa_choices
[DSA_NUM
] = {
430 {"dsa512", R_DSA_512
},
431 {"dsa1024", R_DSA_1024
},
432 {"dsa2048", R_DSA_2048
}
434 static double dsa_results
[DSA_NUM
][2]; /* 2 ops: sign then verify */
435 #endif /* OPENSSL_NO_DSA */
437 #ifndef OPENSSL_NO_DEPRECATED_3_0
439 R_RSA_512
, R_RSA_1024
, R_RSA_2048
, R_RSA_3072
, R_RSA_4096
, R_RSA_7680
,
442 static const OPT_PAIR rsa_choices
[RSA_NUM
] = {
443 {"rsa512", R_RSA_512
},
444 {"rsa1024", R_RSA_1024
},
445 {"rsa2048", R_RSA_2048
},
446 {"rsa3072", R_RSA_3072
},
447 {"rsa4096", R_RSA_4096
},
448 {"rsa7680", R_RSA_7680
},
449 {"rsa15360", R_RSA_15360
}
452 static double rsa_results
[RSA_NUM
][2]; /* 2 ops: sign then verify */
453 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
455 #ifndef OPENSSL_NO_DH
457 R_FFDH_2048
, R_FFDH_3072
, R_FFDH_4096
, R_FFDH_6144
, R_FFDH_8192
, FFDH_NUM
460 static const OPT_PAIR ffdh_choices
[FFDH_NUM
] = {
461 {"ffdh2048", R_FFDH_2048
},
462 {"ffdh3072", R_FFDH_3072
},
463 {"ffdh4096", R_FFDH_4096
},
464 {"ffdh6144", R_FFDH_6144
},
465 {"ffdh8192", R_FFDH_8192
},
468 static double ffdh_results
[FFDH_NUM
][1]; /* 1 op: derivation */
469 #endif /* OPENSSL_NO_DH */
471 #ifndef OPENSSL_NO_EC
473 R_EC_P160
, R_EC_P192
, R_EC_P224
, R_EC_P256
, R_EC_P384
, R_EC_P521
,
474 # ifndef OPENSSL_NO_EC2M
475 R_EC_K163
, R_EC_K233
, R_EC_K283
, R_EC_K409
, R_EC_K571
,
476 R_EC_B163
, R_EC_B233
, R_EC_B283
, R_EC_B409
, R_EC_B571
,
478 R_EC_BRP256R1
, R_EC_BRP256T1
, R_EC_BRP384R1
, R_EC_BRP384T1
,
479 R_EC_BRP512R1
, R_EC_BRP512T1
, ECDSA_NUM
481 /* list of ecdsa curves */
482 static const OPT_PAIR ecdsa_choices
[ECDSA_NUM
] = {
483 {"ecdsap160", R_EC_P160
},
484 {"ecdsap192", R_EC_P192
},
485 {"ecdsap224", R_EC_P224
},
486 {"ecdsap256", R_EC_P256
},
487 {"ecdsap384", R_EC_P384
},
488 {"ecdsap521", R_EC_P521
},
489 # ifndef OPENSSL_NO_EC2M
490 {"ecdsak163", R_EC_K163
},
491 {"ecdsak233", R_EC_K233
},
492 {"ecdsak283", R_EC_K283
},
493 {"ecdsak409", R_EC_K409
},
494 {"ecdsak571", R_EC_K571
},
495 {"ecdsab163", R_EC_B163
},
496 {"ecdsab233", R_EC_B233
},
497 {"ecdsab283", R_EC_B283
},
498 {"ecdsab409", R_EC_B409
},
499 {"ecdsab571", R_EC_B571
},
501 {"ecdsabrp256r1", R_EC_BRP256R1
},
502 {"ecdsabrp256t1", R_EC_BRP256T1
},
503 {"ecdsabrp384r1", R_EC_BRP384R1
},
504 {"ecdsabrp384t1", R_EC_BRP384T1
},
505 {"ecdsabrp512r1", R_EC_BRP512R1
},
506 {"ecdsabrp512t1", R_EC_BRP512T1
}
508 enum { R_EC_X25519
= ECDSA_NUM
, R_EC_X448
, EC_NUM
};
509 /* list of ecdh curves, extension of |ecdsa_choices| list above */
510 static const OPT_PAIR ecdh_choices
[EC_NUM
] = {
511 {"ecdhp160", R_EC_P160
},
512 {"ecdhp192", R_EC_P192
},
513 {"ecdhp224", R_EC_P224
},
514 {"ecdhp256", R_EC_P256
},
515 {"ecdhp384", R_EC_P384
},
516 {"ecdhp521", R_EC_P521
},
517 # ifndef OPENSSL_NO_EC2M
518 {"ecdhk163", R_EC_K163
},
519 {"ecdhk233", R_EC_K233
},
520 {"ecdhk283", R_EC_K283
},
521 {"ecdhk409", R_EC_K409
},
522 {"ecdhk571", R_EC_K571
},
523 {"ecdhb163", R_EC_B163
},
524 {"ecdhb233", R_EC_B233
},
525 {"ecdhb283", R_EC_B283
},
526 {"ecdhb409", R_EC_B409
},
527 {"ecdhb571", R_EC_B571
},
529 {"ecdhbrp256r1", R_EC_BRP256R1
},
530 {"ecdhbrp256t1", R_EC_BRP256T1
},
531 {"ecdhbrp384r1", R_EC_BRP384R1
},
532 {"ecdhbrp384t1", R_EC_BRP384T1
},
533 {"ecdhbrp512r1", R_EC_BRP512R1
},
534 {"ecdhbrp512t1", R_EC_BRP512T1
},
535 {"ecdhx25519", R_EC_X25519
},
536 {"ecdhx448", R_EC_X448
}
539 static double ecdh_results
[EC_NUM
][1]; /* 1 op: derivation */
540 static double ecdsa_results
[ECDSA_NUM
][2]; /* 2 ops: sign then verify */
542 enum { R_EC_Ed25519
, R_EC_Ed448
, EdDSA_NUM
};
543 static const OPT_PAIR eddsa_choices
[EdDSA_NUM
] = {
544 {"ed25519", R_EC_Ed25519
},
545 {"ed448", R_EC_Ed448
}
548 static double eddsa_results
[EdDSA_NUM
][2]; /* 2 ops: sign then verify */
550 # ifndef OPENSSL_NO_SM2
551 enum { R_EC_CURVESM2
, SM2_NUM
};
552 static const OPT_PAIR sm2_choices
[SM2_NUM
] = {
553 {"curveSM2", R_EC_CURVESM2
}
555 # define SM2_ID "TLSv1.3+GM+Cipher+Suite"
556 # define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1
557 static double sm2_results
[SM2_NUM
][2]; /* 2 ops: sign then verify */
558 # endif /* OPENSSL_NO_SM2 */
559 #endif /* OPENSSL_NO_EC */
562 # define COND(d) (count < (d))
563 # define COUNT(d) (d)
565 # define COND(unused_cond) (run && count<0x7fffffff)
566 # define COUNT(d) (count)
569 typedef struct loopargs_st
{
570 ASYNC_JOB
*inprogress_job
;
571 ASYNC_WAIT_CTX
*wait_ctx
;
574 unsigned char *buf_malloc
;
575 unsigned char *buf2_malloc
;
579 #ifndef OPENSSL_NO_DEPRECATED_3_0
580 RSA
*rsa_key
[RSA_NUM
];
582 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
583 DSA
*dsa_key
[DSA_NUM
];
585 #ifndef OPENSSL_NO_EC
586 # ifndef OPENSSL_NO_DEPRECATED_3_0
587 EC_KEY
*ecdsa
[ECDSA_NUM
];
589 EVP_PKEY_CTX
*ecdh_ctx
[EC_NUM
];
590 EVP_MD_CTX
*eddsa_ctx
[EdDSA_NUM
];
591 EVP_MD_CTX
*eddsa_ctx2
[EdDSA_NUM
];
592 # ifndef OPENSSL_NO_SM2
593 EVP_MD_CTX
*sm2_ctx
[SM2_NUM
];
594 EVP_MD_CTX
*sm2_vfy_ctx
[SM2_NUM
];
595 EVP_PKEY
*sm2_pkey
[SM2_NUM
];
597 unsigned char *secret_a
;
598 unsigned char *secret_b
;
599 size_t outlen
[EC_NUM
];
601 #ifndef OPENSSL_NO_DH
602 EVP_PKEY_CTX
*ffdh_ctx
[FFDH_NUM
];
603 unsigned char *secret_ff_a
;
604 unsigned char *secret_ff_b
;
607 #ifndef OPENSSL_NO_DEPRECATED_3_0
610 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
613 GCM128_CONTEXT
*gcm_ctx
;
615 static int run_benchmark(int async_jobs
, int (*loop_function
) (void *),
616 loopargs_t
* loopargs
);
618 static unsigned int testnum
;
620 /* Nb of iterations to do per algorithm and key-size */
621 static long c
[ALGOR_NUM
][SIZE_NUM
];
623 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
624 static int EVP_Digest_MD2_loop(void *args
)
626 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
627 unsigned char *buf
= tempargs
->buf
;
628 unsigned char md2
[MD2_DIGEST_LENGTH
];
631 for (count
= 0; COND(c
[D_MD2
][testnum
]); count
++) {
632 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md2
, NULL
, EVP_md2(),
640 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
641 static int EVP_Digest_MDC2_loop(void *args
)
643 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
644 unsigned char *buf
= tempargs
->buf
;
645 unsigned char mdc2
[MDC2_DIGEST_LENGTH
];
648 for (count
= 0; COND(c
[D_MDC2
][testnum
]); count
++) {
649 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], mdc2
, NULL
, EVP_mdc2(),
657 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
658 static int EVP_Digest_MD4_loop(void *args
)
660 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
661 unsigned char *buf
= tempargs
->buf
;
662 unsigned char md4
[MD4_DIGEST_LENGTH
];
665 for (count
= 0; COND(c
[D_MD4
][testnum
]); count
++) {
666 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md4
, NULL
, EVP_md4(),
674 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
675 static int MD5_loop(void *args
)
677 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
678 unsigned char *buf
= tempargs
->buf
;
679 unsigned char md5
[MD5_DIGEST_LENGTH
];
681 for (count
= 0; COND(c
[D_MD5
][testnum
]); count
++)
682 MD5(buf
, lengths
[testnum
], md5
);
686 # ifndef OPENSSL_NO_DEPRECATED_3_0
687 static int HMAC_loop(void *args
)
689 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
690 unsigned char *buf
= tempargs
->buf
;
691 HMAC_CTX
*hctx
= tempargs
->hctx
;
692 unsigned char hmac
[MD5_DIGEST_LENGTH
];
695 for (count
= 0; COND(c
[D_HMAC
][testnum
]); count
++) {
696 HMAC_Init_ex(hctx
, NULL
, 0, NULL
, NULL
);
697 HMAC_Update(hctx
, buf
, lengths
[testnum
]);
698 HMAC_Final(hctx
, hmac
, NULL
);
705 #ifndef OPENSSL_NO_DEPRECATED_3_0
706 static int SHA1_loop(void *args
)
708 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
709 unsigned char *buf
= tempargs
->buf
;
710 unsigned char sha
[SHA_DIGEST_LENGTH
];
712 for (count
= 0; COND(c
[D_SHA1
][testnum
]); count
++)
713 SHA1(buf
, lengths
[testnum
], sha
);
717 static int SHA256_loop(void *args
)
719 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
720 unsigned char *buf
= tempargs
->buf
;
721 unsigned char sha256
[SHA256_DIGEST_LENGTH
];
723 for (count
= 0; COND(c
[D_SHA256
][testnum
]); count
++)
724 SHA256(buf
, lengths
[testnum
], sha256
);
728 static int SHA512_loop(void *args
)
730 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
731 unsigned char *buf
= tempargs
->buf
;
732 unsigned char sha512
[SHA512_DIGEST_LENGTH
];
734 for (count
= 0; COND(c
[D_SHA512
][testnum
]); count
++)
735 SHA512(buf
, lengths
[testnum
], sha512
);
740 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
741 static int WHIRLPOOL_loop(void *args
)
743 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
744 unsigned char *buf
= tempargs
->buf
;
745 unsigned char whirlpool
[WHIRLPOOL_DIGEST_LENGTH
];
747 for (count
= 0; COND(c
[D_WHIRLPOOL
][testnum
]); count
++)
748 WHIRLPOOL(buf
, lengths
[testnum
], whirlpool
);
753 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
754 static int EVP_Digest_RMD160_loop(void *args
)
756 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
757 unsigned char *buf
= tempargs
->buf
;
758 unsigned char rmd160
[RIPEMD160_DIGEST_LENGTH
];
760 for (count
= 0; COND(c
[D_RMD160
][testnum
]); count
++) {
761 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], &(rmd160
[0]),
762 NULL
, EVP_ripemd160(), NULL
))
769 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
770 static RC4_KEY rc4_ks
;
771 static int RC4_loop(void *args
)
773 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
774 unsigned char *buf
= tempargs
->buf
;
776 for (count
= 0; COND(c
[D_RC4
][testnum
]); count
++)
777 RC4(&rc4_ks
, (size_t)lengths
[testnum
], buf
, buf
);
782 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
783 static unsigned char DES_iv
[8];
784 static DES_key_schedule sch
[3];
785 static int DES_ncbc_encrypt_loop(void *args
)
787 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
788 unsigned char *buf
= tempargs
->buf
;
790 for (count
= 0; COND(c
[D_CBC_DES
][testnum
]); count
++)
791 DES_ncbc_encrypt(buf
, buf
, lengths
[testnum
], &sch
[0],
792 &DES_iv
, DES_ENCRYPT
);
796 static int DES_ede3_cbc_encrypt_loop(void *args
)
798 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
799 unsigned char *buf
= tempargs
->buf
;
801 for (count
= 0; COND(c
[D_EDE3_DES
][testnum
]); count
++)
802 DES_ede3_cbc_encrypt(buf
, buf
, lengths
[testnum
],
803 &sch
[0], &sch
[1], &sch
[2], &DES_iv
, DES_ENCRYPT
);
808 #define MAX_BLOCK_SIZE 128
810 static unsigned char iv
[2 * MAX_BLOCK_SIZE
/ 8];
812 #ifndef OPENSSL_NO_DEPRECATED_3_0
813 static AES_KEY aes_ks1
, aes_ks2
, aes_ks3
;
814 static int AES_cbc_128_encrypt_loop(void *args
)
816 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
817 unsigned char *buf
= tempargs
->buf
;
819 for (count
= 0; COND(c
[D_CBC_128_AES
][testnum
]); count
++)
820 AES_cbc_encrypt(buf
, buf
,
821 (size_t)lengths
[testnum
], &aes_ks1
, iv
, AES_ENCRYPT
);
825 static int AES_cbc_192_encrypt_loop(void *args
)
827 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
828 unsigned char *buf
= tempargs
->buf
;
830 for (count
= 0; COND(c
[D_CBC_192_AES
][testnum
]); count
++)
831 AES_cbc_encrypt(buf
, buf
,
832 (size_t)lengths
[testnum
], &aes_ks2
, iv
, AES_ENCRYPT
);
836 static int AES_cbc_256_encrypt_loop(void *args
)
838 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
839 unsigned char *buf
= tempargs
->buf
;
841 for (count
= 0; COND(c
[D_CBC_256_AES
][testnum
]); count
++)
842 AES_cbc_encrypt(buf
, buf
,
843 (size_t)lengths
[testnum
], &aes_ks3
, iv
, AES_ENCRYPT
);
847 static int AES_ige_128_encrypt_loop(void *args
)
849 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
850 unsigned char *buf
= tempargs
->buf
;
851 unsigned char *buf2
= tempargs
->buf2
;
853 for (count
= 0; COND(c
[D_IGE_128_AES
][testnum
]); count
++)
854 AES_ige_encrypt(buf
, buf2
,
855 (size_t)lengths
[testnum
], &aes_ks1
, iv
, AES_ENCRYPT
);
859 static int AES_ige_192_encrypt_loop(void *args
)
861 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
862 unsigned char *buf
= tempargs
->buf
;
863 unsigned char *buf2
= tempargs
->buf2
;
865 for (count
= 0; COND(c
[D_IGE_192_AES
][testnum
]); count
++)
866 AES_ige_encrypt(buf
, buf2
,
867 (size_t)lengths
[testnum
], &aes_ks2
, iv
, AES_ENCRYPT
);
871 static int AES_ige_256_encrypt_loop(void *args
)
873 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
874 unsigned char *buf
= tempargs
->buf
;
875 unsigned char *buf2
= tempargs
->buf2
;
877 for (count
= 0; COND(c
[D_IGE_256_AES
][testnum
]); count
++)
878 AES_ige_encrypt(buf
, buf2
,
879 (size_t)lengths
[testnum
], &aes_ks3
, iv
, AES_ENCRYPT
);
883 static int CRYPTO_gcm128_aad_loop(void *args
)
885 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
886 unsigned char *buf
= tempargs
->buf
;
887 GCM128_CONTEXT
*gcm_ctx
= tempargs
->gcm_ctx
;
889 for (count
= 0; COND(c
[D_GHASH
][testnum
]); count
++)
890 CRYPTO_gcm128_aad(gcm_ctx
, buf
, lengths
[testnum
]);
895 static int RAND_bytes_loop(void *args
)
897 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
898 unsigned char *buf
= tempargs
->buf
;
901 for (count
= 0; COND(c
[D_RAND
][testnum
]); count
++)
902 RAND_bytes(buf
, lengths
[testnum
]);
906 static int decrypt
= 0;
907 static int EVP_Update_loop(void *args
)
909 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
910 unsigned char *buf
= tempargs
->buf
;
911 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
915 for (count
= 0; COND(c
[D_EVP
][testnum
]); count
++) {
916 rc
= EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
918 /* reset iv in case of counter overflow */
919 EVP_CipherInit_ex(ctx
, NULL
, NULL
, NULL
, iv
, -1);
923 for (count
= 0; COND(c
[D_EVP
][testnum
]); count
++) {
924 rc
= EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
926 /* reset iv in case of counter overflow */
927 EVP_CipherInit_ex(ctx
, NULL
, NULL
, NULL
, iv
, -1);
932 EVP_DecryptFinal_ex(ctx
, buf
, &outl
);
934 EVP_EncryptFinal_ex(ctx
, buf
, &outl
);
939 * CCM does not support streaming. For the purpose of performance measurement,
940 * each message is encrypted using the same (key,iv)-pair. Do not use this
941 * code in your application.
943 static int EVP_Update_loop_ccm(void *args
)
945 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
946 unsigned char *buf
= tempargs
->buf
;
947 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
949 unsigned char tag
[12];
952 for (count
= 0; COND(c
[D_EVP
][testnum
]); count
++) {
953 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_TAG
, sizeof(tag
), tag
);
955 EVP_DecryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
956 /* counter is reset on every update */
957 EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
960 for (count
= 0; COND(c
[D_EVP
][testnum
]); count
++) {
961 /* restore iv length field */
962 EVP_EncryptUpdate(ctx
, NULL
, &outl
, NULL
, lengths
[testnum
]);
963 /* counter is reset on every update */
964 EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
968 EVP_DecryptFinal_ex(ctx
, buf
, &outl
);
970 EVP_EncryptFinal_ex(ctx
, buf
, &outl
);
975 * To make AEAD benchmarking more relevant perform TLS-like operations,
976 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
977 * payload length is not actually limited by 16KB...
979 static int EVP_Update_loop_aead(void *args
)
981 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
982 unsigned char *buf
= tempargs
->buf
;
983 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
985 unsigned char aad
[13] = { 0xcc };
986 unsigned char faketag
[16] = { 0xcc };
989 for (count
= 0; COND(c
[D_EVP
][testnum
]); count
++) {
990 EVP_DecryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
991 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_TAG
,
992 sizeof(faketag
), faketag
);
993 EVP_DecryptUpdate(ctx
, NULL
, &outl
, aad
, sizeof(aad
));
994 EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
995 EVP_DecryptFinal_ex(ctx
, buf
+ outl
, &outl
);
998 for (count
= 0; COND(c
[D_EVP
][testnum
]); count
++) {
999 EVP_EncryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
1000 EVP_EncryptUpdate(ctx
, NULL
, &outl
, aad
, sizeof(aad
));
1001 EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
1002 EVP_EncryptFinal_ex(ctx
, buf
+ outl
, &outl
);
1008 static EVP_MD
*evp_md
= NULL
;
1009 static int fetched_alg
= 0;
1011 static int EVP_Digest_loop(void *args
)
1013 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1014 unsigned char *buf
= tempargs
->buf
;
1015 unsigned char md
[EVP_MAX_MD_SIZE
];
1018 for (count
= 0; COND(c
[D_EVP
][testnum
]); count
++) {
1019 if (!EVP_Digest(buf
, lengths
[testnum
], md
, NULL
, evp_md
, NULL
))
1025 #ifndef OPENSSL_NO_DEPRECATED_3_0
1026 static const EVP_MD
*evp_hmac_md
= NULL
;
1027 static char *evp_hmac_name
= NULL
;
1028 static int EVP_HMAC_loop(void *args
)
1030 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1031 unsigned char *buf
= tempargs
->buf
;
1032 unsigned char no_key
[32];
1035 for (count
= 0; COND(c
[D_EVP_HMAC
][testnum
]); count
++) {
1036 if (HMAC(evp_hmac_md
, no_key
, sizeof(no_key
), buf
, lengths
[testnum
],
1037 NULL
, NULL
) == NULL
)
1044 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1045 static const EVP_CIPHER
*evp_cmac_cipher
= NULL
;
1046 static char *evp_cmac_name
= NULL
;
1048 static int EVP_CMAC_loop(void *args
)
1050 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1051 unsigned char *buf
= tempargs
->buf
;
1052 CMAC_CTX
*cmac_ctx
= tempargs
->cmac_ctx
;
1053 static const char key
[16] = "This is a key...";
1054 unsigned char mac
[16];
1055 size_t len
= sizeof(mac
);
1058 for (count
= 0; COND(c
[D_EVP_CMAC
][testnum
]); count
++) {
1059 if (!CMAC_Init(cmac_ctx
, key
, sizeof(key
), evp_cmac_cipher
, NULL
)
1060 || !CMAC_Update(cmac_ctx
, buf
, lengths
[testnum
])
1061 || !CMAC_Final(cmac_ctx
, mac
, &len
))
1068 #ifndef OPENSSL_NO_DEPRECATED_3_0
1069 static long rsa_c
[RSA_NUM
][2]; /* # RSA iteration test */
1071 static int RSA_sign_loop(void *args
)
1073 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1074 unsigned char *buf
= tempargs
->buf
;
1075 unsigned char *buf2
= tempargs
->buf2
;
1076 unsigned int *rsa_num
= &tempargs
->siglen
;
1077 RSA
**rsa_key
= tempargs
->rsa_key
;
1079 for (count
= 0; COND(rsa_c
[testnum
][0]); count
++) {
1080 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
1082 BIO_printf(bio_err
, "RSA sign failure\n");
1083 ERR_print_errors(bio_err
);
1091 static int RSA_verify_loop(void *args
)
1093 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1094 unsigned char *buf
= tempargs
->buf
;
1095 unsigned char *buf2
= tempargs
->buf2
;
1096 unsigned int rsa_num
= tempargs
->siglen
;
1097 RSA
**rsa_key
= tempargs
->rsa_key
;
1099 for (count
= 0; COND(rsa_c
[testnum
][1]); count
++) {
1101 RSA_verify(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
1103 BIO_printf(bio_err
, "RSA verify failure\n");
1104 ERR_print_errors(bio_err
);
1113 #ifndef OPENSSL_NO_DH
1114 static long ffdh_c
[FFDH_NUM
][1];
1116 static int FFDH_derive_key_loop(void *args
)
1118 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1119 EVP_PKEY_CTX
*ffdh_ctx
= tempargs
->ffdh_ctx
[testnum
];
1120 unsigned char *derived_secret
= tempargs
->secret_ff_a
;
1121 size_t outlen
= MAX_FFDH_SIZE
;
1124 for (count
= 0; COND(ffdh_c
[testnum
][0]); count
++)
1125 EVP_PKEY_derive(ffdh_ctx
, derived_secret
, &outlen
);
1129 #endif /* OPENSSL_NO_DH */
1131 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1132 static long dsa_c
[DSA_NUM
][2];
1133 static int DSA_sign_loop(void *args
)
1135 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1136 unsigned char *buf
= tempargs
->buf
;
1137 unsigned char *buf2
= tempargs
->buf2
;
1138 DSA
**dsa_key
= tempargs
->dsa_key
;
1139 unsigned int *siglen
= &tempargs
->siglen
;
1141 for (count
= 0; COND(dsa_c
[testnum
][0]); count
++) {
1142 ret
= DSA_sign(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
1144 BIO_printf(bio_err
, "DSA sign failure\n");
1145 ERR_print_errors(bio_err
);
1153 static int DSA_verify_loop(void *args
)
1155 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1156 unsigned char *buf
= tempargs
->buf
;
1157 unsigned char *buf2
= tempargs
->buf2
;
1158 DSA
**dsa_key
= tempargs
->dsa_key
;
1159 unsigned int siglen
= tempargs
->siglen
;
1161 for (count
= 0; COND(dsa_c
[testnum
][1]); count
++) {
1162 ret
= DSA_verify(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
1164 BIO_printf(bio_err
, "DSA verify failure\n");
1165 ERR_print_errors(bio_err
);
1174 #ifndef OPENSSL_NO_EC
1175 # ifndef OPENSSL_NO_DEPRECATED_3_0
1176 static long ecdsa_c
[ECDSA_NUM
][2];
1177 static int ECDSA_sign_loop(void *args
)
1179 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1180 unsigned char *buf
= tempargs
->buf
;
1181 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1182 unsigned char *ecdsasig
= tempargs
->buf2
;
1183 unsigned int *ecdsasiglen
= &tempargs
->siglen
;
1185 for (count
= 0; COND(ecdsa_c
[testnum
][0]); count
++) {
1186 ret
= ECDSA_sign(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[testnum
]);
1188 BIO_printf(bio_err
, "ECDSA sign failure\n");
1189 ERR_print_errors(bio_err
);
1197 static int ECDSA_verify_loop(void *args
)
1199 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1200 unsigned char *buf
= tempargs
->buf
;
1201 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1202 unsigned char *ecdsasig
= tempargs
->buf2
;
1203 unsigned int ecdsasiglen
= tempargs
->siglen
;
1205 for (count
= 0; COND(ecdsa_c
[testnum
][1]); count
++) {
1206 ret
= ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[testnum
]);
1208 BIO_printf(bio_err
, "ECDSA verify failure\n");
1209 ERR_print_errors(bio_err
);
1218 /* ******************************************************************** */
1219 static long ecdh_c
[EC_NUM
][1];
1221 static int ECDH_EVP_derive_key_loop(void *args
)
1223 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1224 EVP_PKEY_CTX
*ctx
= tempargs
->ecdh_ctx
[testnum
];
1225 unsigned char *derived_secret
= tempargs
->secret_a
;
1227 size_t *outlen
= &(tempargs
->outlen
[testnum
]);
1229 for (count
= 0; COND(ecdh_c
[testnum
][0]); count
++)
1230 EVP_PKEY_derive(ctx
, derived_secret
, outlen
);
1235 static long eddsa_c
[EdDSA_NUM
][2];
1236 static int EdDSA_sign_loop(void *args
)
1238 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1239 unsigned char *buf
= tempargs
->buf
;
1240 EVP_MD_CTX
**edctx
= tempargs
->eddsa_ctx
;
1241 unsigned char *eddsasig
= tempargs
->buf2
;
1242 size_t *eddsasigsize
= &tempargs
->sigsize
;
1245 for (count
= 0; COND(eddsa_c
[testnum
][0]); count
++) {
1246 ret
= EVP_DigestSign(edctx
[testnum
], eddsasig
, eddsasigsize
, buf
, 20);
1248 BIO_printf(bio_err
, "EdDSA sign failure\n");
1249 ERR_print_errors(bio_err
);
1257 static int EdDSA_verify_loop(void *args
)
1259 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1260 unsigned char *buf
= tempargs
->buf
;
1261 EVP_MD_CTX
**edctx
= tempargs
->eddsa_ctx2
;
1262 unsigned char *eddsasig
= tempargs
->buf2
;
1263 size_t eddsasigsize
= tempargs
->sigsize
;
1266 for (count
= 0; COND(eddsa_c
[testnum
][1]); count
++) {
1267 ret
= EVP_DigestVerify(edctx
[testnum
], eddsasig
, eddsasigsize
, buf
, 20);
1269 BIO_printf(bio_err
, "EdDSA verify failure\n");
1270 ERR_print_errors(bio_err
);
1278 # ifndef OPENSSL_NO_SM2
1279 static long sm2_c
[SM2_NUM
][2];
1280 static int SM2_sign_loop(void *args
)
1282 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1283 unsigned char *buf
= tempargs
->buf
;
1284 EVP_MD_CTX
**sm2ctx
= tempargs
->sm2_ctx
;
1285 unsigned char *sm2sig
= tempargs
->buf2
;
1286 size_t sm2sigsize
= tempargs
->sigsize
;
1287 const size_t max_size
= tempargs
->sigsize
;
1289 EVP_PKEY
**sm2_pkey
= tempargs
->sm2_pkey
;
1291 for (count
= 0; COND(sm2_c
[testnum
][0]); count
++) {
1292 if (!EVP_DigestSignInit(sm2ctx
[testnum
], NULL
, EVP_sm3(),
1293 NULL
, sm2_pkey
[testnum
])) {
1294 BIO_printf(bio_err
, "SM2 init sign failure\n");
1295 ERR_print_errors(bio_err
);
1299 ret
= EVP_DigestSign(sm2ctx
[testnum
], sm2sig
, &sm2sigsize
,
1302 BIO_printf(bio_err
, "SM2 sign failure\n");
1303 ERR_print_errors(bio_err
);
1307 /* update the latest returned size and always use the fixed buffer size */
1308 tempargs
->sigsize
= sm2sigsize
;
1309 sm2sigsize
= max_size
;
1315 static int SM2_verify_loop(void *args
)
1317 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1318 unsigned char *buf
= tempargs
->buf
;
1319 EVP_MD_CTX
**sm2ctx
= tempargs
->sm2_vfy_ctx
;
1320 unsigned char *sm2sig
= tempargs
->buf2
;
1321 size_t sm2sigsize
= tempargs
->sigsize
;
1323 EVP_PKEY
**sm2_pkey
= tempargs
->sm2_pkey
;
1325 for (count
= 0; COND(sm2_c
[testnum
][1]); count
++) {
1326 if (!EVP_DigestVerifyInit(sm2ctx
[testnum
], NULL
, EVP_sm3(),
1327 NULL
, sm2_pkey
[testnum
])) {
1328 BIO_printf(bio_err
, "SM2 verify init failure\n");
1329 ERR_print_errors(bio_err
);
1333 ret
= EVP_DigestVerify(sm2ctx
[testnum
], sm2sig
, sm2sigsize
,
1336 BIO_printf(bio_err
, "SM2 verify failure\n");
1337 ERR_print_errors(bio_err
);
1344 # endif /* OPENSSL_NO_SM2 */
1345 #endif /* OPENSSL_NO_EC */
1347 static int run_benchmark(int async_jobs
,
1348 int (*loop_function
) (void *), loopargs_t
* loopargs
)
1350 int job_op_count
= 0;
1351 int total_op_count
= 0;
1352 int num_inprogress
= 0;
1353 int error
= 0, i
= 0, ret
= 0;
1354 OSSL_ASYNC_FD job_fd
= 0;
1355 size_t num_job_fds
= 0;
1357 if (async_jobs
== 0) {
1358 return loop_function((void *)&loopargs
);
1361 for (i
= 0; i
< async_jobs
&& !error
; i
++) {
1362 loopargs_t
*looparg_item
= loopargs
+ i
;
1364 /* Copy pointer content (looparg_t item address) into async context */
1365 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
, loopargs
[i
].wait_ctx
,
1366 &job_op_count
, loop_function
,
1367 (void *)&looparg_item
, sizeof(looparg_item
));
1373 if (job_op_count
== -1) {
1376 total_op_count
+= job_op_count
;
1381 BIO_printf(bio_err
, "Failure in the job\n");
1382 ERR_print_errors(bio_err
);
1388 while (num_inprogress
> 0) {
1389 #if defined(OPENSSL_SYS_WINDOWS)
1391 #elif defined(OPENSSL_SYS_UNIX)
1392 int select_result
= 0;
1393 OSSL_ASYNC_FD max_fd
= 0;
1396 FD_ZERO(&waitfdset
);
1398 for (i
= 0; i
< async_jobs
&& num_inprogress
> 0; i
++) {
1399 if (loopargs
[i
].inprogress_job
== NULL
)
1402 if (!ASYNC_WAIT_CTX_get_all_fds
1403 (loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1404 || num_job_fds
> 1) {
1405 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1406 ERR_print_errors(bio_err
);
1410 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
,
1412 FD_SET(job_fd
, &waitfdset
);
1413 if (job_fd
> max_fd
)
1417 if (max_fd
>= (OSSL_ASYNC_FD
)FD_SETSIZE
) {
1419 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1420 "Decrease the value of async_jobs\n",
1421 max_fd
, FD_SETSIZE
);
1422 ERR_print_errors(bio_err
);
1427 select_result
= select(max_fd
+ 1, &waitfdset
, NULL
, NULL
, NULL
);
1428 if (select_result
== -1 && errno
== EINTR
)
1431 if (select_result
== -1) {
1432 BIO_printf(bio_err
, "Failure in the select\n");
1433 ERR_print_errors(bio_err
);
1438 if (select_result
== 0)
1442 for (i
= 0; i
< async_jobs
; i
++) {
1443 if (loopargs
[i
].inprogress_job
== NULL
)
1446 if (!ASYNC_WAIT_CTX_get_all_fds
1447 (loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1448 || num_job_fds
> 1) {
1449 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1450 ERR_print_errors(bio_err
);
1454 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
,
1457 #if defined(OPENSSL_SYS_UNIX)
1458 if (num_job_fds
== 1 && !FD_ISSET(job_fd
, &waitfdset
))
1460 #elif defined(OPENSSL_SYS_WINDOWS)
1461 if (num_job_fds
== 1
1462 && !PeekNamedPipe(job_fd
, NULL
, 0, NULL
, &avail
, NULL
)
1467 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
,
1468 loopargs
[i
].wait_ctx
, &job_op_count
,
1469 loop_function
, (void *)(loopargs
+ i
),
1470 sizeof(loopargs_t
));
1475 if (job_op_count
== -1) {
1478 total_op_count
+= job_op_count
;
1481 loopargs
[i
].inprogress_job
= NULL
;
1486 loopargs
[i
].inprogress_job
= NULL
;
1487 BIO_printf(bio_err
, "Failure in the job\n");
1488 ERR_print_errors(bio_err
);
1495 return error
? -1 : total_op_count
;
1498 static EVP_MD
*obtain_md(const char *name
)
1502 /* Look through providers' digests */
1504 md
= EVP_MD_fetch(NULL
, name
, NULL
);
1511 return (EVP_MD
*)EVP_get_digestbyname(name
);
1514 static EVP_CIPHER
*obtain_cipher(const char *name
)
1516 EVP_CIPHER
*cipher
= NULL
;
1518 /* Look through providers' ciphers */
1520 cipher
= EVP_CIPHER_fetch(NULL
, name
, NULL
);
1522 if (cipher
!= NULL
) {
1527 return (EVP_CIPHER
*)EVP_get_cipherbyname(name
);
1530 #define stop_it(do_it, test_num)\
1531 memset(do_it + test_num, 0, OSSL_NELEM(do_it) - test_num);
1533 int speed_main(int argc
, char **argv
)
1536 loopargs_t
*loopargs
= NULL
;
1538 const char *engine_id
= NULL
;
1539 EVP_CIPHER
*evp_cipher
= NULL
;
1542 int async_init
= 0, multiblock
= 0, pr_header
= 0;
1543 uint8_t doit
[ALGOR_NUM
] = { 0 };
1544 int ret
= 1, misalign
= 0, lengths_single
= 0, aead
= 0;
1546 unsigned int size_num
= SIZE_NUM
;
1547 unsigned int i
, k
, loopargs_len
= 0, async_jobs
= 0;
1553 #if !defined(OPENSSL_NO_DEPRECATED_3_0) \
1554 || !defined(OPENSSL_NO_DSA) \
1555 || !defined(OPENSSL_NO_DH) \
1556 || !defined(OPENSSL_NO_EC)
1559 openssl_speed_sec_t seconds
= { SECONDS
, RSA_SECONDS
, DSA_SECONDS
,
1560 ECDSA_SECONDS
, ECDH_SECONDS
,
1561 EdDSA_SECONDS
, SM2_SECONDS
,
1564 /* What follows are the buffers and key material. */
1565 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1568 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1571 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1572 IDEA_KEY_SCHEDULE idea_ks
;
1574 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1575 SEED_KEY_SCHEDULE seed_ks
;
1577 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1580 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1583 #ifndef OPENSSL_NO_DEPRECATED_3_0
1584 static const unsigned char key16
[16] = {
1585 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1586 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1588 static const unsigned char key24
[24] = {
1589 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1590 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1591 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1593 static const unsigned char key32
[32] = {
1594 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1595 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1596 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1597 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1600 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1601 CAMELLIA_KEY camellia_ks
[3];
1603 #ifndef OPENSSL_NO_DEPRECATED_3_0
1604 static const struct {
1605 const unsigned char *data
;
1606 unsigned int length
;
1609 { test512
, sizeof(test512
), 512 },
1610 { test1024
, sizeof(test1024
), 1024 },
1611 { test2048
, sizeof(test2048
), 2048 },
1612 { test3072
, sizeof(test3072
), 3072 },
1613 { test4096
, sizeof(test4096
), 4092 },
1614 { test7680
, sizeof(test7680
), 7680 },
1615 { test15360
, sizeof(test15360
), 15360 }
1617 uint8_t rsa_doit
[RSA_NUM
] = { 0 };
1618 int primes
= RSA_DEFAULT_PRIME_NUM
;
1620 #ifndef OPENSSL_NO_DH
1621 typedef struct ffdh_params_st
{
1627 static const FFDH_PARAMS ffdh_params
[FFDH_NUM
] = {
1628 {"ffdh2048", NID_ffdhe2048
, 2048},
1629 {"ffdh3072", NID_ffdhe3072
, 3072},
1630 {"ffdh4096", NID_ffdhe4096
, 4096},
1631 {"ffdh6144", NID_ffdhe6144
, 6144},
1632 {"ffdh8192", NID_ffdhe8192
, 8192}
1634 uint8_t ffdh_doit
[FFDH_NUM
] = { 0 };
1636 #endif /* OPENSSL_NO_DH */
1637 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1638 static const unsigned int dsa_bits
[DSA_NUM
] = { 512, 1024, 2048 };
1639 uint8_t dsa_doit
[DSA_NUM
] = { 0 };
1641 #ifndef OPENSSL_NO_EC
1642 typedef struct ec_curve_st
{
1646 size_t sigsize
; /* only used for EdDSA curves */
1649 * We only test over the following curves as they are representative, To
1650 * add tests over more curves, simply add the curve NID and curve name to
1651 * the following arrays and increase the |ecdh_choices| and |ecdsa_choices|
1652 * lists accordingly.
1654 static const EC_CURVE ec_curves
[EC_NUM
] = {
1656 {"secp160r1", NID_secp160r1
, 160},
1657 {"nistp192", NID_X9_62_prime192v1
, 192},
1658 {"nistp224", NID_secp224r1
, 224},
1659 {"nistp256", NID_X9_62_prime256v1
, 256},
1660 {"nistp384", NID_secp384r1
, 384},
1661 {"nistp521", NID_secp521r1
, 521},
1662 # ifndef OPENSSL_NO_EC2M
1664 {"nistk163", NID_sect163k1
, 163},
1665 {"nistk233", NID_sect233k1
, 233},
1666 {"nistk283", NID_sect283k1
, 283},
1667 {"nistk409", NID_sect409k1
, 409},
1668 {"nistk571", NID_sect571k1
, 571},
1669 {"nistb163", NID_sect163r2
, 163},
1670 {"nistb233", NID_sect233r1
, 233},
1671 {"nistb283", NID_sect283r1
, 283},
1672 {"nistb409", NID_sect409r1
, 409},
1673 {"nistb571", NID_sect571r1
, 571},
1675 {"brainpoolP256r1", NID_brainpoolP256r1
, 256},
1676 {"brainpoolP256t1", NID_brainpoolP256t1
, 256},
1677 {"brainpoolP384r1", NID_brainpoolP384r1
, 384},
1678 {"brainpoolP384t1", NID_brainpoolP384t1
, 384},
1679 {"brainpoolP512r1", NID_brainpoolP512r1
, 512},
1680 {"brainpoolP512t1", NID_brainpoolP512t1
, 512},
1681 /* Other and ECDH only ones */
1682 {"X25519", NID_X25519
, 253},
1683 {"X448", NID_X448
, 448}
1685 static const EC_CURVE ed_curves
[EdDSA_NUM
] = {
1687 {"Ed25519", NID_ED25519
, 253, 64},
1688 {"Ed448", NID_ED448
, 456, 114}
1690 # ifndef OPENSSL_NO_SM2
1691 static const EC_CURVE sm2_curves
[SM2_NUM
] = {
1693 {"CurveSM2", NID_sm2
, 256}
1695 uint8_t sm2_doit
[SM2_NUM
] = { 0 };
1697 uint8_t ecdsa_doit
[ECDSA_NUM
] = { 0 };
1698 uint8_t ecdh_doit
[EC_NUM
] = { 0 };
1699 uint8_t eddsa_doit
[EdDSA_NUM
] = { 0 };
1701 /* checks declarated curves against choices list. */
1702 OPENSSL_assert(ed_curves
[EdDSA_NUM
- 1].nid
== NID_ED448
);
1703 OPENSSL_assert(strcmp(eddsa_choices
[EdDSA_NUM
- 1].name
, "ed448") == 0);
1705 OPENSSL_assert(ec_curves
[EC_NUM
- 1].nid
== NID_X448
);
1706 OPENSSL_assert(strcmp(ecdh_choices
[EC_NUM
- 1].name
, "ecdhx448") == 0);
1708 OPENSSL_assert(ec_curves
[ECDSA_NUM
- 1].nid
== NID_brainpoolP512t1
);
1709 OPENSSL_assert(strcmp(ecdsa_choices
[ECDSA_NUM
- 1].name
, "ecdsabrp512t1") == 0);
1711 # ifndef OPENSSL_NO_SM2
1712 OPENSSL_assert(sm2_curves
[SM2_NUM
- 1].nid
== NID_sm2
);
1713 OPENSSL_assert(strcmp(sm2_choices
[SM2_NUM
- 1].name
, "curveSM2") == 0);
1715 #endif /* ndef OPENSSL_NO_EC */
1717 prog
= opt_init(argc
, argv
, speed_options
);
1718 while ((o
= opt_next()) != OPT_EOF
) {
1723 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
1726 opt_help(speed_options
);
1734 BIO_printf(bio_err
, "%s: -evp option cannot be used more than once\n", prog
);
1738 evp_cipher
= obtain_cipher(opt_arg());
1739 if (evp_cipher
== NULL
)
1740 evp_md
= obtain_md(opt_arg());
1741 if (evp_cipher
== NULL
&& evp_md
== NULL
) {
1743 "%s: %s is an unknown cipher or digest\n",
1750 #ifndef OPENSSL_NO_DEPRECATED_3_0
1751 evp_hmac_md
= EVP_get_digestbyname(opt_arg());
1752 if (evp_hmac_md
== NULL
) {
1753 BIO_printf(bio_err
, "%s: %s is an unknown digest\n",
1757 doit
[D_EVP_HMAC
] = 1;
1761 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1762 evp_cmac_cipher
= EVP_get_cipherbyname(opt_arg());
1763 if (evp_cmac_cipher
== NULL
) {
1764 BIO_printf(bio_err
, "%s: %s is an unknown cipher\n",
1768 doit
[D_EVP_CMAC
] = 1;
1776 * In a forked execution, an engine might need to be
1777 * initialised by each child process, not by the parent.
1778 * So store the name here and run setup_engine() later on.
1780 engine_id
= opt_arg();
1784 multi
= atoi(opt_arg());
1788 #ifndef OPENSSL_NO_ASYNC
1789 async_jobs
= atoi(opt_arg());
1790 if (!ASYNC_is_capable()) {
1792 "%s: async_jobs specified but async not supported\n",
1796 if (async_jobs
> 99999) {
1797 BIO_printf(bio_err
, "%s: too many async_jobs\n", prog
);
1803 if (!opt_int(opt_arg(), &misalign
))
1805 if (misalign
> MISALIGN
) {
1807 "%s: Maximum offset is %d\n", prog
, MISALIGN
);
1816 #ifdef OPENSSL_NO_MULTIBLOCK
1818 "%s: -mb specified but multi-block support is disabled\n",
1827 case OPT_PROV_CASES
:
1828 if (!opt_provider(o
))
1832 #ifndef OPENSSL_NO_DEPRECATED_3_0
1833 if (!opt_int(opt_arg(), &primes
))
1838 seconds
.sym
= seconds
.rsa
= seconds
.dsa
= seconds
.ecdsa
1839 = seconds
.ecdh
= seconds
.eddsa
1840 = seconds
.sm2
= seconds
.ffdh
= atoi(opt_arg());
1843 lengths_single
= atoi(opt_arg());
1844 lengths
= &lengths_single
;
1853 /* Remaining arguments are algorithms. */
1854 argc
= opt_num_rest();
1857 for (; *argv
; argv
++) {
1858 const char *algo
= *argv
;
1860 if (opt_found(algo
, doit_choices
, &i
)) {
1864 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1865 if (strcmp(algo
, "des") == 0) {
1866 doit
[D_CBC_DES
] = doit
[D_EDE3_DES
] = 1;
1870 if (strcmp(algo
, "sha") == 0) {
1871 doit
[D_SHA1
] = doit
[D_SHA256
] = doit
[D_SHA512
] = 1;
1874 #ifndef OPENSSL_NO_DEPRECATED_3_0
1875 if (strcmp(algo
, "openssl") == 0) /* just for compatibility */
1877 if (strncmp(algo
, "rsa", 3) == 0) {
1878 if (algo
[3] == '\0') {
1879 memset(rsa_doit
, 1, sizeof(rsa_doit
));
1882 if (opt_found(algo
, rsa_choices
, &i
)) {
1888 #ifndef OPENSSL_NO_DH
1889 if (strncmp(algo
, "ffdh", 4) == 0) {
1890 if (algo
[4] == '\0') {
1891 memset(ffdh_doit
, 1, sizeof(ffdh_doit
));
1894 if (opt_found(algo
, ffdh_choices
, &i
)) {
1900 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1901 if (strncmp(algo
, "dsa", 3) == 0) {
1902 if (algo
[3] == '\0') {
1903 memset(dsa_doit
, 1, sizeof(dsa_doit
));
1906 if (opt_found(algo
, dsa_choices
, &i
)) {
1912 #ifndef OPENSSL_NO_DEPRECATED_3_0
1913 if (strcmp(algo
, "aes") == 0) {
1914 doit
[D_CBC_128_AES
] = doit
[D_CBC_192_AES
] = doit
[D_CBC_256_AES
] = 1;
1918 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1919 if (strcmp(algo
, "camellia") == 0) {
1920 doit
[D_CBC_128_CML
] = doit
[D_CBC_192_CML
] = doit
[D_CBC_256_CML
] = 1;
1924 #ifndef OPENSSL_NO_EC
1925 if (strncmp(algo
, "ecdsa", 5) == 0) {
1926 if (algo
[5] == '\0') {
1927 memset(ecdsa_doit
, 1, sizeof(ecdsa_doit
));
1930 if (opt_found(algo
, ecdsa_choices
, &i
)) {
1935 if (strncmp(algo
, "ecdh", 4) == 0) {
1936 if (algo
[4] == '\0') {
1937 memset(ecdh_doit
, 1, sizeof(ecdh_doit
));
1940 if (opt_found(algo
, ecdh_choices
, &i
)) {
1945 if (strcmp(algo
, "eddsa") == 0) {
1946 memset(eddsa_doit
, 1, sizeof(eddsa_doit
));
1949 if (opt_found(algo
, eddsa_choices
, &i
)) {
1953 # ifndef OPENSSL_NO_SM2
1954 if (strcmp(algo
, "sm2") == 0) {
1955 memset(sm2_doit
, 1, sizeof(sm2_doit
));
1958 if (opt_found(algo
, sm2_choices
, &i
)) {
1963 #endif /* OPENSSL_NO_EC */
1964 BIO_printf(bio_err
, "%s: Unknown algorithm %s\n", prog
, algo
);
1970 if (evp_cipher
== NULL
) {
1971 BIO_printf(bio_err
, "-aead can be used only with an AEAD cipher\n");
1973 } else if (!(EVP_CIPHER_flags(evp_cipher
) &
1974 EVP_CIPH_FLAG_AEAD_CIPHER
)) {
1975 BIO_printf(bio_err
, "%s is not an AEAD cipher\n",
1976 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
)));
1981 if (evp_cipher
== NULL
) {
1982 BIO_printf(bio_err
,"-mb can be used only with a multi-block"
1983 " capable cipher\n");
1985 } else if (!(EVP_CIPHER_flags(evp_cipher
) &
1986 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
)) {
1987 BIO_printf(bio_err
, "%s is not a multi-block capable\n",
1988 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
)));
1990 } else if (async_jobs
> 0) {
1991 BIO_printf(bio_err
, "Async mode is not supported with -mb");
1996 /* Initialize the job pool if async mode is enabled */
1997 if (async_jobs
> 0) {
1998 async_init
= ASYNC_init_thread(async_jobs
, async_jobs
);
2000 BIO_printf(bio_err
, "Error creating the ASYNC job pool\n");
2005 loopargs_len
= (async_jobs
== 0 ? 1 : async_jobs
);
2007 app_malloc(loopargs_len
* sizeof(loopargs_t
), "array of loopargs");
2008 memset(loopargs
, 0, loopargs_len
* sizeof(loopargs_t
));
2010 for (i
= 0; i
< loopargs_len
; i
++) {
2011 if (async_jobs
> 0) {
2012 loopargs
[i
].wait_ctx
= ASYNC_WAIT_CTX_new();
2013 if (loopargs
[i
].wait_ctx
== NULL
) {
2014 BIO_printf(bio_err
, "Error creating the ASYNC_WAIT_CTX\n");
2019 buflen
= lengths
[size_num
- 1];
2020 if (buflen
< 36) /* size of random vector in RSA benchmark */
2022 buflen
+= MAX_MISALIGNMENT
+ 1;
2023 loopargs
[i
].buf_malloc
= app_malloc(buflen
, "input buffer");
2024 loopargs
[i
].buf2_malloc
= app_malloc(buflen
, "input buffer");
2025 memset(loopargs
[i
].buf_malloc
, 0, buflen
);
2026 memset(loopargs
[i
].buf2_malloc
, 0, buflen
);
2028 /* Align the start of buffers on a 64 byte boundary */
2029 loopargs
[i
].buf
= loopargs
[i
].buf_malloc
+ misalign
;
2030 loopargs
[i
].buf2
= loopargs
[i
].buf2_malloc
+ misalign
;
2031 #ifndef OPENSSL_NO_EC
2032 loopargs
[i
].secret_a
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret a");
2033 loopargs
[i
].secret_b
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret b");
2035 #ifndef OPENSSL_NO_DH
2036 loopargs
[i
].secret_ff_a
= app_malloc(MAX_FFDH_SIZE
, "FFDH secret a");
2037 loopargs
[i
].secret_ff_b
= app_malloc(MAX_FFDH_SIZE
, "FFDH secret b");
2042 if (multi
&& do_multi(multi
, size_num
))
2046 /* Initialize the engine after the fork */
2047 e
= setup_engine(engine_id
, 0);
2049 /* No parameters; turn on everything. */
2050 if (argc
== 0 && !doit
[D_EVP
] && !doit
[D_EVP_HMAC
] && !doit
[D_EVP_CMAC
]) {
2051 memset(doit
, 1, sizeof(doit
));
2052 doit
[D_EVP
] = doit
[D_EVP_HMAC
] = doit
[D_EVP_CMAC
] = 0;
2053 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2056 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2059 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2062 #ifndef OPENSSL_NO_DEPRECATED_3_0
2063 memset(rsa_doit
, 1, sizeof(rsa_doit
));
2065 #ifndef OPENSSL_NO_DH
2066 memset(ffdh_doit
, 1, sizeof(ffdh_doit
));
2068 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2069 memset(dsa_doit
, 1, sizeof(dsa_doit
));
2071 #ifndef OPENSSL_NO_EC
2072 memset(ecdsa_doit
, 1, sizeof(ecdsa_doit
));
2073 memset(ecdh_doit
, 1, sizeof(ecdh_doit
));
2074 memset(eddsa_doit
, 1, sizeof(eddsa_doit
));
2075 # ifndef OPENSSL_NO_SM2
2076 memset(sm2_doit
, 1, sizeof(sm2_doit
));
2080 for (i
= 0; i
< ALGOR_NUM
; i
++)
2084 if (usertime
== 0 && !mr
)
2086 "You have chosen to measure elapsed time "
2087 "instead of user CPU time.\n");
2089 #ifndef OPENSSL_NO_DEPRECATED_3_0
2090 for (i
= 0; i
< loopargs_len
; i
++) {
2091 if (primes
> RSA_DEFAULT_PRIME_NUM
) {
2092 /* for multi-prime RSA, skip this */
2095 for (k
= 0; k
< RSA_NUM
; k
++) {
2096 const unsigned char *p
= rsa_keys
[k
].data
;
2098 loopargs
[i
].rsa_key
[k
] =
2099 d2i_RSAPrivateKey(NULL
, &p
, rsa_keys
[k
].length
);
2100 if (loopargs
[i
].rsa_key
[k
] == NULL
) {
2102 "internal error loading RSA key number %d\n", k
);
2108 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2109 for (i
= 0; i
< loopargs_len
; i
++) {
2110 loopargs
[i
].dsa_key
[0] = get_dsa(512);
2111 loopargs
[i
].dsa_key
[1] = get_dsa(1024);
2112 loopargs
[i
].dsa_key
[2] = get_dsa(2048);
2115 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2116 if (doit
[D_CBC_DES
] || doit
[D_EDE3_DES
]) {
2117 static DES_cblock keys
[] = {
2118 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }, /* keys[0] */
2119 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }, /* keys[1] */
2120 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 } /* keys[3] */
2122 DES_set_key_unchecked(&keys
[0], &sch
[0]);
2123 DES_set_key_unchecked(&keys
[1], &sch
[1]);
2124 DES_set_key_unchecked(&keys
[2], &sch
[2]);
2127 #ifndef OPENSSL_NO_DEPRECATED_3_0
2128 AES_set_encrypt_key(key16
, 128, &aes_ks1
);
2129 AES_set_encrypt_key(key24
, 192, &aes_ks2
);
2130 AES_set_encrypt_key(key32
, 256, &aes_ks3
);
2132 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2133 if (doit
[D_CBC_128_CML
] || doit
[D_CBC_192_CML
] || doit
[D_CBC_256_CML
]) {
2134 Camellia_set_key(key16
, 128, &camellia_ks
[0]);
2135 Camellia_set_key(key24
, 192, &camellia_ks
[1]);
2136 Camellia_set_key(key32
, 256, &camellia_ks
[2]);
2139 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2140 if (doit
[D_CBC_IDEA
])
2141 IDEA_set_encrypt_key(key16
, &idea_ks
);
2143 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2144 if (doit
[D_CBC_SEED
])
2145 SEED_set_key(key16
, &seed_ks
);
2147 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2149 RC4_set_key(&rc4_ks
, 16, key16
);
2151 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2152 if (doit
[D_CBC_RC2
])
2153 RC2_set_key(&rc2_ks
, 16, key16
, 128);
2155 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2156 if (doit
[D_CBC_RC5
])
2157 if (!RC5_32_set_key(&rc5_ks
, 16, key16
, 12)) {
2158 BIO_printf(bio_err
, "Failed setting RC5 key\n");
2162 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2164 BF_set_key(&bf_ks
, 16, key16
);
2166 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2167 if (doit
[D_CBC_CAST
])
2168 CAST_set_key(&cast_ks
, 16, key16
);
2171 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2172 BIO_printf(bio_err
, "First we calculate the approximate speed ...\n");
2178 for (it
= count
; it
; it
--)
2179 DES_ecb_encrypt((DES_cblock
*)loopargs
[0].buf
,
2180 (DES_cblock
*)loopargs
[0].buf
, &sch
, DES_ENCRYPT
);
2183 c
[D_MD2
][0] = count
/ 10;
2184 c
[D_MDC2
][0] = count
/ 10;
2185 c
[D_MD4
][0] = count
;
2186 c
[D_MD5
][0] = count
;
2187 c
[D_HMAC
][0] = count
;
2188 c
[D_SHA1
][0] = count
;
2189 c
[D_RMD160
][0] = count
;
2190 c
[D_RC4
][0] = count
* 5;
2191 c
[D_CBC_DES
][0] = count
;
2192 c
[D_EDE3_DES
][0] = count
/ 3;
2193 c
[D_CBC_IDEA
][0] = count
;
2194 c
[D_CBC_SEED
][0] = count
;
2195 c
[D_CBC_RC2
][0] = count
;
2196 c
[D_CBC_RC5
][0] = count
;
2197 c
[D_CBC_BF
][0] = count
;
2198 c
[D_CBC_CAST
][0] = count
;
2199 c
[D_CBC_128_AES
][0] = count
;
2200 c
[D_CBC_192_AES
][0] = count
;
2201 c
[D_CBC_256_AES
][0] = count
;
2202 c
[D_CBC_128_CML
][0] = count
;
2203 c
[D_CBC_192_CML
][0] = count
;
2204 c
[D_CBC_256_CML
][0] = count
;
2205 c
[D_EVP
][0] = count
;
2206 c
[D_SHA256
][0] = count
;
2207 c
[D_SHA512
][0] = count
;
2208 c
[D_WHIRLPOOL
][0] = count
;
2209 c
[D_IGE_128_AES
][0] = count
;
2210 c
[D_IGE_192_AES
][0] = count
;
2211 c
[D_IGE_256_AES
][0] = count
;
2212 c
[D_GHASH
][0] = count
;
2213 c
[D_RAND
][0] = count
;
2214 c
[D_EVP_HMAC
][0] = count
;
2215 c
[D_EVP_CMAC
][0] = count
;
2217 for (i
= 1; i
< size_num
; i
++) {
2218 long l0
= (long)lengths
[0];
2219 long l1
= (long)lengths
[i
];
2221 c
[D_MD2
][i
] = c
[D_MD2
][0] * 4 * l0
/ l1
;
2222 c
[D_MDC2
][i
] = c
[D_MDC2
][0] * 4 * l0
/ l1
;
2223 c
[D_MD4
][i
] = c
[D_MD4
][0] * 4 * l0
/ l1
;
2224 c
[D_MD5
][i
] = c
[D_MD5
][0] * 4 * l0
/ l1
;
2225 c
[D_HMAC
][i
] = c
[D_HMAC
][0] * 4 * l0
/ l1
;
2226 c
[D_SHA1
][i
] = c
[D_SHA1
][0] * 4 * l0
/ l1
;
2227 c
[D_RMD160
][i
] = c
[D_RMD160
][0] * 4 * l0
/ l1
;
2228 c
[D_EVP
][i
] = = c
[D_EVP
][0] * 4 * l0
/ l1
;
2229 c
[D_SHA256
][i
] = c
[D_SHA256
][0] * 4 * l0
/ l1
;
2230 c
[D_SHA512
][i
] = c
[D_SHA512
][0] * 4 * l0
/ l1
;
2231 c
[D_WHIRLPOOL
][i
] = c
[D_WHIRLPOOL
][0] * 4 * l0
/ l1
;
2232 c
[D_GHASH
][i
] = c
[D_GHASH
][0] * 4 * l0
/ l1
;
2233 c
[D_RAND
][i
] = c
[D_RAND
][0] * 4 * l0
/ l1
;
2234 c
[D_EVP_HMAC
][i
] = = c
[D_EVP_HMAC
][0] * 4 * l0
/ l1
;
2235 c
[D_EVP_CMAC
][i
] = = c
[D_EVP_CMAC
][0] * 4 * l0
/ l1
;
2237 l0
= (long)lengths
[i
- 1];
2239 c
[D_RC4
][i
] = c
[D_RC4
][i
- 1] * l0
/ l1
;
2240 c
[D_CBC_DES
][i
] = c
[D_CBC_DES
][i
- 1] * l0
/ l1
;
2241 c
[D_EDE3_DES
][i
] = c
[D_EDE3_DES
][i
- 1] * l0
/ l1
;
2242 c
[D_CBC_IDEA
][i
] = c
[D_CBC_IDEA
][i
- 1] * l0
/ l1
;
2243 c
[D_CBC_SEED
][i
] = c
[D_CBC_SEED
][i
- 1] * l0
/ l1
;
2244 c
[D_CBC_RC2
][i
] = c
[D_CBC_RC2
][i
- 1] * l0
/ l1
;
2245 c
[D_CBC_RC5
][i
] = c
[D_CBC_RC5
][i
- 1] * l0
/ l1
;
2246 c
[D_CBC_BF
][i
] = c
[D_CBC_BF
][i
- 1] * l0
/ l1
;
2247 c
[D_CBC_CAST
][i
] = c
[D_CBC_CAST
][i
- 1] * l0
/ l1
;
2248 c
[D_CBC_128_AES
][i
] = c
[D_CBC_128_AES
][i
- 1] * l0
/ l1
;
2249 c
[D_CBC_192_AES
][i
] = c
[D_CBC_192_AES
][i
- 1] * l0
/ l1
;
2250 c
[D_CBC_256_AES
][i
] = c
[D_CBC_256_AES
][i
- 1] * l0
/ l1
;
2251 c
[D_CBC_128_CML
][i
] = c
[D_CBC_128_CML
][i
- 1] * l0
/ l1
;
2252 c
[D_CBC_192_CML
][i
] = c
[D_CBC_192_CML
][i
- 1] * l0
/ l1
;
2253 c
[D_CBC_256_CML
][i
] = c
[D_CBC_256_CML
][i
- 1] * l0
/ l1
;
2254 c
[D_IGE_128_AES
][i
] = c
[D_IGE_128_AES
][i
- 1] * l0
/ l1
;
2255 c
[D_IGE_192_AES
][i
] = c
[D_IGE_192_AES
][i
- 1] * l0
/ l1
;
2256 c
[D_IGE_256_AES
][i
] = c
[D_IGE_256_AES
][i
- 1] * l0
/ l1
;
2259 # ifndef OPENSSL_NO_DEPRECATED_3_0
2260 rsa_c
[R_RSA_512
][0] = count
/ 2000;
2261 rsa_c
[R_RSA_512
][1] = count
/ 400;
2262 for (i
= 1; i
< RSA_NUM
; i
++) {
2263 rsa_c
[i
][0] = rsa_c
[i
- 1][0] / 8;
2264 rsa_c
[i
][1] = rsa_c
[i
- 1][1] / 4;
2265 if (rsa_doit
[i
] <= 1 && rsa_c
[i
][0] == 0)
2268 if (rsa_c
[i
][0] == 0) {
2269 rsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
2276 # if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2277 dsa_c
[R_DSA_512
][0] = count
/ 1000;
2278 dsa_c
[R_DSA_512
][1] = count
/ 1000 / 2;
2279 for (i
= 1; i
< DSA_NUM
; i
++) {
2280 dsa_c
[i
][0] = dsa_c
[i
- 1][0] / 4;
2281 dsa_c
[i
][1] = dsa_c
[i
- 1][1] / 4;
2282 if (dsa_doit
[i
] <= 1 && dsa_c
[i
][0] == 0)
2285 if (dsa_c
[i
][0] == 0) {
2286 dsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
2293 # ifndef OPENSSL_NO_EC
2294 ecdsa_c
[R_EC_P160
][0] = count
/ 1000;
2295 ecdsa_c
[R_EC_P160
][1] = count
/ 1000 / 2;
2296 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
2297 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
2298 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
2299 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
2302 if (ecdsa_c
[i
][0] == 0) {
2308 # ifndef OPENSSL_NO_EC2M
2309 ecdsa_c
[R_EC_K163
][0] = count
/ 1000;
2310 ecdsa_c
[R_EC_K163
][1] = count
/ 1000 / 2;
2311 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
2312 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
2313 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
2314 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
2317 if (ecdsa_c
[i
][0] == 0) {
2323 ecdsa_c
[R_EC_B163
][0] = count
/ 1000;
2324 ecdsa_c
[R_EC_B163
][1] = count
/ 1000 / 2;
2325 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
2326 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
2327 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
2328 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
2331 if (ecdsa_c
[i
][0] == 0) {
2339 ecdh_c
[R_EC_P160
][0] = count
/ 1000;
2340 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
2341 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
2342 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2345 if (ecdh_c
[i
][0] == 0) {
2350 # ifndef OPENSSL_NO_EC2M
2351 ecdh_c
[R_EC_K163
][0] = count
/ 1000;
2352 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
2353 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
2354 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2357 if (ecdh_c
[i
][0] == 0) {
2362 ecdh_c
[R_EC_B163
][0] = count
/ 1000;
2363 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
2364 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
2365 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2368 if (ecdh_c
[i
][0] == 0) {
2374 /* repeated code good to factorize */
2375 ecdh_c
[R_EC_BRP256R1
][0] = count
/ 1000;
2376 for (i
= R_EC_BRP384R1
; i
<= R_EC_BRP512R1
; i
+= 2) {
2377 ecdh_c
[i
][0] = ecdh_c
[i
- 2][0] / 2;
2378 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2381 if (ecdh_c
[i
][0] == 0) {
2386 ecdh_c
[R_EC_BRP256T1
][0] = count
/ 1000;
2387 for (i
= R_EC_BRP384T1
; i
<= R_EC_BRP512T1
; i
+= 2) {
2388 ecdh_c
[i
][0] = ecdh_c
[i
- 2][0] / 2;
2389 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2392 if (ecdh_c
[i
][0] == 0) {
2397 /* default iteration count for the last two EC Curves */
2398 ecdh_c
[R_EC_X25519
][0] = count
/ 1800;
2399 ecdh_c
[R_EC_X448
][0] = count
/ 7200;
2401 eddsa_c
[R_EC_Ed25519
][0] = count
/ 1800;
2402 eddsa_c
[R_EC_Ed448
][0] = count
/ 7200;
2404 # ifndef OPENSSL_NO_SM2
2405 sm2_c
[R_EC_SM2P256
][0] = count
/ 1800;
2407 # endif /* OPENSSL_NO_EC */
2409 # ifndef OPENSSL_NO_DH
2410 ffdh_c
[R_FFDH_2048
][0] = count
/ 1000;
2411 for (i
= R_FFDH_3072
; i
<= R_FFDH_8192
; i
++) {
2412 ffdh_c
[i
][0] = ffdh_c
[i
- 1][0] / 2;
2413 if (ffdh_doit
[i
] <= 1 && ffdh_c
[i
][0] == 0) {
2416 if (ffdh_c
[i
][0] == 0)
2420 # endif /* OPENSSL_NO_DH */
2423 /* not worth fixing */
2424 # error "You cannot disable DES on systems without SIGALRM."
2425 # endif /* OPENSSL_NO_DES */
2427 signal(SIGALRM
, alarmed
);
2428 #endif /* SIGALRM */
2430 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2432 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2433 print_message(names
[D_MD2
], c
[D_MD2
][testnum
], lengths
[testnum
],
2436 count
= run_benchmark(async_jobs
, EVP_Digest_MD2_loop
, loopargs
);
2438 print_result(D_MD2
, testnum
, count
, d
);
2442 #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2444 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2445 print_message(names
[D_MDC2
], c
[D_MDC2
][testnum
], lengths
[testnum
],
2448 count
= run_benchmark(async_jobs
, EVP_Digest_MDC2_loop
, loopargs
);
2450 print_result(D_MDC2
, testnum
, count
, d
);
2457 #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2459 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2460 print_message(names
[D_MD4
], c
[D_MD4
][testnum
], lengths
[testnum
],
2463 count
= run_benchmark(async_jobs
, EVP_Digest_MD4_loop
, loopargs
);
2465 print_result(D_MD4
, testnum
, count
, d
);
2472 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2474 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2475 print_message(names
[D_MD5
], c
[D_MD5
][testnum
], lengths
[testnum
],
2478 count
= run_benchmark(async_jobs
, MD5_loop
, loopargs
);
2480 print_result(D_MD5
, testnum
, count
, d
);
2484 # ifndef OPENSSL_NO_DEPRECATED_3_0
2486 static const char hmac_key
[] = "This is a key...";
2487 int len
= strlen(hmac_key
);
2489 for (i
= 0; i
< loopargs_len
; i
++) {
2490 loopargs
[i
].hctx
= HMAC_CTX_new();
2491 if (loopargs
[i
].hctx
== NULL
) {
2492 BIO_printf(bio_err
, "HMAC malloc failure, exiting...");
2496 HMAC_Init_ex(loopargs
[i
].hctx
, hmac_key
, len
, EVP_md5(), NULL
);
2498 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2499 print_message(names
[D_HMAC
], c
[D_HMAC
][testnum
], lengths
[testnum
],
2502 count
= run_benchmark(async_jobs
, HMAC_loop
, loopargs
);
2504 print_result(D_HMAC
, testnum
, count
, d
);
2506 for (i
= 0; i
< loopargs_len
; i
++)
2507 HMAC_CTX_free(loopargs
[i
].hctx
);
2511 #ifndef OPENSSL_NO_DEPRECATED_3_0
2513 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2514 print_message(names
[D_SHA1
], c
[D_SHA1
][testnum
], lengths
[testnum
],
2517 count
= run_benchmark(async_jobs
, SHA1_loop
, loopargs
);
2519 print_result(D_SHA1
, testnum
, count
, d
);
2522 if (doit
[D_SHA256
]) {
2523 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2524 print_message(names
[D_SHA256
], c
[D_SHA256
][testnum
],
2525 lengths
[testnum
], seconds
.sym
);
2527 count
= run_benchmark(async_jobs
, SHA256_loop
, loopargs
);
2529 print_result(D_SHA256
, testnum
, count
, d
);
2532 if (doit
[D_SHA512
]) {
2533 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2534 print_message(names
[D_SHA512
], c
[D_SHA512
][testnum
],
2535 lengths
[testnum
], seconds
.sym
);
2537 count
= run_benchmark(async_jobs
, SHA512_loop
, loopargs
);
2539 print_result(D_SHA512
, testnum
, count
, d
);
2543 #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2544 if (doit
[D_WHIRLPOOL
]) {
2545 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2546 print_message(names
[D_WHIRLPOOL
], c
[D_WHIRLPOOL
][testnum
],
2547 lengths
[testnum
], seconds
.sym
);
2549 count
= run_benchmark(async_jobs
, WHIRLPOOL_loop
, loopargs
);
2551 print_result(D_WHIRLPOOL
, testnum
, count
, d
);
2556 #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2557 if (doit
[D_RMD160
]) {
2558 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2559 print_message(names
[D_RMD160
], c
[D_RMD160
][testnum
],
2560 lengths
[testnum
], seconds
.sym
);
2562 count
= run_benchmark(async_jobs
, EVP_Digest_RMD160_loop
, loopargs
);
2564 print_result(D_RMD160
, testnum
, count
, d
);
2570 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2572 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2573 print_message(names
[D_RC4
], c
[D_RC4
][testnum
], lengths
[testnum
],
2576 count
= run_benchmark(async_jobs
, RC4_loop
, loopargs
);
2578 print_result(D_RC4
, testnum
, count
, d
);
2582 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2583 if (doit
[D_CBC_DES
]) {
2584 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2585 print_message(names
[D_CBC_DES
], c
[D_CBC_DES
][testnum
],
2586 lengths
[testnum
], seconds
.sym
);
2588 count
= run_benchmark(async_jobs
, DES_ncbc_encrypt_loop
, loopargs
);
2590 print_result(D_CBC_DES
, testnum
, count
, d
);
2594 if (doit
[D_EDE3_DES
]) {
2595 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2596 print_message(names
[D_EDE3_DES
], c
[D_EDE3_DES
][testnum
],
2597 lengths
[testnum
], seconds
.sym
);
2600 run_benchmark(async_jobs
, DES_ede3_cbc_encrypt_loop
, loopargs
);
2602 print_result(D_EDE3_DES
, testnum
, count
, d
);
2607 #ifndef OPENSSL_NO_DEPRECATED_3_0
2608 if (doit
[D_CBC_128_AES
]) {
2609 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2610 print_message(names
[D_CBC_128_AES
], c
[D_CBC_128_AES
][testnum
],
2611 lengths
[testnum
], seconds
.sym
);
2614 run_benchmark(async_jobs
, AES_cbc_128_encrypt_loop
, loopargs
);
2616 print_result(D_CBC_128_AES
, testnum
, count
, d
);
2619 if (doit
[D_CBC_192_AES
]) {
2620 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2621 print_message(names
[D_CBC_192_AES
], c
[D_CBC_192_AES
][testnum
],
2622 lengths
[testnum
], seconds
.sym
);
2625 run_benchmark(async_jobs
, AES_cbc_192_encrypt_loop
, loopargs
);
2627 print_result(D_CBC_192_AES
, testnum
, count
, d
);
2630 if (doit
[D_CBC_256_AES
]) {
2631 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2632 print_message(names
[D_CBC_256_AES
], c
[D_CBC_256_AES
][testnum
],
2633 lengths
[testnum
], seconds
.sym
);
2636 run_benchmark(async_jobs
, AES_cbc_256_encrypt_loop
, loopargs
);
2638 print_result(D_CBC_256_AES
, testnum
, count
, d
);
2643 if (doit
[D_IGE_128_AES
]) {
2644 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2645 print_message(names
[D_IGE_128_AES
], c
[D_IGE_128_AES
][testnum
],
2646 lengths
[testnum
], seconds
.sym
);
2649 run_benchmark(async_jobs
, AES_ige_128_encrypt_loop
, loopargs
);
2651 print_result(D_IGE_128_AES
, testnum
, count
, d
);
2654 if (doit
[D_IGE_192_AES
]) {
2655 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2656 print_message(names
[D_IGE_192_AES
], c
[D_IGE_192_AES
][testnum
],
2657 lengths
[testnum
], seconds
.sym
);
2660 run_benchmark(async_jobs
, AES_ige_192_encrypt_loop
, loopargs
);
2662 print_result(D_IGE_192_AES
, testnum
, count
, d
);
2665 if (doit
[D_IGE_256_AES
]) {
2666 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2667 print_message(names
[D_IGE_256_AES
], c
[D_IGE_256_AES
][testnum
],
2668 lengths
[testnum
], seconds
.sym
);
2671 run_benchmark(async_jobs
, AES_ige_256_encrypt_loop
, loopargs
);
2673 print_result(D_IGE_256_AES
, testnum
, count
, d
);
2676 if (doit
[D_GHASH
]) {
2677 for (i
= 0; i
< loopargs_len
; i
++) {
2678 loopargs
[i
].gcm_ctx
=
2679 CRYPTO_gcm128_new(&aes_ks1
, (block128_f
) AES_encrypt
);
2680 CRYPTO_gcm128_setiv(loopargs
[i
].gcm_ctx
,
2681 (unsigned char *)"0123456789ab", 12);
2684 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2685 print_message(names
[D_GHASH
], c
[D_GHASH
][testnum
],
2686 lengths
[testnum
], seconds
.sym
);
2688 count
= run_benchmark(async_jobs
, CRYPTO_gcm128_aad_loop
, loopargs
);
2690 print_result(D_GHASH
, testnum
, count
, d
);
2692 for (i
= 0; i
< loopargs_len
; i
++)
2693 CRYPTO_gcm128_release(loopargs
[i
].gcm_ctx
);
2695 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
2696 #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2697 if (doit
[D_CBC_128_CML
]) {
2698 if (async_jobs
> 0) {
2699 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2700 names
[D_CBC_128_CML
]);
2701 doit
[D_CBC_128_CML
] = 0;
2703 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2704 print_message(names
[D_CBC_128_CML
], c
[D_CBC_128_CML
][testnum
],
2705 lengths
[testnum
], seconds
.sym
);
2707 for (count
= 0; COND(c
[D_CBC_128_CML
][testnum
]); count
++)
2708 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2709 (size_t)lengths
[testnum
], &camellia_ks
[0],
2710 iv
, CAMELLIA_ENCRYPT
);
2712 print_result(D_CBC_128_CML
, testnum
, count
, d
);
2715 if (doit
[D_CBC_192_CML
]) {
2716 if (async_jobs
> 0) {
2717 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2718 names
[D_CBC_192_CML
]);
2719 doit
[D_CBC_192_CML
] = 0;
2721 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2722 print_message(names
[D_CBC_192_CML
], c
[D_CBC_192_CML
][testnum
],
2723 lengths
[testnum
], seconds
.sym
);
2724 if (async_jobs
> 0) {
2725 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2729 for (count
= 0; COND(c
[D_CBC_192_CML
][testnum
]); count
++)
2730 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2731 (size_t)lengths
[testnum
], &camellia_ks
[1],
2732 iv
, CAMELLIA_ENCRYPT
);
2734 print_result(D_CBC_192_CML
, testnum
, count
, d
);
2737 if (doit
[D_CBC_256_CML
]) {
2738 if (async_jobs
> 0) {
2739 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2740 names
[D_CBC_256_CML
]);
2741 doit
[D_CBC_256_CML
] = 0;
2743 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2744 print_message(names
[D_CBC_256_CML
], c
[D_CBC_256_CML
][testnum
],
2745 lengths
[testnum
], seconds
.sym
);
2747 for (count
= 0; COND(c
[D_CBC_256_CML
][testnum
]); count
++)
2748 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2749 (size_t)lengths
[testnum
], &camellia_ks
[2],
2750 iv
, CAMELLIA_ENCRYPT
);
2752 print_result(D_CBC_256_CML
, testnum
, count
, d
);
2756 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2757 if (doit
[D_CBC_IDEA
]) {
2758 if (async_jobs
> 0) {
2759 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2761 doit
[D_CBC_IDEA
] = 0;
2763 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2764 print_message(names
[D_CBC_IDEA
], c
[D_CBC_IDEA
][testnum
],
2765 lengths
[testnum
], seconds
.sym
);
2767 for (count
= 0; COND(c
[D_CBC_IDEA
][testnum
]); count
++)
2768 IDEA_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2769 (size_t)lengths
[testnum
], &idea_ks
,
2772 print_result(D_CBC_IDEA
, testnum
, count
, d
);
2776 #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2777 if (doit
[D_CBC_SEED
]) {
2778 if (async_jobs
> 0) {
2779 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2781 doit
[D_CBC_SEED
] = 0;
2783 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2784 print_message(names
[D_CBC_SEED
], c
[D_CBC_SEED
][testnum
],
2785 lengths
[testnum
], seconds
.sym
);
2787 for (count
= 0; COND(c
[D_CBC_SEED
][testnum
]); count
++)
2788 SEED_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2789 (size_t)lengths
[testnum
], &seed_ks
, iv
, 1);
2791 print_result(D_CBC_SEED
, testnum
, count
, d
);
2795 #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2796 if (doit
[D_CBC_RC2
]) {
2797 if (async_jobs
> 0) {
2798 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2800 doit
[D_CBC_RC2
] = 0;
2802 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2803 print_message(names
[D_CBC_RC2
], c
[D_CBC_RC2
][testnum
],
2804 lengths
[testnum
], seconds
.sym
);
2805 if (async_jobs
> 0) {
2806 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2810 for (count
= 0; COND(c
[D_CBC_RC2
][testnum
]); count
++)
2811 RC2_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2812 (size_t)lengths
[testnum
], &rc2_ks
,
2815 print_result(D_CBC_RC2
, testnum
, count
, d
);
2819 #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2820 if (doit
[D_CBC_RC5
]) {
2821 if (async_jobs
> 0) {
2822 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2824 doit
[D_CBC_RC5
] = 0;
2826 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2827 print_message(names
[D_CBC_RC5
], c
[D_CBC_RC5
][testnum
],
2828 lengths
[testnum
], seconds
.sym
);
2829 if (async_jobs
> 0) {
2830 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2834 for (count
= 0; COND(c
[D_CBC_RC5
][testnum
]); count
++)
2835 RC5_32_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2836 (size_t)lengths
[testnum
], &rc5_ks
,
2839 print_result(D_CBC_RC5
, testnum
, count
, d
);
2843 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2844 if (doit
[D_CBC_BF
]) {
2845 if (async_jobs
> 0) {
2846 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2850 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2851 print_message(names
[D_CBC_BF
], c
[D_CBC_BF
][testnum
],
2852 lengths
[testnum
], seconds
.sym
);
2854 for (count
= 0; COND(c
[D_CBC_BF
][testnum
]); count
++)
2855 BF_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2856 (size_t)lengths
[testnum
], &bf_ks
,
2859 print_result(D_CBC_BF
, testnum
, count
, d
);
2863 #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2864 if (doit
[D_CBC_CAST
]) {
2865 if (async_jobs
> 0) {
2866 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2868 doit
[D_CBC_CAST
] = 0;
2870 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2871 print_message(names
[D_CBC_CAST
], c
[D_CBC_CAST
][testnum
],
2872 lengths
[testnum
], seconds
.sym
);
2874 for (count
= 0; COND(c
[D_CBC_CAST
][testnum
]); count
++)
2875 CAST_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2876 (size_t)lengths
[testnum
], &cast_ks
,
2879 print_result(D_CBC_CAST
, testnum
, count
, d
);
2884 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2885 print_message(names
[D_RAND
], c
[D_RAND
][testnum
], lengths
[testnum
],
2888 count
= run_benchmark(async_jobs
, RAND_bytes_loop
, loopargs
);
2890 print_result(D_RAND
, testnum
, count
, d
);
2895 if (evp_cipher
!= NULL
) {
2896 int (*loopfunc
) (void *) = EVP_Update_loop
;
2898 if (multiblock
&& (EVP_CIPHER_flags(evp_cipher
) &
2899 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
)) {
2900 multiblock_speed(evp_cipher
, lengths_single
, &seconds
);
2905 names
[D_EVP
] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
2907 if (EVP_CIPHER_mode(evp_cipher
) == EVP_CIPH_CCM_MODE
) {
2908 loopfunc
= EVP_Update_loop_ccm
;
2909 } else if (aead
&& (EVP_CIPHER_flags(evp_cipher
) &
2910 EVP_CIPH_FLAG_AEAD_CIPHER
)) {
2911 loopfunc
= EVP_Update_loop_aead
;
2912 if (lengths
== lengths_list
) {
2913 lengths
= aead_lengths_list
;
2914 size_num
= OSSL_NELEM(aead_lengths_list
);
2918 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2919 print_message(names
[D_EVP
], c
[D_EVP
][testnum
], lengths
[testnum
],
2922 for (k
= 0; k
< loopargs_len
; k
++) {
2923 loopargs
[k
].ctx
= EVP_CIPHER_CTX_new();
2924 if (loopargs
[k
].ctx
== NULL
) {
2925 BIO_printf(bio_err
, "\nEVP_CIPHER_CTX_new failure\n");
2928 if (!EVP_CipherInit_ex(loopargs
[k
].ctx
, evp_cipher
, NULL
,
2929 NULL
, iv
, decrypt
? 0 : 1)) {
2930 BIO_printf(bio_err
, "\nEVP_CipherInit_ex failure\n");
2931 ERR_print_errors(bio_err
);
2935 EVP_CIPHER_CTX_set_padding(loopargs
[k
].ctx
, 0);
2937 keylen
= EVP_CIPHER_CTX_key_length(loopargs
[k
].ctx
);
2938 loopargs
[k
].key
= app_malloc(keylen
, "evp_cipher key");
2939 EVP_CIPHER_CTX_rand_key(loopargs
[k
].ctx
, loopargs
[k
].key
);
2940 if (!EVP_CipherInit_ex(loopargs
[k
].ctx
, NULL
, NULL
,
2941 loopargs
[k
].key
, NULL
, -1)) {
2942 BIO_printf(bio_err
, "\nEVP_CipherInit_ex failure\n");
2943 ERR_print_errors(bio_err
);
2946 OPENSSL_clear_free(loopargs
[k
].key
, keylen
);
2948 /* SIV mode only allows for a single Update operation */
2949 if (EVP_CIPHER_mode(evp_cipher
) == EVP_CIPH_SIV_MODE
)
2950 EVP_CIPHER_CTX_ctrl(loopargs
[k
].ctx
, EVP_CTRL_SET_SPEED
, 1, NULL
);
2954 count
= run_benchmark(async_jobs
, loopfunc
, loopargs
);
2956 for (k
= 0; k
< loopargs_len
; k
++) {
2957 EVP_CIPHER_CTX_free(loopargs
[k
].ctx
);
2959 print_result(D_EVP
, testnum
, count
, d
);
2961 } else if (evp_md
!= NULL
) {
2962 names
[D_EVP
] = OBJ_nid2ln(EVP_MD_type(evp_md
));
2964 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2965 print_message(names
[D_EVP
], c
[D_EVP
][testnum
], lengths
[testnum
],
2968 count
= run_benchmark(async_jobs
, EVP_Digest_loop
, loopargs
);
2970 print_result(D_EVP
, testnum
, count
, d
);
2975 #ifndef OPENSSL_NO_DEPRECATED_3_0
2976 if (doit
[D_EVP_HMAC
] && evp_hmac_md
!= NULL
) {
2977 const char *md_name
= OBJ_nid2ln(EVP_MD_type(evp_hmac_md
));
2979 evp_hmac_name
= app_malloc(sizeof("HMAC()") + strlen(md_name
),
2981 sprintf(evp_hmac_name
, "HMAC(%s)", md_name
);
2982 names
[D_EVP_HMAC
] = evp_hmac_name
;
2984 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2985 print_message(names
[D_EVP_HMAC
], c
[D_EVP_HMAC
][testnum
], lengths
[testnum
],
2988 count
= run_benchmark(async_jobs
, EVP_HMAC_loop
, loopargs
);
2990 print_result(D_EVP_HMAC
, testnum
, count
, d
);
2995 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
2996 if (doit
[D_EVP_CMAC
] && evp_cmac_cipher
!= NULL
) {
2997 const char *cipher_name
= OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher
));
2999 evp_cmac_name
= app_malloc(sizeof("CMAC()") + strlen(cipher_name
),
3001 sprintf(evp_cmac_name
, "CMAC(%s)", cipher_name
);
3002 names
[D_EVP_CMAC
] = evp_cmac_name
;
3004 for (i
= 0; i
< loopargs_len
; i
++) {
3005 loopargs
[i
].cmac_ctx
= CMAC_CTX_new();
3006 if (loopargs
[i
].cmac_ctx
== NULL
) {
3007 BIO_printf(bio_err
, "CMAC malloc failure, exiting...");
3011 for (testnum
= 0; testnum
< size_num
; testnum
++) {
3012 print_message(names
[D_EVP_CMAC
], c
[D_EVP_CMAC
][testnum
], lengths
[testnum
],
3015 count
= run_benchmark(async_jobs
, EVP_CMAC_loop
, loopargs
);
3017 print_result(D_EVP_CMAC
, testnum
, count
, d
);
3019 for (i
= 0; i
< loopargs_len
; i
++)
3020 CMAC_CTX_free(loopargs
[i
].cmac_ctx
);
3024 for (i
= 0; i
< loopargs_len
; i
++)
3025 if (RAND_bytes(loopargs
[i
].buf
, 36) <= 0)
3028 #ifndef OPENSSL_NO_DEPRECATED_3_0
3029 for (testnum
= 0; testnum
< RSA_NUM
; testnum
++) {
3031 if (!rsa_doit
[testnum
])
3033 for (i
= 0; i
< loopargs_len
; i
++) {
3034 if (primes
> RSA_DEFAULT_PRIME_NUM
) {
3035 /* we haven't set keys yet, generate multi-prime RSA keys */
3036 BIGNUM
*bn
= BN_new();
3040 if (!BN_set_word(bn
, RSA_F4
)) {
3045 BIO_printf(bio_err
, "Generate multi-prime RSA key for %s\n",
3046 rsa_choices
[testnum
].name
);
3048 loopargs
[i
].rsa_key
[testnum
] = RSA_new();
3049 if (loopargs
[i
].rsa_key
[testnum
] == NULL
) {
3054 if (!RSA_generate_multi_prime_key(loopargs
[i
].rsa_key
[testnum
],
3055 rsa_keys
[testnum
].bits
,
3056 primes
, bn
, NULL
)) {
3062 st
= RSA_sign(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
3063 &loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
3069 "RSA sign failure. No RSA sign will be done.\n");
3070 ERR_print_errors(bio_err
);
3073 pkey_print_message("private", "rsa",
3074 rsa_c
[testnum
][0], rsa_keys
[testnum
].bits
,
3076 /* RSA_blinding_on(rsa_key[testnum],NULL); */
3078 count
= run_benchmark(async_jobs
, RSA_sign_loop
, loopargs
);
3081 mr
? "+R1:%ld:%d:%.2f\n"
3082 : "%ld %u bits private RSA's in %.2fs\n",
3083 count
, rsa_keys
[testnum
].bits
, d
);
3084 rsa_results
[testnum
][0] = (double)count
/ d
;
3088 for (i
= 0; i
< loopargs_len
; i
++) {
3089 st
= RSA_verify(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
3090 loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
3096 "RSA verify failure. No RSA verify will be done.\n");
3097 ERR_print_errors(bio_err
);
3098 rsa_doit
[testnum
] = 0;
3100 pkey_print_message("public", "rsa",
3101 rsa_c
[testnum
][1], rsa_keys
[testnum
].bits
,
3104 count
= run_benchmark(async_jobs
, RSA_verify_loop
, loopargs
);
3107 mr
? "+R2:%ld:%d:%.2f\n"
3108 : "%ld %u bits public RSA's in %.2fs\n",
3109 count
, rsa_keys
[testnum
].bits
, d
);
3110 rsa_results
[testnum
][1] = (double)count
/ d
;
3113 if (op_count
<= 1) {
3114 /* if longer than 10s, don't do any more */
3115 stop_it(rsa_doit
, testnum
);
3118 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
3120 for (i
= 0; i
< loopargs_len
; i
++)
3121 if (RAND_bytes(loopargs
[i
].buf
, 36) <= 0)
3124 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3125 for (testnum
= 0; testnum
< DSA_NUM
; testnum
++) {
3127 if (!dsa_doit
[testnum
])
3130 /* DSA_generate_key(dsa_key[testnum]); */
3131 /* DSA_sign_setup(dsa_key[testnum],NULL); */
3132 for (i
= 0; i
< loopargs_len
; i
++) {
3133 st
= DSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
3134 &loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
3140 "DSA sign failure. No DSA sign will be done.\n");
3141 ERR_print_errors(bio_err
);
3144 pkey_print_message("sign", "dsa",
3145 dsa_c
[testnum
][0], dsa_bits
[testnum
],
3148 count
= run_benchmark(async_jobs
, DSA_sign_loop
, loopargs
);
3151 mr
? "+R3:%ld:%u:%.2f\n"
3152 : "%ld %u bits DSA signs in %.2fs\n",
3153 count
, dsa_bits
[testnum
], d
);
3154 dsa_results
[testnum
][0] = (double)count
/ d
;
3158 for (i
= 0; i
< loopargs_len
; i
++) {
3159 st
= DSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
3160 loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
3166 "DSA verify failure. No DSA verify will be done.\n");
3167 ERR_print_errors(bio_err
);
3168 dsa_doit
[testnum
] = 0;
3170 pkey_print_message("verify", "dsa",
3171 dsa_c
[testnum
][1], dsa_bits
[testnum
],
3174 count
= run_benchmark(async_jobs
, DSA_verify_loop
, loopargs
);
3177 mr
? "+R4:%ld:%u:%.2f\n"
3178 : "%ld %u bits DSA verify in %.2fs\n",
3179 count
, dsa_bits
[testnum
], d
);
3180 dsa_results
[testnum
][1] = (double)count
/ d
;
3183 if (op_count
<= 1) {
3184 /* if longer than 10s, don't do any more */
3185 stop_it(dsa_doit
, testnum
);
3188 #endif /* OPENSSL_NO_DSA */
3190 #ifndef OPENSSL_NO_EC
3191 # ifndef OPENSSL_NO_DEPRECATED_3_0
3192 for (testnum
= 0; testnum
< ECDSA_NUM
; testnum
++) {
3195 if (!ecdsa_doit
[testnum
])
3196 continue; /* Ignore Curve */
3197 for (i
= 0; i
< loopargs_len
; i
++) {
3198 loopargs
[i
].ecdsa
[testnum
] =
3199 EC_KEY_new_by_curve_name(ec_curves
[testnum
].nid
);
3200 if (loopargs
[i
].ecdsa
[testnum
] == NULL
) {
3206 BIO_printf(bio_err
, "ECDSA failure.\n");
3207 ERR_print_errors(bio_err
);
3210 for (i
= 0; i
< loopargs_len
; i
++) {
3211 /* Perform ECDSA signature test */
3212 EC_KEY_generate_key(loopargs
[i
].ecdsa
[testnum
]);
3213 st
= ECDSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
3214 &loopargs
[i
].siglen
,
3215 loopargs
[i
].ecdsa
[testnum
]);
3221 "ECDSA sign failure. No ECDSA sign will be done.\n");
3222 ERR_print_errors(bio_err
);
3225 pkey_print_message("sign", "ecdsa",
3226 ecdsa_c
[testnum
][0],
3227 ec_curves
[testnum
].bits
, seconds
.ecdsa
);
3229 count
= run_benchmark(async_jobs
, ECDSA_sign_loop
, loopargs
);
3233 mr
? "+R5:%ld:%u:%.2f\n" :
3234 "%ld %u bits ECDSA signs in %.2fs \n",
3235 count
, ec_curves
[testnum
].bits
, d
);
3236 ecdsa_results
[testnum
][0] = (double)count
/ d
;
3240 /* Perform ECDSA verification test */
3241 for (i
= 0; i
< loopargs_len
; i
++) {
3242 st
= ECDSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
3244 loopargs
[i
].ecdsa
[testnum
]);
3250 "ECDSA verify failure. No ECDSA verify will be done.\n");
3251 ERR_print_errors(bio_err
);
3252 ecdsa_doit
[testnum
] = 0;
3254 pkey_print_message("verify", "ecdsa",
3255 ecdsa_c
[testnum
][1],
3256 ec_curves
[testnum
].bits
, seconds
.ecdsa
);
3258 count
= run_benchmark(async_jobs
, ECDSA_verify_loop
, loopargs
);
3261 mr
? "+R6:%ld:%u:%.2f\n"
3262 : "%ld %u bits ECDSA verify in %.2fs\n",
3263 count
, ec_curves
[testnum
].bits
, d
);
3264 ecdsa_results
[testnum
][1] = (double)count
/ d
;
3267 if (op_count
<= 1) {
3268 /* if longer than 10s, don't do any more */
3269 stop_it(ecdsa_doit
, testnum
);
3273 # endif /* OPENSSL_NO_DEPRECATED_3_0 */
3275 for (testnum
= 0; testnum
< EC_NUM
; testnum
++) {
3276 int ecdh_checks
= 1;
3278 if (!ecdh_doit
[testnum
])
3281 for (i
= 0; i
< loopargs_len
; i
++) {
3282 EVP_PKEY_CTX
*kctx
= NULL
;
3283 EVP_PKEY_CTX
*test_ctx
= NULL
;
3284 EVP_PKEY_CTX
*ctx
= NULL
;
3285 EVP_PKEY
*key_A
= NULL
;
3286 EVP_PKEY
*key_B
= NULL
;
3290 /* Ensure that the error queue is empty */
3291 if (ERR_peek_error()) {
3293 "WARNING: the error queue contains previous unhandled errors.\n");
3294 ERR_print_errors(bio_err
);
3297 /* Let's try to create a ctx directly from the NID: this works for
3298 * curves like Curve25519 that are not implemented through the low
3299 * level EC interface.
3300 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
3301 * then we set the curve by NID before deriving the actual keygen
3302 * ctx for that specific curve. */
3303 kctx
= EVP_PKEY_CTX_new_id(ec_curves
[testnum
].nid
, NULL
); /* keygen ctx from NID */
3305 EVP_PKEY_CTX
*pctx
= NULL
;
3306 EVP_PKEY
*params
= NULL
;
3308 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
3309 * "int_ctx_new:unsupported algorithm" error was added to the
3311 * We remove it from the error queue as we are handling it. */
3312 unsigned long error
= ERR_peek_error(); /* peek the latest error in the queue */
3313 if (error
== ERR_peek_last_error() && /* oldest and latest errors match */
3314 /* check that the error origin matches */
3315 ERR_GET_LIB(error
) == ERR_LIB_EVP
&&
3316 ERR_GET_REASON(error
) == EVP_R_UNSUPPORTED_ALGORITHM
)
3317 ERR_get_error(); /* pop error from queue */
3318 if (ERR_peek_error()) {
3320 "Unhandled error in the error queue during ECDH init.\n");
3321 ERR_print_errors(bio_err
);
3326 /* Create the context for parameter generation */
3327 if (!(pctx
= EVP_PKEY_CTX_new_id(EVP_PKEY_EC
, NULL
)) ||
3328 /* Initialise the parameter generation */
3329 !EVP_PKEY_paramgen_init(pctx
) ||
3330 /* Set the curve by NID */
3331 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx
,
3334 /* Create the parameter object params */
3335 !EVP_PKEY_paramgen(pctx
, ¶ms
)) {
3337 BIO_printf(bio_err
, "ECDH EC params init failure.\n");
3338 ERR_print_errors(bio_err
);
3342 /* Create the context for the key generation */
3343 kctx
= EVP_PKEY_CTX_new(params
, NULL
);
3345 EVP_PKEY_free(params
);
3347 EVP_PKEY_CTX_free(pctx
);
3350 if (kctx
== NULL
|| /* keygen ctx is not null */
3351 EVP_PKEY_keygen_init(kctx
) <= 0/* init keygen ctx */ ) {
3353 BIO_printf(bio_err
, "ECDH keygen failure.\n");
3354 ERR_print_errors(bio_err
);
3359 if (EVP_PKEY_keygen(kctx
, &key_A
) <= 0 || /* generate secret key A */
3360 EVP_PKEY_keygen(kctx
, &key_B
) <= 0 || /* generate secret key B */
3361 !(ctx
= EVP_PKEY_CTX_new(key_A
, NULL
)) || /* derivation ctx from skeyA */
3362 EVP_PKEY_derive_init(ctx
) <= 0 || /* init derivation ctx */
3363 EVP_PKEY_derive_set_peer(ctx
, key_B
) <= 0 || /* set peer pubkey in ctx */
3364 EVP_PKEY_derive(ctx
, NULL
, &outlen
) <= 0 || /* determine max length */
3365 outlen
== 0 || /* ensure outlen is a valid size */
3366 outlen
> MAX_ECDH_SIZE
/* avoid buffer overflow */ ) {
3368 BIO_printf(bio_err
, "ECDH key generation failure.\n");
3369 ERR_print_errors(bio_err
);
3374 /* Here we perform a test run, comparing the output of a*B and b*A;
3375 * we try this here and assume that further EVP_PKEY_derive calls
3376 * never fail, so we can skip checks in the actually benchmarked
3377 * code, for maximum performance. */
3378 if (!(test_ctx
= EVP_PKEY_CTX_new(key_B
, NULL
)) || /* test ctx from skeyB */
3379 !EVP_PKEY_derive_init(test_ctx
) || /* init derivation test_ctx */
3380 !EVP_PKEY_derive_set_peer(test_ctx
, key_A
) || /* set peer pubkey in test_ctx */
3381 !EVP_PKEY_derive(test_ctx
, NULL
, &test_outlen
) || /* determine max length */
3382 !EVP_PKEY_derive(ctx
, loopargs
[i
].secret_a
, &outlen
) || /* compute a*B */
3383 !EVP_PKEY_derive(test_ctx
, loopargs
[i
].secret_b
, &test_outlen
) || /* compute b*A */
3384 test_outlen
!= outlen
/* compare output length */ ) {
3386 BIO_printf(bio_err
, "ECDH computation failure.\n");
3387 ERR_print_errors(bio_err
);
3392 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3393 if (CRYPTO_memcmp(loopargs
[i
].secret_a
,
3394 loopargs
[i
].secret_b
, outlen
)) {
3396 BIO_printf(bio_err
, "ECDH computations don't match.\n");
3397 ERR_print_errors(bio_err
);
3402 loopargs
[i
].ecdh_ctx
[testnum
] = ctx
;
3403 loopargs
[i
].outlen
[testnum
] = outlen
;
3405 EVP_PKEY_free(key_A
);
3406 EVP_PKEY_free(key_B
);
3407 EVP_PKEY_CTX_free(kctx
);
3409 EVP_PKEY_CTX_free(test_ctx
);
3412 if (ecdh_checks
!= 0) {
3413 pkey_print_message("", "ecdh",
3415 ec_curves
[testnum
].bits
, seconds
.ecdh
);
3418 run_benchmark(async_jobs
, ECDH_EVP_derive_key_loop
, loopargs
);
3421 mr
? "+R7:%ld:%d:%.2f\n" :
3422 "%ld %u-bits ECDH ops in %.2fs\n", count
,
3423 ec_curves
[testnum
].bits
, d
);
3424 ecdh_results
[testnum
][0] = (double)count
/ d
;
3428 if (op_count
<= 1) {
3429 /* if longer than 10s, don't do any more */
3430 stop_it(ecdh_doit
, testnum
);
3434 for (testnum
= 0; testnum
< EdDSA_NUM
; testnum
++) {
3436 EVP_PKEY
*ed_pkey
= NULL
;
3437 EVP_PKEY_CTX
*ed_pctx
= NULL
;
3439 if (!eddsa_doit
[testnum
])
3440 continue; /* Ignore Curve */
3441 for (i
= 0; i
< loopargs_len
; i
++) {
3442 loopargs
[i
].eddsa_ctx
[testnum
] = EVP_MD_CTX_new();
3443 if (loopargs
[i
].eddsa_ctx
[testnum
] == NULL
) {
3447 loopargs
[i
].eddsa_ctx2
[testnum
] = EVP_MD_CTX_new();
3448 if (loopargs
[i
].eddsa_ctx2
[testnum
] == NULL
) {
3453 if ((ed_pctx
= EVP_PKEY_CTX_new_id(ed_curves
[testnum
].nid
, NULL
))
3455 || EVP_PKEY_keygen_init(ed_pctx
) <= 0
3456 || EVP_PKEY_keygen(ed_pctx
, &ed_pkey
) <= 0) {
3458 EVP_PKEY_CTX_free(ed_pctx
);
3461 EVP_PKEY_CTX_free(ed_pctx
);
3463 if (!EVP_DigestSignInit(loopargs
[i
].eddsa_ctx
[testnum
], NULL
, NULL
,
3466 EVP_PKEY_free(ed_pkey
);
3469 if (!EVP_DigestVerifyInit(loopargs
[i
].eddsa_ctx2
[testnum
], NULL
,
3470 NULL
, NULL
, ed_pkey
)) {
3472 EVP_PKEY_free(ed_pkey
);
3476 EVP_PKEY_free(ed_pkey
);
3480 BIO_printf(bio_err
, "EdDSA failure.\n");
3481 ERR_print_errors(bio_err
);
3484 for (i
= 0; i
< loopargs_len
; i
++) {
3485 /* Perform EdDSA signature test */
3486 loopargs
[i
].sigsize
= ed_curves
[testnum
].sigsize
;
3487 st
= EVP_DigestSign(loopargs
[i
].eddsa_ctx
[testnum
],
3488 loopargs
[i
].buf2
, &loopargs
[i
].sigsize
,
3489 loopargs
[i
].buf
, 20);
3495 "EdDSA sign failure. No EdDSA sign will be done.\n");
3496 ERR_print_errors(bio_err
);
3499 pkey_print_message("sign", ed_curves
[testnum
].name
,
3500 eddsa_c
[testnum
][0],
3501 ed_curves
[testnum
].bits
, seconds
.eddsa
);
3503 count
= run_benchmark(async_jobs
, EdDSA_sign_loop
, loopargs
);
3507 mr
? "+R8:%ld:%u:%s:%.2f\n" :
3508 "%ld %u bits %s signs in %.2fs \n",
3509 count
, ed_curves
[testnum
].bits
,
3510 ed_curves
[testnum
].name
, d
);
3511 eddsa_results
[testnum
][0] = (double)count
/ d
;
3514 /* Perform EdDSA verification test */
3515 for (i
= 0; i
< loopargs_len
; i
++) {
3516 st
= EVP_DigestVerify(loopargs
[i
].eddsa_ctx2
[testnum
],
3517 loopargs
[i
].buf2
, loopargs
[i
].sigsize
,
3518 loopargs
[i
].buf
, 20);
3524 "EdDSA verify failure. No EdDSA verify will be done.\n");
3525 ERR_print_errors(bio_err
);
3526 eddsa_doit
[testnum
] = 0;
3528 pkey_print_message("verify", ed_curves
[testnum
].name
,
3529 eddsa_c
[testnum
][1],
3530 ed_curves
[testnum
].bits
, seconds
.eddsa
);
3532 count
= run_benchmark(async_jobs
, EdDSA_verify_loop
, loopargs
);
3535 mr
? "+R9:%ld:%u:%s:%.2f\n"
3536 : "%ld %u bits %s verify in %.2fs\n",
3537 count
, ed_curves
[testnum
].bits
,
3538 ed_curves
[testnum
].name
, d
);
3539 eddsa_results
[testnum
][1] = (double)count
/ d
;
3542 if (op_count
<= 1) {
3543 /* if longer than 10s, don't do any more */
3544 stop_it(eddsa_doit
, testnum
);
3549 # ifndef OPENSSL_NO_SM2
3550 for (testnum
= 0; testnum
< SM2_NUM
; testnum
++) {
3552 EVP_PKEY
*sm2_pkey
= NULL
;
3554 if (!sm2_doit
[testnum
])
3555 continue; /* Ignore Curve */
3556 /* Init signing and verification */
3557 for (i
= 0; i
< loopargs_len
; i
++) {
3558 EVP_PKEY_CTX
*sm2_pctx
= NULL
;
3559 EVP_PKEY_CTX
*sm2_vfy_pctx
= NULL
;
3560 EVP_PKEY_CTX
*pctx
= NULL
;
3563 loopargs
[i
].sm2_ctx
[testnum
] = EVP_MD_CTX_new();
3564 loopargs
[i
].sm2_vfy_ctx
[testnum
] = EVP_MD_CTX_new();
3565 if (loopargs
[i
].sm2_ctx
[testnum
] == NULL
3566 || loopargs
[i
].sm2_vfy_ctx
[testnum
] == NULL
)
3569 /* SM2 keys are generated as normal EC keys with a special curve */
3570 st
= !((pctx
= EVP_PKEY_CTX_new_id(EVP_PKEY_EC
, NULL
)) == NULL
3571 || EVP_PKEY_keygen_init(pctx
) <= 0
3572 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx
,
3573 sm2_curves
[testnum
].nid
) <= 0
3574 || EVP_PKEY_keygen(pctx
, &sm2_pkey
) <= 0);
3575 EVP_PKEY_CTX_free(pctx
);
3579 st
= 0; /* set back to zero */
3580 /* attach it sooner to rely on main final cleanup */
3581 loopargs
[i
].sm2_pkey
[testnum
] = sm2_pkey
;
3582 loopargs
[i
].sigsize
= EVP_PKEY_size(sm2_pkey
);
3584 sm2_pctx
= EVP_PKEY_CTX_new(sm2_pkey
, NULL
);
3585 sm2_vfy_pctx
= EVP_PKEY_CTX_new(sm2_pkey
, NULL
);
3586 if (sm2_pctx
== NULL
|| sm2_vfy_pctx
== NULL
) {
3587 EVP_PKEY_CTX_free(sm2_vfy_pctx
);
3591 /* attach them directly to respective ctx */
3592 EVP_MD_CTX_set_pkey_ctx(loopargs
[i
].sm2_ctx
[testnum
], sm2_pctx
);
3593 EVP_MD_CTX_set_pkey_ctx(loopargs
[i
].sm2_vfy_ctx
[testnum
], sm2_vfy_pctx
);
3596 * No need to allow user to set an explicit ID here, just use
3597 * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D.
3599 if (EVP_PKEY_CTX_set1_id(sm2_pctx
, SM2_ID
, SM2_ID_LEN
) != 1
3600 || EVP_PKEY_CTX_set1_id(sm2_vfy_pctx
, SM2_ID
, SM2_ID_LEN
) != 1)
3603 if (!EVP_DigestSignInit(loopargs
[i
].sm2_ctx
[testnum
], NULL
,
3604 EVP_sm3(), NULL
, sm2_pkey
))
3606 if (!EVP_DigestVerifyInit(loopargs
[i
].sm2_vfy_ctx
[testnum
], NULL
,
3607 EVP_sm3(), NULL
, sm2_pkey
))
3609 st
= 1; /* mark loop as succeeded */
3612 BIO_printf(bio_err
, "SM2 init failure.\n");
3613 ERR_print_errors(bio_err
);
3616 for (i
= 0; i
< loopargs_len
; i
++) {
3617 size_t sm2_sigsize
= loopargs
[i
].sigsize
;
3619 /* Perform SM2 signature test */
3620 st
= EVP_DigestSign(loopargs
[i
].sm2_ctx
[testnum
],
3621 loopargs
[i
].buf2
, &sm2_sigsize
,
3622 loopargs
[i
].buf
, 20);
3628 "SM2 sign failure. No SM2 sign will be done.\n");
3629 ERR_print_errors(bio_err
);
3632 pkey_print_message("sign", sm2_curves
[testnum
].name
,
3634 sm2_curves
[testnum
].bits
, seconds
.sm2
);
3636 count
= run_benchmark(async_jobs
, SM2_sign_loop
, loopargs
);
3640 mr
? "+R10:%ld:%u:%s:%.2f\n" :
3641 "%ld %u bits %s signs in %.2fs \n",
3642 count
, sm2_curves
[testnum
].bits
,
3643 sm2_curves
[testnum
].name
, d
);
3644 sm2_results
[testnum
][0] = (double)count
/ d
;
3648 /* Perform SM2 verification test */
3649 for (i
= 0; i
< loopargs_len
; i
++) {
3650 st
= EVP_DigestVerify(loopargs
[i
].sm2_vfy_ctx
[testnum
],
3651 loopargs
[i
].buf2
, loopargs
[i
].sigsize
,
3652 loopargs
[i
].buf
, 20);
3658 "SM2 verify failure. No SM2 verify will be done.\n");
3659 ERR_print_errors(bio_err
);
3660 sm2_doit
[testnum
] = 0;
3662 pkey_print_message("verify", sm2_curves
[testnum
].name
,
3664 sm2_curves
[testnum
].bits
, seconds
.sm2
);
3666 count
= run_benchmark(async_jobs
, SM2_verify_loop
, loopargs
);
3669 mr
? "+R11:%ld:%u:%s:%.2f\n"
3670 : "%ld %u bits %s verify in %.2fs\n",
3671 count
, sm2_curves
[testnum
].bits
,
3672 sm2_curves
[testnum
].name
, d
);
3673 sm2_results
[testnum
][1] = (double)count
/ d
;
3676 if (op_count
<= 1) {
3677 /* if longer than 10s, don't do any more */
3678 for (testnum
++; testnum
< SM2_NUM
; testnum
++)
3679 sm2_doit
[testnum
] = 0;
3683 # endif /* OPENSSL_NO_SM2 */
3684 #endif /* OPENSSL_NO_EC */
3686 #ifndef OPENSSL_NO_DH
3687 for (testnum
= 0; testnum
< FFDH_NUM
; testnum
++) {
3688 int ffdh_checks
= 1;
3690 if (!ffdh_doit
[testnum
])
3693 for (i
= 0; i
< loopargs_len
; i
++) {
3694 EVP_PKEY
*pkey_A
= NULL
;
3695 EVP_PKEY
*pkey_B
= NULL
;
3696 EVP_PKEY_CTX
*ffdh_ctx
= NULL
;
3697 EVP_PKEY_CTX
*test_ctx
= NULL
;
3701 /* Ensure that the error queue is empty */
3702 if (ERR_peek_error()) {
3704 "WARNING: the error queue contains previous unhandled errors.\n");
3705 ERR_print_errors(bio_err
);
3708 pkey_A
= EVP_PKEY_new();
3710 BIO_printf(bio_err
, "Error while initialising EVP_PKEY (out of memory?).\n");
3711 ERR_print_errors(bio_err
);
3716 pkey_B
= EVP_PKEY_new();
3718 BIO_printf(bio_err
, "Error while initialising EVP_PKEY (out of memory?).\n");
3719 ERR_print_errors(bio_err
);
3725 ffdh_ctx
= EVP_PKEY_CTX_new_id(EVP_PKEY_DH
, NULL
);
3727 BIO_printf(bio_err
, "Error while allocating EVP_PKEY_CTX.\n");
3728 ERR_print_errors(bio_err
);
3734 if (EVP_PKEY_keygen_init(ffdh_ctx
) <= 0) {
3735 BIO_printf(bio_err
, "Error while initialising EVP_PKEY_CTX.\n");
3736 ERR_print_errors(bio_err
);
3741 if (EVP_PKEY_CTX_set_dh_nid(ffdh_ctx
, ffdh_params
[testnum
].nid
) <= 0) {
3742 BIO_printf(bio_err
, "Error setting DH key size for keygen.\n");
3743 ERR_print_errors(bio_err
);
3749 if (EVP_PKEY_keygen(ffdh_ctx
, &pkey_A
) <= 0 ||
3750 EVP_PKEY_keygen(ffdh_ctx
, &pkey_B
) <= 0) {
3751 BIO_printf(bio_err
, "FFDH key generation failure.\n");
3752 ERR_print_errors(bio_err
);
3758 EVP_PKEY_CTX_free(ffdh_ctx
);
3760 /* check if the derivation works correctly both ways so that
3761 * we know if future derive calls will fail, and we can skip
3762 * error checking in benchmarked code */
3763 ffdh_ctx
= EVP_PKEY_CTX_new(pkey_A
, NULL
);
3765 BIO_printf(bio_err
, "Error while allocating EVP_PKEY_CTX.\n");
3766 ERR_print_errors(bio_err
);
3771 if (EVP_PKEY_derive_init(ffdh_ctx
) <= 0) {
3772 BIO_printf(bio_err
, "FFDH derivation context init failure.\n");
3773 ERR_print_errors(bio_err
);
3778 if (EVP_PKEY_derive_set_peer(ffdh_ctx
, pkey_B
) <= 0) {
3779 BIO_printf(bio_err
, "Assigning peer key for derivation failed.\n");
3780 ERR_print_errors(bio_err
);
3785 if (EVP_PKEY_derive(ffdh_ctx
, NULL
, &secret_size
) <= 0) {
3786 BIO_printf(bio_err
, "Checking size of shared secret failed.\n");
3787 ERR_print_errors(bio_err
);
3792 if (secret_size
> MAX_FFDH_SIZE
) {
3793 BIO_printf(bio_err
, "Assertion failure: shared secret too large.\n");
3798 if (EVP_PKEY_derive(ffdh_ctx
,
3799 loopargs
[i
].secret_ff_a
,
3800 &secret_size
) <= 0) {
3801 BIO_printf(bio_err
, "Shared secret derive failure.\n");
3802 ERR_print_errors(bio_err
);
3807 /* Now check from side B */
3808 test_ctx
= EVP_PKEY_CTX_new(pkey_B
, NULL
);
3810 BIO_printf(bio_err
, "Error while allocating EVP_PKEY_CTX.\n");
3811 ERR_print_errors(bio_err
);
3816 if (!EVP_PKEY_derive_init(test_ctx
) ||
3817 !EVP_PKEY_derive_set_peer(test_ctx
, pkey_A
) ||
3818 !EVP_PKEY_derive(test_ctx
, NULL
, &test_out
) ||
3819 !EVP_PKEY_derive(test_ctx
, loopargs
[i
].secret_ff_b
, &test_out
) ||
3820 test_out
!= secret_size
) {
3821 BIO_printf(bio_err
, "FFDH computation failure.\n");
3827 /* compare the computed secrets */
3828 if (CRYPTO_memcmp(loopargs
[i
].secret_ff_a
,
3829 loopargs
[i
].secret_ff_b
, secret_size
)) {
3830 BIO_printf(bio_err
, "FFDH computations don't match.\n");
3831 ERR_print_errors(bio_err
);
3837 loopargs
[i
].ffdh_ctx
[testnum
] = ffdh_ctx
;
3839 EVP_PKEY_free(pkey_A
);
3841 EVP_PKEY_free(pkey_B
);
3843 EVP_PKEY_CTX_free(test_ctx
);
3846 if (ffdh_checks
!= 0) {
3847 pkey_print_message("", "ffdh", ffdh_c
[testnum
][0],
3848 ffdh_params
[testnum
].bits
, seconds
.ffdh
);
3851 run_benchmark(async_jobs
, FFDH_derive_key_loop
, loopargs
);
3854 mr
? "+R12:%ld:%d:%.2f\n" :
3855 "%ld %u-bits FFDH ops in %.2fs\n", count
,
3856 ffdh_params
[testnum
].bits
, d
);
3857 ffdh_results
[testnum
][0] = (double)count
/ d
;
3860 if (op_count
<= 1) {
3861 /* if longer than 10s, don't do any more */
3862 stop_it(ffdh_doit
, testnum
);
3865 #endif /* OPENSSL_NO_DH */
3870 printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING
));
3871 printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON
));
3873 printf("%s ", BN_options());
3874 #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3875 printf("%s ", MD2_options());
3877 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3878 printf("%s ", RC4_options());
3880 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3881 printf("%s ", DES_options());
3883 #ifndef OPENSSL_NO_DEPRECATED_3_0
3884 printf("%s ", AES_options());
3886 #if !defined(OPENSSL_NO_IDEA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3887 printf("%s ", IDEA_options());
3889 #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3890 printf("%s ", BF_options());
3892 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS
));
3893 printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO
));
3901 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3904 for (testnum
= 0; testnum
< size_num
; testnum
++)
3905 printf(mr
? ":%d" : "%7d bytes", lengths
[testnum
]);
3909 for (k
= 0; k
< ALGOR_NUM
; k
++) {
3913 printf("+F:%u:%s", k
, names
[k
]);
3915 printf("%-13s", names
[k
]);
3916 for (testnum
= 0; testnum
< size_num
; testnum
++) {
3917 if (results
[k
][testnum
] > 10000 && !mr
)
3918 printf(" %11.2fk", results
[k
][testnum
] / 1e3
);
3920 printf(mr
? ":%.2f" : " %11.2f ", results
[k
][testnum
]);
3924 #ifndef OPENSSL_NO_DEPRECATED_3_0
3926 for (k
= 0; k
< RSA_NUM
; k
++) {
3929 if (testnum
&& !mr
) {
3930 printf("%18ssign verify sign/s verify/s\n", " ");
3934 printf("+F2:%u:%u:%f:%f\n",
3935 k
, rsa_keys
[k
].bits
, rsa_results
[k
][0], rsa_results
[k
][1]);
3937 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3938 rsa_keys
[k
].bits
, 1.0 / rsa_results
[k
][0], 1.0 / rsa_results
[k
][1],
3939 rsa_results
[k
][0], rsa_results
[k
][1]);
3942 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
3944 for (k
= 0; k
< DSA_NUM
; k
++) {
3947 if (testnum
&& !mr
) {
3948 printf("%18ssign verify sign/s verify/s\n", " ");
3952 printf("+F3:%u:%u:%f:%f\n",
3953 k
, dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1]);
3955 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3956 dsa_bits
[k
], 1.0 / dsa_results
[k
][0], 1.0 / dsa_results
[k
][1],
3957 dsa_results
[k
][0], dsa_results
[k
][1]);
3960 #ifndef OPENSSL_NO_EC
3962 for (k
= 0; k
< OSSL_NELEM(ecdsa_doit
); k
++) {
3965 if (testnum
&& !mr
) {
3966 printf("%30ssign verify sign/s verify/s\n", " ");
3971 printf("+F4:%u:%u:%f:%f\n",
3972 k
, ec_curves
[k
].bits
,
3973 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
3975 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3976 ec_curves
[k
].bits
, ec_curves
[k
].name
,
3977 1.0 / ecdsa_results
[k
][0], 1.0 / ecdsa_results
[k
][1],
3978 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
3982 for (k
= 0; k
< EC_NUM
; k
++) {
3985 if (testnum
&& !mr
) {
3986 printf("%30sop op/s\n", " ");
3990 printf("+F5:%u:%u:%f:%f\n",
3991 k
, ec_curves
[k
].bits
,
3992 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
3995 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3996 ec_curves
[k
].bits
, ec_curves
[k
].name
,
3997 1.0 / ecdh_results
[k
][0], ecdh_results
[k
][0]);
4001 for (k
= 0; k
< OSSL_NELEM(eddsa_doit
); k
++) {
4004 if (testnum
&& !mr
) {
4005 printf("%30ssign verify sign/s verify/s\n", " ");
4010 printf("+F6:%u:%u:%s:%f:%f\n",
4011 k
, ed_curves
[k
].bits
, ed_curves
[k
].name
,
4012 eddsa_results
[k
][0], eddsa_results
[k
][1]);
4014 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
4015 ed_curves
[k
].bits
, ed_curves
[k
].name
,
4016 1.0 / eddsa_results
[k
][0], 1.0 / eddsa_results
[k
][1],
4017 eddsa_results
[k
][0], eddsa_results
[k
][1]);
4020 # ifndef OPENSSL_NO_SM2
4022 for (k
= 0; k
< OSSL_NELEM(sm2_doit
); k
++) {
4025 if (testnum
&& !mr
) {
4026 printf("%30ssign verify sign/s verify/s\n", " ");
4031 printf("+F7:%u:%u:%s:%f:%f\n",
4032 k
, sm2_curves
[k
].bits
, sm2_curves
[k
].name
,
4033 sm2_results
[k
][0], sm2_results
[k
][1]);
4035 printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
4036 sm2_curves
[k
].bits
, sm2_curves
[k
].name
,
4037 1.0 / sm2_results
[k
][0], 1.0 / sm2_results
[k
][1],
4038 sm2_results
[k
][0], sm2_results
[k
][1]);
4041 #endif /* OPENSSL_NO_EC */
4042 #ifndef OPENSSL_NO_DH
4044 for (k
= 0; k
< FFDH_NUM
; k
++) {
4047 if (testnum
&& !mr
) {
4048 printf("%23sop op/s\n", " ");
4052 printf("+F8:%u:%u:%f:%f\n",
4053 k
, ffdh_params
[k
].bits
,
4054 ffdh_results
[k
][0], 1.0 / ffdh_results
[k
][0]);
4057 printf("%4u bits ffdh %8.4fs %8.1f\n",
4058 ffdh_params
[k
].bits
,
4059 1.0 / ffdh_results
[k
][0], ffdh_results
[k
][0]);
4061 #endif /* OPENSSL_NO_DH */
4066 ERR_print_errors(bio_err
);
4067 for (i
= 0; i
< loopargs_len
; i
++) {
4068 OPENSSL_free(loopargs
[i
].buf_malloc
);
4069 OPENSSL_free(loopargs
[i
].buf2_malloc
);
4071 #ifndef OPENSSL_NO_DEPRECATED_3_0
4072 for (k
= 0; k
< RSA_NUM
; k
++)
4073 RSA_free(loopargs
[i
].rsa_key
[k
]);
4075 #ifndef OPENSSL_NO_DH
4076 OPENSSL_free(loopargs
[i
].secret_ff_a
);
4077 OPENSSL_free(loopargs
[i
].secret_ff_b
);
4078 for (k
= 0; k
< FFDH_NUM
; k
++) {
4079 EVP_PKEY_CTX_free(loopargs
[i
].ffdh_ctx
[k
]);
4082 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4083 for (k
= 0; k
< DSA_NUM
; k
++)
4084 DSA_free(loopargs
[i
].dsa_key
[k
]);
4086 #ifndef OPENSSL_NO_EC
4087 # if !defined(OPENSSL_NO_DEPRECATED_3_0)
4088 for (k
= 0; k
< ECDSA_NUM
; k
++)
4089 EC_KEY_free(loopargs
[i
].ecdsa
[k
]);
4091 for (k
= 0; k
< EC_NUM
; k
++)
4092 EVP_PKEY_CTX_free(loopargs
[i
].ecdh_ctx
[k
]);
4093 for (k
= 0; k
< EdDSA_NUM
; k
++) {
4094 EVP_MD_CTX_free(loopargs
[i
].eddsa_ctx
[k
]);
4095 EVP_MD_CTX_free(loopargs
[i
].eddsa_ctx2
[k
]);
4097 # ifndef OPENSSL_NO_SM2
4098 for (k
= 0; k
< SM2_NUM
; k
++) {
4099 EVP_PKEY_CTX
*pctx
= NULL
;
4101 /* free signing ctx */
4102 if (loopargs
[i
].sm2_ctx
[k
] != NULL
4103 && (pctx
= EVP_MD_CTX_pkey_ctx(loopargs
[i
].sm2_ctx
[k
])) != NULL
)
4104 EVP_PKEY_CTX_free(pctx
);
4105 EVP_MD_CTX_free(loopargs
[i
].sm2_ctx
[k
]);
4106 /* free verification ctx */
4107 if (loopargs
[i
].sm2_vfy_ctx
[k
] != NULL
4108 && (pctx
= EVP_MD_CTX_pkey_ctx(loopargs
[i
].sm2_vfy_ctx
[k
])) != NULL
)
4109 EVP_PKEY_CTX_free(pctx
);
4110 EVP_MD_CTX_free(loopargs
[i
].sm2_vfy_ctx
[k
]);
4112 EVP_PKEY_free(loopargs
[i
].sm2_pkey
[k
]);
4115 OPENSSL_free(loopargs
[i
].secret_a
);
4116 OPENSSL_free(loopargs
[i
].secret_b
);
4119 #ifndef OPENSSL_NO_DEPRECATED_3_0
4120 OPENSSL_free(evp_hmac_name
);
4122 #if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4123 OPENSSL_free(evp_cmac_name
);
4126 if (async_jobs
> 0) {
4127 for (i
= 0; i
< loopargs_len
; i
++)
4128 ASYNC_WAIT_CTX_free(loopargs
[i
].wait_ctx
);
4132 ASYNC_cleanup_thread();
4134 OPENSSL_free(loopargs
);
4137 EVP_MD_free(evp_md
);
4138 EVP_CIPHER_free(evp_cipher
);
4143 static void print_message(const char *s
, long num
, int length
, int tm
)
4147 mr
? "+DT:%s:%d:%d\n"
4148 : "Doing %s for %ds on %d size blocks: ", s
, tm
, length
);
4149 (void)BIO_flush(bio_err
);
4154 mr
? "+DN:%s:%ld:%d\n"
4155 : "Doing %s %ld times on %d size blocks: ", s
, num
, length
);
4156 (void)BIO_flush(bio_err
);
4160 #if !defined(OPENSSL_NO_DEPRECATED_3_0) \
4161 || !defined(OPENSSL_NO_DSA) \
4162 || !defined(OPENSSL_NO_DH) \
4163 || !defined(OPENSSL_NO_EC)
4164 static void pkey_print_message(const char *str
, const char *str2
, long num
,
4165 unsigned int bits
, int tm
)
4169 mr
? "+DTP:%d:%s:%s:%d\n"
4170 : "Doing %u bits %s %s's for %ds: ", bits
, str
, str2
, tm
);
4171 (void)BIO_flush(bio_err
);
4176 mr
? "+DNP:%ld:%d:%s:%s\n"
4177 : "Doing %ld %u bits %s %s's: ", num
, bits
, str
, str2
);
4178 (void)BIO_flush(bio_err
);
4183 static void print_result(int alg
, int run_no
, int count
, double time_used
)
4186 BIO_printf(bio_err
, "%s error!\n", names
[alg
]);
4187 ERR_print_errors(bio_err
);
4188 /* exit(1); disable exit until default provider enabled */
4192 mr
? "+R:%d:%s:%f\n"
4193 : "%d %s's in %.2fs\n", count
, names
[alg
], time_used
);
4194 results
[alg
][run_no
] = ((double)count
) / time_used
* lengths
[run_no
];
4198 static char *sstrsep(char **string
, const char *delim
)
4201 char *token
= *string
;
4206 memset(isdelim
, 0, sizeof(isdelim
));
4210 isdelim
[(unsigned char)(*delim
)] = 1;
4214 while (!isdelim
[(unsigned char)(**string
)]) {
4226 static int do_multi(int multi
, int size_num
)
4231 static char sep
[] = ":";
4233 fds
= app_malloc(sizeof(*fds
) * multi
, "fd buffer for do_multi");
4234 for (n
= 0; n
< multi
; ++n
) {
4235 if (pipe(fd
) == -1) {
4236 BIO_printf(bio_err
, "pipe failure\n");
4240 (void)BIO_flush(bio_err
);
4247 if (dup(fd
[1]) == -1) {
4248 BIO_printf(bio_err
, "dup failed\n");
4257 printf("Forked child %d\n", n
);
4260 /* for now, assume the pipe is long enough to take all the output */
4261 for (n
= 0; n
< multi
; ++n
) {
4266 f
= fdopen(fds
[n
], "r");
4267 while (fgets(buf
, sizeof(buf
), f
)) {
4268 p
= strchr(buf
, '\n');
4271 if (buf
[0] != '+') {
4273 "Don't understand line '%s' from child %d\n", buf
,
4277 printf("Got: %s from %d\n", buf
, n
);
4278 if (strncmp(buf
, "+F:", 3) == 0) {
4283 alg
= atoi(sstrsep(&p
, sep
));
4285 for (j
= 0; j
< size_num
; ++j
)
4286 results
[alg
][j
] += atof(sstrsep(&p
, sep
));
4288 #ifndef OPENSSL_NO_DEPRECATED_3_0
4289 else if (strncmp(buf
, "+F2:", 4) == 0) {
4294 k
= atoi(sstrsep(&p
, sep
));
4297 d
= atof(sstrsep(&p
, sep
));
4298 rsa_results
[k
][0] += d
;
4300 d
= atof(sstrsep(&p
, sep
));
4301 rsa_results
[k
][1] += d
;
4304 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
4305 else if (strncmp(buf
, "+F3:", 4) == 0) {
4310 k
= atoi(sstrsep(&p
, sep
));
4313 d
= atof(sstrsep(&p
, sep
));
4314 dsa_results
[k
][0] += d
;
4316 d
= atof(sstrsep(&p
, sep
));
4317 dsa_results
[k
][1] += d
;
4320 # ifndef OPENSSL_NO_EC
4321 else if (strncmp(buf
, "+F4:", 4) == 0) {
4326 k
= atoi(sstrsep(&p
, sep
));
4329 d
= atof(sstrsep(&p
, sep
));
4330 ecdsa_results
[k
][0] += d
;
4332 d
= atof(sstrsep(&p
, sep
));
4333 ecdsa_results
[k
][1] += d
;
4334 } else if (strncmp(buf
, "+F5:", 4) == 0) {
4339 k
= atoi(sstrsep(&p
, sep
));
4342 d
= atof(sstrsep(&p
, sep
));
4343 ecdh_results
[k
][0] += d
;
4344 } else if (strncmp(buf
, "+F6:", 4) == 0) {
4349 k
= atoi(sstrsep(&p
, sep
));
4353 d
= atof(sstrsep(&p
, sep
));
4354 eddsa_results
[k
][0] += d
;
4356 d
= atof(sstrsep(&p
, sep
));
4357 eddsa_results
[k
][1] += d
;
4359 # ifndef OPENSSL_NO_SM2
4360 else if (strncmp(buf
, "+F7:", 4) == 0) {
4365 k
= atoi(sstrsep(&p
, sep
));
4369 d
= atof(sstrsep(&p
, sep
));
4370 sm2_results
[k
][0] += d
;
4372 d
= atof(sstrsep(&p
, sep
));
4373 sm2_results
[k
][1] += d
;
4375 # endif /* OPENSSL_NO_SM2 */
4376 # endif /* OPENSSL_NO_EC */
4377 # ifndef OPENSSL_NO_DH
4378 else if (strncmp(buf
, "+F8:", 4) == 0) {
4383 k
= atoi(sstrsep(&p
, sep
));
4386 d
= atof(sstrsep(&p
, sep
));
4387 ffdh_results
[k
][0] += d
;
4389 # endif /* OPENSSL_NO_DH */
4391 else if (strncmp(buf
, "+H:", 3) == 0) {
4394 BIO_printf(bio_err
, "Unknown type '%s' from child %d\n", buf
,
4405 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
, int lengths_single
,
4406 const openssl_speed_sec_t
*seconds
)
4408 static const int mblengths_list
[] =
4409 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
4410 const int *mblengths
= mblengths_list
;
4411 int j
, count
, keylen
, num
= OSSL_NELEM(mblengths_list
);
4412 const char *alg_name
;
4413 unsigned char *inp
, *out
, *key
, no_key
[32], no_iv
[16];
4414 EVP_CIPHER_CTX
*ctx
;
4417 if (lengths_single
) {
4418 mblengths
= &lengths_single
;
4422 inp
= app_malloc(mblengths
[num
- 1], "multiblock input buffer");
4423 out
= app_malloc(mblengths
[num
- 1] + 1024, "multiblock output buffer");
4424 ctx
= EVP_CIPHER_CTX_new();
4425 EVP_EncryptInit_ex(ctx
, evp_cipher
, NULL
, NULL
, no_iv
);
4427 keylen
= EVP_CIPHER_CTX_key_length(ctx
);
4428 key
= app_malloc(keylen
, "evp_cipher key");
4429 EVP_CIPHER_CTX_rand_key(ctx
, key
);
4430 EVP_EncryptInit_ex(ctx
, NULL
, NULL
, key
, NULL
);
4431 OPENSSL_clear_free(key
, keylen
);
4433 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_MAC_KEY
, sizeof(no_key
), no_key
);
4434 alg_name
= OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
4436 for (j
= 0; j
< num
; j
++) {
4437 print_message(alg_name
, 0, mblengths
[j
], seconds
->sym
);
4439 for (count
= 0; run
&& count
< 0x7fffffff; count
++) {
4440 unsigned char aad
[EVP_AEAD_TLS1_AAD_LEN
];
4441 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param
;
4442 size_t len
= mblengths
[j
];
4445 memset(aad
, 0, 8); /* avoid uninitialized values */
4446 aad
[8] = 23; /* SSL3_RT_APPLICATION_DATA */
4447 aad
[9] = 3; /* version */
4449 aad
[11] = 0; /* length */
4451 mb_param
.out
= NULL
;
4454 mb_param
.interleave
= 8;
4456 packlen
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD
,
4457 sizeof(mb_param
), &mb_param
);
4463 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT
,
4464 sizeof(mb_param
), &mb_param
);
4468 RAND_bytes(out
, 16);
4470 aad
[11] = (unsigned char)(len
>> 8);
4471 aad
[12] = (unsigned char)(len
);
4472 pad
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_TLS1_AAD
,
4473 EVP_AEAD_TLS1_AAD_LEN
, aad
);
4474 EVP_Cipher(ctx
, out
, inp
, len
+ pad
);
4478 BIO_printf(bio_err
, mr
? "+R:%d:%s:%f\n"
4479 : "%d %s's in %.2fs\n", count
, "evp", d
);
4480 results
[D_EVP
][j
] = ((double)count
) / d
* mblengths
[j
];
4484 fprintf(stdout
, "+H");
4485 for (j
= 0; j
< num
; j
++)
4486 fprintf(stdout
, ":%d", mblengths
[j
]);
4487 fprintf(stdout
, "\n");
4488 fprintf(stdout
, "+F:%d:%s", D_EVP
, alg_name
);
4489 for (j
= 0; j
< num
; j
++)
4490 fprintf(stdout
, ":%.2f", results
[D_EVP
][j
]);
4491 fprintf(stdout
, "\n");
4494 "The 'numbers' are in 1000s of bytes per second processed.\n");
4495 fprintf(stdout
, "type ");
4496 for (j
= 0; j
< num
; j
++)
4497 fprintf(stdout
, "%7d bytes", mblengths
[j
]);
4498 fprintf(stdout
, "\n");
4499 fprintf(stdout
, "%-24s", alg_name
);
4501 for (j
= 0; j
< num
; j
++) {
4502 if (results
[D_EVP
][j
] > 10000)
4503 fprintf(stdout
, " %11.2fk", results
[D_EVP
][j
] / 1e3
);
4505 fprintf(stdout
, " %11.2f ", results
[D_EVP
][j
]);
4507 fprintf(stdout
, "\n");
4512 EVP_CIPHER_CTX_free(ctx
);