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 *ecdh_a[EC_NUM];
167 //EVP_PKEY *ecdh_b[EC_NUM];
168 EVP_PKEY_CTX
*ecdh_ctx
[EC_NUM
];
169 unsigned char *secret_a
;
170 unsigned char *secret_b
;
176 GCM128_CONTEXT
*gcm_ctx
;
179 #ifndef OPENSSL_NO_MD2
180 static int EVP_Digest_MD2_loop(void *args
);
183 #ifndef OPENSSL_NO_MDC2
184 static int EVP_Digest_MDC2_loop(void *args
);
186 #ifndef OPENSSL_NO_MD4
187 static int EVP_Digest_MD4_loop(void *args
);
189 #ifndef OPENSSL_NO_MD5
190 static int MD5_loop(void *args
);
191 static int HMAC_loop(void *args
);
193 static int SHA1_loop(void *args
);
194 static int SHA256_loop(void *args
);
195 static int SHA512_loop(void *args
);
196 #ifndef OPENSSL_NO_WHIRLPOOL
197 static int WHIRLPOOL_loop(void *args
);
199 #ifndef OPENSSL_NO_RMD160
200 static int EVP_Digest_RMD160_loop(void *args
);
202 #ifndef OPENSSL_NO_RC4
203 static int RC4_loop(void *args
);
205 #ifndef OPENSSL_NO_DES
206 static int DES_ncbc_encrypt_loop(void *args
);
207 static int DES_ede3_cbc_encrypt_loop(void *args
);
209 static int AES_cbc_128_encrypt_loop(void *args
);
210 static int AES_cbc_192_encrypt_loop(void *args
);
211 static int AES_ige_128_encrypt_loop(void *args
);
212 static int AES_cbc_256_encrypt_loop(void *args
);
213 static int AES_ige_192_encrypt_loop(void *args
);
214 static int AES_ige_256_encrypt_loop(void *args
);
215 static int CRYPTO_gcm128_aad_loop(void *args
);
216 static int EVP_Update_loop(void *args
);
217 static int EVP_Digest_loop(void *args
);
218 #ifndef OPENSSL_NO_RSA
219 static int RSA_sign_loop(void *args
);
220 static int RSA_verify_loop(void *args
);
222 #ifndef OPENSSL_NO_DSA
223 static int DSA_sign_loop(void *args
);
224 static int DSA_verify_loop(void *args
);
226 #ifndef OPENSSL_NO_EC
227 static int ECDSA_sign_loop(void *args
);
228 static int ECDSA_verify_loop(void *args
);
229 static int ECDH_compute_key_loop(void *args
);
231 static int run_benchmark(int async_jobs
, int (*loop_function
)(void *), loopargs_t
*loopargs
);
233 static double Time_F(int s
);
234 static void print_message(const char *s
, long num
, int length
);
235 static void pkey_print_message(const char *str
, const char *str2
,
236 long num
, int bits
, int sec
);
237 static void print_result(int alg
, int run_no
, int count
, double time_used
);
239 static int do_multi(int multi
);
242 static const char *names
[ALGOR_NUM
] = {
243 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
244 "des cbc", "des ede3", "idea cbc", "seed cbc",
245 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
246 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
247 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
248 "evp", "sha256", "sha512", "whirlpool",
249 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
252 static double results
[ALGOR_NUM
][SIZE_NUM
];
254 static const int lengths
[SIZE_NUM
] = {
255 16, 64, 256, 1024, 8 * 1024, 16 * 1024
258 #ifndef OPENSSL_NO_RSA
259 static double rsa_results
[RSA_NUM
][2];
261 #ifndef OPENSSL_NO_DSA
262 static double dsa_results
[DSA_NUM
][2];
264 #ifndef OPENSSL_NO_EC
265 static double ecdsa_results
[EC_NUM
][2];
266 static double ecdh_results
[EC_NUM
][1];
269 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
270 static const char rnd_seed
[] =
271 "string to make the random number generator think it has entropy";
275 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
276 # define SIGRETTYPE void
278 # define SIGRETTYPE int
281 static SIGRETTYPE
sig_done(int sig
);
282 static SIGRETTYPE
sig_done(int sig
)
284 signal(SIGALRM
, sig_done
);
294 # if !defined(SIGALRM)
297 static unsigned int lapse
, schlock
;
298 static void alarm_win32(unsigned int secs
)
303 # define alarm alarm_win32
305 static DWORD WINAPI
sleepy(VOID
* arg
)
313 static double Time_F(int s
)
320 thr
= CreateThread(NULL
, 4096, sleepy
, NULL
, 0, NULL
);
322 DWORD err
= GetLastError();
323 BIO_printf(bio_err
, "unable to CreateThread (%lu)", err
);
327 Sleep(0); /* scheduler spinlock */
328 ret
= app_tminterval(s
, usertime
);
330 ret
= app_tminterval(s
, usertime
);
332 TerminateThread(thr
, 0);
340 static double Time_F(int s
)
342 double ret
= app_tminterval(s
, usertime
);
349 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
);
351 static int found(const char *name
, const OPT_PAIR
*pairs
, int *result
)
353 for (; pairs
->name
; pairs
++)
354 if (strcmp(name
, pairs
->name
) == 0) {
355 *result
= pairs
->retval
;
361 typedef enum OPTION_choice
{
362 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
363 OPT_ELAPSED
, OPT_EVP
, OPT_DECRYPT
, OPT_ENGINE
, OPT_MULTI
,
364 OPT_MR
, OPT_MB
, OPT_MISALIGN
, OPT_ASYNCJOBS
367 const OPTIONS speed_options
[] = {
368 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] ciphers...\n"},
369 {OPT_HELP_STR
, 1, '-', "Valid options are:\n"},
370 {"help", OPT_HELP
, '-', "Display this summary"},
371 {"evp", OPT_EVP
, 's', "Use specified EVP cipher"},
372 {"decrypt", OPT_DECRYPT
, '-',
373 "Time decryption instead of encryption (only EVP)"},
374 {"mr", OPT_MR
, '-', "Produce machine readable output"},
376 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
377 {"misalign", OPT_MISALIGN
, 'n', "Amount to mis-align buffers"},
378 {"elapsed", OPT_ELAPSED
, '-',
379 "Measure time in real time instead of CPU user time"},
381 {"multi", OPT_MULTI
, 'p', "Run benchmarks in parallel"},
383 #ifndef OPENSSL_NO_ASYNC
384 {"async_jobs", OPT_ASYNCJOBS
, 'p',
385 "Enable async mode and start pnum jobs"},
387 #ifndef OPENSSL_NO_ENGINE
388 {"engine", OPT_ENGINE
, 's', "Use engine, possibly a hardware device"},
403 #define D_CBC_IDEA 10
404 #define D_CBC_SEED 11
408 #define D_CBC_CAST 15
409 #define D_CBC_128_AES 16
410 #define D_CBC_192_AES 17
411 #define D_CBC_256_AES 18
412 #define D_CBC_128_CML 19
413 #define D_CBC_192_CML 20
414 #define D_CBC_256_CML 21
418 #define D_WHIRLPOOL 25
419 #define D_IGE_128_AES 26
420 #define D_IGE_192_AES 27
421 #define D_IGE_256_AES 28
423 static OPT_PAIR doit_choices
[] = {
424 #ifndef OPENSSL_NO_MD2
427 #ifndef OPENSSL_NO_MDC2
430 #ifndef OPENSSL_NO_MD4
433 #ifndef OPENSSL_NO_MD5
438 {"sha256", D_SHA256
},
439 {"sha512", D_SHA512
},
440 #ifndef OPENSSL_NO_WHIRLPOOL
441 {"whirlpool", D_WHIRLPOOL
},
443 #ifndef OPENSSL_NO_RMD160
444 {"ripemd", D_RMD160
},
445 {"rmd160", D_RMD160
},
446 {"ripemd160", D_RMD160
},
448 #ifndef OPENSSL_NO_RC4
451 #ifndef OPENSSL_NO_DES
452 {"des-cbc", D_CBC_DES
},
453 {"des-ede3", D_EDE3_DES
},
455 {"aes-128-cbc", D_CBC_128_AES
},
456 {"aes-192-cbc", D_CBC_192_AES
},
457 {"aes-256-cbc", D_CBC_256_AES
},
458 {"aes-128-ige", D_IGE_128_AES
},
459 {"aes-192-ige", D_IGE_192_AES
},
460 {"aes-256-ige", D_IGE_256_AES
},
461 #ifndef OPENSSL_NO_RC2
462 {"rc2-cbc", D_CBC_RC2
},
465 #ifndef OPENSSL_NO_RC5
466 {"rc5-cbc", D_CBC_RC5
},
469 #ifndef OPENSSL_NO_IDEA
470 {"idea-cbc", D_CBC_IDEA
},
471 {"idea", D_CBC_IDEA
},
473 #ifndef OPENSSL_NO_SEED
474 {"seed-cbc", D_CBC_SEED
},
475 {"seed", D_CBC_SEED
},
477 #ifndef OPENSSL_NO_BF
478 {"bf-cbc", D_CBC_BF
},
479 {"blowfish", D_CBC_BF
},
482 #ifndef OPENSSL_NO_CAST
483 {"cast-cbc", D_CBC_CAST
},
484 {"cast", D_CBC_CAST
},
485 {"cast5", D_CBC_CAST
},
491 #ifndef OPENSSL_NO_DSA
493 # define R_DSA_1024 1
494 # define R_DSA_2048 2
495 static OPT_PAIR dsa_choices
[] = {
496 {"dsa512", R_DSA_512
},
497 {"dsa1024", R_DSA_1024
},
498 {"dsa2048", R_DSA_2048
},
509 #define R_RSA_15360 6
510 static OPT_PAIR rsa_choices
[] = {
511 {"rsa512", R_RSA_512
},
512 {"rsa1024", R_RSA_1024
},
513 {"rsa2048", R_RSA_2048
},
514 {"rsa3072", R_RSA_3072
},
515 {"rsa4096", R_RSA_4096
},
516 {"rsa7680", R_RSA_7680
},
517 {"rsa15360", R_RSA_15360
},
537 #define R_EC_X25519 16
538 #ifndef OPENSSL_NO_EC
539 static OPT_PAIR ecdsa_choices
[] = {
540 {"ecdsap160", R_EC_P160
},
541 {"ecdsap192", R_EC_P192
},
542 {"ecdsap224", R_EC_P224
},
543 {"ecdsap256", R_EC_P256
},
544 {"ecdsap384", R_EC_P384
},
545 {"ecdsap521", R_EC_P521
},
546 {"ecdsak163", R_EC_K163
},
547 {"ecdsak233", R_EC_K233
},
548 {"ecdsak283", R_EC_K283
},
549 {"ecdsak409", R_EC_K409
},
550 {"ecdsak571", R_EC_K571
},
551 {"ecdsab163", R_EC_B163
},
552 {"ecdsab233", R_EC_B233
},
553 {"ecdsab283", R_EC_B283
},
554 {"ecdsab409", R_EC_B409
},
555 {"ecdsab571", R_EC_B571
},
559 static OPT_PAIR ecdh_choices
[] = {
560 {"ecdhp160", R_EC_P160
},
561 {"ecdhp192", R_EC_P192
},
562 {"ecdhp224", R_EC_P224
},
563 {"ecdhp256", R_EC_P256
},
564 {"ecdhp384", R_EC_P384
},
565 {"ecdhp521", R_EC_P521
},
566 {"ecdhk163", R_EC_K163
},
567 {"ecdhk233", R_EC_K233
},
568 {"ecdhk283", R_EC_K283
},
569 {"ecdhk409", R_EC_K409
},
570 {"ecdhk571", R_EC_K571
},
571 {"ecdhb163", R_EC_B163
},
572 {"ecdhb233", R_EC_B233
},
573 {"ecdhb283", R_EC_B283
},
574 {"ecdhb409", R_EC_B409
},
575 {"ecdhb571", R_EC_B571
},
576 {"ecdhx25519", R_EC_X25519
},
582 # define COND(d) (count < (d))
583 # define COUNT(d) (d)
585 # define COND(unused_cond) (run && count<0x7fffffff)
586 # define COUNT(d) (count)
591 /* Nb of iterations to do per algorithm and key-size */
592 static long c
[ALGOR_NUM
][SIZE_NUM
];
594 #ifndef OPENSSL_NO_MD2
595 static int EVP_Digest_MD2_loop(void *args
)
597 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
598 unsigned char *buf
= tempargs
->buf
;
599 unsigned char md2
[MD2_DIGEST_LENGTH
];
602 for (count
= 0; COND(c
[D_MD2
][testnum
]); count
++) {
603 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md2
, NULL
, EVP_md2(),
611 #ifndef OPENSSL_NO_MDC2
612 static int EVP_Digest_MDC2_loop(void *args
)
614 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
615 unsigned char *buf
= tempargs
->buf
;
616 unsigned char mdc2
[MDC2_DIGEST_LENGTH
];
619 for (count
= 0; COND(c
[D_MDC2
][testnum
]); count
++) {
620 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], mdc2
, NULL
, EVP_mdc2(),
628 #ifndef OPENSSL_NO_MD4
629 static int EVP_Digest_MD4_loop(void *args
)
631 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
632 unsigned char *buf
= tempargs
->buf
;
633 unsigned char md4
[MD4_DIGEST_LENGTH
];
636 for (count
= 0; COND(c
[D_MD4
][testnum
]); count
++) {
637 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md4
, NULL
, EVP_md4(),
645 #ifndef OPENSSL_NO_MD5
646 static int MD5_loop(void *args
)
648 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
649 unsigned char *buf
= tempargs
->buf
;
650 unsigned char md5
[MD5_DIGEST_LENGTH
];
652 for (count
= 0; COND(c
[D_MD5
][testnum
]); count
++)
653 MD5(buf
, lengths
[testnum
], md5
);
657 static int HMAC_loop(void *args
)
659 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
660 unsigned char *buf
= tempargs
->buf
;
661 HMAC_CTX
*hctx
= tempargs
->hctx
;
662 unsigned char hmac
[MD5_DIGEST_LENGTH
];
665 for (count
= 0; COND(c
[D_HMAC
][testnum
]); count
++) {
666 HMAC_Init_ex(hctx
, NULL
, 0, NULL
, NULL
);
667 HMAC_Update(hctx
, buf
, lengths
[testnum
]);
668 HMAC_Final(hctx
, hmac
, NULL
);
674 static int SHA1_loop(void *args
)
676 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
677 unsigned char *buf
= tempargs
->buf
;
678 unsigned char sha
[SHA_DIGEST_LENGTH
];
680 for (count
= 0; COND(c
[D_SHA1
][testnum
]); count
++)
681 SHA1(buf
, lengths
[testnum
], sha
);
685 static int SHA256_loop(void *args
)
687 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
688 unsigned char *buf
= tempargs
->buf
;
689 unsigned char sha256
[SHA256_DIGEST_LENGTH
];
691 for (count
= 0; COND(c
[D_SHA256
][testnum
]); count
++)
692 SHA256(buf
, lengths
[testnum
], sha256
);
696 static int SHA512_loop(void *args
)
698 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
699 unsigned char *buf
= tempargs
->buf
;
700 unsigned char sha512
[SHA512_DIGEST_LENGTH
];
702 for (count
= 0; COND(c
[D_SHA512
][testnum
]); count
++)
703 SHA512(buf
, lengths
[testnum
], sha512
);
707 #ifndef OPENSSL_NO_WHIRLPOOL
708 static int WHIRLPOOL_loop(void *args
)
710 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
711 unsigned char *buf
= tempargs
->buf
;
712 unsigned char whirlpool
[WHIRLPOOL_DIGEST_LENGTH
];
714 for (count
= 0; COND(c
[D_WHIRLPOOL
][testnum
]); count
++)
715 WHIRLPOOL(buf
, lengths
[testnum
], whirlpool
);
720 #ifndef OPENSSL_NO_RMD160
721 static int EVP_Digest_RMD160_loop(void *args
)
723 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
724 unsigned char *buf
= tempargs
->buf
;
725 unsigned char rmd160
[RIPEMD160_DIGEST_LENGTH
];
727 for (count
= 0; COND(c
[D_RMD160
][testnum
]); count
++) {
728 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], &(rmd160
[0]),
729 NULL
, EVP_ripemd160(), NULL
))
736 #ifndef OPENSSL_NO_RC4
737 static RC4_KEY rc4_ks
;
738 static int RC4_loop(void *args
)
740 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
741 unsigned char *buf
= tempargs
->buf
;
743 for (count
= 0; COND(c
[D_RC4
][testnum
]); count
++)
744 RC4(&rc4_ks
, (size_t)lengths
[testnum
], buf
, buf
);
749 #ifndef OPENSSL_NO_DES
750 static unsigned char DES_iv
[8];
751 static DES_key_schedule sch
;
752 static DES_key_schedule sch2
;
753 static DES_key_schedule sch3
;
754 static int DES_ncbc_encrypt_loop(void *args
)
756 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
757 unsigned char *buf
= tempargs
->buf
;
759 for (count
= 0; COND(c
[D_CBC_DES
][testnum
]); count
++)
760 DES_ncbc_encrypt(buf
, buf
, lengths
[testnum
], &sch
,
761 &DES_iv
, DES_ENCRYPT
);
765 static int DES_ede3_cbc_encrypt_loop(void *args
)
767 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
768 unsigned char *buf
= tempargs
->buf
;
770 for (count
= 0; COND(c
[D_EDE3_DES
][testnum
]); count
++)
771 DES_ede3_cbc_encrypt(buf
, buf
, lengths
[testnum
],
773 &DES_iv
, DES_ENCRYPT
);
778 #define MAX_BLOCK_SIZE 128
780 static unsigned char iv
[2 * MAX_BLOCK_SIZE
/ 8];
781 static AES_KEY aes_ks1
, aes_ks2
, aes_ks3
;
782 static int AES_cbc_128_encrypt_loop(void *args
)
784 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
785 unsigned char *buf
= tempargs
->buf
;
787 for (count
= 0; COND(c
[D_CBC_128_AES
][testnum
]); count
++)
788 AES_cbc_encrypt(buf
, buf
,
789 (size_t)lengths
[testnum
], &aes_ks1
,
794 static int AES_cbc_192_encrypt_loop(void *args
)
796 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
797 unsigned char *buf
= tempargs
->buf
;
799 for (count
= 0; COND(c
[D_CBC_192_AES
][testnum
]); count
++)
800 AES_cbc_encrypt(buf
, buf
,
801 (size_t)lengths
[testnum
], &aes_ks2
,
806 static int AES_cbc_256_encrypt_loop(void *args
)
808 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
809 unsigned char *buf
= tempargs
->buf
;
811 for (count
= 0; COND(c
[D_CBC_256_AES
][testnum
]); count
++)
812 AES_cbc_encrypt(buf
, buf
,
813 (size_t)lengths
[testnum
], &aes_ks3
,
818 static int AES_ige_128_encrypt_loop(void *args
)
820 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
821 unsigned char *buf
= tempargs
->buf
;
822 unsigned char *buf2
= tempargs
->buf2
;
824 for (count
= 0; COND(c
[D_IGE_128_AES
][testnum
]); count
++)
825 AES_ige_encrypt(buf
, buf2
,
826 (size_t)lengths
[testnum
], &aes_ks1
,
831 static int AES_ige_192_encrypt_loop(void *args
)
833 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
834 unsigned char *buf
= tempargs
->buf
;
835 unsigned char *buf2
= tempargs
->buf2
;
837 for (count
= 0; COND(c
[D_IGE_192_AES
][testnum
]); count
++)
838 AES_ige_encrypt(buf
, buf2
,
839 (size_t)lengths
[testnum
], &aes_ks2
,
844 static int AES_ige_256_encrypt_loop(void *args
)
846 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
847 unsigned char *buf
= tempargs
->buf
;
848 unsigned char *buf2
= tempargs
->buf2
;
850 for (count
= 0; COND(c
[D_IGE_256_AES
][testnum
]); count
++)
851 AES_ige_encrypt(buf
, buf2
,
852 (size_t)lengths
[testnum
], &aes_ks3
,
857 static int CRYPTO_gcm128_aad_loop(void *args
)
859 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
860 unsigned char *buf
= tempargs
->buf
;
861 GCM128_CONTEXT
*gcm_ctx
= tempargs
->gcm_ctx
;
863 for (count
= 0; COND(c
[D_GHASH
][testnum
]); count
++)
864 CRYPTO_gcm128_aad(gcm_ctx
, buf
, lengths
[testnum
]);
868 static long save_count
= 0;
869 static int decrypt
= 0;
870 static int EVP_Update_loop(void *args
)
872 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
873 unsigned char *buf
= tempargs
->buf
;
874 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
877 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
880 for (count
= 0; COND(nb_iter
); count
++)
881 EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
883 for (count
= 0; COND(nb_iter
); count
++)
884 EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
886 EVP_DecryptFinal_ex(ctx
, buf
, &outl
);
888 EVP_EncryptFinal_ex(ctx
, buf
, &outl
);
892 static const EVP_MD
*evp_md
= NULL
;
893 static int EVP_Digest_loop(void *args
)
895 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
896 unsigned char *buf
= tempargs
->buf
;
897 unsigned char md
[EVP_MAX_MD_SIZE
];
900 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
903 for (count
= 0; COND(nb_iter
); count
++) {
904 if (!EVP_Digest(buf
, lengths
[testnum
], md
, NULL
, evp_md
, NULL
))
910 #ifndef OPENSSL_NO_RSA
911 static long rsa_c
[RSA_NUM
][2]; /* # RSA iteration test */
913 static int RSA_sign_loop(void *args
)
915 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
916 unsigned char *buf
= tempargs
->buf
;
917 unsigned char *buf2
= tempargs
->buf2
;
918 unsigned int *rsa_num
= &tempargs
->siglen
;
919 RSA
**rsa_key
= tempargs
->rsa_key
;
921 for (count
= 0; COND(rsa_c
[testnum
][0]); count
++) {
922 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
924 BIO_printf(bio_err
, "RSA sign failure\n");
925 ERR_print_errors(bio_err
);
933 static int RSA_verify_loop(void *args
)
935 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
936 unsigned char *buf
= tempargs
->buf
;
937 unsigned char *buf2
= tempargs
->buf2
;
938 unsigned int rsa_num
= tempargs
->siglen
;
939 RSA
**rsa_key
= tempargs
->rsa_key
;
941 for (count
= 0; COND(rsa_c
[testnum
][1]); count
++) {
942 ret
= RSA_verify(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
944 BIO_printf(bio_err
, "RSA verify failure\n");
945 ERR_print_errors(bio_err
);
954 #ifndef OPENSSL_NO_DSA
955 static long dsa_c
[DSA_NUM
][2];
956 static int DSA_sign_loop(void *args
)
958 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
959 unsigned char *buf
= tempargs
->buf
;
960 unsigned char *buf2
= tempargs
->buf2
;
961 DSA
**dsa_key
= tempargs
->dsa_key
;
962 unsigned int *siglen
= &tempargs
->siglen
;
964 for (count
= 0; COND(dsa_c
[testnum
][0]); count
++) {
965 ret
= DSA_sign(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
967 BIO_printf(bio_err
, "DSA sign failure\n");
968 ERR_print_errors(bio_err
);
976 static int DSA_verify_loop(void *args
)
978 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
979 unsigned char *buf
= tempargs
->buf
;
980 unsigned char *buf2
= tempargs
->buf2
;
981 DSA
**dsa_key
= tempargs
->dsa_key
;
982 unsigned int siglen
= tempargs
->siglen
;
984 for (count
= 0; COND(dsa_c
[testnum
][1]); count
++) {
985 ret
= DSA_verify(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
987 BIO_printf(bio_err
, "DSA verify failure\n");
988 ERR_print_errors(bio_err
);
997 #ifndef OPENSSL_NO_EC
998 static long ecdsa_c
[EC_NUM
][2];
999 static int ECDSA_sign_loop(void *args
)
1001 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
1002 unsigned char *buf
= tempargs
->buf
;
1003 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1004 unsigned char *ecdsasig
= tempargs
->buf2
;
1005 unsigned int *ecdsasiglen
= &tempargs
->siglen
;
1007 for (count
= 0; COND(ecdsa_c
[testnum
][0]); count
++) {
1008 ret
= ECDSA_sign(0, buf
, 20,
1009 ecdsasig
, ecdsasiglen
, ecdsa
[testnum
]);
1011 BIO_printf(bio_err
, "ECDSA sign failure\n");
1012 ERR_print_errors(bio_err
);
1020 static int ECDSA_verify_loop(void *args
)
1022 loopargs_t
*tempargs
= *(loopargs_t
**)args
;
1023 unsigned char *buf
= tempargs
->buf
;
1024 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1025 unsigned char *ecdsasig
= tempargs
->buf2
;
1026 unsigned int ecdsasiglen
= tempargs
->siglen
;
1028 for (count
= 0; COND(ecdsa_c
[testnum
][1]); count
++) {
1029 ret
= ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
,
1032 BIO_printf(bio_err
, "ECDSA verify failure\n");
1033 ERR_print_errors(bio_err
);
1041 /* ******************************************************************** */
1042 static long ecdh_c
[EC_NUM
][1];
1044 static void ECDH_EVP_derive_key(unsigned char *derived_secret
,
1046 /*EVP_PKEY *ecdh_a,EVP_PKEY *ecdh_b,*/
1049 if( !EVP_PKEY_derive(ctx
, derived_secret
, outlen
) ) {
1050 // FIXME: handle errors
1056 static int ECDH_EVP_derive_key_loop(void *args
)
1058 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1059 //EVP_PKEY *ecdh_a = tempargs->ecdh_a[testnum];
1060 //EVP_PKEY *ecdh_b = tempargs->ecdh_b[testnum];
1061 EVP_PKEY_CTX
*ctx
= tempargs
->ecdh_ctx
[testnum
];
1062 unsigned char *derived_secret
= tempargs
->secret_a
;
1064 size_t *outlen
= &(tempargs
->outlen
);
1066 for (count
= 0; COND(ecdh_c
[testnum
][0]); count
++) {
1067 ECDH_EVP_derive_key(derived_secret
, outlen
, /*ecdh_a, ecdh_b,*/ ctx
);
1072 static const size_t KDF1_SHA1_len
= 20;
1073 static void *KDF1_SHA1(const void *in
, size_t inlen
, void *out
,
1076 if (*outlen
< SHA_DIGEST_LENGTH
)
1078 *outlen
= SHA_DIGEST_LENGTH
;
1079 return SHA1(in
, inlen
, out
);
1081 #endif /* OPENSSL_NO_EC */
1083 static int run_benchmark(int async_jobs
,
1084 int (*loop_function
)(void *), loopargs_t
*loopargs
)
1086 int job_op_count
= 0;
1087 int total_op_count
= 0;
1088 int num_inprogress
= 0;
1089 int error
= 0, i
= 0, ret
= 0;
1090 OSSL_ASYNC_FD job_fd
= 0;
1091 size_t num_job_fds
= 0;
1095 if (async_jobs
== 0) {
1096 return loop_function((void *)&loopargs
);
1099 for (i
= 0; i
< async_jobs
&& !error
; i
++) {
1100 loopargs_t
*looparg_item
= loopargs
+ i
;
1102 /* Copy pointer content (looparg_t item address) into async context */
1103 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
, loopargs
[i
].wait_ctx
,
1104 &job_op_count
, loop_function
,
1105 (void *)&looparg_item
, sizeof(looparg_item
));
1111 if (job_op_count
== -1) {
1114 total_op_count
+= job_op_count
;
1119 BIO_printf(bio_err
, "Failure in the job\n");
1120 ERR_print_errors(bio_err
);
1126 while (num_inprogress
> 0) {
1127 #if defined(OPENSSL_SYS_WINDOWS)
1129 #elif defined(OPENSSL_SYS_UNIX)
1130 int select_result
= 0;
1131 OSSL_ASYNC_FD max_fd
= 0;
1134 FD_ZERO(&waitfdset
);
1136 for (i
= 0; i
< async_jobs
&& num_inprogress
> 0; i
++) {
1137 if (loopargs
[i
].inprogress_job
== NULL
)
1140 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1141 || num_job_fds
> 1) {
1142 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1143 ERR_print_errors(bio_err
);
1147 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
, &num_job_fds
);
1148 FD_SET(job_fd
, &waitfdset
);
1149 if (job_fd
> max_fd
)
1153 if (max_fd
>= (OSSL_ASYNC_FD
)FD_SETSIZE
) {
1155 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1156 "Decrease the value of async_jobs\n",
1157 max_fd
, FD_SETSIZE
);
1158 ERR_print_errors(bio_err
);
1163 select_result
= select(max_fd
+ 1, &waitfdset
, NULL
, NULL
, NULL
);
1164 if (select_result
== -1 && errno
== EINTR
)
1167 if (select_result
== -1) {
1168 BIO_printf(bio_err
, "Failure in the select\n");
1169 ERR_print_errors(bio_err
);
1174 if (select_result
== 0)
1178 for (i
= 0; i
< async_jobs
; i
++) {
1179 if (loopargs
[i
].inprogress_job
== NULL
)
1182 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1183 || num_job_fds
> 1) {
1184 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1185 ERR_print_errors(bio_err
);
1189 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
, &num_job_fds
);
1191 #if defined(OPENSSL_SYS_UNIX)
1192 if (num_job_fds
== 1 && !FD_ISSET(job_fd
, &waitfdset
))
1194 #elif defined(OPENSSL_SYS_WINDOWS)
1195 if (num_job_fds
== 1
1196 && !PeekNamedPipe(job_fd
, NULL
, 0, NULL
, &avail
, NULL
)
1201 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
,
1202 loopargs
[i
].wait_ctx
, &job_op_count
, loop_function
,
1203 (void *)(loopargs
+ i
), sizeof(loopargs_t
));
1208 if (job_op_count
== -1) {
1211 total_op_count
+= job_op_count
;
1214 loopargs
[i
].inprogress_job
= NULL
;
1219 loopargs
[i
].inprogress_job
= NULL
;
1220 BIO_printf(bio_err
, "Failure in the job\n");
1221 ERR_print_errors(bio_err
);
1228 return error
? -1 : total_op_count
;
1231 int speed_main(int argc
, char **argv
)
1234 loopargs_t
*loopargs
= NULL
;
1236 int loopargs_len
= 0;
1238 const char *engine_id
= NULL
;
1239 const EVP_CIPHER
*evp_cipher
= NULL
;
1242 int multiblock
= 0, pr_header
= 0;
1243 int doit
[ALGOR_NUM
] = { 0 };
1244 int ret
= 1, i
, k
, misalign
= 0;
1250 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1251 || !defined(OPENSSL_NO_EC)
1255 /* What follows are the buffers and key material. */
1256 #ifndef OPENSSL_NO_RC5
1259 #ifndef OPENSSL_NO_RC2
1262 #ifndef OPENSSL_NO_IDEA
1263 IDEA_KEY_SCHEDULE idea_ks
;
1265 #ifndef OPENSSL_NO_SEED
1266 SEED_KEY_SCHEDULE seed_ks
;
1268 #ifndef OPENSSL_NO_BF
1271 #ifndef OPENSSL_NO_CAST
1274 static const unsigned char key16
[16] = {
1275 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1276 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1278 static const unsigned char key24
[24] = {
1279 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1280 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1281 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1283 static const unsigned char key32
[32] = {
1284 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1285 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1286 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1287 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1289 #ifndef OPENSSL_NO_CAMELLIA
1290 static const unsigned char ckey24
[24] = {
1291 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1292 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1293 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1295 static const unsigned char ckey32
[32] = {
1296 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1297 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1298 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1299 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1301 CAMELLIA_KEY camellia_ks1
, camellia_ks2
, camellia_ks3
;
1303 #ifndef OPENSSL_NO_DES
1304 static DES_cblock key
= {
1305 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1307 static DES_cblock key2
= {
1308 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1310 static DES_cblock key3
= {
1311 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1314 #ifndef OPENSSL_NO_RSA
1315 static const unsigned int rsa_bits
[RSA_NUM
] = {
1316 512, 1024, 2048, 3072, 4096, 7680, 15360
1318 static const unsigned char *rsa_data
[RSA_NUM
] = {
1319 test512
, test1024
, test2048
, test3072
, test4096
, test7680
, test15360
1321 static const int rsa_data_length
[RSA_NUM
] = {
1322 sizeof(test512
), sizeof(test1024
),
1323 sizeof(test2048
), sizeof(test3072
),
1324 sizeof(test4096
), sizeof(test7680
),
1327 int rsa_doit
[RSA_NUM
] = { 0 };
1329 #ifndef OPENSSL_NO_DSA
1330 static const unsigned int dsa_bits
[DSA_NUM
] = { 512, 1024, 2048 };
1331 int dsa_doit
[DSA_NUM
] = { 0 };
1333 #ifndef OPENSSL_NO_EC
1335 * We only test over the following curves as they are representative, To
1336 * add tests over more curves, simply add the curve NID and curve name to
1337 * the following arrays and increase the EC_NUM value accordingly.
1339 static const unsigned int test_curves
[EC_NUM
] = {
1341 NID_secp160r1
, NID_X9_62_prime192v1
, NID_secp224r1
,
1342 NID_X9_62_prime256v1
, NID_secp384r1
, NID_secp521r1
,
1344 NID_sect163k1
, NID_sect233k1
, NID_sect283k1
,
1345 NID_sect409k1
, NID_sect571k1
, NID_sect163r2
,
1346 NID_sect233r1
, NID_sect283r1
, NID_sect409r1
,
1351 static const char *test_curves_names
[EC_NUM
] = {
1353 "secp160r1", "nistp192", "nistp224",
1354 "nistp256", "nistp384", "nistp521",
1356 "nistk163", "nistk233", "nistk283",
1357 "nistk409", "nistk571", "nistb163",
1358 "nistb233", "nistb283", "nistb409",
1363 static const int test_curves_bits
[EC_NUM
] = {
1369 571, 253 /* X25519 */
1372 int ecdsa_doit
[EC_NUM
] = { 0 };
1373 int ecdh_doit
[EC_NUM
] = { 0 };
1374 #endif /* ndef OPENSSL_NO_EC */
1376 prog
= opt_init(argc
, argv
, speed_options
);
1377 while ((o
= opt_next()) != OPT_EOF
) {
1382 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
1385 opt_help(speed_options
);
1392 evp_cipher
= EVP_get_cipherbyname(opt_arg());
1393 if (evp_cipher
== NULL
)
1394 evp_md
= EVP_get_digestbyname(opt_arg());
1395 if (evp_cipher
== NULL
&& evp_md
== NULL
) {
1397 "%s: %s is an unknown cipher or digest\n",
1408 * In a forked execution, an engine might need to be
1409 * initialised by each child process, not by the parent.
1410 * So store the name here and run setup_engine() later on.
1412 engine_id
= opt_arg();
1416 multi
= atoi(opt_arg());
1420 #ifndef OPENSSL_NO_ASYNC
1421 async_jobs
= atoi(opt_arg());
1422 if (!ASYNC_is_capable()) {
1424 "%s: async_jobs specified but async not supported\n",
1431 if (!opt_int(opt_arg(), &misalign
))
1433 if (misalign
> MISALIGN
) {
1435 "%s: Maximum offset is %d\n", prog
, MISALIGN
);
1444 #ifdef OPENSSL_NO_MULTIBLOCK
1446 "%s: -mb specified but multi-block support is disabled\n",
1453 argc
= opt_num_rest();
1456 /* Remaining arguments are algorithms. */
1457 for ( ; *argv
; argv
++) {
1458 if (found(*argv
, doit_choices
, &i
)) {
1462 #ifndef OPENSSL_NO_DES
1463 if (strcmp(*argv
, "des") == 0) {
1464 doit
[D_CBC_DES
] = doit
[D_EDE3_DES
] = 1;
1468 if (strcmp(*argv
, "sha") == 0) {
1469 doit
[D_SHA1
] = doit
[D_SHA256
] = doit
[D_SHA512
] = 1;
1472 #ifndef OPENSSL_NO_RSA
1474 if (strcmp(*argv
, "openssl") == 0) {
1475 RSA_set_default_method(RSA_PKCS1_OpenSSL());
1479 if (strcmp(*argv
, "rsa") == 0) {
1480 rsa_doit
[R_RSA_512
] = rsa_doit
[R_RSA_1024
] =
1481 rsa_doit
[R_RSA_2048
] = rsa_doit
[R_RSA_3072
] =
1482 rsa_doit
[R_RSA_4096
] = rsa_doit
[R_RSA_7680
] =
1483 rsa_doit
[R_RSA_15360
] = 1;
1486 if (found(*argv
, rsa_choices
, &i
)) {
1491 #ifndef OPENSSL_NO_DSA
1492 if (strcmp(*argv
, "dsa") == 0) {
1493 dsa_doit
[R_DSA_512
] = dsa_doit
[R_DSA_1024
] =
1494 dsa_doit
[R_DSA_2048
] = 1;
1497 if (found(*argv
, dsa_choices
, &i
)) {
1502 if (strcmp(*argv
, "aes") == 0) {
1503 doit
[D_CBC_128_AES
] = doit
[D_CBC_192_AES
] =
1504 doit
[D_CBC_256_AES
] = 1;
1507 #ifndef OPENSSL_NO_CAMELLIA
1508 if (strcmp(*argv
, "camellia") == 0) {
1509 doit
[D_CBC_128_CML
] = doit
[D_CBC_192_CML
] =
1510 doit
[D_CBC_256_CML
] = 1;
1514 #ifndef OPENSSL_NO_EC
1515 if (strcmp(*argv
, "ecdsa") == 0) {
1516 for (i
= 0; i
< EC_NUM
; i
++)
1520 if (found(*argv
, ecdsa_choices
, &i
)) {
1524 if (strcmp(*argv
, "ecdh") == 0) {
1525 for (i
= 0; i
< EC_NUM
; i
++)
1529 if (found(*argv
, ecdh_choices
, &i
)) {
1534 BIO_printf(bio_err
, "%s: Unknown algorithm %s\n", prog
, *argv
);
1538 /* Initialize the job pool if async mode is enabled */
1539 if (async_jobs
> 0) {
1540 async_init
= ASYNC_init_thread(async_jobs
, async_jobs
);
1542 BIO_printf(bio_err
, "Error creating the ASYNC job pool\n");
1547 loopargs_len
= (async_jobs
== 0 ? 1 : async_jobs
);
1548 loopargs
= app_malloc(loopargs_len
* sizeof(loopargs_t
), "array of loopargs");
1549 memset(loopargs
, 0, loopargs_len
* sizeof(loopargs_t
));
1551 for (i
= 0; i
< loopargs_len
; i
++) {
1552 if (async_jobs
> 0) {
1553 loopargs
[i
].wait_ctx
= ASYNC_WAIT_CTX_new();
1554 if (loopargs
[i
].wait_ctx
== NULL
) {
1555 BIO_printf(bio_err
, "Error creating the ASYNC_WAIT_CTX\n");
1560 loopargs
[i
].buf_malloc
= app_malloc((int)BUFSIZE
+ MAX_MISALIGNMENT
+ 1, "input buffer");
1561 loopargs
[i
].buf2_malloc
= app_malloc((int)BUFSIZE
+ MAX_MISALIGNMENT
+ 1, "input buffer");
1562 /* Align the start of buffers on a 64 byte boundary */
1563 loopargs
[i
].buf
= loopargs
[i
].buf_malloc
+ misalign
;
1564 loopargs
[i
].buf2
= loopargs
[i
].buf2_malloc
+ misalign
;
1565 #ifndef OPENSSL_NO_EC
1566 loopargs
[i
].secret_a
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret a");
1567 loopargs
[i
].secret_b
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret b");
1572 if (multi
&& do_multi(multi
))
1576 /* Initialize the engine after the fork */
1577 e
= setup_engine(engine_id
, 0);
1579 /* No parameters; turn on everything. */
1580 if ((argc
== 0) && !doit
[D_EVP
]) {
1581 for (i
= 0; i
< ALGOR_NUM
; i
++)
1584 #ifndef OPENSSL_NO_RSA
1585 for (i
= 0; i
< RSA_NUM
; i
++)
1588 #ifndef OPENSSL_NO_DSA
1589 for (i
= 0; i
< DSA_NUM
; i
++)
1592 #ifndef OPENSSL_NO_EC
1593 for (i
= 0; i
< EC_NUM
; i
++)
1595 for (i
= 0; i
< EC_NUM
; i
++)
1599 for (i
= 0; i
< ALGOR_NUM
; i
++)
1603 if (usertime
== 0 && !mr
)
1605 "You have chosen to measure elapsed time "
1606 "instead of user CPU time.\n");
1608 #ifndef OPENSSL_NO_RSA
1609 for (i
= 0; i
< loopargs_len
; i
++) {
1610 for (k
= 0; k
< RSA_NUM
; k
++) {
1611 const unsigned char *p
;
1614 loopargs
[i
].rsa_key
[k
] = d2i_RSAPrivateKey(NULL
, &p
, rsa_data_length
[k
]);
1615 if (loopargs
[i
].rsa_key
[k
] == NULL
) {
1616 BIO_printf(bio_err
, "internal error loading RSA key number %d\n",
1623 #ifndef OPENSSL_NO_DSA
1624 for (i
= 0; i
< loopargs_len
; i
++) {
1625 loopargs
[i
].dsa_key
[0] = get_dsa512();
1626 loopargs
[i
].dsa_key
[1] = get_dsa1024();
1627 loopargs
[i
].dsa_key
[2] = get_dsa2048();
1630 #ifndef OPENSSL_NO_DES
1631 DES_set_key_unchecked(&key
, &sch
);
1632 DES_set_key_unchecked(&key2
, &sch2
);
1633 DES_set_key_unchecked(&key3
, &sch3
);
1635 AES_set_encrypt_key(key16
, 128, &aes_ks1
);
1636 AES_set_encrypt_key(key24
, 192, &aes_ks2
);
1637 AES_set_encrypt_key(key32
, 256, &aes_ks3
);
1638 #ifndef OPENSSL_NO_CAMELLIA
1639 Camellia_set_key(key16
, 128, &camellia_ks1
);
1640 Camellia_set_key(ckey24
, 192, &camellia_ks2
);
1641 Camellia_set_key(ckey32
, 256, &camellia_ks3
);
1643 #ifndef OPENSSL_NO_IDEA
1644 IDEA_set_encrypt_key(key16
, &idea_ks
);
1646 #ifndef OPENSSL_NO_SEED
1647 SEED_set_key(key16
, &seed_ks
);
1649 #ifndef OPENSSL_NO_RC4
1650 RC4_set_key(&rc4_ks
, 16, key16
);
1652 #ifndef OPENSSL_NO_RC2
1653 RC2_set_key(&rc2_ks
, 16, key16
, 128);
1655 #ifndef OPENSSL_NO_RC5
1656 RC5_32_set_key(&rc5_ks
, 16, key16
, 12);
1658 #ifndef OPENSSL_NO_BF
1659 BF_set_key(&bf_ks
, 16, key16
);
1661 #ifndef OPENSSL_NO_CAST
1662 CAST_set_key(&cast_ks
, 16, key16
);
1665 # ifndef OPENSSL_NO_DES
1666 BIO_printf(bio_err
, "First we calculate the approximate speed ...\n");
1672 for (it
= count
; it
; it
--)
1673 DES_ecb_encrypt((DES_cblock
*)loopargs
[0].buf
,
1674 (DES_cblock
*)loopargs
[0].buf
, &sch
, DES_ENCRYPT
);
1678 c
[D_MD2
][0] = count
/ 10;
1679 c
[D_MDC2
][0] = count
/ 10;
1680 c
[D_MD4
][0] = count
;
1681 c
[D_MD5
][0] = count
;
1682 c
[D_HMAC
][0] = count
;
1683 c
[D_SHA1
][0] = count
;
1684 c
[D_RMD160
][0] = count
;
1685 c
[D_RC4
][0] = count
* 5;
1686 c
[D_CBC_DES
][0] = count
;
1687 c
[D_EDE3_DES
][0] = count
/ 3;
1688 c
[D_CBC_IDEA
][0] = count
;
1689 c
[D_CBC_SEED
][0] = count
;
1690 c
[D_CBC_RC2
][0] = count
;
1691 c
[D_CBC_RC5
][0] = count
;
1692 c
[D_CBC_BF
][0] = count
;
1693 c
[D_CBC_CAST
][0] = count
;
1694 c
[D_CBC_128_AES
][0] = count
;
1695 c
[D_CBC_192_AES
][0] = count
;
1696 c
[D_CBC_256_AES
][0] = count
;
1697 c
[D_CBC_128_CML
][0] = count
;
1698 c
[D_CBC_192_CML
][0] = count
;
1699 c
[D_CBC_256_CML
][0] = count
;
1700 c
[D_SHA256
][0] = count
;
1701 c
[D_SHA512
][0] = count
;
1702 c
[D_WHIRLPOOL
][0] = count
;
1703 c
[D_IGE_128_AES
][0] = count
;
1704 c
[D_IGE_192_AES
][0] = count
;
1705 c
[D_IGE_256_AES
][0] = count
;
1706 c
[D_GHASH
][0] = count
;
1708 for (i
= 1; i
< SIZE_NUM
; i
++) {
1711 l0
= (long)lengths
[0];
1712 l1
= (long)lengths
[i
];
1714 c
[D_MD2
][i
] = c
[D_MD2
][0] * 4 * l0
/ l1
;
1715 c
[D_MDC2
][i
] = c
[D_MDC2
][0] * 4 * l0
/ l1
;
1716 c
[D_MD4
][i
] = c
[D_MD4
][0] * 4 * l0
/ l1
;
1717 c
[D_MD5
][i
] = c
[D_MD5
][0] * 4 * l0
/ l1
;
1718 c
[D_HMAC
][i
] = c
[D_HMAC
][0] * 4 * l0
/ l1
;
1719 c
[D_SHA1
][i
] = c
[D_SHA1
][0] * 4 * l0
/ l1
;
1720 c
[D_RMD160
][i
] = c
[D_RMD160
][0] * 4 * l0
/ l1
;
1721 c
[D_SHA256
][i
] = c
[D_SHA256
][0] * 4 * l0
/ l1
;
1722 c
[D_SHA512
][i
] = c
[D_SHA512
][0] * 4 * l0
/ l1
;
1723 c
[D_WHIRLPOOL
][i
] = c
[D_WHIRLPOOL
][0] * 4 * l0
/ l1
;
1724 c
[D_GHASH
][i
] = c
[D_GHASH
][0] * 4 * l0
/ l1
;
1726 l0
= (long)lengths
[i
- 1];
1728 c
[D_RC4
][i
] = c
[D_RC4
][i
- 1] * l0
/ l1
;
1729 c
[D_CBC_DES
][i
] = c
[D_CBC_DES
][i
- 1] * l0
/ l1
;
1730 c
[D_EDE3_DES
][i
] = c
[D_EDE3_DES
][i
- 1] * l0
/ l1
;
1731 c
[D_CBC_IDEA
][i
] = c
[D_CBC_IDEA
][i
- 1] * l0
/ l1
;
1732 c
[D_CBC_SEED
][i
] = c
[D_CBC_SEED
][i
- 1] * l0
/ l1
;
1733 c
[D_CBC_RC2
][i
] = c
[D_CBC_RC2
][i
- 1] * l0
/ l1
;
1734 c
[D_CBC_RC5
][i
] = c
[D_CBC_RC5
][i
- 1] * l0
/ l1
;
1735 c
[D_CBC_BF
][i
] = c
[D_CBC_BF
][i
- 1] * l0
/ l1
;
1736 c
[D_CBC_CAST
][i
] = c
[D_CBC_CAST
][i
- 1] * l0
/ l1
;
1737 c
[D_CBC_128_AES
][i
] = c
[D_CBC_128_AES
][i
- 1] * l0
/ l1
;
1738 c
[D_CBC_192_AES
][i
] = c
[D_CBC_192_AES
][i
- 1] * l0
/ l1
;
1739 c
[D_CBC_256_AES
][i
] = c
[D_CBC_256_AES
][i
- 1] * l0
/ l1
;
1740 c
[D_CBC_128_CML
][i
] = c
[D_CBC_128_CML
][i
- 1] * l0
/ l1
;
1741 c
[D_CBC_192_CML
][i
] = c
[D_CBC_192_CML
][i
- 1] * l0
/ l1
;
1742 c
[D_CBC_256_CML
][i
] = c
[D_CBC_256_CML
][i
- 1] * l0
/ l1
;
1743 c
[D_IGE_128_AES
][i
] = c
[D_IGE_128_AES
][i
- 1] * l0
/ l1
;
1744 c
[D_IGE_192_AES
][i
] = c
[D_IGE_192_AES
][i
- 1] * l0
/ l1
;
1745 c
[D_IGE_256_AES
][i
] = c
[D_IGE_256_AES
][i
- 1] * l0
/ l1
;
1748 # ifndef OPENSSL_NO_RSA
1749 rsa_c
[R_RSA_512
][0] = count
/ 2000;
1750 rsa_c
[R_RSA_512
][1] = count
/ 400;
1751 for (i
= 1; i
< RSA_NUM
; i
++) {
1752 rsa_c
[i
][0] = rsa_c
[i
- 1][0] / 8;
1753 rsa_c
[i
][1] = rsa_c
[i
- 1][1] / 4;
1754 if (rsa_doit
[i
] <= 1 && rsa_c
[i
][0] == 0)
1757 if (rsa_c
[i
][0] == 0) {
1758 rsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
1765 # ifndef OPENSSL_NO_DSA
1766 dsa_c
[R_DSA_512
][0] = count
/ 1000;
1767 dsa_c
[R_DSA_512
][1] = count
/ 1000 / 2;
1768 for (i
= 1; i
< DSA_NUM
; i
++) {
1769 dsa_c
[i
][0] = dsa_c
[i
- 1][0] / 4;
1770 dsa_c
[i
][1] = dsa_c
[i
- 1][1] / 4;
1771 if (dsa_doit
[i
] <= 1 && dsa_c
[i
][0] == 0)
1774 if (dsa_c
[i
][0] == 0) {
1775 dsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
1782 # ifndef OPENSSL_NO_EC
1783 ecdsa_c
[R_EC_P160
][0] = count
/ 1000;
1784 ecdsa_c
[R_EC_P160
][1] = count
/ 1000 / 2;
1785 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
1786 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1787 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1788 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
1791 if (ecdsa_c
[i
][0] == 0) {
1797 ecdsa_c
[R_EC_K163
][0] = count
/ 1000;
1798 ecdsa_c
[R_EC_K163
][1] = count
/ 1000 / 2;
1799 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
1800 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1801 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1802 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
1805 if (ecdsa_c
[i
][0] == 0) {
1811 ecdsa_c
[R_EC_B163
][0] = count
/ 1000;
1812 ecdsa_c
[R_EC_B163
][1] = count
/ 1000 / 2;
1813 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
1814 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1815 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1816 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
1819 if (ecdsa_c
[i
][0] == 0) {
1826 ecdh_c
[R_EC_P160
][0] = count
/ 1000;
1827 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
1828 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1829 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
1832 if (ecdh_c
[i
][0] == 0) {
1837 ecdh_c
[R_EC_K163
][0] = count
/ 1000;
1838 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
1839 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1840 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
1843 if (ecdh_c
[i
][0] == 0) {
1848 ecdh_c
[R_EC_B163
][0] = count
/ 1000;
1849 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
1850 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1851 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
1854 if (ecdh_c
[i
][0] == 0) {
1862 /* not worth fixing */
1863 # error "You cannot disable DES on systems without SIGALRM."
1864 # endif /* OPENSSL_NO_DES */
1867 signal(SIGALRM
, sig_done
);
1869 #endif /* SIGALRM */
1871 #ifndef OPENSSL_NO_MD2
1873 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1874 print_message(names
[D_MD2
], c
[D_MD2
][testnum
], lengths
[testnum
]);
1876 count
= run_benchmark(async_jobs
, EVP_Digest_MD2_loop
, loopargs
);
1878 print_result(D_MD2
, testnum
, count
, d
);
1882 #ifndef OPENSSL_NO_MDC2
1884 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1885 print_message(names
[D_MDC2
], c
[D_MDC2
][testnum
], lengths
[testnum
]);
1887 count
= run_benchmark(async_jobs
, EVP_Digest_MDC2_loop
, loopargs
);
1889 print_result(D_MDC2
, testnum
, count
, d
);
1894 #ifndef OPENSSL_NO_MD4
1896 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1897 print_message(names
[D_MD4
], c
[D_MD4
][testnum
], lengths
[testnum
]);
1899 count
= run_benchmark(async_jobs
, EVP_Digest_MD4_loop
, loopargs
);
1901 print_result(D_MD4
, testnum
, count
, d
);
1906 #ifndef OPENSSL_NO_MD5
1908 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1909 print_message(names
[D_MD5
], c
[D_MD5
][testnum
], lengths
[testnum
]);
1911 count
= run_benchmark(async_jobs
, MD5_loop
, loopargs
);
1913 print_result(D_MD5
, testnum
, count
, d
);
1918 static const char hmac_key
[] = "This is a key...";
1919 int len
= strlen(hmac_key
);
1921 for (i
= 0; i
< loopargs_len
; i
++) {
1922 loopargs
[i
].hctx
= HMAC_CTX_new();
1923 if (loopargs
[i
].hctx
== NULL
) {
1924 BIO_printf(bio_err
, "HMAC malloc failure, exiting...");
1928 HMAC_Init_ex(loopargs
[i
].hctx
, hmac_key
, len
, EVP_md5(), NULL
);
1930 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1931 print_message(names
[D_HMAC
], c
[D_HMAC
][testnum
], lengths
[testnum
]);
1933 count
= run_benchmark(async_jobs
, HMAC_loop
, loopargs
);
1935 print_result(D_HMAC
, testnum
, count
, d
);
1937 for (i
= 0; i
< loopargs_len
; i
++) {
1938 HMAC_CTX_free(loopargs
[i
].hctx
);
1943 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1944 print_message(names
[D_SHA1
], c
[D_SHA1
][testnum
], lengths
[testnum
]);
1946 count
= run_benchmark(async_jobs
, SHA1_loop
, loopargs
);
1948 print_result(D_SHA1
, testnum
, count
, d
);
1951 if (doit
[D_SHA256
]) {
1952 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1953 print_message(names
[D_SHA256
], c
[D_SHA256
][testnum
], lengths
[testnum
]);
1955 count
= run_benchmark(async_jobs
, SHA256_loop
, loopargs
);
1957 print_result(D_SHA256
, testnum
, count
, d
);
1960 if (doit
[D_SHA512
]) {
1961 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1962 print_message(names
[D_SHA512
], c
[D_SHA512
][testnum
], lengths
[testnum
]);
1964 count
= run_benchmark(async_jobs
, SHA512_loop
, loopargs
);
1966 print_result(D_SHA512
, testnum
, count
, d
);
1970 #ifndef OPENSSL_NO_WHIRLPOOL
1971 if (doit
[D_WHIRLPOOL
]) {
1972 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1973 print_message(names
[D_WHIRLPOOL
], c
[D_WHIRLPOOL
][testnum
], lengths
[testnum
]);
1975 count
= run_benchmark(async_jobs
, WHIRLPOOL_loop
, loopargs
);
1977 print_result(D_WHIRLPOOL
, testnum
, count
, d
);
1982 #ifndef OPENSSL_NO_RMD160
1983 if (doit
[D_RMD160
]) {
1984 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1985 print_message(names
[D_RMD160
], c
[D_RMD160
][testnum
], lengths
[testnum
]);
1987 count
= run_benchmark(async_jobs
, EVP_Digest_RMD160_loop
, loopargs
);
1989 print_result(D_RMD160
, testnum
, count
, d
);
1993 #ifndef OPENSSL_NO_RC4
1995 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1996 print_message(names
[D_RC4
], c
[D_RC4
][testnum
], lengths
[testnum
]);
1998 count
= run_benchmark(async_jobs
, RC4_loop
, loopargs
);
2000 print_result(D_RC4
, testnum
, count
, d
);
2004 #ifndef OPENSSL_NO_DES
2005 if (doit
[D_CBC_DES
]) {
2006 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2007 print_message(names
[D_CBC_DES
], c
[D_CBC_DES
][testnum
], lengths
[testnum
]);
2009 count
= run_benchmark(async_jobs
, DES_ncbc_encrypt_loop
, loopargs
);
2011 print_result(D_CBC_DES
, testnum
, count
, d
);
2015 if (doit
[D_EDE3_DES
]) {
2016 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2017 print_message(names
[D_EDE3_DES
], c
[D_EDE3_DES
][testnum
], lengths
[testnum
]);
2019 count
= run_benchmark(async_jobs
, DES_ede3_cbc_encrypt_loop
, loopargs
);
2021 print_result(D_EDE3_DES
, testnum
, count
, d
);
2026 if (doit
[D_CBC_128_AES
]) {
2027 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2028 print_message(names
[D_CBC_128_AES
], c
[D_CBC_128_AES
][testnum
],
2031 count
= run_benchmark(async_jobs
, AES_cbc_128_encrypt_loop
, loopargs
);
2033 print_result(D_CBC_128_AES
, testnum
, count
, d
);
2036 if (doit
[D_CBC_192_AES
]) {
2037 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2038 print_message(names
[D_CBC_192_AES
], c
[D_CBC_192_AES
][testnum
],
2041 count
= run_benchmark(async_jobs
, AES_cbc_192_encrypt_loop
, loopargs
);
2043 print_result(D_CBC_192_AES
, testnum
, count
, d
);
2046 if (doit
[D_CBC_256_AES
]) {
2047 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2048 print_message(names
[D_CBC_256_AES
], c
[D_CBC_256_AES
][testnum
],
2051 count
= run_benchmark(async_jobs
, AES_cbc_256_encrypt_loop
, loopargs
);
2053 print_result(D_CBC_256_AES
, testnum
, count
, d
);
2057 if (doit
[D_IGE_128_AES
]) {
2058 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2059 print_message(names
[D_IGE_128_AES
], c
[D_IGE_128_AES
][testnum
],
2062 count
= run_benchmark(async_jobs
, AES_ige_128_encrypt_loop
, loopargs
);
2064 print_result(D_IGE_128_AES
, testnum
, count
, d
);
2067 if (doit
[D_IGE_192_AES
]) {
2068 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2069 print_message(names
[D_IGE_192_AES
], c
[D_IGE_192_AES
][testnum
],
2072 count
= run_benchmark(async_jobs
, AES_ige_192_encrypt_loop
, loopargs
);
2074 print_result(D_IGE_192_AES
, testnum
, count
, d
);
2077 if (doit
[D_IGE_256_AES
]) {
2078 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2079 print_message(names
[D_IGE_256_AES
], c
[D_IGE_256_AES
][testnum
],
2082 count
= run_benchmark(async_jobs
, AES_ige_256_encrypt_loop
, loopargs
);
2084 print_result(D_IGE_256_AES
, testnum
, count
, d
);
2087 if (doit
[D_GHASH
]) {
2088 for (i
= 0; i
< loopargs_len
; i
++) {
2089 loopargs
[i
].gcm_ctx
= CRYPTO_gcm128_new(&aes_ks1
, (block128_f
) AES_encrypt
);
2090 CRYPTO_gcm128_setiv(loopargs
[i
].gcm_ctx
, (unsigned char *)"0123456789ab", 12);
2093 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2094 print_message(names
[D_GHASH
], c
[D_GHASH
][testnum
], lengths
[testnum
]);
2096 count
= run_benchmark(async_jobs
, CRYPTO_gcm128_aad_loop
, loopargs
);
2098 print_result(D_GHASH
, testnum
, count
, d
);
2100 for (i
= 0; i
< loopargs_len
; i
++)
2101 CRYPTO_gcm128_release(loopargs
[i
].gcm_ctx
);
2104 #ifndef OPENSSL_NO_CAMELLIA
2105 if (doit
[D_CBC_128_CML
]) {
2106 if (async_jobs
> 0) {
2107 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2108 names
[D_CBC_128_CML
]);
2109 doit
[D_CBC_128_CML
] = 0;
2111 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2112 print_message(names
[D_CBC_128_CML
], c
[D_CBC_128_CML
][testnum
],
2115 for (count
= 0, run
= 1; COND(c
[D_CBC_128_CML
][testnum
]); count
++)
2116 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2117 (size_t)lengths
[testnum
], &camellia_ks1
,
2118 iv
, CAMELLIA_ENCRYPT
);
2120 print_result(D_CBC_128_CML
, testnum
, count
, d
);
2123 if (doit
[D_CBC_192_CML
]) {
2124 if (async_jobs
> 0) {
2125 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2126 names
[D_CBC_192_CML
]);
2127 doit
[D_CBC_192_CML
] = 0;
2129 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2130 print_message(names
[D_CBC_192_CML
], c
[D_CBC_192_CML
][testnum
],
2132 if (async_jobs
> 0) {
2133 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2137 for (count
= 0, run
= 1; COND(c
[D_CBC_192_CML
][testnum
]); count
++)
2138 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2139 (size_t)lengths
[testnum
], &camellia_ks2
,
2140 iv
, CAMELLIA_ENCRYPT
);
2142 print_result(D_CBC_192_CML
, testnum
, count
, d
);
2145 if (doit
[D_CBC_256_CML
]) {
2146 if (async_jobs
> 0) {
2147 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2148 names
[D_CBC_256_CML
]);
2149 doit
[D_CBC_256_CML
] = 0;
2151 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2152 print_message(names
[D_CBC_256_CML
], c
[D_CBC_256_CML
][testnum
],
2155 for (count
= 0, run
= 1; COND(c
[D_CBC_256_CML
][testnum
]); count
++)
2156 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2157 (size_t)lengths
[testnum
], &camellia_ks3
,
2158 iv
, CAMELLIA_ENCRYPT
);
2160 print_result(D_CBC_256_CML
, testnum
, count
, d
);
2164 #ifndef OPENSSL_NO_IDEA
2165 if (doit
[D_CBC_IDEA
]) {
2166 if (async_jobs
> 0) {
2167 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2169 doit
[D_CBC_IDEA
] = 0;
2171 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2172 print_message(names
[D_CBC_IDEA
], c
[D_CBC_IDEA
][testnum
], lengths
[testnum
]);
2174 for (count
= 0, run
= 1; COND(c
[D_CBC_IDEA
][testnum
]); count
++)
2175 IDEA_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2176 (size_t)lengths
[testnum
], &idea_ks
,
2179 print_result(D_CBC_IDEA
, testnum
, count
, d
);
2183 #ifndef OPENSSL_NO_SEED
2184 if (doit
[D_CBC_SEED
]) {
2185 if (async_jobs
> 0) {
2186 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2188 doit
[D_CBC_SEED
] = 0;
2190 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2191 print_message(names
[D_CBC_SEED
], c
[D_CBC_SEED
][testnum
], lengths
[testnum
]);
2193 for (count
= 0, run
= 1; COND(c
[D_CBC_SEED
][testnum
]); count
++)
2194 SEED_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2195 (size_t)lengths
[testnum
], &seed_ks
, iv
, 1);
2197 print_result(D_CBC_SEED
, testnum
, count
, d
);
2201 #ifndef OPENSSL_NO_RC2
2202 if (doit
[D_CBC_RC2
]) {
2203 if (async_jobs
> 0) {
2204 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2206 doit
[D_CBC_RC2
] = 0;
2208 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2209 print_message(names
[D_CBC_RC2
], c
[D_CBC_RC2
][testnum
], lengths
[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_RC2
][testnum
]); count
++)
2216 RC2_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2217 (size_t)lengths
[testnum
], &rc2_ks
,
2220 print_result(D_CBC_RC2
, testnum
, count
, d
);
2224 #ifndef OPENSSL_NO_RC5
2225 if (doit
[D_CBC_RC5
]) {
2226 if (async_jobs
> 0) {
2227 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2229 doit
[D_CBC_RC5
] = 0;
2231 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2232 print_message(names
[D_CBC_RC5
], c
[D_CBC_RC5
][testnum
], lengths
[testnum
]);
2233 if (async_jobs
> 0) {
2234 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2238 for (count
= 0, run
= 1; COND(c
[D_CBC_RC5
][testnum
]); count
++)
2239 RC5_32_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2240 (size_t)lengths
[testnum
], &rc5_ks
,
2243 print_result(D_CBC_RC5
, testnum
, count
, d
);
2247 #ifndef OPENSSL_NO_BF
2248 if (doit
[D_CBC_BF
]) {
2249 if (async_jobs
> 0) {
2250 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2254 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2255 print_message(names
[D_CBC_BF
], c
[D_CBC_BF
][testnum
], lengths
[testnum
]);
2257 for (count
= 0, run
= 1; COND(c
[D_CBC_BF
][testnum
]); count
++)
2258 BF_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2259 (size_t)lengths
[testnum
], &bf_ks
,
2262 print_result(D_CBC_BF
, testnum
, count
, d
);
2266 #ifndef OPENSSL_NO_CAST
2267 if (doit
[D_CBC_CAST
]) {
2268 if (async_jobs
> 0) {
2269 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2271 doit
[D_CBC_CAST
] = 0;
2273 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2274 print_message(names
[D_CBC_CAST
], c
[D_CBC_CAST
][testnum
], lengths
[testnum
]);
2276 for (count
= 0, run
= 1; COND(c
[D_CBC_CAST
][testnum
]); count
++)
2277 CAST_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2278 (size_t)lengths
[testnum
], &cast_ks
,
2281 print_result(D_CBC_CAST
, testnum
, count
, d
);
2287 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2288 if (multiblock
&& evp_cipher
) {
2290 (EVP_CIPHER_flags(evp_cipher
) &
2291 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
)) {
2292 BIO_printf(bio_err
, "%s is not multi-block capable\n",
2293 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
)));
2296 if (async_jobs
> 0) {
2297 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2300 multiblock_speed(evp_cipher
);
2305 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2308 names
[D_EVP
] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
2310 * -O3 -fschedule-insns messes up an optimization here!
2311 * names[D_EVP] somehow becomes NULL
2313 print_message(names
[D_EVP
], save_count
, lengths
[testnum
]);
2315 for (k
= 0; k
< loopargs_len
; k
++) {
2316 loopargs
[k
].ctx
= EVP_CIPHER_CTX_new();
2318 EVP_DecryptInit_ex(loopargs
[k
].ctx
, evp_cipher
, NULL
, key16
, iv
);
2320 EVP_EncryptInit_ex(loopargs
[k
].ctx
, evp_cipher
, NULL
, key16
, iv
);
2321 EVP_CIPHER_CTX_set_padding(loopargs
[k
].ctx
, 0);
2325 count
= run_benchmark(async_jobs
, EVP_Update_loop
, loopargs
);
2327 for (k
= 0; k
< loopargs_len
; k
++) {
2328 EVP_CIPHER_CTX_free(loopargs
[k
].ctx
);
2332 names
[D_EVP
] = OBJ_nid2ln(EVP_MD_type(evp_md
));
2333 print_message(names
[D_EVP
], save_count
, lengths
[testnum
]);
2335 count
= run_benchmark(async_jobs
, EVP_Digest_loop
, loopargs
);
2338 print_result(D_EVP
, testnum
, count
, d
);
2342 for (i
= 0; i
< loopargs_len
; i
++)
2343 RAND_bytes(loopargs
[i
].buf
, 36);
2345 #ifndef OPENSSL_NO_RSA
2346 for (testnum
= 0; testnum
< RSA_NUM
; testnum
++) {
2348 if (!rsa_doit
[testnum
])
2350 for (i
= 0; i
< loopargs_len
; i
++) {
2351 st
= RSA_sign(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
2352 &loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
2358 "RSA sign failure. No RSA sign will be done.\n");
2359 ERR_print_errors(bio_err
);
2362 pkey_print_message("private", "rsa",
2363 rsa_c
[testnum
][0], rsa_bits
[testnum
], RSA_SECONDS
);
2364 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2366 count
= run_benchmark(async_jobs
, RSA_sign_loop
, loopargs
);
2369 mr
? "+R1:%ld:%d:%.2f\n"
2370 : "%ld %d bit private RSA's in %.2fs\n",
2371 count
, rsa_bits
[testnum
], d
);
2372 rsa_results
[testnum
][0] = d
/ (double)count
;
2376 for (i
= 0; i
< loopargs_len
; i
++) {
2377 st
= RSA_verify(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
2378 loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
2384 "RSA verify failure. No RSA verify will be done.\n");
2385 ERR_print_errors(bio_err
);
2386 rsa_doit
[testnum
] = 0;
2388 pkey_print_message("public", "rsa",
2389 rsa_c
[testnum
][1], rsa_bits
[testnum
], RSA_SECONDS
);
2391 count
= run_benchmark(async_jobs
, RSA_verify_loop
, loopargs
);
2394 mr
? "+R2:%ld:%d:%.2f\n"
2395 : "%ld %d bit public RSA's in %.2fs\n",
2396 count
, rsa_bits
[testnum
], d
);
2397 rsa_results
[testnum
][1] = d
/ (double)count
;
2400 if (rsa_count
<= 1) {
2401 /* if longer than 10s, don't do any more */
2402 for (testnum
++; testnum
< RSA_NUM
; testnum
++)
2403 rsa_doit
[testnum
] = 0;
2406 #endif /* OPENSSL_NO_RSA */
2408 for (i
= 0; i
< loopargs_len
; i
++)
2409 RAND_bytes(loopargs
[i
].buf
, 36);
2411 #ifndef OPENSSL_NO_DSA
2412 if (RAND_status() != 1) {
2413 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2415 for (testnum
= 0; testnum
< DSA_NUM
; testnum
++) {
2417 if (!dsa_doit
[testnum
])
2420 /* DSA_generate_key(dsa_key[testnum]); */
2421 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2422 for (i
= 0; i
< loopargs_len
; i
++) {
2423 st
= DSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2424 &loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
2430 "DSA sign failure. No DSA sign will be done.\n");
2431 ERR_print_errors(bio_err
);
2434 pkey_print_message("sign", "dsa",
2435 dsa_c
[testnum
][0], dsa_bits
[testnum
], DSA_SECONDS
);
2437 count
= run_benchmark(async_jobs
, DSA_sign_loop
, loopargs
);
2440 mr
? "+R3:%ld:%d:%.2f\n"
2441 : "%ld %d bit DSA signs in %.2fs\n",
2442 count
, dsa_bits
[testnum
], d
);
2443 dsa_results
[testnum
][0] = d
/ (double)count
;
2447 for (i
= 0; i
< loopargs_len
; i
++) {
2448 st
= DSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2449 loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
2455 "DSA verify failure. No DSA verify will be done.\n");
2456 ERR_print_errors(bio_err
);
2457 dsa_doit
[testnum
] = 0;
2459 pkey_print_message("verify", "dsa",
2460 dsa_c
[testnum
][1], dsa_bits
[testnum
], DSA_SECONDS
);
2462 count
= run_benchmark(async_jobs
, DSA_verify_loop
, loopargs
);
2465 mr
? "+R4:%ld:%d:%.2f\n"
2466 : "%ld %d bit DSA verify in %.2fs\n",
2467 count
, dsa_bits
[testnum
], d
);
2468 dsa_results
[testnum
][1] = d
/ (double)count
;
2471 if (rsa_count
<= 1) {
2472 /* if longer than 10s, don't do any more */
2473 for (testnum
++; testnum
< DSA_NUM
; testnum
++)
2474 dsa_doit
[testnum
] = 0;
2477 #endif /* OPENSSL_NO_DSA */
2479 #ifndef OPENSSL_NO_EC
2480 if (RAND_status() != 1) {
2481 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2483 for (testnum
= 0; testnum
< EC_NUM
; testnum
++) {
2486 if (!ecdsa_doit
[testnum
])
2487 continue; /* Ignore Curve */
2488 for (i
= 0; i
< loopargs_len
; i
++) {
2489 loopargs
[i
].ecdsa
[testnum
] = EC_KEY_new_by_curve_name(test_curves
[testnum
]);
2490 if (loopargs
[i
].ecdsa
[testnum
] == NULL
) {
2496 BIO_printf(bio_err
, "ECDSA failure.\n");
2497 ERR_print_errors(bio_err
);
2500 for (i
= 0; i
< loopargs_len
; i
++) {
2501 EC_KEY_precompute_mult(loopargs
[i
].ecdsa
[testnum
], NULL
);
2502 /* Perform ECDSA signature test */
2503 EC_KEY_generate_key(loopargs
[i
].ecdsa
[testnum
]);
2504 st
= ECDSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2505 &loopargs
[i
].siglen
, loopargs
[i
].ecdsa
[testnum
]);
2511 "ECDSA sign failure. No ECDSA sign will be done.\n");
2512 ERR_print_errors(bio_err
);
2515 pkey_print_message("sign", "ecdsa",
2516 ecdsa_c
[testnum
][0],
2517 test_curves_bits
[testnum
], ECDSA_SECONDS
);
2519 count
= run_benchmark(async_jobs
, ECDSA_sign_loop
, loopargs
);
2523 mr
? "+R5:%ld:%d:%.2f\n" :
2524 "%ld %d bit ECDSA signs in %.2fs \n",
2525 count
, test_curves_bits
[testnum
], d
);
2526 ecdsa_results
[testnum
][0] = d
/ (double)count
;
2530 /* Perform ECDSA verification test */
2531 for (i
= 0; i
< loopargs_len
; i
++) {
2532 st
= ECDSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2533 loopargs
[i
].siglen
, loopargs
[i
].ecdsa
[testnum
]);
2539 "ECDSA verify failure. No ECDSA verify will be done.\n");
2540 ERR_print_errors(bio_err
);
2541 ecdsa_doit
[testnum
] = 0;
2543 pkey_print_message("verify", "ecdsa",
2544 ecdsa_c
[testnum
][1],
2545 test_curves_bits
[testnum
], ECDSA_SECONDS
);
2547 count
= run_benchmark(async_jobs
, ECDSA_verify_loop
, loopargs
);
2550 mr
? "+R6:%ld:%d:%.2f\n"
2551 : "%ld %d bit ECDSA verify in %.2fs\n",
2552 count
, test_curves_bits
[testnum
], d
);
2553 ecdsa_results
[testnum
][1] = d
/ (double)count
;
2556 if (rsa_count
<= 1) {
2557 /* if longer than 10s, don't do any more */
2558 for (testnum
++; testnum
< EC_NUM
; testnum
++)
2559 ecdsa_doit
[testnum
] = 0;
2564 if (RAND_status() != 1) {
2565 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2567 for (testnum
= 0; testnum
< EC_NUM
; testnum
++) {
2568 int ecdh_checks
= 1;
2570 if (!ecdh_doit
[testnum
])
2573 for (i
= 0; i
< loopargs_len
; i
++) {
2574 EVP_PKEY_CTX
*kctx
= NULL
, *ctx
= NULL
;
2575 EVP_PKEY
*key_A
= NULL
, *key_B
= NULL
;
2577 if (testnum
== R_EC_X25519
) {
2578 kctx
= EVP_PKEY_CTX_new_id(test_curves
[testnum
], NULL
); // keygen ctx from NID
2580 EVP_PKEY_CTX
*pctx
= NULL
;
2581 EVP_PKEY
*params
= NULL
;
2583 if( /* Create the context for parameter generation */
2584 !(pctx
= EVP_PKEY_CTX_new_id(EVP_PKEY_EC
, NULL
)) ||
2585 /* Initialise the parameter generation */
2586 !EVP_PKEY_paramgen_init(pctx
) ||
2587 /* Set the curve by NID */
2588 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx
, test_curves
[testnum
]) ||
2589 /* Create the parameter object params */
2590 !EVP_PKEY_paramgen(pctx
, ¶ms
) ||
2593 BIO_printf(bio_err
, "ECDH init failure.\n");
2594 ERR_print_errors(bio_err
);
2598 /* Create the context for the key generation */
2599 kctx
= EVP_PKEY_CTX_new(params
, NULL
);
2601 EVP_PKEY_free(params
); params
= NULL
;
2602 EVP_PKEY_CTX_free(pctx
); pctx
= NULL
;
2604 if ( !kctx
|| // keygen ctx is not null
2605 !EVP_PKEY_keygen_init(kctx
) || // init keygen ctx
2608 BIO_printf(bio_err
, "ECDH keygen failure.\n");
2609 ERR_print_errors(bio_err
);
2614 if ( !EVP_PKEY_keygen(kctx
, &key_A
) || // generate secret key A
2615 !EVP_PKEY_keygen(kctx
, &key_B
) || // generate secret key B
2616 !(ctx
= EVP_PKEY_CTX_new(key_A
, NULL
)) || // derivation ctx from skeyA
2617 !EVP_PKEY_derive_init(ctx
) || // init derivation ctx
2618 !EVP_PKEY_derive_set_peer(ctx
, key_B
) || // set peer pubkey in ctx
2621 BIO_printf(bio_err
, "ECDH key generation failure.\n");
2622 ERR_print_errors(bio_err
);
2627 //loopargs[i].ecdh_a[testnum] = key_A;
2628 //loopargs[i].ecdh_b[testnum] = key_B;
2629 loopargs
[i
].ecdh_ctx
[testnum
] = ctx
;
2631 EVP_PKEY_CTX_free(kctx
); kctx
= NULL
;
2633 if (ecdh_checks
!= 0) {
2634 pkey_print_message("", "ecdh",
2636 test_curves_bits
[testnum
], ECDH_SECONDS
);
2638 count
= run_benchmark(async_jobs
, ECDH_EVP_derive_key_loop
, loopargs
);
2641 mr
? "+R7:%ld:%d:%.2f\n" :
2642 "%ld %d-bit ECDH ops in %.2fs\n", count
,
2643 test_curves_bits
[testnum
], d
);
2644 ecdh_results
[testnum
][0] = d
/ (double)count
;
2648 if (rsa_count
<= 1) {
2649 /* if longer than 10s, don't do any more */
2650 for (testnum
++; testnum
< EC_NUM
; testnum
++)
2651 ecdh_doit
[testnum
] = 0;
2654 #endif /* OPENSSL_NO_EC */
2659 printf("%s\n", OpenSSL_version(OPENSSL_VERSION
));
2660 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON
));
2662 printf("%s ", BN_options());
2663 #ifndef OPENSSL_NO_MD2
2664 printf("%s ", MD2_options());
2666 #ifndef OPENSSL_NO_RC4
2667 printf("%s ", RC4_options());
2669 #ifndef OPENSSL_NO_DES
2670 printf("%s ", DES_options());
2672 printf("%s ", AES_options());
2673 #ifndef OPENSSL_NO_IDEA
2674 printf("%s ", IDEA_options());
2676 #ifndef OPENSSL_NO_BF
2677 printf("%s ", BF_options());
2679 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS
));
2687 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2690 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++)
2691 printf(mr
? ":%d" : "%7d bytes", lengths
[testnum
]);
2695 for (k
= 0; k
< ALGOR_NUM
; k
++) {
2699 printf("+F:%d:%s", k
, names
[k
]);
2701 printf("%-13s", names
[k
]);
2702 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2703 if (results
[k
][testnum
] > 10000 && !mr
)
2704 printf(" %11.2fk", results
[k
][testnum
] / 1e3
);
2706 printf(mr
? ":%.2f" : " %11.2f ", results
[k
][testnum
]);
2710 #ifndef OPENSSL_NO_RSA
2712 for (k
= 0; k
< RSA_NUM
; k
++) {
2715 if (testnum
&& !mr
) {
2716 printf("%18ssign verify sign/s verify/s\n", " ");
2720 printf("+F2:%u:%u:%f:%f\n",
2721 k
, rsa_bits
[k
], rsa_results
[k
][0], rsa_results
[k
][1]);
2723 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2724 rsa_bits
[k
], rsa_results
[k
][0], rsa_results
[k
][1],
2725 1.0 / rsa_results
[k
][0], 1.0 / rsa_results
[k
][1]);
2728 #ifndef OPENSSL_NO_DSA
2730 for (k
= 0; k
< DSA_NUM
; k
++) {
2733 if (testnum
&& !mr
) {
2734 printf("%18ssign verify sign/s verify/s\n", " ");
2738 printf("+F3:%u:%u:%f:%f\n",
2739 k
, dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1]);
2741 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2742 dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1],
2743 1.0 / dsa_results
[k
][0], 1.0 / dsa_results
[k
][1]);
2746 #ifndef OPENSSL_NO_EC
2748 for (k
= 0; k
< EC_NUM
; k
++) {
2751 if (testnum
&& !mr
) {
2752 printf("%30ssign verify sign/s verify/s\n", " ");
2757 printf("+F4:%u:%u:%f:%f\n",
2758 k
, test_curves_bits
[k
],
2759 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
2761 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2762 test_curves_bits
[k
],
2763 test_curves_names
[k
],
2764 ecdsa_results
[k
][0], ecdsa_results
[k
][1],
2765 1.0 / ecdsa_results
[k
][0], 1.0 / ecdsa_results
[k
][1]);
2769 for (k
= 0; k
< EC_NUM
; k
++) {
2772 if (testnum
&& !mr
) {
2773 printf("%30sop op/s\n", " ");
2777 printf("+F5:%u:%u:%f:%f\n",
2778 k
, test_curves_bits
[k
],
2779 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
2782 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2783 test_curves_bits
[k
],
2784 test_curves_names
[k
],
2785 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
2792 ERR_print_errors(bio_err
);
2793 for (i
= 0; i
< loopargs_len
; i
++) {
2794 OPENSSL_free(loopargs
[i
].buf_malloc
);
2795 OPENSSL_free(loopargs
[i
].buf2_malloc
);
2797 #ifndef OPENSSL_NO_RSA
2798 for (k
= 0; k
< RSA_NUM
; k
++)
2799 RSA_free(loopargs
[i
].rsa_key
[k
]);
2801 #ifndef OPENSSL_NO_DSA
2802 for (k
= 0; k
< DSA_NUM
; k
++)
2803 DSA_free(loopargs
[i
].dsa_key
[k
]);
2805 #ifndef OPENSSL_NO_EC
2806 for (k
= 0; k
< EC_NUM
; k
++) {
2807 EC_KEY_free(loopargs
[i
].ecdsa
[k
]);
2808 //EVP_PKEY_free(loopargs[i].ecdh_a[k]);
2809 //EVP_PKEY_free(loopargs[i].ecdh_b[k]);
2810 EVP_PKEY_CTX_free(loopargs
[i
].ecdh_ctx
[k
]);
2812 OPENSSL_free(loopargs
[i
].secret_a
);
2813 OPENSSL_free(loopargs
[i
].secret_b
);
2817 if (async_jobs
> 0) {
2818 for (i
= 0; i
< loopargs_len
; i
++)
2819 ASYNC_WAIT_CTX_free(loopargs
[i
].wait_ctx
);
2823 ASYNC_cleanup_thread();
2825 OPENSSL_free(loopargs
);
2830 static void print_message(const char *s
, long num
, int length
)
2834 mr
? "+DT:%s:%d:%d\n"
2835 : "Doing %s for %ds on %d size blocks: ", s
, SECONDS
, length
);
2836 (void)BIO_flush(bio_err
);
2840 mr
? "+DN:%s:%ld:%d\n"
2841 : "Doing %s %ld times on %d size blocks: ", s
, num
, length
);
2842 (void)BIO_flush(bio_err
);
2846 static void pkey_print_message(const char *str
, const char *str2
, long num
,
2851 mr
? "+DTP:%d:%s:%s:%d\n"
2852 : "Doing %d bit %s %s's for %ds: ", bits
, str
, str2
, tm
);
2853 (void)BIO_flush(bio_err
);
2857 mr
? "+DNP:%ld:%d:%s:%s\n"
2858 : "Doing %ld %d bit %s %s's: ", num
, bits
, str
, str2
);
2859 (void)BIO_flush(bio_err
);
2863 static void print_result(int alg
, int run_no
, int count
, double time_used
)
2866 BIO_puts(bio_err
, "EVP error!\n");
2870 mr
? "+R:%d:%s:%f\n"
2871 : "%d %s's in %.2fs\n", count
, names
[alg
], time_used
);
2872 results
[alg
][run_no
] = ((double)count
) / time_used
* lengths
[run_no
];
2876 static char *sstrsep(char **string
, const char *delim
)
2879 char *token
= *string
;
2884 memset(isdelim
, 0, sizeof isdelim
);
2888 isdelim
[(unsigned char)(*delim
)] = 1;
2892 while (!isdelim
[(unsigned char)(**string
)]) {
2904 static int do_multi(int multi
)
2909 static char sep
[] = ":";
2911 fds
= malloc(sizeof(*fds
) * multi
);
2912 for (n
= 0; n
< multi
; ++n
) {
2913 if (pipe(fd
) == -1) {
2914 BIO_printf(bio_err
, "pipe failure\n");
2918 (void)BIO_flush(bio_err
);
2925 if (dup(fd
[1]) == -1) {
2926 BIO_printf(bio_err
, "dup failed\n");
2935 printf("Forked child %d\n", n
);
2938 /* for now, assume the pipe is long enough to take all the output */
2939 for (n
= 0; n
< multi
; ++n
) {
2944 f
= fdopen(fds
[n
], "r");
2945 while (fgets(buf
, sizeof buf
, f
)) {
2946 p
= strchr(buf
, '\n');
2949 if (buf
[0] != '+') {
2950 BIO_printf(bio_err
, "Don't understand line '%s' from child %d\n",
2954 printf("Got: %s from %d\n", buf
, n
);
2955 if (strncmp(buf
, "+F:", 3) == 0) {
2960 alg
= atoi(sstrsep(&p
, sep
));
2962 for (j
= 0; j
< SIZE_NUM
; ++j
)
2963 results
[alg
][j
] += atof(sstrsep(&p
, sep
));
2964 } else if (strncmp(buf
, "+F2:", 4) == 0) {
2969 k
= atoi(sstrsep(&p
, sep
));
2972 d
= atof(sstrsep(&p
, sep
));
2974 rsa_results
[k
][0] = 1 / (1 / rsa_results
[k
][0] + 1 / d
);
2976 rsa_results
[k
][0] = d
;
2978 d
= atof(sstrsep(&p
, sep
));
2980 rsa_results
[k
][1] = 1 / (1 / rsa_results
[k
][1] + 1 / d
);
2982 rsa_results
[k
][1] = d
;
2984 # ifndef OPENSSL_NO_DSA
2985 else if (strncmp(buf
, "+F3:", 4) == 0) {
2990 k
= atoi(sstrsep(&p
, sep
));
2993 d
= atof(sstrsep(&p
, sep
));
2995 dsa_results
[k
][0] = 1 / (1 / dsa_results
[k
][0] + 1 / d
);
2997 dsa_results
[k
][0] = d
;
2999 d
= atof(sstrsep(&p
, sep
));
3001 dsa_results
[k
][1] = 1 / (1 / dsa_results
[k
][1] + 1 / d
);
3003 dsa_results
[k
][1] = d
;
3006 # ifndef OPENSSL_NO_EC
3007 else if (strncmp(buf
, "+F4:", 4) == 0) {
3012 k
= atoi(sstrsep(&p
, sep
));
3015 d
= atof(sstrsep(&p
, sep
));
3017 ecdsa_results
[k
][0] =
3018 1 / (1 / ecdsa_results
[k
][0] + 1 / d
);
3020 ecdsa_results
[k
][0] = d
;
3022 d
= atof(sstrsep(&p
, sep
));
3024 ecdsa_results
[k
][1] =
3025 1 / (1 / ecdsa_results
[k
][1] + 1 / d
);
3027 ecdsa_results
[k
][1] = d
;
3028 } else if (strncmp(buf
, "+F5:", 4) == 0) {
3033 k
= atoi(sstrsep(&p
, sep
));
3036 d
= atof(sstrsep(&p
, sep
));
3038 ecdh_results
[k
][0] = 1 / (1 / ecdh_results
[k
][0] + 1 / d
);
3040 ecdh_results
[k
][0] = d
;
3045 else if (strncmp(buf
, "+H:", 3) == 0) {
3048 BIO_printf(bio_err
, "Unknown type '%s' from child %d\n", buf
, n
);
3058 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
)
3060 static int mblengths
[] =
3061 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3062 int j
, count
, num
= OSSL_NELEM(mblengths
);
3063 const char *alg_name
;
3064 unsigned char *inp
, *out
, no_key
[32], no_iv
[16];
3065 EVP_CIPHER_CTX
*ctx
;
3068 inp
= app_malloc(mblengths
[num
- 1], "multiblock input buffer");
3069 out
= app_malloc(mblengths
[num
- 1] + 1024, "multiblock output buffer");
3070 ctx
= EVP_CIPHER_CTX_new();
3071 EVP_EncryptInit_ex(ctx
, evp_cipher
, NULL
, no_key
, no_iv
);
3072 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_MAC_KEY
, sizeof(no_key
),
3074 alg_name
= OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
3076 for (j
= 0; j
< num
; j
++) {
3077 print_message(alg_name
, 0, mblengths
[j
]);
3079 for (count
= 0, run
= 1; run
&& count
< 0x7fffffff; count
++) {
3080 unsigned char aad
[EVP_AEAD_TLS1_AAD_LEN
];
3081 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param
;
3082 size_t len
= mblengths
[j
];
3085 memset(aad
, 0, 8); /* avoid uninitialized values */
3086 aad
[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3087 aad
[9] = 3; /* version */
3089 aad
[11] = 0; /* length */
3091 mb_param
.out
= NULL
;
3094 mb_param
.interleave
= 8;
3096 packlen
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD
,
3097 sizeof(mb_param
), &mb_param
);
3103 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT
,
3104 sizeof(mb_param
), &mb_param
);
3108 RAND_bytes(out
, 16);
3112 pad
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_TLS1_AAD
,
3113 EVP_AEAD_TLS1_AAD_LEN
, aad
);
3114 EVP_Cipher(ctx
, out
, inp
, len
+ pad
);
3118 BIO_printf(bio_err
, mr
? "+R:%d:%s:%f\n"
3119 : "%d %s's in %.2fs\n", count
, "evp", d
);
3120 results
[D_EVP
][j
] = ((double)count
) / d
* mblengths
[j
];
3124 fprintf(stdout
, "+H");
3125 for (j
= 0; j
< num
; j
++)
3126 fprintf(stdout
, ":%d", mblengths
[j
]);
3127 fprintf(stdout
, "\n");
3128 fprintf(stdout
, "+F:%d:%s", D_EVP
, alg_name
);
3129 for (j
= 0; j
< num
; j
++)
3130 fprintf(stdout
, ":%.2f", results
[D_EVP
][j
]);
3131 fprintf(stdout
, "\n");
3134 "The 'numbers' are in 1000s of bytes per second processed.\n");
3135 fprintf(stdout
, "type ");
3136 for (j
= 0; j
< num
; j
++)
3137 fprintf(stdout
, "%7d bytes", mblengths
[j
]);
3138 fprintf(stdout
, "\n");
3139 fprintf(stdout
, "%-24s", alg_name
);
3141 for (j
= 0; j
< num
; j
++) {
3142 if (results
[D_EVP
][j
] > 10000)
3143 fprintf(stdout
, " %11.2fk", results
[D_EVP
][j
] / 1e3
);
3145 fprintf(stdout
, " %11.2f ", results
[D_EVP
][j
]);
3147 fprintf(stdout
, "\n");
3152 EVP_CIPHER_CTX_free(ctx
);