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)
1280 #ifndef OPENSSL_NO_EC
1284 /* What follows are the buffers and key material. */
1285 #ifndef OPENSSL_NO_RC5
1288 #ifndef OPENSSL_NO_RC2
1291 #ifndef OPENSSL_NO_IDEA
1292 IDEA_KEY_SCHEDULE idea_ks;
1294 #ifndef OPENSSL_NO_SEED
1295 SEED_KEY_SCHEDULE seed_ks;
1297 #ifndef OPENSSL_NO_BF
1300 #ifndef OPENSSL_NO_CAST
1303 static const unsigned char key16[16] = {
1304 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1305 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1307 static const unsigned char key24[24] = {
1308 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1309 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1310 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1312 static const unsigned char key32[32] = {
1313 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1314 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1315 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1316 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1318 #ifndef OPENSSL_NO_CAMELLIA
1319 static const unsigned char ckey24[24] = {
1320 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1321 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1322 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1324 static const unsigned char ckey32[32] = {
1325 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1326 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1327 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1328 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1330 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1332 #ifndef OPENSSL_NO_DES
1333 static DES_cblock key = {
1334 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1336 static DES_cblock key2 = {
1337 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1339 static DES_cblock key3 = {
1340 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1343 #ifndef OPENSSL_NO_RSA
1344 static const unsigned int rsa_bits[RSA_NUM] = {
1345 512, 1024, 2048, 3072, 4096, 7680, 15360
1347 static const unsigned char *rsa_data[RSA_NUM] = {
1348 test512, test1024, test2048, test3072, test4096, test7680, test15360
1350 static const int rsa_data_length[RSA_NUM] = {
1351 sizeof(test512), sizeof(test1024),
1352 sizeof(test2048), sizeof(test3072),
1353 sizeof(test4096), sizeof(test7680),
1356 int rsa_doit[RSA_NUM] = { 0 };
1357 int primes = RSA_DEFAULT_PRIME_NUM;
1359 #ifndef OPENSSL_NO_DSA
1360 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1361 int dsa_doit[DSA_NUM] = { 0 };
1363 #ifndef OPENSSL_NO_EC
1365 * We only test over the following curves as they are representative, To
1366 * add tests over more curves, simply add the curve NID and curve name to
1367 * the following arrays and increase the EC_NUM value accordingly.
1369 static const unsigned int test_curves[EC_NUM] = {
1371 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1372 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1374 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1375 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1376 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1381 static const char *test_curves_names[EC_NUM] = {
1383 "secp160r1", "nistp192", "nistp224",
1384 "nistp256", "nistp384", "nistp521",
1386 "nistk163", "nistk233", "nistk283",
1387 "nistk409", "nistk571", "nistb163",
1388 "nistb233", "nistb283", "nistb409",
1393 static const int test_curves_bits[EC_NUM] = {
1399 571, 253 /* X25519 */
1402 int ecdsa_doit[EC_NUM] = { 0 };
1403 int ecdh_doit[EC_NUM] = { 0 };
1404 #endif /* ndef OPENSSL_NO_EC */
1406 openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
1407 ECDSA_SECONDS, ECDH_SECONDS };
1409 prog = opt_init(argc, argv, speed_options);
1410 while ((o = opt_next()) != OPT_EOF) {
1415 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1418 opt_help(speed_options);
1426 evp_cipher = EVP_get_cipherbyname(opt_arg());
1427 if (evp_cipher == NULL)
1428 evp_md = EVP_get_digestbyname(opt_arg());
1429 if (evp_cipher == NULL && evp_md == NULL) {
1431 "%s: %s is an unknown cipher or digest\n",
1442 * In a forked execution, an engine might need to be
1443 * initialised by each child process, not by the parent.
1444 * So store the name here and run setup_engine() later on.
1446 engine_id = opt_arg();
1450 multi = atoi(opt_arg());
1454 #ifndef OPENSSL_NO_ASYNC
1455 async_jobs = atoi(opt_arg());
1456 if (!ASYNC_is_capable()) {
1458 "%s: async_jobs specified but async not supported\n",
1462 if (async_jobs > 99999) {
1464 "%s: too many async_jobs\n",
1471 if (!opt_int(opt_arg(), &misalign))
1473 if (misalign > MISALIGN) {
1475 "%s: Maximum offset is %d\n", prog, MISALIGN);
1484 #ifdef OPENSSL_NO_MULTIBLOCK
1486 "%s: -mb specified but multi-block support is disabled\n",
1496 if (!opt_int(opt_arg(), &primes))
1500 seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
1501 = seconds.ecdh = atoi(opt_arg());
1504 lengths_single = atoi(opt_arg());
1505 lengths = &lengths_single;
1510 argc = opt_num_rest();
1513 /* Remaining arguments are algorithms. */
1514 for (; *argv; argv++) {
1515 if (found(*argv, doit_choices, &i)) {
1519 #ifndef OPENSSL_NO_DES
1520 if (strcmp(*argv, "des") == 0) {
1521 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1525 if (strcmp(*argv, "sha") == 0) {
1526 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1529 #ifndef OPENSSL_NO_RSA
1530 if (strcmp(*argv, "openssl") == 0)
1532 if (strcmp(*argv, "rsa") == 0) {
1533 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1534 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1535 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1536 rsa_doit[R_RSA_15360] = 1;
1539 if (found(*argv, rsa_choices, &i)) {
1544 #ifndef OPENSSL_NO_DSA
1545 if (strcmp(*argv, "dsa") == 0) {
1546 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1547 dsa_doit[R_DSA_2048] = 1;
1550 if (found(*argv, dsa_choices, &i)) {
1555 if (strcmp(*argv, "aes") == 0) {
1556 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1559 #ifndef OPENSSL_NO_CAMELLIA
1560 if (strcmp(*argv, "camellia") == 0) {
1561 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1565 #ifndef OPENSSL_NO_EC
1566 if (strcmp(*argv, "ecdsa") == 0) {
1567 for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++)
1568 ecdsa_doit[ecdsa_choices[loop].retval] = 1;
1571 if (found(*argv, ecdsa_choices, &i)) {
1575 if (strcmp(*argv, "ecdh") == 0) {
1576 for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++)
1577 ecdh_doit[ecdh_choices[loop].retval] = 1;
1580 if (found(*argv, ecdh_choices, &i)) {
1585 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1589 /* Initialize the job pool if async mode is enabled */
1590 if (async_jobs > 0) {
1591 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1593 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1598 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1600 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1601 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1603 for (i = 0; i < loopargs_len; i++) {
1604 if (async_jobs > 0) {
1605 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1606 if (loopargs[i].wait_ctx == NULL) {
1607 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1612 buflen = lengths[size_num - 1] + MAX_MISALIGNMENT + 1;
1613 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
1614 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
1615 memset(loopargs[i].buf_malloc, 0, buflen);
1616 memset(loopargs[i].buf2_malloc, 0, buflen);
1618 /* Align the start of buffers on a 64 byte boundary */
1619 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1620 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1621 #ifndef OPENSSL_NO_EC
1622 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1623 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1628 if (multi && do_multi(multi, size_num))
1632 /* Initialize the engine after the fork */
1633 e = setup_engine(engine_id, 0);
1635 /* No parameters; turn on everything. */
1636 if ((argc == 0) && !doit[D_EVP]) {
1637 for (i = 0; i < ALGOR_NUM; i++)
1640 #ifndef OPENSSL_NO_RSA
1641 for (i = 0; i < RSA_NUM; i++)
1644 #ifndef OPENSSL_NO_DSA
1645 for (i = 0; i < DSA_NUM; i++)
1648 #ifndef OPENSSL_NO_EC
1649 for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++)
1650 ecdsa_doit[ecdsa_choices[loop].retval] = 1;
1651 for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++)
1652 ecdh_doit[ecdh_choices[loop].retval] = 1;
1655 for (i = 0; i < ALGOR_NUM; i++)
1659 if (usertime == 0 && !mr)
1661 "You have chosen to measure elapsed time "
1662 "instead of user CPU time.\n");
1664 #ifndef OPENSSL_NO_RSA
1665 for (i = 0; i < loopargs_len; i++) {
1666 if (primes > RSA_DEFAULT_PRIME_NUM) {
1667 /* for multi-prime RSA, skip this */
1670 for (k = 0; k < RSA_NUM; k++) {
1671 const unsigned char *p;
1674 loopargs[i].rsa_key[k] =
1675 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1676 if (loopargs[i].rsa_key[k] == NULL) {
1678 "internal error loading RSA key number %d\n", k);
1684 #ifndef OPENSSL_NO_DSA
1685 for (i = 0; i < loopargs_len; i++) {
1686 loopargs[i].dsa_key[0] = get_dsa(512);
1687 loopargs[i].dsa_key[1] = get_dsa(1024);
1688 loopargs[i].dsa_key[2] = get_dsa(2048);
1691 #ifndef OPENSSL_NO_DES
1692 DES_set_key_unchecked(&key, &sch);
1693 DES_set_key_unchecked(&key2, &sch2);
1694 DES_set_key_unchecked(&key3, &sch3);
1696 AES_set_encrypt_key(key16, 128, &aes_ks1);
1697 AES_set_encrypt_key(key24, 192, &aes_ks2);
1698 AES_set_encrypt_key(key32, 256, &aes_ks3);
1699 #ifndef OPENSSL_NO_CAMELLIA
1700 Camellia_set_key(key16, 128, &camellia_ks1);
1701 Camellia_set_key(ckey24, 192, &camellia_ks2);
1702 Camellia_set_key(ckey32, 256, &camellia_ks3);
1704 #ifndef OPENSSL_NO_IDEA
1705 IDEA_set_encrypt_key(key16, &idea_ks);
1707 #ifndef OPENSSL_NO_SEED
1708 SEED_set_key(key16, &seed_ks);
1710 #ifndef OPENSSL_NO_RC4
1711 RC4_set_key(&rc4_ks, 16, key16);
1713 #ifndef OPENSSL_NO_RC2
1714 RC2_set_key(&rc2_ks, 16, key16, 128);
1716 #ifndef OPENSSL_NO_RC5
1717 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1719 #ifndef OPENSSL_NO_BF
1720 BF_set_key(&bf_ks, 16, key16);
1722 #ifndef OPENSSL_NO_CAST
1723 CAST_set_key(&cast_ks, 16, key16);
1726 # ifndef OPENSSL_NO_DES
1727 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1733 for (it = count; it; it--)
1734 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1735 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1739 c[D_MD2][0] = count / 10;
1740 c[D_MDC2][0] = count / 10;
1741 c[D_MD4][0] = count;
1742 c[D_MD5][0] = count;
1743 c[D_HMAC][0] = count;
1744 c[D_SHA1][0] = count;
1745 c[D_RMD160][0] = count;
1746 c[D_RC4][0] = count * 5;
1747 c[D_CBC_DES][0] = count;
1748 c[D_EDE3_DES][0] = count / 3;
1749 c[D_CBC_IDEA][0] = count;
1750 c[D_CBC_SEED][0] = count;
1751 c[D_CBC_RC2][0] = count;
1752 c[D_CBC_RC5][0] = count;
1753 c[D_CBC_BF][0] = count;
1754 c[D_CBC_CAST][0] = count;
1755 c[D_CBC_128_AES][0] = count;
1756 c[D_CBC_192_AES][0] = count;
1757 c[D_CBC_256_AES][0] = count;
1758 c[D_CBC_128_CML][0] = count;
1759 c[D_CBC_192_CML][0] = count;
1760 c[D_CBC_256_CML][0] = count;
1761 c[D_SHA256][0] = count;
1762 c[D_SHA512][0] = count;
1763 c[D_WHIRLPOOL][0] = count;
1764 c[D_IGE_128_AES][0] = count;
1765 c[D_IGE_192_AES][0] = count;
1766 c[D_IGE_256_AES][0] = count;
1767 c[D_GHASH][0] = count;
1768 c[D_RAND][0] = count;
1770 for (i = 1; i < size_num; i++) {
1773 l0 = (long)lengths[0];
1774 l1 = (long)lengths[i];
1776 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1777 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1778 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1779 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1780 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1781 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1782 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1783 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1784 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1785 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1786 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1787 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
1789 l0 = (long)lengths[i - 1];
1791 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1792 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1793 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1794 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1795 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1796 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1797 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1798 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1799 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1800 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1801 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1802 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1803 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1804 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1805 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1806 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1807 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1808 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1811 # ifndef OPENSSL_NO_RSA
1812 rsa_c[R_RSA_512][0] = count / 2000;
1813 rsa_c[R_RSA_512][1] = count / 400;
1814 for (i = 1; i < RSA_NUM; i++) {
1815 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1816 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1817 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1820 if (rsa_c[i][0] == 0) {
1821 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1828 # ifndef OPENSSL_NO_DSA
1829 dsa_c[R_DSA_512][0] = count / 1000;
1830 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1831 for (i = 1; i < DSA_NUM; i++) {
1832 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1833 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1834 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1837 if (dsa_c[i][0] == 0) {
1838 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1845 # ifndef OPENSSL_NO_EC
1846 ecdsa_c[R_EC_P160][0] = count / 1000;
1847 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1848 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1849 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1850 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1851 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1854 if (ecdsa_c[i][0] == 0) {
1860 ecdsa_c[R_EC_K163][0] = count / 1000;
1861 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1862 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1863 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1864 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1865 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1868 if (ecdsa_c[i][0] == 0) {
1874 ecdsa_c[R_EC_B163][0] = count / 1000;
1875 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1876 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1877 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1878 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1879 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1882 if (ecdsa_c[i][0] == 0) {
1889 ecdh_c[R_EC_P160][0] = count / 1000;
1890 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1891 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1892 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1895 if (ecdh_c[i][0] == 0) {
1900 ecdh_c[R_EC_K163][0] = count / 1000;
1901 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1902 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1903 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1906 if (ecdh_c[i][0] == 0) {
1911 ecdh_c[R_EC_B163][0] = count / 1000;
1912 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1913 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1914 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1917 if (ecdh_c[i][0] == 0) {
1925 /* not worth fixing */
1926 # error "You cannot disable DES on systems without SIGALRM."
1927 # endif /* OPENSSL_NO_DES */
1930 signal(SIGALRM, sig_done);
1932 #endif /* SIGALRM */
1934 #ifndef OPENSSL_NO_MD2
1936 for (testnum = 0; testnum < size_num; testnum++) {
1937 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
1940 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1942 print_result(D_MD2, testnum, count, d);
1946 #ifndef OPENSSL_NO_MDC2
1948 for (testnum = 0; testnum < size_num; testnum++) {
1949 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
1952 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1954 print_result(D_MDC2, testnum, count, d);
1959 #ifndef OPENSSL_NO_MD4
1961 for (testnum = 0; testnum < size_num; testnum++) {
1962 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
1965 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1967 print_result(D_MD4, testnum, count, d);
1972 #ifndef OPENSSL_NO_MD5
1974 for (testnum = 0; testnum < size_num; testnum++) {
1975 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
1978 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1980 print_result(D_MD5, testnum, count, d);
1985 static const char hmac_key[] = "This is a key...";
1986 int len = strlen(hmac_key);
1988 for (i = 0; i < loopargs_len; i++) {
1989 loopargs[i].hctx = HMAC_CTX_new();
1990 if (loopargs[i].hctx == NULL) {
1991 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1995 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1997 for (testnum = 0; testnum < size_num; testnum++) {
1998 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
2001 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
2003 print_result(D_HMAC, testnum, count, d);
2005 for (i = 0; i < loopargs_len; i++) {
2006 HMAC_CTX_free(loopargs[i].hctx);
2011 for (testnum = 0; testnum < size_num; testnum++) {
2012 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
2015 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
2017 print_result(D_SHA1, testnum, count, d);
2020 if (doit[D_SHA256]) {
2021 for (testnum = 0; testnum < size_num; testnum++) {
2022 print_message(names[D_SHA256], c[D_SHA256][testnum],
2023 lengths[testnum], seconds.sym);
2025 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
2027 print_result(D_SHA256, testnum, count, d);
2030 if (doit[D_SHA512]) {
2031 for (testnum = 0; testnum < size_num; testnum++) {
2032 print_message(names[D_SHA512], c[D_SHA512][testnum],
2033 lengths[testnum], seconds.sym);
2035 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
2037 print_result(D_SHA512, testnum, count, d);
2040 #ifndef OPENSSL_NO_WHIRLPOOL
2041 if (doit[D_WHIRLPOOL]) {
2042 for (testnum = 0; testnum < size_num; testnum++) {
2043 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
2044 lengths[testnum], seconds.sym);
2046 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2048 print_result(D_WHIRLPOOL, testnum, count, d);
2053 #ifndef OPENSSL_NO_RMD160
2054 if (doit[D_RMD160]) {
2055 for (testnum = 0; testnum < size_num; testnum++) {
2056 print_message(names[D_RMD160], c[D_RMD160][testnum],
2057 lengths[testnum], seconds.sym);
2059 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2061 print_result(D_RMD160, testnum, count, d);
2065 #ifndef OPENSSL_NO_RC4
2067 for (testnum = 0; testnum < size_num; testnum++) {
2068 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
2071 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2073 print_result(D_RC4, testnum, count, d);
2077 #ifndef OPENSSL_NO_DES
2078 if (doit[D_CBC_DES]) {
2079 for (testnum = 0; testnum < size_num; testnum++) {
2080 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2081 lengths[testnum], seconds.sym);
2083 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2085 print_result(D_CBC_DES, testnum, count, d);
2089 if (doit[D_EDE3_DES]) {
2090 for (testnum = 0; testnum < size_num; testnum++) {
2091 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2092 lengths[testnum], seconds.sym);
2095 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2097 print_result(D_EDE3_DES, testnum, count, d);
2102 if (doit[D_CBC_128_AES]) {
2103 for (testnum = 0; testnum < size_num; testnum++) {
2104 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2105 lengths[testnum], seconds.sym);
2108 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2110 print_result(D_CBC_128_AES, testnum, count, d);
2113 if (doit[D_CBC_192_AES]) {
2114 for (testnum = 0; testnum < size_num; testnum++) {
2115 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2116 lengths[testnum], seconds.sym);
2119 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2121 print_result(D_CBC_192_AES, testnum, count, d);
2124 if (doit[D_CBC_256_AES]) {
2125 for (testnum = 0; testnum < size_num; testnum++) {
2126 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2127 lengths[testnum], seconds.sym);
2130 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2132 print_result(D_CBC_256_AES, testnum, count, d);
2136 if (doit[D_IGE_128_AES]) {
2137 for (testnum = 0; testnum < size_num; testnum++) {
2138 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2139 lengths[testnum], seconds.sym);
2142 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2144 print_result(D_IGE_128_AES, testnum, count, d);
2147 if (doit[D_IGE_192_AES]) {
2148 for (testnum = 0; testnum < size_num; testnum++) {
2149 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2150 lengths[testnum], seconds.sym);
2153 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2155 print_result(D_IGE_192_AES, testnum, count, d);
2158 if (doit[D_IGE_256_AES]) {
2159 for (testnum = 0; testnum < size_num; testnum++) {
2160 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2161 lengths[testnum], seconds.sym);
2164 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2166 print_result(D_IGE_256_AES, testnum, count, d);
2169 if (doit[D_GHASH]) {
2170 for (i = 0; i < loopargs_len; i++) {
2171 loopargs[i].gcm_ctx =
2172 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2173 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2174 (unsigned char *)"0123456789ab", 12);
2177 for (testnum = 0; testnum < size_num; testnum++) {
2178 print_message(names[D_GHASH], c[D_GHASH][testnum],
2179 lengths[testnum], seconds.sym);
2181 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2183 print_result(D_GHASH, testnum, count, d);
2185 for (i = 0; i < loopargs_len; i++)
2186 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2188 #ifndef OPENSSL_NO_CAMELLIA
2189 if (doit[D_CBC_128_CML]) {
2190 if (async_jobs > 0) {
2191 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2192 names[D_CBC_128_CML]);
2193 doit[D_CBC_128_CML] = 0;
2195 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2196 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2197 lengths[testnum], seconds.sym);
2199 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2200 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2201 (size_t)lengths[testnum], &camellia_ks1,
2202 iv, CAMELLIA_ENCRYPT);
2204 print_result(D_CBC_128_CML, testnum, count, d);
2207 if (doit[D_CBC_192_CML]) {
2208 if (async_jobs > 0) {
2209 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2210 names[D_CBC_192_CML]);
2211 doit[D_CBC_192_CML] = 0;
2213 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2214 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2215 lengths[testnum], seconds.sym);
2216 if (async_jobs > 0) {
2217 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2221 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2222 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2223 (size_t)lengths[testnum], &camellia_ks2,
2224 iv, CAMELLIA_ENCRYPT);
2226 print_result(D_CBC_192_CML, testnum, count, d);
2229 if (doit[D_CBC_256_CML]) {
2230 if (async_jobs > 0) {
2231 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2232 names[D_CBC_256_CML]);
2233 doit[D_CBC_256_CML] = 0;
2235 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2236 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2237 lengths[testnum], seconds.sym);
2239 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2240 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2241 (size_t)lengths[testnum], &camellia_ks3,
2242 iv, CAMELLIA_ENCRYPT);
2244 print_result(D_CBC_256_CML, testnum, count, d);
2248 #ifndef OPENSSL_NO_IDEA
2249 if (doit[D_CBC_IDEA]) {
2250 if (async_jobs > 0) {
2251 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2253 doit[D_CBC_IDEA] = 0;
2255 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2256 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2257 lengths[testnum], seconds.sym);
2259 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2260 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2261 (size_t)lengths[testnum], &idea_ks,
2264 print_result(D_CBC_IDEA, testnum, count, d);
2268 #ifndef OPENSSL_NO_SEED
2269 if (doit[D_CBC_SEED]) {
2270 if (async_jobs > 0) {
2271 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2273 doit[D_CBC_SEED] = 0;
2275 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2276 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2277 lengths[testnum], seconds.sym);
2279 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2280 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2281 (size_t)lengths[testnum], &seed_ks, iv, 1);
2283 print_result(D_CBC_SEED, testnum, count, d);
2287 #ifndef OPENSSL_NO_RC2
2288 if (doit[D_CBC_RC2]) {
2289 if (async_jobs > 0) {
2290 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2292 doit[D_CBC_RC2] = 0;
2294 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2295 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2296 lengths[testnum], seconds.sym);
2297 if (async_jobs > 0) {
2298 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2302 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2303 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2304 (size_t)lengths[testnum], &rc2_ks,
2307 print_result(D_CBC_RC2, testnum, count, d);
2311 #ifndef OPENSSL_NO_RC5
2312 if (doit[D_CBC_RC5]) {
2313 if (async_jobs > 0) {
2314 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2316 doit[D_CBC_RC5] = 0;
2318 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2319 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2320 lengths[testnum], seconds.sym);
2321 if (async_jobs > 0) {
2322 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2326 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2327 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2328 (size_t)lengths[testnum], &rc5_ks,
2331 print_result(D_CBC_RC5, testnum, count, d);
2335 #ifndef OPENSSL_NO_BF
2336 if (doit[D_CBC_BF]) {
2337 if (async_jobs > 0) {
2338 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2342 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2343 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2344 lengths[testnum], seconds.sym);
2346 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2347 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2348 (size_t)lengths[testnum], &bf_ks,
2351 print_result(D_CBC_BF, testnum, count, d);
2355 #ifndef OPENSSL_NO_CAST
2356 if (doit[D_CBC_CAST]) {
2357 if (async_jobs > 0) {
2358 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2360 doit[D_CBC_CAST] = 0;
2362 for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
2363 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2364 lengths[testnum], seconds.sym);
2366 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2367 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2368 (size_t)lengths[testnum], &cast_ks,
2371 print_result(D_CBC_CAST, testnum, count, d);
2376 for (testnum = 0; testnum < size_num; testnum++) {
2377 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
2380 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2382 print_result(D_RAND, testnum, count, d);
2387 if (multiblock && evp_cipher) {
2389 (EVP_CIPHER_flags(evp_cipher) &
2390 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2391 BIO_printf(bio_err, "%s is not multi-block capable\n",
2392 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2395 if (async_jobs > 0) {
2396 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2399 multiblock_speed(evp_cipher, &seconds);
2403 for (testnum = 0; testnum < size_num; testnum++) {
2406 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2408 * -O3 -fschedule-insns messes up an optimization here!
2409 * names[D_EVP] somehow becomes NULL
2411 print_message(names[D_EVP], save_count, lengths[testnum],
2414 for (k = 0; k < loopargs_len; k++) {
2415 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2416 EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
2417 iv, decrypt ? 0 : 1);
2419 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2421 keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
2422 loopargs[k].key = app_malloc(keylen, "evp_cipher key");
2423 EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
2424 EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
2425 loopargs[k].key, NULL, -1);
2426 OPENSSL_clear_free(loopargs[k].key, keylen);
2428 switch (EVP_CIPHER_mode(evp_cipher)) {
2429 case EVP_CIPH_CCM_MODE:
2430 loopfunc = EVP_Update_loop_ccm;
2433 loopfunc = EVP_Update_loop;
2437 count = run_benchmark(async_jobs, loopfunc, loopargs);
2439 for (k = 0; k < loopargs_len; k++) {
2440 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2444 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2445 print_message(names[D_EVP], save_count, lengths[testnum],
2448 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2451 print_result(D_EVP, testnum, count, d);
2455 for (i = 0; i < loopargs_len; i++)
2456 RAND_bytes(loopargs[i].buf, 36);
2458 #ifndef OPENSSL_NO_RSA
2459 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2461 if (!rsa_doit[testnum])
2463 for (i = 0; i < loopargs_len; i++) {
2465 /* we haven't set keys yet, generate multi-prime RSA keys */
2466 BIGNUM *bn = BN_new();
2470 if (!BN_set_word(bn, RSA_F4)) {
2475 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2476 rsa_choices[testnum].name);
2478 loopargs[i].rsa_key[testnum] = RSA_new();
2479 if (loopargs[i].rsa_key[testnum] == NULL) {
2484 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2486 primes, bn, NULL)) {
2492 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2493 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2499 "RSA sign failure. No RSA sign will be done.\n");
2500 ERR_print_errors(bio_err);
2503 pkey_print_message("private", "rsa",
2504 rsa_c[testnum][0], rsa_bits[testnum],
2506 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2508 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2511 mr ? "+R1:%ld:%d:%.2f\n"
2512 : "%ld %d bit private RSA's in %.2fs\n",
2513 count, rsa_bits[testnum], d);
2514 rsa_results[testnum][0] = (double)count / d;
2518 for (i = 0; i < loopargs_len; i++) {
2519 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2520 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2526 "RSA verify failure. No RSA verify will be done.\n");
2527 ERR_print_errors(bio_err);
2528 rsa_doit[testnum] = 0;
2530 pkey_print_message("public", "rsa",
2531 rsa_c[testnum][1], rsa_bits[testnum],
2534 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2537 mr ? "+R2:%ld:%d:%.2f\n"
2538 : "%ld %d bit public RSA's in %.2fs\n",
2539 count, rsa_bits[testnum], d);
2540 rsa_results[testnum][1] = (double)count / d;
2543 if (rsa_count <= 1) {
2544 /* if longer than 10s, don't do any more */
2545 for (testnum++; testnum < RSA_NUM; testnum++)
2546 rsa_doit[testnum] = 0;
2549 #endif /* OPENSSL_NO_RSA */
2551 for (i = 0; i < loopargs_len; i++)
2552 RAND_bytes(loopargs[i].buf, 36);
2554 #ifndef OPENSSL_NO_DSA
2555 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2557 if (!dsa_doit[testnum])
2560 /* DSA_generate_key(dsa_key[testnum]); */
2561 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2562 for (i = 0; i < loopargs_len; i++) {
2563 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2564 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2570 "DSA sign failure. No DSA sign will be done.\n");
2571 ERR_print_errors(bio_err);
2574 pkey_print_message("sign", "dsa",
2575 dsa_c[testnum][0], dsa_bits[testnum],
2578 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2581 mr ? "+R3:%ld:%d:%.2f\n"
2582 : "%ld %d bit DSA signs in %.2fs\n",
2583 count, dsa_bits[testnum], d);
2584 dsa_results[testnum][0] = (double)count / d;
2588 for (i = 0; i < loopargs_len; i++) {
2589 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2590 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2596 "DSA verify failure. No DSA verify will be done.\n");
2597 ERR_print_errors(bio_err);
2598 dsa_doit[testnum] = 0;
2600 pkey_print_message("verify", "dsa",
2601 dsa_c[testnum][1], dsa_bits[testnum],
2604 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2607 mr ? "+R4:%ld:%d:%.2f\n"
2608 : "%ld %d bit DSA verify in %.2fs\n",
2609 count, dsa_bits[testnum], d);
2610 dsa_results[testnum][1] = (double)count / d;
2613 if (rsa_count <= 1) {
2614 /* if longer than 10s, don't do any more */
2615 for (testnum++; testnum < DSA_NUM; testnum++)
2616 dsa_doit[testnum] = 0;
2619 #endif /* OPENSSL_NO_DSA */
2621 #ifndef OPENSSL_NO_EC
2622 for (testnum = 0; testnum < EC_NUM; testnum++) {
2625 if (!ecdsa_doit[testnum])
2626 continue; /* Ignore Curve */
2627 for (i = 0; i < loopargs_len; i++) {
2628 loopargs[i].ecdsa[testnum] =
2629 EC_KEY_new_by_curve_name(test_curves[testnum]);
2630 if (loopargs[i].ecdsa[testnum] == NULL) {
2636 BIO_printf(bio_err, "ECDSA failure.\n");
2637 ERR_print_errors(bio_err);
2640 for (i = 0; i < loopargs_len; i++) {
2641 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2642 /* Perform ECDSA signature test */
2643 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2644 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2645 &loopargs[i].siglen,
2646 loopargs[i].ecdsa[testnum]);
2652 "ECDSA sign failure. No ECDSA sign will be done.\n");
2653 ERR_print_errors(bio_err);
2656 pkey_print_message("sign", "ecdsa",
2657 ecdsa_c[testnum][0],
2658 test_curves_bits[testnum],
2661 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2665 mr ? "+R5:%ld:%d:%.2f\n" :
2666 "%ld %d bit ECDSA signs in %.2fs \n",
2667 count, test_curves_bits[testnum], d);
2668 ecdsa_results[testnum][0] = (double)count / d;
2672 /* Perform ECDSA verification test */
2673 for (i = 0; i < loopargs_len; i++) {
2674 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2676 loopargs[i].ecdsa[testnum]);
2682 "ECDSA verify failure. No ECDSA verify will be done.\n");
2683 ERR_print_errors(bio_err);
2684 ecdsa_doit[testnum] = 0;
2686 pkey_print_message("verify", "ecdsa",
2687 ecdsa_c[testnum][1],
2688 test_curves_bits[testnum],
2691 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2694 mr ? "+R6:%ld:%d:%.2f\n"
2695 : "%ld %d bit ECDSA verify in %.2fs\n",
2696 count, test_curves_bits[testnum], d);
2697 ecdsa_results[testnum][1] = (double)count / d;
2700 if (rsa_count <= 1) {
2701 /* if longer than 10s, don't do any more */
2702 for (testnum++; testnum < EC_NUM; testnum++)
2703 ecdsa_doit[testnum] = 0;
2708 for (testnum = 0; testnum < EC_NUM; testnum++) {
2709 int ecdh_checks = 1;
2711 if (!ecdh_doit[testnum])
2714 for (i = 0; i < loopargs_len; i++) {
2715 EVP_PKEY_CTX *kctx = NULL;
2716 EVP_PKEY_CTX *test_ctx = NULL;
2717 EVP_PKEY_CTX *ctx = NULL;
2718 EVP_PKEY *key_A = NULL;
2719 EVP_PKEY *key_B = NULL;
2723 /* Ensure that the error queue is empty */
2724 if (ERR_peek_error()) {
2726 "WARNING: the error queue contains previous unhandled errors.\n");
2727 ERR_print_errors(bio_err);
2730 /* Let's try to create a ctx directly from the NID: this works for
2731 * curves like Curve25519 that are not implemented through the low
2732 * level EC interface.
2733 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2734 * then we set the curve by NID before deriving the actual keygen
2735 * ctx for that specific curve. */
2736 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2738 EVP_PKEY_CTX *pctx = NULL;
2739 EVP_PKEY *params = NULL;
2741 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2742 * "int_ctx_new:unsupported algorithm" error was added to the
2744 * We remove it from the error queue as we are handling it. */
2745 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2746 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2747 /* check that the error origin matches */
2748 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2749 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2750 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2751 ERR_get_error(); /* pop error from queue */
2752 if (ERR_peek_error()) {
2754 "Unhandled error in the error queue during ECDH init.\n");
2755 ERR_print_errors(bio_err);
2760 if ( /* Create the context for parameter generation */
2761 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2762 /* Initialise the parameter generation */
2763 !EVP_PKEY_paramgen_init(pctx) ||
2764 /* Set the curve by NID */
2765 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2768 /* Create the parameter object params */
2769 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2771 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2772 ERR_print_errors(bio_err);
2776 /* Create the context for the key generation */
2777 kctx = EVP_PKEY_CTX_new(params, NULL);
2779 EVP_PKEY_free(params);
2781 EVP_PKEY_CTX_free(pctx);
2784 if (kctx == NULL || /* keygen ctx is not null */
2785 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2787 BIO_printf(bio_err, "ECDH keygen failure.\n");
2788 ERR_print_errors(bio_err);
2793 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2794 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2795 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2796 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2797 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2798 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2799 outlen == 0 || /* ensure outlen is a valid size */
2800 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2802 BIO_printf(bio_err, "ECDH key generation failure.\n");
2803 ERR_print_errors(bio_err);
2808 /* Here we perform a test run, comparing the output of a*B and b*A;
2809 * we try this here and assume that further EVP_PKEY_derive calls
2810 * never fail, so we can skip checks in the actually benchmarked
2811 * code, for maximum performance. */
2812 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2813 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2814 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2815 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2816 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2817 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2818 test_outlen != outlen /* compare output length */ ) {
2820 BIO_printf(bio_err, "ECDH computation failure.\n");
2821 ERR_print_errors(bio_err);
2826 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2827 if (CRYPTO_memcmp(loopargs[i].secret_a,
2828 loopargs[i].secret_b, outlen)) {
2830 BIO_printf(bio_err, "ECDH computations don't match.\n");
2831 ERR_print_errors(bio_err);
2836 loopargs[i].ecdh_ctx[testnum] = ctx;
2837 loopargs[i].outlen[testnum] = outlen;
2839 EVP_PKEY_free(key_A);
2840 EVP_PKEY_free(key_B);
2841 EVP_PKEY_CTX_free(kctx);
2843 EVP_PKEY_CTX_free(test_ctx);
2846 if (ecdh_checks != 0) {
2847 pkey_print_message("", "ecdh",
2849 test_curves_bits[testnum],
2853 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2856 mr ? "+R7:%ld:%d:%.2f\n" :
2857 "%ld %d-bit ECDH ops in %.2fs\n", count,
2858 test_curves_bits[testnum], d);
2859 ecdh_results[testnum][0] = (double)count / d;
2863 if (rsa_count <= 1) {
2864 /* if longer than 10s, don't do any more */
2865 for (testnum++; testnum < EC_NUM; testnum++)
2866 ecdh_doit[testnum] = 0;
2869 #endif /* OPENSSL_NO_EC */
2874 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2875 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2877 printf("%s ", BN_options());
2878 #ifndef OPENSSL_NO_MD2
2879 printf("%s ", MD2_options());
2881 #ifndef OPENSSL_NO_RC4
2882 printf("%s ", RC4_options());
2884 #ifndef OPENSSL_NO_DES
2885 printf("%s ", DES_options());
2887 printf("%s ", AES_options());
2888 #ifndef OPENSSL_NO_IDEA
2889 printf("%s ", IDEA_options());
2891 #ifndef OPENSSL_NO_BF
2892 printf("%s ", BF_options());
2894 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2902 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2905 for (testnum = 0; testnum < size_num; testnum++)
2906 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2910 for (k = 0; k < ALGOR_NUM; k++) {
2914 printf("+F:%d:%s", k, names[k]);
2916 printf("%-13s", names[k]);
2917 for (testnum = 0; testnum < size_num; testnum++) {
2918 if (results[k][testnum] > 10000 && !mr)
2919 printf(" %11.2fk", results[k][testnum] / 1e3);
2921 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2925 #ifndef OPENSSL_NO_RSA
2927 for (k = 0; k < RSA_NUM; k++) {
2930 if (testnum && !mr) {
2931 printf("%18ssign verify sign/s verify/s\n", " ");
2935 printf("+F2:%u:%u:%f:%f\n",
2936 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2938 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2939 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2940 rsa_results[k][0], rsa_results[k][1]);
2943 #ifndef OPENSSL_NO_DSA
2945 for (k = 0; k < DSA_NUM; k++) {
2948 if (testnum && !mr) {
2949 printf("%18ssign verify sign/s verify/s\n", " ");
2953 printf("+F3:%u:%u:%f:%f\n",
2954 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2956 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2957 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2958 dsa_results[k][0], dsa_results[k][1]);
2961 #ifndef OPENSSL_NO_EC
2963 for (k = 0; k < EC_NUM; k++) {
2966 if (testnum && !mr) {
2967 printf("%30ssign verify sign/s verify/s\n", " ");
2972 printf("+F4:%u:%u:%f:%f\n",
2973 k, test_curves_bits[k],
2974 ecdsa_results[k][0], ecdsa_results[k][1]);
2976 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2977 test_curves_bits[k],
2978 test_curves_names[k],
2979 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2980 ecdsa_results[k][0], ecdsa_results[k][1]);
2984 for (k = 0; k < EC_NUM; k++) {
2987 if (testnum && !mr) {
2988 printf("%30sop op/s\n", " ");
2992 printf("+F5:%u:%u:%f:%f\n",
2993 k, test_curves_bits[k],
2994 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2997 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2998 test_curves_bits[k],
2999 test_curves_names[k],
3000 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
3007 ERR_print_errors(bio_err);
3008 for (i = 0; i < loopargs_len; i++) {
3009 OPENSSL_free(loopargs[i].buf_malloc);
3010 OPENSSL_free(loopargs[i].buf2_malloc);
3012 #ifndef OPENSSL_NO_RSA
3013 for (k = 0; k < RSA_NUM; k++)
3014 RSA_free(loopargs[i].rsa_key[k]);
3016 #ifndef OPENSSL_NO_DSA
3017 for (k = 0; k < DSA_NUM; k++)
3018 DSA_free(loopargs[i].dsa_key[k]);
3020 #ifndef OPENSSL_NO_EC
3021 for (k = 0; k < EC_NUM; k++) {
3022 EC_KEY_free(loopargs[i].ecdsa[k]);
3023 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
3025 OPENSSL_free(loopargs[i].secret_a);
3026 OPENSSL_free(loopargs[i].secret_b);
3030 if (async_jobs > 0) {
3031 for (i = 0; i < loopargs_len; i++)
3032 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
3036 ASYNC_cleanup_thread();
3038 OPENSSL_free(loopargs);
3043 static void print_message(const char *s, long num, int length, int tm)
3047 mr ? "+DT:%s:%d:%d\n"
3048 : "Doing %s for %ds on %d size blocks: ", s, tm, length);
3049 (void)BIO_flush(bio_err);
3053 mr ? "+DN:%s:%ld:%d\n"
3054 : "Doing %s %ld times on %d size blocks: ", s, num, length);
3055 (void)BIO_flush(bio_err);
3059 static void pkey_print_message(const char *str, const char *str2, long num,
3064 mr ? "+DTP:%d:%s:%s:%d\n"
3065 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
3066 (void)BIO_flush(bio_err);
3070 mr ? "+DNP:%ld:%d:%s:%s\n"
3071 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
3072 (void)BIO_flush(bio_err);
3076 static void print_result(int alg, int run_no, int count, double time_used)
3079 BIO_puts(bio_err, "EVP error!\n");
3083 mr ? "+R:%d:%s:%f\n"
3084 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3085 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3089 static char *sstrsep(char **string, const char *delim)
3092 char *token = *string;
3097 memset(isdelim, 0, sizeof(isdelim));
3101 isdelim[(unsigned char)(*delim)] = 1;
3105 while (!isdelim[(unsigned char)(**string)]) {
3117 static int do_multi(int multi, int size_num)
3122 static char sep[] = ":";
3124 fds = malloc(sizeof(*fds) * multi);
3125 for (n = 0; n < multi; ++n) {
3126 if (pipe(fd) == -1) {
3127 BIO_printf(bio_err, "pipe failure\n");
3131 (void)BIO_flush(bio_err);
3138 if (dup(fd[1]) == -1) {
3139 BIO_printf(bio_err, "dup failed\n");
3148 printf("Forked child %d\n", n);
3151 /* for now, assume the pipe is long enough to take all the output */
3152 for (n = 0; n < multi; ++n) {
3157 f = fdopen(fds[n], "r");
3158 while (fgets(buf, sizeof(buf), f)) {
3159 p = strchr(buf, '\n');
3162 if (buf[0] != '+') {
3164 "Don't understand line '%s' from child %d\n", buf,
3168 printf("Got: %s from %d\n", buf, n);
3169 if (strncmp(buf, "+F:", 3) == 0) {
3174 alg = atoi(sstrsep(&p, sep));
3176 for (j = 0; j < size_num; ++j)
3177 results[alg][j] += atof(sstrsep(&p, sep));
3178 } else if (strncmp(buf, "+F2:", 4) == 0) {
3183 k = atoi(sstrsep(&p, sep));
3186 d = atof(sstrsep(&p, sep));
3187 rsa_results[k][0] += d;
3189 d = atof(sstrsep(&p, sep));
3190 rsa_results[k][1] += d;
3192 # ifndef OPENSSL_NO_DSA
3193 else if (strncmp(buf, "+F3:", 4) == 0) {
3198 k = atoi(sstrsep(&p, sep));
3201 d = atof(sstrsep(&p, sep));
3202 dsa_results[k][0] += d;
3204 d = atof(sstrsep(&p, sep));
3205 dsa_results[k][1] += d;
3208 # ifndef OPENSSL_NO_EC
3209 else if (strncmp(buf, "+F4:", 4) == 0) {
3214 k = atoi(sstrsep(&p, sep));
3217 d = atof(sstrsep(&p, sep));
3218 ecdsa_results[k][0] += d;
3220 d = atof(sstrsep(&p, sep));
3221 ecdsa_results[k][1] += d;
3222 } else if (strncmp(buf, "+F5:", 4) == 0) {
3227 k = atoi(sstrsep(&p, sep));
3230 d = atof(sstrsep(&p, sep));
3231 ecdh_results[k][0] += d;
3235 else if (strncmp(buf, "+H:", 3) == 0) {
3238 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3249 static void multiblock_speed(const EVP_CIPHER *evp_cipher,
3250 const openssl_speed_sec_t *seconds)
3252 static const int mblengths_list[] =
3253 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3254 const int *mblengths = mblengths_list;
3255 int j, count, keylen, num = OSSL_NELEM(mblengths_list);
3256 const char *alg_name;
3257 unsigned char *inp, *out, *key, no_key[32], no_iv[16];
3258 EVP_CIPHER_CTX *ctx;
3261 if (lengths_single) {
3262 mblengths = &lengths_single;
3266 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3267 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3268 ctx = EVP_CIPHER_CTX_new();
3269 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
3271 keylen = EVP_CIPHER_CTX_key_length(ctx);
3272 key = app_malloc(keylen, "evp_cipher key");
3273 EVP_CIPHER_CTX_rand_key(ctx, key);
3274 EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
3275 OPENSSL_clear_free(key, keylen);
3277 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3278 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3280 for (j = 0; j < num; j++) {
3281 print_message(alg_name, 0, mblengths[j], seconds->sym);
3283 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3284 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3285 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3286 size_t len = mblengths[j];
3289 memset(aad, 0, 8); /* avoid uninitialized values */
3290 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3291 aad[9] = 3; /* version */
3293 aad[11] = 0; /* length */
3295 mb_param.out = NULL;
3298 mb_param.interleave = 8;
3300 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3301 sizeof(mb_param), &mb_param);
3307 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3308 sizeof(mb_param), &mb_param);
3312 RAND_bytes(out, 16);
3314 aad[11] = (unsigned char)(len >> 8);
3315 aad[12] = (unsigned char)(len);
3316 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3317 EVP_AEAD_TLS1_AAD_LEN, aad);
3318 EVP_Cipher(ctx, out, inp, len + pad);
3322 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3323 : "%d %s's in %.2fs\n", count, "evp", d);
3324 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3328 fprintf(stdout, "+H");
3329 for (j = 0; j < num; j++)
3330 fprintf(stdout, ":%d", mblengths[j]);
3331 fprintf(stdout, "\n");
3332 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3333 for (j = 0; j < num; j++)
3334 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3335 fprintf(stdout, "\n");
3338 "The 'numbers' are in 1000s of bytes per second processed.\n");
3339 fprintf(stdout, "type ");
3340 for (j = 0; j < num; j++)
3341 fprintf(stdout, "%7d bytes", mblengths[j]);
3342 fprintf(stdout, "\n");
3343 fprintf(stdout, "%-24s", alg_name);
3345 for (j = 0; j < num; j++) {
3346 if (results[D_EVP][j] > 10000)
3347 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3349 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3351 fprintf(stdout, "\n");
3356 EVP_CIPHER_CTX_free(ctx);