2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the OpenSSL license (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
23 #include <openssl/crypto.h>
24 #include <openssl/rand.h>
25 #include <openssl/err.h>
26 #include <openssl/evp.h>
27 #include <openssl/objects.h>
28 #include <openssl/async.h>
29 #if !defined(OPENSSL_SYS_MSDOS)
30 # include OPENSSL_UNISTD
37 #include <openssl/bn.h>
38 #ifndef OPENSSL_NO_DES
39 # include <openssl/des.h>
41 #include <openssl/aes.h>
42 #ifndef OPENSSL_NO_CAMELLIA
43 # include <openssl/camellia.h>
45 #ifndef OPENSSL_NO_MD2
46 # include <openssl/md2.h>
48 #ifndef OPENSSL_NO_MDC2
49 # include <openssl/mdc2.h>
51 #ifndef OPENSSL_NO_MD4
52 # include <openssl/md4.h>
54 #ifndef OPENSSL_NO_MD5
55 # include <openssl/md5.h>
57 #include <openssl/hmac.h>
58 #include <openssl/sha.h>
59 #ifndef OPENSSL_NO_RMD160
60 # include <openssl/ripemd.h>
62 #ifndef OPENSSL_NO_WHIRLPOOL
63 # include <openssl/whrlpool.h>
65 #ifndef OPENSSL_NO_RC4
66 # include <openssl/rc4.h>
68 #ifndef OPENSSL_NO_RC5
69 # include <openssl/rc5.h>
71 #ifndef OPENSSL_NO_RC2
72 # include <openssl/rc2.h>
74 #ifndef OPENSSL_NO_IDEA
75 # include <openssl/idea.h>
77 #ifndef OPENSSL_NO_SEED
78 # include <openssl/seed.h>
81 # include <openssl/blowfish.h>
83 #ifndef OPENSSL_NO_CAST
84 # include <openssl/cast.h>
86 #ifndef OPENSSL_NO_RSA
87 # include <openssl/rsa.h>
88 # include "./testrsa.h"
90 #include <openssl/x509.h>
91 #ifndef OPENSSL_NO_DSA
92 # include <openssl/dsa.h>
93 # include "./testdsa.h"
96 # include <openssl/ec.h>
98 #include <openssl/modes.h>
101 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
114 #define MAX_MISALIGNMENT 63
121 #define MAX_ECDH_SIZE 256
124 typedef struct openssl_speed_sec_st {
130 } openssl_speed_sec_t;
132 static volatile int run = 0;
135 static int usertime = 1;
137 typedef struct loopargs_st {
138 ASYNC_JOB *inprogress_job;
139 ASYNC_WAIT_CTX *wait_ctx;
142 unsigned char *buf_malloc;
143 unsigned char *buf2_malloc;
146 #ifndef OPENSSL_NO_RSA
147 RSA *rsa_key[RSA_NUM];
149 #ifndef OPENSSL_NO_DSA
150 DSA *dsa_key[DSA_NUM];
152 #ifndef OPENSSL_NO_EC
153 EC_KEY *ecdsa[EC_NUM];
154 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
155 unsigned char *secret_a;
156 unsigned char *secret_b;
157 size_t outlen[EC_NUM];
161 GCM128_CONTEXT *gcm_ctx;
164 #ifndef OPENSSL_NO_MD2
165 static int EVP_Digest_MD2_loop(void *args);
168 #ifndef OPENSSL_NO_MDC2
169 static int EVP_Digest_MDC2_loop(void *args);
171 #ifndef OPENSSL_NO_MD4
172 static int EVP_Digest_MD4_loop(void *args);
174 #ifndef OPENSSL_NO_MD5
175 static int MD5_loop(void *args);
176 static int HMAC_loop(void *args);
178 static int SHA1_loop(void *args);
179 static int SHA256_loop(void *args);
180 static int SHA512_loop(void *args);
181 #ifndef OPENSSL_NO_WHIRLPOOL
182 static int WHIRLPOOL_loop(void *args);
184 #ifndef OPENSSL_NO_RMD160
185 static int EVP_Digest_RMD160_loop(void *args);
187 #ifndef OPENSSL_NO_RC4
188 static int RC4_loop(void *args);
190 #ifndef OPENSSL_NO_DES
191 static int DES_ncbc_encrypt_loop(void *args);
192 static int DES_ede3_cbc_encrypt_loop(void *args);
194 static int AES_cbc_128_encrypt_loop(void *args);
195 static int AES_cbc_192_encrypt_loop(void *args);
196 static int AES_ige_128_encrypt_loop(void *args);
197 static int AES_cbc_256_encrypt_loop(void *args);
198 static int AES_ige_192_encrypt_loop(void *args);
199 static int AES_ige_256_encrypt_loop(void *args);
200 static int CRYPTO_gcm128_aad_loop(void *args);
201 static int RAND_bytes_loop(void *args);
202 static int EVP_Update_loop(void *args);
203 static int EVP_Update_loop_ccm(void *args);
204 static int EVP_Digest_loop(void *args);
205 #ifndef OPENSSL_NO_RSA
206 static int RSA_sign_loop(void *args);
207 static int RSA_verify_loop(void *args);
209 #ifndef OPENSSL_NO_DSA
210 static int DSA_sign_loop(void *args);
211 static int DSA_verify_loop(void *args);
213 #ifndef OPENSSL_NO_EC
214 static int ECDSA_sign_loop(void *args);
215 static int ECDSA_verify_loop(void *args);
217 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
218 loopargs_t * loopargs);
220 static double Time_F(int s);
221 static void print_message(const char *s, long num, int length, int tm);
222 static void pkey_print_message(const char *str, const char *str2,
223 long num, int bits, int sec);
224 static void print_result(int alg, int run_no, int count, double time_used);
226 static int do_multi(int multi, int size_num);
229 static const int lengths_list[] = {
230 16, 64, 256, 1024, 8 * 1024, 16 * 1024
232 static int lengths_single = 0;
234 static const int *lengths = lengths_list;
236 static const char *names[ALGOR_NUM] = {
237 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
238 "des cbc", "des ede3", "idea cbc", "seed cbc",
239 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
240 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
241 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
242 "evp", "sha256", "sha512", "whirlpool",
243 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
247 static double results[ALGOR_NUM][OSSL_NELEM(lengths_list)];
249 #ifndef OPENSSL_NO_RSA
250 static double rsa_results[RSA_NUM][2];
252 #ifndef OPENSSL_NO_DSA
253 static double dsa_results[DSA_NUM][2];
255 #ifndef OPENSSL_NO_EC
256 static double ecdsa_results[EC_NUM][2];
257 static double ecdh_results[EC_NUM][1];
261 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
262 # define SIGRETTYPE void
264 # define SIGRETTYPE int
267 static SIGRETTYPE sig_done(int sig);
268 static SIGRETTYPE sig_done(int sig)
270 signal(SIGALRM, sig_done);
280 # if !defined(SIGALRM)
283 static unsigned int lapse;
284 static volatile unsigned int schlock;
285 static void alarm_win32(unsigned int secs)
290 # define alarm alarm_win32
292 static DWORD WINAPI sleepy(VOID * arg)
300 static double Time_F(int s)
307 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
309 DWORD err = GetLastError();
310 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
314 Sleep(0); /* scheduler spinlock */
315 ret = app_tminterval(s, usertime);
317 ret = app_tminterval(s, usertime);
319 TerminateThread(thr, 0);
327 static double Time_F(int s)
329 double ret = app_tminterval(s, usertime);
336 static void multiblock_speed(const EVP_CIPHER *evp_cipher,
337 const openssl_speed_sec_t *seconds);
339 static int found(const char *name, const OPT_PAIR *pairs, int *result)
341 for (; pairs->name; pairs++)
342 if (strcmp(name, pairs->name) == 0) {
343 *result = pairs->retval;
349 typedef enum OPTION_choice {
350 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
351 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
352 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
353 OPT_PRIMES, OPT_SECONDS, OPT_BYTES
356 const OPTIONS speed_options[] = {
357 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
358 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
359 {"help", OPT_HELP, '-', "Display this summary"},
360 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
361 {"decrypt", OPT_DECRYPT, '-',
362 "Time decryption instead of encryption (only EVP)"},
363 {"mr", OPT_MR, '-', "Produce machine readable output"},
365 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
366 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
367 {"elapsed", OPT_ELAPSED, '-',
368 "Measure time in real time instead of CPU user time"},
370 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
372 #ifndef OPENSSL_NO_ASYNC
373 {"async_jobs", OPT_ASYNCJOBS, 'p',
374 "Enable async mode and start pnum jobs"},
377 #ifndef OPENSSL_NO_ENGINE
378 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
380 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
381 {"seconds", OPT_SECONDS, 'p',
382 "Run benchmarks for pnum seconds"},
383 {"bytes", OPT_BYTES, 'p',
384 "Run cipher, digest and rand benchmarks on pnum bytes"},
398 #define D_CBC_IDEA 10
399 #define D_CBC_SEED 11
403 #define D_CBC_CAST 15
404 #define D_CBC_128_AES 16
405 #define D_CBC_192_AES 17
406 #define D_CBC_256_AES 18
407 #define D_CBC_128_CML 19
408 #define D_CBC_192_CML 20
409 #define D_CBC_256_CML 21
413 #define D_WHIRLPOOL 25
414 #define D_IGE_128_AES 26
415 #define D_IGE_192_AES 27
416 #define D_IGE_256_AES 28
419 static OPT_PAIR doit_choices[] = {
420 #ifndef OPENSSL_NO_MD2
423 #ifndef OPENSSL_NO_MDC2
426 #ifndef OPENSSL_NO_MD4
429 #ifndef OPENSSL_NO_MD5
434 {"sha256", D_SHA256},
435 {"sha512", D_SHA512},
436 #ifndef OPENSSL_NO_WHIRLPOOL
437 {"whirlpool", D_WHIRLPOOL},
439 #ifndef OPENSSL_NO_RMD160
440 {"ripemd", D_RMD160},
441 {"rmd160", D_RMD160},
442 {"ripemd160", D_RMD160},
444 #ifndef OPENSSL_NO_RC4
447 #ifndef OPENSSL_NO_DES
448 {"des-cbc", D_CBC_DES},
449 {"des-ede3", D_EDE3_DES},
451 {"aes-128-cbc", D_CBC_128_AES},
452 {"aes-192-cbc", D_CBC_192_AES},
453 {"aes-256-cbc", D_CBC_256_AES},
454 {"aes-128-ige", D_IGE_128_AES},
455 {"aes-192-ige", D_IGE_192_AES},
456 {"aes-256-ige", D_IGE_256_AES},
457 #ifndef OPENSSL_NO_RC2
458 {"rc2-cbc", D_CBC_RC2},
461 #ifndef OPENSSL_NO_RC5
462 {"rc5-cbc", D_CBC_RC5},
465 #ifndef OPENSSL_NO_IDEA
466 {"idea-cbc", D_CBC_IDEA},
467 {"idea", D_CBC_IDEA},
469 #ifndef OPENSSL_NO_SEED
470 {"seed-cbc", D_CBC_SEED},
471 {"seed", D_CBC_SEED},
473 #ifndef OPENSSL_NO_BF
474 {"bf-cbc", D_CBC_BF},
475 {"blowfish", D_CBC_BF},
478 #ifndef OPENSSL_NO_CAST
479 {"cast-cbc", D_CBC_CAST},
480 {"cast", D_CBC_CAST},
481 {"cast5", D_CBC_CAST},
488 #ifndef OPENSSL_NO_DSA
490 # define R_DSA_1024 1
491 # define R_DSA_2048 2
492 static OPT_PAIR dsa_choices[] = {
493 {"dsa512", R_DSA_512},
494 {"dsa1024", R_DSA_1024},
495 {"dsa2048", R_DSA_2048},
506 #define R_RSA_15360 6
507 static OPT_PAIR rsa_choices[] = {
508 {"rsa512", R_RSA_512},
509 {"rsa1024", R_RSA_1024},
510 {"rsa2048", R_RSA_2048},
511 {"rsa3072", R_RSA_3072},
512 {"rsa4096", R_RSA_4096},
513 {"rsa7680", R_RSA_7680},
514 {"rsa15360", R_RSA_15360},
534 #define R_EC_X25519 16
535 #ifndef OPENSSL_NO_EC
536 static OPT_PAIR ecdsa_choices[] = {
537 {"ecdsap160", R_EC_P160},
538 {"ecdsap192", R_EC_P192},
539 {"ecdsap224", R_EC_P224},
540 {"ecdsap256", R_EC_P256},
541 {"ecdsap384", R_EC_P384},
542 {"ecdsap521", R_EC_P521},
543 {"ecdsak163", R_EC_K163},
544 {"ecdsak233", R_EC_K233},
545 {"ecdsak283", R_EC_K283},
546 {"ecdsak409", R_EC_K409},
547 {"ecdsak571", R_EC_K571},
548 {"ecdsab163", R_EC_B163},
549 {"ecdsab233", R_EC_B233},
550 {"ecdsab283", R_EC_B283},
551 {"ecdsab409", R_EC_B409},
552 {"ecdsab571", R_EC_B571},
556 static OPT_PAIR ecdh_choices[] = {
557 {"ecdhp160", R_EC_P160},
558 {"ecdhp192", R_EC_P192},
559 {"ecdhp224", R_EC_P224},
560 {"ecdhp256", R_EC_P256},
561 {"ecdhp384", R_EC_P384},
562 {"ecdhp521", R_EC_P521},
563 {"ecdhk163", R_EC_K163},
564 {"ecdhk233", R_EC_K233},
565 {"ecdhk283", R_EC_K283},
566 {"ecdhk409", R_EC_K409},
567 {"ecdhk571", R_EC_K571},
568 {"ecdhb163", R_EC_B163},
569 {"ecdhb233", R_EC_B233},
570 {"ecdhb283", R_EC_B283},
571 {"ecdhb409", R_EC_B409},
572 {"ecdhb571", R_EC_B571},
573 {"ecdhx25519", R_EC_X25519},
579 # define COND(d) (count < (d))
580 # define COUNT(d) (d)
582 # define COND(unused_cond) (run && count<0x7fffffff)
583 # define COUNT(d) (count)
588 /* Nb of iterations to do per algorithm and key-size */
589 static long c[ALGOR_NUM][OSSL_NELEM(lengths_list)];
591 #ifndef OPENSSL_NO_MD2
592 static int EVP_Digest_MD2_loop(void *args)
594 loopargs_t *tempargs = *(loopargs_t **) args;
595 unsigned char *buf = tempargs->buf;
596 unsigned char md2[MD2_DIGEST_LENGTH];
599 for (count = 0; COND(c[D_MD2][testnum]); count++) {
600 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
608 #ifndef OPENSSL_NO_MDC2
609 static int EVP_Digest_MDC2_loop(void *args)
611 loopargs_t *tempargs = *(loopargs_t **) args;
612 unsigned char *buf = tempargs->buf;
613 unsigned char mdc2[MDC2_DIGEST_LENGTH];
616 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
617 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
625 #ifndef OPENSSL_NO_MD4
626 static int EVP_Digest_MD4_loop(void *args)
628 loopargs_t *tempargs = *(loopargs_t **) args;
629 unsigned char *buf = tempargs->buf;
630 unsigned char md4[MD4_DIGEST_LENGTH];
633 for (count = 0; COND(c[D_MD4][testnum]); count++) {
634 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
642 #ifndef OPENSSL_NO_MD5
643 static int MD5_loop(void *args)
645 loopargs_t *tempargs = *(loopargs_t **) args;
646 unsigned char *buf = tempargs->buf;
647 unsigned char md5[MD5_DIGEST_LENGTH];
649 for (count = 0; COND(c[D_MD5][testnum]); count++)
650 MD5(buf, lengths[testnum], md5);
654 static int HMAC_loop(void *args)
656 loopargs_t *tempargs = *(loopargs_t **) args;
657 unsigned char *buf = tempargs->buf;
658 HMAC_CTX *hctx = tempargs->hctx;
659 unsigned char hmac[MD5_DIGEST_LENGTH];
662 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
663 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
664 HMAC_Update(hctx, buf, lengths[testnum]);
665 HMAC_Final(hctx, hmac, NULL);
671 static int SHA1_loop(void *args)
673 loopargs_t *tempargs = *(loopargs_t **) args;
674 unsigned char *buf = tempargs->buf;
675 unsigned char sha[SHA_DIGEST_LENGTH];
677 for (count = 0; COND(c[D_SHA1][testnum]); count++)
678 SHA1(buf, lengths[testnum], sha);
682 static int SHA256_loop(void *args)
684 loopargs_t *tempargs = *(loopargs_t **) args;
685 unsigned char *buf = tempargs->buf;
686 unsigned char sha256[SHA256_DIGEST_LENGTH];
688 for (count = 0; COND(c[D_SHA256][testnum]); count++)
689 SHA256(buf, lengths[testnum], sha256);
693 static int SHA512_loop(void *args)
695 loopargs_t *tempargs = *(loopargs_t **) args;
696 unsigned char *buf = tempargs->buf;
697 unsigned char sha512[SHA512_DIGEST_LENGTH];
699 for (count = 0; COND(c[D_SHA512][testnum]); count++)
700 SHA512(buf, lengths[testnum], sha512);
704 #ifndef OPENSSL_NO_WHIRLPOOL
705 static int WHIRLPOOL_loop(void *args)
707 loopargs_t *tempargs = *(loopargs_t **) args;
708 unsigned char *buf = tempargs->buf;
709 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
711 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
712 WHIRLPOOL(buf, lengths[testnum], whirlpool);
717 #ifndef OPENSSL_NO_RMD160
718 static int EVP_Digest_RMD160_loop(void *args)
720 loopargs_t *tempargs = *(loopargs_t **) args;
721 unsigned char *buf = tempargs->buf;
722 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
724 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
725 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
726 NULL, EVP_ripemd160(), NULL))
733 #ifndef OPENSSL_NO_RC4
734 static RC4_KEY rc4_ks;
735 static int RC4_loop(void *args)
737 loopargs_t *tempargs = *(loopargs_t **) args;
738 unsigned char *buf = tempargs->buf;
740 for (count = 0; COND(c[D_RC4][testnum]); count++)
741 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
746 #ifndef OPENSSL_NO_DES
747 static unsigned char DES_iv[8];
748 static DES_key_schedule sch;
749 static DES_key_schedule sch2;
750 static DES_key_schedule sch3;
751 static int DES_ncbc_encrypt_loop(void *args)
753 loopargs_t *tempargs = *(loopargs_t **) args;
754 unsigned char *buf = tempargs->buf;
756 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
757 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
758 &DES_iv, DES_ENCRYPT);
762 static int DES_ede3_cbc_encrypt_loop(void *args)
764 loopargs_t *tempargs = *(loopargs_t **) args;
765 unsigned char *buf = tempargs->buf;
767 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
768 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
769 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
774 #define MAX_BLOCK_SIZE 128
776 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
777 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
778 static int AES_cbc_128_encrypt_loop(void *args)
780 loopargs_t *tempargs = *(loopargs_t **) args;
781 unsigned char *buf = tempargs->buf;
783 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
784 AES_cbc_encrypt(buf, buf,
785 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
789 static int AES_cbc_192_encrypt_loop(void *args)
791 loopargs_t *tempargs = *(loopargs_t **) args;
792 unsigned char *buf = tempargs->buf;
794 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
795 AES_cbc_encrypt(buf, buf,
796 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
800 static int AES_cbc_256_encrypt_loop(void *args)
802 loopargs_t *tempargs = *(loopargs_t **) args;
803 unsigned char *buf = tempargs->buf;
805 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
806 AES_cbc_encrypt(buf, buf,
807 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
811 static int AES_ige_128_encrypt_loop(void *args)
813 loopargs_t *tempargs = *(loopargs_t **) args;
814 unsigned char *buf = tempargs->buf;
815 unsigned char *buf2 = tempargs->buf2;
817 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
818 AES_ige_encrypt(buf, buf2,
819 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
823 static int AES_ige_192_encrypt_loop(void *args)
825 loopargs_t *tempargs = *(loopargs_t **) args;
826 unsigned char *buf = tempargs->buf;
827 unsigned char *buf2 = tempargs->buf2;
829 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
830 AES_ige_encrypt(buf, buf2,
831 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
835 static int AES_ige_256_encrypt_loop(void *args)
837 loopargs_t *tempargs = *(loopargs_t **) args;
838 unsigned char *buf = tempargs->buf;
839 unsigned char *buf2 = tempargs->buf2;
841 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
842 AES_ige_encrypt(buf, buf2,
843 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
847 static int CRYPTO_gcm128_aad_loop(void *args)
849 loopargs_t *tempargs = *(loopargs_t **) args;
850 unsigned char *buf = tempargs->buf;
851 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
853 for (count = 0; COND(c[D_GHASH][testnum]); count++)
854 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
858 static int RAND_bytes_loop(void *args)
860 loopargs_t *tempargs = *(loopargs_t **) args;
861 unsigned char *buf = tempargs->buf;
864 for (count = 0; COND(c[D_RAND][testnum]); count++)
865 RAND_bytes(buf, lengths[testnum]);
869 static long save_count = 0;
870 static int decrypt = 0;
871 static int EVP_Update_loop(void *args)
873 loopargs_t *tempargs = *(loopargs_t **) args;
874 unsigned char *buf = tempargs->buf;
875 EVP_CIPHER_CTX *ctx = tempargs->ctx;
878 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
881 for (count = 0; COND(nb_iter); count++) {
882 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
884 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
887 for (count = 0; COND(nb_iter); count++) {
888 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
890 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
894 EVP_DecryptFinal_ex(ctx, buf, &outl);
896 EVP_EncryptFinal_ex(ctx, buf, &outl);
900 * CCM does not support streaming. For the purpose of performance measurement,
901 * each message is encrypted using the same (key,iv)-pair. Do not use this
902 * code in your application.
904 static int EVP_Update_loop_ccm(void *args)
906 loopargs_t *tempargs = *(loopargs_t **) args;
907 unsigned char *buf = tempargs->buf;
908 EVP_CIPHER_CTX *ctx = tempargs->ctx;
910 unsigned char tag[12];
912 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
915 for (count = 0; COND(nb_iter); count++) {
916 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
917 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
918 EVP_DecryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
919 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
920 EVP_DecryptFinal_ex(ctx, buf, &outl);
923 for (count = 0; COND(nb_iter); count++) {
924 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
925 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
926 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
927 EVP_EncryptFinal_ex(ctx, buf, &outl);
933 static const EVP_MD *evp_md = NULL;
934 static int EVP_Digest_loop(void *args)
936 loopargs_t *tempargs = *(loopargs_t **) args;
937 unsigned char *buf = tempargs->buf;
938 unsigned char md[EVP_MAX_MD_SIZE];
941 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
944 for (count = 0; COND(nb_iter); count++) {
945 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
951 #ifndef OPENSSL_NO_RSA
952 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
954 static int RSA_sign_loop(void *args)
956 loopargs_t *tempargs = *(loopargs_t **) args;
957 unsigned char *buf = tempargs->buf;
958 unsigned char *buf2 = tempargs->buf2;
959 unsigned int *rsa_num = &tempargs->siglen;
960 RSA **rsa_key = tempargs->rsa_key;
962 for (count = 0; COND(rsa_c[testnum][0]); count++) {
963 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
965 BIO_printf(bio_err, "RSA sign failure\n");
966 ERR_print_errors(bio_err);
974 static int RSA_verify_loop(void *args)
976 loopargs_t *tempargs = *(loopargs_t **) args;
977 unsigned char *buf = tempargs->buf;
978 unsigned char *buf2 = tempargs->buf2;
979 unsigned int rsa_num = tempargs->siglen;
980 RSA **rsa_key = tempargs->rsa_key;
982 for (count = 0; COND(rsa_c[testnum][1]); count++) {
984 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
986 BIO_printf(bio_err, "RSA verify failure\n");
987 ERR_print_errors(bio_err);
996 #ifndef OPENSSL_NO_DSA
997 static long dsa_c[DSA_NUM][2];
998 static int DSA_sign_loop(void *args)
1000 loopargs_t *tempargs = *(loopargs_t **) args;
1001 unsigned char *buf = tempargs->buf;
1002 unsigned char *buf2 = tempargs->buf2;
1003 DSA **dsa_key = tempargs->dsa_key;
1004 unsigned int *siglen = &tempargs->siglen;
1006 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1007 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1009 BIO_printf(bio_err, "DSA sign failure\n");
1010 ERR_print_errors(bio_err);
1018 static int DSA_verify_loop(void *args)
1020 loopargs_t *tempargs = *(loopargs_t **) args;
1021 unsigned char *buf = tempargs->buf;
1022 unsigned char *buf2 = tempargs->buf2;
1023 DSA **dsa_key = tempargs->dsa_key;
1024 unsigned int siglen = tempargs->siglen;
1026 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1027 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1029 BIO_printf(bio_err, "DSA verify failure\n");
1030 ERR_print_errors(bio_err);
1039 #ifndef OPENSSL_NO_EC
1040 static long ecdsa_c[EC_NUM][2];
1041 static int ECDSA_sign_loop(void *args)
1043 loopargs_t *tempargs = *(loopargs_t **) args;
1044 unsigned char *buf = tempargs->buf;
1045 EC_KEY **ecdsa = tempargs->ecdsa;
1046 unsigned char *ecdsasig = tempargs->buf2;
1047 unsigned int *ecdsasiglen = &tempargs->siglen;
1049 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1050 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1052 BIO_printf(bio_err, "ECDSA sign failure\n");
1053 ERR_print_errors(bio_err);
1061 static int ECDSA_verify_loop(void *args)
1063 loopargs_t *tempargs = *(loopargs_t **) args;
1064 unsigned char *buf = tempargs->buf;
1065 EC_KEY **ecdsa = tempargs->ecdsa;
1066 unsigned char *ecdsasig = tempargs->buf2;
1067 unsigned int ecdsasiglen = tempargs->siglen;
1069 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1070 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1072 BIO_printf(bio_err, "ECDSA verify failure\n");
1073 ERR_print_errors(bio_err);
1081 /* ******************************************************************** */
1082 static long ecdh_c[EC_NUM][1];
1084 static int ECDH_EVP_derive_key_loop(void *args)
1086 loopargs_t *tempargs = *(loopargs_t **) args;
1087 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1088 unsigned char *derived_secret = tempargs->secret_a;
1090 size_t *outlen = &(tempargs->outlen[testnum]);
1092 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1093 EVP_PKEY_derive(ctx, derived_secret, outlen);
1098 #endif /* OPENSSL_NO_EC */
1100 static int run_benchmark(int async_jobs,
1101 int (*loop_function) (void *), loopargs_t * loopargs)
1103 int job_op_count = 0;
1104 int total_op_count = 0;
1105 int num_inprogress = 0;
1106 int error = 0, i = 0, ret = 0;
1107 OSSL_ASYNC_FD job_fd = 0;
1108 size_t num_job_fds = 0;
1112 if (async_jobs == 0) {
1113 return loop_function((void *)&loopargs);
1116 for (i = 0; i < async_jobs && !error; i++) {
1117 loopargs_t *looparg_item = loopargs + i;
1119 /* Copy pointer content (looparg_t item address) into async context */
1120 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1121 &job_op_count, loop_function,
1122 (void *)&looparg_item, sizeof(looparg_item));
1128 if (job_op_count == -1) {
1131 total_op_count += job_op_count;
1136 BIO_printf(bio_err, "Failure in the job\n");
1137 ERR_print_errors(bio_err);
1143 while (num_inprogress > 0) {
1144 #if defined(OPENSSL_SYS_WINDOWS)
1146 #elif defined(OPENSSL_SYS_UNIX)
1147 int select_result = 0;
1148 OSSL_ASYNC_FD max_fd = 0;
1151 FD_ZERO(&waitfdset);
1153 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1154 if (loopargs[i].inprogress_job == NULL)
1157 if (!ASYNC_WAIT_CTX_get_all_fds
1158 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1159 || num_job_fds > 1) {
1160 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1161 ERR_print_errors(bio_err);
1165 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1167 FD_SET(job_fd, &waitfdset);
1168 if (job_fd > max_fd)
1172 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1174 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1175 "Decrease the value of async_jobs\n",
1176 max_fd, FD_SETSIZE);
1177 ERR_print_errors(bio_err);
1182 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1183 if (select_result == -1 && errno == EINTR)
1186 if (select_result == -1) {
1187 BIO_printf(bio_err, "Failure in the select\n");
1188 ERR_print_errors(bio_err);
1193 if (select_result == 0)
1197 for (i = 0; i < async_jobs; i++) {
1198 if (loopargs[i].inprogress_job == NULL)
1201 if (!ASYNC_WAIT_CTX_get_all_fds
1202 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1203 || num_job_fds > 1) {
1204 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1205 ERR_print_errors(bio_err);
1209 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1212 #if defined(OPENSSL_SYS_UNIX)
1213 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1215 #elif defined(OPENSSL_SYS_WINDOWS)
1216 if (num_job_fds == 1
1217 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1222 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1223 loopargs[i].wait_ctx, &job_op_count,
1224 loop_function, (void *)(loopargs + i),
1225 sizeof(loopargs_t));
1230 if (job_op_count == -1) {
1233 total_op_count += job_op_count;
1236 loopargs[i].inprogress_job = NULL;
1241 loopargs[i].inprogress_job = NULL;
1242 BIO_printf(bio_err, "Failure in the job\n");
1243 ERR_print_errors(bio_err);
1250 return error ? -1 : total_op_count;
1253 int speed_main(int argc, char **argv)
1256 int (*loopfunc)(void *args);
1257 loopargs_t *loopargs = NULL;
1259 int loopargs_len = 0;
1261 const char *engine_id = NULL;
1262 const EVP_CIPHER *evp_cipher = NULL;
1265 int multiblock = 0, pr_header = 0;
1266 int doit[ALGOR_NUM] = { 0 };
1267 int ret = 1, i, k, misalign = 0;
1269 int size_num = OSSL_NELEM(lengths_list);
1275 unsigned int async_jobs = 0;
1276 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1277 || !defined(OPENSSL_NO_EC)
1281 /* What follows are the buffers and key material. */
1282 #ifndef OPENSSL_NO_RC5
1285 #ifndef OPENSSL_NO_RC2
1288 #ifndef OPENSSL_NO_IDEA
1289 IDEA_KEY_SCHEDULE idea_ks;
1291 #ifndef OPENSSL_NO_SEED
1292 SEED_KEY_SCHEDULE seed_ks;
1294 #ifndef OPENSSL_NO_BF
1297 #ifndef OPENSSL_NO_CAST
1300 static const unsigned char key16[16] = {
1301 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1302 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1304 static const unsigned char key24[24] = {
1305 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1306 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1307 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1309 static const unsigned char key32[32] = {
1310 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1311 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1312 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1313 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1315 #ifndef OPENSSL_NO_CAMELLIA
1316 static const unsigned char ckey24[24] = {
1317 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1318 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1319 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1321 static const unsigned char ckey32[32] = {
1322 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1323 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1324 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1325 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1327 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1329 #ifndef OPENSSL_NO_DES
1330 static DES_cblock key = {
1331 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1333 static DES_cblock key2 = {
1334 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1336 static DES_cblock key3 = {
1337 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1340 #ifndef OPENSSL_NO_RSA
1341 static const unsigned int rsa_bits[RSA_NUM] = {
1342 512, 1024, 2048, 3072, 4096, 7680, 15360
1344 static const unsigned char *rsa_data[RSA_NUM] = {
1345 test512, test1024, test2048, test3072, test4096, test7680, test15360
1347 static const int rsa_data_length[RSA_NUM] = {
1348 sizeof(test512), sizeof(test1024),
1349 sizeof(test2048), sizeof(test3072),
1350 sizeof(test4096), sizeof(test7680),
1353 int rsa_doit[RSA_NUM] = { 0 };
1354 int primes = RSA_DEFAULT_PRIME_NUM;
1356 #ifndef OPENSSL_NO_DSA
1357 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1358 int dsa_doit[DSA_NUM] = { 0 };
1360 #ifndef OPENSSL_NO_EC
1362 * We only test over the following curves as they are representative, To
1363 * add tests over more curves, simply add the curve NID and curve name to
1364 * the following arrays and increase the EC_NUM value accordingly.
1366 static const unsigned int test_curves[EC_NUM] = {
1368 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1369 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1371 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1372 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1373 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1378 static const char *test_curves_names[EC_NUM] = {
1380 "secp160r1", "nistp192", "nistp224",
1381 "nistp256", "nistp384", "nistp521",
1383 "nistk163", "nistk233", "nistk283",
1384 "nistk409", "nistk571", "nistb163",
1385 "nistb233", "nistb283", "nistb409",
1390 static const int test_curves_bits[EC_NUM] = {
1396 571, 253 /* X25519 */
1399 int ecdsa_doit[EC_NUM] = { 0 };
1400 int ecdh_doit[EC_NUM] = { 0 };
1401 #endif /* ndef OPENSSL_NO_EC */
1403 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1404 ECDSA_SECONDS, ECDH_SECONDS };
1406 prog = opt_init(argc, argv, speed_options);
1407 while ((o = opt_next()) != OPT_EOF) {
1412 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1415 opt_help(speed_options);
1423 evp_cipher = EVP_get_cipherbyname(opt_arg());
1424 if (evp_cipher == NULL)
1425 evp_md = EVP_get_digestbyname(opt_arg());
1426 if (evp_cipher == NULL && evp_md == NULL) {
1428 "%s: %s is an unknown cipher or digest\n",
1439 * In a forked execution, an engine might need to be
1440 * initialised by each child process, not by the parent.
1441 * So store the name here and run setup_engine() later on.
1443 engine_id = opt_arg();
1447 multi = atoi(opt_arg());
1451 #ifndef OPENSSL_NO_ASYNC
1452 async_jobs = atoi(opt_arg());
1453 if (!ASYNC_is_capable()) {
1455 "%s: async_jobs specified but async not supported\n",
1459 if (async_jobs > 99999) {
1461 "%s: too many async_jobs\n",
1468 if (!opt_int(opt_arg(), &misalign))
1470 if (misalign > MISALIGN) {
1472 "%s: Maximum offset is %d\n", prog, MISALIGN);
1481 #ifdef OPENSSL_NO_MULTIBLOCK
1483 "%s: -mb specified but multi-block support is disabled\n",
1493 if (!opt_int(opt_arg(), &primes))
1497 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1498 = seconds.ecdh = atoi(opt_arg());
1501 lengths_single = atoi(opt_arg());
1502 lengths = &lengths_single;
1507 argc = opt_num_rest();
1510 /* Remaining arguments are algorithms. */
1511 for (; *argv; argv++) {
1512 if (found(*argv, doit_choices, &i)) {
1516 #ifndef OPENSSL_NO_DES
1517 if (strcmp(*argv, "des") == 0) {
1518 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1522 if (strcmp(*argv, "sha") == 0) {
1523 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1526 #ifndef OPENSSL_NO_RSA
1527 if (strcmp(*argv, "openssl") == 0)
1529 if (strcmp(*argv, "rsa") == 0) {
1530 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1531 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1532 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1533 rsa_doit[R_RSA_15360] = 1;
1536 if (found(*argv, rsa_choices, &i)) {
1541 #ifndef OPENSSL_NO_DSA
1542 if (strcmp(*argv, "dsa") == 0) {
1543 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1544 dsa_doit[R_DSA_2048] = 1;
1547 if (found(*argv, dsa_choices, &i)) {
1552 if (strcmp(*argv, "aes") == 0) {
1553 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1556 #ifndef OPENSSL_NO_CAMELLIA
1557 if (strcmp(*argv, "camellia") == 0) {
1558 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1562 #ifndef OPENSSL_NO_EC
1563 if (strcmp(*argv, "ecdsa") == 0) {
1564 for (i = 0; i < EC_NUM; i++)
1568 if (found(*argv, ecdsa_choices, &i)) {
1572 if (strcmp(*argv, "ecdh") == 0) {
1573 for (i = 0; i < EC_NUM; i++)
1577 if (found(*argv, ecdh_choices, &i)) {
1582 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1586 /* Initialize the job pool if async mode is enabled */
1587 if (async_jobs > 0) {
1588 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1590 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1595 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1597 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1598 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1600 for (i = 0; i < loopargs_len; i++) {
1601 if (async_jobs > 0) {
1602 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1603 if (loopargs[i].wait_ctx == NULL) {
1604 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1609 buflen = lengths[size_num - 1] + MAX_MISALIGNMENT + 1;
1610 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1611 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1612 memset(loopargs[i].buf_malloc, 0, buflen);
1613 memset(loopargs[i].buf2_malloc, 0, buflen);
1615 /* Align the start of buffers on a 64 byte boundary */
1616 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1617 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1618 #ifndef OPENSSL_NO_EC
1619 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1620 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1625 if (multi && do_multi(multi, size_num))
1629 /* Initialize the engine after the fork */
1630 e = setup_engine(engine_id, 0);
1632 /* No parameters; turn on everything. */
1633 if ((argc == 0) && !doit[D_EVP]) {
1634 for (i = 0; i < ALGOR_NUM; i++)
1637 #ifndef OPENSSL_NO_RSA
1638 for (i = 0; i < RSA_NUM; i++)
1641 #ifndef OPENSSL_NO_DSA
1642 for (i = 0; i < DSA_NUM; i++)
1645 #ifndef OPENSSL_NO_EC
1646 for (i = 0; i < EC_NUM; i++)
1648 for (i = 0; i < EC_NUM; i++)
1652 for (i = 0; i < ALGOR_NUM; i++)
1656 if (usertime == 0 && !mr)
1658 "You have chosen to measure elapsed time "
1659 "instead of user CPU time.\n");
1661 #ifndef OPENSSL_NO_RSA
1662 for (i = 0; i < loopargs_len; i++) {
1663 if (primes > RSA_DEFAULT_PRIME_NUM) {
1664 /* for multi-prime RSA, skip this */
1667 for (k = 0; k < RSA_NUM; k++) {
1668 const unsigned char *p;
1671 loopargs[i].rsa_key[k] =
1672 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1673 if (loopargs[i].rsa_key[k] == NULL) {
1675 "internal error loading RSA key number %d\n", k);
1681 #ifndef OPENSSL_NO_DSA
1682 for (i = 0; i < loopargs_len; i++) {
1683 loopargs[i].dsa_key[0] = get_dsa(512);
1684 loopargs[i].dsa_key[1] = get_dsa(1024);
1685 loopargs[i].dsa_key[2] = get_dsa(2048);
1688 #ifndef OPENSSL_NO_DES
1689 DES_set_key_unchecked(&key, &sch);
1690 DES_set_key_unchecked(&key2, &sch2);
1691 DES_set_key_unchecked(&key3, &sch3);
1693 AES_set_encrypt_key(key16, 128, &aes_ks1);
1694 AES_set_encrypt_key(key24, 192, &aes_ks2);
1695 AES_set_encrypt_key(key32, 256, &aes_ks3);
1696 #ifndef OPENSSL_NO_CAMELLIA
1697 Camellia_set_key(key16, 128, &camellia_ks1);
1698 Camellia_set_key(ckey24, 192, &camellia_ks2);
1699 Camellia_set_key(ckey32, 256, &camellia_ks3);
1701 #ifndef OPENSSL_NO_IDEA
1702 IDEA_set_encrypt_key(key16, &idea_ks);
1704 #ifndef OPENSSL_NO_SEED
1705 SEED_set_key(key16, &seed_ks);
1707 #ifndef OPENSSL_NO_RC4
1708 RC4_set_key(&rc4_ks, 16, key16);
1710 #ifndef OPENSSL_NO_RC2
1711 RC2_set_key(&rc2_ks, 16, key16, 128);
1713 #ifndef OPENSSL_NO_RC5
1714 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1716 #ifndef OPENSSL_NO_BF
1717 BF_set_key(&bf_ks, 16, key16);
1719 #ifndef OPENSSL_NO_CAST
1720 CAST_set_key(&cast_ks, 16, key16);
1723 # ifndef OPENSSL_NO_DES
1724 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1730 for (it = count; it; it--)
1731 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1732 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1736 c[D_MD2][0] = count / 10;
1737 c[D_MDC2][0] = count / 10;
1738 c[D_MD4][0] = count;
1739 c[D_MD5][0] = count;
1740 c[D_HMAC][0] = count;
1741 c[D_SHA1][0] = count;
1742 c[D_RMD160][0] = count;
1743 c[D_RC4][0] = count * 5;
1744 c[D_CBC_DES][0] = count;
1745 c[D_EDE3_DES][0] = count / 3;
1746 c[D_CBC_IDEA][0] = count;
1747 c[D_CBC_SEED][0] = count;
1748 c[D_CBC_RC2][0] = count;
1749 c[D_CBC_RC5][0] = count;
1750 c[D_CBC_BF][0] = count;
1751 c[D_CBC_CAST][0] = count;
1752 c[D_CBC_128_AES][0] = count;
1753 c[D_CBC_192_AES][0] = count;
1754 c[D_CBC_256_AES][0] = count;
1755 c[D_CBC_128_CML][0] = count;
1756 c[D_CBC_192_CML][0] = count;
1757 c[D_CBC_256_CML][0] = count;
1758 c[D_SHA256][0] = count;
1759 c[D_SHA512][0] = count;
1760 c[D_WHIRLPOOL][0] = count;
1761 c[D_IGE_128_AES][0] = count;
1762 c[D_IGE_192_AES][0] = count;
1763 c[D_IGE_256_AES][0] = count;
1764 c[D_GHASH][0] = count;
1765 c[D_RAND][0] = count;
1767 for (i = 1; i < size_num; i++) {
1770 l0 = (long)lengths[0];
1771 l1 = (long)lengths[i];
1773 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1774 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1775 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1776 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1777 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1778 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1779 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1780 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1781 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1782 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1783 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1784 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
1786 l0 = (long)lengths[i - 1];
1788 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1789 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1790 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1791 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1792 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1793 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1794 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1795 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1796 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1797 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1798 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1799 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1800 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1801 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1802 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1803 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1804 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1805 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1808 # ifndef OPENSSL_NO_RSA
1809 rsa_c[R_RSA_512][0] = count / 2000;
1810 rsa_c[R_RSA_512][1] = count / 400;
1811 for (i = 1; i < RSA_NUM; i++) {
1812 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1813 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1814 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1817 if (rsa_c[i][0] == 0) {
1818 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1825 # ifndef OPENSSL_NO_DSA
1826 dsa_c[R_DSA_512][0] = count / 1000;
1827 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1828 for (i = 1; i < DSA_NUM; i++) {
1829 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1830 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1831 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1834 if (dsa_c[i][0] == 0) {
1835 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1842 # ifndef OPENSSL_NO_EC
1843 ecdsa_c[R_EC_P160][0] = count / 1000;
1844 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1845 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1846 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1847 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1848 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1851 if (ecdsa_c[i][0] == 0) {
1857 ecdsa_c[R_EC_K163][0] = count / 1000;
1858 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1859 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1860 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1861 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1862 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1865 if (ecdsa_c[i][0] == 0) {
1871 ecdsa_c[R_EC_B163][0] = count / 1000;
1872 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1873 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1874 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1875 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1876 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1879 if (ecdsa_c[i][0] == 0) {
1886 ecdh_c[R_EC_P160][0] = count / 1000;
1887 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1888 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1889 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1892 if (ecdh_c[i][0] == 0) {
1897 ecdh_c[R_EC_K163][0] = count / 1000;
1898 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1899 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1900 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1903 if (ecdh_c[i][0] == 0) {
1908 ecdh_c[R_EC_B163][0] = count / 1000;
1909 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1910 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1911 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1914 if (ecdh_c[i][0] == 0) {
1922 /* not worth fixing */
1923 # error "You cannot disable DES on systems without SIGALRM."
1924 # endif /* OPENSSL_NO_DES */
1927 signal(SIGALRM, sig_done);
1929 #endif /* SIGALRM */
1931 #ifndef OPENSSL_NO_MD2
1933 for (testnum = 0; testnum < size_num; testnum++) {
1934 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
1937 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1939 print_result(D_MD2, testnum, count, d);
1943 #ifndef OPENSSL_NO_MDC2
1945 for (testnum = 0; testnum < size_num; testnum++) {
1946 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
1949 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1951 print_result(D_MDC2, testnum, count, d);
1956 #ifndef OPENSSL_NO_MD4
1958 for (testnum = 0; testnum < size_num; testnum++) {
1959 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
1962 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1964 print_result(D_MD4, testnum, count, d);
1969 #ifndef OPENSSL_NO_MD5
1971 for (testnum = 0; testnum < size_num; testnum++) {
1972 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
1975 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1977 print_result(D_MD5, testnum, count, d);
1982 static const char hmac_key[] = "This is a key...";
1983 int len = strlen(hmac_key);
1985 for (i = 0; i < loopargs_len; i++) {
1986 loopargs[i].hctx = HMAC_CTX_new();
1987 if (loopargs[i].hctx == NULL) {
1988 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1992 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1994 for (testnum = 0; testnum < size_num; testnum++) {
1995 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
1998 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2000 print_result(D_HMAC, testnum, count, d);
2002 for (i = 0; i < loopargs_len; i++) {
2003 HMAC_CTX_free(loopargs[i].hctx);
2008 for (testnum = 0; testnum < size_num; testnum++) {
2009 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2012 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2014 print_result(D_SHA1, testnum, count, d);
2017 if (doit[D_SHA256]) {
2018 for (testnum = 0; testnum < size_num; testnum++) {
2019 print_message(names[D_SHA256], c[D_SHA256][testnum],
2020 lengths[testnum], seconds.sym);
2022 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2024 print_result(D_SHA256, testnum, count, d);
2027 if (doit[D_SHA512]) {
2028 for (testnum = 0; testnum < size_num; testnum++) {
2029 print_message(names[D_SHA512], c[D_SHA512][testnum],
2030 lengths[testnum], seconds.sym);
2032 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2034 print_result(D_SHA512, testnum, count, d);
2037 #ifndef OPENSSL_NO_WHIRLPOOL
2038 if (doit[D_WHIRLPOOL]) {
2039 for (testnum = 0; testnum < size_num; testnum++) {
2040 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2041 lengths[testnum], seconds.sym);
2043 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2045 print_result(D_WHIRLPOOL, testnum, count, d);
2050 #ifndef OPENSSL_NO_RMD160
2051 if (doit[D_RMD160]) {
2052 for (testnum = 0; testnum < size_num; testnum++) {
2053 print_message(names[D_RMD160], c[D_RMD160][testnum],
2054 lengths[testnum], seconds.sym);
2056 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2058 print_result(D_RMD160, testnum, count, d);
2062 #ifndef OPENSSL_NO_RC4
2064 for (testnum = 0; testnum < size_num; testnum++) {
2065 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2068 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2070 print_result(D_RC4, testnum, count, d);
2074 #ifndef OPENSSL_NO_DES
2075 if (doit[D_CBC_DES]) {
2076 for (testnum = 0; testnum < size_num; testnum++) {
2077 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2078 lengths[testnum], seconds.sym);
2080 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2082 print_result(D_CBC_DES, testnum, count, d);
2086 if (doit[D_EDE3_DES]) {
2087 for (testnum = 0; testnum < size_num; testnum++) {
2088 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2089 lengths[testnum], seconds.sym);
2092 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2094 print_result(D_EDE3_DES, testnum, count, d);
2099 if (doit[D_CBC_128_AES]) {
2100 for (testnum = 0; testnum < size_num; testnum++) {
2101 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2102 lengths[testnum], seconds.sym);
2105 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2107 print_result(D_CBC_128_AES, testnum, count, d);
2110 if (doit[D_CBC_192_AES]) {
2111 for (testnum = 0; testnum < size_num; testnum++) {
2112 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2113 lengths[testnum], seconds.sym);
2116 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2118 print_result(D_CBC_192_AES, testnum, count, d);
2121 if (doit[D_CBC_256_AES]) {
2122 for (testnum = 0; testnum < size_num; testnum++) {
2123 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2124 lengths[testnum], seconds.sym);
2127 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2129 print_result(D_CBC_256_AES, testnum, count, d);
2133 if (doit[D_IGE_128_AES]) {
2134 for (testnum = 0; testnum < size_num; testnum++) {
2135 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2136 lengths[testnum], seconds.sym);
2139 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2141 print_result(D_IGE_128_AES, testnum, count, d);
2144 if (doit[D_IGE_192_AES]) {
2145 for (testnum = 0; testnum < size_num; testnum++) {
2146 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2147 lengths[testnum], seconds.sym);
2150 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2152 print_result(D_IGE_192_AES, testnum, count, d);
2155 if (doit[D_IGE_256_AES]) {
2156 for (testnum = 0; testnum < size_num; testnum++) {
2157 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2158 lengths[testnum], seconds.sym);
2161 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2163 print_result(D_IGE_256_AES, testnum, count, d);
2166 if (doit[D_GHASH]) {
2167 for (i = 0; i < loopargs_len; i++) {
2168 loopargs[i].gcm_ctx =
2169 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2170 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2171 (unsigned char *)"0123456789ab", 12);
2174 for (testnum = 0; testnum < size_num; testnum++) {
2175 print_message(names[D_GHASH], c[D_GHASH][testnum],
2176 lengths[testnum], seconds.sym);
2178 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2180 print_result(D_GHASH, testnum, count, d);
2182 for (i = 0; i < loopargs_len; i++)
2183 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2185 #ifndef OPENSSL_NO_CAMELLIA
2186 if (doit[D_CBC_128_CML]) {
2187 if (async_jobs > 0) {
2188 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2189 names[D_CBC_128_CML]);
2190 doit[D_CBC_128_CML] = 0;
2192 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2193 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2194 lengths[testnum], seconds.sym);
2196 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2197 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2198 (size_t)lengths[testnum], &camellia_ks1,
2199 iv, CAMELLIA_ENCRYPT);
2201 print_result(D_CBC_128_CML, testnum, count, d);
2204 if (doit[D_CBC_192_CML]) {
2205 if (async_jobs > 0) {
2206 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2207 names[D_CBC_192_CML]);
2208 doit[D_CBC_192_CML] = 0;
2210 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2211 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2212 lengths[testnum], seconds.sym);
2213 if (async_jobs > 0) {
2214 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2218 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2219 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2220 (size_t)lengths[testnum], &camellia_ks2,
2221 iv, CAMELLIA_ENCRYPT);
2223 print_result(D_CBC_192_CML, testnum, count, d);
2226 if (doit[D_CBC_256_CML]) {
2227 if (async_jobs > 0) {
2228 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2229 names[D_CBC_256_CML]);
2230 doit[D_CBC_256_CML] = 0;
2232 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2233 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2234 lengths[testnum], seconds.sym);
2236 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2237 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2238 (size_t)lengths[testnum], &camellia_ks3,
2239 iv, CAMELLIA_ENCRYPT);
2241 print_result(D_CBC_256_CML, testnum, count, d);
2245 #ifndef OPENSSL_NO_IDEA
2246 if (doit[D_CBC_IDEA]) {
2247 if (async_jobs > 0) {
2248 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2250 doit[D_CBC_IDEA] = 0;
2252 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2253 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2254 lengths[testnum], seconds.sym);
2256 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2257 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2258 (size_t)lengths[testnum], &idea_ks,
2261 print_result(D_CBC_IDEA, testnum, count, d);
2265 #ifndef OPENSSL_NO_SEED
2266 if (doit[D_CBC_SEED]) {
2267 if (async_jobs > 0) {
2268 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2270 doit[D_CBC_SEED] = 0;
2272 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2273 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2274 lengths[testnum], seconds.sym);
2276 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2277 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2278 (size_t)lengths[testnum], &seed_ks, iv, 1);
2280 print_result(D_CBC_SEED, testnum, count, d);
2284 #ifndef OPENSSL_NO_RC2
2285 if (doit[D_CBC_RC2]) {
2286 if (async_jobs > 0) {
2287 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2289 doit[D_CBC_RC2] = 0;
2291 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2292 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2293 lengths[testnum], seconds.sym);
2294 if (async_jobs > 0) {
2295 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2299 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2300 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2301 (size_t)lengths[testnum], &rc2_ks,
2304 print_result(D_CBC_RC2, testnum, count, d);
2308 #ifndef OPENSSL_NO_RC5
2309 if (doit[D_CBC_RC5]) {
2310 if (async_jobs > 0) {
2311 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2313 doit[D_CBC_RC5] = 0;
2315 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2316 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2317 lengths[testnum], seconds.sym);
2318 if (async_jobs > 0) {
2319 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2323 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2324 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2325 (size_t)lengths[testnum], &rc5_ks,
2328 print_result(D_CBC_RC5, testnum, count, d);
2332 #ifndef OPENSSL_NO_BF
2333 if (doit[D_CBC_BF]) {
2334 if (async_jobs > 0) {
2335 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2339 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2340 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2341 lengths[testnum], seconds.sym);
2343 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2344 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2345 (size_t)lengths[testnum], &bf_ks,
2348 print_result(D_CBC_BF, testnum, count, d);
2352 #ifndef OPENSSL_NO_CAST
2353 if (doit[D_CBC_CAST]) {
2354 if (async_jobs > 0) {
2355 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2357 doit[D_CBC_CAST] = 0;
2359 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2360 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2361 lengths[testnum], seconds.sym);
2363 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2364 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2365 (size_t)lengths[testnum], &cast_ks,
2368 print_result(D_CBC_CAST, testnum, count, d);
2373 for (testnum = 0; testnum < size_num; testnum++) {
2374 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2377 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2379 print_result(D_RAND, testnum, count, d);
2384 if (multiblock && evp_cipher) {
2386 (EVP_CIPHER_flags(evp_cipher) &
2387 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2388 BIO_printf(bio_err, "%s is not multi-block capable\n",
2389 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2392 if (async_jobs > 0) {
2393 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2396 multiblock_speed(evp_cipher, &seconds);
2400 for (testnum = 0; testnum < size_num; testnum++) {
2403 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2405 * -O3 -fschedule-insns messes up an optimization here!
2406 * names[D_EVP] somehow becomes NULL
2408 print_message(names[D_EVP], save_count, lengths[testnum],
2411 for (k = 0; k < loopargs_len; k++) {
2412 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2413 EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
2414 iv, decrypt ? 0 : 1);
2416 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2418 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2419 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2420 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2421 EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2422 loopargs[k].key, NULL, -1);
2423 OPENSSL_clear_free(loopargs[k].key, keylen);
2425 switch (EVP_CIPHER_mode(evp_cipher)) {
2426 case EVP_CIPH_CCM_MODE:
2427 loopfunc = EVP_Update_loop_ccm;
2430 loopfunc = EVP_Update_loop;
2434 count = run_benchmark(async_jobs, loopfunc, loopargs);
2436 for (k = 0; k < loopargs_len; k++) {
2437 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2441 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2442 print_message(names[D_EVP], save_count, lengths[testnum],
2445 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2448 print_result(D_EVP, testnum, count, d);
2452 for (i = 0; i < loopargs_len; i++)
2453 RAND_bytes(loopargs[i].buf, 36);
2455 #ifndef OPENSSL_NO_RSA
2456 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2458 if (!rsa_doit[testnum])
2460 for (i = 0; i < loopargs_len; i++) {
2462 /* we haven't set keys yet, generate multi-prime RSA keys */
2463 BIGNUM *bn = BN_new();
2467 if (!BN_set_word(bn, RSA_F4)) {
2472 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2473 rsa_choices[testnum].name);
2475 loopargs[i].rsa_key[testnum] = RSA_new();
2476 if (loopargs[i].rsa_key[testnum] == NULL) {
2481 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2483 primes, bn, NULL)) {
2489 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2490 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2496 "RSA sign failure. No RSA sign will be done.\n");
2497 ERR_print_errors(bio_err);
2500 pkey_print_message("private", "rsa",
2501 rsa_c[testnum][0], rsa_bits[testnum],
2503 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2505 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2508 mr ? "+R1:%ld:%d:%.2f\n"
2509 : "%ld %d bit private RSA's in %.2fs\n",
2510 count, rsa_bits[testnum], d);
2511 rsa_results[testnum][0] = (double)count / d;
2515 for (i = 0; i < loopargs_len; i++) {
2516 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2517 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2523 "RSA verify failure. No RSA verify will be done.\n");
2524 ERR_print_errors(bio_err);
2525 rsa_doit[testnum] = 0;
2527 pkey_print_message("public", "rsa",
2528 rsa_c[testnum][1], rsa_bits[testnum],
2531 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2534 mr ? "+R2:%ld:%d:%.2f\n"
2535 : "%ld %d bit public RSA's in %.2fs\n",
2536 count, rsa_bits[testnum], d);
2537 rsa_results[testnum][1] = (double)count / d;
2540 if (rsa_count <= 1) {
2541 /* if longer than 10s, don't do any more */
2542 for (testnum++; testnum < RSA_NUM; testnum++)
2543 rsa_doit[testnum] = 0;
2546 #endif /* OPENSSL_NO_RSA */
2548 for (i = 0; i < loopargs_len; i++)
2549 RAND_bytes(loopargs[i].buf, 36);
2551 #ifndef OPENSSL_NO_DSA
2552 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2554 if (!dsa_doit[testnum])
2557 /* DSA_generate_key(dsa_key[testnum]); */
2558 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2559 for (i = 0; i < loopargs_len; i++) {
2560 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2561 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2567 "DSA sign failure. No DSA sign will be done.\n");
2568 ERR_print_errors(bio_err);
2571 pkey_print_message("sign", "dsa",
2572 dsa_c[testnum][0], dsa_bits[testnum],
2575 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2578 mr ? "+R3:%ld:%d:%.2f\n"
2579 : "%ld %d bit DSA signs in %.2fs\n",
2580 count, dsa_bits[testnum], d);
2581 dsa_results[testnum][0] = (double)count / d;
2585 for (i = 0; i < loopargs_len; i++) {
2586 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2587 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2593 "DSA verify failure. No DSA verify will be done.\n");
2594 ERR_print_errors(bio_err);
2595 dsa_doit[testnum] = 0;
2597 pkey_print_message("verify", "dsa",
2598 dsa_c[testnum][1], dsa_bits[testnum],
2601 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2604 mr ? "+R4:%ld:%d:%.2f\n"
2605 : "%ld %d bit DSA verify in %.2fs\n",
2606 count, dsa_bits[testnum], d);
2607 dsa_results[testnum][1] = (double)count / d;
2610 if (rsa_count <= 1) {
2611 /* if longer than 10s, don't do any more */
2612 for (testnum++; testnum < DSA_NUM; testnum++)
2613 dsa_doit[testnum] = 0;
2616 #endif /* OPENSSL_NO_DSA */
2618 #ifndef OPENSSL_NO_EC
2619 for (testnum = 0; testnum < EC_NUM; testnum++) {
2622 if (!ecdsa_doit[testnum])
2623 continue; /* Ignore Curve */
2624 for (i = 0; i < loopargs_len; i++) {
2625 loopargs[i].ecdsa[testnum] =
2626 EC_KEY_new_by_curve_name(test_curves[testnum]);
2627 if (loopargs[i].ecdsa[testnum] == NULL) {
2633 BIO_printf(bio_err, "ECDSA failure.\n");
2634 ERR_print_errors(bio_err);
2637 for (i = 0; i < loopargs_len; i++) {
2638 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2639 /* Perform ECDSA signature test */
2640 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2641 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2642 &loopargs[i].siglen,
2643 loopargs[i].ecdsa[testnum]);
2649 "ECDSA sign failure. No ECDSA sign will be done.\n");
2650 ERR_print_errors(bio_err);
2653 pkey_print_message("sign", "ecdsa",
2654 ecdsa_c[testnum][0],
2655 test_curves_bits[testnum],
2658 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2662 mr ? "+R5:%ld:%d:%.2f\n" :
2663 "%ld %d bit ECDSA signs in %.2fs \n",
2664 count, test_curves_bits[testnum], d);
2665 ecdsa_results[testnum][0] = (double)count / d;
2669 /* Perform ECDSA verification test */
2670 for (i = 0; i < loopargs_len; i++) {
2671 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2673 loopargs[i].ecdsa[testnum]);
2679 "ECDSA verify failure. No ECDSA verify will be done.\n");
2680 ERR_print_errors(bio_err);
2681 ecdsa_doit[testnum] = 0;
2683 pkey_print_message("verify", "ecdsa",
2684 ecdsa_c[testnum][1],
2685 test_curves_bits[testnum],
2688 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2691 mr ? "+R6:%ld:%d:%.2f\n"
2692 : "%ld %d bit ECDSA verify in %.2fs\n",
2693 count, test_curves_bits[testnum], d);
2694 ecdsa_results[testnum][1] = (double)count / d;
2697 if (rsa_count <= 1) {
2698 /* if longer than 10s, don't do any more */
2699 for (testnum++; testnum < EC_NUM; testnum++)
2700 ecdsa_doit[testnum] = 0;
2705 for (testnum = 0; testnum < EC_NUM; testnum++) {
2706 int ecdh_checks = 1;
2708 if (!ecdh_doit[testnum])
2711 for (i = 0; i < loopargs_len; i++) {
2712 EVP_PKEY_CTX *kctx = NULL;
2713 EVP_PKEY_CTX *test_ctx = NULL;
2714 EVP_PKEY_CTX *ctx = NULL;
2715 EVP_PKEY *key_A = NULL;
2716 EVP_PKEY *key_B = NULL;
2720 /* Ensure that the error queue is empty */
2721 if (ERR_peek_error()) {
2723 "WARNING: the error queue contains previous unhandled errors.\n");
2724 ERR_print_errors(bio_err);
2727 /* Let's try to create a ctx directly from the NID: this works for
2728 * curves like Curve25519 that are not implemented through the low
2729 * level EC interface.
2730 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2731 * then we set the curve by NID before deriving the actual keygen
2732 * ctx for that specific curve. */
2733 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2735 EVP_PKEY_CTX *pctx = NULL;
2736 EVP_PKEY *params = NULL;
2738 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2739 * "int_ctx_new:unsupported algorithm" error was added to the
2741 * We remove it from the error queue as we are handling it. */
2742 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2743 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2744 /* check that the error origin matches */
2745 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2746 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2747 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2748 ERR_get_error(); /* pop error from queue */
2749 if (ERR_peek_error()) {
2751 "Unhandled error in the error queue during ECDH init.\n");
2752 ERR_print_errors(bio_err);
2757 if ( /* Create the context for parameter generation */
2758 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2759 /* Initialise the parameter generation */
2760 !EVP_PKEY_paramgen_init(pctx) ||
2761 /* Set the curve by NID */
2762 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2765 /* Create the parameter object params */
2766 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2768 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2769 ERR_print_errors(bio_err);
2773 /* Create the context for the key generation */
2774 kctx = EVP_PKEY_CTX_new(params, NULL);
2776 EVP_PKEY_free(params);
2778 EVP_PKEY_CTX_free(pctx);
2781 if (kctx == NULL || /* keygen ctx is not null */
2782 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2784 BIO_printf(bio_err, "ECDH keygen failure.\n");
2785 ERR_print_errors(bio_err);
2790 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2791 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2792 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2793 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2794 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2795 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2796 outlen == 0 || /* ensure outlen is a valid size */
2797 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2799 BIO_printf(bio_err, "ECDH key generation failure.\n");
2800 ERR_print_errors(bio_err);
2805 /* Here we perform a test run, comparing the output of a*B and b*A;
2806 * we try this here and assume that further EVP_PKEY_derive calls
2807 * never fail, so we can skip checks in the actually benchmarked
2808 * code, for maximum performance. */
2809 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2810 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2811 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2812 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2813 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2814 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2815 test_outlen != outlen /* compare output length */ ) {
2817 BIO_printf(bio_err, "ECDH computation failure.\n");
2818 ERR_print_errors(bio_err);
2823 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2824 if (CRYPTO_memcmp(loopargs[i].secret_a,
2825 loopargs[i].secret_b, outlen)) {
2827 BIO_printf(bio_err, "ECDH computations don't match.\n");
2828 ERR_print_errors(bio_err);
2833 loopargs[i].ecdh_ctx[testnum] = ctx;
2834 loopargs[i].outlen[testnum] = outlen;
2836 EVP_PKEY_free(key_A);
2837 EVP_PKEY_free(key_B);
2838 EVP_PKEY_CTX_free(kctx);
2840 EVP_PKEY_CTX_free(test_ctx);
2843 if (ecdh_checks != 0) {
2844 pkey_print_message("", "ecdh",
2846 test_curves_bits[testnum],
2850 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2853 mr ? "+R7:%ld:%d:%.2f\n" :
2854 "%ld %d-bit ECDH ops in %.2fs\n", count,
2855 test_curves_bits[testnum], d);
2856 ecdh_results[testnum][0] = (double)count / d;
2860 if (rsa_count <= 1) {
2861 /* if longer than 10s, don't do any more */
2862 for (testnum++; testnum < EC_NUM; testnum++)
2863 ecdh_doit[testnum] = 0;
2866 #endif /* OPENSSL_NO_EC */
2871 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2872 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2874 printf("%s ", BN_options());
2875 #ifndef OPENSSL_NO_MD2
2876 printf("%s ", MD2_options());
2878 #ifndef OPENSSL_NO_RC4
2879 printf("%s ", RC4_options());
2881 #ifndef OPENSSL_NO_DES
2882 printf("%s ", DES_options());
2884 printf("%s ", AES_options());
2885 #ifndef OPENSSL_NO_IDEA
2886 printf("%s ", IDEA_options());
2888 #ifndef OPENSSL_NO_BF
2889 printf("%s ", BF_options());
2891 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2899 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2902 for (testnum = 0; testnum < size_num; testnum++)
2903 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2907 for (k = 0; k < ALGOR_NUM; k++) {
2911 printf("+F:%d:%s", k, names[k]);
2913 printf("%-13s", names[k]);
2914 for (testnum = 0; testnum < size_num; testnum++) {
2915 if (results[k][testnum] > 10000 && !mr)
2916 printf(" %11.2fk", results[k][testnum] / 1e3);
2918 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2922 #ifndef OPENSSL_NO_RSA
2924 for (k = 0; k < RSA_NUM; k++) {
2927 if (testnum && !mr) {
2928 printf("%18ssign verify sign/s verify/s\n", " ");
2932 printf("+F2:%u:%u:%f:%f\n",
2933 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2935 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2936 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2937 rsa_results[k][0], rsa_results[k][1]);
2940 #ifndef OPENSSL_NO_DSA
2942 for (k = 0; k < DSA_NUM; k++) {
2945 if (testnum && !mr) {
2946 printf("%18ssign verify sign/s verify/s\n", " ");
2950 printf("+F3:%u:%u:%f:%f\n",
2951 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2953 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2954 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2955 dsa_results[k][0], dsa_results[k][1]);
2958 #ifndef OPENSSL_NO_EC
2960 for (k = 0; k < EC_NUM; k++) {
2963 if (testnum && !mr) {
2964 printf("%30ssign verify sign/s verify/s\n", " ");
2969 printf("+F4:%u:%u:%f:%f\n",
2970 k, test_curves_bits[k],
2971 ecdsa_results[k][0], ecdsa_results[k][1]);
2973 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2974 test_curves_bits[k],
2975 test_curves_names[k],
2976 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2977 ecdsa_results[k][0], ecdsa_results[k][1]);
2981 for (k = 0; k < EC_NUM; k++) {
2984 if (testnum && !mr) {
2985 printf("%30sop op/s\n", " ");
2989 printf("+F5:%u:%u:%f:%f\n",
2990 k, test_curves_bits[k],
2991 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2994 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2995 test_curves_bits[k],
2996 test_curves_names[k],
2997 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3004 ERR_print_errors(bio_err);
3005 for (i = 0; i < loopargs_len; i++) {
3006 OPENSSL_free(loopargs[i].buf_malloc);
3007 OPENSSL_free(loopargs[i].buf2_malloc);
3009 #ifndef OPENSSL_NO_RSA
3010 for (k = 0; k < RSA_NUM; k++)
3011 RSA_free(loopargs[i].rsa_key[k]);
3013 #ifndef OPENSSL_NO_DSA
3014 for (k = 0; k < DSA_NUM; k++)
3015 DSA_free(loopargs[i].dsa_key[k]);
3017 #ifndef OPENSSL_NO_EC
3018 for (k = 0; k < EC_NUM; k++) {
3019 EC_KEY_free(loopargs[i].ecdsa[k]);
3020 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3022 OPENSSL_free(loopargs[i].secret_a);
3023 OPENSSL_free(loopargs[i].secret_b);
3027 if (async_jobs > 0) {
3028 for (i = 0; i < loopargs_len; i++)
3029 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3033 ASYNC_cleanup_thread();
3035 OPENSSL_free(loopargs);
3040 static void print_message(const char *s, long num, int length, int tm)
3044 mr ? "+DT:%s:%d:%d\n"
3045 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3046 (void)BIO_flush(bio_err);
3050 mr ? "+DN:%s:%ld:%d\n"
3051 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3052 (void)BIO_flush(bio_err);
3056 static void pkey_print_message(const char *str, const char *str2, long num,
3061 mr ? "+DTP:%d:%s:%s:%d\n"
3062 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
3063 (void)BIO_flush(bio_err);
3067 mr ? "+DNP:%ld:%d:%s:%s\n"
3068 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
3069 (void)BIO_flush(bio_err);
3073 static void print_result(int alg, int run_no, int count, double time_used)
3076 BIO_puts(bio_err, "EVP error!\n");
3080 mr ? "+R:%d:%s:%f\n"
3081 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3082 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3086 static char *sstrsep(char **string, const char *delim)
3089 char *token = *string;
3094 memset(isdelim, 0, sizeof(isdelim));
3098 isdelim[(unsigned char)(*delim)] = 1;
3102 while (!isdelim[(unsigned char)(**string)]) {
3114 static int do_multi(int multi, int size_num)
3119 static char sep[] = ":";
3121 fds = malloc(sizeof(*fds) * multi);
3122 for (n = 0; n < multi; ++n) {
3123 if (pipe(fd) == -1) {
3124 BIO_printf(bio_err, "pipe failure\n");
3128 (void)BIO_flush(bio_err);
3135 if (dup(fd[1]) == -1) {
3136 BIO_printf(bio_err, "dup failed\n");
3145 printf("Forked child %d\n", n);
3148 /* for now, assume the pipe is long enough to take all the output */
3149 for (n = 0; n < multi; ++n) {
3154 f = fdopen(fds[n], "r");
3155 while (fgets(buf, sizeof(buf), f)) {
3156 p = strchr(buf, '\n');
3159 if (buf[0] != '+') {
3161 "Don't understand line '%s' from child %d\n", buf,
3165 printf("Got: %s from %d\n", buf, n);
3166 if (strncmp(buf, "+F:", 3) == 0) {
3171 alg = atoi(sstrsep(&p, sep));
3173 for (j = 0; j < size_num; ++j)
3174 results[alg][j] += atof(sstrsep(&p, sep));
3175 } else if (strncmp(buf, "+F2:", 4) == 0) {
3180 k = atoi(sstrsep(&p, sep));
3183 d = atof(sstrsep(&p, sep));
3184 rsa_results[k][0] += d;
3186 d = atof(sstrsep(&p, sep));
3187 rsa_results[k][1] += d;
3189 # ifndef OPENSSL_NO_DSA
3190 else if (strncmp(buf, "+F3:", 4) == 0) {
3195 k = atoi(sstrsep(&p, sep));
3198 d = atof(sstrsep(&p, sep));
3199 dsa_results[k][0] += d;
3201 d = atof(sstrsep(&p, sep));
3202 dsa_results[k][1] += d;
3205 # ifndef OPENSSL_NO_EC
3206 else if (strncmp(buf, "+F4:", 4) == 0) {
3211 k = atoi(sstrsep(&p, sep));
3214 d = atof(sstrsep(&p, sep));
3215 ecdsa_results[k][0] += d;
3217 d = atof(sstrsep(&p, sep));
3218 ecdsa_results[k][1] += d;
3219 } else if (strncmp(buf, "+F5:", 4) == 0) {
3224 k = atoi(sstrsep(&p, sep));
3227 d = atof(sstrsep(&p, sep));
3228 ecdh_results[k][0] += d;
3232 else if (strncmp(buf, "+H:", 3) == 0) {
3235 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3246 static void multiblock_speed(const EVP_CIPHER *evp_cipher,
3247 const openssl_speed_sec_t *seconds)
3249 static const int mblengths_list[] =
3250 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3251 const int *mblengths = mblengths_list;
3252 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
3253 const char *alg_name;
3254 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
3255 EVP_CIPHER_CTX *ctx;
3258 if (lengths_single) {
3259 mblengths = &lengths_single;
3263 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3264 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3265 ctx = EVP_CIPHER_CTX_new();
3266 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
3268 keylen = EVP_CIPHER_CTX_key_length(ctx);
3269 key = app_malloc(keylen, "evp_cipher key");
3270 EVP_CIPHER_CTX_rand_key(ctx, key);
3271 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
3272 OPENSSL_clear_free(key, keylen);
3274 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3275 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3277 for (j = 0; j < num; j++) {
3278 print_message(alg_name, 0, mblengths[j], seconds->sym);
3280 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3281 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3282 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3283 size_t len = mblengths[j];
3286 memset(aad, 0, 8); /* avoid uninitialized values */
3287 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3288 aad[9] = 3; /* version */
3290 aad[11] = 0; /* length */
3292 mb_param.out = NULL;
3295 mb_param.interleave = 8;
3297 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3298 sizeof(mb_param), &mb_param);
3304 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3305 sizeof(mb_param), &mb_param);
3309 RAND_bytes(out, 16);
3311 aad[11] = (unsigned char)(len >> 8);
3312 aad[12] = (unsigned char)(len);
3313 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3314 EVP_AEAD_TLS1_AAD_LEN, aad);
3315 EVP_Cipher(ctx, out, inp, len + pad);
3319 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3320 : "%d %s's in %.2fs\n", count, "evp", d);
3321 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3325 fprintf(stdout, "+H");
3326 for (j = 0; j < num; j++)
3327 fprintf(stdout, ":%d", mblengths[j]);
3328 fprintf(stdout, "\n");
3329 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3330 for (j = 0; j < num; j++)
3331 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3332 fprintf(stdout, "\n");
3335 "The 'numbers' are in 1000s of bytes per second processed.\n");
3336 fprintf(stdout, "type ");
3337 for (j = 0; j < num; j++)
3338 fprintf(stdout, "%7d bytes", mblengths[j]);
3339 fprintf(stdout, "\n");
3340 fprintf(stdout, "%-24s", alg_name);
3342 for (j = 0; j < num; j++) {
3343 if (results[D_EVP][j] > 10000)
3344 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3346 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3348 fprintf(stdout, "\n");
3353 EVP_CIPHER_CTX_free(ctx);