2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the OpenSSL license (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #define RSA_SECONDS 10
14 #define DSA_SECONDS 10
15 #define ECDSA_SECONDS 10
16 #define ECDH_SECONDS 10
23 #include <openssl/crypto.h>
24 #include <openssl/rand.h>
25 #include <openssl/err.h>
26 #include <openssl/evp.h>
27 #include <openssl/objects.h>
28 #include <openssl/async.h>
29 #if !defined(OPENSSL_SYS_MSDOS)
30 # include OPENSSL_UNISTD
37 #include <openssl/bn.h>
38 #ifndef OPENSSL_NO_DES
39 # include <openssl/des.h>
41 #include <openssl/aes.h>
42 #ifndef OPENSSL_NO_CAMELLIA
43 # include <openssl/camellia.h>
45 #ifndef OPENSSL_NO_MD2
46 # include <openssl/md2.h>
48 #ifndef OPENSSL_NO_MDC2
49 # include <openssl/mdc2.h>
51 #ifndef OPENSSL_NO_MD4
52 # include <openssl/md4.h>
54 #ifndef OPENSSL_NO_MD5
55 # include <openssl/md5.h>
57 #include <openssl/hmac.h>
58 #include <openssl/sha.h>
59 #ifndef OPENSSL_NO_RMD160
60 # include <openssl/ripemd.h>
62 #ifndef OPENSSL_NO_WHIRLPOOL
63 # include <openssl/whrlpool.h>
65 #ifndef OPENSSL_NO_RC4
66 # include <openssl/rc4.h>
68 #ifndef OPENSSL_NO_RC5
69 # include <openssl/rc5.h>
71 #ifndef OPENSSL_NO_RC2
72 # include <openssl/rc2.h>
74 #ifndef OPENSSL_NO_IDEA
75 # include <openssl/idea.h>
77 #ifndef OPENSSL_NO_SEED
78 # include <openssl/seed.h>
81 # include <openssl/blowfish.h>
83 #ifndef OPENSSL_NO_CAST
84 # include <openssl/cast.h>
86 #ifndef OPENSSL_NO_RSA
87 # include <openssl/rsa.h>
88 # include "./testrsa.h"
90 #include <openssl/x509.h>
91 #ifndef OPENSSL_NO_DSA
92 # include <openssl/dsa.h>
93 # include "./testdsa.h"
96 # include <openssl/ec.h>
98 #include <openssl/modes.h>
101 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
115 #define BUFSIZE (1024*16+1)
116 #define MAX_MISALIGNMENT 63
124 #define MAX_ECDH_SIZE 256
127 static volatile int run = 0;
130 static int usertime = 1;
132 typedef struct loopargs_st {
133 ASYNC_JOB *inprogress_job;
134 ASYNC_WAIT_CTX *wait_ctx;
137 unsigned char *buf_malloc;
138 unsigned char *buf2_malloc;
140 #ifndef OPENSSL_NO_RSA
141 RSA *rsa_key[RSA_NUM];
143 #ifndef OPENSSL_NO_DSA
144 DSA *dsa_key[DSA_NUM];
146 #ifndef OPENSSL_NO_EC
147 EC_KEY *ecdsa[EC_NUM];
148 EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
149 unsigned char *secret_a;
150 unsigned char *secret_b;
151 size_t outlen[EC_NUM];
155 GCM128_CONTEXT *gcm_ctx;
158 #ifndef OPENSSL_NO_MD2
159 static int EVP_Digest_MD2_loop(void *args);
162 #ifndef OPENSSL_NO_MDC2
163 static int EVP_Digest_MDC2_loop(void *args);
165 #ifndef OPENSSL_NO_MD4
166 static int EVP_Digest_MD4_loop(void *args);
168 #ifndef OPENSSL_NO_MD5
169 static int MD5_loop(void *args);
170 static int HMAC_loop(void *args);
172 static int SHA1_loop(void *args);
173 static int SHA256_loop(void *args);
174 static int SHA512_loop(void *args);
175 #ifndef OPENSSL_NO_WHIRLPOOL
176 static int WHIRLPOOL_loop(void *args);
178 #ifndef OPENSSL_NO_RMD160
179 static int EVP_Digest_RMD160_loop(void *args);
181 #ifndef OPENSSL_NO_RC4
182 static int RC4_loop(void *args);
184 #ifndef OPENSSL_NO_DES
185 static int DES_ncbc_encrypt_loop(void *args);
186 static int DES_ede3_cbc_encrypt_loop(void *args);
188 static int AES_cbc_128_encrypt_loop(void *args);
189 static int AES_cbc_192_encrypt_loop(void *args);
190 static int AES_ige_128_encrypt_loop(void *args);
191 static int AES_cbc_256_encrypt_loop(void *args);
192 static int AES_ige_192_encrypt_loop(void *args);
193 static int AES_ige_256_encrypt_loop(void *args);
194 static int CRYPTO_gcm128_aad_loop(void *args);
195 static int EVP_Update_loop(void *args);
196 static int EVP_Digest_loop(void *args);
197 #ifndef OPENSSL_NO_RSA
198 static int RSA_sign_loop(void *args);
199 static int RSA_verify_loop(void *args);
201 #ifndef OPENSSL_NO_DSA
202 static int DSA_sign_loop(void *args);
203 static int DSA_verify_loop(void *args);
205 #ifndef OPENSSL_NO_EC
206 static int ECDSA_sign_loop(void *args);
207 static int ECDSA_verify_loop(void *args);
209 static int run_benchmark(int async_jobs, int (*loop_function) (void *),
210 loopargs_t * loopargs);
212 static double Time_F(int s);
213 static void print_message(const char *s, long num, int length);
214 static void pkey_print_message(const char *str, const char *str2,
215 long num, int bits, int sec);
216 static void print_result(int alg, int run_no, int count, double time_used);
218 static int do_multi(int multi);
221 static const char *names[ALGOR_NUM] = {
222 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
223 "des cbc", "des ede3", "idea cbc", "seed cbc",
224 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
225 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
226 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
227 "evp", "sha256", "sha512", "whirlpool",
228 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
231 static double results[ALGOR_NUM][SIZE_NUM];
233 static const int lengths[SIZE_NUM] = {
234 16, 64, 256, 1024, 8 * 1024, 16 * 1024
237 #ifndef OPENSSL_NO_RSA
238 static double rsa_results[RSA_NUM][2];
240 #ifndef OPENSSL_NO_DSA
241 static double dsa_results[DSA_NUM][2];
243 #ifndef OPENSSL_NO_EC
244 static double ecdsa_results[EC_NUM][2];
245 static double ecdh_results[EC_NUM][1];
249 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
250 # define SIGRETTYPE void
252 # define SIGRETTYPE int
255 static SIGRETTYPE sig_done(int sig);
256 static SIGRETTYPE sig_done(int sig)
258 signal(SIGALRM, sig_done);
268 # if !defined(SIGALRM)
271 static unsigned int lapse;
272 static volatile unsigned int schlock;
273 static void alarm_win32(unsigned int secs)
278 # define alarm alarm_win32
280 static DWORD WINAPI sleepy(VOID * arg)
288 static double Time_F(int s)
295 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
297 DWORD err = GetLastError();
298 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
302 Sleep(0); /* scheduler spinlock */
303 ret = app_tminterval(s, usertime);
305 ret = app_tminterval(s, usertime);
307 TerminateThread(thr, 0);
315 static double Time_F(int s)
317 double ret = app_tminterval(s, usertime);
324 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
326 static int found(const char *name, const OPT_PAIR *pairs, int *result)
328 for (; pairs->name; pairs++)
329 if (strcmp(name, pairs->name) == 0) {
330 *result = pairs->retval;
336 typedef enum OPTION_choice {
337 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
338 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
339 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM
342 const OPTIONS speed_options[] = {
343 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
344 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
345 {"help", OPT_HELP, '-', "Display this summary"},
346 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
347 {"decrypt", OPT_DECRYPT, '-',
348 "Time decryption instead of encryption (only EVP)"},
349 {"mr", OPT_MR, '-', "Produce machine readable output"},
351 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
352 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
353 {"elapsed", OPT_ELAPSED, '-',
354 "Measure time in real time instead of CPU user time"},
356 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
358 #ifndef OPENSSL_NO_ASYNC
359 {"async_jobs", OPT_ASYNCJOBS, 'p',
360 "Enable async mode and start pnum jobs"},
363 #ifndef OPENSSL_NO_ENGINE
364 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
379 #define D_CBC_IDEA 10
380 #define D_CBC_SEED 11
384 #define D_CBC_CAST 15
385 #define D_CBC_128_AES 16
386 #define D_CBC_192_AES 17
387 #define D_CBC_256_AES 18
388 #define D_CBC_128_CML 19
389 #define D_CBC_192_CML 20
390 #define D_CBC_256_CML 21
394 #define D_WHIRLPOOL 25
395 #define D_IGE_128_AES 26
396 #define D_IGE_192_AES 27
397 #define D_IGE_256_AES 28
399 static OPT_PAIR doit_choices[] = {
400 #ifndef OPENSSL_NO_MD2
403 #ifndef OPENSSL_NO_MDC2
406 #ifndef OPENSSL_NO_MD4
409 #ifndef OPENSSL_NO_MD5
414 {"sha256", D_SHA256},
415 {"sha512", D_SHA512},
416 #ifndef OPENSSL_NO_WHIRLPOOL
417 {"whirlpool", D_WHIRLPOOL},
419 #ifndef OPENSSL_NO_RMD160
420 {"ripemd", D_RMD160},
421 {"rmd160", D_RMD160},
422 {"ripemd160", D_RMD160},
424 #ifndef OPENSSL_NO_RC4
427 #ifndef OPENSSL_NO_DES
428 {"des-cbc", D_CBC_DES},
429 {"des-ede3", D_EDE3_DES},
431 {"aes-128-cbc", D_CBC_128_AES},
432 {"aes-192-cbc", D_CBC_192_AES},
433 {"aes-256-cbc", D_CBC_256_AES},
434 {"aes-128-ige", D_IGE_128_AES},
435 {"aes-192-ige", D_IGE_192_AES},
436 {"aes-256-ige", D_IGE_256_AES},
437 #ifndef OPENSSL_NO_RC2
438 {"rc2-cbc", D_CBC_RC2},
441 #ifndef OPENSSL_NO_RC5
442 {"rc5-cbc", D_CBC_RC5},
445 #ifndef OPENSSL_NO_IDEA
446 {"idea-cbc", D_CBC_IDEA},
447 {"idea", D_CBC_IDEA},
449 #ifndef OPENSSL_NO_SEED
450 {"seed-cbc", D_CBC_SEED},
451 {"seed", D_CBC_SEED},
453 #ifndef OPENSSL_NO_BF
454 {"bf-cbc", D_CBC_BF},
455 {"blowfish", D_CBC_BF},
458 #ifndef OPENSSL_NO_CAST
459 {"cast-cbc", D_CBC_CAST},
460 {"cast", D_CBC_CAST},
461 {"cast5", D_CBC_CAST},
467 #ifndef OPENSSL_NO_DSA
469 # define R_DSA_1024 1
470 # define R_DSA_2048 2
471 static OPT_PAIR dsa_choices[] = {
472 {"dsa512", R_DSA_512},
473 {"dsa1024", R_DSA_1024},
474 {"dsa2048", R_DSA_2048},
485 #define R_RSA_15360 6
486 static OPT_PAIR rsa_choices[] = {
487 {"rsa512", R_RSA_512},
488 {"rsa1024", R_RSA_1024},
489 {"rsa2048", R_RSA_2048},
490 {"rsa3072", R_RSA_3072},
491 {"rsa4096", R_RSA_4096},
492 {"rsa7680", R_RSA_7680},
493 {"rsa15360", R_RSA_15360},
513 #define R_EC_X25519 16
514 #ifndef OPENSSL_NO_EC
515 static OPT_PAIR ecdsa_choices[] = {
516 {"ecdsap160", R_EC_P160},
517 {"ecdsap192", R_EC_P192},
518 {"ecdsap224", R_EC_P224},
519 {"ecdsap256", R_EC_P256},
520 {"ecdsap384", R_EC_P384},
521 {"ecdsap521", R_EC_P521},
522 {"ecdsak163", R_EC_K163},
523 {"ecdsak233", R_EC_K233},
524 {"ecdsak283", R_EC_K283},
525 {"ecdsak409", R_EC_K409},
526 {"ecdsak571", R_EC_K571},
527 {"ecdsab163", R_EC_B163},
528 {"ecdsab233", R_EC_B233},
529 {"ecdsab283", R_EC_B283},
530 {"ecdsab409", R_EC_B409},
531 {"ecdsab571", R_EC_B571},
535 static OPT_PAIR ecdh_choices[] = {
536 {"ecdhp160", R_EC_P160},
537 {"ecdhp192", R_EC_P192},
538 {"ecdhp224", R_EC_P224},
539 {"ecdhp256", R_EC_P256},
540 {"ecdhp384", R_EC_P384},
541 {"ecdhp521", R_EC_P521},
542 {"ecdhk163", R_EC_K163},
543 {"ecdhk233", R_EC_K233},
544 {"ecdhk283", R_EC_K283},
545 {"ecdhk409", R_EC_K409},
546 {"ecdhk571", R_EC_K571},
547 {"ecdhb163", R_EC_B163},
548 {"ecdhb233", R_EC_B233},
549 {"ecdhb283", R_EC_B283},
550 {"ecdhb409", R_EC_B409},
551 {"ecdhb571", R_EC_B571},
552 {"ecdhx25519", R_EC_X25519},
558 # define COND(d) (count < (d))
559 # define COUNT(d) (d)
561 # define COND(unused_cond) (run && count<0x7fffffff)
562 # define COUNT(d) (count)
567 /* Nb of iterations to do per algorithm and key-size */
568 static long c[ALGOR_NUM][SIZE_NUM];
570 #ifndef OPENSSL_NO_MD2
571 static int EVP_Digest_MD2_loop(void *args)
573 loopargs_t *tempargs = *(loopargs_t **) args;
574 unsigned char *buf = tempargs->buf;
575 unsigned char md2[MD2_DIGEST_LENGTH];
578 for (count = 0; COND(c[D_MD2][testnum]); count++) {
579 if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
587 #ifndef OPENSSL_NO_MDC2
588 static int EVP_Digest_MDC2_loop(void *args)
590 loopargs_t *tempargs = *(loopargs_t **) args;
591 unsigned char *buf = tempargs->buf;
592 unsigned char mdc2[MDC2_DIGEST_LENGTH];
595 for (count = 0; COND(c[D_MDC2][testnum]); count++) {
596 if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
604 #ifndef OPENSSL_NO_MD4
605 static int EVP_Digest_MD4_loop(void *args)
607 loopargs_t *tempargs = *(loopargs_t **) args;
608 unsigned char *buf = tempargs->buf;
609 unsigned char md4[MD4_DIGEST_LENGTH];
612 for (count = 0; COND(c[D_MD4][testnum]); count++) {
613 if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
621 #ifndef OPENSSL_NO_MD5
622 static int MD5_loop(void *args)
624 loopargs_t *tempargs = *(loopargs_t **) args;
625 unsigned char *buf = tempargs->buf;
626 unsigned char md5[MD5_DIGEST_LENGTH];
628 for (count = 0; COND(c[D_MD5][testnum]); count++)
629 MD5(buf, lengths[testnum], md5);
633 static int HMAC_loop(void *args)
635 loopargs_t *tempargs = *(loopargs_t **) args;
636 unsigned char *buf = tempargs->buf;
637 HMAC_CTX *hctx = tempargs->hctx;
638 unsigned char hmac[MD5_DIGEST_LENGTH];
641 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
642 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
643 HMAC_Update(hctx, buf, lengths[testnum]);
644 HMAC_Final(hctx, hmac, NULL);
650 static int SHA1_loop(void *args)
652 loopargs_t *tempargs = *(loopargs_t **) args;
653 unsigned char *buf = tempargs->buf;
654 unsigned char sha[SHA_DIGEST_LENGTH];
656 for (count = 0; COND(c[D_SHA1][testnum]); count++)
657 SHA1(buf, lengths[testnum], sha);
661 static int SHA256_loop(void *args)
663 loopargs_t *tempargs = *(loopargs_t **) args;
664 unsigned char *buf = tempargs->buf;
665 unsigned char sha256[SHA256_DIGEST_LENGTH];
667 for (count = 0; COND(c[D_SHA256][testnum]); count++)
668 SHA256(buf, lengths[testnum], sha256);
672 static int SHA512_loop(void *args)
674 loopargs_t *tempargs = *(loopargs_t **) args;
675 unsigned char *buf = tempargs->buf;
676 unsigned char sha512[SHA512_DIGEST_LENGTH];
678 for (count = 0; COND(c[D_SHA512][testnum]); count++)
679 SHA512(buf, lengths[testnum], sha512);
683 #ifndef OPENSSL_NO_WHIRLPOOL
684 static int WHIRLPOOL_loop(void *args)
686 loopargs_t *tempargs = *(loopargs_t **) args;
687 unsigned char *buf = tempargs->buf;
688 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
690 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
691 WHIRLPOOL(buf, lengths[testnum], whirlpool);
696 #ifndef OPENSSL_NO_RMD160
697 static int EVP_Digest_RMD160_loop(void *args)
699 loopargs_t *tempargs = *(loopargs_t **) args;
700 unsigned char *buf = tempargs->buf;
701 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
703 for (count = 0; COND(c[D_RMD160][testnum]); count++) {
704 if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
705 NULL, EVP_ripemd160(), NULL))
712 #ifndef OPENSSL_NO_RC4
713 static RC4_KEY rc4_ks;
714 static int RC4_loop(void *args)
716 loopargs_t *tempargs = *(loopargs_t **) args;
717 unsigned char *buf = tempargs->buf;
719 for (count = 0; COND(c[D_RC4][testnum]); count++)
720 RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
725 #ifndef OPENSSL_NO_DES
726 static unsigned char DES_iv[8];
727 static DES_key_schedule sch;
728 static DES_key_schedule sch2;
729 static DES_key_schedule sch3;
730 static int DES_ncbc_encrypt_loop(void *args)
732 loopargs_t *tempargs = *(loopargs_t **) args;
733 unsigned char *buf = tempargs->buf;
735 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
736 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
737 &DES_iv, DES_ENCRYPT);
741 static int DES_ede3_cbc_encrypt_loop(void *args)
743 loopargs_t *tempargs = *(loopargs_t **) args;
744 unsigned char *buf = tempargs->buf;
746 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
747 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
748 &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
753 #define MAX_BLOCK_SIZE 128
755 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
756 static AES_KEY aes_ks1, aes_ks2, aes_ks3;
757 static int AES_cbc_128_encrypt_loop(void *args)
759 loopargs_t *tempargs = *(loopargs_t **) args;
760 unsigned char *buf = tempargs->buf;
762 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
763 AES_cbc_encrypt(buf, buf,
764 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
768 static int AES_cbc_192_encrypt_loop(void *args)
770 loopargs_t *tempargs = *(loopargs_t **) args;
771 unsigned char *buf = tempargs->buf;
773 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
774 AES_cbc_encrypt(buf, buf,
775 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
779 static int AES_cbc_256_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_256_AES][testnum]); count++)
785 AES_cbc_encrypt(buf, buf,
786 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
790 static int AES_ige_128_encrypt_loop(void *args)
792 loopargs_t *tempargs = *(loopargs_t **) args;
793 unsigned char *buf = tempargs->buf;
794 unsigned char *buf2 = tempargs->buf2;
796 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
797 AES_ige_encrypt(buf, buf2,
798 (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
802 static int AES_ige_192_encrypt_loop(void *args)
804 loopargs_t *tempargs = *(loopargs_t **) args;
805 unsigned char *buf = tempargs->buf;
806 unsigned char *buf2 = tempargs->buf2;
808 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
809 AES_ige_encrypt(buf, buf2,
810 (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
814 static int AES_ige_256_encrypt_loop(void *args)
816 loopargs_t *tempargs = *(loopargs_t **) args;
817 unsigned char *buf = tempargs->buf;
818 unsigned char *buf2 = tempargs->buf2;
820 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
821 AES_ige_encrypt(buf, buf2,
822 (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
826 static int CRYPTO_gcm128_aad_loop(void *args)
828 loopargs_t *tempargs = *(loopargs_t **) args;
829 unsigned char *buf = tempargs->buf;
830 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
832 for (count = 0; COND(c[D_GHASH][testnum]); count++)
833 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
837 static long save_count = 0;
838 static int decrypt = 0;
839 static int EVP_Update_loop(void *args)
841 loopargs_t *tempargs = *(loopargs_t **) args;
842 unsigned char *buf = tempargs->buf;
843 EVP_CIPHER_CTX *ctx = tempargs->ctx;
846 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
849 for (count = 0; COND(nb_iter); count++)
850 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
852 for (count = 0; COND(nb_iter); count++)
853 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
855 EVP_DecryptFinal_ex(ctx, buf, &outl);
857 EVP_EncryptFinal_ex(ctx, buf, &outl);
861 static const EVP_MD *evp_md = NULL;
862 static int EVP_Digest_loop(void *args)
864 loopargs_t *tempargs = *(loopargs_t **) args;
865 unsigned char *buf = tempargs->buf;
866 unsigned char md[EVP_MAX_MD_SIZE];
869 int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
872 for (count = 0; COND(nb_iter); count++) {
873 if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
879 #ifndef OPENSSL_NO_RSA
880 static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
882 static int RSA_sign_loop(void *args)
884 loopargs_t *tempargs = *(loopargs_t **) args;
885 unsigned char *buf = tempargs->buf;
886 unsigned char *buf2 = tempargs->buf2;
887 unsigned int *rsa_num = &tempargs->siglen;
888 RSA **rsa_key = tempargs->rsa_key;
890 for (count = 0; COND(rsa_c[testnum][0]); count++) {
891 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
893 BIO_printf(bio_err, "RSA sign failure\n");
894 ERR_print_errors(bio_err);
902 static int RSA_verify_loop(void *args)
904 loopargs_t *tempargs = *(loopargs_t **) args;
905 unsigned char *buf = tempargs->buf;
906 unsigned char *buf2 = tempargs->buf2;
907 unsigned int rsa_num = tempargs->siglen;
908 RSA **rsa_key = tempargs->rsa_key;
910 for (count = 0; COND(rsa_c[testnum][1]); count++) {
912 RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
914 BIO_printf(bio_err, "RSA verify failure\n");
915 ERR_print_errors(bio_err);
924 #ifndef OPENSSL_NO_DSA
925 static long dsa_c[DSA_NUM][2];
926 static int DSA_sign_loop(void *args)
928 loopargs_t *tempargs = *(loopargs_t **) args;
929 unsigned char *buf = tempargs->buf;
930 unsigned char *buf2 = tempargs->buf2;
931 DSA **dsa_key = tempargs->dsa_key;
932 unsigned int *siglen = &tempargs->siglen;
934 for (count = 0; COND(dsa_c[testnum][0]); count++) {
935 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
937 BIO_printf(bio_err, "DSA sign failure\n");
938 ERR_print_errors(bio_err);
946 static int DSA_verify_loop(void *args)
948 loopargs_t *tempargs = *(loopargs_t **) args;
949 unsigned char *buf = tempargs->buf;
950 unsigned char *buf2 = tempargs->buf2;
951 DSA **dsa_key = tempargs->dsa_key;
952 unsigned int siglen = tempargs->siglen;
954 for (count = 0; COND(dsa_c[testnum][1]); count++) {
955 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
957 BIO_printf(bio_err, "DSA verify failure\n");
958 ERR_print_errors(bio_err);
967 #ifndef OPENSSL_NO_EC
968 static long ecdsa_c[EC_NUM][2];
969 static int ECDSA_sign_loop(void *args)
971 loopargs_t *tempargs = *(loopargs_t **) args;
972 unsigned char *buf = tempargs->buf;
973 EC_KEY **ecdsa = tempargs->ecdsa;
974 unsigned char *ecdsasig = tempargs->buf2;
975 unsigned int *ecdsasiglen = &tempargs->siglen;
977 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
978 ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
980 BIO_printf(bio_err, "ECDSA sign failure\n");
981 ERR_print_errors(bio_err);
989 static int ECDSA_verify_loop(void *args)
991 loopargs_t *tempargs = *(loopargs_t **) args;
992 unsigned char *buf = tempargs->buf;
993 EC_KEY **ecdsa = tempargs->ecdsa;
994 unsigned char *ecdsasig = tempargs->buf2;
995 unsigned int ecdsasiglen = tempargs->siglen;
997 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
998 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
1000 BIO_printf(bio_err, "ECDSA verify failure\n");
1001 ERR_print_errors(bio_err);
1009 /* ******************************************************************** */
1010 static long ecdh_c[EC_NUM][1];
1012 static int ECDH_EVP_derive_key_loop(void *args)
1014 loopargs_t *tempargs = *(loopargs_t **) args;
1015 EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
1016 unsigned char *derived_secret = tempargs->secret_a;
1018 size_t *outlen = &(tempargs->outlen[testnum]);
1020 for (count = 0; COND(ecdh_c[testnum][0]); count++)
1021 EVP_PKEY_derive(ctx, derived_secret, outlen);
1026 #endif /* OPENSSL_NO_EC */
1028 static int run_benchmark(int async_jobs,
1029 int (*loop_function) (void *), loopargs_t * loopargs)
1031 int job_op_count = 0;
1032 int total_op_count = 0;
1033 int num_inprogress = 0;
1034 int error = 0, i = 0, ret = 0;
1035 OSSL_ASYNC_FD job_fd = 0;
1036 size_t num_job_fds = 0;
1040 if (async_jobs == 0) {
1041 return loop_function((void *)&loopargs);
1044 for (i = 0; i < async_jobs && !error; i++) {
1045 loopargs_t *looparg_item = loopargs + i;
1047 /* Copy pointer content (looparg_t item address) into async context */
1048 ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
1049 &job_op_count, loop_function,
1050 (void *)&looparg_item, sizeof(looparg_item));
1056 if (job_op_count == -1) {
1059 total_op_count += job_op_count;
1064 BIO_printf(bio_err, "Failure in the job\n");
1065 ERR_print_errors(bio_err);
1071 while (num_inprogress > 0) {
1072 #if defined(OPENSSL_SYS_WINDOWS)
1074 #elif defined(OPENSSL_SYS_UNIX)
1075 int select_result = 0;
1076 OSSL_ASYNC_FD max_fd = 0;
1079 FD_ZERO(&waitfdset);
1081 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1082 if (loopargs[i].inprogress_job == NULL)
1085 if (!ASYNC_WAIT_CTX_get_all_fds
1086 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1087 || num_job_fds > 1) {
1088 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1089 ERR_print_errors(bio_err);
1093 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1095 FD_SET(job_fd, &waitfdset);
1096 if (job_fd > max_fd)
1100 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
1102 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1103 "Decrease the value of async_jobs\n",
1104 max_fd, FD_SETSIZE);
1105 ERR_print_errors(bio_err);
1110 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
1111 if (select_result == -1 && errno == EINTR)
1114 if (select_result == -1) {
1115 BIO_printf(bio_err, "Failure in the select\n");
1116 ERR_print_errors(bio_err);
1121 if (select_result == 0)
1125 for (i = 0; i < async_jobs; i++) {
1126 if (loopargs[i].inprogress_job == NULL)
1129 if (!ASYNC_WAIT_CTX_get_all_fds
1130 (loopargs[i].wait_ctx, NULL, &num_job_fds)
1131 || num_job_fds > 1) {
1132 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1133 ERR_print_errors(bio_err);
1137 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
1140 #if defined(OPENSSL_SYS_UNIX)
1141 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
1143 #elif defined(OPENSSL_SYS_WINDOWS)
1144 if (num_job_fds == 1
1145 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
1150 ret = ASYNC_start_job(&loopargs[i].inprogress_job,
1151 loopargs[i].wait_ctx, &job_op_count,
1152 loop_function, (void *)(loopargs + i),
1153 sizeof(loopargs_t));
1158 if (job_op_count == -1) {
1161 total_op_count += job_op_count;
1164 loopargs[i].inprogress_job = NULL;
1169 loopargs[i].inprogress_job = NULL;
1170 BIO_printf(bio_err, "Failure in the job\n");
1171 ERR_print_errors(bio_err);
1178 return error ? -1 : total_op_count;
1181 int speed_main(int argc, char **argv)
1184 loopargs_t *loopargs = NULL;
1186 int loopargs_len = 0;
1188 const char *engine_id = NULL;
1189 const EVP_CIPHER *evp_cipher = NULL;
1192 int multiblock = 0, pr_header = 0;
1193 int doit[ALGOR_NUM] = { 0 };
1194 int ret = 1, i, k, misalign = 0;
1199 unsigned int async_jobs = 0;
1200 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1201 || !defined(OPENSSL_NO_EC)
1205 /* What follows are the buffers and key material. */
1206 #ifndef OPENSSL_NO_RC5
1209 #ifndef OPENSSL_NO_RC2
1212 #ifndef OPENSSL_NO_IDEA
1213 IDEA_KEY_SCHEDULE idea_ks;
1215 #ifndef OPENSSL_NO_SEED
1216 SEED_KEY_SCHEDULE seed_ks;
1218 #ifndef OPENSSL_NO_BF
1221 #ifndef OPENSSL_NO_CAST
1224 static const unsigned char key16[16] = {
1225 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1226 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1228 static const unsigned char key24[24] = {
1229 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1230 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1231 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1233 static const unsigned char key32[32] = {
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,
1237 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1239 #ifndef OPENSSL_NO_CAMELLIA
1240 static const unsigned char ckey24[24] = {
1241 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1242 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1243 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1245 static const unsigned char ckey32[32] = {
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,
1249 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1251 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
1253 #ifndef OPENSSL_NO_DES
1254 static DES_cblock key = {
1255 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1257 static DES_cblock key2 = {
1258 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1260 static DES_cblock key3 = {
1261 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1264 #ifndef OPENSSL_NO_RSA
1265 static const unsigned int rsa_bits[RSA_NUM] = {
1266 512, 1024, 2048, 3072, 4096, 7680, 15360
1268 static const unsigned char *rsa_data[RSA_NUM] = {
1269 test512, test1024, test2048, test3072, test4096, test7680, test15360
1271 static const int rsa_data_length[RSA_NUM] = {
1272 sizeof(test512), sizeof(test1024),
1273 sizeof(test2048), sizeof(test3072),
1274 sizeof(test4096), sizeof(test7680),
1277 int rsa_doit[RSA_NUM] = { 0 };
1279 #ifndef OPENSSL_NO_DSA
1280 static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
1281 int dsa_doit[DSA_NUM] = { 0 };
1283 #ifndef OPENSSL_NO_EC
1285 * We only test over the following curves as they are representative, To
1286 * add tests over more curves, simply add the curve NID and curve name to
1287 * the following arrays and increase the EC_NUM value accordingly.
1289 static const unsigned int test_curves[EC_NUM] = {
1291 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1292 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
1294 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1295 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1296 NID_sect233r1, NID_sect283r1, NID_sect409r1,
1301 static const char *test_curves_names[EC_NUM] = {
1303 "secp160r1", "nistp192", "nistp224",
1304 "nistp256", "nistp384", "nistp521",
1306 "nistk163", "nistk233", "nistk283",
1307 "nistk409", "nistk571", "nistb163",
1308 "nistb233", "nistb283", "nistb409",
1313 static const int test_curves_bits[EC_NUM] = {
1319 571, 253 /* X25519 */
1322 int ecdsa_doit[EC_NUM] = { 0 };
1323 int ecdh_doit[EC_NUM] = { 0 };
1324 #endif /* ndef OPENSSL_NO_EC */
1326 prog = opt_init(argc, argv, speed_options);
1327 while ((o = opt_next()) != OPT_EOF) {
1332 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1335 opt_help(speed_options);
1343 evp_cipher = EVP_get_cipherbyname(opt_arg());
1344 if (evp_cipher == NULL)
1345 evp_md = EVP_get_digestbyname(opt_arg());
1346 if (evp_cipher == NULL && evp_md == NULL) {
1348 "%s: %s is an unknown cipher or digest\n",
1359 * In a forked execution, an engine might need to be
1360 * initialised by each child process, not by the parent.
1361 * So store the name here and run setup_engine() later on.
1363 engine_id = opt_arg();
1367 multi = atoi(opt_arg());
1371 #ifndef OPENSSL_NO_ASYNC
1372 async_jobs = atoi(opt_arg());
1373 if (!ASYNC_is_capable()) {
1375 "%s: async_jobs specified but async not supported\n",
1379 if (async_jobs > 99999) {
1381 "%s: too many async_jobs\n",
1388 if (!opt_int(opt_arg(), &misalign))
1390 if (misalign > MISALIGN) {
1392 "%s: Maximum offset is %d\n", prog, MISALIGN);
1401 #ifdef OPENSSL_NO_MULTIBLOCK
1403 "%s: -mb specified but multi-block support is disabled\n",
1414 argc = opt_num_rest();
1417 /* Remaining arguments are algorithms. */
1418 for (; *argv; argv++) {
1419 if (found(*argv, doit_choices, &i)) {
1423 #ifndef OPENSSL_NO_DES
1424 if (strcmp(*argv, "des") == 0) {
1425 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1429 if (strcmp(*argv, "sha") == 0) {
1430 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1433 #ifndef OPENSSL_NO_RSA
1434 if (strcmp(*argv, "openssl") == 0)
1436 if (strcmp(*argv, "rsa") == 0) {
1437 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1438 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1439 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1440 rsa_doit[R_RSA_15360] = 1;
1443 if (found(*argv, rsa_choices, &i)) {
1448 #ifndef OPENSSL_NO_DSA
1449 if (strcmp(*argv, "dsa") == 0) {
1450 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1451 dsa_doit[R_DSA_2048] = 1;
1454 if (found(*argv, dsa_choices, &i)) {
1459 if (strcmp(*argv, "aes") == 0) {
1460 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
1463 #ifndef OPENSSL_NO_CAMELLIA
1464 if (strcmp(*argv, "camellia") == 0) {
1465 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
1469 #ifndef OPENSSL_NO_EC
1470 if (strcmp(*argv, "ecdsa") == 0) {
1471 for (i = 0; i < EC_NUM; i++)
1475 if (found(*argv, ecdsa_choices, &i)) {
1479 if (strcmp(*argv, "ecdh") == 0) {
1480 for (i = 0; i < EC_NUM; i++)
1484 if (found(*argv, ecdh_choices, &i)) {
1489 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1493 /* Initialize the job pool if async mode is enabled */
1494 if (async_jobs > 0) {
1495 async_init = ASYNC_init_thread(async_jobs, async_jobs);
1497 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1502 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1504 app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1505 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1507 for (i = 0; i < loopargs_len; i++) {
1508 if (async_jobs > 0) {
1509 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1510 if (loopargs[i].wait_ctx == NULL) {
1511 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1516 loopargs[i].buf_malloc =
1517 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1518 loopargs[i].buf2_malloc =
1519 app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1520 /* Align the start of buffers on a 64 byte boundary */
1521 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1522 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
1523 #ifndef OPENSSL_NO_EC
1524 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1525 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1530 if (multi && do_multi(multi))
1534 /* Initialize the engine after the fork */
1535 e = setup_engine(engine_id, 0);
1537 /* No parameters; turn on everything. */
1538 if ((argc == 0) && !doit[D_EVP]) {
1539 for (i = 0; i < ALGOR_NUM; i++)
1542 #ifndef OPENSSL_NO_RSA
1543 for (i = 0; i < RSA_NUM; i++)
1546 #ifndef OPENSSL_NO_DSA
1547 for (i = 0; i < DSA_NUM; i++)
1550 #ifndef OPENSSL_NO_EC
1551 for (i = 0; i < EC_NUM; i++)
1553 for (i = 0; i < EC_NUM; i++)
1557 for (i = 0; i < ALGOR_NUM; i++)
1561 if (usertime == 0 && !mr)
1563 "You have chosen to measure elapsed time "
1564 "instead of user CPU time.\n");
1566 #ifndef OPENSSL_NO_RSA
1567 for (i = 0; i < loopargs_len; i++) {
1568 for (k = 0; k < RSA_NUM; k++) {
1569 const unsigned char *p;
1572 loopargs[i].rsa_key[k] =
1573 d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1574 if (loopargs[i].rsa_key[k] == NULL) {
1576 "internal error loading RSA key number %d\n", k);
1582 #ifndef OPENSSL_NO_DSA
1583 for (i = 0; i < loopargs_len; i++) {
1584 loopargs[i].dsa_key[0] = get_dsa(512);
1585 loopargs[i].dsa_key[1] = get_dsa(1024);
1586 loopargs[i].dsa_key[2] = get_dsa(2048);
1589 #ifndef OPENSSL_NO_DES
1590 DES_set_key_unchecked(&key, &sch);
1591 DES_set_key_unchecked(&key2, &sch2);
1592 DES_set_key_unchecked(&key3, &sch3);
1594 AES_set_encrypt_key(key16, 128, &aes_ks1);
1595 AES_set_encrypt_key(key24, 192, &aes_ks2);
1596 AES_set_encrypt_key(key32, 256, &aes_ks3);
1597 #ifndef OPENSSL_NO_CAMELLIA
1598 Camellia_set_key(key16, 128, &camellia_ks1);
1599 Camellia_set_key(ckey24, 192, &camellia_ks2);
1600 Camellia_set_key(ckey32, 256, &camellia_ks3);
1602 #ifndef OPENSSL_NO_IDEA
1603 IDEA_set_encrypt_key(key16, &idea_ks);
1605 #ifndef OPENSSL_NO_SEED
1606 SEED_set_key(key16, &seed_ks);
1608 #ifndef OPENSSL_NO_RC4
1609 RC4_set_key(&rc4_ks, 16, key16);
1611 #ifndef OPENSSL_NO_RC2
1612 RC2_set_key(&rc2_ks, 16, key16, 128);
1614 #ifndef OPENSSL_NO_RC5
1615 RC5_32_set_key(&rc5_ks, 16, key16, 12);
1617 #ifndef OPENSSL_NO_BF
1618 BF_set_key(&bf_ks, 16, key16);
1620 #ifndef OPENSSL_NO_CAST
1621 CAST_set_key(&cast_ks, 16, key16);
1624 # ifndef OPENSSL_NO_DES
1625 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1631 for (it = count; it; it--)
1632 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1633 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
1637 c[D_MD2][0] = count / 10;
1638 c[D_MDC2][0] = count / 10;
1639 c[D_MD4][0] = count;
1640 c[D_MD5][0] = count;
1641 c[D_HMAC][0] = count;
1642 c[D_SHA1][0] = count;
1643 c[D_RMD160][0] = count;
1644 c[D_RC4][0] = count * 5;
1645 c[D_CBC_DES][0] = count;
1646 c[D_EDE3_DES][0] = count / 3;
1647 c[D_CBC_IDEA][0] = count;
1648 c[D_CBC_SEED][0] = count;
1649 c[D_CBC_RC2][0] = count;
1650 c[D_CBC_RC5][0] = count;
1651 c[D_CBC_BF][0] = count;
1652 c[D_CBC_CAST][0] = count;
1653 c[D_CBC_128_AES][0] = count;
1654 c[D_CBC_192_AES][0] = count;
1655 c[D_CBC_256_AES][0] = count;
1656 c[D_CBC_128_CML][0] = count;
1657 c[D_CBC_192_CML][0] = count;
1658 c[D_CBC_256_CML][0] = count;
1659 c[D_SHA256][0] = count;
1660 c[D_SHA512][0] = count;
1661 c[D_WHIRLPOOL][0] = count;
1662 c[D_IGE_128_AES][0] = count;
1663 c[D_IGE_192_AES][0] = count;
1664 c[D_IGE_256_AES][0] = count;
1665 c[D_GHASH][0] = count;
1667 for (i = 1; i < SIZE_NUM; i++) {
1670 l0 = (long)lengths[0];
1671 l1 = (long)lengths[i];
1673 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1674 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1675 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1676 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1677 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1678 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1679 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1680 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1681 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1682 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1683 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
1685 l0 = (long)lengths[i - 1];
1687 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1688 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1689 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1690 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1691 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1692 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1693 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1694 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1695 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1696 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1697 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1698 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1699 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1700 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1701 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1702 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1703 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1704 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1707 # ifndef OPENSSL_NO_RSA
1708 rsa_c[R_RSA_512][0] = count / 2000;
1709 rsa_c[R_RSA_512][1] = count / 400;
1710 for (i = 1; i < RSA_NUM; i++) {
1711 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1712 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1713 if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
1716 if (rsa_c[i][0] == 0) {
1717 rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1724 # ifndef OPENSSL_NO_DSA
1725 dsa_c[R_DSA_512][0] = count / 1000;
1726 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1727 for (i = 1; i < DSA_NUM; i++) {
1728 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1729 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1730 if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
1733 if (dsa_c[i][0] == 0) {
1734 dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
1741 # ifndef OPENSSL_NO_EC
1742 ecdsa_c[R_EC_P160][0] = count / 1000;
1743 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1744 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1745 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1746 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1747 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1750 if (ecdsa_c[i][0] == 0) {
1756 ecdsa_c[R_EC_K163][0] = count / 1000;
1757 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1758 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1759 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1760 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1761 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1764 if (ecdsa_c[i][0] == 0) {
1770 ecdsa_c[R_EC_B163][0] = count / 1000;
1771 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1772 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1773 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1774 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1775 if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
1778 if (ecdsa_c[i][0] == 0) {
1785 ecdh_c[R_EC_P160][0] = count / 1000;
1786 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1787 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1788 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1791 if (ecdh_c[i][0] == 0) {
1796 ecdh_c[R_EC_K163][0] = count / 1000;
1797 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1798 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1799 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1802 if (ecdh_c[i][0] == 0) {
1807 ecdh_c[R_EC_B163][0] = count / 1000;
1808 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1809 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1810 if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
1813 if (ecdh_c[i][0] == 0) {
1821 /* not worth fixing */
1822 # error "You cannot disable DES on systems without SIGALRM."
1823 # endif /* OPENSSL_NO_DES */
1826 signal(SIGALRM, sig_done);
1828 #endif /* SIGALRM */
1830 #ifndef OPENSSL_NO_MD2
1832 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1833 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
1835 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
1837 print_result(D_MD2, testnum, count, d);
1841 #ifndef OPENSSL_NO_MDC2
1843 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1844 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
1846 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
1848 print_result(D_MDC2, testnum, count, d);
1853 #ifndef OPENSSL_NO_MD4
1855 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1856 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
1858 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
1860 print_result(D_MD4, testnum, count, d);
1865 #ifndef OPENSSL_NO_MD5
1867 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1868 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
1870 count = run_benchmark(async_jobs, MD5_loop, loopargs);
1872 print_result(D_MD5, testnum, count, d);
1877 static const char hmac_key[] = "This is a key...";
1878 int len = strlen(hmac_key);
1880 for (i = 0; i < loopargs_len; i++) {
1881 loopargs[i].hctx = HMAC_CTX_new();
1882 if (loopargs[i].hctx == NULL) {
1883 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1887 HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
1889 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1890 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1892 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1894 print_result(D_HMAC, testnum, count, d);
1896 for (i = 0; i < loopargs_len; i++) {
1897 HMAC_CTX_free(loopargs[i].hctx);
1902 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1903 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
1905 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
1907 print_result(D_SHA1, testnum, count, d);
1910 if (doit[D_SHA256]) {
1911 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1912 print_message(names[D_SHA256], c[D_SHA256][testnum],
1915 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
1917 print_result(D_SHA256, testnum, count, d);
1920 if (doit[D_SHA512]) {
1921 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1922 print_message(names[D_SHA512], c[D_SHA512][testnum],
1925 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
1927 print_result(D_SHA512, testnum, count, d);
1930 #ifndef OPENSSL_NO_WHIRLPOOL
1931 if (doit[D_WHIRLPOOL]) {
1932 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1933 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
1936 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
1938 print_result(D_WHIRLPOOL, testnum, count, d);
1943 #ifndef OPENSSL_NO_RMD160
1944 if (doit[D_RMD160]) {
1945 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1946 print_message(names[D_RMD160], c[D_RMD160][testnum],
1949 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
1951 print_result(D_RMD160, testnum, count, d);
1955 #ifndef OPENSSL_NO_RC4
1957 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1958 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
1960 count = run_benchmark(async_jobs, RC4_loop, loopargs);
1962 print_result(D_RC4, testnum, count, d);
1966 #ifndef OPENSSL_NO_DES
1967 if (doit[D_CBC_DES]) {
1968 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1969 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
1972 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
1974 print_result(D_CBC_DES, testnum, count, d);
1978 if (doit[D_EDE3_DES]) {
1979 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1980 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
1984 run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
1986 print_result(D_EDE3_DES, testnum, count, d);
1991 if (doit[D_CBC_128_AES]) {
1992 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1993 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
1997 run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
1999 print_result(D_CBC_128_AES, testnum, count, d);
2002 if (doit[D_CBC_192_AES]) {
2003 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2004 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2008 run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
2010 print_result(D_CBC_192_AES, testnum, count, d);
2013 if (doit[D_CBC_256_AES]) {
2014 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2015 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2019 run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
2021 print_result(D_CBC_256_AES, testnum, count, d);
2025 if (doit[D_IGE_128_AES]) {
2026 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2027 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2031 run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
2033 print_result(D_IGE_128_AES, testnum, count, d);
2036 if (doit[D_IGE_192_AES]) {
2037 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2038 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2042 run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
2044 print_result(D_IGE_192_AES, testnum, count, d);
2047 if (doit[D_IGE_256_AES]) {
2048 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2049 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2053 run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
2055 print_result(D_IGE_256_AES, testnum, count, d);
2058 if (doit[D_GHASH]) {
2059 for (i = 0; i < loopargs_len; i++) {
2060 loopargs[i].gcm_ctx =
2061 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2062 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
2063 (unsigned char *)"0123456789ab", 12);
2066 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2067 print_message(names[D_GHASH], c[D_GHASH][testnum],
2070 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2072 print_result(D_GHASH, testnum, count, d);
2074 for (i = 0; i < loopargs_len; i++)
2075 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
2077 #ifndef OPENSSL_NO_CAMELLIA
2078 if (doit[D_CBC_128_CML]) {
2079 if (async_jobs > 0) {
2080 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2081 names[D_CBC_128_CML]);
2082 doit[D_CBC_128_CML] = 0;
2084 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2085 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2088 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2089 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2090 (size_t)lengths[testnum], &camellia_ks1,
2091 iv, CAMELLIA_ENCRYPT);
2093 print_result(D_CBC_128_CML, testnum, count, d);
2096 if (doit[D_CBC_192_CML]) {
2097 if (async_jobs > 0) {
2098 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2099 names[D_CBC_192_CML]);
2100 doit[D_CBC_192_CML] = 0;
2102 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2103 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2105 if (async_jobs > 0) {
2106 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2110 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2111 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2112 (size_t)lengths[testnum], &camellia_ks2,
2113 iv, CAMELLIA_ENCRYPT);
2115 print_result(D_CBC_192_CML, testnum, count, d);
2118 if (doit[D_CBC_256_CML]) {
2119 if (async_jobs > 0) {
2120 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2121 names[D_CBC_256_CML]);
2122 doit[D_CBC_256_CML] = 0;
2124 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2125 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2128 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2129 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2130 (size_t)lengths[testnum], &camellia_ks3,
2131 iv, CAMELLIA_ENCRYPT);
2133 print_result(D_CBC_256_CML, testnum, count, d);
2137 #ifndef OPENSSL_NO_IDEA
2138 if (doit[D_CBC_IDEA]) {
2139 if (async_jobs > 0) {
2140 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2142 doit[D_CBC_IDEA] = 0;
2144 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2145 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
2148 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2149 IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2150 (size_t)lengths[testnum], &idea_ks,
2153 print_result(D_CBC_IDEA, testnum, count, d);
2157 #ifndef OPENSSL_NO_SEED
2158 if (doit[D_CBC_SEED]) {
2159 if (async_jobs > 0) {
2160 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2162 doit[D_CBC_SEED] = 0;
2164 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2165 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
2168 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2169 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2170 (size_t)lengths[testnum], &seed_ks, iv, 1);
2172 print_result(D_CBC_SEED, testnum, count, d);
2176 #ifndef OPENSSL_NO_RC2
2177 if (doit[D_CBC_RC2]) {
2178 if (async_jobs > 0) {
2179 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2181 doit[D_CBC_RC2] = 0;
2183 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2184 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
2186 if (async_jobs > 0) {
2187 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2191 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2192 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2193 (size_t)lengths[testnum], &rc2_ks,
2196 print_result(D_CBC_RC2, testnum, count, d);
2200 #ifndef OPENSSL_NO_RC5
2201 if (doit[D_CBC_RC5]) {
2202 if (async_jobs > 0) {
2203 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2205 doit[D_CBC_RC5] = 0;
2207 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2208 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
2210 if (async_jobs > 0) {
2211 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2215 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2216 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2217 (size_t)lengths[testnum], &rc5_ks,
2220 print_result(D_CBC_RC5, testnum, count, d);
2224 #ifndef OPENSSL_NO_BF
2225 if (doit[D_CBC_BF]) {
2226 if (async_jobs > 0) {
2227 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2231 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2232 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
2235 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2236 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2237 (size_t)lengths[testnum], &bf_ks,
2240 print_result(D_CBC_BF, testnum, count, d);
2244 #ifndef OPENSSL_NO_CAST
2245 if (doit[D_CBC_CAST]) {
2246 if (async_jobs > 0) {
2247 BIO_printf(bio_err, "Async mode is not supported with %s\n",
2249 doit[D_CBC_CAST] = 0;
2251 for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
2252 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
2255 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2256 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2257 (size_t)lengths[testnum], &cast_ks,
2260 print_result(D_CBC_CAST, testnum, count, d);
2266 if (multiblock && evp_cipher) {
2268 (EVP_CIPHER_flags(evp_cipher) &
2269 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
2270 BIO_printf(bio_err, "%s is not multi-block capable\n",
2271 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
2274 if (async_jobs > 0) {
2275 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2278 multiblock_speed(evp_cipher);
2282 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2285 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
2287 * -O3 -fschedule-insns messes up an optimization here!
2288 * names[D_EVP] somehow becomes NULL
2290 print_message(names[D_EVP], save_count, lengths[testnum]);
2292 for (k = 0; k < loopargs_len; k++) {
2293 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2295 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2298 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL,
2300 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2304 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
2306 for (k = 0; k < loopargs_len; k++) {
2307 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2311 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
2312 print_message(names[D_EVP], save_count, lengths[testnum]);
2314 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
2317 print_result(D_EVP, testnum, count, d);
2321 for (i = 0; i < loopargs_len; i++)
2322 RAND_bytes(loopargs[i].buf, 36);
2324 #ifndef OPENSSL_NO_RSA
2325 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2327 if (!rsa_doit[testnum])
2329 for (i = 0; i < loopargs_len; i++) {
2330 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2331 &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2337 "RSA sign failure. No RSA sign will be done.\n");
2338 ERR_print_errors(bio_err);
2341 pkey_print_message("private", "rsa",
2342 rsa_c[testnum][0], rsa_bits[testnum],
2344 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2346 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
2349 mr ? "+R1:%ld:%d:%.2f\n"
2350 : "%ld %d bit private RSA's in %.2fs\n",
2351 count, rsa_bits[testnum], d);
2352 rsa_results[testnum][0] = (double)count / d;
2356 for (i = 0; i < loopargs_len; i++) {
2357 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2358 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
2364 "RSA verify failure. No RSA verify will be done.\n");
2365 ERR_print_errors(bio_err);
2366 rsa_doit[testnum] = 0;
2368 pkey_print_message("public", "rsa",
2369 rsa_c[testnum][1], rsa_bits[testnum],
2372 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
2375 mr ? "+R2:%ld:%d:%.2f\n"
2376 : "%ld %d bit public RSA's in %.2fs\n",
2377 count, rsa_bits[testnum], d);
2378 rsa_results[testnum][1] = (double)count / d;
2381 if (rsa_count <= 1) {
2382 /* if longer than 10s, don't do any more */
2383 for (testnum++; testnum < RSA_NUM; testnum++)
2384 rsa_doit[testnum] = 0;
2387 #endif /* OPENSSL_NO_RSA */
2389 for (i = 0; i < loopargs_len; i++)
2390 RAND_bytes(loopargs[i].buf, 36);
2392 #ifndef OPENSSL_NO_DSA
2393 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2395 if (!dsa_doit[testnum])
2398 /* DSA_generate_key(dsa_key[testnum]); */
2399 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2400 for (i = 0; i < loopargs_len; i++) {
2401 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2402 &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2408 "DSA sign failure. No DSA sign will be done.\n");
2409 ERR_print_errors(bio_err);
2412 pkey_print_message("sign", "dsa",
2413 dsa_c[testnum][0], dsa_bits[testnum],
2416 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
2419 mr ? "+R3:%ld:%d:%.2f\n"
2420 : "%ld %d bit DSA signs in %.2fs\n",
2421 count, dsa_bits[testnum], d);
2422 dsa_results[testnum][0] = (double)count / d;
2426 for (i = 0; i < loopargs_len; i++) {
2427 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2428 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
2434 "DSA verify failure. No DSA verify will be done.\n");
2435 ERR_print_errors(bio_err);
2436 dsa_doit[testnum] = 0;
2438 pkey_print_message("verify", "dsa",
2439 dsa_c[testnum][1], dsa_bits[testnum],
2442 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
2445 mr ? "+R4:%ld:%d:%.2f\n"
2446 : "%ld %d bit DSA verify in %.2fs\n",
2447 count, dsa_bits[testnum], d);
2448 dsa_results[testnum][1] = (double)count / d;
2451 if (rsa_count <= 1) {
2452 /* if longer than 10s, don't do any more */
2453 for (testnum++; testnum < DSA_NUM; testnum++)
2454 dsa_doit[testnum] = 0;
2457 #endif /* OPENSSL_NO_DSA */
2459 #ifndef OPENSSL_NO_EC
2460 for (testnum = 0; testnum < EC_NUM; testnum++) {
2463 if (!ecdsa_doit[testnum])
2464 continue; /* Ignore Curve */
2465 for (i = 0; i < loopargs_len; i++) {
2466 loopargs[i].ecdsa[testnum] =
2467 EC_KEY_new_by_curve_name(test_curves[testnum]);
2468 if (loopargs[i].ecdsa[testnum] == NULL) {
2474 BIO_printf(bio_err, "ECDSA failure.\n");
2475 ERR_print_errors(bio_err);
2478 for (i = 0; i < loopargs_len; i++) {
2479 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2480 /* Perform ECDSA signature test */
2481 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2482 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2483 &loopargs[i].siglen,
2484 loopargs[i].ecdsa[testnum]);
2490 "ECDSA sign failure. No ECDSA sign will be done.\n");
2491 ERR_print_errors(bio_err);
2494 pkey_print_message("sign", "ecdsa",
2495 ecdsa_c[testnum][0],
2496 test_curves_bits[testnum], ECDSA_SECONDS);
2498 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
2502 mr ? "+R5:%ld:%d:%.2f\n" :
2503 "%ld %d bit ECDSA signs in %.2fs \n",
2504 count, test_curves_bits[testnum], d);
2505 ecdsa_results[testnum][0] = (double)count / d;
2509 /* Perform ECDSA verification test */
2510 for (i = 0; i < loopargs_len; i++) {
2511 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2513 loopargs[i].ecdsa[testnum]);
2519 "ECDSA verify failure. No ECDSA verify will be done.\n");
2520 ERR_print_errors(bio_err);
2521 ecdsa_doit[testnum] = 0;
2523 pkey_print_message("verify", "ecdsa",
2524 ecdsa_c[testnum][1],
2525 test_curves_bits[testnum], ECDSA_SECONDS);
2527 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
2530 mr ? "+R6:%ld:%d:%.2f\n"
2531 : "%ld %d bit ECDSA verify in %.2fs\n",
2532 count, test_curves_bits[testnum], d);
2533 ecdsa_results[testnum][1] = (double)count / d;
2536 if (rsa_count <= 1) {
2537 /* if longer than 10s, don't do any more */
2538 for (testnum++; testnum < EC_NUM; testnum++)
2539 ecdsa_doit[testnum] = 0;
2544 for (testnum = 0; testnum < EC_NUM; testnum++) {
2545 int ecdh_checks = 1;
2547 if (!ecdh_doit[testnum])
2550 for (i = 0; i < loopargs_len; i++) {
2551 EVP_PKEY_CTX *kctx = NULL;
2552 EVP_PKEY_CTX *test_ctx = NULL;
2553 EVP_PKEY_CTX *ctx = NULL;
2554 EVP_PKEY *key_A = NULL;
2555 EVP_PKEY *key_B = NULL;
2559 /* Ensure that the error queue is empty */
2560 if (ERR_peek_error()) {
2562 "WARNING: the error queue contains previous unhandled errors.\n");
2563 ERR_print_errors(bio_err);
2566 /* Let's try to create a ctx directly from the NID: this works for
2567 * curves like Curve25519 that are not implemented through the low
2568 * level EC interface.
2569 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2570 * then we set the curve by NID before deriving the actual keygen
2571 * ctx for that specific curve. */
2572 kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */
2574 EVP_PKEY_CTX *pctx = NULL;
2575 EVP_PKEY *params = NULL;
2577 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2578 * "int_ctx_new:unsupported algorithm" error was added to the
2580 * We remove it from the error queue as we are handling it. */
2581 unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
2582 if (error == ERR_peek_last_error() && /* oldest and latest errors match */
2583 /* check that the error origin matches */
2584 ERR_GET_LIB(error) == ERR_LIB_EVP &&
2585 ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
2586 ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
2587 ERR_get_error(); /* pop error from queue */
2588 if (ERR_peek_error()) {
2590 "Unhandled error in the error queue during ECDH init.\n");
2591 ERR_print_errors(bio_err);
2596 if ( /* Create the context for parameter generation */
2597 !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
2598 /* Initialise the parameter generation */
2599 !EVP_PKEY_paramgen_init(pctx) ||
2600 /* Set the curve by NID */
2601 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
2604 /* Create the parameter object params */
2605 !EVP_PKEY_paramgen(pctx, ¶ms)) {
2607 BIO_printf(bio_err, "ECDH EC params init failure.\n");
2608 ERR_print_errors(bio_err);
2612 /* Create the context for the key generation */
2613 kctx = EVP_PKEY_CTX_new(params, NULL);
2615 EVP_PKEY_free(params);
2617 EVP_PKEY_CTX_free(pctx);
2620 if (kctx == NULL || /* keygen ctx is not null */
2621 !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
2623 BIO_printf(bio_err, "ECDH keygen failure.\n");
2624 ERR_print_errors(bio_err);
2629 if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
2630 !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
2631 !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
2632 !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
2633 !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
2634 !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
2635 outlen == 0 || /* ensure outlen is a valid size */
2636 outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
2638 BIO_printf(bio_err, "ECDH key generation failure.\n");
2639 ERR_print_errors(bio_err);
2644 /* Here we perform a test run, comparing the output of a*B and b*A;
2645 * we try this here and assume that further EVP_PKEY_derive calls
2646 * never fail, so we can skip checks in the actually benchmarked
2647 * code, for maximum performance. */
2648 if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
2649 !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
2650 !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
2651 !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
2652 !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
2653 !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
2654 test_outlen != outlen /* compare output length */ ) {
2656 BIO_printf(bio_err, "ECDH computation failure.\n");
2657 ERR_print_errors(bio_err);
2662 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2663 if (CRYPTO_memcmp(loopargs[i].secret_a,
2664 loopargs[i].secret_b, outlen)) {
2666 BIO_printf(bio_err, "ECDH computations don't match.\n");
2667 ERR_print_errors(bio_err);
2672 loopargs[i].ecdh_ctx[testnum] = ctx;
2673 loopargs[i].outlen[testnum] = outlen;
2675 EVP_PKEY_CTX_free(kctx);
2677 EVP_PKEY_CTX_free(test_ctx);
2680 if (ecdh_checks != 0) {
2681 pkey_print_message("", "ecdh",
2683 test_curves_bits[testnum], ECDH_SECONDS);
2686 run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
2689 mr ? "+R7:%ld:%d:%.2f\n" :
2690 "%ld %d-bit ECDH ops in %.2fs\n", count,
2691 test_curves_bits[testnum], d);
2692 ecdh_results[testnum][0] = (double)count / d;
2696 if (rsa_count <= 1) {
2697 /* if longer than 10s, don't do any more */
2698 for (testnum++; testnum < EC_NUM; testnum++)
2699 ecdh_doit[testnum] = 0;
2702 #endif /* OPENSSL_NO_EC */
2707 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2708 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
2710 printf("%s ", BN_options());
2711 #ifndef OPENSSL_NO_MD2
2712 printf("%s ", MD2_options());
2714 #ifndef OPENSSL_NO_RC4
2715 printf("%s ", RC4_options());
2717 #ifndef OPENSSL_NO_DES
2718 printf("%s ", DES_options());
2720 printf("%s ", AES_options());
2721 #ifndef OPENSSL_NO_IDEA
2722 printf("%s ", IDEA_options());
2724 #ifndef OPENSSL_NO_BF
2725 printf("%s ", BF_options());
2727 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
2735 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2738 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2739 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
2743 for (k = 0; k < ALGOR_NUM; k++) {
2747 printf("+F:%d:%s", k, names[k]);
2749 printf("%-13s", names[k]);
2750 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2751 if (results[k][testnum] > 10000 && !mr)
2752 printf(" %11.2fk", results[k][testnum] / 1e3);
2754 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
2758 #ifndef OPENSSL_NO_RSA
2760 for (k = 0; k < RSA_NUM; k++) {
2763 if (testnum && !mr) {
2764 printf("%18ssign verify sign/s verify/s\n", " ");
2768 printf("+F2:%u:%u:%f:%f\n",
2769 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2771 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2772 rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
2773 rsa_results[k][0], rsa_results[k][1]);
2776 #ifndef OPENSSL_NO_DSA
2778 for (k = 0; k < DSA_NUM; k++) {
2781 if (testnum && !mr) {
2782 printf("%18ssign verify sign/s verify/s\n", " ");
2786 printf("+F3:%u:%u:%f:%f\n",
2787 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2789 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2790 dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
2791 dsa_results[k][0], dsa_results[k][1]);
2794 #ifndef OPENSSL_NO_EC
2796 for (k = 0; k < EC_NUM; k++) {
2799 if (testnum && !mr) {
2800 printf("%30ssign verify sign/s verify/s\n", " ");
2805 printf("+F4:%u:%u:%f:%f\n",
2806 k, test_curves_bits[k],
2807 ecdsa_results[k][0], ecdsa_results[k][1]);
2809 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2810 test_curves_bits[k],
2811 test_curves_names[k],
2812 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
2813 ecdsa_results[k][0], ecdsa_results[k][1]);
2817 for (k = 0; k < EC_NUM; k++) {
2820 if (testnum && !mr) {
2821 printf("%30sop op/s\n", " ");
2825 printf("+F5:%u:%u:%f:%f\n",
2826 k, test_curves_bits[k],
2827 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2830 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2831 test_curves_bits[k],
2832 test_curves_names[k],
2833 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
2840 ERR_print_errors(bio_err);
2841 for (i = 0; i < loopargs_len; i++) {
2842 OPENSSL_free(loopargs[i].buf_malloc);
2843 OPENSSL_free(loopargs[i].buf2_malloc);
2845 #ifndef OPENSSL_NO_RSA
2846 for (k = 0; k < RSA_NUM; k++)
2847 RSA_free(loopargs[i].rsa_key[k]);
2849 #ifndef OPENSSL_NO_DSA
2850 for (k = 0; k < DSA_NUM; k++)
2851 DSA_free(loopargs[i].dsa_key[k]);
2853 #ifndef OPENSSL_NO_EC
2854 for (k = 0; k < EC_NUM; k++) {
2855 EC_KEY_free(loopargs[i].ecdsa[k]);
2856 EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
2858 OPENSSL_free(loopargs[i].secret_a);
2859 OPENSSL_free(loopargs[i].secret_b);
2863 if (async_jobs > 0) {
2864 for (i = 0; i < loopargs_len; i++)
2865 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2869 ASYNC_cleanup_thread();
2871 OPENSSL_free(loopargs);
2876 static void print_message(const char *s, long num, int length)
2880 mr ? "+DT:%s:%d:%d\n"
2881 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2882 (void)BIO_flush(bio_err);
2886 mr ? "+DN:%s:%ld:%d\n"
2887 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2888 (void)BIO_flush(bio_err);
2892 static void pkey_print_message(const char *str, const char *str2, long num,
2897 mr ? "+DTP:%d:%s:%s:%d\n"
2898 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2899 (void)BIO_flush(bio_err);
2903 mr ? "+DNP:%ld:%d:%s:%s\n"
2904 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2905 (void)BIO_flush(bio_err);
2909 static void print_result(int alg, int run_no, int count, double time_used)
2912 BIO_puts(bio_err, "EVP error!\n");
2916 mr ? "+R:%d:%s:%f\n"
2917 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2918 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2922 static char *sstrsep(char **string, const char *delim)
2925 char *token = *string;
2930 memset(isdelim, 0, sizeof isdelim);
2934 isdelim[(unsigned char)(*delim)] = 1;
2938 while (!isdelim[(unsigned char)(**string)]) {
2950 static int do_multi(int multi)
2955 static char sep[] = ":";
2957 fds = malloc(sizeof(*fds) * multi);
2958 for (n = 0; n < multi; ++n) {
2959 if (pipe(fd) == -1) {
2960 BIO_printf(bio_err, "pipe failure\n");
2964 (void)BIO_flush(bio_err);
2971 if (dup(fd[1]) == -1) {
2972 BIO_printf(bio_err, "dup failed\n");
2981 printf("Forked child %d\n", n);
2984 /* for now, assume the pipe is long enough to take all the output */
2985 for (n = 0; n < multi; ++n) {
2990 f = fdopen(fds[n], "r");
2991 while (fgets(buf, sizeof buf, f)) {
2992 p = strchr(buf, '\n');
2995 if (buf[0] != '+') {
2997 "Don't understand line '%s' from child %d\n", buf,
3001 printf("Got: %s from %d\n", buf, n);
3002 if (strncmp(buf, "+F:", 3) == 0) {
3007 alg = atoi(sstrsep(&p, sep));
3009 for (j = 0; j < SIZE_NUM; ++j)
3010 results[alg][j] += atof(sstrsep(&p, sep));
3011 } else if (strncmp(buf, "+F2:", 4) == 0) {
3016 k = atoi(sstrsep(&p, sep));
3019 d = atof(sstrsep(&p, sep));
3020 rsa_results[k][0] += d;
3022 d = atof(sstrsep(&p, sep));
3023 rsa_results[k][1] += d;
3025 # ifndef OPENSSL_NO_DSA
3026 else if (strncmp(buf, "+F3:", 4) == 0) {
3031 k = atoi(sstrsep(&p, sep));
3034 d = atof(sstrsep(&p, sep));
3035 dsa_results[k][0] += d;
3037 d = atof(sstrsep(&p, sep));
3038 dsa_results[k][1] += d;
3041 # ifndef OPENSSL_NO_EC
3042 else if (strncmp(buf, "+F4:", 4) == 0) {
3047 k = atoi(sstrsep(&p, sep));
3050 d = atof(sstrsep(&p, sep));
3051 ecdsa_results[k][0] += d;
3053 d = atof(sstrsep(&p, sep));
3054 ecdsa_results[k][1] += d;
3055 } else if (strncmp(buf, "+F5:", 4) == 0) {
3060 k = atoi(sstrsep(&p, sep));
3063 d = atof(sstrsep(&p, sep));
3064 ecdh_results[k][0] += d;
3068 else if (strncmp(buf, "+H:", 3) == 0) {
3071 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
3082 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
3084 static int mblengths[] =
3085 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3086 int j, count, num = OSSL_NELEM(mblengths);
3087 const char *alg_name;
3088 unsigned char *inp, *out, no_key[32], no_iv[16];
3089 EVP_CIPHER_CTX *ctx;
3092 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3093 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
3094 ctx = EVP_CIPHER_CTX_new();
3095 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3096 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
3097 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
3099 for (j = 0; j < num; j++) {
3100 print_message(alg_name, 0, mblengths[j]);
3102 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
3103 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
3104 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3105 size_t len = mblengths[j];
3108 memset(aad, 0, 8); /* avoid uninitialized values */
3109 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3110 aad[9] = 3; /* version */
3112 aad[11] = 0; /* length */
3114 mb_param.out = NULL;
3117 mb_param.interleave = 8;
3119 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
3120 sizeof(mb_param), &mb_param);
3126 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
3127 sizeof(mb_param), &mb_param);
3131 RAND_bytes(out, 16);
3135 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
3136 EVP_AEAD_TLS1_AAD_LEN, aad);
3137 EVP_Cipher(ctx, out, inp, len + pad);
3141 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
3142 : "%d %s's in %.2fs\n", count, "evp", d);
3143 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3147 fprintf(stdout, "+H");
3148 for (j = 0; j < num; j++)
3149 fprintf(stdout, ":%d", mblengths[j]);
3150 fprintf(stdout, "\n");
3151 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3152 for (j = 0; j < num; j++)
3153 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3154 fprintf(stdout, "\n");
3157 "The 'numbers' are in 1000s of bytes per second processed.\n");
3158 fprintf(stdout, "type ");
3159 for (j = 0; j < num; j++)
3160 fprintf(stdout, "%7d bytes", mblengths[j]);
3161 fprintf(stdout, "\n");
3162 fprintf(stdout, "%-24s", alg_name);
3164 for (j = 0; j < num; j++) {
3165 if (results[D_EVP][j] > 10000)
3166 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3168 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3170 fprintf(stdout, "\n");
3175 EVP_CIPHER_CTX_free(ctx);