2 * Copyright 1995-2017 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)
115 #define BUFSIZE (1024*16+1)
116 #define MAX_MISALIGNMENT 63
124 #define MAX_ECDH_SIZE 256
127 static volatile int run = 0;
130 static int usertime = 1;
132 typedef struct loopargs_st {
133 ASYNC_JOB *inprogress_job;
134 ASYNC_WAIT_CTX *wait_ctx;
137 unsigned char *buf_malloc;
138 unsigned char *buf2_malloc;
140 #ifndef OPENSSL_NO_RSA
141 RSA *rsa_key[RSA_NUM];
143 #ifndef OPENSSL_NO_DSA
144 DSA *dsa_key[DSA_NUM];
146 #ifndef OPENSSL_NO_EC
147 EC_KEY *ecdsa[EC_NUM];
148 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
149 unsigned char *secret_a;
150 unsigned char *secret_b;
151 size_t outlen[EC_NUM];
155 GCM128_CONTEXT *gcm_ctx;
158 #ifndef OPENSSL_NO_MD2
159 static int EVP_Digest_MD2_loop(void *args);
162 #ifndef OPENSSL_NO_MDC2
163 static int EVP_Digest_MDC2_loop(void *args);
165 #ifndef OPENSSL_NO_MD4
166 static int EVP_Digest_MD4_loop(void *args);
168 #ifndef OPENSSL_NO_MD5
169 static int MD5_loop(void *args);
170 static int HMAC_loop(void *args);
172 static int SHA1_loop(void *args);
173 static int SHA256_loop(void *args);
174 static int SHA512_loop(void *args);
175 #ifndef OPENSSL_NO_WHIRLPOOL
176 static int WHIRLPOOL_loop(void *args);
178 #ifndef OPENSSL_NO_RMD160
179 static int EVP_Digest_RMD160_loop(void *args);
181 #ifndef OPENSSL_NO_RC4
182 static int RC4_loop(void *args);
184 #ifndef OPENSSL_NO_DES
185 static int DES_ncbc_encrypt_loop(void *args);
186 static int DES_ede3_cbc_encrypt_loop(void *args);
188 static int AES_cbc_128_encrypt_loop(void *args);
189 static int AES_cbc_192_encrypt_loop(void *args);
190 static int AES_ige_128_encrypt_loop(void *args);
191 static int AES_cbc_256_encrypt_loop(void *args);
192 static int AES_ige_192_encrypt_loop(void *args);
193 static int AES_ige_256_encrypt_loop(void *args);
194 static int CRYPTO_gcm128_aad_loop(void *args);
195 static int RAND_bytes_loop(void *args);
196 static int EVP_Update_loop(void *args);
197 static int EVP_Update_loop_ccm(void *args);
198 static int EVP_Digest_loop(void *args);
199 #ifndef OPENSSL_NO_RSA
200 static int RSA_sign_loop(void *args);
201 static int RSA_verify_loop(void *args);
203 #ifndef OPENSSL_NO_DSA
204 static int DSA_sign_loop(void *args);
205 static int DSA_verify_loop(void *args);
207 #ifndef OPENSSL_NO_EC
208 static int ECDSA_sign_loop(void *args);
209 static int ECDSA_verify_loop(void *args);
211 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
212 loopargs_t * loopargs);
214 static double Time_F(int s);
215 static void print_message(const char *s, long num, int length);
216 static void pkey_print_message(const char *str, const char *str2,
217 long num, int bits, int sec);
218 static void print_result(int alg, int run_no, int count, double time_used);
220 static int do_multi(int multi);
223 static const char *names[ALGOR_NUM] = {
224 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
225 "des cbc", "des ede3", "idea cbc", "seed cbc",
226 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
227 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
228 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
229 "evp", "sha256", "sha512", "whirlpool",
230 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
234 static double results[ALGOR_NUM][SIZE_NUM];
236 static const int lengths[SIZE_NUM] = {
237 16, 64, 256, 1024, 8 * 1024, 16 * 1024
240 #ifndef OPENSSL_NO_RSA
241 static double rsa_results[RSA_NUM][2];
243 #ifndef OPENSSL_NO_DSA
244 static double dsa_results[DSA_NUM][2];
246 #ifndef OPENSSL_NO_EC
247 static double ecdsa_results[EC_NUM][2];
248 static double ecdh_results[EC_NUM][1];
252 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
253 # define SIGRETTYPE void
255 # define SIGRETTYPE int
258 static SIGRETTYPE sig_done(int sig);
259 static SIGRETTYPE sig_done(int sig)
261 signal(SIGALRM, sig_done);
271 # if !defined(SIGALRM)
274 static unsigned int lapse;
275 static volatile unsigned int schlock;
276 static void alarm_win32(unsigned int secs)
281 # define alarm alarm_win32
283 static DWORD WINAPI sleepy(VOID * arg)
291 static double Time_F(int s)
298 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
300 DWORD err = GetLastError();
301 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
305 Sleep(0); /* scheduler spinlock */
306 ret = app_tminterval(s, usertime);
308 ret = app_tminterval(s, usertime);
310 TerminateThread(thr, 0);
318 static double Time_F(int s)
320 double ret = app_tminterval(s, usertime);
327 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
329 static int found(const char *name, const OPT_PAIR *pairs, int *result)
331 for (; pairs->name; pairs++)
332 if (strcmp(name, pairs->name) == 0) {
333 *result = pairs->retval;
339 typedef enum OPTION_choice {
340 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
341 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
342 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM
345 const OPTIONS speed_options[] = {
346 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
347 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
348 {"help", OPT_HELP, '-', "Display this summary"},
349 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
350 {"decrypt", OPT_DECRYPT, '-',
351 "Time decryption instead of encryption (only EVP)"},
352 {"mr", OPT_MR, '-', "Produce machine readable output"},
354 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
355 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
356 {"elapsed", OPT_ELAPSED, '-',
357 "Measure time in real time instead of CPU user time"},
359 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
361 #ifndef OPENSSL_NO_ASYNC
362 {"async_jobs", OPT_ASYNCJOBS, 'p',
363 "Enable async mode and start pnum jobs"},
366 #ifndef OPENSSL_NO_ENGINE
367 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
382 #define D_CBC_IDEA 10
383 #define D_CBC_SEED 11
387 #define D_CBC_CAST 15
388 #define D_CBC_128_AES 16
389 #define D_CBC_192_AES 17
390 #define D_CBC_256_AES 18
391 #define D_CBC_128_CML 19
392 #define D_CBC_192_CML 20
393 #define D_CBC_256_CML 21
397 #define D_WHIRLPOOL 25
398 #define D_IGE_128_AES 26
399 #define D_IGE_192_AES 27
400 #define D_IGE_256_AES 28
403 static OPT_PAIR doit_choices[] = {
404 #ifndef OPENSSL_NO_MD2
407 #ifndef OPENSSL_NO_MDC2
410 #ifndef OPENSSL_NO_MD4
413 #ifndef OPENSSL_NO_MD5
418 {"sha256", D_SHA256},
419 {"sha512", D_SHA512},
420 #ifndef OPENSSL_NO_WHIRLPOOL
421 {"whirlpool", D_WHIRLPOOL},
423 #ifndef OPENSSL_NO_RMD160
424 {"ripemd", D_RMD160},
425 {"rmd160", D_RMD160},
426 {"ripemd160", D_RMD160},
428 #ifndef OPENSSL_NO_RC4
431 #ifndef OPENSSL_NO_DES
432 {"des-cbc", D_CBC_DES},
433 {"des-ede3", D_EDE3_DES},
435 {"aes-128-cbc", D_CBC_128_AES},
436 {"aes-192-cbc", D_CBC_192_AES},
437 {"aes-256-cbc", D_CBC_256_AES},
438 {"aes-128-ige", D_IGE_128_AES},
439 {"aes-192-ige", D_IGE_192_AES},
440 {"aes-256-ige", D_IGE_256_AES},
441 #ifndef OPENSSL_NO_RC2
442 {"rc2-cbc", D_CBC_RC2},
445 #ifndef OPENSSL_NO_RC5
446 {"rc5-cbc", D_CBC_RC5},
449 #ifndef OPENSSL_NO_IDEA
450 {"idea-cbc", D_CBC_IDEA},
451 {"idea", D_CBC_IDEA},
453 #ifndef OPENSSL_NO_SEED
454 {"seed-cbc", D_CBC_SEED},
455 {"seed", D_CBC_SEED},
457 #ifndef OPENSSL_NO_BF
458 {"bf-cbc", D_CBC_BF},
459 {"blowfish", D_CBC_BF},
462 #ifndef OPENSSL_NO_CAST
463 {"cast-cbc", D_CBC_CAST},
464 {"cast", D_CBC_CAST},
465 {"cast5", D_CBC_CAST},
472 #ifndef OPENSSL_NO_DSA
474 # define R_DSA_1024 1
475 # define R_DSA_2048 2
476 static OPT_PAIR dsa_choices[] = {
477 {"dsa512", R_DSA_512},
478 {"dsa1024", R_DSA_1024},
479 {"dsa2048", R_DSA_2048},
490 #define R_RSA_15360 6
491 static OPT_PAIR rsa_choices[] = {
492 {"rsa512", R_RSA_512},
493 {"rsa1024", R_RSA_1024},
494 {"rsa2048", R_RSA_2048},
495 {"rsa3072", R_RSA_3072},
496 {"rsa4096", R_RSA_4096},
497 {"rsa7680", R_RSA_7680},
498 {"rsa15360", R_RSA_15360},
518 #define R_EC_X25519 16
519 #ifndef OPENSSL_NO_EC
520 static OPT_PAIR ecdsa_choices[] = {
521 {"ecdsap160", R_EC_P160},
522 {"ecdsap192", R_EC_P192},
523 {"ecdsap224", R_EC_P224},
524 {"ecdsap256", R_EC_P256},
525 {"ecdsap384", R_EC_P384},
526 {"ecdsap521", R_EC_P521},
527 {"ecdsak163", R_EC_K163},
528 {"ecdsak233", R_EC_K233},
529 {"ecdsak283", R_EC_K283},
530 {"ecdsak409", R_EC_K409},
531 {"ecdsak571", R_EC_K571},
532 {"ecdsab163", R_EC_B163},
533 {"ecdsab233", R_EC_B233},
534 {"ecdsab283", R_EC_B283},
535 {"ecdsab409", R_EC_B409},
536 {"ecdsab571", R_EC_B571},
540 static OPT_PAIR ecdh_choices[] = {
541 {"ecdhp160", R_EC_P160},
542 {"ecdhp192", R_EC_P192},
543 {"ecdhp224", R_EC_P224},
544 {"ecdhp256", R_EC_P256},
545 {"ecdhp384", R_EC_P384},
546 {"ecdhp521", R_EC_P521},
547 {"ecdhk163", R_EC_K163},
548 {"ecdhk233", R_EC_K233},
549 {"ecdhk283", R_EC_K283},
550 {"ecdhk409", R_EC_K409},
551 {"ecdhk571", R_EC_K571},
552 {"ecdhb163", R_EC_B163},
553 {"ecdhb233", R_EC_B233},
554 {"ecdhb283", R_EC_B283},
555 {"ecdhb409", R_EC_B409},
556 {"ecdhb571", R_EC_B571},
557 {"ecdhx25519", R_EC_X25519},
563 # define COND(d) (count < (d))
564 # define COUNT(d) (d)
566 # define COND(unused_cond) (run && count<0x7fffffff)
567 # define COUNT(d) (count)
572 /* Nb of iterations to do per algorithm and key-size */
573 static long c[ALGOR_NUM][SIZE_NUM];
575 #ifndef OPENSSL_NO_MD2
576 static int EVP_Digest_MD2_loop(void *args)
578 loopargs_t *tempargs = *(loopargs_t **) args;
579 unsigned char *buf = tempargs->buf;
580 unsigned char md2[MD2_DIGEST_LENGTH];
583 for (count = 0; COND(c[D_MD2][testnum]); count++) {
584 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
592 #ifndef OPENSSL_NO_MDC2
593 static int EVP_Digest_MDC2_loop(void *args)
595 loopargs_t *tempargs = *(loopargs_t **) args;
596 unsigned char *buf = tempargs->buf;
597 unsigned char mdc2[MDC2_DIGEST_LENGTH];
600 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
601 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
609 #ifndef OPENSSL_NO_MD4
610 static int EVP_Digest_MD4_loop(void *args)
612 loopargs_t *tempargs = *(loopargs_t **) args;
613 unsigned char *buf = tempargs->buf;
614 unsigned char md4[MD4_DIGEST_LENGTH];
617 for (count = 0; COND(c[D_MD4][testnum]); count++) {
618 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
626 #ifndef OPENSSL_NO_MD5
627 static int MD5_loop(void *args)
629 loopargs_t *tempargs = *(loopargs_t **) args;
630 unsigned char *buf = tempargs->buf;
631 unsigned char md5[MD5_DIGEST_LENGTH];
633 for (count = 0; COND(c[D_MD5][testnum]); count++)
634 MD5(buf, lengths[testnum], md5);
638 static int HMAC_loop(void *args)
640 loopargs_t *tempargs = *(loopargs_t **) args;
641 unsigned char *buf = tempargs->buf;
642 HMAC_CTX *hctx = tempargs->hctx;
643 unsigned char hmac[MD5_DIGEST_LENGTH];
646 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
647 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
648 HMAC_Update(hctx, buf, lengths[testnum]);
649 HMAC_Final(hctx, hmac, NULL);
655 static int SHA1_loop(void *args)
657 loopargs_t *tempargs = *(loopargs_t **) args;
658 unsigned char *buf = tempargs->buf;
659 unsigned char sha[SHA_DIGEST_LENGTH];
661 for (count = 0; COND(c[D_SHA1][testnum]); count++)
662 SHA1(buf, lengths[testnum], sha);
666 static int SHA256_loop(void *args)
668 loopargs_t *tempargs = *(loopargs_t **) args;
669 unsigned char *buf = tempargs->buf;
670 unsigned char sha256[SHA256_DIGEST_LENGTH];
672 for (count = 0; COND(c[D_SHA256][testnum]); count++)
673 SHA256(buf, lengths[testnum], sha256);
677 static int SHA512_loop(void *args)
679 loopargs_t *tempargs = *(loopargs_t **) args;
680 unsigned char *buf = tempargs->buf;
681 unsigned char sha512[SHA512_DIGEST_LENGTH];
683 for (count = 0; COND(c[D_SHA512][testnum]); count++)
684 SHA512(buf, lengths[testnum], sha512);
688 #ifndef OPENSSL_NO_WHIRLPOOL
689 static int WHIRLPOOL_loop(void *args)
691 loopargs_t *tempargs = *(loopargs_t **) args;
692 unsigned char *buf = tempargs->buf;
693 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
695 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
696 WHIRLPOOL(buf, lengths[testnum], whirlpool);
701 #ifndef OPENSSL_NO_RMD160
702 static int EVP_Digest_RMD160_loop(void *args)
704 loopargs_t *tempargs = *(loopargs_t **) args;
705 unsigned char *buf = tempargs->buf;
706 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
708 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
709 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
710 NULL, EVP_ripemd160(), NULL))
717 #ifndef OPENSSL_NO_RC4
718 static RC4_KEY rc4_ks;
719 static int RC4_loop(void *args)
721 loopargs_t *tempargs = *(loopargs_t **) args;
722 unsigned char *buf = tempargs->buf;
724 for (count = 0; COND(c[D_RC4][testnum]); count++)
725 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
730 #ifndef OPENSSL_NO_DES
731 static unsigned char DES_iv[8];
732 static DES_key_schedule sch;
733 static DES_key_schedule sch2;
734 static DES_key_schedule sch3;
735 static int DES_ncbc_encrypt_loop(void *args)
737 loopargs_t *tempargs = *(loopargs_t **) args;
738 unsigned char *buf = tempargs->buf;
740 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
741 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
742 &DES_iv, DES_ENCRYPT);
746 static int DES_ede3_cbc_encrypt_loop(void *args)
748 loopargs_t *tempargs = *(loopargs_t **) args;
749 unsigned char *buf = tempargs->buf;
751 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
752 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
753 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
758 #define MAX_BLOCK_SIZE 128
760 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
761 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
762 static int AES_cbc_128_encrypt_loop(void *args)
764 loopargs_t *tempargs = *(loopargs_t **) args;
765 unsigned char *buf = tempargs->buf;
767 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
768 AES_cbc_encrypt(buf, buf,
769 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
773 static int AES_cbc_192_encrypt_loop(void *args)
775 loopargs_t *tempargs = *(loopargs_t **) args;
776 unsigned char *buf = tempargs->buf;
778 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
779 AES_cbc_encrypt(buf, buf,
780 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
784 static int AES_cbc_256_encrypt_loop(void *args)
786 loopargs_t *tempargs = *(loopargs_t **) args;
787 unsigned char *buf = tempargs->buf;
789 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
790 AES_cbc_encrypt(buf, buf,
791 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
795 static int AES_ige_128_encrypt_loop(void *args)
797 loopargs_t *tempargs = *(loopargs_t **) args;
798 unsigned char *buf = tempargs->buf;
799 unsigned char *buf2 = tempargs->buf2;
801 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
802 AES_ige_encrypt(buf, buf2,
803 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
807 static int AES_ige_192_encrypt_loop(void *args)
809 loopargs_t *tempargs = *(loopargs_t **) args;
810 unsigned char *buf = tempargs->buf;
811 unsigned char *buf2 = tempargs->buf2;
813 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
814 AES_ige_encrypt(buf, buf2,
815 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
819 static int AES_ige_256_encrypt_loop(void *args)
821 loopargs_t *tempargs = *(loopargs_t **) args;
822 unsigned char *buf = tempargs->buf;
823 unsigned char *buf2 = tempargs->buf2;
825 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
826 AES_ige_encrypt(buf, buf2,
827 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
831 static int CRYPTO_gcm128_aad_loop(void *args)
833 loopargs_t *tempargs = *(loopargs_t **) args;
834 unsigned char *buf = tempargs->buf;
835 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
837 for (count = 0; COND(c[D_GHASH][testnum]); count++)
838 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
842 static int RAND_bytes_loop(void *args)
844 loopargs_t *tempargs = *(loopargs_t **) args;
845 unsigned char *buf = tempargs->buf;
848 for (count = 0; COND(c[D_RAND][testnum]); count++)
849 RAND_bytes(buf, lengths[testnum]);
853 static long save_count = 0;
854 static int decrypt = 0;
855 static int EVP_Update_loop(void *args)
857 loopargs_t *tempargs = *(loopargs_t **) args;
858 unsigned char *buf = tempargs->buf;
859 EVP_CIPHER_CTX *ctx = tempargs->ctx;
862 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
865 for (count = 0; COND(nb_iter); count++)
866 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
868 for (count = 0; COND(nb_iter); count++)
869 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
871 EVP_DecryptFinal_ex(ctx, buf, &outl);
873 EVP_EncryptFinal_ex(ctx, buf, &outl);
877 * CCM does not support streaming. For the purpose of performance measurement,
878 * each message is encrypted using the same (key,iv)-pair. Do not use this
879 * code in your application.
881 static int EVP_Update_loop_ccm(void *args)
883 loopargs_t *tempargs = *(loopargs_t **) args;
884 unsigned char *buf = tempargs->buf;
885 EVP_CIPHER_CTX *ctx = tempargs->ctx;
887 unsigned char tag[12];
889 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
892 for (count = 0; COND(nb_iter); count++) {
893 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
894 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
895 EVP_DecryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
896 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
897 EVP_DecryptFinal_ex(ctx, buf, &outl);
900 for (count = 0; COND(nb_iter); count++) {
901 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
902 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
903 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
904 EVP_EncryptFinal_ex(ctx, buf, &outl);
910 static const EVP_MD *evp_md = NULL;
911 static int EVP_Digest_loop(void *args)
913 loopargs_t *tempargs = *(loopargs_t **) args;
914 unsigned char *buf = tempargs->buf;
915 unsigned char md[EVP_MAX_MD_SIZE];
918 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
921 for (count = 0; COND(nb_iter); count++) {
922 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
928 #ifndef OPENSSL_NO_RSA
929 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
931 static int RSA_sign_loop(void *args)
933 loopargs_t *tempargs = *(loopargs_t **) args;
934 unsigned char *buf = tempargs->buf;
935 unsigned char *buf2 = tempargs->buf2;
936 unsigned int *rsa_num = &tempargs->siglen;
937 RSA **rsa_key = tempargs->rsa_key;
939 for (count = 0; COND(rsa_c[testnum][0]); count++) {
940 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
942 BIO_printf(bio_err, "RSA sign failure\n");
943 ERR_print_errors(bio_err);
951 static int RSA_verify_loop(void *args)
953 loopargs_t *tempargs = *(loopargs_t **) args;
954 unsigned char *buf = tempargs->buf;
955 unsigned char *buf2 = tempargs->buf2;
956 unsigned int rsa_num = tempargs->siglen;
957 RSA **rsa_key = tempargs->rsa_key;
959 for (count = 0; COND(rsa_c[testnum][1]); count++) {
961 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
963 BIO_printf(bio_err, "RSA verify failure\n");
964 ERR_print_errors(bio_err);
973 #ifndef OPENSSL_NO_DSA
974 static long dsa_c[DSA_NUM][2];
975 static int DSA_sign_loop(void *args)
977 loopargs_t *tempargs = *(loopargs_t **) args;
978 unsigned char *buf = tempargs->buf;
979 unsigned char *buf2 = tempargs->buf2;
980 DSA **dsa_key = tempargs->dsa_key;
981 unsigned int *siglen = &tempargs->siglen;
983 for (count = 0; COND(dsa_c[testnum][0]); count++) {
984 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
986 BIO_printf(bio_err, "DSA sign failure\n");
987 ERR_print_errors(bio_err);
995 static int DSA_verify_loop(void *args)
997 loopargs_t *tempargs = *(loopargs_t **) args;
998 unsigned char *buf = tempargs->buf;
999 unsigned char *buf2 = tempargs->buf2;
1000 DSA **dsa_key = tempargs->dsa_key;
1001 unsigned int siglen = tempargs->siglen;
1003 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1004 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1006 BIO_printf(bio_err, "DSA verify failure\n");
1007 ERR_print_errors(bio_err);
1016 #ifndef OPENSSL_NO_EC
1017 static long ecdsa_c[EC_NUM][2];
1018 static int ECDSA_sign_loop(void *args)
1020 loopargs_t *tempargs = *(loopargs_t **) args;
1021 unsigned char *buf = tempargs->buf;
1022 EC_KEY **ecdsa = tempargs->ecdsa;
1023 unsigned char *ecdsasig = tempargs->buf2;
1024 unsigned int *ecdsasiglen = &tempargs->siglen;
1026 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1027 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1029 BIO_printf(bio_err, "ECDSA sign failure\n");
1030 ERR_print_errors(bio_err);
1038 static int ECDSA_verify_loop(void *args)
1040 loopargs_t *tempargs = *(loopargs_t **) args;
1041 unsigned char *buf = tempargs->buf;
1042 EC_KEY **ecdsa = tempargs->ecdsa;
1043 unsigned char *ecdsasig = tempargs->buf2;
1044 unsigned int ecdsasiglen = tempargs->siglen;
1046 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1047 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1049 BIO_printf(bio_err, "ECDSA verify failure\n");
1050 ERR_print_errors(bio_err);
1058 /* ******************************************************************** */
1059 static long ecdh_c[EC_NUM][1];
1061 static int ECDH_EVP_derive_key_loop(void *args)
1063 loopargs_t *tempargs = *(loopargs_t **) args;
1064 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1065 unsigned char *derived_secret = tempargs->secret_a;
1067 size_t *outlen = &(tempargs->outlen[testnum]);
1069 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1070 EVP_PKEY_derive(ctx, derived_secret, outlen);
1075 #endif /* OPENSSL_NO_EC */
1077 static int run_benchmark(int async_jobs,
1078 int (*loop_function) (void *), loopargs_t * loopargs)
1080 int job_op_count = 0;
1081 int total_op_count = 0;
1082 int num_inprogress = 0;
1083 int error = 0, i = 0, ret = 0;
1084 OSSL_ASYNC_FD job_fd = 0;
1085 size_t num_job_fds = 0;
1089 if (async_jobs == 0) {
1090 return loop_function((void *)&loopargs);
1093 for (i = 0; i < async_jobs && !error; i++) {
1094 loopargs_t *looparg_item = loopargs + i;
1096 /* Copy pointer content (looparg_t item address) into async context */
1097 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1098 &job_op_count, loop_function,
1099 (void *)&looparg_item, sizeof(looparg_item));
1105 if (job_op_count == -1) {
1108 total_op_count += job_op_count;
1113 BIO_printf(bio_err, "Failure in the job\n");
1114 ERR_print_errors(bio_err);
1120 while (num_inprogress > 0) {
1121 #if defined(OPENSSL_SYS_WINDOWS)
1123 #elif defined(OPENSSL_SYS_UNIX)
1124 int select_result = 0;
1125 OSSL_ASYNC_FD max_fd = 0;
1128 FD_ZERO(&waitfdset);
1130 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1131 if (loopargs[i].inprogress_job == NULL)
1134 if (!ASYNC_WAIT_CTX_get_all_fds
1135 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1136 || num_job_fds > 1) {
1137 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1138 ERR_print_errors(bio_err);
1142 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1144 FD_SET(job_fd, &waitfdset);
1145 if (job_fd > max_fd)
1149 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1151 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1152 "Decrease the value of async_jobs\n",
1153 max_fd, FD_SETSIZE);
1154 ERR_print_errors(bio_err);
1159 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1160 if (select_result == -1 && errno == EINTR)
1163 if (select_result == -1) {
1164 BIO_printf(bio_err, "Failure in the select\n");
1165 ERR_print_errors(bio_err);
1170 if (select_result == 0)
1174 for (i = 0; i < async_jobs; i++) {
1175 if (loopargs[i].inprogress_job == NULL)
1178 if (!ASYNC_WAIT_CTX_get_all_fds
1179 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1180 || num_job_fds > 1) {
1181 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1182 ERR_print_errors(bio_err);
1186 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1189 #if defined(OPENSSL_SYS_UNIX)
1190 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1192 #elif defined(OPENSSL_SYS_WINDOWS)
1193 if (num_job_fds == 1
1194 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1199 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1200 loopargs[i].wait_ctx, &job_op_count,
1201 loop_function, (void *)(loopargs + i),
1202 sizeof(loopargs_t));
1207 if (job_op_count == -1) {
1210 total_op_count += job_op_count;
1213 loopargs[i].inprogress_job = NULL;
1218 loopargs[i].inprogress_job = NULL;
1219 BIO_printf(bio_err, "Failure in the job\n");
1220 ERR_print_errors(bio_err);
1227 return error ? -1 : total_op_count;
1230 int speed_main(int argc, char **argv)
1233 int (*loopfunc)(void *args);
1234 loopargs_t *loopargs = NULL;
1236 int loopargs_len = 0;
1238 const char *engine_id = NULL;
1239 const EVP_CIPHER *evp_cipher = NULL;
1242 int multiblock = 0, pr_header = 0;
1243 int doit[ALGOR_NUM] = { 0 };
1244 int ret = 1, i, k, misalign = 0;
1249 unsigned int async_jobs = 0;
1250 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1251 || !defined(OPENSSL_NO_EC)
1255 /* What follows are the buffers and key material. */
1256 #ifndef OPENSSL_NO_RC5
1259 #ifndef OPENSSL_NO_RC2
1262 #ifndef OPENSSL_NO_IDEA
1263 IDEA_KEY_SCHEDULE idea_ks;
1265 #ifndef OPENSSL_NO_SEED
1266 SEED_KEY_SCHEDULE seed_ks;
1268 #ifndef OPENSSL_NO_BF
1271 #ifndef OPENSSL_NO_CAST
1274 static const unsigned char key16[16] = {
1275 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1276 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1278 static const unsigned char key24[24] = {
1279 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1280 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1281 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1283 static const unsigned char key32[32] = {
1284 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1285 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1286 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1287 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1289 #ifndef OPENSSL_NO_CAMELLIA
1290 static const unsigned char ckey24[24] = {
1291 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1292 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1293 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1295 static const unsigned char ckey32[32] = {
1296 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1297 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1298 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1299 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1301 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1303 #ifndef OPENSSL_NO_DES
1304 static DES_cblock key = {
1305 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1307 static DES_cblock key2 = {
1308 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1310 static DES_cblock key3 = {
1311 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1314 #ifndef OPENSSL_NO_RSA
1315 static const unsigned int rsa_bits[RSA_NUM] = {
1316 512, 1024, 2048, 3072, 4096, 7680, 15360
1318 static const unsigned char *rsa_data[RSA_NUM] = {
1319 test512, test1024, test2048, test3072, test4096, test7680, test15360
1321 static const int rsa_data_length[RSA_NUM] = {
1322 sizeof(test512), sizeof(test1024),
1323 sizeof(test2048), sizeof(test3072),
1324 sizeof(test4096), sizeof(test7680),
1327 int rsa_doit[RSA_NUM] = { 0 };
1329 #ifndef OPENSSL_NO_DSA
1330 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1331 int dsa_doit[DSA_NUM] = { 0 };
1333 #ifndef OPENSSL_NO_EC
1335 * We only test over the following curves as they are representative, To
1336 * add tests over more curves, simply add the curve NID and curve name to
1337 * the following arrays and increase the EC_NUM value accordingly.
1339 static const unsigned int test_curves[EC_NUM] = {
1341 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1342 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1344 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1345 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1346 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1351 static const char *test_curves_names[EC_NUM] = {
1353 "secp160r1", "nistp192", "nistp224",
1354 "nistp256", "nistp384", "nistp521",
1356 "nistk163", "nistk233", "nistk283",
1357 "nistk409", "nistk571", "nistb163",
1358 "nistb233", "nistb283", "nistb409",
1363 static const int test_curves_bits[EC_NUM] = {
1369 571, 253 /* X25519 */
1372 int ecdsa_doit[EC_NUM] = { 0 };
1373 int ecdh_doit[EC_NUM] = { 0 };
1374 #endif /* ndef OPENSSL_NO_EC */
1376 prog = opt_init(argc, argv, speed_options);
1377 while ((o = opt_next()) != OPT_EOF) {
1382 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1385 opt_help(speed_options);
1393 evp_cipher = EVP_get_cipherbyname(opt_arg());
1394 if (evp_cipher == NULL)
1395 evp_md = EVP_get_digestbyname(opt_arg());
1396 if (evp_cipher == NULL && evp_md == NULL) {
1398 "%s: %s is an unknown cipher or digest\n",
1409 * In a forked execution, an engine might need to be
1410 * initialised by each child process, not by the parent.
1411 * So store the name here and run setup_engine() later on.
1413 engine_id = opt_arg();
1417 multi = atoi(opt_arg());
1421 #ifndef OPENSSL_NO_ASYNC
1422 async_jobs = atoi(opt_arg());
1423 if (!ASYNC_is_capable()) {
1425 "%s: async_jobs specified but async not supported\n",
1429 if (async_jobs > 99999) {
1431 "%s: too many async_jobs\n",
1438 if (!opt_int(opt_arg(), &misalign))
1440 if (misalign > MISALIGN) {
1442 "%s: Maximum offset is %d\n", prog, MISALIGN);
1451 #ifdef OPENSSL_NO_MULTIBLOCK
1453 "%s: -mb specified but multi-block support is disabled\n",
1464 argc = opt_num_rest();
1467 /* Remaining arguments are algorithms. */
1468 for (; *argv; argv++) {
1469 if (found(*argv, doit_choices, &i)) {
1473 #ifndef OPENSSL_NO_DES
1474 if (strcmp(*argv, "des") == 0) {
1475 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1479 if (strcmp(*argv, "sha") == 0) {
1480 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1483 #ifndef OPENSSL_NO_RSA
1484 if (strcmp(*argv, "openssl") == 0)
1486 if (strcmp(*argv, "rsa") == 0) {
1487 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1488 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1489 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1490 rsa_doit[R_RSA_15360] = 1;
1493 if (found(*argv, rsa_choices, &i)) {
1498 #ifndef OPENSSL_NO_DSA
1499 if (strcmp(*argv, "dsa") == 0) {
1500 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1501 dsa_doit[R_DSA_2048] = 1;
1504 if (found(*argv, dsa_choices, &i)) {
1509 if (strcmp(*argv, "aes") == 0) {
1510 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1513 #ifndef OPENSSL_NO_CAMELLIA
1514 if (strcmp(*argv, "camellia") == 0) {
1515 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1519 #ifndef OPENSSL_NO_EC
1520 if (strcmp(*argv, "ecdsa") == 0) {
1521 for (i = 0; i < EC_NUM; i++)
1525 if (found(*argv, ecdsa_choices, &i)) {
1529 if (strcmp(*argv, "ecdh") == 0) {
1530 for (i = 0; i < EC_NUM; i++)
1534 if (found(*argv, ecdh_choices, &i)) {
1539 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1543 /* Initialize the job pool if async mode is enabled */
1544 if (async_jobs > 0) {
1545 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1547 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1552 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1554 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1555 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1557 for (i = 0; i < loopargs_len; i++) {
1558 if (async_jobs > 0) {
1559 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1560 if (loopargs[i].wait_ctx == NULL) {
1561 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1566 loopargs[i].buf_malloc =
1567 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1568 loopargs[i].buf2_malloc =
1569 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1570 /* Align the start of buffers on a 64 byte boundary */
1571 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1572 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1573 #ifndef OPENSSL_NO_EC
1574 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1575 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1580 if (multi && do_multi(multi))
1584 /* Initialize the engine after the fork */
1585 e = setup_engine(engine_id, 0);
1587 /* No parameters; turn on everything. */
1588 if ((argc == 0) && !doit[D_EVP]) {
1589 for (i = 0; i < ALGOR_NUM; i++)
1592 #ifndef OPENSSL_NO_RSA
1593 for (i = 0; i < RSA_NUM; i++)
1596 #ifndef OPENSSL_NO_DSA
1597 for (i = 0; i < DSA_NUM; i++)
1600 #ifndef OPENSSL_NO_EC
1601 for (i = 0; i < EC_NUM; i++)
1603 for (i = 0; i < EC_NUM; i++)
1607 for (i = 0; i < ALGOR_NUM; i++)
1611 if (usertime == 0 && !mr)
1613 "You have chosen to measure elapsed time "
1614 "instead of user CPU time.\n");
1616 #ifndef OPENSSL_NO_RSA
1617 for (i = 0; i < loopargs_len; i++) {
1618 for (k = 0; k < RSA_NUM; k++) {
1619 const unsigned char *p;
1622 loopargs[i].rsa_key[k] =
1623 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1624 if (loopargs[i].rsa_key[k] == NULL) {
1626 "internal error loading RSA key number %d\n", k);
1632 #ifndef OPENSSL_NO_DSA
1633 for (i = 0; i < loopargs_len; i++) {
1634 loopargs[i].dsa_key[0] = get_dsa(512);
1635 loopargs[i].dsa_key[1] = get_dsa(1024);
1636 loopargs[i].dsa_key[2] = get_dsa(2048);
1639 #ifndef OPENSSL_NO_DES
1640 DES_set_key_unchecked(&key, &sch);
1641 DES_set_key_unchecked(&key2, &sch2);
1642 DES_set_key_unchecked(&key3, &sch3);
1644 AES_set_encrypt_key(key16, 128, &aes_ks1);
1645 AES_set_encrypt_key(key24, 192, &aes_ks2);
1646 AES_set_encrypt_key(key32, 256, &aes_ks3);
1647 #ifndef OPENSSL_NO_CAMELLIA
1648 Camellia_set_key(key16, 128, &camellia_ks1);
1649 Camellia_set_key(ckey24, 192, &camellia_ks2);
1650 Camellia_set_key(ckey32, 256, &camellia_ks3);
1652 #ifndef OPENSSL_NO_IDEA
1653 IDEA_set_encrypt_key(key16, &idea_ks);
1655 #ifndef OPENSSL_NO_SEED
1656 SEED_set_key(key16, &seed_ks);
1658 #ifndef OPENSSL_NO_RC4
1659 RC4_set_key(&rc4_ks, 16, key16);
1661 #ifndef OPENSSL_NO_RC2
1662 RC2_set_key(&rc2_ks, 16, key16, 128);
1664 #ifndef OPENSSL_NO_RC5
1665 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1667 #ifndef OPENSSL_NO_BF
1668 BF_set_key(&bf_ks, 16, key16);
1670 #ifndef OPENSSL_NO_CAST
1671 CAST_set_key(&cast_ks, 16, key16);
1674 # ifndef OPENSSL_NO_DES
1675 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1681 for (it = count; it; it--)
1682 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1683 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1687 c[D_MD2][0] = count / 10;
1688 c[D_MDC2][0] = count / 10;
1689 c[D_MD4][0] = count;
1690 c[D_MD5][0] = count;
1691 c[D_HMAC][0] = count;
1692 c[D_SHA1][0] = count;
1693 c[D_RMD160][0] = count;
1694 c[D_RC4][0] = count * 5;
1695 c[D_CBC_DES][0] = count;
1696 c[D_EDE3_DES][0] = count / 3;
1697 c[D_CBC_IDEA][0] = count;
1698 c[D_CBC_SEED][0] = count;
1699 c[D_CBC_RC2][0] = count;
1700 c[D_CBC_RC5][0] = count;
1701 c[D_CBC_BF][0] = count;
1702 c[D_CBC_CAST][0] = count;
1703 c[D_CBC_128_AES][0] = count;
1704 c[D_CBC_192_AES][0] = count;
1705 c[D_CBC_256_AES][0] = count;
1706 c[D_CBC_128_CML][0] = count;
1707 c[D_CBC_192_CML][0] = count;
1708 c[D_CBC_256_CML][0] = count;
1709 c[D_SHA256][0] = count;
1710 c[D_SHA512][0] = count;
1711 c[D_WHIRLPOOL][0] = count;
1712 c[D_IGE_128_AES][0] = count;
1713 c[D_IGE_192_AES][0] = count;
1714 c[D_IGE_256_AES][0] = count;
1715 c[D_GHASH][0] = count;
1716 c[D_RAND][0] = count;
1718 for (i = 1; i < SIZE_NUM; i++) {
1721 l0 = (long)lengths[0];
1722 l1 = (long)lengths[i];
1724 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1725 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1726 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1727 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1728 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1729 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1730 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1731 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1732 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1733 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1734 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1735 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
1737 l0 = (long)lengths[i - 1];
1739 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1740 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1741 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1742 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1743 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1744 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1745 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1746 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1747 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1748 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1749 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1750 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1751 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1752 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1753 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1754 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1755 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1756 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1759 # ifndef OPENSSL_NO_RSA
1760 rsa_c[R_RSA_512][0] = count / 2000;
1761 rsa_c[R_RSA_512][1] = count / 400;
1762 for (i = 1; i < RSA_NUM; i++) {
1763 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1764 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1765 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1768 if (rsa_c[i][0] == 0) {
1769 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1776 # ifndef OPENSSL_NO_DSA
1777 dsa_c[R_DSA_512][0] = count / 1000;
1778 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1779 for (i = 1; i < DSA_NUM; i++) {
1780 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1781 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1782 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1785 if (dsa_c[i][0] == 0) {
1786 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1793 # ifndef OPENSSL_NO_EC
1794 ecdsa_c[R_EC_P160][0] = count / 1000;
1795 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1796 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1797 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1798 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1799 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1802 if (ecdsa_c[i][0] == 0) {
1808 ecdsa_c[R_EC_K163][0] = count / 1000;
1809 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1810 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1811 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1812 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1813 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1816 if (ecdsa_c[i][0] == 0) {
1822 ecdsa_c[R_EC_B163][0] = count / 1000;
1823 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1824 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1825 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1826 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1827 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1830 if (ecdsa_c[i][0] == 0) {
1837 ecdh_c[R_EC_P160][0] = count / 1000;
1838 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1839 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1840 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1843 if (ecdh_c[i][0] == 0) {
1848 ecdh_c[R_EC_K163][0] = count / 1000;
1849 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1850 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1851 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1854 if (ecdh_c[i][0] == 0) {
1859 ecdh_c[R_EC_B163][0] = count / 1000;
1860 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1861 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1862 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1865 if (ecdh_c[i][0] == 0) {
1873 /* not worth fixing */
1874 # error "You cannot disable DES on systems without SIGALRM."
1875 # endif /* OPENSSL_NO_DES */
1878 signal(SIGALRM, sig_done);
1880 #endif /* SIGALRM */
1882 #ifndef OPENSSL_NO_MD2
1884 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1885 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1887 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1889 print_result(D_MD2, testnum, count, d);
1893 #ifndef OPENSSL_NO_MDC2
1895 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1896 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1898 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1900 print_result(D_MDC2, testnum, count, d);
1905 #ifndef OPENSSL_NO_MD4
1907 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1908 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1910 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1912 print_result(D_MD4, testnum, count, d);
1917 #ifndef OPENSSL_NO_MD5
1919 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1920 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1922 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1924 print_result(D_MD5, testnum, count, d);
1929 static const char hmac_key[] = "This is a key...";
1930 int len = strlen(hmac_key);
1932 for (i = 0; i < loopargs_len; i++) {
1933 loopargs[i].hctx = HMAC_CTX_new();
1934 if (loopargs[i].hctx == NULL) {
1935 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1939 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1941 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1942 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1944 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1946 print_result(D_HMAC, testnum, count, d);
1948 for (i = 0; i < loopargs_len; i++) {
1949 HMAC_CTX_free(loopargs[i].hctx);
1954 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1955 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1957 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1959 print_result(D_SHA1, testnum, count, d);
1962 if (doit[D_SHA256]) {
1963 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1964 print_message(names[D_SHA256], c[D_SHA256][testnum],
1967 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1969 print_result(D_SHA256, testnum, count, d);
1972 if (doit[D_SHA512]) {
1973 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1974 print_message(names[D_SHA512], c[D_SHA512][testnum],
1977 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1979 print_result(D_SHA512, testnum, count, d);
1982 #ifndef OPENSSL_NO_WHIRLPOOL
1983 if (doit[D_WHIRLPOOL]) {
1984 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1985 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1988 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1990 print_result(D_WHIRLPOOL, testnum, count, d);
1995 #ifndef OPENSSL_NO_RMD160
1996 if (doit[D_RMD160]) {
1997 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1998 print_message(names[D_RMD160], c[D_RMD160][testnum],
2001 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2003 print_result(D_RMD160, testnum, count, d);
2007 #ifndef OPENSSL_NO_RC4
2009 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2010 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2012 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2014 print_result(D_RC4, testnum, count, d);
2018 #ifndef OPENSSL_NO_DES
2019 if (doit[D_CBC_DES]) {
2020 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2021 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2024 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2026 print_result(D_CBC_DES, testnum, count, d);
2030 if (doit[D_EDE3_DES]) {
2031 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2032 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2036 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2038 print_result(D_EDE3_DES, testnum, count, d);
2043 if (doit[D_CBC_128_AES]) {
2044 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2045 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2049 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2051 print_result(D_CBC_128_AES, testnum, count, d);
2054 if (doit[D_CBC_192_AES]) {
2055 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2056 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2060 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2062 print_result(D_CBC_192_AES, testnum, count, d);
2065 if (doit[D_CBC_256_AES]) {
2066 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2067 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2071 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2073 print_result(D_CBC_256_AES, testnum, count, d);
2077 if (doit[D_IGE_128_AES]) {
2078 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2079 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2083 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2085 print_result(D_IGE_128_AES, testnum, count, d);
2088 if (doit[D_IGE_192_AES]) {
2089 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2090 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2094 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2096 print_result(D_IGE_192_AES, testnum, count, d);
2099 if (doit[D_IGE_256_AES]) {
2100 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2101 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2105 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2107 print_result(D_IGE_256_AES, testnum, count, d);
2110 if (doit[D_GHASH]) {
2111 for (i = 0; i < loopargs_len; i++) {
2112 loopargs[i].gcm_ctx =
2113 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2114 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2115 (unsigned char *)"0123456789ab", 12);
2118 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2119 print_message(names[D_GHASH], c[D_GHASH][testnum],
2122 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2124 print_result(D_GHASH, testnum, count, d);
2126 for (i = 0; i < loopargs_len; i++)
2127 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2129 #ifndef OPENSSL_NO_CAMELLIA
2130 if (doit[D_CBC_128_CML]) {
2131 if (async_jobs > 0) {
2132 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2133 names[D_CBC_128_CML]);
2134 doit[D_CBC_128_CML] = 0;
2136 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2137 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2140 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2141 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2142 (size_t)lengths[testnum], &camellia_ks1,
2143 iv, CAMELLIA_ENCRYPT);
2145 print_result(D_CBC_128_CML, testnum, count, d);
2148 if (doit[D_CBC_192_CML]) {
2149 if (async_jobs > 0) {
2150 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2151 names[D_CBC_192_CML]);
2152 doit[D_CBC_192_CML] = 0;
2154 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2155 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2157 if (async_jobs > 0) {
2158 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2162 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2163 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2164 (size_t)lengths[testnum], &camellia_ks2,
2165 iv, CAMELLIA_ENCRYPT);
2167 print_result(D_CBC_192_CML, testnum, count, d);
2170 if (doit[D_CBC_256_CML]) {
2171 if (async_jobs > 0) {
2172 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2173 names[D_CBC_256_CML]);
2174 doit[D_CBC_256_CML] = 0;
2176 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2177 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2180 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2181 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2182 (size_t)lengths[testnum], &camellia_ks3,
2183 iv, CAMELLIA_ENCRYPT);
2185 print_result(D_CBC_256_CML, testnum, count, d);
2189 #ifndef OPENSSL_NO_IDEA
2190 if (doit[D_CBC_IDEA]) {
2191 if (async_jobs > 0) {
2192 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2194 doit[D_CBC_IDEA] = 0;
2196 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2197 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2200 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2201 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2202 (size_t)lengths[testnum], &idea_ks,
2205 print_result(D_CBC_IDEA, testnum, count, d);
2209 #ifndef OPENSSL_NO_SEED
2210 if (doit[D_CBC_SEED]) {
2211 if (async_jobs > 0) {
2212 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2214 doit[D_CBC_SEED] = 0;
2216 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2217 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2220 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2221 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2222 (size_t)lengths[testnum], &seed_ks, iv, 1);
2224 print_result(D_CBC_SEED, testnum, count, d);
2228 #ifndef OPENSSL_NO_RC2
2229 if (doit[D_CBC_RC2]) {
2230 if (async_jobs > 0) {
2231 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2233 doit[D_CBC_RC2] = 0;
2235 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2236 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2238 if (async_jobs > 0) {
2239 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2243 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2244 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2245 (size_t)lengths[testnum], &rc2_ks,
2248 print_result(D_CBC_RC2, testnum, count, d);
2252 #ifndef OPENSSL_NO_RC5
2253 if (doit[D_CBC_RC5]) {
2254 if (async_jobs > 0) {
2255 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2257 doit[D_CBC_RC5] = 0;
2259 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2260 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2262 if (async_jobs > 0) {
2263 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2267 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2268 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2269 (size_t)lengths[testnum], &rc5_ks,
2272 print_result(D_CBC_RC5, testnum, count, d);
2276 #ifndef OPENSSL_NO_BF
2277 if (doit[D_CBC_BF]) {
2278 if (async_jobs > 0) {
2279 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2283 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2284 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2287 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2288 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2289 (size_t)lengths[testnum], &bf_ks,
2292 print_result(D_CBC_BF, testnum, count, d);
2296 #ifndef OPENSSL_NO_CAST
2297 if (doit[D_CBC_CAST]) {
2298 if (async_jobs > 0) {
2299 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2301 doit[D_CBC_CAST] = 0;
2303 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2304 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2307 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2308 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2309 (size_t)lengths[testnum], &cast_ks,
2312 print_result(D_CBC_CAST, testnum, count, d);
2317 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2318 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum]);
2320 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2322 print_result(D_RAND, testnum, count, d);
2327 if (multiblock && evp_cipher) {
2329 (EVP_CIPHER_flags(evp_cipher) &
2330 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2331 BIO_printf(bio_err, "%s is not multi-block capable\n",
2332 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2335 if (async_jobs > 0) {
2336 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2339 multiblock_speed(evp_cipher);
2343 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2346 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2348 * -O3 -fschedule-insns messes up an optimization here!
2349 * names[D_EVP] somehow becomes NULL
2351 print_message(names[D_EVP], save_count, lengths[testnum]);
2353 for (k = 0; k < loopargs_len; k++) {
2354 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2356 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2359 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2361 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2363 switch (EVP_CIPHER_mode(evp_cipher)) {
2364 case EVP_CIPH_CCM_MODE:
2365 loopfunc = EVP_Update_loop_ccm;
2368 loopfunc = EVP_Update_loop;
2372 count = run_benchmark(async_jobs, loopfunc, loopargs);
2374 for (k = 0; k < loopargs_len; k++) {
2375 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2379 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2380 print_message(names[D_EVP], save_count, lengths[testnum]);
2382 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2385 print_result(D_EVP, testnum, count, d);
2389 for (i = 0; i < loopargs_len; i++)
2390 RAND_bytes(loopargs[i].buf, 36);
2392 #ifndef OPENSSL_NO_RSA
2393 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2395 if (!rsa_doit[testnum])
2397 for (i = 0; i < loopargs_len; i++) {
2398 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2399 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2405 "RSA sign failure. No RSA sign will be done.\n");
2406 ERR_print_errors(bio_err);
2409 pkey_print_message("private", "rsa",
2410 rsa_c[testnum][0], rsa_bits[testnum],
2412 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2414 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2417 mr ? "+R1:%ld:%d:%.2f\n"
2418 : "%ld %d bit private RSA's in %.2fs\n",
2419 count, rsa_bits[testnum], d);
2420 rsa_results[testnum][0] = (double)count / d;
2424 for (i = 0; i < loopargs_len; i++) {
2425 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2426 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2432 "RSA verify failure. No RSA verify will be done.\n");
2433 ERR_print_errors(bio_err);
2434 rsa_doit[testnum] = 0;
2436 pkey_print_message("public", "rsa",
2437 rsa_c[testnum][1], rsa_bits[testnum],
2440 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2443 mr ? "+R2:%ld:%d:%.2f\n"
2444 : "%ld %d bit public RSA's in %.2fs\n",
2445 count, rsa_bits[testnum], d);
2446 rsa_results[testnum][1] = (double)count / d;
2449 if (rsa_count <= 1) {
2450 /* if longer than 10s, don't do any more */
2451 for (testnum++; testnum < RSA_NUM; testnum++)
2452 rsa_doit[testnum] = 0;
2455 #endif /* OPENSSL_NO_RSA */
2457 for (i = 0; i < loopargs_len; i++)
2458 RAND_bytes(loopargs[i].buf, 36);
2460 #ifndef OPENSSL_NO_DSA
2461 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2463 if (!dsa_doit[testnum])
2466 /* DSA_generate_key(dsa_key[testnum]); */
2467 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2468 for (i = 0; i < loopargs_len; i++) {
2469 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2470 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2476 "DSA sign failure. No DSA sign will be done.\n");
2477 ERR_print_errors(bio_err);
2480 pkey_print_message("sign", "dsa",
2481 dsa_c[testnum][0], dsa_bits[testnum],
2484 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2487 mr ? "+R3:%ld:%d:%.2f\n"
2488 : "%ld %d bit DSA signs in %.2fs\n",
2489 count, dsa_bits[testnum], d);
2490 dsa_results[testnum][0] = (double)count / d;
2494 for (i = 0; i < loopargs_len; i++) {
2495 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2496 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2502 "DSA verify failure. No DSA verify will be done.\n");
2503 ERR_print_errors(bio_err);
2504 dsa_doit[testnum] = 0;
2506 pkey_print_message("verify", "dsa",
2507 dsa_c[testnum][1], dsa_bits[testnum],
2510 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2513 mr ? "+R4:%ld:%d:%.2f\n"
2514 : "%ld %d bit DSA verify in %.2fs\n",
2515 count, dsa_bits[testnum], d);
2516 dsa_results[testnum][1] = (double)count / d;
2519 if (rsa_count <= 1) {
2520 /* if longer than 10s, don't do any more */
2521 for (testnum++; testnum < DSA_NUM; testnum++)
2522 dsa_doit[testnum] = 0;
2525 #endif /* OPENSSL_NO_DSA */
2527 #ifndef OPENSSL_NO_EC
2528 for (testnum = 0; testnum < EC_NUM; testnum++) {
2531 if (!ecdsa_doit[testnum])
2532 continue; /* Ignore Curve */
2533 for (i = 0; i < loopargs_len; i++) {
2534 loopargs[i].ecdsa[testnum] =
2535 EC_KEY_new_by_curve_name(test_curves[testnum]);
2536 if (loopargs[i].ecdsa[testnum] == NULL) {
2542 BIO_printf(bio_err, "ECDSA failure.\n");
2543 ERR_print_errors(bio_err);
2546 for (i = 0; i < loopargs_len; i++) {
2547 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2548 /* Perform ECDSA signature test */
2549 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2550 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2551 &loopargs[i].siglen,
2552 loopargs[i].ecdsa[testnum]);
2558 "ECDSA sign failure. No ECDSA sign will be done.\n");
2559 ERR_print_errors(bio_err);
2562 pkey_print_message("sign", "ecdsa",
2563 ecdsa_c[testnum][0],
2564 test_curves_bits[testnum], ECDSA_SECONDS);
2566 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2570 mr ? "+R5:%ld:%d:%.2f\n" :
2571 "%ld %d bit ECDSA signs in %.2fs \n",
2572 count, test_curves_bits[testnum], d);
2573 ecdsa_results[testnum][0] = (double)count / d;
2577 /* Perform ECDSA verification test */
2578 for (i = 0; i < loopargs_len; i++) {
2579 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2581 loopargs[i].ecdsa[testnum]);
2587 "ECDSA verify failure. No ECDSA verify will be done.\n");
2588 ERR_print_errors(bio_err);
2589 ecdsa_doit[testnum] = 0;
2591 pkey_print_message("verify", "ecdsa",
2592 ecdsa_c[testnum][1],
2593 test_curves_bits[testnum], ECDSA_SECONDS);
2595 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2598 mr ? "+R6:%ld:%d:%.2f\n"
2599 : "%ld %d bit ECDSA verify in %.2fs\n",
2600 count, test_curves_bits[testnum], d);
2601 ecdsa_results[testnum][1] = (double)count / d;
2604 if (rsa_count <= 1) {
2605 /* if longer than 10s, don't do any more */
2606 for (testnum++; testnum < EC_NUM; testnum++)
2607 ecdsa_doit[testnum] = 0;
2612 for (testnum = 0; testnum < EC_NUM; testnum++) {
2613 int ecdh_checks = 1;
2615 if (!ecdh_doit[testnum])
2618 for (i = 0; i < loopargs_len; i++) {
2619 EVP_PKEY_CTX *kctx = NULL;
2620 EVP_PKEY_CTX *test_ctx = NULL;
2621 EVP_PKEY_CTX *ctx = NULL;
2622 EVP_PKEY *key_A = NULL;
2623 EVP_PKEY *key_B = NULL;
2627 /* Ensure that the error queue is empty */
2628 if (ERR_peek_error()) {
2630 "WARNING: the error queue contains previous unhandled errors.\n");
2631 ERR_print_errors(bio_err);
2634 /* Let's try to create a ctx directly from the NID: this works for
2635 * curves like Curve25519 that are not implemented through the low
2636 * level EC interface.
2637 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2638 * then we set the curve by NID before deriving the actual keygen
2639 * ctx for that specific curve. */
2640 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2642 EVP_PKEY_CTX *pctx = NULL;
2643 EVP_PKEY *params = NULL;
2645 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2646 * "int_ctx_new:unsupported algorithm" error was added to the
2648 * We remove it from the error queue as we are handling it. */
2649 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2650 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2651 /* check that the error origin matches */
2652 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2653 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2654 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2655 ERR_get_error(); /* pop error from queue */
2656 if (ERR_peek_error()) {
2658 "Unhandled error in the error queue during ECDH init.\n");
2659 ERR_print_errors(bio_err);
2664 if ( /* Create the context for parameter generation */
2665 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2666 /* Initialise the parameter generation */
2667 !EVP_PKEY_paramgen_init(pctx) ||
2668 /* Set the curve by NID */
2669 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2672 /* Create the parameter object params */
2673 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2675 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2676 ERR_print_errors(bio_err);
2680 /* Create the context for the key generation */
2681 kctx = EVP_PKEY_CTX_new(params, NULL);
2683 EVP_PKEY_free(params);
2685 EVP_PKEY_CTX_free(pctx);
2688 if (kctx == NULL || /* keygen ctx is not null */
2689 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2691 BIO_printf(bio_err, "ECDH keygen failure.\n");
2692 ERR_print_errors(bio_err);
2697 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2698 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2699 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2700 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2701 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2702 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2703 outlen == 0 || /* ensure outlen is a valid size */
2704 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2706 BIO_printf(bio_err, "ECDH key generation failure.\n");
2707 ERR_print_errors(bio_err);
2712 /* Here we perform a test run, comparing the output of a*B and b*A;
2713 * we try this here and assume that further EVP_PKEY_derive calls
2714 * never fail, so we can skip checks in the actually benchmarked
2715 * code, for maximum performance. */
2716 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2717 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2718 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2719 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2720 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2721 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2722 test_outlen != outlen /* compare output length */ ) {
2724 BIO_printf(bio_err, "ECDH computation failure.\n");
2725 ERR_print_errors(bio_err);
2730 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2731 if (CRYPTO_memcmp(loopargs[i].secret_a,
2732 loopargs[i].secret_b, outlen)) {
2734 BIO_printf(bio_err, "ECDH computations don't match.\n");
2735 ERR_print_errors(bio_err);
2740 loopargs[i].ecdh_ctx[testnum] = ctx;
2741 loopargs[i].outlen[testnum] = outlen;
2743 EVP_PKEY_CTX_free(kctx);
2745 EVP_PKEY_CTX_free(test_ctx);
2748 if (ecdh_checks != 0) {
2749 pkey_print_message("", "ecdh",
2751 test_curves_bits[testnum], ECDH_SECONDS);
2754 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2757 mr ? "+R7:%ld:%d:%.2f\n" :
2758 "%ld %d-bit ECDH ops in %.2fs\n", count,
2759 test_curves_bits[testnum], d);
2760 ecdh_results[testnum][0] = (double)count / d;
2764 if (rsa_count <= 1) {
2765 /* if longer than 10s, don't do any more */
2766 for (testnum++; testnum < EC_NUM; testnum++)
2767 ecdh_doit[testnum] = 0;
2770 #endif /* OPENSSL_NO_EC */
2775 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2776 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2778 printf("%s ", BN_options());
2779 #ifndef OPENSSL_NO_MD2
2780 printf("%s ", MD2_options());
2782 #ifndef OPENSSL_NO_RC4
2783 printf("%s ", RC4_options());
2785 #ifndef OPENSSL_NO_DES
2786 printf("%s ", DES_options());
2788 printf("%s ", AES_options());
2789 #ifndef OPENSSL_NO_IDEA
2790 printf("%s ", IDEA_options());
2792 #ifndef OPENSSL_NO_BF
2793 printf("%s ", BF_options());
2795 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2803 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2806 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2807 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2811 for (k = 0; k < ALGOR_NUM; k++) {
2815 printf("+F:%d:%s", k, names[k]);
2817 printf("%-13s", names[k]);
2818 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2819 if (results[k][testnum] > 10000 && !mr)
2820 printf(" %11.2fk", results[k][testnum] / 1e3);
2822 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2826 #ifndef OPENSSL_NO_RSA
2828 for (k = 0; k < RSA_NUM; k++) {
2831 if (testnum && !mr) {
2832 printf("%18ssign verify sign/s verify/s\n", " ");
2836 printf("+F2:%u:%u:%f:%f\n",
2837 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2839 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2840 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2841 rsa_results[k][0], rsa_results[k][1]);
2844 #ifndef OPENSSL_NO_DSA
2846 for (k = 0; k < DSA_NUM; k++) {
2849 if (testnum && !mr) {
2850 printf("%18ssign verify sign/s verify/s\n", " ");
2854 printf("+F3:%u:%u:%f:%f\n",
2855 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2857 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2858 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2859 dsa_results[k][0], dsa_results[k][1]);
2862 #ifndef OPENSSL_NO_EC
2864 for (k = 0; k < EC_NUM; k++) {
2867 if (testnum && !mr) {
2868 printf("%30ssign verify sign/s verify/s\n", " ");
2873 printf("+F4:%u:%u:%f:%f\n",
2874 k, test_curves_bits[k],
2875 ecdsa_results[k][0], ecdsa_results[k][1]);
2877 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2878 test_curves_bits[k],
2879 test_curves_names[k],
2880 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2881 ecdsa_results[k][0], ecdsa_results[k][1]);
2885 for (k = 0; k < EC_NUM; k++) {
2888 if (testnum && !mr) {
2889 printf("%30sop op/s\n", " ");
2893 printf("+F5:%u:%u:%f:%f\n",
2894 k, test_curves_bits[k],
2895 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2898 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2899 test_curves_bits[k],
2900 test_curves_names[k],
2901 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2908 ERR_print_errors(bio_err);
2909 for (i = 0; i < loopargs_len; i++) {
2910 OPENSSL_free(loopargs[i].buf_malloc);
2911 OPENSSL_free(loopargs[i].buf2_malloc);
2913 #ifndef OPENSSL_NO_RSA
2914 for (k = 0; k < RSA_NUM; k++)
2915 RSA_free(loopargs[i].rsa_key[k]);
2917 #ifndef OPENSSL_NO_DSA
2918 for (k = 0; k < DSA_NUM; k++)
2919 DSA_free(loopargs[i].dsa_key[k]);
2921 #ifndef OPENSSL_NO_EC
2922 for (k = 0; k < EC_NUM; k++) {
2923 EC_KEY_free(loopargs[i].ecdsa[k]);
2924 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2926 OPENSSL_free(loopargs[i].secret_a);
2927 OPENSSL_free(loopargs[i].secret_b);
2931 if (async_jobs > 0) {
2932 for (i = 0; i < loopargs_len; i++)
2933 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2937 ASYNC_cleanup_thread();
2939 OPENSSL_free(loopargs);
2944 static void print_message(const char *s, long num, int length)
2948 mr ? "+DT:%s:%d:%d\n"
2949 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2950 (void)BIO_flush(bio_err);
2954 mr ? "+DN:%s:%ld:%d\n"
2955 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2956 (void)BIO_flush(bio_err);
2960 static void pkey_print_message(const char *str, const char *str2, long num,
2965 mr ? "+DTP:%d:%s:%s:%d\n"
2966 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2967 (void)BIO_flush(bio_err);
2971 mr ? "+DNP:%ld:%d:%s:%s\n"
2972 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2973 (void)BIO_flush(bio_err);
2977 static void print_result(int alg, int run_no, int count, double time_used)
2980 BIO_puts(bio_err, "EVP error!\n");
2984 mr ? "+R:%d:%s:%f\n"
2985 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2986 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2990 static char *sstrsep(char **string, const char *delim)
2993 char *token = *string;
2998 memset(isdelim, 0, sizeof isdelim);
3002 isdelim[(unsigned char)(*delim)] = 1;
3006 while (!isdelim[(unsigned char)(**string)]) {
3018 static int do_multi(int multi)
3023 static char sep[] = ":";
3025 fds = malloc(sizeof(*fds) * multi);
3026 for (n = 0; n < multi; ++n) {
3027 if (pipe(fd) == -1) {
3028 BIO_printf(bio_err, "pipe failure\n");
3032 (void)BIO_flush(bio_err);
3039 if (dup(fd[1]) == -1) {
3040 BIO_printf(bio_err, "dup failed\n");
3049 printf("Forked child %d\n", n);
3052 /* for now, assume the pipe is long enough to take all the output */
3053 for (n = 0; n < multi; ++n) {
3058 f = fdopen(fds[n], "r");
3059 while (fgets(buf, sizeof buf, f)) {
3060 p = strchr(buf, '\n');
3063 if (buf[0] != '+') {
3065 "Don't understand line '%s' from child %d\n", buf,
3069 printf("Got: %s from %d\n", buf, n);
3070 if (strncmp(buf, "+F:", 3) == 0) {
3075 alg = atoi(sstrsep(&p, sep));
3077 for (j = 0; j < SIZE_NUM; ++j)
3078 results[alg][j] += atof(sstrsep(&p, sep));
3079 } else if (strncmp(buf, "+F2:", 4) == 0) {
3084 k = atoi(sstrsep(&p, sep));
3087 d = atof(sstrsep(&p, sep));
3088 rsa_results[k][0] += d;
3090 d = atof(sstrsep(&p, sep));
3091 rsa_results[k][1] += d;
3093 # ifndef OPENSSL_NO_DSA
3094 else if (strncmp(buf, "+F3:", 4) == 0) {
3099 k = atoi(sstrsep(&p, sep));
3102 d = atof(sstrsep(&p, sep));
3103 dsa_results[k][0] += d;
3105 d = atof(sstrsep(&p, sep));
3106 dsa_results[k][1] += d;
3109 # ifndef OPENSSL_NO_EC
3110 else if (strncmp(buf, "+F4:", 4) == 0) {
3115 k = atoi(sstrsep(&p, sep));
3118 d = atof(sstrsep(&p, sep));
3119 ecdsa_results[k][0] += d;
3121 d = atof(sstrsep(&p, sep));
3122 ecdsa_results[k][1] += d;
3123 } else if (strncmp(buf, "+F5:", 4) == 0) {
3128 k = atoi(sstrsep(&p, sep));
3131 d = atof(sstrsep(&p, sep));
3132 ecdh_results[k][0] += d;
3136 else if (strncmp(buf, "+H:", 3) == 0) {
3139 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3150 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3152 static int mblengths[] =
3153 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3154 int j, count, num = OSSL_NELEM(mblengths);
3155 const char *alg_name;
3156 unsigned char *inp, *out, no_key[32], no_iv[16];
3157 EVP_CIPHER_CTX *ctx;
3160 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3161 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3162 ctx = EVP_CIPHER_CTX_new();
3163 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3164 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3165 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3167 for (j = 0; j < num; j++) {
3168 print_message(alg_name, 0, mblengths[j]);
3170 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3171 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3172 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3173 size_t len = mblengths[j];
3176 memset(aad, 0, 8); /* avoid uninitialized values */
3177 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3178 aad[9] = 3; /* version */
3180 aad[11] = 0; /* length */
3182 mb_param.out = NULL;
3185 mb_param.interleave = 8;
3187 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3188 sizeof(mb_param), &mb_param);
3194 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3195 sizeof(mb_param), &mb_param);
3199 RAND_bytes(out, 16);
3201 aad[11] = (unsigned char)(len >> 8);
3202 aad[12] = (unsigned char)(len);
3203 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3204 EVP_AEAD_TLS1_AAD_LEN, aad);
3205 EVP_Cipher(ctx, out, inp, len + pad);
3209 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3210 : "%d %s's in %.2fs\n", count, "evp", d);
3211 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3215 fprintf(stdout, "+H");
3216 for (j = 0; j < num; j++)
3217 fprintf(stdout, ":%d", mblengths[j]);
3218 fprintf(stdout, "\n");
3219 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3220 for (j = 0; j < num; j++)
3221 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3222 fprintf(stdout, "\n");
3225 "The 'numbers' are in 1000s of bytes per second processed.\n");
3226 fprintf(stdout, "type ");
3227 for (j = 0; j < num; j++)
3228 fprintf(stdout, "%7d bytes", mblengths[j]);
3229 fprintf(stdout, "\n");
3230 fprintf(stdout, "%-24s", alg_name);
3232 for (j = 0; j < num; j++) {
3233 if (results[D_EVP][j] > 10000)
3234 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3236 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3238 fprintf(stdout, "\n");
3243 EVP_CIPHER_CTX_free(ctx);