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 PRIME_SECONDS 10
14 #define RSA_SECONDS 10
15 #define DSA_SECONDS 10
16 #define ECDSA_SECONDS 10
17 #define ECDH_SECONDS 10
24 #include <openssl/crypto.h>
25 #include <openssl/rand.h>
26 #include <openssl/err.h>
27 #include <openssl/evp.h>
28 #include <openssl/objects.h>
29 #include <openssl/async.h>
30 #if !defined(OPENSSL_SYS_MSDOS)
31 # include OPENSSL_UNISTD
38 #include <openssl/bn.h>
39 #ifndef OPENSSL_NO_DES
40 # include <openssl/des.h>
42 #include <openssl/aes.h>
43 #ifndef OPENSSL_NO_CAMELLIA
44 # include <openssl/camellia.h>
46 #ifndef OPENSSL_NO_MD2
47 # include <openssl/md2.h>
49 #ifndef OPENSSL_NO_MDC2
50 # include <openssl/mdc2.h>
52 #ifndef OPENSSL_NO_MD4
53 # include <openssl/md4.h>
55 #ifndef OPENSSL_NO_MD5
56 # include <openssl/md5.h>
58 #include <openssl/hmac.h>
59 #include <openssl/sha.h>
60 #ifndef OPENSSL_NO_RMD160
61 # include <openssl/ripemd.h>
63 #ifndef OPENSSL_NO_WHIRLPOOL
64 # include <openssl/whrlpool.h>
66 #ifndef OPENSSL_NO_RC4
67 # include <openssl/rc4.h>
69 #ifndef OPENSSL_NO_RC5
70 # include <openssl/rc5.h>
72 #ifndef OPENSSL_NO_RC2
73 # include <openssl/rc2.h>
75 #ifndef OPENSSL_NO_IDEA
76 # include <openssl/idea.h>
78 #ifndef OPENSSL_NO_SEED
79 # include <openssl/seed.h>
82 # include <openssl/blowfish.h>
84 #ifndef OPENSSL_NO_CAST
85 # include <openssl/cast.h>
87 #ifndef OPENSSL_NO_RSA
88 # include <openssl/rsa.h>
89 # include "./testrsa.h"
91 #include <openssl/x509.h>
92 #ifndef OPENSSL_NO_DSA
93 # include <openssl/dsa.h>
94 # include "./testdsa.h"
97 # include <openssl/ec.h>
99 #include <openssl/modes.h>
102 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
116 #define BUFSIZE (1024*16+1)
117 #define MAX_MISALIGNMENT 63
126 #define MAX_ECDH_SIZE 256
129 static volatile int run = 0;
132 static int usertime = 1;
134 typedef struct loopargs_st {
135 ASYNC_JOB *inprogress_job;
136 ASYNC_WAIT_CTX *wait_ctx;
139 unsigned char *buf_malloc;
140 unsigned char *buf2_malloc;
142 #ifndef OPENSSL_NO_RSA
143 RSA *rsa_key[RSA_NUM];
145 #ifndef OPENSSL_NO_DSA
146 DSA *dsa_key[DSA_NUM];
148 #ifndef OPENSSL_NO_EC
149 EC_KEY *ecdsa[EC_NUM];
150 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
151 unsigned char *secret_a;
152 unsigned char *secret_b;
153 size_t outlen[EC_NUM];
157 GCM128_CONTEXT *gcm_ctx;
160 #ifndef OPENSSL_NO_MD2
161 static int EVP_Digest_MD2_loop(void *args);
164 #ifndef OPENSSL_NO_MDC2
165 static int EVP_Digest_MDC2_loop(void *args);
167 #ifndef OPENSSL_NO_MD4
168 static int EVP_Digest_MD4_loop(void *args);
170 #ifndef OPENSSL_NO_MD5
171 static int MD5_loop(void *args);
172 static int HMAC_loop(void *args);
174 static int SHA1_loop(void *args);
175 static int SHA256_loop(void *args);
176 static int SHA512_loop(void *args);
177 #ifndef OPENSSL_NO_WHIRLPOOL
178 static int WHIRLPOOL_loop(void *args);
180 #ifndef OPENSSL_NO_RMD160
181 static int EVP_Digest_RMD160_loop(void *args);
183 #ifndef OPENSSL_NO_RC4
184 static int RC4_loop(void *args);
186 #ifndef OPENSSL_NO_DES
187 static int DES_ncbc_encrypt_loop(void *args);
188 static int DES_ede3_cbc_encrypt_loop(void *args);
190 static int AES_cbc_128_encrypt_loop(void *args);
191 static int AES_cbc_192_encrypt_loop(void *args);
192 static int AES_ige_128_encrypt_loop(void *args);
193 static int AES_cbc_256_encrypt_loop(void *args);
194 static int AES_ige_192_encrypt_loop(void *args);
195 static int AES_ige_256_encrypt_loop(void *args);
196 static int CRYPTO_gcm128_aad_loop(void *args);
197 static int EVP_Update_loop(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"
233 static double results[ALGOR_NUM][SIZE_NUM];
235 static const int lengths[SIZE_NUM] = {
236 16, 64, 256, 1024, 8 * 1024, 16 * 1024
239 #ifndef OPENSSL_NO_RSA
240 static double rsa_results[RSA_NUM][2];
242 #ifndef OPENSSL_NO_DSA
243 static double dsa_results[DSA_NUM][2];
245 #ifndef OPENSSL_NO_EC
246 static double ecdsa_results[EC_NUM][2];
247 static double ecdh_results[EC_NUM][1];
250 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
251 static const char rnd_seed[] =
252 "string to make the random number generator think it has randomness";
256 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
257 # define SIGRETTYPE void
259 # define SIGRETTYPE int
262 static SIGRETTYPE sig_done(int sig);
263 static SIGRETTYPE sig_done(int sig)
265 signal(SIGALRM, sig_done);
275 # if !defined(SIGALRM)
278 static unsigned int lapse, schlock;
279 static void alarm_win32(unsigned int secs)
284 # define alarm alarm_win32
286 static DWORD WINAPI sleepy(VOID * arg)
294 static double Time_F(int s)
301 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
303 DWORD err = GetLastError();
304 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
308 Sleep(0); /* scheduler spinlock */
309 ret = app_tminterval(s, usertime);
311 ret = app_tminterval(s, usertime);
313 TerminateThread(thr, 0);
321 static double Time_F(int s)
323 double ret = app_tminterval(s, usertime);
330 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
332 static int found(const char *name, const OPT_PAIR *pairs, int *result)
334 for (; pairs->name; pairs++)
335 if (strcmp(name, pairs->name) == 0) {
336 *result = pairs->retval;
342 typedef enum OPTION_choice {
343 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
344 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
345 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
348 const OPTIONS speed_options[] = {
349 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
350 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
351 {"help", OPT_HELP, '-', "Display this summary"},
352 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
353 {"decrypt", OPT_DECRYPT, '-',
354 "Time decryption instead of encryption (only EVP)"},
355 {"mr", OPT_MR, '-', "Produce machine readable output"},
357 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
358 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
359 {"elapsed", OPT_ELAPSED, '-',
360 "Measure time in real time instead of CPU user time"},
362 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
364 #ifndef OPENSSL_NO_ASYNC
365 {"async_jobs", OPT_ASYNCJOBS, 'p',
366 "Enable async mode and start pnum jobs"},
368 #ifndef OPENSSL_NO_ENGINE
369 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
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
404 static OPT_PAIR doit_choices[] = {
405 #ifndef OPENSSL_NO_MD2
408 #ifndef OPENSSL_NO_MDC2
411 #ifndef OPENSSL_NO_MD4
414 #ifndef OPENSSL_NO_MD5
419 {"sha256", D_SHA256},
420 {"sha512", D_SHA512},
421 #ifndef OPENSSL_NO_WHIRLPOOL
422 {"whirlpool", D_WHIRLPOOL},
424 #ifndef OPENSSL_NO_RMD160
425 {"ripemd", D_RMD160},
426 {"rmd160", D_RMD160},
427 {"ripemd160", D_RMD160},
429 #ifndef OPENSSL_NO_RC4
432 #ifndef OPENSSL_NO_DES
433 {"des-cbc", D_CBC_DES},
434 {"des-ede3", D_EDE3_DES},
436 {"aes-128-cbc", D_CBC_128_AES},
437 {"aes-192-cbc", D_CBC_192_AES},
438 {"aes-256-cbc", D_CBC_256_AES},
439 {"aes-128-ige", D_IGE_128_AES},
440 {"aes-192-ige", D_IGE_192_AES},
441 {"aes-256-ige", D_IGE_256_AES},
442 #ifndef OPENSSL_NO_RC2
443 {"rc2-cbc", D_CBC_RC2},
446 #ifndef OPENSSL_NO_RC5
447 {"rc5-cbc", D_CBC_RC5},
450 #ifndef OPENSSL_NO_IDEA
451 {"idea-cbc", D_CBC_IDEA},
452 {"idea", D_CBC_IDEA},
454 #ifndef OPENSSL_NO_SEED
455 {"seed-cbc", D_CBC_SEED},
456 {"seed", D_CBC_SEED},
458 #ifndef OPENSSL_NO_BF
459 {"bf-cbc", D_CBC_BF},
460 {"blowfish", D_CBC_BF},
463 #ifndef OPENSSL_NO_CAST
464 {"cast-cbc", D_CBC_CAST},
465 {"cast", D_CBC_CAST},
466 {"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 long save_count = 0;
843 static int decrypt = 0;
844 static int EVP_Update_loop(void *args)
846 loopargs_t *tempargs = *(loopargs_t **) args;
847 unsigned char *buf = tempargs->buf;
848 EVP_CIPHER_CTX *ctx = tempargs->ctx;
851 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
854 for (count = 0; COND(nb_iter); count++)
855 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
857 for (count = 0; COND(nb_iter); count++)
858 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
860 EVP_DecryptFinal_ex(ctx, buf, &outl);
862 EVP_EncryptFinal_ex(ctx, buf, &outl);
866 static const EVP_MD *evp_md = NULL;
867 static int EVP_Digest_loop(void *args)
869 loopargs_t *tempargs = *(loopargs_t **) args;
870 unsigned char *buf = tempargs->buf;
871 unsigned char md[EVP_MAX_MD_SIZE];
874 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
877 for (count = 0; COND(nb_iter); count++) {
878 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
884 #ifndef OPENSSL_NO_RSA
885 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
887 static int RSA_sign_loop(void *args)
889 loopargs_t *tempargs = *(loopargs_t **) args;
890 unsigned char *buf = tempargs->buf;
891 unsigned char *buf2 = tempargs->buf2;
892 unsigned int *rsa_num = &tempargs->siglen;
893 RSA **rsa_key = tempargs->rsa_key;
895 for (count = 0; COND(rsa_c[testnum][0]); count++) {
896 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
898 BIO_printf(bio_err, "RSA sign failure\n");
899 ERR_print_errors(bio_err);
907 static int RSA_verify_loop(void *args)
909 loopargs_t *tempargs = *(loopargs_t **) args;
910 unsigned char *buf = tempargs->buf;
911 unsigned char *buf2 = tempargs->buf2;
912 unsigned int rsa_num = tempargs->siglen;
913 RSA **rsa_key = tempargs->rsa_key;
915 for (count = 0; COND(rsa_c[testnum][1]); count++) {
917 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
919 BIO_printf(bio_err, "RSA verify failure\n");
920 ERR_print_errors(bio_err);
929 #ifndef OPENSSL_NO_DSA
930 static long dsa_c[DSA_NUM][2];
931 static int DSA_sign_loop(void *args)
933 loopargs_t *tempargs = *(loopargs_t **) args;
934 unsigned char *buf = tempargs->buf;
935 unsigned char *buf2 = tempargs->buf2;
936 DSA **dsa_key = tempargs->dsa_key;
937 unsigned int *siglen = &tempargs->siglen;
939 for (count = 0; COND(dsa_c[testnum][0]); count++) {
940 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
942 BIO_printf(bio_err, "DSA sign failure\n");
943 ERR_print_errors(bio_err);
951 static int DSA_verify_loop(void *args)
953 loopargs_t *tempargs = *(loopargs_t **) args;
954 unsigned char *buf = tempargs->buf;
955 unsigned char *buf2 = tempargs->buf2;
956 DSA **dsa_key = tempargs->dsa_key;
957 unsigned int siglen = tempargs->siglen;
959 for (count = 0; COND(dsa_c[testnum][1]); count++) {
960 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
962 BIO_printf(bio_err, "DSA verify failure\n");
963 ERR_print_errors(bio_err);
972 #ifndef OPENSSL_NO_EC
973 static long ecdsa_c[EC_NUM][2];
974 static int ECDSA_sign_loop(void *args)
976 loopargs_t *tempargs = *(loopargs_t **) args;
977 unsigned char *buf = tempargs->buf;
978 EC_KEY **ecdsa = tempargs->ecdsa;
979 unsigned char *ecdsasig = tempargs->buf2;
980 unsigned int *ecdsasiglen = &tempargs->siglen;
982 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
983 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
985 BIO_printf(bio_err, "ECDSA sign failure\n");
986 ERR_print_errors(bio_err);
994 static int ECDSA_verify_loop(void *args)
996 loopargs_t *tempargs = *(loopargs_t **) args;
997 unsigned char *buf = tempargs->buf;
998 EC_KEY **ecdsa = tempargs->ecdsa;
999 unsigned char *ecdsasig = tempargs->buf2;
1000 unsigned int ecdsasiglen = tempargs->siglen;
1002 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1003 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1005 BIO_printf(bio_err, "ECDSA verify failure\n");
1006 ERR_print_errors(bio_err);
1014 /* ******************************************************************** */
1015 static long ecdh_c[EC_NUM][1];
1017 static int ECDH_EVP_derive_key_loop(void *args)
1019 loopargs_t *tempargs = *(loopargs_t **) args;
1020 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1021 unsigned char *derived_secret = tempargs->secret_a;
1023 size_t *outlen = &(tempargs->outlen[testnum]);
1025 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1026 EVP_PKEY_derive(ctx, derived_secret, outlen);
1031 #endif /* OPENSSL_NO_EC */
1033 static int run_benchmark(int async_jobs,
1034 int (*loop_function) (void *), loopargs_t * loopargs)
1036 int job_op_count = 0;
1037 int total_op_count = 0;
1038 int num_inprogress = 0;
1039 int error = 0, i = 0, ret = 0;
1040 OSSL_ASYNC_FD job_fd = 0;
1041 size_t num_job_fds = 0;
1045 if (async_jobs == 0) {
1046 return loop_function((void *)&loopargs);
1049 for (i = 0; i < async_jobs && !error; i++) {
1050 loopargs_t *looparg_item = loopargs + i;
1052 /* Copy pointer content (looparg_t item address) into async context */
1053 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1054 &job_op_count, loop_function,
1055 (void *)&looparg_item, sizeof(looparg_item));
1061 if (job_op_count == -1) {
1064 total_op_count += job_op_count;
1069 BIO_printf(bio_err, "Failure in the job\n");
1070 ERR_print_errors(bio_err);
1076 while (num_inprogress > 0) {
1077 #if defined(OPENSSL_SYS_WINDOWS)
1079 #elif defined(OPENSSL_SYS_UNIX)
1080 int select_result = 0;
1081 OSSL_ASYNC_FD max_fd = 0;
1084 FD_ZERO(&waitfdset);
1086 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1087 if (loopargs[i].inprogress_job == NULL)
1090 if (!ASYNC_WAIT_CTX_get_all_fds
1091 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1092 || num_job_fds > 1) {
1093 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1094 ERR_print_errors(bio_err);
1098 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1100 FD_SET(job_fd, &waitfdset);
1101 if (job_fd > max_fd)
1105 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1107 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1108 "Decrease the value of async_jobs\n",
1109 max_fd, FD_SETSIZE);
1110 ERR_print_errors(bio_err);
1115 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1116 if (select_result == -1 && errno == EINTR)
1119 if (select_result == -1) {
1120 BIO_printf(bio_err, "Failure in the select\n");
1121 ERR_print_errors(bio_err);
1126 if (select_result == 0)
1130 for (i = 0; i < async_jobs; 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,
1145 #if defined(OPENSSL_SYS_UNIX)
1146 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1148 #elif defined(OPENSSL_SYS_WINDOWS)
1149 if (num_job_fds == 1
1150 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1155 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1156 loopargs[i].wait_ctx, &job_op_count,
1157 loop_function, (void *)(loopargs + i),
1158 sizeof(loopargs_t));
1163 if (job_op_count == -1) {
1166 total_op_count += job_op_count;
1169 loopargs[i].inprogress_job = NULL;
1174 loopargs[i].inprogress_job = NULL;
1175 BIO_printf(bio_err, "Failure in the job\n");
1176 ERR_print_errors(bio_err);
1183 return error ? -1 : total_op_count;
1186 int speed_main(int argc, char **argv)
1189 loopargs_t *loopargs = NULL;
1191 int loopargs_len = 0;
1193 const char *engine_id = NULL;
1194 const EVP_CIPHER *evp_cipher = NULL;
1197 int multiblock = 0, pr_header = 0;
1198 int doit[ALGOR_NUM] = { 0 };
1199 int ret = 1, i, k, misalign = 0;
1204 unsigned int async_jobs = 0;
1205 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1206 || !defined(OPENSSL_NO_EC)
1210 /* What follows are the buffers and key material. */
1211 #ifndef OPENSSL_NO_RC5
1214 #ifndef OPENSSL_NO_RC2
1217 #ifndef OPENSSL_NO_IDEA
1218 IDEA_KEY_SCHEDULE idea_ks;
1220 #ifndef OPENSSL_NO_SEED
1221 SEED_KEY_SCHEDULE seed_ks;
1223 #ifndef OPENSSL_NO_BF
1226 #ifndef OPENSSL_NO_CAST
1229 static const unsigned char key16[16] = {
1230 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1231 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1233 static const unsigned char key24[24] = {
1234 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1235 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1236 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1238 static const unsigned char key32[32] = {
1239 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1240 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1241 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1242 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1244 #ifndef OPENSSL_NO_CAMELLIA
1245 static const unsigned char ckey24[24] = {
1246 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1247 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1248 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1250 static const unsigned char ckey32[32] = {
1251 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1252 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1253 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1254 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1256 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1258 #ifndef OPENSSL_NO_DES
1259 static DES_cblock key = {
1260 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1262 static DES_cblock key2 = {
1263 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1265 static DES_cblock key3 = {
1266 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1269 #ifndef OPENSSL_NO_RSA
1270 static const unsigned int rsa_bits[RSA_NUM] = {
1271 512, 1024, 2048, 3072, 4096, 7680, 15360
1273 static const unsigned char *rsa_data[RSA_NUM] = {
1274 test512, test1024, test2048, test3072, test4096, test7680, test15360
1276 static const int rsa_data_length[RSA_NUM] = {
1277 sizeof(test512), sizeof(test1024),
1278 sizeof(test2048), sizeof(test3072),
1279 sizeof(test4096), sizeof(test7680),
1282 int rsa_doit[RSA_NUM] = { 0 };
1284 #ifndef OPENSSL_NO_DSA
1285 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1286 int dsa_doit[DSA_NUM] = { 0 };
1288 #ifndef OPENSSL_NO_EC
1290 * We only test over the following curves as they are representative, To
1291 * add tests over more curves, simply add the curve NID and curve name to
1292 * the following arrays and increase the EC_NUM value accordingly.
1294 static const unsigned int test_curves[EC_NUM] = {
1296 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1297 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1299 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1300 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1301 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1306 static const char *test_curves_names[EC_NUM] = {
1308 "secp160r1", "nistp192", "nistp224",
1309 "nistp256", "nistp384", "nistp521",
1311 "nistk163", "nistk233", "nistk283",
1312 "nistk409", "nistk571", "nistb163",
1313 "nistb233", "nistb283", "nistb409",
1318 static const int test_curves_bits[EC_NUM] = {
1324 571, 253 /* X25519 */
1327 int ecdsa_doit[EC_NUM] = { 0 };
1328 int ecdh_doit[EC_NUM] = { 0 };
1329 #endif /* ndef OPENSSL_NO_EC */
1331 prog = opt_init(argc, argv, speed_options);
1332 while ((o = opt_next()) != OPT_EOF) {
1337 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1340 opt_help(speed_options);
1348 evp_cipher = EVP_get_cipherbyname(opt_arg());
1349 if (evp_cipher == NULL)
1350 evp_md = EVP_get_digestbyname(opt_arg());
1351 if (evp_cipher == NULL && evp_md == NULL) {
1353 "%s: %s is an unknown cipher or digest\n",
1364 * In a forked execution, an engine might need to be
1365 * initialised by each child process, not by the parent.
1366 * So store the name here and run setup_engine() later on.
1368 engine_id = opt_arg();
1372 multi = atoi(opt_arg());
1376 #ifndef OPENSSL_NO_ASYNC
1377 async_jobs = atoi(opt_arg());
1378 if (!ASYNC_is_capable()) {
1380 "%s: async_jobs specified but async not supported\n",
1384 if (async_jobs > 99999) {
1386 "%s: too many async_jobs\n",
1393 if (!opt_int(opt_arg(), &misalign))
1395 if (misalign > MISALIGN) {
1397 "%s: Maximum offset is %d\n", prog, MISALIGN);
1406 #ifdef OPENSSL_NO_MULTIBLOCK
1408 "%s: -mb specified but multi-block support is disabled\n",
1415 argc = opt_num_rest();
1418 /* Remaining arguments are algorithms. */
1419 for (; *argv; argv++) {
1420 if (found(*argv, doit_choices, &i)) {
1424 #ifndef OPENSSL_NO_DES
1425 if (strcmp(*argv, "des") == 0) {
1426 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1430 if (strcmp(*argv, "sha") == 0) {
1431 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1434 #ifndef OPENSSL_NO_RSA
1435 if (strcmp(*argv, "openssl") == 0)
1437 if (strcmp(*argv, "rsa") == 0) {
1438 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1439 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1440 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1441 rsa_doit[R_RSA_15360] = 1;
1444 if (found(*argv, rsa_choices, &i)) {
1449 #ifndef OPENSSL_NO_DSA
1450 if (strcmp(*argv, "dsa") == 0) {
1451 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1452 dsa_doit[R_DSA_2048] = 1;
1455 if (found(*argv, dsa_choices, &i)) {
1460 if (strcmp(*argv, "aes") == 0) {
1461 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1464 #ifndef OPENSSL_NO_CAMELLIA
1465 if (strcmp(*argv, "camellia") == 0) {
1466 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1470 #ifndef OPENSSL_NO_EC
1471 if (strcmp(*argv, "ecdsa") == 0) {
1472 for (i = 0; i < EC_NUM; i++)
1476 if (found(*argv, ecdsa_choices, &i)) {
1480 if (strcmp(*argv, "ecdh") == 0) {
1481 for (i = 0; i < EC_NUM; i++)
1485 if (found(*argv, ecdh_choices, &i)) {
1490 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1494 /* Initialize the job pool if async mode is enabled */
1495 if (async_jobs > 0) {
1496 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1498 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1503 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1505 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1506 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1508 for (i = 0; i < loopargs_len; i++) {
1509 if (async_jobs > 0) {
1510 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1511 if (loopargs[i].wait_ctx == NULL) {
1512 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1517 loopargs[i].buf_malloc =
1518 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1519 loopargs[i].buf2_malloc =
1520 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1521 /* Align the start of buffers on a 64 byte boundary */
1522 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1523 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1524 #ifndef OPENSSL_NO_EC
1525 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1526 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1531 if (multi && do_multi(multi))
1535 /* Initialize the engine after the fork */
1536 e = setup_engine(engine_id, 0);
1538 /* No parameters; turn on everything. */
1539 if ((argc == 0) && !doit[D_EVP]) {
1540 for (i = 0; i < ALGOR_NUM; i++)
1543 #ifndef OPENSSL_NO_RSA
1544 for (i = 0; i < RSA_NUM; i++)
1547 #ifndef OPENSSL_NO_DSA
1548 for (i = 0; i < DSA_NUM; i++)
1551 #ifndef OPENSSL_NO_EC
1552 for (i = 0; i < EC_NUM; i++)
1554 for (i = 0; i < EC_NUM; i++)
1558 for (i = 0; i < ALGOR_NUM; i++)
1562 if (usertime == 0 && !mr)
1564 "You have chosen to measure elapsed time "
1565 "instead of user CPU time.\n");
1567 #ifndef OPENSSL_NO_RSA
1568 for (i = 0; i < loopargs_len; i++) {
1569 for (k = 0; k < RSA_NUM; k++) {
1570 const unsigned char *p;
1573 loopargs[i].rsa_key[k] =
1574 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1575 if (loopargs[i].rsa_key[k] == NULL) {
1577 "internal error loading RSA key number %d\n", k);
1583 #ifndef OPENSSL_NO_DSA
1584 for (i = 0; i < loopargs_len; i++) {
1585 loopargs[i].dsa_key[0] = get_dsa(512);
1586 loopargs[i].dsa_key[1] = get_dsa(1024);
1587 loopargs[i].dsa_key[2] = get_dsa(2048);
1590 #ifndef OPENSSL_NO_DES
1591 DES_set_key_unchecked(&key, &sch);
1592 DES_set_key_unchecked(&key2, &sch2);
1593 DES_set_key_unchecked(&key3, &sch3);
1595 AES_set_encrypt_key(key16, 128, &aes_ks1);
1596 AES_set_encrypt_key(key24, 192, &aes_ks2);
1597 AES_set_encrypt_key(key32, 256, &aes_ks3);
1598 #ifndef OPENSSL_NO_CAMELLIA
1599 Camellia_set_key(key16, 128, &camellia_ks1);
1600 Camellia_set_key(ckey24, 192, &camellia_ks2);
1601 Camellia_set_key(ckey32, 256, &camellia_ks3);
1603 #ifndef OPENSSL_NO_IDEA
1604 IDEA_set_encrypt_key(key16, &idea_ks);
1606 #ifndef OPENSSL_NO_SEED
1607 SEED_set_key(key16, &seed_ks);
1609 #ifndef OPENSSL_NO_RC4
1610 RC4_set_key(&rc4_ks, 16, key16);
1612 #ifndef OPENSSL_NO_RC2
1613 RC2_set_key(&rc2_ks, 16, key16, 128);
1615 #ifndef OPENSSL_NO_RC5
1616 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1618 #ifndef OPENSSL_NO_BF
1619 BF_set_key(&bf_ks, 16, key16);
1621 #ifndef OPENSSL_NO_CAST
1622 CAST_set_key(&cast_ks, 16, key16);
1625 # ifndef OPENSSL_NO_DES
1626 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1632 for (it = count; it; it--)
1633 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1634 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1638 c[D_MD2][0] = count / 10;
1639 c[D_MDC2][0] = count / 10;
1640 c[D_MD4][0] = count;
1641 c[D_MD5][0] = count;
1642 c[D_HMAC][0] = count;
1643 c[D_SHA1][0] = count;
1644 c[D_RMD160][0] = count;
1645 c[D_RC4][0] = count * 5;
1646 c[D_CBC_DES][0] = count;
1647 c[D_EDE3_DES][0] = count / 3;
1648 c[D_CBC_IDEA][0] = count;
1649 c[D_CBC_SEED][0] = count;
1650 c[D_CBC_RC2][0] = count;
1651 c[D_CBC_RC5][0] = count;
1652 c[D_CBC_BF][0] = count;
1653 c[D_CBC_CAST][0] = count;
1654 c[D_CBC_128_AES][0] = count;
1655 c[D_CBC_192_AES][0] = count;
1656 c[D_CBC_256_AES][0] = count;
1657 c[D_CBC_128_CML][0] = count;
1658 c[D_CBC_192_CML][0] = count;
1659 c[D_CBC_256_CML][0] = count;
1660 c[D_SHA256][0] = count;
1661 c[D_SHA512][0] = count;
1662 c[D_WHIRLPOOL][0] = count;
1663 c[D_IGE_128_AES][0] = count;
1664 c[D_IGE_192_AES][0] = count;
1665 c[D_IGE_256_AES][0] = count;
1666 c[D_GHASH][0] = count;
1668 for (i = 1; i < SIZE_NUM; i++) {
1671 l0 = (long)lengths[0];
1672 l1 = (long)lengths[i];
1674 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1675 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1676 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1677 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1678 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1679 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1680 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1681 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1682 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1683 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1684 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1686 l0 = (long)lengths[i - 1];
1688 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1689 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1690 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1691 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1692 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1693 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1694 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1695 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1696 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1697 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1698 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1699 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1700 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1701 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1702 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1703 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1704 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1705 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1708 # ifndef OPENSSL_NO_RSA
1709 rsa_c[R_RSA_512][0] = count / 2000;
1710 rsa_c[R_RSA_512][1] = count / 400;
1711 for (i = 1; i < RSA_NUM; i++) {
1712 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1713 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1714 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1717 if (rsa_c[i][0] == 0) {
1718 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1725 # ifndef OPENSSL_NO_DSA
1726 dsa_c[R_DSA_512][0] = count / 1000;
1727 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1728 for (i = 1; i < DSA_NUM; i++) {
1729 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1730 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1731 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1734 if (dsa_c[i][0] == 0) {
1735 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1742 # ifndef OPENSSL_NO_EC
1743 ecdsa_c[R_EC_P160][0] = count / 1000;
1744 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1745 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1746 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1747 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1748 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1751 if (ecdsa_c[i][0] == 0) {
1757 ecdsa_c[R_EC_K163][0] = count / 1000;
1758 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1759 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1760 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1761 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1762 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1765 if (ecdsa_c[i][0] == 0) {
1771 ecdsa_c[R_EC_B163][0] = count / 1000;
1772 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1773 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1774 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1775 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1776 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1779 if (ecdsa_c[i][0] == 0) {
1786 ecdh_c[R_EC_P160][0] = count / 1000;
1787 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1788 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1789 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1792 if (ecdh_c[i][0] == 0) {
1797 ecdh_c[R_EC_K163][0] = count / 1000;
1798 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1799 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1800 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1803 if (ecdh_c[i][0] == 0) {
1808 ecdh_c[R_EC_B163][0] = count / 1000;
1809 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1810 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1811 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1814 if (ecdh_c[i][0] == 0) {
1822 /* not worth fixing */
1823 # error "You cannot disable DES on systems without SIGALRM."
1824 # endif /* OPENSSL_NO_DES */
1827 signal(SIGALRM, sig_done);
1829 #endif /* SIGALRM */
1831 #ifndef OPENSSL_NO_MD2
1833 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1834 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1836 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1838 print_result(D_MD2, testnum, count, d);
1842 #ifndef OPENSSL_NO_MDC2
1844 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1845 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1847 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1849 print_result(D_MDC2, testnum, count, d);
1854 #ifndef OPENSSL_NO_MD4
1856 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1857 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1859 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1861 print_result(D_MD4, testnum, count, d);
1866 #ifndef OPENSSL_NO_MD5
1868 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1869 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1871 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1873 print_result(D_MD5, testnum, count, d);
1878 static const char hmac_key[] = "This is a key...";
1879 int len = strlen(hmac_key);
1881 for (i = 0; i < loopargs_len; i++) {
1882 loopargs[i].hctx = HMAC_CTX_new();
1883 if (loopargs[i].hctx == NULL) {
1884 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1888 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1890 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1891 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1893 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1895 print_result(D_HMAC, testnum, count, d);
1897 for (i = 0; i < loopargs_len; i++) {
1898 HMAC_CTX_free(loopargs[i].hctx);
1903 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1904 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1906 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1908 print_result(D_SHA1, testnum, count, d);
1911 if (doit[D_SHA256]) {
1912 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1913 print_message(names[D_SHA256], c[D_SHA256][testnum],
1916 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1918 print_result(D_SHA256, testnum, count, d);
1921 if (doit[D_SHA512]) {
1922 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1923 print_message(names[D_SHA512], c[D_SHA512][testnum],
1926 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1928 print_result(D_SHA512, testnum, count, d);
1931 #ifndef OPENSSL_NO_WHIRLPOOL
1932 if (doit[D_WHIRLPOOL]) {
1933 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1934 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1937 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1939 print_result(D_WHIRLPOOL, testnum, count, d);
1944 #ifndef OPENSSL_NO_RMD160
1945 if (doit[D_RMD160]) {
1946 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1947 print_message(names[D_RMD160], c[D_RMD160][testnum],
1950 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1952 print_result(D_RMD160, testnum, count, d);
1956 #ifndef OPENSSL_NO_RC4
1958 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1959 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1961 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1963 print_result(D_RC4, testnum, count, d);
1967 #ifndef OPENSSL_NO_DES
1968 if (doit[D_CBC_DES]) {
1969 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1970 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
1973 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1975 print_result(D_CBC_DES, testnum, count, d);
1979 if (doit[D_EDE3_DES]) {
1980 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1981 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
1985 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
1987 print_result(D_EDE3_DES, testnum, count, d);
1992 if (doit[D_CBC_128_AES]) {
1993 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1994 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
1998 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2000 print_result(D_CBC_128_AES, testnum, count, d);
2003 if (doit[D_CBC_192_AES]) {
2004 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2005 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2009 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2011 print_result(D_CBC_192_AES, testnum, count, d);
2014 if (doit[D_CBC_256_AES]) {
2015 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2016 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2020 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2022 print_result(D_CBC_256_AES, testnum, count, d);
2026 if (doit[D_IGE_128_AES]) {
2027 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2028 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2032 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2034 print_result(D_IGE_128_AES, testnum, count, d);
2037 if (doit[D_IGE_192_AES]) {
2038 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2039 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2043 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2045 print_result(D_IGE_192_AES, testnum, count, d);
2048 if (doit[D_IGE_256_AES]) {
2049 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2050 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2054 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2056 print_result(D_IGE_256_AES, testnum, count, d);
2059 if (doit[D_GHASH]) {
2060 for (i = 0; i < loopargs_len; i++) {
2061 loopargs[i].gcm_ctx =
2062 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2063 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2064 (unsigned char *)"0123456789ab", 12);
2067 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2068 print_message(names[D_GHASH], c[D_GHASH][testnum],
2071 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2073 print_result(D_GHASH, testnum, count, d);
2075 for (i = 0; i < loopargs_len; i++)
2076 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2078 #ifndef OPENSSL_NO_CAMELLIA
2079 if (doit[D_CBC_128_CML]) {
2080 if (async_jobs > 0) {
2081 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2082 names[D_CBC_128_CML]);
2083 doit[D_CBC_128_CML] = 0;
2085 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2086 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2089 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2090 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2091 (size_t)lengths[testnum], &camellia_ks1,
2092 iv, CAMELLIA_ENCRYPT);
2094 print_result(D_CBC_128_CML, testnum, count, d);
2097 if (doit[D_CBC_192_CML]) {
2098 if (async_jobs > 0) {
2099 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2100 names[D_CBC_192_CML]);
2101 doit[D_CBC_192_CML] = 0;
2103 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2104 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2106 if (async_jobs > 0) {
2107 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2111 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2112 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2113 (size_t)lengths[testnum], &camellia_ks2,
2114 iv, CAMELLIA_ENCRYPT);
2116 print_result(D_CBC_192_CML, testnum, count, d);
2119 if (doit[D_CBC_256_CML]) {
2120 if (async_jobs > 0) {
2121 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2122 names[D_CBC_256_CML]);
2123 doit[D_CBC_256_CML] = 0;
2125 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2126 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2129 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2130 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2131 (size_t)lengths[testnum], &camellia_ks3,
2132 iv, CAMELLIA_ENCRYPT);
2134 print_result(D_CBC_256_CML, testnum, count, d);
2138 #ifndef OPENSSL_NO_IDEA
2139 if (doit[D_CBC_IDEA]) {
2140 if (async_jobs > 0) {
2141 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2143 doit[D_CBC_IDEA] = 0;
2145 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2146 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2149 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2150 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2151 (size_t)lengths[testnum], &idea_ks,
2154 print_result(D_CBC_IDEA, testnum, count, d);
2158 #ifndef OPENSSL_NO_SEED
2159 if (doit[D_CBC_SEED]) {
2160 if (async_jobs > 0) {
2161 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2163 doit[D_CBC_SEED] = 0;
2165 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2166 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2169 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2170 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2171 (size_t)lengths[testnum], &seed_ks, iv, 1);
2173 print_result(D_CBC_SEED, testnum, count, d);
2177 #ifndef OPENSSL_NO_RC2
2178 if (doit[D_CBC_RC2]) {
2179 if (async_jobs > 0) {
2180 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2182 doit[D_CBC_RC2] = 0;
2184 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2185 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2187 if (async_jobs > 0) {
2188 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2192 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2193 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2194 (size_t)lengths[testnum], &rc2_ks,
2197 print_result(D_CBC_RC2, testnum, count, d);
2201 #ifndef OPENSSL_NO_RC5
2202 if (doit[D_CBC_RC5]) {
2203 if (async_jobs > 0) {
2204 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2206 doit[D_CBC_RC5] = 0;
2208 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2209 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2211 if (async_jobs > 0) {
2212 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2216 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2217 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2218 (size_t)lengths[testnum], &rc5_ks,
2221 print_result(D_CBC_RC5, testnum, count, d);
2225 #ifndef OPENSSL_NO_BF
2226 if (doit[D_CBC_BF]) {
2227 if (async_jobs > 0) {
2228 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2232 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2233 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2236 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2237 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2238 (size_t)lengths[testnum], &bf_ks,
2241 print_result(D_CBC_BF, testnum, count, d);
2245 #ifndef OPENSSL_NO_CAST
2246 if (doit[D_CBC_CAST]) {
2247 if (async_jobs > 0) {
2248 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2250 doit[D_CBC_CAST] = 0;
2252 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2253 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2256 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2257 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2258 (size_t)lengths[testnum], &cast_ks,
2261 print_result(D_CBC_CAST, testnum, count, d);
2267 if (multiblock && evp_cipher) {
2269 (EVP_CIPHER_flags(evp_cipher) &
2270 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2271 BIO_printf(bio_err, "%s is not multi-block capable\n",
2272 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2275 if (async_jobs > 0) {
2276 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2279 multiblock_speed(evp_cipher);
2283 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2286 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2288 * -O3 -fschedule-insns messes up an optimization here!
2289 * names[D_EVP] somehow becomes NULL
2291 print_message(names[D_EVP], save_count, lengths[testnum]);
2293 for (k = 0; k < loopargs_len; k++) {
2294 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2296 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2299 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2301 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2305 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2307 for (k = 0; k < loopargs_len; k++) {
2308 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2312 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2313 print_message(names[D_EVP], save_count, lengths[testnum]);
2315 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2318 print_result(D_EVP, testnum, count, d);
2322 for (i = 0; i < loopargs_len; i++)
2323 RAND_bytes(loopargs[i].buf, 36);
2325 #ifndef OPENSSL_NO_RSA
2326 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2328 if (!rsa_doit[testnum])
2330 for (i = 0; i < loopargs_len; i++) {
2331 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2332 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2338 "RSA sign failure. No RSA sign will be done.\n");
2339 ERR_print_errors(bio_err);
2342 pkey_print_message("private", "rsa",
2343 rsa_c[testnum][0], rsa_bits[testnum],
2345 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2347 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2350 mr ? "+R1:%ld:%d:%.2f\n"
2351 : "%ld %d bit private RSA's in %.2fs\n",
2352 count, rsa_bits[testnum], d);
2353 rsa_results[testnum][0] = (double)count / d;
2357 for (i = 0; i < loopargs_len; i++) {
2358 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2359 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2365 "RSA verify failure. No RSA verify will be done.\n");
2366 ERR_print_errors(bio_err);
2367 rsa_doit[testnum] = 0;
2369 pkey_print_message("public", "rsa",
2370 rsa_c[testnum][1], rsa_bits[testnum],
2373 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2376 mr ? "+R2:%ld:%d:%.2f\n"
2377 : "%ld %d bit public RSA's in %.2fs\n",
2378 count, rsa_bits[testnum], d);
2379 rsa_results[testnum][1] = (double)count / d;
2382 if (rsa_count <= 1) {
2383 /* if longer than 10s, don't do any more */
2384 for (testnum++; testnum < RSA_NUM; testnum++)
2385 rsa_doit[testnum] = 0;
2388 #endif /* OPENSSL_NO_RSA */
2390 for (i = 0; i < loopargs_len; i++)
2391 RAND_bytes(loopargs[i].buf, 36);
2393 #ifndef OPENSSL_NO_DSA
2394 if (RAND_status() != 1) {
2395 RAND_seed(rnd_seed, sizeof rnd_seed);
2397 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2399 if (!dsa_doit[testnum])
2402 /* DSA_generate_key(dsa_key[testnum]); */
2403 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2404 for (i = 0; i < loopargs_len; i++) {
2405 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2406 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2412 "DSA sign failure. No DSA sign will be done.\n");
2413 ERR_print_errors(bio_err);
2416 pkey_print_message("sign", "dsa",
2417 dsa_c[testnum][0], dsa_bits[testnum],
2420 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2423 mr ? "+R3:%ld:%d:%.2f\n"
2424 : "%ld %d bit DSA signs in %.2fs\n",
2425 count, dsa_bits[testnum], d);
2426 dsa_results[testnum][0] = (double)count / d;
2430 for (i = 0; i < loopargs_len; i++) {
2431 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2432 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2438 "DSA verify failure. No DSA verify will be done.\n");
2439 ERR_print_errors(bio_err);
2440 dsa_doit[testnum] = 0;
2442 pkey_print_message("verify", "dsa",
2443 dsa_c[testnum][1], dsa_bits[testnum],
2446 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2449 mr ? "+R4:%ld:%d:%.2f\n"
2450 : "%ld %d bit DSA verify in %.2fs\n",
2451 count, dsa_bits[testnum], d);
2452 dsa_results[testnum][1] = (double)count / d;
2455 if (rsa_count <= 1) {
2456 /* if longer than 10s, don't do any more */
2457 for (testnum++; testnum < DSA_NUM; testnum++)
2458 dsa_doit[testnum] = 0;
2461 #endif /* OPENSSL_NO_DSA */
2463 #ifndef OPENSSL_NO_EC
2464 if (RAND_status() != 1) {
2465 RAND_seed(rnd_seed, sizeof rnd_seed);
2467 for (testnum = 0; testnum < EC_NUM; testnum++) {
2470 if (!ecdsa_doit[testnum])
2471 continue; /* Ignore Curve */
2472 for (i = 0; i < loopargs_len; i++) {
2473 loopargs[i].ecdsa[testnum] =
2474 EC_KEY_new_by_curve_name(test_curves[testnum]);
2475 if (loopargs[i].ecdsa[testnum] == NULL) {
2481 BIO_printf(bio_err, "ECDSA failure.\n");
2482 ERR_print_errors(bio_err);
2485 for (i = 0; i < loopargs_len; i++) {
2486 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2487 /* Perform ECDSA signature test */
2488 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2489 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2490 &loopargs[i].siglen,
2491 loopargs[i].ecdsa[testnum]);
2497 "ECDSA sign failure. No ECDSA sign will be done.\n");
2498 ERR_print_errors(bio_err);
2501 pkey_print_message("sign", "ecdsa",
2502 ecdsa_c[testnum][0],
2503 test_curves_bits[testnum], ECDSA_SECONDS);
2505 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2509 mr ? "+R5:%ld:%d:%.2f\n" :
2510 "%ld %d bit ECDSA signs in %.2fs \n",
2511 count, test_curves_bits[testnum], d);
2512 ecdsa_results[testnum][0] = (double)count / d;
2516 /* Perform ECDSA verification test */
2517 for (i = 0; i < loopargs_len; i++) {
2518 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2520 loopargs[i].ecdsa[testnum]);
2526 "ECDSA verify failure. No ECDSA verify will be done.\n");
2527 ERR_print_errors(bio_err);
2528 ecdsa_doit[testnum] = 0;
2530 pkey_print_message("verify", "ecdsa",
2531 ecdsa_c[testnum][1],
2532 test_curves_bits[testnum], ECDSA_SECONDS);
2534 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2537 mr ? "+R6:%ld:%d:%.2f\n"
2538 : "%ld %d bit ECDSA verify in %.2fs\n",
2539 count, test_curves_bits[testnum], d);
2540 ecdsa_results[testnum][1] = (double)count / d;
2543 if (rsa_count <= 1) {
2544 /* if longer than 10s, don't do any more */
2545 for (testnum++; testnum < EC_NUM; testnum++)
2546 ecdsa_doit[testnum] = 0;
2551 if (RAND_status() != 1) {
2552 RAND_seed(rnd_seed, sizeof rnd_seed);
2554 for (testnum = 0; testnum < EC_NUM; testnum++) {
2555 int ecdh_checks = 1;
2557 if (!ecdh_doit[testnum])
2560 for (i = 0; i < loopargs_len; i++) {
2561 EVP_PKEY_CTX *kctx = NULL;
2562 EVP_PKEY_CTX *test_ctx = NULL;
2563 EVP_PKEY_CTX *ctx = NULL;
2564 EVP_PKEY *key_A = NULL;
2565 EVP_PKEY *key_B = NULL;
2569 /* Ensure that the error queue is empty */
2570 if (ERR_peek_error()) {
2572 "WARNING: the error queue contains previous unhandled errors.\n");
2573 ERR_print_errors(bio_err);
2576 /* Let's try to create a ctx directly from the NID: this works for
2577 * curves like Curve25519 that are not implemented through the low
2578 * level EC interface.
2579 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2580 * then we set the curve by NID before deriving the actual keygen
2581 * ctx for that specific curve. */
2582 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2584 EVP_PKEY_CTX *pctx = NULL;
2585 EVP_PKEY *params = NULL;
2587 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2588 * "int_ctx_new:unsupported algorithm" error was added to the
2590 * We remove it from the error queue as we are handling it. */
2591 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2592 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2593 /* check that the error origin matches */
2594 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2595 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2596 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2597 ERR_get_error(); /* pop error from queue */
2598 if (ERR_peek_error()) {
2600 "Unhandled error in the error queue during ECDH init.\n");
2601 ERR_print_errors(bio_err);
2606 if ( /* Create the context for parameter generation */
2607 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2608 /* Initialise the parameter generation */
2609 !EVP_PKEY_paramgen_init(pctx) ||
2610 /* Set the curve by NID */
2611 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2614 /* Create the parameter object params */
2615 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2617 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2618 ERR_print_errors(bio_err);
2622 /* Create the context for the key generation */
2623 kctx = EVP_PKEY_CTX_new(params, NULL);
2625 EVP_PKEY_free(params);
2627 EVP_PKEY_CTX_free(pctx);
2630 if (kctx == NULL || /* keygen ctx is not null */
2631 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2633 BIO_printf(bio_err, "ECDH keygen failure.\n");
2634 ERR_print_errors(bio_err);
2639 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2640 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2641 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2642 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2643 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2644 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2645 outlen == 0 || /* ensure outlen is a valid size */
2646 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2648 BIO_printf(bio_err, "ECDH key generation failure.\n");
2649 ERR_print_errors(bio_err);
2654 /* Here we perform a test run, comparing the output of a*B and b*A;
2655 * we try this here and assume that further EVP_PKEY_derive calls
2656 * never fail, so we can skip checks in the actually benchmarked
2657 * code, for maximum performance. */
2658 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2659 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2660 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2661 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2662 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2663 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2664 test_outlen != outlen /* compare output length */ ) {
2666 BIO_printf(bio_err, "ECDH computation failure.\n");
2667 ERR_print_errors(bio_err);
2672 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2673 if (CRYPTO_memcmp(loopargs[i].secret_a,
2674 loopargs[i].secret_b, outlen)) {
2676 BIO_printf(bio_err, "ECDH computations don't match.\n");
2677 ERR_print_errors(bio_err);
2682 loopargs[i].ecdh_ctx[testnum] = ctx;
2683 loopargs[i].outlen[testnum] = outlen;
2685 EVP_PKEY_CTX_free(kctx);
2687 EVP_PKEY_CTX_free(test_ctx);
2690 if (ecdh_checks != 0) {
2691 pkey_print_message("", "ecdh",
2693 test_curves_bits[testnum], ECDH_SECONDS);
2696 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2699 mr ? "+R7:%ld:%d:%.2f\n" :
2700 "%ld %d-bit ECDH ops in %.2fs\n", count,
2701 test_curves_bits[testnum], d);
2702 ecdh_results[testnum][0] = (double)count / d;
2706 if (rsa_count <= 1) {
2707 /* if longer than 10s, don't do any more */
2708 for (testnum++; testnum < EC_NUM; testnum++)
2709 ecdh_doit[testnum] = 0;
2712 #endif /* OPENSSL_NO_EC */
2717 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2718 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2720 printf("%s ", BN_options());
2721 #ifndef OPENSSL_NO_MD2
2722 printf("%s ", MD2_options());
2724 #ifndef OPENSSL_NO_RC4
2725 printf("%s ", RC4_options());
2727 #ifndef OPENSSL_NO_DES
2728 printf("%s ", DES_options());
2730 printf("%s ", AES_options());
2731 #ifndef OPENSSL_NO_IDEA
2732 printf("%s ", IDEA_options());
2734 #ifndef OPENSSL_NO_BF
2735 printf("%s ", BF_options());
2737 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2745 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2748 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2749 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2753 for (k = 0; k < ALGOR_NUM; k++) {
2757 printf("+F:%d:%s", k, names[k]);
2759 printf("%-13s", names[k]);
2760 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2761 if (results[k][testnum] > 10000 && !mr)
2762 printf(" %11.2fk", results[k][testnum] / 1e3);
2764 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2768 #ifndef OPENSSL_NO_RSA
2770 for (k = 0; k < RSA_NUM; k++) {
2773 if (testnum && !mr) {
2774 printf("%18ssign verify sign/s verify/s\n", " ");
2778 printf("+F2:%u:%u:%f:%f\n",
2779 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2781 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2782 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2783 rsa_results[k][0], rsa_results[k][1]);
2786 #ifndef OPENSSL_NO_DSA
2788 for (k = 0; k < DSA_NUM; k++) {
2791 if (testnum && !mr) {
2792 printf("%18ssign verify sign/s verify/s\n", " ");
2796 printf("+F3:%u:%u:%f:%f\n",
2797 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2799 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2800 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2801 dsa_results[k][0], dsa_results[k][1]);
2804 #ifndef OPENSSL_NO_EC
2806 for (k = 0; k < EC_NUM; k++) {
2809 if (testnum && !mr) {
2810 printf("%30ssign verify sign/s verify/s\n", " ");
2815 printf("+F4:%u:%u:%f:%f\n",
2816 k, test_curves_bits[k],
2817 ecdsa_results[k][0], ecdsa_results[k][1]);
2819 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2820 test_curves_bits[k],
2821 test_curves_names[k],
2822 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2823 ecdsa_results[k][0], ecdsa_results[k][1]);
2827 for (k = 0; k < EC_NUM; k++) {
2830 if (testnum && !mr) {
2831 printf("%30sop op/s\n", " ");
2835 printf("+F5:%u:%u:%f:%f\n",
2836 k, test_curves_bits[k],
2837 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2840 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2841 test_curves_bits[k],
2842 test_curves_names[k],
2843 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2850 ERR_print_errors(bio_err);
2851 for (i = 0; i < loopargs_len; i++) {
2852 OPENSSL_free(loopargs[i].buf_malloc);
2853 OPENSSL_free(loopargs[i].buf2_malloc);
2855 #ifndef OPENSSL_NO_RSA
2856 for (k = 0; k < RSA_NUM; k++)
2857 RSA_free(loopargs[i].rsa_key[k]);
2859 #ifndef OPENSSL_NO_DSA
2860 for (k = 0; k < DSA_NUM; k++)
2861 DSA_free(loopargs[i].dsa_key[k]);
2863 #ifndef OPENSSL_NO_EC
2864 for (k = 0; k < EC_NUM; k++) {
2865 EC_KEY_free(loopargs[i].ecdsa[k]);
2866 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2868 OPENSSL_free(loopargs[i].secret_a);
2869 OPENSSL_free(loopargs[i].secret_b);
2873 if (async_jobs > 0) {
2874 for (i = 0; i < loopargs_len; i++)
2875 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2879 ASYNC_cleanup_thread();
2881 OPENSSL_free(loopargs);
2886 static void print_message(const char *s, long num, int length)
2890 mr ? "+DT:%s:%d:%d\n"
2891 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2892 (void)BIO_flush(bio_err);
2896 mr ? "+DN:%s:%ld:%d\n"
2897 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2898 (void)BIO_flush(bio_err);
2902 static void pkey_print_message(const char *str, const char *str2, long num,
2907 mr ? "+DTP:%d:%s:%s:%d\n"
2908 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2909 (void)BIO_flush(bio_err);
2913 mr ? "+DNP:%ld:%d:%s:%s\n"
2914 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2915 (void)BIO_flush(bio_err);
2919 static void print_result(int alg, int run_no, int count, double time_used)
2922 BIO_puts(bio_err, "EVP error!\n");
2926 mr ? "+R:%d:%s:%f\n"
2927 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2928 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2932 static char *sstrsep(char **string, const char *delim)
2935 char *token = *string;
2940 memset(isdelim, 0, sizeof isdelim);
2944 isdelim[(unsigned char)(*delim)] = 1;
2948 while (!isdelim[(unsigned char)(**string)]) {
2960 static int do_multi(int multi)
2965 static char sep[] = ":";
2967 fds = malloc(sizeof(*fds) * multi);
2968 for (n = 0; n < multi; ++n) {
2969 if (pipe(fd) == -1) {
2970 BIO_printf(bio_err, "pipe failure\n");
2974 (void)BIO_flush(bio_err);
2981 if (dup(fd[1]) == -1) {
2982 BIO_printf(bio_err, "dup failed\n");
2991 printf("Forked child %d\n", n);
2994 /* for now, assume the pipe is long enough to take all the output */
2995 for (n = 0; n < multi; ++n) {
3000 f = fdopen(fds[n], "r");
3001 while (fgets(buf, sizeof buf, f)) {
3002 p = strchr(buf, '\n');
3005 if (buf[0] != '+') {
3007 "Don't understand line '%s' from child %d\n", buf,
3011 printf("Got: %s from %d\n", buf, n);
3012 if (strncmp(buf, "+F:", 3) == 0) {
3017 alg = atoi(sstrsep(&p, sep));
3019 for (j = 0; j < SIZE_NUM; ++j)
3020 results[alg][j] += atof(sstrsep(&p, sep));
3021 } else if (strncmp(buf, "+F2:", 4) == 0) {
3026 k = atoi(sstrsep(&p, sep));
3029 d = atof(sstrsep(&p, sep));
3030 rsa_results[k][0] += d;
3032 d = atof(sstrsep(&p, sep));
3033 rsa_results[k][1] += d;
3035 # ifndef OPENSSL_NO_DSA
3036 else if (strncmp(buf, "+F3:", 4) == 0) {
3041 k = atoi(sstrsep(&p, sep));
3044 d = atof(sstrsep(&p, sep));
3045 dsa_results[k][0] += d;
3047 d = atof(sstrsep(&p, sep));
3048 dsa_results[k][1] += d;
3051 # ifndef OPENSSL_NO_EC
3052 else if (strncmp(buf, "+F4:", 4) == 0) {
3057 k = atoi(sstrsep(&p, sep));
3060 d = atof(sstrsep(&p, sep));
3061 ecdsa_results[k][0] += d;
3063 d = atof(sstrsep(&p, sep));
3064 ecdsa_results[k][1] += d;
3065 } else if (strncmp(buf, "+F5:", 4) == 0) {
3070 k = atoi(sstrsep(&p, sep));
3073 d = atof(sstrsep(&p, sep));
3074 ecdh_results[k][0] += d;
3078 else if (strncmp(buf, "+H:", 3) == 0) {
3081 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3092 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3094 static int mblengths[] =
3095 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3096 int j, count, num = OSSL_NELEM(mblengths);
3097 const char *alg_name;
3098 unsigned char *inp, *out, no_key[32], no_iv[16];
3099 EVP_CIPHER_CTX *ctx;
3102 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3103 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3104 ctx = EVP_CIPHER_CTX_new();
3105 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3106 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3107 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3109 for (j = 0; j < num; j++) {
3110 print_message(alg_name, 0, mblengths[j]);
3112 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3113 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3114 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3115 size_t len = mblengths[j];
3118 memset(aad, 0, 8); /* avoid uninitialized values */
3119 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3120 aad[9] = 3; /* version */
3122 aad[11] = 0; /* length */
3124 mb_param.out = NULL;
3127 mb_param.interleave = 8;
3129 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3130 sizeof(mb_param), &mb_param);
3136 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3137 sizeof(mb_param), &mb_param);
3141 RAND_bytes(out, 16);
3145 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3146 EVP_AEAD_TLS1_AAD_LEN, aad);
3147 EVP_Cipher(ctx, out, inp, len + pad);
3151 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3152 : "%d %s's in %.2fs\n", count, "evp", d);
3153 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3157 fprintf(stdout, "+H");
3158 for (j = 0; j < num; j++)
3159 fprintf(stdout, ":%d", mblengths[j]);
3160 fprintf(stdout, "\n");
3161 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3162 for (j = 0; j < num; j++)
3163 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3164 fprintf(stdout, "\n");
3167 "The 'numbers' are in 1000s of bytes per second processed.\n");
3168 fprintf(stdout, "type ");
3169 for (j = 0; j < num; j++)
3170 fprintf(stdout, "%7d bytes", mblengths[j]);
3171 fprintf(stdout, "\n");
3172 fprintf(stdout, "%-24s", alg_name);
3174 for (j = 0; j < num; j++) {
3175 if (results[D_EVP][j] > 10000)
3176 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3178 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3180 fprintf(stdout, "\n");
3185 EVP_CIPHER_CTX_free(ctx);