2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* ====================================================================
11 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
13 * Portions of the attached software ("Contribution") are developed by
14 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
16 * The Contribution is licensed pursuant to the OpenSSL open source
17 * license provided above.
19 * The ECDH and ECDSA speed test software is originally written by
20 * Sumit Gupta of Sun Microsystems Laboratories.
26 #define PRIME_SECONDS 10
27 #define RSA_SECONDS 10
28 #define DSA_SECONDS 10
29 #define ECDSA_SECONDS 10
30 #define ECDH_SECONDS 10
37 #include <openssl/crypto.h>
38 #include <openssl/rand.h>
39 #include <openssl/err.h>
40 #include <openssl/evp.h>
41 #include <openssl/objects.h>
42 #include <openssl/async.h>
43 #if !defined(OPENSSL_SYS_MSDOS)
44 # include OPENSSL_UNISTD
51 #include <openssl/bn.h>
52 #ifndef OPENSSL_NO_DES
53 # include <openssl/des.h>
55 #include <openssl/aes.h>
56 #ifndef OPENSSL_NO_CAMELLIA
57 # include <openssl/camellia.h>
59 #ifndef OPENSSL_NO_MD2
60 # include <openssl/md2.h>
62 #ifndef OPENSSL_NO_MDC2
63 # include <openssl/mdc2.h>
65 #ifndef OPENSSL_NO_MD4
66 # include <openssl/md4.h>
68 #ifndef OPENSSL_NO_MD5
69 # include <openssl/md5.h>
71 #include <openssl/hmac.h>
72 #include <openssl/sha.h>
73 #ifndef OPENSSL_NO_RMD160
74 # include <openssl/ripemd.h>
76 #ifndef OPENSSL_NO_WHIRLPOOL
77 # include <openssl/whrlpool.h>
79 #ifndef OPENSSL_NO_RC4
80 # include <openssl/rc4.h>
82 #ifndef OPENSSL_NO_RC5
83 # include <openssl/rc5.h>
85 #ifndef OPENSSL_NO_RC2
86 # include <openssl/rc2.h>
88 #ifndef OPENSSL_NO_IDEA
89 # include <openssl/idea.h>
91 #ifndef OPENSSL_NO_SEED
92 # include <openssl/seed.h>
95 # include <openssl/blowfish.h>
97 #ifndef OPENSSL_NO_CAST
98 # include <openssl/cast.h>
100 #ifndef OPENSSL_NO_RSA
101 # include <openssl/rsa.h>
102 # include "./testrsa.h"
104 #include <openssl/x509.h>
105 #ifndef OPENSSL_NO_DSA
106 # include <openssl/dsa.h>
107 # include "./testdsa.h"
109 #ifndef OPENSSL_NO_EC
110 # include <openssl/ec.h>
112 #include <openssl/modes.h>
115 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
129 #define BUFSIZE (1024*16+1)
130 #define MAX_MISALIGNMENT 63
139 #define MAX_ECDH_SIZE 256
142 static volatile int run = 0;
145 static int usertime = 1;
147 typedef void *(*kdf_fn) (
148 const void *in, size_t inlen, void *out, size_t *xoutlen);
150 typedef struct loopargs_st {
151 ASYNC_JOB *inprogress_job;
152 ASYNC_WAIT_CTX *wait_ctx;
155 unsigned char *buf_malloc;
156 unsigned char *buf2_malloc;
158 #ifndef OPENSSL_NO_RSA
159 RSA *rsa_key[RSA_NUM];
161 #ifndef OPENSSL_NO_DSA
162 DSA *dsa_key[DSA_NUM];
164 #ifndef OPENSSL_NO_EC
165 EC_KEY *ecdsa[EC_NUM];
166 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
167 unsigned char *secret_a;
168 unsigned char *secret_b;
174 GCM128_CONTEXT *gcm_ctx;
177 #ifndef OPENSSL_NO_MD2
178 static int EVP_Digest_MD2_loop(void *args);
181 #ifndef OPENSSL_NO_MDC2
182 static int EVP_Digest_MDC2_loop(void *args);
184 #ifndef OPENSSL_NO_MD4
185 static int EVP_Digest_MD4_loop(void *args);
187 #ifndef OPENSSL_NO_MD5
188 static int MD5_loop(void *args);
189 static int HMAC_loop(void *args);
191 static int SHA1_loop(void *args);
192 static int SHA256_loop(void *args);
193 static int SHA512_loop(void *args);
194 #ifndef OPENSSL_NO_WHIRLPOOL
195 static int WHIRLPOOL_loop(void *args);
197 #ifndef OPENSSL_NO_RMD160
198 static int EVP_Digest_RMD160_loop(void *args);
200 #ifndef OPENSSL_NO_RC4
201 static int RC4_loop(void *args);
203 #ifndef OPENSSL_NO_DES
204 static int DES_ncbc_encrypt_loop(void *args);
205 static int DES_ede3_cbc_encrypt_loop(void *args);
207 static int AES_cbc_128_encrypt_loop(void *args);
208 static int AES_cbc_192_encrypt_loop(void *args);
209 static int AES_ige_128_encrypt_loop(void *args);
210 static int AES_cbc_256_encrypt_loop(void *args);
211 static int AES_ige_192_encrypt_loop(void *args);
212 static int AES_ige_256_encrypt_loop(void *args);
213 static int CRYPTO_gcm128_aad_loop(void *args);
214 static int EVP_Update_loop(void *args);
215 static int EVP_Digest_loop(void *args);
216 #ifndef OPENSSL_NO_RSA
217 static int RSA_sign_loop(void *args);
218 static int RSA_verify_loop(void *args);
220 #ifndef OPENSSL_NO_DSA
221 static int DSA_sign_loop(void *args);
222 static int DSA_verify_loop(void *args);
224 #ifndef OPENSSL_NO_EC
225 static int ECDSA_sign_loop(void *args);
226 static int ECDSA_verify_loop(void *args);
228 static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
230 static double Time_F(int s);
231 static void print_message(const char *s, long num, int length);
232 static void pkey_print_message(const char *str, const char *str2,
233 long num, int bits, int sec);
234 static void print_result(int alg, int run_no, int count, double time_used);
236 static int do_multi(int multi);
239 static const char *names[ALGOR_NUM] = {
240 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
241 "des cbc", "des ede3", "idea cbc", "seed cbc",
242 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
243 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
244 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
245 "evp", "sha256", "sha512", "whirlpool",
246 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
249 static double results[ALGOR_NUM][SIZE_NUM];
251 static const int lengths[SIZE_NUM] = {
252 16, 64, 256, 1024, 8 * 1024, 16 * 1024
255 #ifndef OPENSSL_NO_RSA
256 static double rsa_results[RSA_NUM][2];
258 #ifndef OPENSSL_NO_DSA
259 static double dsa_results[DSA_NUM][2];
261 #ifndef OPENSSL_NO_EC
262 static double ecdsa_results[EC_NUM][2];
263 static double ecdh_results[EC_NUM][1];
266 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
267 static const char rnd_seed[] =
268 "string to make the random number generator think it has entropy";
272 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
273 # define SIGRETTYPE void
275 # define SIGRETTYPE int
278 static SIGRETTYPE sig_done(int sig);
279 static SIGRETTYPE sig_done(int sig)
281 signal(SIGALRM, sig_done);
291 # if !defined(SIGALRM)
294 static unsigned int lapse, schlock;
295 static void alarm_win32(unsigned int secs)
300 # define alarm alarm_win32
302 static DWORD WINAPI sleepy(VOID * arg)
310 static double Time_F(int s)
317 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
319 DWORD err = GetLastError();
320 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
324 Sleep(0); /* scheduler spinlock */
325 ret = app_tminterval(s, usertime);
327 ret = app_tminterval(s, usertime);
329 TerminateThread(thr, 0);
337 static double Time_F(int s)
339 double ret = app_tminterval(s, usertime);
346 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
348 static int found(const char *name, const OPT_PAIR *pairs, int *result)
350 for (; pairs->name; pairs++)
351 if (strcmp(name, pairs->name) == 0) {
352 *result = pairs->retval;
358 typedef enum OPTION_choice {
359 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
360 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
361 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
364 const OPTIONS speed_options[] = {
365 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
366 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
367 {"help", OPT_HELP, '-', "Display this summary"},
368 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
369 {"decrypt", OPT_DECRYPT, '-',
370 "Time decryption instead of encryption (only EVP)"},
371 {"mr", OPT_MR, '-', "Produce machine readable output"},
373 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
374 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
375 {"elapsed", OPT_ELAPSED, '-',
376 "Measure time in real time instead of CPU user time"},
378 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
380 #ifndef OPENSSL_NO_ASYNC
381 {"async_jobs", OPT_ASYNCJOBS, 'p',
382 "Enable async mode and start pnum jobs"},
384 #ifndef OPENSSL_NO_ENGINE
385 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
400 #define D_CBC_IDEA 10
401 #define D_CBC_SEED 11
405 #define D_CBC_CAST 15
406 #define D_CBC_128_AES 16
407 #define D_CBC_192_AES 17
408 #define D_CBC_256_AES 18
409 #define D_CBC_128_CML 19
410 #define D_CBC_192_CML 20
411 #define D_CBC_256_CML 21
415 #define D_WHIRLPOOL 25
416 #define D_IGE_128_AES 26
417 #define D_IGE_192_AES 27
418 #define D_IGE_256_AES 28
420 static OPT_PAIR doit_choices[] = {
421 #ifndef OPENSSL_NO_MD2
424 #ifndef OPENSSL_NO_MDC2
427 #ifndef OPENSSL_NO_MD4
430 #ifndef OPENSSL_NO_MD5
435 {"sha256", D_SHA256},
436 {"sha512", D_SHA512},
437 #ifndef OPENSSL_NO_WHIRLPOOL
438 {"whirlpool", D_WHIRLPOOL},
440 #ifndef OPENSSL_NO_RMD160
441 {"ripemd", D_RMD160},
442 {"rmd160", D_RMD160},
443 {"ripemd160", D_RMD160},
445 #ifndef OPENSSL_NO_RC4
448 #ifndef OPENSSL_NO_DES
449 {"des-cbc", D_CBC_DES},
450 {"des-ede3", D_EDE3_DES},
452 {"aes-128-cbc", D_CBC_128_AES},
453 {"aes-192-cbc", D_CBC_192_AES},
454 {"aes-256-cbc", D_CBC_256_AES},
455 {"aes-128-ige", D_IGE_128_AES},
456 {"aes-192-ige", D_IGE_192_AES},
457 {"aes-256-ige", D_IGE_256_AES},
458 #ifndef OPENSSL_NO_RC2
459 {"rc2-cbc", D_CBC_RC2},
462 #ifndef OPENSSL_NO_RC5
463 {"rc5-cbc", D_CBC_RC5},
466 #ifndef OPENSSL_NO_IDEA
467 {"idea-cbc", D_CBC_IDEA},
468 {"idea", D_CBC_IDEA},
470 #ifndef OPENSSL_NO_SEED
471 {"seed-cbc", D_CBC_SEED},
472 {"seed", D_CBC_SEED},
474 #ifndef OPENSSL_NO_BF
475 {"bf-cbc", D_CBC_BF},
476 {"blowfish", D_CBC_BF},
479 #ifndef OPENSSL_NO_CAST
480 {"cast-cbc", D_CBC_CAST},
481 {"cast", D_CBC_CAST},
482 {"cast5", D_CBC_CAST},
488 #ifndef OPENSSL_NO_DSA
490 # define R_DSA_1024 1
491 # define R_DSA_2048 2
492 static OPT_PAIR dsa_choices[] = {
493 {"dsa512", R_DSA_512},
494 {"dsa1024", R_DSA_1024},
495 {"dsa2048", R_DSA_2048},
506 #define R_RSA_15360 6
507 static OPT_PAIR rsa_choices[] = {
508 {"rsa512", R_RSA_512},
509 {"rsa1024", R_RSA_1024},
510 {"rsa2048", R_RSA_2048},
511 {"rsa3072", R_RSA_3072},
512 {"rsa4096", R_RSA_4096},
513 {"rsa7680", R_RSA_7680},
514 {"rsa15360", R_RSA_15360},
534 #define R_EC_X25519 16
535 #ifndef OPENSSL_NO_EC
536 static OPT_PAIR ecdsa_choices[] = {
537 {"ecdsap160", R_EC_P160},
538 {"ecdsap192", R_EC_P192},
539 {"ecdsap224", R_EC_P224},
540 {"ecdsap256", R_EC_P256},
541 {"ecdsap384", R_EC_P384},
542 {"ecdsap521", R_EC_P521},
543 {"ecdsak163", R_EC_K163},
544 {"ecdsak233", R_EC_K233},
545 {"ecdsak283", R_EC_K283},
546 {"ecdsak409", R_EC_K409},
547 {"ecdsak571", R_EC_K571},
548 {"ecdsab163", R_EC_B163},
549 {"ecdsab233", R_EC_B233},
550 {"ecdsab283", R_EC_B283},
551 {"ecdsab409", R_EC_B409},
552 {"ecdsab571", R_EC_B571},
556 static OPT_PAIR ecdh_choices[] = {
557 {"ecdhp160", R_EC_P160},
558 {"ecdhp192", R_EC_P192},
559 {"ecdhp224", R_EC_P224},
560 {"ecdhp256", R_EC_P256},
561 {"ecdhp384", R_EC_P384},
562 {"ecdhp521", R_EC_P521},
563 {"ecdhk163", R_EC_K163},
564 {"ecdhk233", R_EC_K233},
565 {"ecdhk283", R_EC_K283},
566 {"ecdhk409", R_EC_K409},
567 {"ecdhk571", R_EC_K571},
568 {"ecdhb163", R_EC_B163},
569 {"ecdhb233", R_EC_B233},
570 {"ecdhb283", R_EC_B283},
571 {"ecdhb409", R_EC_B409},
572 {"ecdhb571", R_EC_B571},
573 {"ecdhx25519", R_EC_X25519},
579 # define COND(d) (count < (d))
580 # define COUNT(d) (d)
582 # define COND(unused_cond) (run && count<0x7fffffff)
583 # define COUNT(d) (count)
588 /* Nb of iterations to do per algorithm and key-size */
589 static long c[ALGOR_NUM][SIZE_NUM];
591 #ifndef OPENSSL_NO_MD2
592 static int EVP_Digest_MD2_loop(void *args)
594 loopargs_t *tempargs = *(loopargs_t **)args;
595 unsigned char *buf = tempargs->buf;
596 unsigned char md2[MD2_DIGEST_LENGTH];
599 for (count = 0; COND(c[D_MD2][testnum]); count++) {
600 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
608 #ifndef OPENSSL_NO_MDC2
609 static int EVP_Digest_MDC2_loop(void *args)
611 loopargs_t *tempargs = *(loopargs_t **)args;
612 unsigned char *buf = tempargs->buf;
613 unsigned char mdc2[MDC2_DIGEST_LENGTH];
616 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
617 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
625 #ifndef OPENSSL_NO_MD4
626 static int EVP_Digest_MD4_loop(void *args)
628 loopargs_t *tempargs = *(loopargs_t **)args;
629 unsigned char *buf = tempargs->buf;
630 unsigned char md4[MD4_DIGEST_LENGTH];
633 for (count = 0; COND(c[D_MD4][testnum]); count++) {
634 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
642 #ifndef OPENSSL_NO_MD5
643 static int MD5_loop(void *args)
645 loopargs_t *tempargs = *(loopargs_t **)args;
646 unsigned char *buf = tempargs->buf;
647 unsigned char md5[MD5_DIGEST_LENGTH];
649 for (count = 0; COND(c[D_MD5][testnum]); count++)
650 MD5(buf, lengths[testnum], md5);
654 static int HMAC_loop(void *args)
656 loopargs_t *tempargs = *(loopargs_t **)args;
657 unsigned char *buf = tempargs->buf;
658 HMAC_CTX *hctx = tempargs->hctx;
659 unsigned char hmac[MD5_DIGEST_LENGTH];
662 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
663 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
664 HMAC_Update(hctx, buf, lengths[testnum]);
665 HMAC_Final(hctx, hmac, NULL);
671 static int SHA1_loop(void *args)
673 loopargs_t *tempargs = *(loopargs_t **)args;
674 unsigned char *buf = tempargs->buf;
675 unsigned char sha[SHA_DIGEST_LENGTH];
677 for (count = 0; COND(c[D_SHA1][testnum]); count++)
678 SHA1(buf, lengths[testnum], sha);
682 static int SHA256_loop(void *args)
684 loopargs_t *tempargs = *(loopargs_t **)args;
685 unsigned char *buf = tempargs->buf;
686 unsigned char sha256[SHA256_DIGEST_LENGTH];
688 for (count = 0; COND(c[D_SHA256][testnum]); count++)
689 SHA256(buf, lengths[testnum], sha256);
693 static int SHA512_loop(void *args)
695 loopargs_t *tempargs = *(loopargs_t **)args;
696 unsigned char *buf = tempargs->buf;
697 unsigned char sha512[SHA512_DIGEST_LENGTH];
699 for (count = 0; COND(c[D_SHA512][testnum]); count++)
700 SHA512(buf, lengths[testnum], sha512);
704 #ifndef OPENSSL_NO_WHIRLPOOL
705 static int WHIRLPOOL_loop(void *args)
707 loopargs_t *tempargs = *(loopargs_t **)args;
708 unsigned char *buf = tempargs->buf;
709 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
711 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
712 WHIRLPOOL(buf, lengths[testnum], whirlpool);
717 #ifndef OPENSSL_NO_RMD160
718 static int EVP_Digest_RMD160_loop(void *args)
720 loopargs_t *tempargs = *(loopargs_t **)args;
721 unsigned char *buf = tempargs->buf;
722 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
724 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
725 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
726 NULL, EVP_ripemd160(), NULL))
733 #ifndef OPENSSL_NO_RC4
734 static RC4_KEY rc4_ks;
735 static int RC4_loop(void *args)
737 loopargs_t *tempargs = *(loopargs_t **)args;
738 unsigned char *buf = tempargs->buf;
740 for (count = 0; COND(c[D_RC4][testnum]); count++)
741 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
746 #ifndef OPENSSL_NO_DES
747 static unsigned char DES_iv[8];
748 static DES_key_schedule sch;
749 static DES_key_schedule sch2;
750 static DES_key_schedule sch3;
751 static int DES_ncbc_encrypt_loop(void *args)
753 loopargs_t *tempargs = *(loopargs_t **)args;
754 unsigned char *buf = tempargs->buf;
756 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
757 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
758 &DES_iv, DES_ENCRYPT);
762 static int DES_ede3_cbc_encrypt_loop(void *args)
764 loopargs_t *tempargs = *(loopargs_t **)args;
765 unsigned char *buf = tempargs->buf;
767 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
768 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
770 &DES_iv, DES_ENCRYPT);
775 #define MAX_BLOCK_SIZE 128
777 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
778 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
779 static int AES_cbc_128_encrypt_loop(void *args)
781 loopargs_t *tempargs = *(loopargs_t **)args;
782 unsigned char *buf = tempargs->buf;
784 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
785 AES_cbc_encrypt(buf, buf,
786 (size_t)lengths[testnum], &aes_ks1,
791 static int AES_cbc_192_encrypt_loop(void *args)
793 loopargs_t *tempargs = *(loopargs_t **)args;
794 unsigned char *buf = tempargs->buf;
796 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
797 AES_cbc_encrypt(buf, buf,
798 (size_t)lengths[testnum], &aes_ks2,
803 static int AES_cbc_256_encrypt_loop(void *args)
805 loopargs_t *tempargs = *(loopargs_t **)args;
806 unsigned char *buf = tempargs->buf;
808 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
809 AES_cbc_encrypt(buf, buf,
810 (size_t)lengths[testnum], &aes_ks3,
815 static int AES_ige_128_encrypt_loop(void *args)
817 loopargs_t *tempargs = *(loopargs_t **)args;
818 unsigned char *buf = tempargs->buf;
819 unsigned char *buf2 = tempargs->buf2;
821 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
822 AES_ige_encrypt(buf, buf2,
823 (size_t)lengths[testnum], &aes_ks1,
828 static int AES_ige_192_encrypt_loop(void *args)
830 loopargs_t *tempargs = *(loopargs_t **)args;
831 unsigned char *buf = tempargs->buf;
832 unsigned char *buf2 = tempargs->buf2;
834 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
835 AES_ige_encrypt(buf, buf2,
836 (size_t)lengths[testnum], &aes_ks2,
841 static int AES_ige_256_encrypt_loop(void *args)
843 loopargs_t *tempargs = *(loopargs_t **)args;
844 unsigned char *buf = tempargs->buf;
845 unsigned char *buf2 = tempargs->buf2;
847 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
848 AES_ige_encrypt(buf, buf2,
849 (size_t)lengths[testnum], &aes_ks3,
854 static int CRYPTO_gcm128_aad_loop(void *args)
856 loopargs_t *tempargs = *(loopargs_t **)args;
857 unsigned char *buf = tempargs->buf;
858 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
860 for (count = 0; COND(c[D_GHASH][testnum]); count++)
861 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
865 static long save_count = 0;
866 static int decrypt = 0;
867 static int EVP_Update_loop(void *args)
869 loopargs_t *tempargs = *(loopargs_t **)args;
870 unsigned char *buf = tempargs->buf;
871 EVP_CIPHER_CTX *ctx = tempargs->ctx;
874 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
877 for (count = 0; COND(nb_iter); count++)
878 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
880 for (count = 0; COND(nb_iter); count++)
881 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
883 EVP_DecryptFinal_ex(ctx, buf, &outl);
885 EVP_EncryptFinal_ex(ctx, buf, &outl);
889 static const EVP_MD *evp_md = NULL;
890 static int EVP_Digest_loop(void *args)
892 loopargs_t *tempargs = *(loopargs_t **)args;
893 unsigned char *buf = tempargs->buf;
894 unsigned char md[EVP_MAX_MD_SIZE];
897 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
900 for (count = 0; COND(nb_iter); count++) {
901 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
907 #ifndef OPENSSL_NO_RSA
908 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
910 static int RSA_sign_loop(void *args)
912 loopargs_t *tempargs = *(loopargs_t **)args;
913 unsigned char *buf = tempargs->buf;
914 unsigned char *buf2 = tempargs->buf2;
915 unsigned int *rsa_num = &tempargs->siglen;
916 RSA **rsa_key = tempargs->rsa_key;
918 for (count = 0; COND(rsa_c[testnum][0]); count++) {
919 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
921 BIO_printf(bio_err, "RSA sign failure\n");
922 ERR_print_errors(bio_err);
930 static int RSA_verify_loop(void *args)
932 loopargs_t *tempargs = *(loopargs_t **)args;
933 unsigned char *buf = tempargs->buf;
934 unsigned char *buf2 = tempargs->buf2;
935 unsigned int rsa_num = tempargs->siglen;
936 RSA **rsa_key = tempargs->rsa_key;
938 for (count = 0; COND(rsa_c[testnum][1]); count++) {
939 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
941 BIO_printf(bio_err, "RSA verify failure\n");
942 ERR_print_errors(bio_err);
951 #ifndef OPENSSL_NO_DSA
952 static long dsa_c[DSA_NUM][2];
953 static int DSA_sign_loop(void *args)
955 loopargs_t *tempargs = *(loopargs_t **)args;
956 unsigned char *buf = tempargs->buf;
957 unsigned char *buf2 = tempargs->buf2;
958 DSA **dsa_key = tempargs->dsa_key;
959 unsigned int *siglen = &tempargs->siglen;
961 for (count = 0; COND(dsa_c[testnum][0]); count++) {
962 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
964 BIO_printf(bio_err, "DSA sign failure\n");
965 ERR_print_errors(bio_err);
973 static int DSA_verify_loop(void *args)
975 loopargs_t *tempargs = *(loopargs_t **)args;
976 unsigned char *buf = tempargs->buf;
977 unsigned char *buf2 = tempargs->buf2;
978 DSA **dsa_key = tempargs->dsa_key;
979 unsigned int siglen = tempargs->siglen;
981 for (count = 0; COND(dsa_c[testnum][1]); count++) {
982 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
984 BIO_printf(bio_err, "DSA verify failure\n");
985 ERR_print_errors(bio_err);
994 #ifndef OPENSSL_NO_EC
995 static long ecdsa_c[EC_NUM][2];
996 static int ECDSA_sign_loop(void *args)
998 loopargs_t *tempargs = *(loopargs_t **)args;
999 unsigned char *buf = tempargs->buf;
1000 EC_KEY **ecdsa = tempargs->ecdsa;
1001 unsigned char *ecdsasig = tempargs->buf2;
1002 unsigned int *ecdsasiglen = &tempargs->siglen;
1004 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1005 ret = ECDSA_sign(0, buf, 20,
1006 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1008 BIO_printf(bio_err, "ECDSA sign failure\n");
1009 ERR_print_errors(bio_err);
1017 static int ECDSA_verify_loop(void *args)
1019 loopargs_t *tempargs = *(loopargs_t **)args;
1020 unsigned char *buf = tempargs->buf;
1021 EC_KEY **ecdsa = tempargs->ecdsa;
1022 unsigned char *ecdsasig = tempargs->buf2;
1023 unsigned int ecdsasiglen = tempargs->siglen;
1025 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1026 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1029 BIO_printf(bio_err, "ECDSA verify failure\n");
1030 ERR_print_errors(bio_err);
1038 /* ******************************************************************** */
1039 static long ecdh_c[EC_NUM][1];
1041 static void ECDH_EVP_derive_key(unsigned char *derived_secret,
1045 if( !EVP_PKEY_derive(ctx, derived_secret, outlen) ) {
1046 /* FIXME: handle errors */
1052 static int ECDH_EVP_derive_key_loop(void *args)
1054 loopargs_t *tempargs = *(loopargs_t **) args;
1055 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1056 unsigned char *derived_secret = tempargs->secret_a;
1058 size_t *outlen = &(tempargs->outlen);
1060 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1061 ECDH_EVP_derive_key(derived_secret, outlen, ctx);
1066 #endif /* OPENSSL_NO_EC */
1068 static int run_benchmark(int async_jobs,
1069 int (*loop_function)(void *), loopargs_t *loopargs)
1071 int job_op_count = 0;
1072 int total_op_count = 0;
1073 int num_inprogress = 0;
1074 int error = 0, i = 0, ret = 0;
1075 OSSL_ASYNC_FD job_fd = 0;
1076 size_t num_job_fds = 0;
1080 if (async_jobs == 0) {
1081 return loop_function((void *)&loopargs);
1084 for (i = 0; i < async_jobs && !error; i++) {
1085 loopargs_t *looparg_item = loopargs + i;
1087 /* Copy pointer content (looparg_t item address) into async context */
1088 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1089 &job_op_count, loop_function,
1090 (void *)&looparg_item, sizeof(looparg_item));
1096 if (job_op_count == -1) {
1099 total_op_count += job_op_count;
1104 BIO_printf(bio_err, "Failure in the job\n");
1105 ERR_print_errors(bio_err);
1111 while (num_inprogress > 0) {
1112 #if defined(OPENSSL_SYS_WINDOWS)
1114 #elif defined(OPENSSL_SYS_UNIX)
1115 int select_result = 0;
1116 OSSL_ASYNC_FD max_fd = 0;
1119 FD_ZERO(&waitfdset);
1121 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1122 if (loopargs[i].inprogress_job == NULL)
1125 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1126 || num_job_fds > 1) {
1127 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1128 ERR_print_errors(bio_err);
1132 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1133 FD_SET(job_fd, &waitfdset);
1134 if (job_fd > max_fd)
1138 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1140 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1141 "Decrease the value of async_jobs\n",
1142 max_fd, FD_SETSIZE);
1143 ERR_print_errors(bio_err);
1148 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1149 if (select_result == -1 && errno == EINTR)
1152 if (select_result == -1) {
1153 BIO_printf(bio_err, "Failure in the select\n");
1154 ERR_print_errors(bio_err);
1159 if (select_result == 0)
1163 for (i = 0; i < async_jobs; i++) {
1164 if (loopargs[i].inprogress_job == NULL)
1167 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1168 || num_job_fds > 1) {
1169 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1170 ERR_print_errors(bio_err);
1174 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1176 #if defined(OPENSSL_SYS_UNIX)
1177 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1179 #elif defined(OPENSSL_SYS_WINDOWS)
1180 if (num_job_fds == 1
1181 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1186 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1187 loopargs[i].wait_ctx, &job_op_count, loop_function,
1188 (void *)(loopargs + i), sizeof(loopargs_t));
1193 if (job_op_count == -1) {
1196 total_op_count += job_op_count;
1199 loopargs[i].inprogress_job = NULL;
1204 loopargs[i].inprogress_job = NULL;
1205 BIO_printf(bio_err, "Failure in the job\n");
1206 ERR_print_errors(bio_err);
1213 return error ? -1 : total_op_count;
1216 int speed_main(int argc, char **argv)
1219 loopargs_t *loopargs = NULL;
1221 int loopargs_len = 0;
1223 const char *engine_id = NULL;
1224 const EVP_CIPHER *evp_cipher = NULL;
1227 int multiblock = 0, pr_header = 0;
1228 int doit[ALGOR_NUM] = { 0 };
1229 int ret = 1, i, k, misalign = 0;
1235 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1236 || !defined(OPENSSL_NO_EC)
1240 /* What follows are the buffers and key material. */
1241 #ifndef OPENSSL_NO_RC5
1244 #ifndef OPENSSL_NO_RC2
1247 #ifndef OPENSSL_NO_IDEA
1248 IDEA_KEY_SCHEDULE idea_ks;
1250 #ifndef OPENSSL_NO_SEED
1251 SEED_KEY_SCHEDULE seed_ks;
1253 #ifndef OPENSSL_NO_BF
1256 #ifndef OPENSSL_NO_CAST
1259 static const unsigned char key16[16] = {
1260 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1261 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1263 static const unsigned char key24[24] = {
1264 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1265 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1266 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1268 static const unsigned char key32[32] = {
1269 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1270 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1271 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1272 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1274 #ifndef OPENSSL_NO_CAMELLIA
1275 static const unsigned char ckey24[24] = {
1276 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1277 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1278 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1280 static const unsigned char ckey32[32] = {
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,
1284 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1286 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1288 #ifndef OPENSSL_NO_DES
1289 static DES_cblock key = {
1290 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1292 static DES_cblock key2 = {
1293 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1295 static DES_cblock key3 = {
1296 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1299 #ifndef OPENSSL_NO_RSA
1300 static const unsigned int rsa_bits[RSA_NUM] = {
1301 512, 1024, 2048, 3072, 4096, 7680, 15360
1303 static const unsigned char *rsa_data[RSA_NUM] = {
1304 test512, test1024, test2048, test3072, test4096, test7680, test15360
1306 static const int rsa_data_length[RSA_NUM] = {
1307 sizeof(test512), sizeof(test1024),
1308 sizeof(test2048), sizeof(test3072),
1309 sizeof(test4096), sizeof(test7680),
1312 int rsa_doit[RSA_NUM] = { 0 };
1314 #ifndef OPENSSL_NO_DSA
1315 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1316 int dsa_doit[DSA_NUM] = { 0 };
1318 #ifndef OPENSSL_NO_EC
1320 * We only test over the following curves as they are representative, To
1321 * add tests over more curves, simply add the curve NID and curve name to
1322 * the following arrays and increase the EC_NUM value accordingly.
1324 static const unsigned int test_curves[EC_NUM] = {
1326 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1327 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1329 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1330 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1331 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1336 static const char *test_curves_names[EC_NUM] = {
1338 "secp160r1", "nistp192", "nistp224",
1339 "nistp256", "nistp384", "nistp521",
1341 "nistk163", "nistk233", "nistk283",
1342 "nistk409", "nistk571", "nistb163",
1343 "nistb233", "nistb283", "nistb409",
1348 static const int test_curves_bits[EC_NUM] = {
1354 571, 253 /* X25519 */
1357 int ecdsa_doit[EC_NUM] = { 0 };
1358 int ecdh_doit[EC_NUM] = { 0 };
1359 #endif /* ndef OPENSSL_NO_EC */
1361 prog = opt_init(argc, argv, speed_options);
1362 while ((o = opt_next()) != OPT_EOF) {
1367 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1370 opt_help(speed_options);
1377 evp_cipher = EVP_get_cipherbyname(opt_arg());
1378 if (evp_cipher == NULL)
1379 evp_md = EVP_get_digestbyname(opt_arg());
1380 if (evp_cipher == NULL && evp_md == NULL) {
1382 "%s: %s is an unknown cipher or digest\n",
1393 * In a forked execution, an engine might need to be
1394 * initialised by each child process, not by the parent.
1395 * So store the name here and run setup_engine() later on.
1397 engine_id = opt_arg();
1401 multi = atoi(opt_arg());
1405 #ifndef OPENSSL_NO_ASYNC
1406 async_jobs = atoi(opt_arg());
1407 if (!ASYNC_is_capable()) {
1409 "%s: async_jobs specified but async not supported\n",
1416 if (!opt_int(opt_arg(), &misalign))
1418 if (misalign > MISALIGN) {
1420 "%s: Maximum offset is %d\n", prog, MISALIGN);
1429 #ifdef OPENSSL_NO_MULTIBLOCK
1431 "%s: -mb specified but multi-block support is disabled\n",
1438 argc = opt_num_rest();
1441 /* Remaining arguments are algorithms. */
1442 for ( ; *argv; argv++) {
1443 if (found(*argv, doit_choices, &i)) {
1447 #ifndef OPENSSL_NO_DES
1448 if (strcmp(*argv, "des") == 0) {
1449 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1453 if (strcmp(*argv, "sha") == 0) {
1454 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1457 #ifndef OPENSSL_NO_RSA
1459 if (strcmp(*argv, "openssl") == 0) {
1460 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1464 if (strcmp(*argv, "rsa") == 0) {
1465 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1466 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1467 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1468 rsa_doit[R_RSA_15360] = 1;
1471 if (found(*argv, rsa_choices, &i)) {
1476 #ifndef OPENSSL_NO_DSA
1477 if (strcmp(*argv, "dsa") == 0) {
1478 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1479 dsa_doit[R_DSA_2048] = 1;
1482 if (found(*argv, dsa_choices, &i)) {
1487 if (strcmp(*argv, "aes") == 0) {
1488 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1489 doit[D_CBC_256_AES] = 1;
1492 #ifndef OPENSSL_NO_CAMELLIA
1493 if (strcmp(*argv, "camellia") == 0) {
1494 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1495 doit[D_CBC_256_CML] = 1;
1499 #ifndef OPENSSL_NO_EC
1500 if (strcmp(*argv, "ecdsa") == 0) {
1501 for (i = 0; i < EC_NUM; i++)
1505 if (found(*argv, ecdsa_choices, &i)) {
1509 if (strcmp(*argv, "ecdh") == 0) {
1510 for (i = 0; i < EC_NUM; i++)
1514 if (found(*argv, ecdh_choices, &i)) {
1519 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1523 /* Initialize the job pool if async mode is enabled */
1524 if (async_jobs > 0) {
1525 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1527 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1532 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1533 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1534 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1536 for (i = 0; i < loopargs_len; i++) {
1537 if (async_jobs > 0) {
1538 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1539 if (loopargs[i].wait_ctx == NULL) {
1540 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1545 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1546 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1547 /* Align the start of buffers on a 64 byte boundary */
1548 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1549 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1550 #ifndef OPENSSL_NO_EC
1551 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1552 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1557 if (multi && do_multi(multi))
1561 /* Initialize the engine after the fork */
1562 e = setup_engine(engine_id, 0);
1564 /* No parameters; turn on everything. */
1565 if ((argc == 0) && !doit[D_EVP]) {
1566 for (i = 0; i < ALGOR_NUM; i++)
1569 #ifndef OPENSSL_NO_RSA
1570 for (i = 0; i < RSA_NUM; i++)
1573 #ifndef OPENSSL_NO_DSA
1574 for (i = 0; i < DSA_NUM; i++)
1577 #ifndef OPENSSL_NO_EC
1578 for (i = 0; i < EC_NUM; i++)
1580 for (i = 0; i < EC_NUM; i++)
1584 for (i = 0; i < ALGOR_NUM; i++)
1588 if (usertime == 0 && !mr)
1590 "You have chosen to measure elapsed time "
1591 "instead of user CPU time.\n");
1593 #ifndef OPENSSL_NO_RSA
1594 for (i = 0; i < loopargs_len; i++) {
1595 for (k = 0; k < RSA_NUM; k++) {
1596 const unsigned char *p;
1599 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1600 if (loopargs[i].rsa_key[k] == NULL) {
1601 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1608 #ifndef OPENSSL_NO_DSA
1609 for (i = 0; i < loopargs_len; i++) {
1610 loopargs[i].dsa_key[0] = get_dsa512();
1611 loopargs[i].dsa_key[1] = get_dsa1024();
1612 loopargs[i].dsa_key[2] = get_dsa2048();
1615 #ifndef OPENSSL_NO_DES
1616 DES_set_key_unchecked(&key, &sch);
1617 DES_set_key_unchecked(&key2, &sch2);
1618 DES_set_key_unchecked(&key3, &sch3);
1620 AES_set_encrypt_key(key16, 128, &aes_ks1);
1621 AES_set_encrypt_key(key24, 192, &aes_ks2);
1622 AES_set_encrypt_key(key32, 256, &aes_ks3);
1623 #ifndef OPENSSL_NO_CAMELLIA
1624 Camellia_set_key(key16, 128, &camellia_ks1);
1625 Camellia_set_key(ckey24, 192, &camellia_ks2);
1626 Camellia_set_key(ckey32, 256, &camellia_ks3);
1628 #ifndef OPENSSL_NO_IDEA
1629 IDEA_set_encrypt_key(key16, &idea_ks);
1631 #ifndef OPENSSL_NO_SEED
1632 SEED_set_key(key16, &seed_ks);
1634 #ifndef OPENSSL_NO_RC4
1635 RC4_set_key(&rc4_ks, 16, key16);
1637 #ifndef OPENSSL_NO_RC2
1638 RC2_set_key(&rc2_ks, 16, key16, 128);
1640 #ifndef OPENSSL_NO_RC5
1641 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1643 #ifndef OPENSSL_NO_BF
1644 BF_set_key(&bf_ks, 16, key16);
1646 #ifndef OPENSSL_NO_CAST
1647 CAST_set_key(&cast_ks, 16, key16);
1650 # ifndef OPENSSL_NO_DES
1651 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1657 for (it = count; it; it--)
1658 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1659 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1663 c[D_MD2][0] = count / 10;
1664 c[D_MDC2][0] = count / 10;
1665 c[D_MD4][0] = count;
1666 c[D_MD5][0] = count;
1667 c[D_HMAC][0] = count;
1668 c[D_SHA1][0] = count;
1669 c[D_RMD160][0] = count;
1670 c[D_RC4][0] = count * 5;
1671 c[D_CBC_DES][0] = count;
1672 c[D_EDE3_DES][0] = count / 3;
1673 c[D_CBC_IDEA][0] = count;
1674 c[D_CBC_SEED][0] = count;
1675 c[D_CBC_RC2][0] = count;
1676 c[D_CBC_RC5][0] = count;
1677 c[D_CBC_BF][0] = count;
1678 c[D_CBC_CAST][0] = count;
1679 c[D_CBC_128_AES][0] = count;
1680 c[D_CBC_192_AES][0] = count;
1681 c[D_CBC_256_AES][0] = count;
1682 c[D_CBC_128_CML][0] = count;
1683 c[D_CBC_192_CML][0] = count;
1684 c[D_CBC_256_CML][0] = count;
1685 c[D_SHA256][0] = count;
1686 c[D_SHA512][0] = count;
1687 c[D_WHIRLPOOL][0] = count;
1688 c[D_IGE_128_AES][0] = count;
1689 c[D_IGE_192_AES][0] = count;
1690 c[D_IGE_256_AES][0] = count;
1691 c[D_GHASH][0] = count;
1693 for (i = 1; i < SIZE_NUM; i++) {
1696 l0 = (long)lengths[0];
1697 l1 = (long)lengths[i];
1699 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1700 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1701 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1702 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1703 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1704 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1705 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1706 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1707 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1708 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1709 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1711 l0 = (long)lengths[i - 1];
1713 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1714 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1715 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1716 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1717 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1718 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1719 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1720 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1721 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1722 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1723 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1724 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1725 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1726 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1727 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1728 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1729 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1730 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1733 # ifndef OPENSSL_NO_RSA
1734 rsa_c[R_RSA_512][0] = count / 2000;
1735 rsa_c[R_RSA_512][1] = count / 400;
1736 for (i = 1; i < RSA_NUM; i++) {
1737 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1738 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1739 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1742 if (rsa_c[i][0] == 0) {
1743 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1750 # ifndef OPENSSL_NO_DSA
1751 dsa_c[R_DSA_512][0] = count / 1000;
1752 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1753 for (i = 1; i < DSA_NUM; i++) {
1754 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1755 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1756 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1759 if (dsa_c[i][0] == 0) {
1760 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1767 # ifndef OPENSSL_NO_EC
1768 ecdsa_c[R_EC_P160][0] = count / 1000;
1769 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1770 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1771 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1772 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1773 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1776 if (ecdsa_c[i][0] == 0) {
1782 ecdsa_c[R_EC_K163][0] = count / 1000;
1783 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1784 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1785 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1786 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1787 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1790 if (ecdsa_c[i][0] == 0) {
1796 ecdsa_c[R_EC_B163][0] = count / 1000;
1797 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1798 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1799 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1800 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1801 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1804 if (ecdsa_c[i][0] == 0) {
1811 ecdh_c[R_EC_P160][0] = count / 1000;
1812 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1813 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1814 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1817 if (ecdh_c[i][0] == 0) {
1822 ecdh_c[R_EC_K163][0] = count / 1000;
1823 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1824 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1825 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1828 if (ecdh_c[i][0] == 0) {
1833 ecdh_c[R_EC_B163][0] = count / 1000;
1834 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1835 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1836 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1839 if (ecdh_c[i][0] == 0) {
1847 /* not worth fixing */
1848 # error "You cannot disable DES on systems without SIGALRM."
1849 # endif /* OPENSSL_NO_DES */
1852 signal(SIGALRM, sig_done);
1854 #endif /* SIGALRM */
1856 #ifndef OPENSSL_NO_MD2
1858 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1859 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1861 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1863 print_result(D_MD2, testnum, count, d);
1867 #ifndef OPENSSL_NO_MDC2
1869 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1870 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1872 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1874 print_result(D_MDC2, testnum, count, d);
1879 #ifndef OPENSSL_NO_MD4
1881 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1882 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1884 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1886 print_result(D_MD4, testnum, count, d);
1891 #ifndef OPENSSL_NO_MD5
1893 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1894 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1896 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1898 print_result(D_MD5, testnum, count, d);
1903 static const char hmac_key[] = "This is a key...";
1904 int len = strlen(hmac_key);
1906 for (i = 0; i < loopargs_len; i++) {
1907 loopargs[i].hctx = HMAC_CTX_new();
1908 if (loopargs[i].hctx == NULL) {
1909 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1913 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1915 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1916 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1918 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1920 print_result(D_HMAC, testnum, count, d);
1922 for (i = 0; i < loopargs_len; i++) {
1923 HMAC_CTX_free(loopargs[i].hctx);
1928 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1929 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1931 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1933 print_result(D_SHA1, testnum, count, d);
1936 if (doit[D_SHA256]) {
1937 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1938 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
1940 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1942 print_result(D_SHA256, testnum, count, d);
1945 if (doit[D_SHA512]) {
1946 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1947 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
1949 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1951 print_result(D_SHA512, testnum, count, d);
1955 #ifndef OPENSSL_NO_WHIRLPOOL
1956 if (doit[D_WHIRLPOOL]) {
1957 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1958 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
1960 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1962 print_result(D_WHIRLPOOL, testnum, count, d);
1967 #ifndef OPENSSL_NO_RMD160
1968 if (doit[D_RMD160]) {
1969 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1970 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
1972 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1974 print_result(D_RMD160, testnum, count, d);
1978 #ifndef OPENSSL_NO_RC4
1980 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1981 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1983 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1985 print_result(D_RC4, testnum, count, d);
1989 #ifndef OPENSSL_NO_DES
1990 if (doit[D_CBC_DES]) {
1991 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1992 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
1994 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1996 print_result(D_CBC_DES, testnum, count, d);
2000 if (doit[D_EDE3_DES]) {
2001 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2002 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
2004 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
2006 print_result(D_EDE3_DES, testnum, count, d);
2011 if (doit[D_CBC_128_AES]) {
2012 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2013 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2016 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
2018 print_result(D_CBC_128_AES, testnum, count, d);
2021 if (doit[D_CBC_192_AES]) {
2022 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2023 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2026 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2028 print_result(D_CBC_192_AES, testnum, count, d);
2031 if (doit[D_CBC_256_AES]) {
2032 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2033 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2036 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2038 print_result(D_CBC_256_AES, testnum, count, d);
2042 if (doit[D_IGE_128_AES]) {
2043 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2044 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2047 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2049 print_result(D_IGE_128_AES, testnum, count, d);
2052 if (doit[D_IGE_192_AES]) {
2053 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2054 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2057 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2059 print_result(D_IGE_192_AES, testnum, count, d);
2062 if (doit[D_IGE_256_AES]) {
2063 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2064 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2067 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2069 print_result(D_IGE_256_AES, testnum, count, d);
2072 if (doit[D_GHASH]) {
2073 for (i = 0; i < loopargs_len; i++) {
2074 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2075 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
2078 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2079 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2081 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2083 print_result(D_GHASH, testnum, count, d);
2085 for (i = 0; i < loopargs_len; i++)
2086 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2089 #ifndef OPENSSL_NO_CAMELLIA
2090 if (doit[D_CBC_128_CML]) {
2091 if (async_jobs > 0) {
2092 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2093 names[D_CBC_128_CML]);
2094 doit[D_CBC_128_CML] = 0;
2096 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2097 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2100 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2101 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2102 (size_t)lengths[testnum], &camellia_ks1,
2103 iv, CAMELLIA_ENCRYPT);
2105 print_result(D_CBC_128_CML, testnum, count, d);
2108 if (doit[D_CBC_192_CML]) {
2109 if (async_jobs > 0) {
2110 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2111 names[D_CBC_192_CML]);
2112 doit[D_CBC_192_CML] = 0;
2114 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2115 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2117 if (async_jobs > 0) {
2118 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2122 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2123 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2124 (size_t)lengths[testnum], &camellia_ks2,
2125 iv, CAMELLIA_ENCRYPT);
2127 print_result(D_CBC_192_CML, testnum, count, d);
2130 if (doit[D_CBC_256_CML]) {
2131 if (async_jobs > 0) {
2132 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2133 names[D_CBC_256_CML]);
2134 doit[D_CBC_256_CML] = 0;
2136 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2137 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2140 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2141 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2142 (size_t)lengths[testnum], &camellia_ks3,
2143 iv, CAMELLIA_ENCRYPT);
2145 print_result(D_CBC_256_CML, testnum, count, d);
2149 #ifndef OPENSSL_NO_IDEA
2150 if (doit[D_CBC_IDEA]) {
2151 if (async_jobs > 0) {
2152 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2154 doit[D_CBC_IDEA] = 0;
2156 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2157 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2159 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2160 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2161 (size_t)lengths[testnum], &idea_ks,
2164 print_result(D_CBC_IDEA, testnum, count, d);
2168 #ifndef OPENSSL_NO_SEED
2169 if (doit[D_CBC_SEED]) {
2170 if (async_jobs > 0) {
2171 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2173 doit[D_CBC_SEED] = 0;
2175 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2176 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2178 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2179 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2180 (size_t)lengths[testnum], &seed_ks, iv, 1);
2182 print_result(D_CBC_SEED, testnum, count, d);
2186 #ifndef OPENSSL_NO_RC2
2187 if (doit[D_CBC_RC2]) {
2188 if (async_jobs > 0) {
2189 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2191 doit[D_CBC_RC2] = 0;
2193 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2194 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2195 if (async_jobs > 0) {
2196 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2200 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2201 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2202 (size_t)lengths[testnum], &rc2_ks,
2205 print_result(D_CBC_RC2, testnum, count, d);
2209 #ifndef OPENSSL_NO_RC5
2210 if (doit[D_CBC_RC5]) {
2211 if (async_jobs > 0) {
2212 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2214 doit[D_CBC_RC5] = 0;
2216 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2217 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2218 if (async_jobs > 0) {
2219 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2223 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2224 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2225 (size_t)lengths[testnum], &rc5_ks,
2228 print_result(D_CBC_RC5, testnum, count, d);
2232 #ifndef OPENSSL_NO_BF
2233 if (doit[D_CBC_BF]) {
2234 if (async_jobs > 0) {
2235 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2239 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2240 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2242 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2243 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2244 (size_t)lengths[testnum], &bf_ks,
2247 print_result(D_CBC_BF, testnum, count, d);
2251 #ifndef OPENSSL_NO_CAST
2252 if (doit[D_CBC_CAST]) {
2253 if (async_jobs > 0) {
2254 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2256 doit[D_CBC_CAST] = 0;
2258 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2259 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2261 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2262 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2263 (size_t)lengths[testnum], &cast_ks,
2266 print_result(D_CBC_CAST, testnum, count, d);
2272 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2273 if (multiblock && evp_cipher) {
2275 (EVP_CIPHER_flags(evp_cipher) &
2276 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2277 BIO_printf(bio_err, "%s is not multi-block capable\n",
2278 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2281 if (async_jobs > 0) {
2282 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2285 multiblock_speed(evp_cipher);
2290 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2293 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2295 * -O3 -fschedule-insns messes up an optimization here!
2296 * names[D_EVP] somehow becomes NULL
2298 print_message(names[D_EVP], save_count, lengths[testnum]);
2300 for (k = 0; k < loopargs_len; k++) {
2301 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2303 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2305 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2306 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2310 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2312 for (k = 0; k < loopargs_len; k++) {
2313 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2317 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2318 print_message(names[D_EVP], save_count, lengths[testnum]);
2320 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2323 print_result(D_EVP, testnum, count, d);
2327 for (i = 0; i < loopargs_len; i++)
2328 RAND_bytes(loopargs[i].buf, 36);
2330 #ifndef OPENSSL_NO_RSA
2331 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2333 if (!rsa_doit[testnum])
2335 for (i = 0; i < loopargs_len; i++) {
2336 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2337 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2343 "RSA sign failure. No RSA sign will be done.\n");
2344 ERR_print_errors(bio_err);
2347 pkey_print_message("private", "rsa",
2348 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2349 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2351 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2354 mr ? "+R1:%ld:%d:%.2f\n"
2355 : "%ld %d bit private RSA's in %.2fs\n",
2356 count, rsa_bits[testnum], d);
2357 rsa_results[testnum][0] = d / (double)count;
2361 for (i = 0; i < loopargs_len; i++) {
2362 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2363 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2369 "RSA verify failure. No RSA verify will be done.\n");
2370 ERR_print_errors(bio_err);
2371 rsa_doit[testnum] = 0;
2373 pkey_print_message("public", "rsa",
2374 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
2376 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2379 mr ? "+R2:%ld:%d:%.2f\n"
2380 : "%ld %d bit public RSA's in %.2fs\n",
2381 count, rsa_bits[testnum], d);
2382 rsa_results[testnum][1] = d / (double)count;
2385 if (rsa_count <= 1) {
2386 /* if longer than 10s, don't do any more */
2387 for (testnum++; testnum < RSA_NUM; testnum++)
2388 rsa_doit[testnum] = 0;
2391 #endif /* OPENSSL_NO_RSA */
2393 for (i = 0; i < loopargs_len; i++)
2394 RAND_bytes(loopargs[i].buf, 36);
2396 #ifndef OPENSSL_NO_DSA
2397 if (RAND_status() != 1) {
2398 RAND_seed(rnd_seed, sizeof rnd_seed);
2400 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2402 if (!dsa_doit[testnum])
2405 /* DSA_generate_key(dsa_key[testnum]); */
2406 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2407 for (i = 0; i < loopargs_len; i++) {
2408 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2409 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2415 "DSA sign failure. No DSA sign will be done.\n");
2416 ERR_print_errors(bio_err);
2419 pkey_print_message("sign", "dsa",
2420 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
2422 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2425 mr ? "+R3:%ld:%d:%.2f\n"
2426 : "%ld %d bit DSA signs in %.2fs\n",
2427 count, dsa_bits[testnum], d);
2428 dsa_results[testnum][0] = d / (double)count;
2432 for (i = 0; i < loopargs_len; i++) {
2433 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2434 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2440 "DSA verify failure. No DSA verify will be done.\n");
2441 ERR_print_errors(bio_err);
2442 dsa_doit[testnum] = 0;
2444 pkey_print_message("verify", "dsa",
2445 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
2447 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2450 mr ? "+R4:%ld:%d:%.2f\n"
2451 : "%ld %d bit DSA verify in %.2fs\n",
2452 count, dsa_bits[testnum], d);
2453 dsa_results[testnum][1] = d / (double)count;
2456 if (rsa_count <= 1) {
2457 /* if longer than 10s, don't do any more */
2458 for (testnum++; testnum < DSA_NUM; testnum++)
2459 dsa_doit[testnum] = 0;
2462 #endif /* OPENSSL_NO_DSA */
2464 #ifndef OPENSSL_NO_EC
2465 if (RAND_status() != 1) {
2466 RAND_seed(rnd_seed, sizeof rnd_seed);
2468 for (testnum = 0; testnum < EC_NUM; testnum++) {
2471 if (!ecdsa_doit[testnum])
2472 continue; /* Ignore Curve */
2473 for (i = 0; i < loopargs_len; i++) {
2474 loopargs[i].ecdsa[testnum] = 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, loopargs[i].ecdsa[testnum]);
2496 "ECDSA sign failure. No ECDSA sign will be done.\n");
2497 ERR_print_errors(bio_err);
2500 pkey_print_message("sign", "ecdsa",
2501 ecdsa_c[testnum][0],
2502 test_curves_bits[testnum], ECDSA_SECONDS);
2504 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2508 mr ? "+R5:%ld:%d:%.2f\n" :
2509 "%ld %d bit ECDSA signs in %.2fs \n",
2510 count, test_curves_bits[testnum], d);
2511 ecdsa_results[testnum][0] = d / (double)count;
2515 /* Perform ECDSA verification test */
2516 for (i = 0; i < loopargs_len; i++) {
2517 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2518 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
2524 "ECDSA verify failure. No ECDSA verify will be done.\n");
2525 ERR_print_errors(bio_err);
2526 ecdsa_doit[testnum] = 0;
2528 pkey_print_message("verify", "ecdsa",
2529 ecdsa_c[testnum][1],
2530 test_curves_bits[testnum], ECDSA_SECONDS);
2532 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2535 mr ? "+R6:%ld:%d:%.2f\n"
2536 : "%ld %d bit ECDSA verify in %.2fs\n",
2537 count, test_curves_bits[testnum], d);
2538 ecdsa_results[testnum][1] = d / (double)count;
2541 if (rsa_count <= 1) {
2542 /* if longer than 10s, don't do any more */
2543 for (testnum++; testnum < EC_NUM; testnum++)
2544 ecdsa_doit[testnum] = 0;
2549 if (RAND_status() != 1) {
2550 RAND_seed(rnd_seed, sizeof rnd_seed);
2552 for (testnum = 0; testnum < EC_NUM; testnum++) {
2553 int ecdh_checks = 1;
2555 if (!ecdh_doit[testnum])
2558 for (i = 0; i < loopargs_len; i++) {
2559 EVP_PKEY_CTX *kctx = NULL, *ctx = NULL;
2560 EVP_PKEY *key_A = NULL, *key_B = NULL;
2562 if (testnum == R_EC_X25519) {
2563 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2565 EVP_PKEY_CTX *pctx = NULL;
2566 EVP_PKEY *params = NULL;
2568 if( /* Create the context for parameter generation */
2569 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2570 /* Initialise the parameter generation */
2571 !EVP_PKEY_paramgen_init(pctx) ||
2572 /* Set the curve by NID */
2573 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, test_curves[testnum]) ||
2574 /* Create the parameter object params */
2575 !EVP_PKEY_paramgen(pctx, ¶ms) ||
2578 BIO_printf(bio_err, "ECDH init failure.\n");
2579 ERR_print_errors(bio_err);
2583 /* Create the context for the key generation */
2584 kctx = EVP_PKEY_CTX_new(params, NULL);
2586 EVP_PKEY_free(params); params = NULL;
2587 EVP_PKEY_CTX_free(pctx); pctx = NULL;
2589 if ( !kctx || /* keygen ctx is not null */
2590 !EVP_PKEY_keygen_init(kctx) || /* init keygen ctx */
2593 BIO_printf(bio_err, "ECDH keygen failure.\n");
2594 ERR_print_errors(bio_err);
2599 if ( !EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2600 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2601 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2602 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2603 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2606 BIO_printf(bio_err, "ECDH key generation failure.\n");
2607 ERR_print_errors(bio_err);
2612 loopargs[i].ecdh_ctx[testnum] = ctx;
2614 EVP_PKEY_CTX_free(kctx); kctx = NULL;
2616 if (ecdh_checks != 0) {
2617 pkey_print_message("", "ecdh",
2619 test_curves_bits[testnum], ECDH_SECONDS);
2621 count = run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2624 mr ? "+R7:%ld:%d:%.2f\n" :
2625 "%ld %d-bit ECDH ops in %.2fs\n", count,
2626 test_curves_bits[testnum], d);
2627 ecdh_results[testnum][0] = d / (double)count;
2631 if (rsa_count <= 1) {
2632 /* if longer than 10s, don't do any more */
2633 for (testnum++; testnum < EC_NUM; testnum++)
2634 ecdh_doit[testnum] = 0;
2637 #endif /* OPENSSL_NO_EC */
2642 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2643 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2645 printf("%s ", BN_options());
2646 #ifndef OPENSSL_NO_MD2
2647 printf("%s ", MD2_options());
2649 #ifndef OPENSSL_NO_RC4
2650 printf("%s ", RC4_options());
2652 #ifndef OPENSSL_NO_DES
2653 printf("%s ", DES_options());
2655 printf("%s ", AES_options());
2656 #ifndef OPENSSL_NO_IDEA
2657 printf("%s ", IDEA_options());
2659 #ifndef OPENSSL_NO_BF
2660 printf("%s ", BF_options());
2662 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2670 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2673 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2674 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2678 for (k = 0; k < ALGOR_NUM; k++) {
2682 printf("+F:%d:%s", k, names[k]);
2684 printf("%-13s", names[k]);
2685 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2686 if (results[k][testnum] > 10000 && !mr)
2687 printf(" %11.2fk", results[k][testnum] / 1e3);
2689 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2693 #ifndef OPENSSL_NO_RSA
2695 for (k = 0; k < RSA_NUM; k++) {
2698 if (testnum && !mr) {
2699 printf("%18ssign verify sign/s verify/s\n", " ");
2703 printf("+F2:%u:%u:%f:%f\n",
2704 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2706 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2707 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2708 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2711 #ifndef OPENSSL_NO_DSA
2713 for (k = 0; k < DSA_NUM; k++) {
2716 if (testnum && !mr) {
2717 printf("%18ssign verify sign/s verify/s\n", " ");
2721 printf("+F3:%u:%u:%f:%f\n",
2722 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2724 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2725 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2726 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2729 #ifndef OPENSSL_NO_EC
2731 for (k = 0; k < EC_NUM; k++) {
2734 if (testnum && !mr) {
2735 printf("%30ssign verify sign/s verify/s\n", " ");
2740 printf("+F4:%u:%u:%f:%f\n",
2741 k, test_curves_bits[k],
2742 ecdsa_results[k][0], ecdsa_results[k][1]);
2744 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2745 test_curves_bits[k],
2746 test_curves_names[k],
2747 ecdsa_results[k][0], ecdsa_results[k][1],
2748 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2752 for (k = 0; k < EC_NUM; k++) {
2755 if (testnum && !mr) {
2756 printf("%30sop op/s\n", " ");
2760 printf("+F5:%u:%u:%f:%f\n",
2761 k, test_curves_bits[k],
2762 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2765 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2766 test_curves_bits[k],
2767 test_curves_names[k],
2768 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2775 ERR_print_errors(bio_err);
2776 for (i = 0; i < loopargs_len; i++) {
2777 OPENSSL_free(loopargs[i].buf_malloc);
2778 OPENSSL_free(loopargs[i].buf2_malloc);
2780 #ifndef OPENSSL_NO_RSA
2781 for (k = 0; k < RSA_NUM; k++)
2782 RSA_free(loopargs[i].rsa_key[k]);
2784 #ifndef OPENSSL_NO_DSA
2785 for (k = 0; k < DSA_NUM; k++)
2786 DSA_free(loopargs[i].dsa_key[k]);
2788 #ifndef OPENSSL_NO_EC
2789 for (k = 0; k < EC_NUM; k++) {
2790 EC_KEY_free(loopargs[i].ecdsa[k]);
2791 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2793 OPENSSL_free(loopargs[i].secret_a);
2794 OPENSSL_free(loopargs[i].secret_b);
2798 if (async_jobs > 0) {
2799 for (i = 0; i < loopargs_len; i++)
2800 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2804 ASYNC_cleanup_thread();
2806 OPENSSL_free(loopargs);
2811 static void print_message(const char *s, long num, int length)
2815 mr ? "+DT:%s:%d:%d\n"
2816 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2817 (void)BIO_flush(bio_err);
2821 mr ? "+DN:%s:%ld:%d\n"
2822 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2823 (void)BIO_flush(bio_err);
2827 static void pkey_print_message(const char *str, const char *str2, long num,
2832 mr ? "+DTP:%d:%s:%s:%d\n"
2833 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2834 (void)BIO_flush(bio_err);
2838 mr ? "+DNP:%ld:%d:%s:%s\n"
2839 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2840 (void)BIO_flush(bio_err);
2844 static void print_result(int alg, int run_no, int count, double time_used)
2847 BIO_puts(bio_err, "EVP error!\n");
2851 mr ? "+R:%d:%s:%f\n"
2852 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2853 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2857 static char *sstrsep(char **string, const char *delim)
2860 char *token = *string;
2865 memset(isdelim, 0, sizeof isdelim);
2869 isdelim[(unsigned char)(*delim)] = 1;
2873 while (!isdelim[(unsigned char)(**string)]) {
2885 static int do_multi(int multi)
2890 static char sep[] = ":";
2892 fds = malloc(sizeof(*fds) * multi);
2893 for (n = 0; n < multi; ++n) {
2894 if (pipe(fd) == -1) {
2895 BIO_printf(bio_err, "pipe failure\n");
2899 (void)BIO_flush(bio_err);
2906 if (dup(fd[1]) == -1) {
2907 BIO_printf(bio_err, "dup failed\n");
2916 printf("Forked child %d\n", n);
2919 /* for now, assume the pipe is long enough to take all the output */
2920 for (n = 0; n < multi; ++n) {
2925 f = fdopen(fds[n], "r");
2926 while (fgets(buf, sizeof buf, f)) {
2927 p = strchr(buf, '\n');
2930 if (buf[0] != '+') {
2931 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
2935 printf("Got: %s from %d\n", buf, n);
2936 if (strncmp(buf, "+F:", 3) == 0) {
2941 alg = atoi(sstrsep(&p, sep));
2943 for (j = 0; j < SIZE_NUM; ++j)
2944 results[alg][j] += atof(sstrsep(&p, sep));
2945 } else if (strncmp(buf, "+F2:", 4) == 0) {
2950 k = atoi(sstrsep(&p, sep));
2953 d = atof(sstrsep(&p, sep));
2955 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2957 rsa_results[k][0] = d;
2959 d = atof(sstrsep(&p, sep));
2961 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2963 rsa_results[k][1] = d;
2965 # ifndef OPENSSL_NO_DSA
2966 else if (strncmp(buf, "+F3:", 4) == 0) {
2971 k = atoi(sstrsep(&p, sep));
2974 d = atof(sstrsep(&p, sep));
2976 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2978 dsa_results[k][0] = d;
2980 d = atof(sstrsep(&p, sep));
2982 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2984 dsa_results[k][1] = d;
2987 # ifndef OPENSSL_NO_EC
2988 else if (strncmp(buf, "+F4:", 4) == 0) {
2993 k = atoi(sstrsep(&p, sep));
2996 d = atof(sstrsep(&p, sep));
2998 ecdsa_results[k][0] =
2999 1 / (1 / ecdsa_results[k][0] + 1 / d);
3001 ecdsa_results[k][0] = d;
3003 d = atof(sstrsep(&p, sep));
3005 ecdsa_results[k][1] =
3006 1 / (1 / ecdsa_results[k][1] + 1 / d);
3008 ecdsa_results[k][1] = d;
3009 } else if (strncmp(buf, "+F5:", 4) == 0) {
3014 k = atoi(sstrsep(&p, sep));
3017 d = atof(sstrsep(&p, sep));
3019 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3021 ecdh_results[k][0] = d;
3026 else if (strncmp(buf, "+H:", 3) == 0) {
3029 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
3039 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3041 static int mblengths[] =
3042 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3043 int j, count, num = OSSL_NELEM(mblengths);
3044 const char *alg_name;
3045 unsigned char *inp, *out, no_key[32], no_iv[16];
3046 EVP_CIPHER_CTX *ctx;
3049 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3050 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3051 ctx = EVP_CIPHER_CTX_new();
3052 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3053 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
3055 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3057 for (j = 0; j < num; j++) {
3058 print_message(alg_name, 0, mblengths[j]);
3060 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3061 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3062 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3063 size_t len = mblengths[j];
3066 memset(aad, 0, 8); /* avoid uninitialized values */
3067 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3068 aad[9] = 3; /* version */
3070 aad[11] = 0; /* length */
3072 mb_param.out = NULL;
3075 mb_param.interleave = 8;
3077 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3078 sizeof(mb_param), &mb_param);
3084 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3085 sizeof(mb_param), &mb_param);
3089 RAND_bytes(out, 16);
3093 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3094 EVP_AEAD_TLS1_AAD_LEN, aad);
3095 EVP_Cipher(ctx, out, inp, len + pad);
3099 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3100 : "%d %s's in %.2fs\n", count, "evp", d);
3101 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3105 fprintf(stdout, "+H");
3106 for (j = 0; j < num; j++)
3107 fprintf(stdout, ":%d", mblengths[j]);
3108 fprintf(stdout, "\n");
3109 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3110 for (j = 0; j < num; j++)
3111 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3112 fprintf(stdout, "\n");
3115 "The 'numbers' are in 1000s of bytes per second processed.\n");
3116 fprintf(stdout, "type ");
3117 for (j = 0; j < num; j++)
3118 fprintf(stdout, "%7d bytes", mblengths[j]);
3119 fprintf(stdout, "\n");
3120 fprintf(stdout, "%-24s", alg_name);
3122 for (j = 0; j < num; j++) {
3123 if (results[D_EVP][j] > 10000)
3124 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3126 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3128 fprintf(stdout, "\n");
3133 EVP_CIPHER_CTX_free(ctx);