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,
346 const OPTIONS speed_options[] = {
347 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
348 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
349 {"help", OPT_HELP, '-', "Display this summary"},
350 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
351 {"decrypt", OPT_DECRYPT, '-',
352 "Time decryption instead of encryption (only EVP)"},
353 {"mr", OPT_MR, '-', "Produce machine readable output"},
355 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
356 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
357 {"elapsed", OPT_ELAPSED, '-',
358 "Measure time in real time instead of CPU user time"},
360 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
362 #ifndef OPENSSL_NO_ASYNC
363 {"async_jobs", OPT_ASYNCJOBS, 'p',
364 "Enable async mode and start pnum jobs"},
367 #ifndef OPENSSL_NO_ENGINE
368 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
370 {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
384 #define D_CBC_IDEA 10
385 #define D_CBC_SEED 11
389 #define D_CBC_CAST 15
390 #define D_CBC_128_AES 16
391 #define D_CBC_192_AES 17
392 #define D_CBC_256_AES 18
393 #define D_CBC_128_CML 19
394 #define D_CBC_192_CML 20
395 #define D_CBC_256_CML 21
399 #define D_WHIRLPOOL 25
400 #define D_IGE_128_AES 26
401 #define D_IGE_192_AES 27
402 #define D_IGE_256_AES 28
405 static OPT_PAIR doit_choices[] = {
406 #ifndef OPENSSL_NO_MD2
409 #ifndef OPENSSL_NO_MDC2
412 #ifndef OPENSSL_NO_MD4
415 #ifndef OPENSSL_NO_MD5
420 {"sha256", D_SHA256},
421 {"sha512", D_SHA512},
422 #ifndef OPENSSL_NO_WHIRLPOOL
423 {"whirlpool", D_WHIRLPOOL},
425 #ifndef OPENSSL_NO_RMD160
426 {"ripemd", D_RMD160},
427 {"rmd160", D_RMD160},
428 {"ripemd160", D_RMD160},
430 #ifndef OPENSSL_NO_RC4
433 #ifndef OPENSSL_NO_DES
434 {"des-cbc", D_CBC_DES},
435 {"des-ede3", D_EDE3_DES},
437 {"aes-128-cbc", D_CBC_128_AES},
438 {"aes-192-cbc", D_CBC_192_AES},
439 {"aes-256-cbc", D_CBC_256_AES},
440 {"aes-128-ige", D_IGE_128_AES},
441 {"aes-192-ige", D_IGE_192_AES},
442 {"aes-256-ige", D_IGE_256_AES},
443 #ifndef OPENSSL_NO_RC2
444 {"rc2-cbc", D_CBC_RC2},
447 #ifndef OPENSSL_NO_RC5
448 {"rc5-cbc", D_CBC_RC5},
451 #ifndef OPENSSL_NO_IDEA
452 {"idea-cbc", D_CBC_IDEA},
453 {"idea", D_CBC_IDEA},
455 #ifndef OPENSSL_NO_SEED
456 {"seed-cbc", D_CBC_SEED},
457 {"seed", D_CBC_SEED},
459 #ifndef OPENSSL_NO_BF
460 {"bf-cbc", D_CBC_BF},
461 {"blowfish", D_CBC_BF},
464 #ifndef OPENSSL_NO_CAST
465 {"cast-cbc", D_CBC_CAST},
466 {"cast", D_CBC_CAST},
467 {"cast5", D_CBC_CAST},
474 #ifndef OPENSSL_NO_DSA
476 # define R_DSA_1024 1
477 # define R_DSA_2048 2
478 static OPT_PAIR dsa_choices[] = {
479 {"dsa512", R_DSA_512},
480 {"dsa1024", R_DSA_1024},
481 {"dsa2048", R_DSA_2048},
492 #define R_RSA_15360 6
493 static OPT_PAIR rsa_choices[] = {
494 {"rsa512", R_RSA_512},
495 {"rsa1024", R_RSA_1024},
496 {"rsa2048", R_RSA_2048},
497 {"rsa3072", R_RSA_3072},
498 {"rsa4096", R_RSA_4096},
499 {"rsa7680", R_RSA_7680},
500 {"rsa15360", R_RSA_15360},
520 #define R_EC_X25519 16
521 #ifndef OPENSSL_NO_EC
522 static OPT_PAIR ecdsa_choices[] = {
523 {"ecdsap160", R_EC_P160},
524 {"ecdsap192", R_EC_P192},
525 {"ecdsap224", R_EC_P224},
526 {"ecdsap256", R_EC_P256},
527 {"ecdsap384", R_EC_P384},
528 {"ecdsap521", R_EC_P521},
529 {"ecdsak163", R_EC_K163},
530 {"ecdsak233", R_EC_K233},
531 {"ecdsak283", R_EC_K283},
532 {"ecdsak409", R_EC_K409},
533 {"ecdsak571", R_EC_K571},
534 {"ecdsab163", R_EC_B163},
535 {"ecdsab233", R_EC_B233},
536 {"ecdsab283", R_EC_B283},
537 {"ecdsab409", R_EC_B409},
538 {"ecdsab571", R_EC_B571},
542 static OPT_PAIR ecdh_choices[] = {
543 {"ecdhp160", R_EC_P160},
544 {"ecdhp192", R_EC_P192},
545 {"ecdhp224", R_EC_P224},
546 {"ecdhp256", R_EC_P256},
547 {"ecdhp384", R_EC_P384},
548 {"ecdhp521", R_EC_P521},
549 {"ecdhk163", R_EC_K163},
550 {"ecdhk233", R_EC_K233},
551 {"ecdhk283", R_EC_K283},
552 {"ecdhk409", R_EC_K409},
553 {"ecdhk571", R_EC_K571},
554 {"ecdhb163", R_EC_B163},
555 {"ecdhb233", R_EC_B233},
556 {"ecdhb283", R_EC_B283},
557 {"ecdhb409", R_EC_B409},
558 {"ecdhb571", R_EC_B571},
559 {"ecdhx25519", R_EC_X25519},
565 # define COND(d) (count < (d))
566 # define COUNT(d) (d)
568 # define COND(unused_cond) (run && count<0x7fffffff)
569 # define COUNT(d) (count)
574 /* Nb of iterations to do per algorithm and key-size */
575 static long c[ALGOR_NUM][SIZE_NUM];
577 #ifndef OPENSSL_NO_MD2
578 static int EVP_Digest_MD2_loop(void *args)
580 loopargs_t *tempargs = *(loopargs_t **) args;
581 unsigned char *buf = tempargs->buf;
582 unsigned char md2[MD2_DIGEST_LENGTH];
585 for (count = 0; COND(c[D_MD2][testnum]); count++) {
586 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
594 #ifndef OPENSSL_NO_MDC2
595 static int EVP_Digest_MDC2_loop(void *args)
597 loopargs_t *tempargs = *(loopargs_t **) args;
598 unsigned char *buf = tempargs->buf;
599 unsigned char mdc2[MDC2_DIGEST_LENGTH];
602 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
603 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
611 #ifndef OPENSSL_NO_MD4
612 static int EVP_Digest_MD4_loop(void *args)
614 loopargs_t *tempargs = *(loopargs_t **) args;
615 unsigned char *buf = tempargs->buf;
616 unsigned char md4[MD4_DIGEST_LENGTH];
619 for (count = 0; COND(c[D_MD4][testnum]); count++) {
620 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
628 #ifndef OPENSSL_NO_MD5
629 static int MD5_loop(void *args)
631 loopargs_t *tempargs = *(loopargs_t **) args;
632 unsigned char *buf = tempargs->buf;
633 unsigned char md5[MD5_DIGEST_LENGTH];
635 for (count = 0; COND(c[D_MD5][testnum]); count++)
636 MD5(buf, lengths[testnum], md5);
640 static int HMAC_loop(void *args)
642 loopargs_t *tempargs = *(loopargs_t **) args;
643 unsigned char *buf = tempargs->buf;
644 HMAC_CTX *hctx = tempargs->hctx;
645 unsigned char hmac[MD5_DIGEST_LENGTH];
648 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
649 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
650 HMAC_Update(hctx, buf, lengths[testnum]);
651 HMAC_Final(hctx, hmac, NULL);
657 static int SHA1_loop(void *args)
659 loopargs_t *tempargs = *(loopargs_t **) args;
660 unsigned char *buf = tempargs->buf;
661 unsigned char sha[SHA_DIGEST_LENGTH];
663 for (count = 0; COND(c[D_SHA1][testnum]); count++)
664 SHA1(buf, lengths[testnum], sha);
668 static int SHA256_loop(void *args)
670 loopargs_t *tempargs = *(loopargs_t **) args;
671 unsigned char *buf = tempargs->buf;
672 unsigned char sha256[SHA256_DIGEST_LENGTH];
674 for (count = 0; COND(c[D_SHA256][testnum]); count++)
675 SHA256(buf, lengths[testnum], sha256);
679 static int SHA512_loop(void *args)
681 loopargs_t *tempargs = *(loopargs_t **) args;
682 unsigned char *buf = tempargs->buf;
683 unsigned char sha512[SHA512_DIGEST_LENGTH];
685 for (count = 0; COND(c[D_SHA512][testnum]); count++)
686 SHA512(buf, lengths[testnum], sha512);
690 #ifndef OPENSSL_NO_WHIRLPOOL
691 static int WHIRLPOOL_loop(void *args)
693 loopargs_t *tempargs = *(loopargs_t **) args;
694 unsigned char *buf = tempargs->buf;
695 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
697 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
698 WHIRLPOOL(buf, lengths[testnum], whirlpool);
703 #ifndef OPENSSL_NO_RMD160
704 static int EVP_Digest_RMD160_loop(void *args)
706 loopargs_t *tempargs = *(loopargs_t **) args;
707 unsigned char *buf = tempargs->buf;
708 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
710 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
711 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
712 NULL, EVP_ripemd160(), NULL))
719 #ifndef OPENSSL_NO_RC4
720 static RC4_KEY rc4_ks;
721 static int RC4_loop(void *args)
723 loopargs_t *tempargs = *(loopargs_t **) args;
724 unsigned char *buf = tempargs->buf;
726 for (count = 0; COND(c[D_RC4][testnum]); count++)
727 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
732 #ifndef OPENSSL_NO_DES
733 static unsigned char DES_iv[8];
734 static DES_key_schedule sch;
735 static DES_key_schedule sch2;
736 static DES_key_schedule sch3;
737 static int DES_ncbc_encrypt_loop(void *args)
739 loopargs_t *tempargs = *(loopargs_t **) args;
740 unsigned char *buf = tempargs->buf;
742 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
743 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
744 &DES_iv, DES_ENCRYPT);
748 static int DES_ede3_cbc_encrypt_loop(void *args)
750 loopargs_t *tempargs = *(loopargs_t **) args;
751 unsigned char *buf = tempargs->buf;
753 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
754 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
755 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
760 #define MAX_BLOCK_SIZE 128
762 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
763 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
764 static int AES_cbc_128_encrypt_loop(void *args)
766 loopargs_t *tempargs = *(loopargs_t **) args;
767 unsigned char *buf = tempargs->buf;
769 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
770 AES_cbc_encrypt(buf, buf,
771 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
775 static int AES_cbc_192_encrypt_loop(void *args)
777 loopargs_t *tempargs = *(loopargs_t **) args;
778 unsigned char *buf = tempargs->buf;
780 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
781 AES_cbc_encrypt(buf, buf,
782 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
786 static int AES_cbc_256_encrypt_loop(void *args)
788 loopargs_t *tempargs = *(loopargs_t **) args;
789 unsigned char *buf = tempargs->buf;
791 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
792 AES_cbc_encrypt(buf, buf,
793 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
797 static int AES_ige_128_encrypt_loop(void *args)
799 loopargs_t *tempargs = *(loopargs_t **) args;
800 unsigned char *buf = tempargs->buf;
801 unsigned char *buf2 = tempargs->buf2;
803 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
804 AES_ige_encrypt(buf, buf2,
805 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
809 static int AES_ige_192_encrypt_loop(void *args)
811 loopargs_t *tempargs = *(loopargs_t **) args;
812 unsigned char *buf = tempargs->buf;
813 unsigned char *buf2 = tempargs->buf2;
815 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
816 AES_ige_encrypt(buf, buf2,
817 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
821 static int AES_ige_256_encrypt_loop(void *args)
823 loopargs_t *tempargs = *(loopargs_t **) args;
824 unsigned char *buf = tempargs->buf;
825 unsigned char *buf2 = tempargs->buf2;
827 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
828 AES_ige_encrypt(buf, buf2,
829 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
833 static int CRYPTO_gcm128_aad_loop(void *args)
835 loopargs_t *tempargs = *(loopargs_t **) args;
836 unsigned char *buf = tempargs->buf;
837 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
839 for (count = 0; COND(c[D_GHASH][testnum]); count++)
840 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
844 static int RAND_bytes_loop(void *args)
846 loopargs_t *tempargs = *(loopargs_t **) args;
847 unsigned char *buf = tempargs->buf;
850 for (count = 0; COND(c[D_RAND][testnum]); count++)
851 RAND_bytes(buf, lengths[testnum]);
855 static long save_count = 0;
856 static int decrypt = 0;
857 static int EVP_Update_loop(void *args)
859 loopargs_t *tempargs = *(loopargs_t **) args;
860 unsigned char *buf = tempargs->buf;
861 EVP_CIPHER_CTX *ctx = tempargs->ctx;
864 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
867 for (count = 0; COND(nb_iter); count++)
868 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
870 for (count = 0; COND(nb_iter); count++)
871 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
873 EVP_DecryptFinal_ex(ctx, buf, &outl);
875 EVP_EncryptFinal_ex(ctx, buf, &outl);
879 * CCM does not support streaming. For the purpose of performance measurement,
880 * each message is encrypted using the same (key,iv)-pair. Do not use this
881 * code in your application.
883 static int EVP_Update_loop_ccm(void *args)
885 loopargs_t *tempargs = *(loopargs_t **) args;
886 unsigned char *buf = tempargs->buf;
887 EVP_CIPHER_CTX *ctx = tempargs->ctx;
889 unsigned char tag[12];
891 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
894 for (count = 0; COND(nb_iter); count++) {
895 EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
896 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
897 EVP_DecryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
898 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
899 EVP_DecryptFinal_ex(ctx, buf, &outl);
902 for (count = 0; COND(nb_iter); count++) {
903 EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
904 EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
905 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
906 EVP_EncryptFinal_ex(ctx, buf, &outl);
912 static const EVP_MD *evp_md = NULL;
913 static int EVP_Digest_loop(void *args)
915 loopargs_t *tempargs = *(loopargs_t **) args;
916 unsigned char *buf = tempargs->buf;
917 unsigned char md[EVP_MAX_MD_SIZE];
920 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
923 for (count = 0; COND(nb_iter); count++) {
924 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
930 #ifndef OPENSSL_NO_RSA
931 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
933 static int RSA_sign_loop(void *args)
935 loopargs_t *tempargs = *(loopargs_t **) args;
936 unsigned char *buf = tempargs->buf;
937 unsigned char *buf2 = tempargs->buf2;
938 unsigned int *rsa_num = &tempargs->siglen;
939 RSA **rsa_key = tempargs->rsa_key;
941 for (count = 0; COND(rsa_c[testnum][0]); count++) {
942 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
944 BIO_printf(bio_err, "RSA sign failure\n");
945 ERR_print_errors(bio_err);
953 static int RSA_verify_loop(void *args)
955 loopargs_t *tempargs = *(loopargs_t **) args;
956 unsigned char *buf = tempargs->buf;
957 unsigned char *buf2 = tempargs->buf2;
958 unsigned int rsa_num = tempargs->siglen;
959 RSA **rsa_key = tempargs->rsa_key;
961 for (count = 0; COND(rsa_c[testnum][1]); count++) {
963 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
965 BIO_printf(bio_err, "RSA verify failure\n");
966 ERR_print_errors(bio_err);
975 #ifndef OPENSSL_NO_DSA
976 static long dsa_c[DSA_NUM][2];
977 static int DSA_sign_loop(void *args)
979 loopargs_t *tempargs = *(loopargs_t **) args;
980 unsigned char *buf = tempargs->buf;
981 unsigned char *buf2 = tempargs->buf2;
982 DSA **dsa_key = tempargs->dsa_key;
983 unsigned int *siglen = &tempargs->siglen;
985 for (count = 0; COND(dsa_c[testnum][0]); count++) {
986 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
988 BIO_printf(bio_err, "DSA sign failure\n");
989 ERR_print_errors(bio_err);
997 static int DSA_verify_loop(void *args)
999 loopargs_t *tempargs = *(loopargs_t **) args;
1000 unsigned char *buf = tempargs->buf;
1001 unsigned char *buf2 = tempargs->buf2;
1002 DSA **dsa_key = tempargs->dsa_key;
1003 unsigned int siglen = tempargs->siglen;
1005 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1006 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1008 BIO_printf(bio_err, "DSA verify failure\n");
1009 ERR_print_errors(bio_err);
1018 #ifndef OPENSSL_NO_EC
1019 static long ecdsa_c[EC_NUM][2];
1020 static int ECDSA_sign_loop(void *args)
1022 loopargs_t *tempargs = *(loopargs_t **) args;
1023 unsigned char *buf = tempargs->buf;
1024 EC_KEY **ecdsa = tempargs->ecdsa;
1025 unsigned char *ecdsasig = tempargs->buf2;
1026 unsigned int *ecdsasiglen = &tempargs->siglen;
1028 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1029 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1031 BIO_printf(bio_err, "ECDSA sign failure\n");
1032 ERR_print_errors(bio_err);
1040 static int ECDSA_verify_loop(void *args)
1042 loopargs_t *tempargs = *(loopargs_t **) args;
1043 unsigned char *buf = tempargs->buf;
1044 EC_KEY **ecdsa = tempargs->ecdsa;
1045 unsigned char *ecdsasig = tempargs->buf2;
1046 unsigned int ecdsasiglen = tempargs->siglen;
1048 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1049 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1051 BIO_printf(bio_err, "ECDSA verify failure\n");
1052 ERR_print_errors(bio_err);
1060 /* ******************************************************************** */
1061 static long ecdh_c[EC_NUM][1];
1063 static int ECDH_EVP_derive_key_loop(void *args)
1065 loopargs_t *tempargs = *(loopargs_t **) args;
1066 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1067 unsigned char *derived_secret = tempargs->secret_a;
1069 size_t *outlen = &(tempargs->outlen[testnum]);
1071 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1072 EVP_PKEY_derive(ctx, derived_secret, outlen);
1077 #endif /* OPENSSL_NO_EC */
1079 static int run_benchmark(int async_jobs,
1080 int (*loop_function) (void *), loopargs_t * loopargs)
1082 int job_op_count = 0;
1083 int total_op_count = 0;
1084 int num_inprogress = 0;
1085 int error = 0, i = 0, ret = 0;
1086 OSSL_ASYNC_FD job_fd = 0;
1087 size_t num_job_fds = 0;
1091 if (async_jobs == 0) {
1092 return loop_function((void *)&loopargs);
1095 for (i = 0; i < async_jobs && !error; i++) {
1096 loopargs_t *looparg_item = loopargs + i;
1098 /* Copy pointer content (looparg_t item address) into async context */
1099 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1100 &job_op_count, loop_function,
1101 (void *)&looparg_item, sizeof(looparg_item));
1107 if (job_op_count == -1) {
1110 total_op_count += job_op_count;
1115 BIO_printf(bio_err, "Failure in the job\n");
1116 ERR_print_errors(bio_err);
1122 while (num_inprogress > 0) {
1123 #if defined(OPENSSL_SYS_WINDOWS)
1125 #elif defined(OPENSSL_SYS_UNIX)
1126 int select_result = 0;
1127 OSSL_ASYNC_FD max_fd = 0;
1130 FD_ZERO(&waitfdset);
1132 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1133 if (loopargs[i].inprogress_job == NULL)
1136 if (!ASYNC_WAIT_CTX_get_all_fds
1137 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1138 || num_job_fds > 1) {
1139 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1140 ERR_print_errors(bio_err);
1144 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1146 FD_SET(job_fd, &waitfdset);
1147 if (job_fd > max_fd)
1151 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1153 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1154 "Decrease the value of async_jobs\n",
1155 max_fd, FD_SETSIZE);
1156 ERR_print_errors(bio_err);
1161 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1162 if (select_result == -1 && errno == EINTR)
1165 if (select_result == -1) {
1166 BIO_printf(bio_err, "Failure in the select\n");
1167 ERR_print_errors(bio_err);
1172 if (select_result == 0)
1176 for (i = 0; i < async_jobs; i++) {
1177 if (loopargs[i].inprogress_job == NULL)
1180 if (!ASYNC_WAIT_CTX_get_all_fds
1181 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1182 || num_job_fds > 1) {
1183 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1184 ERR_print_errors(bio_err);
1188 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1191 #if defined(OPENSSL_SYS_UNIX)
1192 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1194 #elif defined(OPENSSL_SYS_WINDOWS)
1195 if (num_job_fds == 1
1196 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1201 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1202 loopargs[i].wait_ctx, &job_op_count,
1203 loop_function, (void *)(loopargs + i),
1204 sizeof(loopargs_t));
1209 if (job_op_count == -1) {
1212 total_op_count += job_op_count;
1215 loopargs[i].inprogress_job = NULL;
1220 loopargs[i].inprogress_job = NULL;
1221 BIO_printf(bio_err, "Failure in the job\n");
1222 ERR_print_errors(bio_err);
1229 return error ? -1 : total_op_count;
1232 int speed_main(int argc, char **argv)
1235 int (*loopfunc)(void *args);
1236 loopargs_t *loopargs = NULL;
1238 int loopargs_len = 0;
1240 const char *engine_id = NULL;
1241 const EVP_CIPHER *evp_cipher = NULL;
1244 int multiblock = 0, pr_header = 0;
1245 int doit[ALGOR_NUM] = { 0 };
1246 int ret = 1, i, k, misalign = 0;
1251 unsigned int async_jobs = 0;
1252 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1253 || !defined(OPENSSL_NO_EC)
1257 /* What follows are the buffers and key material. */
1258 #ifndef OPENSSL_NO_RC5
1261 #ifndef OPENSSL_NO_RC2
1264 #ifndef OPENSSL_NO_IDEA
1265 IDEA_KEY_SCHEDULE idea_ks;
1267 #ifndef OPENSSL_NO_SEED
1268 SEED_KEY_SCHEDULE seed_ks;
1270 #ifndef OPENSSL_NO_BF
1273 #ifndef OPENSSL_NO_CAST
1276 static const unsigned char key16[16] = {
1277 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1278 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1280 static const unsigned char key24[24] = {
1281 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1282 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1283 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1285 static const unsigned char key32[32] = {
1286 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1287 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1288 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1289 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1291 #ifndef OPENSSL_NO_CAMELLIA
1292 static const unsigned char ckey24[24] = {
1293 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1294 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1295 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1297 static const unsigned char ckey32[32] = {
1298 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1299 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1300 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1301 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1303 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1305 #ifndef OPENSSL_NO_DES
1306 static DES_cblock key = {
1307 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1309 static DES_cblock key2 = {
1310 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1312 static DES_cblock key3 = {
1313 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1316 #ifndef OPENSSL_NO_RSA
1317 static const unsigned int rsa_bits[RSA_NUM] = {
1318 512, 1024, 2048, 3072, 4096, 7680, 15360
1320 static const unsigned char *rsa_data[RSA_NUM] = {
1321 test512, test1024, test2048, test3072, test4096, test7680, test15360
1323 static const int rsa_data_length[RSA_NUM] = {
1324 sizeof(test512), sizeof(test1024),
1325 sizeof(test2048), sizeof(test3072),
1326 sizeof(test4096), sizeof(test7680),
1329 int rsa_doit[RSA_NUM] = { 0 };
1330 int primes = RSA_DEFAULT_PRIME_NUM;
1332 #ifndef OPENSSL_NO_DSA
1333 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1334 int dsa_doit[DSA_NUM] = { 0 };
1336 #ifndef OPENSSL_NO_EC
1338 * We only test over the following curves as they are representative, To
1339 * add tests over more curves, simply add the curve NID and curve name to
1340 * the following arrays and increase the EC_NUM value accordingly.
1342 static const unsigned int test_curves[EC_NUM] = {
1344 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1345 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1347 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1348 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1349 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1354 static const char *test_curves_names[EC_NUM] = {
1356 "secp160r1", "nistp192", "nistp224",
1357 "nistp256", "nistp384", "nistp521",
1359 "nistk163", "nistk233", "nistk283",
1360 "nistk409", "nistk571", "nistb163",
1361 "nistb233", "nistb283", "nistb409",
1366 static const int test_curves_bits[EC_NUM] = {
1372 571, 253 /* X25519 */
1375 int ecdsa_doit[EC_NUM] = { 0 };
1376 int ecdh_doit[EC_NUM] = { 0 };
1377 #endif /* ndef OPENSSL_NO_EC */
1379 prog = opt_init(argc, argv, speed_options);
1380 while ((o = opt_next()) != OPT_EOF) {
1385 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1388 opt_help(speed_options);
1396 evp_cipher = EVP_get_cipherbyname(opt_arg());
1397 if (evp_cipher == NULL)
1398 evp_md = EVP_get_digestbyname(opt_arg());
1399 if (evp_cipher == NULL && evp_md == NULL) {
1401 "%s: %s is an unknown cipher or digest\n",
1412 * In a forked execution, an engine might need to be
1413 * initialised by each child process, not by the parent.
1414 * So store the name here and run setup_engine() later on.
1416 engine_id = opt_arg();
1420 multi = atoi(opt_arg());
1424 #ifndef OPENSSL_NO_ASYNC
1425 async_jobs = atoi(opt_arg());
1426 if (!ASYNC_is_capable()) {
1428 "%s: async_jobs specified but async not supported\n",
1432 if (async_jobs > 99999) {
1434 "%s: too many async_jobs\n",
1441 if (!opt_int(opt_arg(), &misalign))
1443 if (misalign > MISALIGN) {
1445 "%s: Maximum offset is %d\n", prog, MISALIGN);
1454 #ifdef OPENSSL_NO_MULTIBLOCK
1456 "%s: -mb specified but multi-block support is disabled\n",
1466 if (!opt_int(opt_arg(), &primes))
1471 argc = opt_num_rest();
1474 /* Remaining arguments are algorithms. */
1475 for (; *argv; argv++) {
1476 if (found(*argv, doit_choices, &i)) {
1480 #ifndef OPENSSL_NO_DES
1481 if (strcmp(*argv, "des") == 0) {
1482 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1486 if (strcmp(*argv, "sha") == 0) {
1487 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1490 #ifndef OPENSSL_NO_RSA
1491 if (strcmp(*argv, "openssl") == 0)
1493 if (strcmp(*argv, "rsa") == 0) {
1494 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1495 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1496 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1497 rsa_doit[R_RSA_15360] = 1;
1500 if (found(*argv, rsa_choices, &i)) {
1505 #ifndef OPENSSL_NO_DSA
1506 if (strcmp(*argv, "dsa") == 0) {
1507 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1508 dsa_doit[R_DSA_2048] = 1;
1511 if (found(*argv, dsa_choices, &i)) {
1516 if (strcmp(*argv, "aes") == 0) {
1517 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1520 #ifndef OPENSSL_NO_CAMELLIA
1521 if (strcmp(*argv, "camellia") == 0) {
1522 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1526 #ifndef OPENSSL_NO_EC
1527 if (strcmp(*argv, "ecdsa") == 0) {
1528 for (i = 0; i < EC_NUM; i++)
1532 if (found(*argv, ecdsa_choices, &i)) {
1536 if (strcmp(*argv, "ecdh") == 0) {
1537 for (i = 0; i < EC_NUM; i++)
1541 if (found(*argv, ecdh_choices, &i)) {
1546 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1550 /* Initialize the job pool if async mode is enabled */
1551 if (async_jobs > 0) {
1552 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1554 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1559 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1561 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1562 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1564 for (i = 0; i < loopargs_len; i++) {
1565 if (async_jobs > 0) {
1566 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1567 if (loopargs[i].wait_ctx == NULL) {
1568 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1573 loopargs[i].buf_malloc =
1574 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1575 loopargs[i].buf2_malloc =
1576 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1577 /* Align the start of buffers on a 64 byte boundary */
1578 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1579 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1580 #ifndef OPENSSL_NO_EC
1581 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1582 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1587 if (multi && do_multi(multi))
1591 /* Initialize the engine after the fork */
1592 e = setup_engine(engine_id, 0);
1594 /* No parameters; turn on everything. */
1595 if ((argc == 0) && !doit[D_EVP]) {
1596 for (i = 0; i < ALGOR_NUM; i++)
1599 #ifndef OPENSSL_NO_RSA
1600 for (i = 0; i < RSA_NUM; i++)
1603 #ifndef OPENSSL_NO_DSA
1604 for (i = 0; i < DSA_NUM; i++)
1607 #ifndef OPENSSL_NO_EC
1608 for (i = 0; i < EC_NUM; i++)
1610 for (i = 0; i < EC_NUM; i++)
1614 for (i = 0; i < ALGOR_NUM; i++)
1618 if (usertime == 0 && !mr)
1620 "You have chosen to measure elapsed time "
1621 "instead of user CPU time.\n");
1623 #ifndef OPENSSL_NO_RSA
1624 for (i = 0; i < loopargs_len; i++) {
1625 if (primes > RSA_DEFAULT_PRIME_NUM) {
1626 /* for multi-prime RSA, skip this */
1629 for (k = 0; k < RSA_NUM; k++) {
1630 const unsigned char *p;
1633 loopargs[i].rsa_key[k] =
1634 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1635 if (loopargs[i].rsa_key[k] == NULL) {
1637 "internal error loading RSA key number %d\n", k);
1643 #ifndef OPENSSL_NO_DSA
1644 for (i = 0; i < loopargs_len; i++) {
1645 loopargs[i].dsa_key[0] = get_dsa(512);
1646 loopargs[i].dsa_key[1] = get_dsa(1024);
1647 loopargs[i].dsa_key[2] = get_dsa(2048);
1650 #ifndef OPENSSL_NO_DES
1651 DES_set_key_unchecked(&key, &sch);
1652 DES_set_key_unchecked(&key2, &sch2);
1653 DES_set_key_unchecked(&key3, &sch3);
1655 AES_set_encrypt_key(key16, 128, &aes_ks1);
1656 AES_set_encrypt_key(key24, 192, &aes_ks2);
1657 AES_set_encrypt_key(key32, 256, &aes_ks3);
1658 #ifndef OPENSSL_NO_CAMELLIA
1659 Camellia_set_key(key16, 128, &camellia_ks1);
1660 Camellia_set_key(ckey24, 192, &camellia_ks2);
1661 Camellia_set_key(ckey32, 256, &camellia_ks3);
1663 #ifndef OPENSSL_NO_IDEA
1664 IDEA_set_encrypt_key(key16, &idea_ks);
1666 #ifndef OPENSSL_NO_SEED
1667 SEED_set_key(key16, &seed_ks);
1669 #ifndef OPENSSL_NO_RC4
1670 RC4_set_key(&rc4_ks, 16, key16);
1672 #ifndef OPENSSL_NO_RC2
1673 RC2_set_key(&rc2_ks, 16, key16, 128);
1675 #ifndef OPENSSL_NO_RC5
1676 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1678 #ifndef OPENSSL_NO_BF
1679 BF_set_key(&bf_ks, 16, key16);
1681 #ifndef OPENSSL_NO_CAST
1682 CAST_set_key(&cast_ks, 16, key16);
1685 # ifndef OPENSSL_NO_DES
1686 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1692 for (it = count; it; it--)
1693 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1694 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1698 c[D_MD2][0] = count / 10;
1699 c[D_MDC2][0] = count / 10;
1700 c[D_MD4][0] = count;
1701 c[D_MD5][0] = count;
1702 c[D_HMAC][0] = count;
1703 c[D_SHA1][0] = count;
1704 c[D_RMD160][0] = count;
1705 c[D_RC4][0] = count * 5;
1706 c[D_CBC_DES][0] = count;
1707 c[D_EDE3_DES][0] = count / 3;
1708 c[D_CBC_IDEA][0] = count;
1709 c[D_CBC_SEED][0] = count;
1710 c[D_CBC_RC2][0] = count;
1711 c[D_CBC_RC5][0] = count;
1712 c[D_CBC_BF][0] = count;
1713 c[D_CBC_CAST][0] = count;
1714 c[D_CBC_128_AES][0] = count;
1715 c[D_CBC_192_AES][0] = count;
1716 c[D_CBC_256_AES][0] = count;
1717 c[D_CBC_128_CML][0] = count;
1718 c[D_CBC_192_CML][0] = count;
1719 c[D_CBC_256_CML][0] = count;
1720 c[D_SHA256][0] = count;
1721 c[D_SHA512][0] = count;
1722 c[D_WHIRLPOOL][0] = count;
1723 c[D_IGE_128_AES][0] = count;
1724 c[D_IGE_192_AES][0] = count;
1725 c[D_IGE_256_AES][0] = count;
1726 c[D_GHASH][0] = count;
1727 c[D_RAND][0] = count;
1729 for (i = 1; i < SIZE_NUM; i++) {
1732 l0 = (long)lengths[0];
1733 l1 = (long)lengths[i];
1735 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1736 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1737 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1738 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1739 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1740 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1741 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1742 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1743 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1744 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1745 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1746 c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
1748 l0 = (long)lengths[i - 1];
1750 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1751 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1752 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1753 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1754 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1755 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1756 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1757 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1758 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1759 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1760 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1761 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1762 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1763 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1764 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1765 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1766 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1767 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1770 # ifndef OPENSSL_NO_RSA
1771 rsa_c[R_RSA_512][0] = count / 2000;
1772 rsa_c[R_RSA_512][1] = count / 400;
1773 for (i = 1; i < RSA_NUM; i++) {
1774 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1775 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1776 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1779 if (rsa_c[i][0] == 0) {
1780 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1787 # ifndef OPENSSL_NO_DSA
1788 dsa_c[R_DSA_512][0] = count / 1000;
1789 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1790 for (i = 1; i < DSA_NUM; i++) {
1791 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1792 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1793 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1796 if (dsa_c[i][0] == 0) {
1797 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1804 # ifndef OPENSSL_NO_EC
1805 ecdsa_c[R_EC_P160][0] = count / 1000;
1806 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1807 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1808 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1809 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1810 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1813 if (ecdsa_c[i][0] == 0) {
1819 ecdsa_c[R_EC_K163][0] = count / 1000;
1820 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1821 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1822 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1823 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1824 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1827 if (ecdsa_c[i][0] == 0) {
1833 ecdsa_c[R_EC_B163][0] = count / 1000;
1834 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1835 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1836 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1837 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1838 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1841 if (ecdsa_c[i][0] == 0) {
1848 ecdh_c[R_EC_P160][0] = count / 1000;
1849 for (i = R_EC_P192; i <= R_EC_P521; 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_K163][0] = count / 1000;
1860 for (i = R_EC_K233; i <= R_EC_K571; 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) {
1870 ecdh_c[R_EC_B163][0] = count / 1000;
1871 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1872 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1873 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1876 if (ecdh_c[i][0] == 0) {
1884 /* not worth fixing */
1885 # error "You cannot disable DES on systems without SIGALRM."
1886 # endif /* OPENSSL_NO_DES */
1889 signal(SIGALRM, sig_done);
1891 #endif /* SIGALRM */
1893 #ifndef OPENSSL_NO_MD2
1895 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1896 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1898 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1900 print_result(D_MD2, testnum, count, d);
1904 #ifndef OPENSSL_NO_MDC2
1906 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1907 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1909 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1911 print_result(D_MDC2, testnum, count, d);
1916 #ifndef OPENSSL_NO_MD4
1918 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1919 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1921 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1923 print_result(D_MD4, testnum, count, d);
1928 #ifndef OPENSSL_NO_MD5
1930 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1931 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1933 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1935 print_result(D_MD5, testnum, count, d);
1940 static const char hmac_key[] = "This is a key...";
1941 int len = strlen(hmac_key);
1943 for (i = 0; i < loopargs_len; i++) {
1944 loopargs[i].hctx = HMAC_CTX_new();
1945 if (loopargs[i].hctx == NULL) {
1946 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1950 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1952 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1953 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1955 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1957 print_result(D_HMAC, testnum, count, d);
1959 for (i = 0; i < loopargs_len; i++) {
1960 HMAC_CTX_free(loopargs[i].hctx);
1965 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1966 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1968 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1970 print_result(D_SHA1, testnum, count, d);
1973 if (doit[D_SHA256]) {
1974 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1975 print_message(names[D_SHA256], c[D_SHA256][testnum],
1978 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1980 print_result(D_SHA256, testnum, count, d);
1983 if (doit[D_SHA512]) {
1984 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1985 print_message(names[D_SHA512], c[D_SHA512][testnum],
1988 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1990 print_result(D_SHA512, testnum, count, d);
1993 #ifndef OPENSSL_NO_WHIRLPOOL
1994 if (doit[D_WHIRLPOOL]) {
1995 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1996 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1999 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
2001 print_result(D_WHIRLPOOL, testnum, count, d);
2006 #ifndef OPENSSL_NO_RMD160
2007 if (doit[D_RMD160]) {
2008 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2009 print_message(names[D_RMD160], c[D_RMD160][testnum],
2012 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
2014 print_result(D_RMD160, testnum, count, d);
2018 #ifndef OPENSSL_NO_RC4
2020 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2021 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
2023 count = run_benchmark(async_jobs, RC4_loop, loopargs);
2025 print_result(D_RC4, testnum, count, d);
2029 #ifndef OPENSSL_NO_DES
2030 if (doit[D_CBC_DES]) {
2031 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2032 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
2035 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
2037 print_result(D_CBC_DES, testnum, count, d);
2041 if (doit[D_EDE3_DES]) {
2042 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2043 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
2047 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2049 print_result(D_EDE3_DES, testnum, count, d);
2054 if (doit[D_CBC_128_AES]) {
2055 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2056 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2060 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2062 print_result(D_CBC_128_AES, testnum, count, d);
2065 if (doit[D_CBC_192_AES]) {
2066 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2067 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2071 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2073 print_result(D_CBC_192_AES, testnum, count, d);
2076 if (doit[D_CBC_256_AES]) {
2077 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2078 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2082 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2084 print_result(D_CBC_256_AES, testnum, count, d);
2088 if (doit[D_IGE_128_AES]) {
2089 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2090 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2094 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2096 print_result(D_IGE_128_AES, testnum, count, d);
2099 if (doit[D_IGE_192_AES]) {
2100 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2101 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2105 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2107 print_result(D_IGE_192_AES, testnum, count, d);
2110 if (doit[D_IGE_256_AES]) {
2111 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2112 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2116 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2118 print_result(D_IGE_256_AES, testnum, count, d);
2121 if (doit[D_GHASH]) {
2122 for (i = 0; i < loopargs_len; i++) {
2123 loopargs[i].gcm_ctx =
2124 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2125 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2126 (unsigned char *)"0123456789ab", 12);
2129 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2130 print_message(names[D_GHASH], c[D_GHASH][testnum],
2133 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2135 print_result(D_GHASH, testnum, count, d);
2137 for (i = 0; i < loopargs_len; i++)
2138 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2140 #ifndef OPENSSL_NO_CAMELLIA
2141 if (doit[D_CBC_128_CML]) {
2142 if (async_jobs > 0) {
2143 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2144 names[D_CBC_128_CML]);
2145 doit[D_CBC_128_CML] = 0;
2147 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2148 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2151 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2152 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2153 (size_t)lengths[testnum], &camellia_ks1,
2154 iv, CAMELLIA_ENCRYPT);
2156 print_result(D_CBC_128_CML, testnum, count, d);
2159 if (doit[D_CBC_192_CML]) {
2160 if (async_jobs > 0) {
2161 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2162 names[D_CBC_192_CML]);
2163 doit[D_CBC_192_CML] = 0;
2165 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2166 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2168 if (async_jobs > 0) {
2169 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2173 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2174 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2175 (size_t)lengths[testnum], &camellia_ks2,
2176 iv, CAMELLIA_ENCRYPT);
2178 print_result(D_CBC_192_CML, testnum, count, d);
2181 if (doit[D_CBC_256_CML]) {
2182 if (async_jobs > 0) {
2183 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2184 names[D_CBC_256_CML]);
2185 doit[D_CBC_256_CML] = 0;
2187 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2188 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2191 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2192 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2193 (size_t)lengths[testnum], &camellia_ks3,
2194 iv, CAMELLIA_ENCRYPT);
2196 print_result(D_CBC_256_CML, testnum, count, d);
2200 #ifndef OPENSSL_NO_IDEA
2201 if (doit[D_CBC_IDEA]) {
2202 if (async_jobs > 0) {
2203 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2205 doit[D_CBC_IDEA] = 0;
2207 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2208 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2211 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2212 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2213 (size_t)lengths[testnum], &idea_ks,
2216 print_result(D_CBC_IDEA, testnum, count, d);
2220 #ifndef OPENSSL_NO_SEED
2221 if (doit[D_CBC_SEED]) {
2222 if (async_jobs > 0) {
2223 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2225 doit[D_CBC_SEED] = 0;
2227 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2228 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2231 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2232 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2233 (size_t)lengths[testnum], &seed_ks, iv, 1);
2235 print_result(D_CBC_SEED, testnum, count, d);
2239 #ifndef OPENSSL_NO_RC2
2240 if (doit[D_CBC_RC2]) {
2241 if (async_jobs > 0) {
2242 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2244 doit[D_CBC_RC2] = 0;
2246 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2247 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2249 if (async_jobs > 0) {
2250 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2254 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2255 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2256 (size_t)lengths[testnum], &rc2_ks,
2259 print_result(D_CBC_RC2, testnum, count, d);
2263 #ifndef OPENSSL_NO_RC5
2264 if (doit[D_CBC_RC5]) {
2265 if (async_jobs > 0) {
2266 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2268 doit[D_CBC_RC5] = 0;
2270 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2271 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2273 if (async_jobs > 0) {
2274 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2278 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2279 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2280 (size_t)lengths[testnum], &rc5_ks,
2283 print_result(D_CBC_RC5, testnum, count, d);
2287 #ifndef OPENSSL_NO_BF
2288 if (doit[D_CBC_BF]) {
2289 if (async_jobs > 0) {
2290 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2294 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2295 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2298 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2299 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2300 (size_t)lengths[testnum], &bf_ks,
2303 print_result(D_CBC_BF, testnum, count, d);
2307 #ifndef OPENSSL_NO_CAST
2308 if (doit[D_CBC_CAST]) {
2309 if (async_jobs > 0) {
2310 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2312 doit[D_CBC_CAST] = 0;
2314 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2315 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2318 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2319 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2320 (size_t)lengths[testnum], &cast_ks,
2323 print_result(D_CBC_CAST, testnum, count, d);
2328 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2329 print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum]);
2331 count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
2333 print_result(D_RAND, testnum, count, d);
2338 if (multiblock && evp_cipher) {
2340 (EVP_CIPHER_flags(evp_cipher) &
2341 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2342 BIO_printf(bio_err, "%s is not multi-block capable\n",
2343 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2346 if (async_jobs > 0) {
2347 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2350 multiblock_speed(evp_cipher);
2354 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2357 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2359 * -O3 -fschedule-insns messes up an optimization here!
2360 * names[D_EVP] somehow becomes NULL
2362 print_message(names[D_EVP], save_count, lengths[testnum]);
2364 for (k = 0; k < loopargs_len; k++) {
2365 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2367 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2370 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2372 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2374 switch (EVP_CIPHER_mode(evp_cipher)) {
2375 case EVP_CIPH_CCM_MODE:
2376 loopfunc = EVP_Update_loop_ccm;
2379 loopfunc = EVP_Update_loop;
2383 count = run_benchmark(async_jobs, loopfunc, loopargs);
2385 for (k = 0; k < loopargs_len; k++) {
2386 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2390 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2391 print_message(names[D_EVP], save_count, lengths[testnum]);
2393 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2396 print_result(D_EVP, testnum, count, d);
2400 for (i = 0; i < loopargs_len; i++)
2401 RAND_bytes(loopargs[i].buf, 36);
2403 #ifndef OPENSSL_NO_RSA
2404 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2406 if (!rsa_doit[testnum])
2408 for (i = 0; i < loopargs_len; i++) {
2410 /* we haven't set keys yet, generate multi-prime RSA keys */
2411 BIGNUM *bn = BN_new();
2415 if (!BN_set_word(bn, RSA_F4)) {
2420 BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
2421 rsa_choices[testnum].name);
2423 loopargs[i].rsa_key[testnum] = RSA_new();
2424 if (loopargs[i].rsa_key[testnum] == NULL) {
2429 if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
2431 primes, bn, NULL)) {
2437 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2438 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2444 "RSA sign failure. No RSA sign will be done.\n");
2445 ERR_print_errors(bio_err);
2448 pkey_print_message("private", "rsa",
2449 rsa_c[testnum][0], rsa_bits[testnum],
2451 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2453 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2456 mr ? "+R1:%ld:%d:%.2f\n"
2457 : "%ld %d bit private RSA's in %.2fs\n",
2458 count, rsa_bits[testnum], d);
2459 rsa_results[testnum][0] = (double)count / d;
2463 for (i = 0; i < loopargs_len; i++) {
2464 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2465 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2471 "RSA verify failure. No RSA verify will be done.\n");
2472 ERR_print_errors(bio_err);
2473 rsa_doit[testnum] = 0;
2475 pkey_print_message("public", "rsa",
2476 rsa_c[testnum][1], rsa_bits[testnum],
2479 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2482 mr ? "+R2:%ld:%d:%.2f\n"
2483 : "%ld %d bit public RSA's in %.2fs\n",
2484 count, rsa_bits[testnum], d);
2485 rsa_results[testnum][1] = (double)count / d;
2488 if (rsa_count <= 1) {
2489 /* if longer than 10s, don't do any more */
2490 for (testnum++; testnum < RSA_NUM; testnum++)
2491 rsa_doit[testnum] = 0;
2494 #endif /* OPENSSL_NO_RSA */
2496 for (i = 0; i < loopargs_len; i++)
2497 RAND_bytes(loopargs[i].buf, 36);
2499 #ifndef OPENSSL_NO_DSA
2500 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2502 if (!dsa_doit[testnum])
2505 /* DSA_generate_key(dsa_key[testnum]); */
2506 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2507 for (i = 0; i < loopargs_len; i++) {
2508 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2509 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2515 "DSA sign failure. No DSA sign will be done.\n");
2516 ERR_print_errors(bio_err);
2519 pkey_print_message("sign", "dsa",
2520 dsa_c[testnum][0], dsa_bits[testnum],
2523 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2526 mr ? "+R3:%ld:%d:%.2f\n"
2527 : "%ld %d bit DSA signs in %.2fs\n",
2528 count, dsa_bits[testnum], d);
2529 dsa_results[testnum][0] = (double)count / d;
2533 for (i = 0; i < loopargs_len; i++) {
2534 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2535 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2541 "DSA verify failure. No DSA verify will be done.\n");
2542 ERR_print_errors(bio_err);
2543 dsa_doit[testnum] = 0;
2545 pkey_print_message("verify", "dsa",
2546 dsa_c[testnum][1], dsa_bits[testnum],
2549 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2552 mr ? "+R4:%ld:%d:%.2f\n"
2553 : "%ld %d bit DSA verify in %.2fs\n",
2554 count, dsa_bits[testnum], d);
2555 dsa_results[testnum][1] = (double)count / d;
2558 if (rsa_count <= 1) {
2559 /* if longer than 10s, don't do any more */
2560 for (testnum++; testnum < DSA_NUM; testnum++)
2561 dsa_doit[testnum] = 0;
2564 #endif /* OPENSSL_NO_DSA */
2566 #ifndef OPENSSL_NO_EC
2567 for (testnum = 0; testnum < EC_NUM; testnum++) {
2570 if (!ecdsa_doit[testnum])
2571 continue; /* Ignore Curve */
2572 for (i = 0; i < loopargs_len; i++) {
2573 loopargs[i].ecdsa[testnum] =
2574 EC_KEY_new_by_curve_name(test_curves[testnum]);
2575 if (loopargs[i].ecdsa[testnum] == NULL) {
2581 BIO_printf(bio_err, "ECDSA failure.\n");
2582 ERR_print_errors(bio_err);
2585 for (i = 0; i < loopargs_len; i++) {
2586 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2587 /* Perform ECDSA signature test */
2588 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2589 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2590 &loopargs[i].siglen,
2591 loopargs[i].ecdsa[testnum]);
2597 "ECDSA sign failure. No ECDSA sign will be done.\n");
2598 ERR_print_errors(bio_err);
2601 pkey_print_message("sign", "ecdsa",
2602 ecdsa_c[testnum][0],
2603 test_curves_bits[testnum], ECDSA_SECONDS);
2605 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2609 mr ? "+R5:%ld:%d:%.2f\n" :
2610 "%ld %d bit ECDSA signs in %.2fs \n",
2611 count, test_curves_bits[testnum], d);
2612 ecdsa_results[testnum][0] = (double)count / d;
2616 /* Perform ECDSA verification test */
2617 for (i = 0; i < loopargs_len; i++) {
2618 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2620 loopargs[i].ecdsa[testnum]);
2626 "ECDSA verify failure. No ECDSA verify will be done.\n");
2627 ERR_print_errors(bio_err);
2628 ecdsa_doit[testnum] = 0;
2630 pkey_print_message("verify", "ecdsa",
2631 ecdsa_c[testnum][1],
2632 test_curves_bits[testnum], ECDSA_SECONDS);
2634 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2637 mr ? "+R6:%ld:%d:%.2f\n"
2638 : "%ld %d bit ECDSA verify in %.2fs\n",
2639 count, test_curves_bits[testnum], d);
2640 ecdsa_results[testnum][1] = (double)count / d;
2643 if (rsa_count <= 1) {
2644 /* if longer than 10s, don't do any more */
2645 for (testnum++; testnum < EC_NUM; testnum++)
2646 ecdsa_doit[testnum] = 0;
2651 for (testnum = 0; testnum < EC_NUM; testnum++) {
2652 int ecdh_checks = 1;
2654 if (!ecdh_doit[testnum])
2657 for (i = 0; i < loopargs_len; i++) {
2658 EVP_PKEY_CTX *kctx = NULL;
2659 EVP_PKEY_CTX *test_ctx = NULL;
2660 EVP_PKEY_CTX *ctx = NULL;
2661 EVP_PKEY *key_A = NULL;
2662 EVP_PKEY *key_B = NULL;
2666 /* Ensure that the error queue is empty */
2667 if (ERR_peek_error()) {
2669 "WARNING: the error queue contains previous unhandled errors.\n");
2670 ERR_print_errors(bio_err);
2673 /* Let's try to create a ctx directly from the NID: this works for
2674 * curves like Curve25519 that are not implemented through the low
2675 * level EC interface.
2676 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2677 * then we set the curve by NID before deriving the actual keygen
2678 * ctx for that specific curve. */
2679 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2681 EVP_PKEY_CTX *pctx = NULL;
2682 EVP_PKEY *params = NULL;
2684 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2685 * "int_ctx_new:unsupported algorithm" error was added to the
2687 * We remove it from the error queue as we are handling it. */
2688 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2689 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2690 /* check that the error origin matches */
2691 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2692 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2693 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2694 ERR_get_error(); /* pop error from queue */
2695 if (ERR_peek_error()) {
2697 "Unhandled error in the error queue during ECDH init.\n");
2698 ERR_print_errors(bio_err);
2703 if ( /* Create the context for parameter generation */
2704 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2705 /* Initialise the parameter generation */
2706 !EVP_PKEY_paramgen_init(pctx) ||
2707 /* Set the curve by NID */
2708 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2711 /* Create the parameter object params */
2712 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2714 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2715 ERR_print_errors(bio_err);
2719 /* Create the context for the key generation */
2720 kctx = EVP_PKEY_CTX_new(params, NULL);
2722 EVP_PKEY_free(params);
2724 EVP_PKEY_CTX_free(pctx);
2727 if (kctx == NULL || /* keygen ctx is not null */
2728 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2730 BIO_printf(bio_err, "ECDH keygen failure.\n");
2731 ERR_print_errors(bio_err);
2736 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2737 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2738 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2739 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2740 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2741 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2742 outlen == 0 || /* ensure outlen is a valid size */
2743 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2745 BIO_printf(bio_err, "ECDH key generation failure.\n");
2746 ERR_print_errors(bio_err);
2751 /* Here we perform a test run, comparing the output of a*B and b*A;
2752 * we try this here and assume that further EVP_PKEY_derive calls
2753 * never fail, so we can skip checks in the actually benchmarked
2754 * code, for maximum performance. */
2755 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2756 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2757 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2758 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2759 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2760 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2761 test_outlen != outlen /* compare output length */ ) {
2763 BIO_printf(bio_err, "ECDH computation failure.\n");
2764 ERR_print_errors(bio_err);
2769 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2770 if (CRYPTO_memcmp(loopargs[i].secret_a,
2771 loopargs[i].secret_b, outlen)) {
2773 BIO_printf(bio_err, "ECDH computations don't match.\n");
2774 ERR_print_errors(bio_err);
2779 loopargs[i].ecdh_ctx[testnum] = ctx;
2780 loopargs[i].outlen[testnum] = outlen;
2782 EVP_PKEY_CTX_free(kctx);
2784 EVP_PKEY_CTX_free(test_ctx);
2787 if (ecdh_checks != 0) {
2788 pkey_print_message("", "ecdh",
2790 test_curves_bits[testnum], ECDH_SECONDS);
2793 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2796 mr ? "+R7:%ld:%d:%.2f\n" :
2797 "%ld %d-bit ECDH ops in %.2fs\n", count,
2798 test_curves_bits[testnum], d);
2799 ecdh_results[testnum][0] = (double)count / d;
2803 if (rsa_count <= 1) {
2804 /* if longer than 10s, don't do any more */
2805 for (testnum++; testnum < EC_NUM; testnum++)
2806 ecdh_doit[testnum] = 0;
2809 #endif /* OPENSSL_NO_EC */
2814 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2815 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2817 printf("%s ", BN_options());
2818 #ifndef OPENSSL_NO_MD2
2819 printf("%s ", MD2_options());
2821 #ifndef OPENSSL_NO_RC4
2822 printf("%s ", RC4_options());
2824 #ifndef OPENSSL_NO_DES
2825 printf("%s ", DES_options());
2827 printf("%s ", AES_options());
2828 #ifndef OPENSSL_NO_IDEA
2829 printf("%s ", IDEA_options());
2831 #ifndef OPENSSL_NO_BF
2832 printf("%s ", BF_options());
2834 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2842 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2845 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2846 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2850 for (k = 0; k < ALGOR_NUM; k++) {
2854 printf("+F:%d:%s", k, names[k]);
2856 printf("%-13s", names[k]);
2857 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2858 if (results[k][testnum] > 10000 && !mr)
2859 printf(" %11.2fk", results[k][testnum] / 1e3);
2861 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2865 #ifndef OPENSSL_NO_RSA
2867 for (k = 0; k < RSA_NUM; k++) {
2870 if (testnum && !mr) {
2871 printf("%18ssign verify sign/s verify/s\n", " ");
2875 printf("+F2:%u:%u:%f:%f\n",
2876 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2878 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2879 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2880 rsa_results[k][0], rsa_results[k][1]);
2883 #ifndef OPENSSL_NO_DSA
2885 for (k = 0; k < DSA_NUM; k++) {
2888 if (testnum && !mr) {
2889 printf("%18ssign verify sign/s verify/s\n", " ");
2893 printf("+F3:%u:%u:%f:%f\n",
2894 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2896 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2897 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2898 dsa_results[k][0], dsa_results[k][1]);
2901 #ifndef OPENSSL_NO_EC
2903 for (k = 0; k < EC_NUM; k++) {
2906 if (testnum && !mr) {
2907 printf("%30ssign verify sign/s verify/s\n", " ");
2912 printf("+F4:%u:%u:%f:%f\n",
2913 k, test_curves_bits[k],
2914 ecdsa_results[k][0], ecdsa_results[k][1]);
2916 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2917 test_curves_bits[k],
2918 test_curves_names[k],
2919 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2920 ecdsa_results[k][0], ecdsa_results[k][1]);
2924 for (k = 0; k < EC_NUM; k++) {
2927 if (testnum && !mr) {
2928 printf("%30sop op/s\n", " ");
2932 printf("+F5:%u:%u:%f:%f\n",
2933 k, test_curves_bits[k],
2934 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2937 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2938 test_curves_bits[k],
2939 test_curves_names[k],
2940 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2947 ERR_print_errors(bio_err);
2948 for (i = 0; i < loopargs_len; i++) {
2949 OPENSSL_free(loopargs[i].buf_malloc);
2950 OPENSSL_free(loopargs[i].buf2_malloc);
2952 #ifndef OPENSSL_NO_RSA
2953 for (k = 0; k < RSA_NUM; k++)
2954 RSA_free(loopargs[i].rsa_key[k]);
2956 #ifndef OPENSSL_NO_DSA
2957 for (k = 0; k < DSA_NUM; k++)
2958 DSA_free(loopargs[i].dsa_key[k]);
2960 #ifndef OPENSSL_NO_EC
2961 for (k = 0; k < EC_NUM; k++) {
2962 EC_KEY_free(loopargs[i].ecdsa[k]);
2963 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2965 OPENSSL_free(loopargs[i].secret_a);
2966 OPENSSL_free(loopargs[i].secret_b);
2970 if (async_jobs > 0) {
2971 for (i = 0; i < loopargs_len; i++)
2972 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2976 ASYNC_cleanup_thread();
2978 OPENSSL_free(loopargs);
2983 static void print_message(const char *s, long num, int length)
2987 mr ? "+DT:%s:%d:%d\n"
2988 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2989 (void)BIO_flush(bio_err);
2993 mr ? "+DN:%s:%ld:%d\n"
2994 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2995 (void)BIO_flush(bio_err);
2999 static void pkey_print_message(const char *str, const char *str2, long num,
3004 mr ? "+DTP:%d:%s:%s:%d\n"
3005 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
3006 (void)BIO_flush(bio_err);
3010 mr ? "+DNP:%ld:%d:%s:%s\n"
3011 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
3012 (void)BIO_flush(bio_err);
3016 static void print_result(int alg, int run_no, int count, double time_used)
3019 BIO_puts(bio_err, "EVP error!\n");
3023 mr ? "+R:%d:%s:%f\n"
3024 : "%d %s's in %.2fs\n", count, names[alg], time_used);
3025 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
3029 static char *sstrsep(char **string, const char *delim)
3032 char *token = *string;
3037 memset(isdelim, 0, sizeof isdelim);
3041 isdelim[(unsigned char)(*delim)] = 1;
3045 while (!isdelim[(unsigned char)(**string)]) {
3057 static int do_multi(int multi)
3062 static char sep[] = ":";
3064 fds = malloc(sizeof(*fds) * multi);
3065 for (n = 0; n < multi; ++n) {
3066 if (pipe(fd) == -1) {
3067 BIO_printf(bio_err, "pipe failure\n");
3071 (void)BIO_flush(bio_err);
3078 if (dup(fd[1]) == -1) {
3079 BIO_printf(bio_err, "dup failed\n");
3088 printf("Forked child %d\n", n);
3091 /* for now, assume the pipe is long enough to take all the output */
3092 for (n = 0; n < multi; ++n) {
3097 f = fdopen(fds[n], "r");
3098 while (fgets(buf, sizeof buf, f)) {
3099 p = strchr(buf, '\n');
3102 if (buf[0] != '+') {
3104 "Don't understand line '%s' from child %d\n", buf,
3108 printf("Got: %s from %d\n", buf, n);
3109 if (strncmp(buf, "+F:", 3) == 0) {
3114 alg = atoi(sstrsep(&p, sep));
3116 for (j = 0; j < SIZE_NUM; ++j)
3117 results[alg][j] += atof(sstrsep(&p, sep));
3118 } else if (strncmp(buf, "+F2:", 4) == 0) {
3123 k = atoi(sstrsep(&p, sep));
3126 d = atof(sstrsep(&p, sep));
3127 rsa_results[k][0] += d;
3129 d = atof(sstrsep(&p, sep));
3130 rsa_results[k][1] += d;
3132 # ifndef OPENSSL_NO_DSA
3133 else if (strncmp(buf, "+F3:", 4) == 0) {
3138 k = atoi(sstrsep(&p, sep));
3141 d = atof(sstrsep(&p, sep));
3142 dsa_results[k][0] += d;
3144 d = atof(sstrsep(&p, sep));
3145 dsa_results[k][1] += d;
3148 # ifndef OPENSSL_NO_EC
3149 else if (strncmp(buf, "+F4:", 4) == 0) {
3154 k = atoi(sstrsep(&p, sep));
3157 d = atof(sstrsep(&p, sep));
3158 ecdsa_results[k][0] += d;
3160 d = atof(sstrsep(&p, sep));
3161 ecdsa_results[k][1] += d;
3162 } else if (strncmp(buf, "+F5:", 4) == 0) {
3167 k = atoi(sstrsep(&p, sep));
3170 d = atof(sstrsep(&p, sep));
3171 ecdh_results[k][0] += d;
3175 else if (strncmp(buf, "+H:", 3) == 0) {
3178 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3189 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3191 static int mblengths[] =
3192 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3193 int j, count, num = OSSL_NELEM(mblengths);
3194 const char *alg_name;
3195 unsigned char *inp, *out, no_key[32], no_iv[16];
3196 EVP_CIPHER_CTX *ctx;
3199 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3200 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3201 ctx = EVP_CIPHER_CTX_new();
3202 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3203 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3204 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3206 for (j = 0; j < num; j++) {
3207 print_message(alg_name, 0, mblengths[j]);
3209 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3210 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3211 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3212 size_t len = mblengths[j];
3215 memset(aad, 0, 8); /* avoid uninitialized values */
3216 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3217 aad[9] = 3; /* version */
3219 aad[11] = 0; /* length */
3221 mb_param.out = NULL;
3224 mb_param.interleave = 8;
3226 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3227 sizeof(mb_param), &mb_param);
3233 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3234 sizeof(mb_param), &mb_param);
3238 RAND_bytes(out, 16);
3240 aad[11] = (unsigned char)(len >> 8);
3241 aad[12] = (unsigned char)(len);
3242 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3243 EVP_AEAD_TLS1_AAD_LEN, aad);
3244 EVP_Cipher(ctx, out, inp, len + pad);
3248 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3249 : "%d %s's in %.2fs\n", count, "evp", d);
3250 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3254 fprintf(stdout, "+H");
3255 for (j = 0; j < num; j++)
3256 fprintf(stdout, ":%d", mblengths[j]);
3257 fprintf(stdout, "\n");
3258 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3259 for (j = 0; j < num; j++)
3260 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3261 fprintf(stdout, "\n");
3264 "The 'numbers' are in 1000s of bytes per second processed.\n");
3265 fprintf(stdout, "type ");
3266 for (j = 0; j < num; j++)
3267 fprintf(stdout, "%7d bytes", mblengths[j]);
3268 fprintf(stdout, "\n");
3269 fprintf(stdout, "%-24s", alg_name);
3271 for (j = 0; j < num; j++) {
3272 if (results[D_EVP][j] > 10000)
3273 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3275 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3277 fprintf(stdout, "\n");
3282 EVP_CIPHER_CTX_free(ctx);