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
24 #include <openssl/crypto.h>
25 #include <openssl/rand.h>
26 #include <openssl/err.h>
27 #include <openssl/evp.h>
28 #include <openssl/objects.h>
29 #include <openssl/async.h>
30 #if !defined(OPENSSL_SYS_MSDOS)
31 # include OPENSSL_UNISTD
38 #include <openssl/bn.h>
39 #ifndef OPENSSL_NO_DES
40 # include <openssl/des.h>
42 #include <openssl/aes.h>
43 #ifndef OPENSSL_NO_CAMELLIA
44 # include <openssl/camellia.h>
46 #ifndef OPENSSL_NO_MD2
47 # include <openssl/md2.h>
49 #ifndef OPENSSL_NO_MDC2
50 # include <openssl/mdc2.h>
52 #ifndef OPENSSL_NO_MD4
53 # include <openssl/md4.h>
55 #ifndef OPENSSL_NO_MD5
56 # include <openssl/md5.h>
58 #include <openssl/hmac.h>
59 #include <openssl/sha.h>
60 #ifndef OPENSSL_NO_RMD160
61 # include <openssl/ripemd.h>
63 #ifndef OPENSSL_NO_WHIRLPOOL
64 # include <openssl/whrlpool.h>
66 #ifndef OPENSSL_NO_RC4
67 # include <openssl/rc4.h>
69 #ifndef OPENSSL_NO_RC5
70 # include <openssl/rc5.h>
72 #ifndef OPENSSL_NO_RC2
73 # include <openssl/rc2.h>
75 #ifndef OPENSSL_NO_IDEA
76 # include <openssl/idea.h>
78 #ifndef OPENSSL_NO_SEED
79 # include <openssl/seed.h>
82 # include <openssl/blowfish.h>
84 #ifndef OPENSSL_NO_CAST
85 # include <openssl/cast.h>
87 #ifndef OPENSSL_NO_RSA
88 # include <openssl/rsa.h>
89 # include "./testrsa.h"
91 #include <openssl/x509.h>
92 #ifndef OPENSSL_NO_DSA
93 # include <openssl/dsa.h>
94 # include "./testdsa.h"
97 # include <openssl/ec.h>
99 #include <openssl/modes.h>
102 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
115 #define MAX_MISALIGNMENT 63
122 #define MAX_ECDH_SIZE 256
125 typedef struct openssl_speed_sec_st {
131 } openssl_speed_sec_t;
133 static volatile int run = 0;
136 static int usertime = 1;
138 typedef struct loopargs_st {
139 ASYNC_JOB *inprogress_job;
140 ASYNC_WAIT_CTX *wait_ctx;
143 unsigned char *buf_malloc;
144 unsigned char *buf2_malloc;
147 #ifndef OPENSSL_NO_RSA
148 RSA *rsa_key[RSA_NUM];
150 #ifndef OPENSSL_NO_DSA
151 DSA *dsa_key[DSA_NUM];
153 #ifndef OPENSSL_NO_EC
154 EC_KEY *ecdsa[EC_NUM];
155 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
156 unsigned char *secret_a;
157 unsigned char *secret_b;
158 size_t outlen[EC_NUM];
162 GCM128_CONTEXT *gcm_ctx;
165 #ifndef OPENSSL_NO_MD2
166 static int EVP_Digest_MD2_loop(void *args);
169 #ifndef OPENSSL_NO_MDC2
170 static int EVP_Digest_MDC2_loop(void *args);
172 #ifndef OPENSSL_NO_MD4
173 static int EVP_Digest_MD4_loop(void *args);
175 #ifndef OPENSSL_NO_MD5
176 static int MD5_loop(void *args);
177 static int HMAC_loop(void *args);
179 static int SHA1_loop(void *args);
180 static int SHA256_loop(void *args);
181 static int SHA512_loop(void *args);
182 #ifndef OPENSSL_NO_WHIRLPOOL
183 static int WHIRLPOOL_loop(void *args);
185 #ifndef OPENSSL_NO_RMD160
186 static int EVP_Digest_RMD160_loop(void *args);
188 #ifndef OPENSSL_NO_RC4
189 static int RC4_loop(void *args);
191 #ifndef OPENSSL_NO_DES
192 static int DES_ncbc_encrypt_loop(void *args);
193 static int DES_ede3_cbc_encrypt_loop(void *args);
195 static int AES_cbc_128_encrypt_loop(void *args);
196 static int AES_cbc_192_encrypt_loop(void *args);
197 static int AES_ige_128_encrypt_loop(void *args);
198 static int AES_cbc_256_encrypt_loop(void *args);
199 static int AES_ige_192_encrypt_loop(void *args);
200 static int AES_ige_256_encrypt_loop(void *args);
201 static int CRYPTO_gcm128_aad_loop(void *args);
202 static int RAND_bytes_loop(void *args);
203 static int EVP_Update_loop(void *args);
204 static int EVP_Update_loop_ccm(void *args);
205 static int EVP_Digest_loop(void *args);
206 #ifndef OPENSSL_NO_RSA
207 static int RSA_sign_loop(void *args);
208 static int RSA_verify_loop(void *args);
210 #ifndef OPENSSL_NO_DSA
211 static int DSA_sign_loop(void *args);
212 static int DSA_verify_loop(void *args);
214 #ifndef OPENSSL_NO_EC
215 static int ECDSA_sign_loop(void *args);
216 static int ECDSA_verify_loop(void *args);
218 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
219 loopargs_t * loopargs);
221 static double Time_F(int s);
222 static void print_message(const char *s, long num, int length, int tm);
223 static void pkey_print_message(const char *str, const char *str2,
224 long num, int bits, int sec);
225 static void print_result(int alg, int run_no, int count, double time_used);
227 static int do_multi(int multi, int size_num);
230 static const int lengths_list[] = {
231 16, 64, 256, 1024, 8 * 1024, 16 * 1024
233 static int lengths_single = 0;
235 static const int *lengths = lengths_list;
237 static const char *names[ALGOR_NUM] = {
238 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
239 "des cbc", "des ede3", "idea cbc", "seed cbc",
240 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
241 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
242 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
243 "evp", "sha256", "sha512", "whirlpool",
244 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
248 static double results[ALGOR_NUM][OSSL_NELEM(lengths_list)];
250 #ifndef OPENSSL_NO_RSA
251 static double rsa_results[RSA_NUM][2];
253 #ifndef OPENSSL_NO_DSA
254 static double dsa_results[DSA_NUM][2];
256 #ifndef OPENSSL_NO_EC
257 static double ecdsa_results[EC_NUM][2];
258 static double ecdh_results[EC_NUM][1];
262 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
263 # define SIGRETTYPE void
265 # define SIGRETTYPE int
268 static SIGRETTYPE sig_done(int sig);
269 static SIGRETTYPE sig_done(int sig)
271 signal(SIGALRM, sig_done);
281 # if !defined(SIGALRM)
284 static unsigned int lapse;
285 static volatile unsigned int schlock;
286 static void alarm_win32(unsigned int secs)
291 # define alarm alarm_win32
293 static DWORD WINAPI sleepy(VOID * arg)
301 static double Time_F(int s)
308 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
310 DWORD err = GetLastError();
311 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
315 Sleep(0); /* scheduler spinlock */
316 ret = app_tminterval(s, usertime);
318 ret = app_tminterval(s, usertime);
320 TerminateThread(thr, 0);
328 static double Time_F(int s)
330 double ret = app_tminterval(s, usertime);
337 static void multiblock_speed(const EVP_CIPHER *evp_cipher,
338 const openssl_speed_sec_t *seconds);
340 static int found(const char *name, const OPT_PAIR *pairs, int *result)
342 for (; pairs->name; pairs++)
343 if (strcmp(name, pairs->name) == 0) {
344 *result = pairs->retval;
350 typedef enum OPTION_choice {
351 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
352 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
353 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
354 OPT_PRIMES, OPT_SECONDS, OPT_BYTES
357 const OPTIONS speed_options[] = {
358 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
359 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
360 {"help", OPT_HELP, '-', "Display this summary"},
361 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
362 {"decrypt", OPT_DECRYPT, '-',
363 "Time decryption instead of encryption (only EVP)"},
364 {"mr", OPT_MR, '-', "Produce machine readable output"},
366 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
367 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
368 {"elapsed", OPT_ELAPSED, '-',
369 "Measure time in real time instead of CPU user time"},
371 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
373 #ifndef OPENSSL_NO_ASYNC
374 {"async_jobs", OPT_ASYNCJOBS, 'p',
375 "Enable async mode and start pnum jobs"},
378 #ifndef OPENSSL_NO_ENGINE
379 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
381 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
382 {"seconds", OPT_SECONDS, 'p',
383 "Run benchmarks for pnum seconds"},
384 {"bytes", OPT_BYTES, 'p',
385 "Run cipher, digest and rand benchmarks on pnum bytes"},
399 #define D_CBC_IDEA 10
400 #define D_CBC_SEED 11
404 #define D_CBC_CAST 15
405 #define D_CBC_128_AES 16
406 #define D_CBC_192_AES 17
407 #define D_CBC_256_AES 18
408 #define D_CBC_128_CML 19
409 #define D_CBC_192_CML 20
410 #define D_CBC_256_CML 21
414 #define D_WHIRLPOOL 25
415 #define D_IGE_128_AES 26
416 #define D_IGE_192_AES 27
417 #define D_IGE_256_AES 28
420 static OPT_PAIR doit_choices[] = {
421 #ifndef OPENSSL_NO_MD2
424 #ifndef OPENSSL_NO_MDC2
427 #ifndef OPENSSL_NO_MD4
430 #ifndef OPENSSL_NO_MD5
435 {"sha256", D_SHA256},
436 {"sha512", D_SHA512},
437 #ifndef OPENSSL_NO_WHIRLPOOL
438 {"whirlpool", D_WHIRLPOOL},
440 #ifndef OPENSSL_NO_RMD160
441 {"ripemd", D_RMD160},
442 {"rmd160", D_RMD160},
443 {"ripemd160", D_RMD160},
445 #ifndef OPENSSL_NO_RC4
448 #ifndef OPENSSL_NO_DES
449 {"des-cbc", D_CBC_DES},
450 {"des-ede3", D_EDE3_DES},
452 {"aes-128-cbc", D_CBC_128_AES},
453 {"aes-192-cbc", D_CBC_192_AES},
454 {"aes-256-cbc", D_CBC_256_AES},
455 {"aes-128-ige", D_IGE_128_AES},
456 {"aes-192-ige", D_IGE_192_AES},
457 {"aes-256-ige", D_IGE_256_AES},
458 #ifndef OPENSSL_NO_RC2
459 {"rc2-cbc", D_CBC_RC2},
462 #ifndef OPENSSL_NO_RC5
463 {"rc5-cbc", D_CBC_RC5},
466 #ifndef OPENSSL_NO_IDEA
467 {"idea-cbc", D_CBC_IDEA},
468 {"idea", D_CBC_IDEA},
470 #ifndef OPENSSL_NO_SEED
471 {"seed-cbc", D_CBC_SEED},
472 {"seed", D_CBC_SEED},
474 #ifndef OPENSSL_NO_BF
475 {"bf-cbc", D_CBC_BF},
476 {"blowfish", D_CBC_BF},
479 #ifndef OPENSSL_NO_CAST
480 {"cast-cbc", D_CBC_CAST},
481 {"cast", D_CBC_CAST},
482 {"cast5", D_CBC_CAST},
489 #ifndef OPENSSL_NO_DSA
491 # define R_DSA_1024 1
492 # define R_DSA_2048 2
493 static OPT_PAIR dsa_choices[] = {
494 {"dsa512", R_DSA_512},
495 {"dsa1024", R_DSA_1024},
496 {"dsa2048", R_DSA_2048},
507 #define R_RSA_15360 6
508 static OPT_PAIR rsa_choices[] = {
509 {"rsa512", R_RSA_512},
510 {"rsa1024", R_RSA_1024},
511 {"rsa2048", R_RSA_2048},
512 {"rsa3072", R_RSA_3072},
513 {"rsa4096", R_RSA_4096},
514 {"rsa7680", R_RSA_7680},
515 {"rsa15360", R_RSA_15360},
535 #define R_EC_X25519 16
536 #ifndef OPENSSL_NO_EC
537 static OPT_PAIR ecdsa_choices[] = {
538 {"ecdsap160", R_EC_P160},
539 {"ecdsap192", R_EC_P192},
540 {"ecdsap224", R_EC_P224},
541 {"ecdsap256", R_EC_P256},
542 {"ecdsap384", R_EC_P384},
543 {"ecdsap521", R_EC_P521},
544 {"ecdsak163", R_EC_K163},
545 {"ecdsak233", R_EC_K233},
546 {"ecdsak283", R_EC_K283},
547 {"ecdsak409", R_EC_K409},
548 {"ecdsak571", R_EC_K571},
549 {"ecdsab163", R_EC_B163},
550 {"ecdsab233", R_EC_B233},
551 {"ecdsab283", R_EC_B283},
552 {"ecdsab409", R_EC_B409},
553 {"ecdsab571", R_EC_B571},
557 static OPT_PAIR ecdh_choices[] = {
558 {"ecdhp160", R_EC_P160},
559 {"ecdhp192", R_EC_P192},
560 {"ecdhp224", R_EC_P224},
561 {"ecdhp256", R_EC_P256},
562 {"ecdhp384", R_EC_P384},
563 {"ecdhp521", R_EC_P521},
564 {"ecdhk163", R_EC_K163},
565 {"ecdhk233", R_EC_K233},
566 {"ecdhk283", R_EC_K283},
567 {"ecdhk409", R_EC_K409},
568 {"ecdhk571", R_EC_K571},
569 {"ecdhb163", R_EC_B163},
570 {"ecdhb233", R_EC_B233},
571 {"ecdhb283", R_EC_B283},
572 {"ecdhb409", R_EC_B409},
573 {"ecdhb571", R_EC_B571},
574 {"ecdhx25519", R_EC_X25519},
580 # define COND(d) (count < (d))
581 # define COUNT(d) (d)
583 # define COND(unused_cond) (run && count<0x7fffffff)
584 # define COUNT(d) (count)
589 /* Nb of iterations to do per algorithm and key-size */
590 static long c[ALGOR_NUM][OSSL_NELEM(lengths_list)];
592 #ifndef OPENSSL_NO_MD2
593 static int EVP_Digest_MD2_loop(void *args)
595 loopargs_t *tempargs = *(loopargs_t **) args;
596 unsigned char *buf = tempargs->buf;
597 unsigned char md2[MD2_DIGEST_LENGTH];
600 for (count = 0; COND(c[D_MD2][testnum]); count++) {
601 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
609 #ifndef OPENSSL_NO_MDC2
610 static int EVP_Digest_MDC2_loop(void *args)
612 loopargs_t *tempargs = *(loopargs_t **) args;
613 unsigned char *buf = tempargs->buf;
614 unsigned char mdc2[MDC2_DIGEST_LENGTH];
617 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
618 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
626 #ifndef OPENSSL_NO_MD4
627 static int EVP_Digest_MD4_loop(void *args)
629 loopargs_t *tempargs = *(loopargs_t **) args;
630 unsigned char *buf = tempargs->buf;
631 unsigned char md4[MD4_DIGEST_LENGTH];
634 for (count = 0; COND(c[D_MD4][testnum]); count++) {
635 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
643 #ifndef OPENSSL_NO_MD5
644 static int MD5_loop(void *args)
646 loopargs_t *tempargs = *(loopargs_t **) args;
647 unsigned char *buf = tempargs->buf;
648 unsigned char md5[MD5_DIGEST_LENGTH];
650 for (count = 0; COND(c[D_MD5][testnum]); count++)
651 MD5(buf, lengths[testnum], md5);
655 static int HMAC_loop(void *args)
657 loopargs_t *tempargs = *(loopargs_t **) args;
658 unsigned char *buf = tempargs->buf;
659 HMAC_CTX *hctx = tempargs->hctx;
660 unsigned char hmac[MD5_DIGEST_LENGTH];
663 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
664 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
665 HMAC_Update(hctx, buf, lengths[testnum]);
666 HMAC_Final(hctx, hmac, NULL);
672 static int SHA1_loop(void *args)
674 loopargs_t *tempargs = *(loopargs_t **) args;
675 unsigned char *buf = tempargs->buf;
676 unsigned char sha[SHA_DIGEST_LENGTH];
678 for (count = 0; COND(c[D_SHA1][testnum]); count++)
679 SHA1(buf, lengths[testnum], sha);
683 static int SHA256_loop(void *args)
685 loopargs_t *tempargs = *(loopargs_t **) args;
686 unsigned char *buf = tempargs->buf;
687 unsigned char sha256[SHA256_DIGEST_LENGTH];
689 for (count = 0; COND(c[D_SHA256][testnum]); count++)
690 SHA256(buf, lengths[testnum], sha256);
694 static int SHA512_loop(void *args)
696 loopargs_t *tempargs = *(loopargs_t **) args;
697 unsigned char *buf = tempargs->buf;
698 unsigned char sha512[SHA512_DIGEST_LENGTH];
700 for (count = 0; COND(c[D_SHA512][testnum]); count++)
701 SHA512(buf, lengths[testnum], sha512);
705 #ifndef OPENSSL_NO_WHIRLPOOL
706 static int WHIRLPOOL_loop(void *args)
708 loopargs_t *tempargs = *(loopargs_t **) args;
709 unsigned char *buf = tempargs->buf;
710 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
712 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
713 WHIRLPOOL(buf, lengths[testnum], whirlpool);
718 #ifndef OPENSSL_NO_RMD160
719 static int EVP_Digest_RMD160_loop(void *args)
721 loopargs_t *tempargs = *(loopargs_t **) args;
722 unsigned char *buf = tempargs->buf;
723 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
725 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
726 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
727 NULL, EVP_ripemd160(), NULL))
734 #ifndef OPENSSL_NO_RC4
735 static RC4_KEY rc4_ks;
736 static int RC4_loop(void *args)
738 loopargs_t *tempargs = *(loopargs_t **) args;
739 unsigned char *buf = tempargs->buf;
741 for (count = 0; COND(c[D_RC4][testnum]); count++)
742 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
747 #ifndef OPENSSL_NO_DES
748 static unsigned char DES_iv[8];
749 static DES_key_schedule sch;
750 static DES_key_schedule sch2;
751 static DES_key_schedule sch3;
752 static int DES_ncbc_encrypt_loop(void *args)
754 loopargs_t *tempargs = *(loopargs_t **) args;
755 unsigned char *buf = tempargs->buf;
757 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
758 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
759 &DES_iv, DES_ENCRYPT);
763 static int DES_ede3_cbc_encrypt_loop(void *args)
765 loopargs_t *tempargs = *(loopargs_t **) args;
766 unsigned char *buf = tempargs->buf;
768 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
769 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
770 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
775 #define MAX_BLOCK_SIZE 128
777 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
778 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
779 static int AES_cbc_128_encrypt_loop(void *args)
781 loopargs_t *tempargs = *(loopargs_t **) args;
782 unsigned char *buf = tempargs->buf;
784 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
785 AES_cbc_encrypt(buf, buf,
786 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
790 static int AES_cbc_192_encrypt_loop(void *args)
792 loopargs_t *tempargs = *(loopargs_t **) args;
793 unsigned char *buf = tempargs->buf;
795 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
796 AES_cbc_encrypt(buf, buf,
797 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
801 static int AES_cbc_256_encrypt_loop(void *args)
803 loopargs_t *tempargs = *(loopargs_t **) args;
804 unsigned char *buf = tempargs->buf;
806 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
807 AES_cbc_encrypt(buf, buf,
808 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
812 static int AES_ige_128_encrypt_loop(void *args)
814 loopargs_t *tempargs = *(loopargs_t **) args;
815 unsigned char *buf = tempargs->buf;
816 unsigned char *buf2 = tempargs->buf2;
818 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
819 AES_ige_encrypt(buf, buf2,
820 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
824 static int AES_ige_192_encrypt_loop(void *args)
826 loopargs_t *tempargs = *(loopargs_t **) args;
827 unsigned char *buf = tempargs->buf;
828 unsigned char *buf2 = tempargs->buf2;
830 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
831 AES_ige_encrypt(buf, buf2,
832 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
836 static int AES_ige_256_encrypt_loop(void *args)
838 loopargs_t *tempargs = *(loopargs_t **) args;
839 unsigned char *buf = tempargs->buf;
840 unsigned char *buf2 = tempargs->buf2;
842 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
843 AES_ige_encrypt(buf, buf2,
844 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
848 static int CRYPTO_gcm128_aad_loop(void *args)
850 loopargs_t *tempargs = *(loopargs_t **) args;
851 unsigned char *buf = tempargs->buf;
852 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
854 for (count = 0; COND(c[D_GHASH][testnum]); count++)
855 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
859 static int RAND_bytes_loop(void *args)
861 loopargs_t *tempargs = *(loopargs_t **) args;
862 unsigned char *buf = tempargs->buf;
865 for (count = 0; COND(c[D_RAND][testnum]); count++)
866 RAND_bytes(buf, lengths[testnum]);
870 static long save_count = 0;
871 static int decrypt = 0;
872 static int EVP_Update_loop(void *args)
874 loopargs_t *tempargs = *(loopargs_t **) args;
875 unsigned char *buf = tempargs->buf;
876 EVP_CIPHER_CTX *ctx = tempargs->ctx;
879 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
882 for (count = 0; COND(nb_iter); count++) {
883 rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
885 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
888 for (count = 0; COND(nb_iter); count++) {
889 rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
891 EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
895 EVP_DecryptFinal_ex(ctx, buf, &outl);
897 EVP_EncryptFinal_ex(ctx, buf, &outl);
901 * CCM does not support streaming. For the purpose of performance measurement,
902 * each message is encrypted using the same (key,iv)-pair. Do not use this
903 * code in your application.
905 static int EVP_Update_loop_ccm(void *args)
907 loopargs_t *tempargs = *(loopargs_t **) args;
908 unsigned char *buf = tempargs->buf;
909 EVP_CIPHER_CTX *ctx = tempargs->ctx;
911 unsigned char tag[12];
913 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
916 for (count = 0; COND(nb_iter); count++) {
917 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
918 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
919 EVP_DecryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
920 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
921 EVP_DecryptFinal_ex(ctx, buf, &outl);
924 for (count = 0; COND(nb_iter); count++) {
925 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
926 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
927 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
928 EVP_EncryptFinal_ex(ctx, buf, &outl);
934 static const EVP_MD *evp_md = NULL;
935 static int EVP_Digest_loop(void *args)
937 loopargs_t *tempargs = *(loopargs_t **) args;
938 unsigned char *buf = tempargs->buf;
939 unsigned char md[EVP_MAX_MD_SIZE];
942 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
945 for (count = 0; COND(nb_iter); count++) {
946 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
952 #ifndef OPENSSL_NO_RSA
953 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
955 static int RSA_sign_loop(void *args)
957 loopargs_t *tempargs = *(loopargs_t **) args;
958 unsigned char *buf = tempargs->buf;
959 unsigned char *buf2 = tempargs->buf2;
960 unsigned int *rsa_num = &tempargs->siglen;
961 RSA **rsa_key = tempargs->rsa_key;
963 for (count = 0; COND(rsa_c[testnum][0]); count++) {
964 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
966 BIO_printf(bio_err, "RSA sign failure\n");
967 ERR_print_errors(bio_err);
975 static int RSA_verify_loop(void *args)
977 loopargs_t *tempargs = *(loopargs_t **) args;
978 unsigned char *buf = tempargs->buf;
979 unsigned char *buf2 = tempargs->buf2;
980 unsigned int rsa_num = tempargs->siglen;
981 RSA **rsa_key = tempargs->rsa_key;
983 for (count = 0; COND(rsa_c[testnum][1]); count++) {
985 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
987 BIO_printf(bio_err, "RSA verify failure\n");
988 ERR_print_errors(bio_err);
997 #ifndef OPENSSL_NO_DSA
998 static long dsa_c[DSA_NUM][2];
999 static int DSA_sign_loop(void *args)
1001 loopargs_t *tempargs = *(loopargs_t **) args;
1002 unsigned char *buf = tempargs->buf;
1003 unsigned char *buf2 = tempargs->buf2;
1004 DSA **dsa_key = tempargs->dsa_key;
1005 unsigned int *siglen = &tempargs->siglen;
1007 for (count = 0; COND(dsa_c[testnum][0]); count++) {
1008 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1010 BIO_printf(bio_err, "DSA sign failure\n");
1011 ERR_print_errors(bio_err);
1019 static int DSA_verify_loop(void *args)
1021 loopargs_t *tempargs = *(loopargs_t **) args;
1022 unsigned char *buf = tempargs->buf;
1023 unsigned char *buf2 = tempargs->buf2;
1024 DSA **dsa_key = tempargs->dsa_key;
1025 unsigned int siglen = tempargs->siglen;
1027 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1028 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1030 BIO_printf(bio_err, "DSA verify failure\n");
1031 ERR_print_errors(bio_err);
1040 #ifndef OPENSSL_NO_EC
1041 static long ecdsa_c[EC_NUM][2];
1042 static int ECDSA_sign_loop(void *args)
1044 loopargs_t *tempargs = *(loopargs_t **) args;
1045 unsigned char *buf = tempargs->buf;
1046 EC_KEY **ecdsa = tempargs->ecdsa;
1047 unsigned char *ecdsasig = tempargs->buf2;
1048 unsigned int *ecdsasiglen = &tempargs->siglen;
1050 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1051 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1053 BIO_printf(bio_err, "ECDSA sign failure\n");
1054 ERR_print_errors(bio_err);
1062 static int ECDSA_verify_loop(void *args)
1064 loopargs_t *tempargs = *(loopargs_t **) args;
1065 unsigned char *buf = tempargs->buf;
1066 EC_KEY **ecdsa = tempargs->ecdsa;
1067 unsigned char *ecdsasig = tempargs->buf2;
1068 unsigned int ecdsasiglen = tempargs->siglen;
1070 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1071 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1073 BIO_printf(bio_err, "ECDSA verify failure\n");
1074 ERR_print_errors(bio_err);
1082 /* ******************************************************************** */
1083 static long ecdh_c[EC_NUM][1];
1085 static int ECDH_EVP_derive_key_loop(void *args)
1087 loopargs_t *tempargs = *(loopargs_t **) args;
1088 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1089 unsigned char *derived_secret = tempargs->secret_a;
1091 size_t *outlen = &(tempargs->outlen[testnum]);
1093 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1094 EVP_PKEY_derive(ctx, derived_secret, outlen);
1099 #endif /* OPENSSL_NO_EC */
1101 static int run_benchmark(int async_jobs,
1102 int (*loop_function) (void *), loopargs_t * loopargs)
1104 int job_op_count = 0;
1105 int total_op_count = 0;
1106 int num_inprogress = 0;
1107 int error = 0, i = 0, ret = 0;
1108 OSSL_ASYNC_FD job_fd = 0;
1109 size_t num_job_fds = 0;
1113 if (async_jobs == 0) {
1114 return loop_function((void *)&loopargs);
1117 for (i = 0; i < async_jobs && !error; i++) {
1118 loopargs_t *looparg_item = loopargs + i;
1120 /* Copy pointer content (looparg_t item address) into async context */
1121 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1122 &job_op_count, loop_function,
1123 (void *)&looparg_item, sizeof(looparg_item));
1129 if (job_op_count == -1) {
1132 total_op_count += job_op_count;
1137 BIO_printf(bio_err, "Failure in the job\n");
1138 ERR_print_errors(bio_err);
1144 while (num_inprogress > 0) {
1145 #if defined(OPENSSL_SYS_WINDOWS)
1147 #elif defined(OPENSSL_SYS_UNIX)
1148 int select_result = 0;
1149 OSSL_ASYNC_FD max_fd = 0;
1152 FD_ZERO(&waitfdset);
1154 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1155 if (loopargs[i].inprogress_job == NULL)
1158 if (!ASYNC_WAIT_CTX_get_all_fds
1159 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1160 || num_job_fds > 1) {
1161 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1162 ERR_print_errors(bio_err);
1166 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1168 FD_SET(job_fd, &waitfdset);
1169 if (job_fd > max_fd)
1173 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1175 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1176 "Decrease the value of async_jobs\n",
1177 max_fd, FD_SETSIZE);
1178 ERR_print_errors(bio_err);
1183 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1184 if (select_result == -1 && errno == EINTR)
1187 if (select_result == -1) {
1188 BIO_printf(bio_err, "Failure in the select\n");
1189 ERR_print_errors(bio_err);
1194 if (select_result == 0)
1198 for (i = 0; i < async_jobs; i++) {
1199 if (loopargs[i].inprogress_job == NULL)
1202 if (!ASYNC_WAIT_CTX_get_all_fds
1203 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1204 || num_job_fds > 1) {
1205 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1206 ERR_print_errors(bio_err);
1210 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1213 #if defined(OPENSSL_SYS_UNIX)
1214 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1216 #elif defined(OPENSSL_SYS_WINDOWS)
1217 if (num_job_fds == 1
1218 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1223 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1224 loopargs[i].wait_ctx, &job_op_count,
1225 loop_function, (void *)(loopargs + i),
1226 sizeof(loopargs_t));
1231 if (job_op_count == -1) {
1234 total_op_count += job_op_count;
1237 loopargs[i].inprogress_job = NULL;
1242 loopargs[i].inprogress_job = NULL;
1243 BIO_printf(bio_err, "Failure in the job\n");
1244 ERR_print_errors(bio_err);
1251 return error ? -1 : total_op_count;
1254 int speed_main(int argc, char **argv)
1257 int (*loopfunc)(void *args);
1258 loopargs_t *loopargs = NULL;
1260 int loopargs_len = 0;
1262 const char *engine_id = NULL;
1263 const EVP_CIPHER *evp_cipher = NULL;
1266 int multiblock = 0, pr_header = 0;
1267 int doit[ALGOR_NUM] = { 0 };
1268 int ret = 1, i, k, misalign = 0;
1270 int size_num = OSSL_NELEM(lengths_list);
1276 unsigned int async_jobs = 0;
1277 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1278 || !defined(OPENSSL_NO_EC)
1281 #ifndef OPENSSL_NO_EC
1285 /* What follows are the buffers and key material. */
1286 #ifndef OPENSSL_NO_RC5
1289 #ifndef OPENSSL_NO_RC2
1292 #ifndef OPENSSL_NO_IDEA
1293 IDEA_KEY_SCHEDULE idea_ks;
1295 #ifndef OPENSSL_NO_SEED
1296 SEED_KEY_SCHEDULE seed_ks;
1298 #ifndef OPENSSL_NO_BF
1301 #ifndef OPENSSL_NO_CAST
1304 static const unsigned char key16[16] = {
1305 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1306 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1308 static const unsigned char key24[24] = {
1309 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1310 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1311 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1313 static const unsigned char key32[32] = {
1314 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1315 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1316 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1317 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1319 #ifndef OPENSSL_NO_CAMELLIA
1320 static const unsigned char ckey24[24] = {
1321 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1322 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1323 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1325 static const unsigned char ckey32[32] = {
1326 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1327 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1328 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1329 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1331 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1333 #ifndef OPENSSL_NO_DES
1334 static DES_cblock key = {
1335 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1337 static DES_cblock key2 = {
1338 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1340 static DES_cblock key3 = {
1341 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1344 #ifndef OPENSSL_NO_RSA
1345 static const unsigned int rsa_bits[RSA_NUM] = {
1346 512, 1024, 2048, 3072, 4096, 7680, 15360
1348 static const unsigned char *rsa_data[RSA_NUM] = {
1349 test512, test1024, test2048, test3072, test4096, test7680, test15360
1351 static const int rsa_data_length[RSA_NUM] = {
1352 sizeof(test512), sizeof(test1024),
1353 sizeof(test2048), sizeof(test3072),
1354 sizeof(test4096), sizeof(test7680),
1357 int rsa_doit[RSA_NUM] = { 0 };
1358 int primes = RSA_DEFAULT_PRIME_NUM;
1360 #ifndef OPENSSL_NO_DSA
1361 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1362 int dsa_doit[DSA_NUM] = { 0 };
1364 #ifndef OPENSSL_NO_EC
1366 * We only test over the following curves as they are representative, To
1367 * add tests over more curves, simply add the curve NID and curve name to
1368 * the following arrays and increase the EC_NUM value accordingly.
1370 static const unsigned int test_curves[EC_NUM] = {
1372 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1373 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1375 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1376 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1377 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1382 static const char *test_curves_names[EC_NUM] = {
1384 "secp160r1", "nistp192", "nistp224",
1385 "nistp256", "nistp384", "nistp521",
1387 "nistk163", "nistk233", "nistk283",
1388 "nistk409", "nistk571", "nistb163",
1389 "nistb233", "nistb283", "nistb409",
1394 static const int test_curves_bits[EC_NUM] = {
1400 571, 253 /* X25519 */
1403 int ecdsa_doit[EC_NUM] = { 0 };
1404 int ecdh_doit[EC_NUM] = { 0 };
1405 #endif /* ndef OPENSSL_NO_EC */
1407 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1408 ECDSA_SECONDS, ECDH_SECONDS };
1410 prog = opt_init(argc, argv, speed_options);
1411 while ((o = opt_next()) != OPT_EOF) {
1416 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1419 opt_help(speed_options);
1427 evp_cipher = EVP_get_cipherbyname(opt_arg());
1428 if (evp_cipher == NULL)
1429 evp_md = EVP_get_digestbyname(opt_arg());
1430 if (evp_cipher == NULL && evp_md == NULL) {
1432 "%s: %s is an unknown cipher or digest\n",
1443 * In a forked execution, an engine might need to be
1444 * initialised by each child process, not by the parent.
1445 * So store the name here and run setup_engine() later on.
1447 engine_id = opt_arg();
1451 multi = atoi(opt_arg());
1455 #ifndef OPENSSL_NO_ASYNC
1456 async_jobs = atoi(opt_arg());
1457 if (!ASYNC_is_capable()) {
1459 "%s: async_jobs specified but async not supported\n",
1463 if (async_jobs > 99999) {
1465 "%s: too many async_jobs\n",
1472 if (!opt_int(opt_arg(), &misalign))
1474 if (misalign > MISALIGN) {
1476 "%s: Maximum offset is %d\n", prog, MISALIGN);
1485 #ifdef OPENSSL_NO_MULTIBLOCK
1487 "%s: -mb specified but multi-block support is disabled\n",
1497 if (!opt_int(opt_arg(), &primes))
1501 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1502 = seconds.ecdh = atoi(opt_arg());
1505 lengths_single = atoi(opt_arg());
1506 lengths = &lengths_single;
1511 argc = opt_num_rest();
1514 /* Remaining arguments are algorithms. */
1515 for (; *argv; argv++) {
1516 if (found(*argv, doit_choices, &i)) {
1520 #ifndef OPENSSL_NO_DES
1521 if (strcmp(*argv, "des") == 0) {
1522 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1526 if (strcmp(*argv, "sha") == 0) {
1527 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1530 #ifndef OPENSSL_NO_RSA
1531 if (strcmp(*argv, "openssl") == 0)
1533 if (strcmp(*argv, "rsa") == 0) {
1534 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1535 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1536 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1537 rsa_doit[R_RSA_15360] = 1;
1540 if (found(*argv, rsa_choices, &i)) {
1545 #ifndef OPENSSL_NO_DSA
1546 if (strcmp(*argv, "dsa") == 0) {
1547 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1548 dsa_doit[R_DSA_2048] = 1;
1551 if (found(*argv, dsa_choices, &i)) {
1556 if (strcmp(*argv, "aes") == 0) {
1557 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1560 #ifndef OPENSSL_NO_CAMELLIA
1561 if (strcmp(*argv, "camellia") == 0) {
1562 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1566 #ifndef OPENSSL_NO_EC
1567 if (strcmp(*argv, "ecdsa") == 0) {
1568 for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++)
1569 ecdsa_doit[ecdsa_choices[loop].retval] = 1;
1572 if (found(*argv, ecdsa_choices, &i)) {
1576 if (strcmp(*argv, "ecdh") == 0) {
1577 for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++)
1578 ecdh_doit[ecdh_choices[loop].retval] = 1;
1581 if (found(*argv, ecdh_choices, &i)) {
1586 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1590 /* Initialize the job pool if async mode is enabled */
1591 if (async_jobs > 0) {
1592 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1594 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1599 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1601 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1602 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1604 for (i = 0; i < loopargs_len; i++) {
1605 if (async_jobs > 0) {
1606 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1607 if (loopargs[i].wait_ctx == NULL) {
1608 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1613 buflen = lengths[size_num - 1] + MAX_MISALIGNMENT + 1;
1614 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1615 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1616 memset(loopargs[i].buf_malloc, 0, buflen);
1617 memset(loopargs[i].buf2_malloc, 0, buflen);
1619 /* Align the start of buffers on a 64 byte boundary */
1620 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1621 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1622 #ifndef OPENSSL_NO_EC
1623 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1624 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1629 if (multi && do_multi(multi, size_num))
1633 /* Initialize the engine after the fork */
1634 e = setup_engine(engine_id, 0);
1636 /* No parameters; turn on everything. */
1637 if ((argc == 0) && !doit[D_EVP]) {
1638 for (i = 0; i < ALGOR_NUM; i++)
1641 #ifndef OPENSSL_NO_RSA
1642 for (i = 0; i < RSA_NUM; i++)
1645 #ifndef OPENSSL_NO_DSA
1646 for (i = 0; i < DSA_NUM; i++)
1649 #ifndef OPENSSL_NO_EC
1650 for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++)
1651 ecdsa_doit[ecdsa_choices[loop].retval] = 1;
1652 for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++)
1653 ecdh_doit[ecdh_choices[loop].retval] = 1;
1656 for (i = 0; i < ALGOR_NUM; i++)
1660 if (usertime == 0 && !mr)
1662 "You have chosen to measure elapsed time "
1663 "instead of user CPU time.\n");
1665 #ifndef OPENSSL_NO_RSA
1666 for (i = 0; i < loopargs_len; i++) {
1667 if (primes > RSA_DEFAULT_PRIME_NUM) {
1668 /* for multi-prime RSA, skip this */
1671 for (k = 0; k < RSA_NUM; k++) {
1672 const unsigned char *p;
1675 loopargs[i].rsa_key[k] =
1676 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1677 if (loopargs[i].rsa_key[k] == NULL) {
1679 "internal error loading RSA key number %d\n", k);
1685 #ifndef OPENSSL_NO_DSA
1686 for (i = 0; i < loopargs_len; i++) {
1687 loopargs[i].dsa_key[0] = get_dsa(512);
1688 loopargs[i].dsa_key[1] = get_dsa(1024);
1689 loopargs[i].dsa_key[2] = get_dsa(2048);
1692 #ifndef OPENSSL_NO_DES
1693 DES_set_key_unchecked(&key, &sch);
1694 DES_set_key_unchecked(&key2, &sch2);
1695 DES_set_key_unchecked(&key3, &sch3);
1697 AES_set_encrypt_key(key16, 128, &aes_ks1);
1698 AES_set_encrypt_key(key24, 192, &aes_ks2);
1699 AES_set_encrypt_key(key32, 256, &aes_ks3);
1700 #ifndef OPENSSL_NO_CAMELLIA
1701 Camellia_set_key(key16, 128, &camellia_ks1);
1702 Camellia_set_key(ckey24, 192, &camellia_ks2);
1703 Camellia_set_key(ckey32, 256, &camellia_ks3);
1705 #ifndef OPENSSL_NO_IDEA
1706 IDEA_set_encrypt_key(key16, &idea_ks);
1708 #ifndef OPENSSL_NO_SEED
1709 SEED_set_key(key16, &seed_ks);
1711 #ifndef OPENSSL_NO_RC4
1712 RC4_set_key(&rc4_ks, 16, key16);
1714 #ifndef OPENSSL_NO_RC2
1715 RC2_set_key(&rc2_ks, 16, key16, 128);
1717 #ifndef OPENSSL_NO_RC5
1718 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1720 #ifndef OPENSSL_NO_BF
1721 BF_set_key(&bf_ks, 16, key16);
1723 #ifndef OPENSSL_NO_CAST
1724 CAST_set_key(&cast_ks, 16, key16);
1727 # ifndef OPENSSL_NO_DES
1728 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1734 for (it = count; it; it--)
1735 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1736 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1740 c[D_MD2][0] = count / 10;
1741 c[D_MDC2][0] = count / 10;
1742 c[D_MD4][0] = count;
1743 c[D_MD5][0] = count;
1744 c[D_HMAC][0] = count;
1745 c[D_SHA1][0] = count;
1746 c[D_RMD160][0] = count;
1747 c[D_RC4][0] = count * 5;
1748 c[D_CBC_DES][0] = count;
1749 c[D_EDE3_DES][0] = count / 3;
1750 c[D_CBC_IDEA][0] = count;
1751 c[D_CBC_SEED][0] = count;
1752 c[D_CBC_RC2][0] = count;
1753 c[D_CBC_RC5][0] = count;
1754 c[D_CBC_BF][0] = count;
1755 c[D_CBC_CAST][0] = count;
1756 c[D_CBC_128_AES][0] = count;
1757 c[D_CBC_192_AES][0] = count;
1758 c[D_CBC_256_AES][0] = count;
1759 c[D_CBC_128_CML][0] = count;
1760 c[D_CBC_192_CML][0] = count;
1761 c[D_CBC_256_CML][0] = count;
1762 c[D_SHA256][0] = count;
1763 c[D_SHA512][0] = count;
1764 c[D_WHIRLPOOL][0] = count;
1765 c[D_IGE_128_AES][0] = count;
1766 c[D_IGE_192_AES][0] = count;
1767 c[D_IGE_256_AES][0] = count;
1768 c[D_GHASH][0] = count;
1769 c[D_RAND][0] = count;
1771 for (i = 1; i < size_num; i++) {
1774 l0 = (long)lengths[0];
1775 l1 = (long)lengths[i];
1777 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1778 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1779 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1780 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1781 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1782 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1783 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1784 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1785 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1786 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1787 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1788 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
1790 l0 = (long)lengths[i - 1];
1792 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1793 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1794 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1795 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1796 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1797 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1798 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1799 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1800 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1801 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1802 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1803 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1804 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1805 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1806 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1807 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1808 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1809 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1812 # ifndef OPENSSL_NO_RSA
1813 rsa_c[R_RSA_512][0] = count / 2000;
1814 rsa_c[R_RSA_512][1] = count / 400;
1815 for (i = 1; i < RSA_NUM; i++) {
1816 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1817 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1818 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1821 if (rsa_c[i][0] == 0) {
1822 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1829 # ifndef OPENSSL_NO_DSA
1830 dsa_c[R_DSA_512][0] = count / 1000;
1831 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1832 for (i = 1; i < DSA_NUM; i++) {
1833 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1834 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1835 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1838 if (dsa_c[i][0] == 0) {
1839 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1846 # ifndef OPENSSL_NO_EC
1847 ecdsa_c[R_EC_P160][0] = count / 1000;
1848 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1849 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1850 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1851 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1852 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1855 if (ecdsa_c[i][0] == 0) {
1861 ecdsa_c[R_EC_K163][0] = count / 1000;
1862 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1863 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1864 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1865 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1866 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1869 if (ecdsa_c[i][0] == 0) {
1875 ecdsa_c[R_EC_B163][0] = count / 1000;
1876 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1877 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1878 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1879 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1880 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1883 if (ecdsa_c[i][0] == 0) {
1890 ecdh_c[R_EC_P160][0] = count / 1000;
1891 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1892 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1893 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1896 if (ecdh_c[i][0] == 0) {
1901 ecdh_c[R_EC_K163][0] = count / 1000;
1902 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1903 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1904 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1907 if (ecdh_c[i][0] == 0) {
1912 ecdh_c[R_EC_B163][0] = count / 1000;
1913 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1914 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1915 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1918 if (ecdh_c[i][0] == 0) {
1926 /* not worth fixing */
1927 # error "You cannot disable DES on systems without SIGALRM."
1928 # endif /* OPENSSL_NO_DES */
1931 signal(SIGALRM, sig_done);
1933 #endif /* SIGALRM */
1935 #ifndef OPENSSL_NO_MD2
1937 for (testnum = 0; testnum < size_num; testnum++) {
1938 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
1941 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1943 print_result(D_MD2, testnum, count, d);
1947 #ifndef OPENSSL_NO_MDC2
1949 for (testnum = 0; testnum < size_num; testnum++) {
1950 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
1953 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1955 print_result(D_MDC2, testnum, count, d);
1960 #ifndef OPENSSL_NO_MD4
1962 for (testnum = 0; testnum < size_num; testnum++) {
1963 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
1966 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1968 print_result(D_MD4, testnum, count, d);
1973 #ifndef OPENSSL_NO_MD5
1975 for (testnum = 0; testnum < size_num; testnum++) {
1976 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
1979 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1981 print_result(D_MD5, testnum, count, d);
1986 static const char hmac_key[] = "This is a key...";
1987 int len = strlen(hmac_key);
1989 for (i = 0; i < loopargs_len; i++) {
1990 loopargs[i].hctx = HMAC_CTX_new();
1991 if (loopargs[i].hctx == NULL) {
1992 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1996 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1998 for (testnum = 0; testnum < size_num; testnum++) {
1999 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2002 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2004 print_result(D_HMAC, testnum, count, d);
2006 for (i = 0; i < loopargs_len; i++) {
2007 HMAC_CTX_free(loopargs[i].hctx);
2012 for (testnum = 0; testnum < size_num; testnum++) {
2013 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2016 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2018 print_result(D_SHA1, testnum, count, d);
2021 if (doit[D_SHA256]) {
2022 for (testnum = 0; testnum < size_num; testnum++) {
2023 print_message(names[D_SHA256], c[D_SHA256][testnum],
2024 lengths[testnum], seconds.sym);
2026 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2028 print_result(D_SHA256, testnum, count, d);
2031 if (doit[D_SHA512]) {
2032 for (testnum = 0; testnum < size_num; testnum++) {
2033 print_message(names[D_SHA512], c[D_SHA512][testnum],
2034 lengths[testnum], seconds.sym);
2036 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2038 print_result(D_SHA512, testnum, count, d);
2041 #ifndef OPENSSL_NO_WHIRLPOOL
2042 if (doit[D_WHIRLPOOL]) {
2043 for (testnum = 0; testnum < size_num; testnum++) {
2044 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2045 lengths[testnum], seconds.sym);
2047 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2049 print_result(D_WHIRLPOOL, testnum, count, d);
2054 #ifndef OPENSSL_NO_RMD160
2055 if (doit[D_RMD160]) {
2056 for (testnum = 0; testnum < size_num; testnum++) {
2057 print_message(names[D_RMD160], c[D_RMD160][testnum],
2058 lengths[testnum], seconds.sym);
2060 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2062 print_result(D_RMD160, testnum, count, d);
2066 #ifndef OPENSSL_NO_RC4
2068 for (testnum = 0; testnum < size_num; testnum++) {
2069 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2072 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2074 print_result(D_RC4, testnum, count, d);
2078 #ifndef OPENSSL_NO_DES
2079 if (doit[D_CBC_DES]) {
2080 for (testnum = 0; testnum < size_num; testnum++) {
2081 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2082 lengths[testnum], seconds.sym);
2084 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2086 print_result(D_CBC_DES, testnum, count, d);
2090 if (doit[D_EDE3_DES]) {
2091 for (testnum = 0; testnum < size_num; testnum++) {
2092 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2093 lengths[testnum], seconds.sym);
2096 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2098 print_result(D_EDE3_DES, testnum, count, d);
2103 if (doit[D_CBC_128_AES]) {
2104 for (testnum = 0; testnum < size_num; testnum++) {
2105 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2106 lengths[testnum], seconds.sym);
2109 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2111 print_result(D_CBC_128_AES, testnum, count, d);
2114 if (doit[D_CBC_192_AES]) {
2115 for (testnum = 0; testnum < size_num; testnum++) {
2116 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2117 lengths[testnum], seconds.sym);
2120 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2122 print_result(D_CBC_192_AES, testnum, count, d);
2125 if (doit[D_CBC_256_AES]) {
2126 for (testnum = 0; testnum < size_num; testnum++) {
2127 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2128 lengths[testnum], seconds.sym);
2131 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2133 print_result(D_CBC_256_AES, testnum, count, d);
2137 if (doit[D_IGE_128_AES]) {
2138 for (testnum = 0; testnum < size_num; testnum++) {
2139 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2140 lengths[testnum], seconds.sym);
2143 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2145 print_result(D_IGE_128_AES, testnum, count, d);
2148 if (doit[D_IGE_192_AES]) {
2149 for (testnum = 0; testnum < size_num; testnum++) {
2150 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2151 lengths[testnum], seconds.sym);
2154 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2156 print_result(D_IGE_192_AES, testnum, count, d);
2159 if (doit[D_IGE_256_AES]) {
2160 for (testnum = 0; testnum < size_num; testnum++) {
2161 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2162 lengths[testnum], seconds.sym);
2165 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2167 print_result(D_IGE_256_AES, testnum, count, d);
2170 if (doit[D_GHASH]) {
2171 for (i = 0; i < loopargs_len; i++) {
2172 loopargs[i].gcm_ctx =
2173 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2174 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2175 (unsigned char *)"0123456789ab", 12);
2178 for (testnum = 0; testnum < size_num; testnum++) {
2179 print_message(names[D_GHASH], c[D_GHASH][testnum],
2180 lengths[testnum], seconds.sym);
2182 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2184 print_result(D_GHASH, testnum, count, d);
2186 for (i = 0; i < loopargs_len; i++)
2187 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2189 #ifndef OPENSSL_NO_CAMELLIA
2190 if (doit[D_CBC_128_CML]) {
2191 if (async_jobs > 0) {
2192 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2193 names[D_CBC_128_CML]);
2194 doit[D_CBC_128_CML] = 0;
2196 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2197 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2198 lengths[testnum], seconds.sym);
2200 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2201 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2202 (size_t)lengths[testnum], &camellia_ks1,
2203 iv, CAMELLIA_ENCRYPT);
2205 print_result(D_CBC_128_CML, testnum, count, d);
2208 if (doit[D_CBC_192_CML]) {
2209 if (async_jobs > 0) {
2210 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2211 names[D_CBC_192_CML]);
2212 doit[D_CBC_192_CML] = 0;
2214 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2215 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2216 lengths[testnum], seconds.sym);
2217 if (async_jobs > 0) {
2218 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2222 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2223 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2224 (size_t)lengths[testnum], &camellia_ks2,
2225 iv, CAMELLIA_ENCRYPT);
2227 print_result(D_CBC_192_CML, testnum, count, d);
2230 if (doit[D_CBC_256_CML]) {
2231 if (async_jobs > 0) {
2232 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2233 names[D_CBC_256_CML]);
2234 doit[D_CBC_256_CML] = 0;
2236 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2237 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2238 lengths[testnum], seconds.sym);
2240 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2241 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2242 (size_t)lengths[testnum], &camellia_ks3,
2243 iv, CAMELLIA_ENCRYPT);
2245 print_result(D_CBC_256_CML, testnum, count, d);
2249 #ifndef OPENSSL_NO_IDEA
2250 if (doit[D_CBC_IDEA]) {
2251 if (async_jobs > 0) {
2252 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2254 doit[D_CBC_IDEA] = 0;
2256 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2257 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2258 lengths[testnum], seconds.sym);
2260 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2261 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2262 (size_t)lengths[testnum], &idea_ks,
2265 print_result(D_CBC_IDEA, testnum, count, d);
2269 #ifndef OPENSSL_NO_SEED
2270 if (doit[D_CBC_SEED]) {
2271 if (async_jobs > 0) {
2272 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2274 doit[D_CBC_SEED] = 0;
2276 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2277 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2278 lengths[testnum], seconds.sym);
2280 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2281 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2282 (size_t)lengths[testnum], &seed_ks, iv, 1);
2284 print_result(D_CBC_SEED, testnum, count, d);
2288 #ifndef OPENSSL_NO_RC2
2289 if (doit[D_CBC_RC2]) {
2290 if (async_jobs > 0) {
2291 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2293 doit[D_CBC_RC2] = 0;
2295 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2296 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2297 lengths[testnum], seconds.sym);
2298 if (async_jobs > 0) {
2299 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2303 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2304 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2305 (size_t)lengths[testnum], &rc2_ks,
2308 print_result(D_CBC_RC2, testnum, count, d);
2312 #ifndef OPENSSL_NO_RC5
2313 if (doit[D_CBC_RC5]) {
2314 if (async_jobs > 0) {
2315 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2317 doit[D_CBC_RC5] = 0;
2319 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2320 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2321 lengths[testnum], seconds.sym);
2322 if (async_jobs > 0) {
2323 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2327 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2328 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2329 (size_t)lengths[testnum], &rc5_ks,
2332 print_result(D_CBC_RC5, testnum, count, d);
2336 #ifndef OPENSSL_NO_BF
2337 if (doit[D_CBC_BF]) {
2338 if (async_jobs > 0) {
2339 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2343 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2344 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2345 lengths[testnum], seconds.sym);
2347 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2348 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2349 (size_t)lengths[testnum], &bf_ks,
2352 print_result(D_CBC_BF, testnum, count, d);
2356 #ifndef OPENSSL_NO_CAST
2357 if (doit[D_CBC_CAST]) {
2358 if (async_jobs > 0) {
2359 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2361 doit[D_CBC_CAST] = 0;
2363 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2364 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2365 lengths[testnum], seconds.sym);
2367 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2368 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2369 (size_t)lengths[testnum], &cast_ks,
2372 print_result(D_CBC_CAST, testnum, count, d);
2377 for (testnum = 0; testnum < size_num; testnum++) {
2378 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2381 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2383 print_result(D_RAND, testnum, count, d);
2388 if (multiblock && evp_cipher) {
2390 (EVP_CIPHER_flags(evp_cipher) &
2391 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2392 BIO_printf(bio_err, "%s is not multi-block capable\n",
2393 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2396 if (async_jobs > 0) {
2397 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2400 multiblock_speed(evp_cipher, &seconds);
2404 for (testnum = 0; testnum < size_num; testnum++) {
2407 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2409 * -O3 -fschedule-insns messes up an optimization here!
2410 * names[D_EVP] somehow becomes NULL
2412 print_message(names[D_EVP], save_count, lengths[testnum],
2415 for (k = 0; k < loopargs_len; k++) {
2416 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2417 EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
2418 iv, decrypt ? 0 : 1);
2420 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2422 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2423 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2424 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2425 EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2426 loopargs[k].key, NULL, -1);
2427 OPENSSL_clear_free(loopargs[k].key, keylen);
2429 switch (EVP_CIPHER_mode(evp_cipher)) {
2430 case EVP_CIPH_CCM_MODE:
2431 loopfunc = EVP_Update_loop_ccm;
2434 loopfunc = EVP_Update_loop;
2438 count = run_benchmark(async_jobs, loopfunc, loopargs);
2440 for (k = 0; k < loopargs_len; k++) {
2441 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2445 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2446 print_message(names[D_EVP], save_count, lengths[testnum],
2449 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2452 print_result(D_EVP, testnum, count, d);
2456 for (i = 0; i < loopargs_len; i++)
2457 RAND_bytes(loopargs[i].buf, 36);
2459 #ifndef OPENSSL_NO_RSA
2460 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2462 if (!rsa_doit[testnum])
2464 for (i = 0; i < loopargs_len; i++) {
2466 /* we haven't set keys yet, generate multi-prime RSA keys */
2467 BIGNUM *bn = BN_new();
2471 if (!BN_set_word(bn, RSA_F4)) {
2476 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2477 rsa_choices[testnum].name);
2479 loopargs[i].rsa_key[testnum] = RSA_new();
2480 if (loopargs[i].rsa_key[testnum] == NULL) {
2485 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2487 primes, bn, NULL)) {
2493 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2494 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2500 "RSA sign failure. No RSA sign will be done.\n");
2501 ERR_print_errors(bio_err);
2504 pkey_print_message("private", "rsa",
2505 rsa_c[testnum][0], rsa_bits[testnum],
2507 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2509 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2512 mr ? "+R1:%ld:%d:%.2f\n"
2513 : "%ld %d bit private RSA's in %.2fs\n",
2514 count, rsa_bits[testnum], d);
2515 rsa_results[testnum][0] = (double)count / d;
2519 for (i = 0; i < loopargs_len; i++) {
2520 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2521 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2527 "RSA verify failure. No RSA verify will be done.\n");
2528 ERR_print_errors(bio_err);
2529 rsa_doit[testnum] = 0;
2531 pkey_print_message("public", "rsa",
2532 rsa_c[testnum][1], rsa_bits[testnum],
2535 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2538 mr ? "+R2:%ld:%d:%.2f\n"
2539 : "%ld %d bit public RSA's in %.2fs\n",
2540 count, rsa_bits[testnum], d);
2541 rsa_results[testnum][1] = (double)count / d;
2544 if (rsa_count <= 1) {
2545 /* if longer than 10s, don't do any more */
2546 for (testnum++; testnum < RSA_NUM; testnum++)
2547 rsa_doit[testnum] = 0;
2550 #endif /* OPENSSL_NO_RSA */
2552 for (i = 0; i < loopargs_len; i++)
2553 RAND_bytes(loopargs[i].buf, 36);
2555 #ifndef OPENSSL_NO_DSA
2556 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2558 if (!dsa_doit[testnum])
2561 /* DSA_generate_key(dsa_key[testnum]); */
2562 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2563 for (i = 0; i < loopargs_len; i++) {
2564 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2565 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2571 "DSA sign failure. No DSA sign will be done.\n");
2572 ERR_print_errors(bio_err);
2575 pkey_print_message("sign", "dsa",
2576 dsa_c[testnum][0], dsa_bits[testnum],
2579 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2582 mr ? "+R3:%ld:%d:%.2f\n"
2583 : "%ld %d bit DSA signs in %.2fs\n",
2584 count, dsa_bits[testnum], d);
2585 dsa_results[testnum][0] = (double)count / d;
2589 for (i = 0; i < loopargs_len; i++) {
2590 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2591 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2597 "DSA verify failure. No DSA verify will be done.\n");
2598 ERR_print_errors(bio_err);
2599 dsa_doit[testnum] = 0;
2601 pkey_print_message("verify", "dsa",
2602 dsa_c[testnum][1], dsa_bits[testnum],
2605 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2608 mr ? "+R4:%ld:%d:%.2f\n"
2609 : "%ld %d bit DSA verify in %.2fs\n",
2610 count, dsa_bits[testnum], d);
2611 dsa_results[testnum][1] = (double)count / d;
2614 if (rsa_count <= 1) {
2615 /* if longer than 10s, don't do any more */
2616 for (testnum++; testnum < DSA_NUM; testnum++)
2617 dsa_doit[testnum] = 0;
2620 #endif /* OPENSSL_NO_DSA */
2622 #ifndef OPENSSL_NO_EC
2623 for (testnum = 0; testnum < EC_NUM; testnum++) {
2626 if (!ecdsa_doit[testnum])
2627 continue; /* Ignore Curve */
2628 for (i = 0; i < loopargs_len; i++) {
2629 loopargs[i].ecdsa[testnum] =
2630 EC_KEY_new_by_curve_name(test_curves[testnum]);
2631 if (loopargs[i].ecdsa[testnum] == NULL) {
2637 BIO_printf(bio_err, "ECDSA failure.\n");
2638 ERR_print_errors(bio_err);
2641 for (i = 0; i < loopargs_len; i++) {
2642 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2643 /* Perform ECDSA signature test */
2644 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2645 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2646 &loopargs[i].siglen,
2647 loopargs[i].ecdsa[testnum]);
2653 "ECDSA sign failure. No ECDSA sign will be done.\n");
2654 ERR_print_errors(bio_err);
2657 pkey_print_message("sign", "ecdsa",
2658 ecdsa_c[testnum][0],
2659 test_curves_bits[testnum],
2662 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2666 mr ? "+R5:%ld:%d:%.2f\n" :
2667 "%ld %d bit ECDSA signs in %.2fs \n",
2668 count, test_curves_bits[testnum], d);
2669 ecdsa_results[testnum][0] = (double)count / d;
2673 /* Perform ECDSA verification test */
2674 for (i = 0; i < loopargs_len; i++) {
2675 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2677 loopargs[i].ecdsa[testnum]);
2683 "ECDSA verify failure. No ECDSA verify will be done.\n");
2684 ERR_print_errors(bio_err);
2685 ecdsa_doit[testnum] = 0;
2687 pkey_print_message("verify", "ecdsa",
2688 ecdsa_c[testnum][1],
2689 test_curves_bits[testnum],
2692 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2695 mr ? "+R6:%ld:%d:%.2f\n"
2696 : "%ld %d bit ECDSA verify in %.2fs\n",
2697 count, test_curves_bits[testnum], d);
2698 ecdsa_results[testnum][1] = (double)count / d;
2701 if (rsa_count <= 1) {
2702 /* if longer than 10s, don't do any more */
2703 for (testnum++; testnum < EC_NUM; testnum++)
2704 ecdsa_doit[testnum] = 0;
2709 for (testnum = 0; testnum < EC_NUM; testnum++) {
2710 int ecdh_checks = 1;
2712 if (!ecdh_doit[testnum])
2715 for (i = 0; i < loopargs_len; i++) {
2716 EVP_PKEY_CTX *kctx = NULL;
2717 EVP_PKEY_CTX *test_ctx = NULL;
2718 EVP_PKEY_CTX *ctx = NULL;
2719 EVP_PKEY *key_A = NULL;
2720 EVP_PKEY *key_B = NULL;
2724 /* Ensure that the error queue is empty */
2725 if (ERR_peek_error()) {
2727 "WARNING: the error queue contains previous unhandled errors.\n");
2728 ERR_print_errors(bio_err);
2731 /* Let's try to create a ctx directly from the NID: this works for
2732 * curves like Curve25519 that are not implemented through the low
2733 * level EC interface.
2734 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2735 * then we set the curve by NID before deriving the actual keygen
2736 * ctx for that specific curve. */
2737 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2739 EVP_PKEY_CTX *pctx = NULL;
2740 EVP_PKEY *params = NULL;
2742 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2743 * "int_ctx_new:unsupported algorithm" error was added to the
2745 * We remove it from the error queue as we are handling it. */
2746 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2747 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2748 /* check that the error origin matches */
2749 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2750 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2751 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2752 ERR_get_error(); /* pop error from queue */
2753 if (ERR_peek_error()) {
2755 "Unhandled error in the error queue during ECDH init.\n");
2756 ERR_print_errors(bio_err);
2761 if ( /* Create the context for parameter generation */
2762 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2763 /* Initialise the parameter generation */
2764 !EVP_PKEY_paramgen_init(pctx) ||
2765 /* Set the curve by NID */
2766 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2769 /* Create the parameter object params */
2770 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2772 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2773 ERR_print_errors(bio_err);
2777 /* Create the context for the key generation */
2778 kctx = EVP_PKEY_CTX_new(params, NULL);
2780 EVP_PKEY_free(params);
2782 EVP_PKEY_CTX_free(pctx);
2785 if (kctx == NULL || /* keygen ctx is not null */
2786 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2788 BIO_printf(bio_err, "ECDH keygen failure.\n");
2789 ERR_print_errors(bio_err);
2794 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2795 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2796 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2797 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2798 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2799 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2800 outlen == 0 || /* ensure outlen is a valid size */
2801 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2803 BIO_printf(bio_err, "ECDH key generation failure.\n");
2804 ERR_print_errors(bio_err);
2809 /* Here we perform a test run, comparing the output of a*B and b*A;
2810 * we try this here and assume that further EVP_PKEY_derive calls
2811 * never fail, so we can skip checks in the actually benchmarked
2812 * code, for maximum performance. */
2813 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2814 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2815 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2816 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2817 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2818 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2819 test_outlen != outlen /* compare output length */ ) {
2821 BIO_printf(bio_err, "ECDH computation failure.\n");
2822 ERR_print_errors(bio_err);
2827 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2828 if (CRYPTO_memcmp(loopargs[i].secret_a,
2829 loopargs[i].secret_b, outlen)) {
2831 BIO_printf(bio_err, "ECDH computations don't match.\n");
2832 ERR_print_errors(bio_err);
2837 loopargs[i].ecdh_ctx[testnum] = ctx;
2838 loopargs[i].outlen[testnum] = outlen;
2840 EVP_PKEY_free(key_A);
2841 EVP_PKEY_free(key_B);
2842 EVP_PKEY_CTX_free(kctx);
2844 EVP_PKEY_CTX_free(test_ctx);
2847 if (ecdh_checks != 0) {
2848 pkey_print_message("", "ecdh",
2850 test_curves_bits[testnum],
2854 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2857 mr ? "+R7:%ld:%d:%.2f\n" :
2858 "%ld %d-bit ECDH ops in %.2fs\n", count,
2859 test_curves_bits[testnum], d);
2860 ecdh_results[testnum][0] = (double)count / d;
2864 if (rsa_count <= 1) {
2865 /* if longer than 10s, don't do any more */
2866 for (testnum++; testnum < EC_NUM; testnum++)
2867 ecdh_doit[testnum] = 0;
2870 #endif /* OPENSSL_NO_EC */
2875 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2876 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2878 printf("%s ", BN_options());
2879 #ifndef OPENSSL_NO_MD2
2880 printf("%s ", MD2_options());
2882 #ifndef OPENSSL_NO_RC4
2883 printf("%s ", RC4_options());
2885 #ifndef OPENSSL_NO_DES
2886 printf("%s ", DES_options());
2888 printf("%s ", AES_options());
2889 #ifndef OPENSSL_NO_IDEA
2890 printf("%s ", IDEA_options());
2892 #ifndef OPENSSL_NO_BF
2893 printf("%s ", BF_options());
2895 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2903 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2906 for (testnum = 0; testnum < size_num; testnum++)
2907 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2911 for (k = 0; k < ALGOR_NUM; k++) {
2915 printf("+F:%d:%s", k, names[k]);
2917 printf("%-13s", names[k]);
2918 for (testnum = 0; testnum < size_num; testnum++) {
2919 if (results[k][testnum] > 10000 && !mr)
2920 printf(" %11.2fk", results[k][testnum] / 1e3);
2922 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2926 #ifndef OPENSSL_NO_RSA
2928 for (k = 0; k < RSA_NUM; k++) {
2931 if (testnum && !mr) {
2932 printf("%18ssign verify sign/s verify/s\n", " ");
2936 printf("+F2:%u:%u:%f:%f\n",
2937 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2939 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2940 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2941 rsa_results[k][0], rsa_results[k][1]);
2944 #ifndef OPENSSL_NO_DSA
2946 for (k = 0; k < DSA_NUM; k++) {
2949 if (testnum && !mr) {
2950 printf("%18ssign verify sign/s verify/s\n", " ");
2954 printf("+F3:%u:%u:%f:%f\n",
2955 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2957 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2958 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2959 dsa_results[k][0], dsa_results[k][1]);
2962 #ifndef OPENSSL_NO_EC
2964 for (k = 0; k < EC_NUM; k++) {
2967 if (testnum && !mr) {
2968 printf("%30ssign verify sign/s verify/s\n", " ");
2973 printf("+F4:%u:%u:%f:%f\n",
2974 k, test_curves_bits[k],
2975 ecdsa_results[k][0], ecdsa_results[k][1]);
2977 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2978 test_curves_bits[k],
2979 test_curves_names[k],
2980 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2981 ecdsa_results[k][0], ecdsa_results[k][1]);
2985 for (k = 0; k < EC_NUM; k++) {
2988 if (testnum && !mr) {
2989 printf("%30sop op/s\n", " ");
2993 printf("+F5:%u:%u:%f:%f\n",
2994 k, test_curves_bits[k],
2995 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2998 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2999 test_curves_bits[k],
3000 test_curves_names[k],
3001 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3008 ERR_print_errors(bio_err);
3009 for (i = 0; i < loopargs_len; i++) {
3010 OPENSSL_free(loopargs[i].buf_malloc);
3011 OPENSSL_free(loopargs[i].buf2_malloc);
3013 #ifndef OPENSSL_NO_RSA
3014 for (k = 0; k < RSA_NUM; k++)
3015 RSA_free(loopargs[i].rsa_key[k]);
3017 #ifndef OPENSSL_NO_DSA
3018 for (k = 0; k < DSA_NUM; k++)
3019 DSA_free(loopargs[i].dsa_key[k]);
3021 #ifndef OPENSSL_NO_EC
3022 for (k = 0; k < EC_NUM; k++) {
3023 EC_KEY_free(loopargs[i].ecdsa[k]);
3024 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3026 OPENSSL_free(loopargs[i].secret_a);
3027 OPENSSL_free(loopargs[i].secret_b);
3031 if (async_jobs > 0) {
3032 for (i = 0; i < loopargs_len; i++)
3033 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3037 ASYNC_cleanup_thread();
3039 OPENSSL_free(loopargs);
3044 static void print_message(const char *s, long num, int length, int tm)
3048 mr ? "+DT:%s:%d:%d\n"
3049 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3050 (void)BIO_flush(bio_err);
3054 mr ? "+DN:%s:%ld:%d\n"
3055 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3056 (void)BIO_flush(bio_err);
3060 static void pkey_print_message(const char *str, const char *str2, long num,
3065 mr ? "+DTP:%d:%s:%s:%d\n"
3066 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
3067 (void)BIO_flush(bio_err);
3071 mr ? "+DNP:%ld:%d:%s:%s\n"
3072 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
3073 (void)BIO_flush(bio_err);
3077 static void print_result(int alg, int run_no, int count, double time_used)
3080 BIO_puts(bio_err, "EVP error!\n");
3084 mr ? "+R:%d:%s:%f\n"
3085 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3086 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3090 static char *sstrsep(char **string, const char *delim)
3093 char *token = *string;
3098 memset(isdelim, 0, sizeof(isdelim));
3102 isdelim[(unsigned char)(*delim)] = 1;
3106 while (!isdelim[(unsigned char)(**string)]) {
3118 static int do_multi(int multi, int size_num)
3123 static char sep[] = ":";
3125 fds = malloc(sizeof(*fds) * multi);
3126 for (n = 0; n < multi; ++n) {
3127 if (pipe(fd) == -1) {
3128 BIO_printf(bio_err, "pipe failure\n");
3132 (void)BIO_flush(bio_err);
3139 if (dup(fd[1]) == -1) {
3140 BIO_printf(bio_err, "dup failed\n");
3149 printf("Forked child %d\n", n);
3152 /* for now, assume the pipe is long enough to take all the output */
3153 for (n = 0; n < multi; ++n) {
3158 f = fdopen(fds[n], "r");
3159 while (fgets(buf, sizeof(buf), f)) {
3160 p = strchr(buf, '\n');
3163 if (buf[0] != '+') {
3165 "Don't understand line '%s' from child %d\n", buf,
3169 printf("Got: %s from %d\n", buf, n);
3170 if (strncmp(buf, "+F:", 3) == 0) {
3175 alg = atoi(sstrsep(&p, sep));
3177 for (j = 0; j < size_num; ++j)
3178 results[alg][j] += atof(sstrsep(&p, sep));
3179 } else if (strncmp(buf, "+F2:", 4) == 0) {
3184 k = atoi(sstrsep(&p, sep));
3187 d = atof(sstrsep(&p, sep));
3188 rsa_results[k][0] += d;
3190 d = atof(sstrsep(&p, sep));
3191 rsa_results[k][1] += d;
3193 # ifndef OPENSSL_NO_DSA
3194 else if (strncmp(buf, "+F3:", 4) == 0) {
3199 k = atoi(sstrsep(&p, sep));
3202 d = atof(sstrsep(&p, sep));
3203 dsa_results[k][0] += d;
3205 d = atof(sstrsep(&p, sep));
3206 dsa_results[k][1] += d;
3209 # ifndef OPENSSL_NO_EC
3210 else if (strncmp(buf, "+F4:", 4) == 0) {
3215 k = atoi(sstrsep(&p, sep));
3218 d = atof(sstrsep(&p, sep));
3219 ecdsa_results[k][0] += d;
3221 d = atof(sstrsep(&p, sep));
3222 ecdsa_results[k][1] += d;
3223 } else if (strncmp(buf, "+F5:", 4) == 0) {
3228 k = atoi(sstrsep(&p, sep));
3231 d = atof(sstrsep(&p, sep));
3232 ecdh_results[k][0] += d;
3236 else if (strncmp(buf, "+H:", 3) == 0) {
3239 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3250 static void multiblock_speed(const EVP_CIPHER *evp_cipher,
3251 const openssl_speed_sec_t *seconds)
3253 static const int mblengths_list[] =
3254 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3255 const int *mblengths = mblengths_list;
3256 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
3257 const char *alg_name;
3258 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
3259 EVP_CIPHER_CTX *ctx;
3262 if (lengths_single) {
3263 mblengths = &lengths_single;
3267 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3268 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3269 ctx = EVP_CIPHER_CTX_new();
3270 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
3272 keylen = EVP_CIPHER_CTX_key_length(ctx);
3273 key = app_malloc(keylen, "evp_cipher key");
3274 EVP_CIPHER_CTX_rand_key(ctx, key);
3275 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
3276 OPENSSL_clear_free(key, keylen);
3278 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3279 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3281 for (j = 0; j < num; j++) {
3282 print_message(alg_name, 0, mblengths[j], seconds->sym);
3284 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3285 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3286 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3287 size_t len = mblengths[j];
3290 memset(aad, 0, 8); /* avoid uninitialized values */
3291 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3292 aad[9] = 3; /* version */
3294 aad[11] = 0; /* length */
3296 mb_param.out = NULL;
3299 mb_param.interleave = 8;
3301 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3302 sizeof(mb_param), &mb_param);
3308 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3309 sizeof(mb_param), &mb_param);
3313 RAND_bytes(out, 16);
3315 aad[11] = (unsigned char)(len >> 8);
3316 aad[12] = (unsigned char)(len);
3317 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3318 EVP_AEAD_TLS1_AAD_LEN, aad);
3319 EVP_Cipher(ctx, out, inp, len + pad);
3323 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3324 : "%d %s's in %.2fs\n", count, "evp", d);
3325 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3329 fprintf(stdout, "+H");
3330 for (j = 0; j < num; j++)
3331 fprintf(stdout, ":%d", mblengths[j]);
3332 fprintf(stdout, "\n");
3333 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3334 for (j = 0; j < num; j++)
3335 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3336 fprintf(stdout, "\n");
3339 "The 'numbers' are in 1000s of bytes per second processed.\n");
3340 fprintf(stdout, "type ");
3341 for (j = 0; j < num; j++)
3342 fprintf(stdout, "%7d bytes", mblengths[j]);
3343 fprintf(stdout, "\n");
3344 fprintf(stdout, "%-24s", alg_name);
3346 for (j = 0; j < num; j++) {
3347 if (results[D_EVP][j] > 10000)
3348 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3350 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3352 fprintf(stdout, "\n");
3357 EVP_CIPHER_CTX_free(ctx);